-
Notifications
You must be signed in to change notification settings - Fork 6
add prank* and mock* cheatcodes family support #334
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
|
|
||
| fn fund_pranked_accounts(prank_enabled: bool, account: Address) { | ||
| // Fuzzed prank addresses have no balance, so they won't exist in revive, and | ||
| // calls will fail, this is not a problem when running in REVM. |
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.
how is it done that account without funds can be used to trigger call in REVM - how is gas charged in this case?
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.
Yeah, that's something I want to investigate.
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.
So, I did some digging, it seems to be because for revive we want to charge the storage deposit from the pranked accounts, I can probably add some hook in there:
https://github.com/paritytech/polkadot-sdk/blob/c61e227f2c59fa0ce7df5f977dad4076ff470f00/substrate/frame/revive/src/lib.rs#L1308
But, I also don't think the funding is such a bad solution.
Signed-off-by: Alexandru Gheorghe <[email protected]>
|
For pranking, couldn't you use an approach like we do in Anvil? #332 Overriding the host functions that do the account recovery |
Unless, I'm misunderstanding #332, these are two different things |
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]>
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]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
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.sender` and the `tx.origin` that a solidity contract sees cheatcode documentation, plus the ability to mock calls and functions. Currently all create/call methods use the `bare_instantiate`/`bare_call` to run things in pallet-revive, the caller then normally gets set automatically, based on what is the call stack, but for `forge test` we 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 - [x] Add tests to make sure the hooks functionality does not regress. --------- Signed-off-by: Alexandru Gheorghe <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.sender` and the `tx.origin` that a solidity contract sees cheatcode documentation, plus the ability to mock calls and functions. Currently all create/call methods use the `bare_instantiate`/`bare_call` to run things in pallet-revive, the caller then normally gets set automatically, based on what is the call stack, but for `forge test` we 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 - [x] Add tests to make sure the hooks functionality does not regress. --------- Signed-off-by: Alexandru Gheorghe <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Depends on: paritytech/polkadot-sdk#9909
Fixes: #324
Fixes: #335
There are a few problems with the way we currently do calls:
ecx.tx.caller., when calling bare_call/bare_instantiate.bare_callfor all type of calls, and that does not allow setting any delegate call info.In this pr I ended up adding a series of hooks in pallet-revive which allows to intercept and control the flow, the interface is described here https://github.com/paritytech/polkadot-sdk/pull/9909/files#diff-62436392e75447324001e88786b55d2966415fdd7e6cf6319708c8d48a980c2fR31 and implemented in this PR.