-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Allow forking from different RPCs/block numbers when testing #834
Comments
This would also allow for testing of apps that run across multiple chains which would be useful |
Another thought - perhaps it would be better to have named urls in the config file and then use the name as the first arg to |
Maybe we can add a Need to think about how to make the cheatcode work. Seems doable. cc @onbjerg, we'd want a way to modify the forked provider's pinned block inside a cheatcode. |
|
any status update for this? cc: @gakonst |
yes there'll be an option to reset/ and change this on the fly, but since this concerns forge, lets keep this open |
+1ing this from MakerDAO as we are very focused on cross-chain support for MCD. |
Support for this has landed in Anvil PR, but has not yet been incorporated into testing, we'd need some cheatcodes first for that @onbjerg ? |
|
Yes! We'd need two things:
For 1. we can either add Also: bonus points if we can make some easy-to-understand or reusable inspector <-> channel abstraction since it is useful for more things. For example, we could use it for a better debugging experience that doesn't crash on big contracts |
@onbjerg I like the generality of I sense that this is somewhat relevant to the efforts of @brockelmore to read/write data from files. is there a formula to kill 2 birds with one stone here? |
Not really. My only concern about only |
One idea in the middle:
Main thing to keep in mind imo is how do you maintain the in memory cache as you switch forks. I'd say vm.env is a little out of scope as a cheatcode , but we want IMO to be able to read env vars into foundry toml so we can have shared prefix urls and only appending the api key cc @mattsse |
FWIW this is also relevant to #939. We'll need a block number anyway, so perhaps we can use |
the rules regarding what state is kept when switching forks are not clear yet. Basically a fork DB consists of two halves: read, write:
when the executor needs a specific storage value then it does this check essentially: let value = write.get(addr, slot).unwrap_or(read.get(addr, slot)) which reads: "if the value exists in the write halve return this, otherwise return from the read halve and fetch from remote if missing" so a possible solution would be to switch out the |
This sounds right to me, but worth considering
Hmm, do we also need to switch out the |
so each fork has its own state, which you can load into the current context ( How would we handle the state of the test contract that we're currently in? clone when changing fork? |
Component
Forge
Describe the feature you would like
Currently if you want to test against mainnet state, you can pass in an RPC url and block number to fork from. However it isn't possible to run tests on multiple networks or fork from different block numbers.
For example, you might want 1 test to run against the state at block number 10000, and another at block number 20000.
Hardhat has a method called
hardhat_reset
which allows you to change the RPC url/block number mainnet state is forked from: https://hardhat.org/hardhat-network/guides/mainnet-forking.html#resetting-the-forkA cheatcode similar to that would be useful. It could look like this:
Additional context
No response
The text was updated successfully, but these errors were encountered: