-
Notifications
You must be signed in to change notification settings - Fork 27
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
time-bound tests fail sometimes #193
Comments
Hey 👋 Thanks for the feedback, I have checked your code quickly in the test. I do not know if it comes to this, since I am not an expert of titanoboa, but maybe it can help. @PatrickAlphaC maybe more titanoboa related or is it something that we can control? From your code to def warp(timestamp: int):
boa.env.evm.patch.timestamp = timestamp It is not in their recent doc, still WIP it will come in the future I think, but you can maybe use def time_travel(
self,
seconds: Optional[int] = None,
blocks: Optional[int] = None,
block_delta: int = 12,
) -> None:
if (seconds is None) == (blocks is None):
raise ValueError("One (and only one) of seconds or blocks should be set")
if seconds is not None:
blocks = seconds // block_delta
else:
assert blocks is not None # mypy hint
seconds = blocks * block_delta
self.evm.patch.timestamp += seconds
self.evm.patch.block_number += blocks |
seems it doesn't solve the issue. should i open the issue in their respective repo? |
Yeah, you can do so @krakovia-evm! Keep this issue thought and link it to titanoboa. It would be great to know the solution of your issue because Mox depends on titanoboa 👍 |
@krakovia-evm I might have found a solution while auditing on CodeHawks contest. I'll write it inside one of my submission with a reworked version of the test and deploy part. |
@krakovia-evm Here is how to avoid the error, how I "fixed" it:
def deploy() -> VyperContract:
current_time = int(boa.env.evm.patch.timestamp)
boa.env.time_travel(THIRTY_DAYS) You can also check the code since I forked the contest: https://github.com/s3bc40/2025-02-vyper-vested-claims/tree/main Hope this helps and that your audited contract will be helpful! Happy coding 🐍 |
I've noticed something weird with tests that depends on block.timestamp.
repo: https://github.com/krakovia-evm/VyperVestedClaims
my platform is windows11
I set the "start" timestamp when i deploy the contract, in /script/deploy.py, function deploy
in my tests (/tests/test_vested_airdrop.py) it seems that the timestamp is incremented when it reach the tests.
If i add a function inside the contract to update the timestamp, and set it as now() just before the function call, the test passes.
Also, if i run the same tests multiple times, they fail occasionally.
would be cool to have a sort of settings where we can "pin" the block.timestamp, or somehow modify how it works.
The text was updated successfully, but these errors were encountered: