-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a57b755
add mock handlers
alexggh 9d13964
minor fixes
alexggh 2c25da9
make no_std build work
alexggh ec1c7c2
review feedback
alexggh 1c24619
pallet-revive: make a try_upload_pvm_code/code_hash public
alexggh 5ab45ad
use references
alexggh 42e82dd
address revivew feedback
alexggh b6d975c
Merge remote-tracking branch 'origin/master' into alexggh/inject_stat…
alexggh 5f4e784
add mock hooks tests
alexggh 98634c8
Merge remote-tracking branch 'origin/master' into alexggh/inject_stat…
alexggh 47418ca
make sure mock calls don't consume gas, storage, transfer value
alexggh 47f5cf8
remove unneeded empty
alexggh 4b2835f
Merge remote-tracking branch 'origin/master' into alexggh/inject_stat…
alexggh ebff833
Update from github-actions[bot] running command 'prdoc --audience nod…
github-actions[bot] 077ef11
Update pr_9909.prdoc
alexggh c63805e
address review feedback
alexggh fc05c46
make semver happy
alexggh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| title: 'pallet-revive: add interface to implement mocks and pranks' | ||
| doc: | ||
| - audience: Node Dev | ||
| description: |- | ||
| Needed for: https://github.com/paritytech/foundry-polkadot/pull/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. | ||
| crates: | ||
| - name: pallet-revive | ||
| bump: major |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alexggh marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ mod weightinfo_extension; | |
|
|
||
| pub mod evm; | ||
| pub mod migrations; | ||
| pub mod mock; | ||
| pub mod precompiles; | ||
| pub mod test_utils; | ||
| pub mod tracing; | ||
|
|
@@ -53,11 +54,11 @@ use crate::{ | |
| runtime::SetWeightLimit, | ||
| CallTracer, GenericTransaction, PrestateTracer, Trace, Tracer, TracerType, TYPE_EIP1559, | ||
| }, | ||
| exec::{AccountIdOf, ExecError, Executable, Stack as ExecStack}, | ||
| exec::{AccountIdOf, ExecError, Stack as ExecStack}, | ||
| gas::GasMeter, | ||
| storage::{meter::Meter as StorageMeter, AccountType, DeletionQueueManager}, | ||
| tracing::if_tracing, | ||
| vm::{pvm::extract_code_and_data, CodeInfo, ContractBlob, RuntimeCosts}, | ||
| vm::{pvm::extract_code_and_data, CodeInfo, RuntimeCosts}, | ||
| weightinfo_extension::OnFinalizeBlockParts, | ||
| }; | ||
| use alloc::{boxed::Box, format, vec}; | ||
|
|
@@ -95,9 +96,10 @@ pub use crate::{ | |
| }, | ||
| debug::DebugSettings, | ||
| evm::{block_hash::ReceiptGasInfo, Address as EthAddress, Block as EthBlock, ReceiptInfo}, | ||
| exec::{Key, MomentOf, Origin as ExecOrigin}, | ||
| exec::{DelegateInfo, Executable, Key, MomentOf, Origin as ExecOrigin}, | ||
| pallet::{genesis, *}, | ||
| storage::{AccountInfo, ContractInfo}, | ||
| vm::ContractBlob, | ||
| }; | ||
| pub use codec; | ||
| pub use frame_support::{self, dispatch::DispatchInfo, weights::Weight}; | ||
|
|
@@ -1483,7 +1485,7 @@ impl<T: Config> Pallet<T> { | |
| gas_limit: Weight, | ||
| storage_deposit_limit: BalanceOf<T>, | ||
| data: Vec<u8>, | ||
| exec_config: ExecConfig, | ||
| exec_config: ExecConfig<T>, | ||
| ) -> ContractResult<ExecReturnValue, BalanceOf<T>> { | ||
| if let Err(contract_result) = Self::ensure_non_contract_if_signed(&origin) { | ||
| return contract_result; | ||
|
|
@@ -1542,7 +1544,7 @@ impl<T: Config> Pallet<T> { | |
| code: Code, | ||
| data: Vec<u8>, | ||
| salt: Option<[u8; 32]>, | ||
| exec_config: ExecConfig, | ||
| exec_config: ExecConfig<T>, | ||
| ) -> ContractResult<InstantiateReturnValue, BalanceOf<T>> { | ||
| // Enforce EIP-3607 for top-level signed origins: deny signed contract addresses. | ||
| if let Err(contract_result) = Self::ensure_non_contract_if_signed(&origin) { | ||
|
|
@@ -2095,11 +2097,11 @@ impl<T: Config> Pallet<T> { | |
| } | ||
|
|
||
| /// Uploads new code and returns the Vm binary contract blob and deposit amount collected. | ||
| fn try_upload_pvm_code( | ||
| pub fn try_upload_pvm_code( | ||
| origin: T::AccountId, | ||
| code: Vec<u8>, | ||
| storage_deposit_limit: BalanceOf<T>, | ||
| exec_config: &ExecConfig, | ||
| exec_config: &ExecConfig<T>, | ||
| ) -> Result<(ContractBlob<T>, BalanceOf<T>), DispatchError> { | ||
| let mut module = ContractBlob::from_pvm_code(code, origin)?; | ||
| let deposit = module.store_code(exec_config, None)?; | ||
|
|
@@ -2127,7 +2129,7 @@ impl<T: Config> Pallet<T> { | |
| } | ||
|
|
||
| /// 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| T::FeeInfo::weight_to_fee(&weight, Combinator::Max).into() | ||
| } | ||
|
|
||
|
|
@@ -2214,7 +2216,7 @@ impl<T: Config> Pallet<T> { | |
| from: &T::AccountId, | ||
| to: &T::AccountId, | ||
| amount: BalanceOf<T>, | ||
| exec_config: &ExecConfig, | ||
| exec_config: &ExecConfig<T>, | ||
| ) -> DispatchResult { | ||
| use frame_support::traits::tokens::{Fortitude, Precision, Preservation}; | ||
| match (exec_config.collect_deposit_from_hold.is_some(), hold_reason) { | ||
|
|
@@ -2259,7 +2261,7 @@ impl<T: Config> Pallet<T> { | |
| from: &T::AccountId, | ||
| to: &T::AccountId, | ||
| amount: BalanceOf<T>, | ||
| exec_config: &ExecConfig, | ||
| exec_config: &ExecConfig<T>, | ||
| ) -> Result<BalanceOf<T>, DispatchError> { | ||
| use frame_support::traits::{ | ||
| tokens::{Fortitude, Precision, Preservation, Restriction}, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.