Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix BlockOutOfRangeError in fuzz tests #4

Open
dpaiton opened this issue Apr 26, 2024 · 5 comments · Fixed by #142
Open

fix BlockOutOfRangeError in fuzz tests #4

dpaiton opened this issue Apr 26, 2024 · 5 comments · Fixed by #142
Labels
bug Something isn't working

Comments

@dpaiton
Copy link
Member

dpaiton commented Apr 26, 2024

Two test occasionally fail with a BlockOutOfRangeError message.

long::open::tests::fuzz_calculate_spot_price_after_long

---- long::open::tests::fuzz_calculate_spot_price_after_long stdout ----
Error: (code: -32602, message: BlockOutOfRangeError: block height is 15 but requested was 16, data: None)

Location:
    /Users/dylan/code/delv/hyperdrive-rs/crates/test-utils/src/agent.rs:471:17

long::targeted::tests::test_calculate_targeted_long_with_budget

---- long::targeted::tests::test_calculate_targeted_long_with_budget stdout ----
Error: (code: -32602, message: BlockOutOfRangeError: block height is 16 but requested was 17, data: None)

Location:
    /Users/dylan/code/delv/hyperdrive-rs/crates/test-utils/src/agent.rs:943:13
@dpaiton
Copy link
Member Author

dpaiton commented May 10, 2024

The two cited line numbers are during initialize and hyperdrive.get_pool_info(), which is a wrappers function. Maybe this is an async issue?

@jalextowle
Copy link
Contributor

Closing since I haven't seen this since fixing the nonce too low issue. We can re-open if we see it pop back up.

@dpaiton
Copy link
Member Author

dpaiton commented Jun 21, 2024

I found this issue again; I think it is happening between mint & approve in agent.fund(). Maybe we need to increase the sleep duration between these two calls?

Error: (code: -32602, message: BlockOutOfRangeError: block height is 114 but requested was 16, data: None)

Location:
    /Users/dylan/code/delv/hyperdrive-rs/crates/hyperdrive-test-utils/src/agent.rs:494:9


failures:
    long::open::tests::fuzz_sol_calculate_open_long

@dpaiton
Copy link
Member Author

dpaiton commented Jun 21, 2024

I was able to consistently reproduce this while working on #142 and then (hopefully) fixed it by adding a sleep after the base approval step in agent.fund()

@dpaiton dpaiton linked a pull request Jun 21, 2024 that will close this issue
dpaiton added a commit that referenced this issue Jun 22, 2024
# Resolved Issues
Making testing more consistent to help narrow problems found when
investigating #29

# Description
- single preamble
We had 3x duplicates of a `preamble` function that would execute a
series of trades on the deployed test pool in order to simulate testing
from a random state. I consolidated it into one location that is
imported elsewhere. I also added some checks on upper trade bounds so
that it is guaranteed to be valid, even if calc_max fails.

- code cleanup
This seemingly innocuous change caused a difficult-to-track Hisenbug
where the ERC20 contract would throw an overflow/underflow error
whenever we'd call `hyperdrive.open_long` or `hyperdrive.open_short`.
This was due to lack of approval, which was due to the approval call not
going through before the open call, which was due to anvil not being
able to keep up with the rust calls coming in.
I fixed that bug (thanks to @mcclurejt for the help!) and in the process
of hunting down that bug did a bunch of code cleanup stuff like improved
error messaging, variable names, organization, etc.
I'm was able to consistently reproduce #4 while tracking this bug, and
the fix we implemented seems to have also fixed that one.

- new tests
I also wrote a couple of new tests while hunting the Heisenbug.

### NOTE:
I had to increase test tolerance for `fuzz_sol_calc_open_short` from 1e9
to 10e18. My best guess as to why this happened is because we're now
testing a wider variety of valid states and we're hitting error modes. I
know that `calculate_open_short` does not match solidity exactly, so
most likely this is the source of the error. I added a comment as a
reminder in #29, but for now I think we should live with the high
tolerance.

That being said, I encourage the reviewer to look carefully. I may have
missed a change in this PR that is causing such a big error.
@dpaiton
Copy link
Member Author

dpaiton commented Jul 2, 2024

Looks like the error is still happening on main:
https://github.com/delvtech/hyperdrive-rs/actions/runs/9751500824/job/26913221206#step:5:862

@dpaiton dpaiton reopened this Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants