delvtech / hyperdrive

An automated market maker for fixed and variable yield with on-demand terms.
Apache License 2.0
26 stars 3 forks source link

fix targeted long tests #952

Closed dpaiton closed 4 months ago

dpaiton commented 4 months ago

Resolved Issues

intermittent CI crashes; no issue created

Description

CI was crashing with intermittent errors. For example:

---- long::targeted::tests::test_calculate_targeted_long_with_budget stdout ----
thread 'long::targeted::tests::test_calculate_targeted_long_with_budget' panicked at crates/hyperdrive-math/src/long/targeted.rs:532:17:
The new_rate=0.065615470865036337 should be <= target_rate=0.040702128765527778 when budget constrained.

failures:
    long::targeted::tests::test_calculate_targeted_long_with_budget

test result: FAILED. 33 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 520.83s

This particular error was caused by an incorrect sign. In that condition, we expected that the test undershot & should raise an error on the opposite condition (the else condition presumes that we undershot, which would be >= instead of <=).

I also added another check for an acceptable but unlikely (if not impossible in this test) failure condition where the target rate is too low, resulting in insolvency.

Review Checklists

Please check each item before approving the pull request. While going through the checklist, it is recommended to leave comments on items that are referenced in the checklist to make sure that they are reviewed. If there are multiple reviewers, copy the checklists into sections titled ## [Reviewer Name]. If the PR doesn't touch Solidity and/or Rust, the corresponding checklist can be removed.

Rust