-
Notifications
You must be signed in to change notification settings - Fork 1.1k
pallet-revive: add interface to implement mocks and pranks #9909
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
Conversation
690e4aa to
3cba3a8
Compare
Signed-off-by: Alexandru Gheorghe <[email protected]>
3cba3a8 to
a57b755
Compare
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
|
@athei @smiasojed changed a bit the approach instead of injecting data I added a mocks hooks trait that we then implement in foundry codebase here: https://github.com/paritytech/foundry-polkadot/pull/334/files#diff-9e3b7cd881b3ef657db58bf38a66549a3b651f550caa7d623f8d4b20a813ea79R73, let me know what you think. |
|
All GitHub workflows were cancelled due to failure one of the required jobs. |
|
|
||
| /// Convert a weight to a gas value. | ||
| fn evm_gas_from_weight(weight: Weight) -> U256 { | ||
| pub fn evm_gas_from_weight(weight: Weight) -> U256 { |
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.
Where is that used from outside the crate?
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.
Signed-off-by: Alexandru Gheorghe <[email protected]>
... to help with foundry-polkadot implementation for etch cheatcode Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
|
Should |
|
Should we charge deposit / gas if the call is mocked |
Good points will have to look in to it, the existing mock/prank testsuite seems to be working well, so probably we are doing the right thing here. |
Looked a bit in foundry and it seems that mocked calls don't consume any gas, https://github.com/paritytech/foundry-polkadot/blob/9dd622a57199cbce23603874bda1d656b5b6e3ec/crates/cheatcodes/src/inspector.rs#L1039, so I guess we need to make it the same here. |
Did some digging a bit and this PR is actually doing the right thingm because we don't actually execute the contract and we just use the mocked values, no gas and storage deposit is recorded in the frame, so we don't charge anything for mocked calls and that is the exact same behaviour as mainline foundry. |
I think that transfer will happen when:
Transfer will NOT happen when:
Is it intentional? |
Alright, I see your point, I did some investigations and foundry mainline doesn't do any transfer of value when calls are mocked, so I will make that consistent for our implementation as well. |
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
|
/cmd prdoc --audience node_dev --bump minor |
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.
LGTM, thanks
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Needed for: paritytech/foundry-polkadot#334.
In foundry-polkadot we need the ability to be able to manipulate the
msg.senderand thetx.originthat a solidity contract sees cheatcode documentation, plus the ability to mock calls and functions.Currently all create/call methods use the
bare_instantiate/bare_callto run things in pallet-revive, the caller then normally gets set automatically, based on what is the call stack, but forforge testwe need to be able to manipulate, so that we can set it to custom values.Additionally, for delegate_call, bare_call is used, so there is no way to specify we are dealing with a delegate call, so the call is not working correcly.
For both this paths, we need a way to inject this information into the execution environment, hence I added an optional hooks interface that we implement from foundry cheatcodes for prank and mock functionality.
TODO