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

Use evm_mine to control the block times #709

Open
iamdefinitelyahuman opened this issue Aug 3, 2020 · 1 comment
Open

Use evm_mine to control the block times #709

iamdefinitelyahuman opened this issue Aug 3, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@iamdefinitelyahuman
Copy link
Member

Ganache adds challenges when testing time-dependent behaviors, because the clock is always advancing. This can be mitigated by disabling auto-mine with miner_stop and then controlling the mining process manually with evm_mine. evm_mine accepts a timestamp as an optional argument, which we can use to force the blocktimes.

Under the hood this could require some significant changes, so it probably belongs in the context of Brownie v2. I think happening in a middleware makes sense, where any call to eth_sendTransaction spawns and waits for thread that calls evm_mine.

Another benefit I see here is the issue with calls-as-transactions sometimes causing issues when the called method relies on a timestamp. For these calls we can always force the mined block to have a timestamp == that of the last transaction, and then we can trust the return value.

I'm not sure how to best expose something like this to the user. Two ideas come to mind:

  1. chain.set_blocktime(seconds=None) where if seconds is None the clock advances normally, otherwise each block is exactly seconds apart.
  2. As a context manager... with chain.blocktimes(seconds): ... to temporarily override the default behavior.

In implementing this, there will also need to be consideration for how chain.sleep and chain.time work.

@iamdefinitelyahuman
Copy link
Member Author

With the general middleware framework added in #997, I think this should be much easier to implement.

Also, once hardhat support arrives this can be accomplished using evm_setNextBlockTimestamp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant