-
Notifications
You must be signed in to change notification settings - Fork 683
feat: allow balance, code, nonce, and state overrides in eth_call
#2565
feat: allow balance, code, nonce, and state overrides in eth_call
#2565
Conversation
Note that geth also supports overriding storage slots, which this PR does not yet implement (because I personally don't need it and also #905 did not implement it). I think this can be added as a follow-up when needed. But if you prefer to include support with this PR, let me know and I can try to add it. |
@domob1812 Thank you for the PR! We are reviewing and adding support for overriding storage slots while we're at it. This should hopefully be available in the next release! |
Ok cool, thanks a lot! If you need any help from my side, let me know. I can also work on the storage slots, although I guess you know the involved code much better than me (of course). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking really great! Exciting to finally see this feature land!
I've requested some changes. Let me know if either of you (@domob1812 @MicaiahReid ) have questions or disagree with any of my comments!
96d6c7f
to
47d583d
Compare
I've done a lot of testing in Geth to see how their
I've made updates so that Ganache behaves the same way, but there's some very specific data validation that we're now doing in the Also, we should probably consider matching our |
eth_call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meant to request changes on the last review. so i'm reeviewing again.
6848f5b
to
d531d39
Compare
Support overriding the contract code, account balances and nonces for simulations with eth_call. This is an extension also supported by geth.
Co-authored-by: David Murdoch <[email protected]>
d531d39
to
37e7596
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3
…2565) * feat: Allow contract code and balance overrides Support overriding the contract code, account balances and nonces for simulations with eth_call. This is an extension also supported by geth. * reorg eth_call override type. add state/stateDiff * support state/stateDiff in eth_call override * fix eth_call code override. reorg a bit * add override structure to eth_call jsdocs * add override to eth_call example in jsdoc * prevent use of state & stateDiff on override * remove unused import on test * add encodeValue/deployContract helpers * reorg previous test to make room for new * add tests for eth_call override * rename eth_call override type * change keccak import to be from @ganache/utils * await async function * change `Object.entries` to more perfomant `for ... in` * rename confusing key name * change `Object.entries` to more performang `for ... in` * move comment * data validation for state/Diff override * add junk data test for eth_call overrides * remove unused file * correctly throw on both state && stateDiff * fix broken test * remove unused throw * change return to continue like a smart person * make state/stateDiff looping more efficient * fix test name * abstract override generation in test * fix override balance test expected value * fix override code test * fix override state/stateDiff test data * fix override stateDiff expected values * fix override state expected values * add todo comment * add bad slot values for state/Diff test * add junk value test for nonce * add data validation method for state/Diff override * validate data for state/Diff override * fix some default data to match geth * Move eth_call overrides setting to helper file * Apply suggestions from code review Co-authored-by: David Murdoch <[email protected]> * extract types to run-call helper * check length directly rather than removing prefix * use copied trie for eth_call * fix copy/paste error * fix copy/paste error * beef up test a bit * remove unused libraries * add tests to confirm eth_call changes are ephemeral * set multiple slots in test * make tests more scrict Co-authored-by: Jacob Evans <[email protected]> Co-authored-by: MicaiahReid <[email protected]> Co-authored-by: David Murdoch <[email protected]>
…2565) * feat: Allow contract code and balance overrides Support overriding the contract code, account balances and nonces for simulations with eth_call. This is an extension also supported by geth. * reorg eth_call override type. add state/stateDiff * support state/stateDiff in eth_call override * fix eth_call code override. reorg a bit * add override structure to eth_call jsdocs * add override to eth_call example in jsdoc * prevent use of state & stateDiff on override * remove unused import on test * add encodeValue/deployContract helpers * reorg previous test to make room for new * add tests for eth_call override * rename eth_call override type * change keccak import to be from @ganache/utils * await async function * change `Object.entries` to more perfomant `for ... in` * rename confusing key name * change `Object.entries` to more performang `for ... in` * move comment * data validation for state/Diff override * add junk data test for eth_call overrides * remove unused file * correctly throw on both state && stateDiff * fix broken test * remove unused throw * change return to continue like a smart person * make state/stateDiff looping more efficient * fix test name * abstract override generation in test * fix override balance test expected value * fix override code test * fix override state/stateDiff test data * fix override stateDiff expected values * fix override state expected values * add todo comment * add bad slot values for state/Diff test * add junk value test for nonce * add data validation method for state/Diff override * validate data for state/Diff override * fix some default data to match geth * Move eth_call overrides setting to helper file * Apply suggestions from code review Co-authored-by: David Murdoch <[email protected]> * extract types to run-call helper * check length directly rather than removing prefix * use copied trie for eth_call * fix copy/paste error * fix copy/paste error * beef up test a bit * remove unused libraries * add tests to confirm eth_call changes are ephemeral * set multiple slots in test * make tests more scrict Co-authored-by: Jacob Evans <[email protected]> Co-authored-by: MicaiahReid <[email protected]> Co-authored-by: David Murdoch <[email protected]>
This PR adds support for overriding the contract code and storage and the account balance and nonce for simulations with
eth_call
. This feature is similarly supported by geth.The
eth_call
RPC method now accepts a third override parameter which is a map from an address to the desired state of that address. The state object has the following keys, all of which are optional:So, an example override object using all fields overriding multiple addresses could look like the following:
Like all state changes made with
eth_call
, the changes are ephemeral and only last for that specific run ofeth_call
. We'd like to give a huge thank you to @domob1812 and @dekz for their initial contributions to this one, you both were a huge help.The PR introducing this feature uses @dekz's #905 as a starting point, and fixes #554 and #2934.