-
Notifications
You must be signed in to change notification settings - Fork 7
Skip auto-funding for accounts that were explicitly dealt #496
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
Changes from 6 commits
fcdab85
18d5d77
f901f52
d903ea1
3816ee4
5db4a6f
5e32478
e70e733
d85147f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ use std::{ | |
| }; | ||
|
|
||
| use alloy_primitives::{Address, Bytes, map::foldhash::HashMap, ruint::aliases::U256}; | ||
| use foundry_cheatcodes::{Ecx, MockCallDataContext, MockCallReturnData}; | ||
| use foundry_cheatcodes::{DealRecord, Ecx, MockCallDataContext, MockCallReturnData}; | ||
| use foundry_evm::constants::CHEATCODE_ADDRESS; | ||
| use polkadot_sdk::{ | ||
| frame_system, | ||
|
|
@@ -60,12 +60,23 @@ impl MockHandlerImpl { | |
| state.mocked_functions = mock_inner.mocked_functions.clone(); | ||
| } | ||
|
|
||
| /// Funds pranked fuzz addresses with u128::MAX so they can make calls in pallet-revive. | ||
| /// Skips accounts that were explicitly dealt to via vm.deal() to preserve balance assertions. | ||
| /// | ||
| /// Note: This only affects accounts that have never been dealt to. Accounts created from | ||
| /// within a test contract (e.g., via `self` calls) are not skipped and will be funded if | ||
| /// their balance is 0. This is intentional - vm.deal() is an explicit user action that | ||
| /// should be respected, while internal contract creations should still get auto-funding. | ||
| pub(crate) fn fund_pranked_accounts(&self, account: Address) { | ||
| // Fuzzed prank addresses have no balance, so they won't exist in revive, and | ||
|
Collaborator
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. how does it work in REVM if prank addresses do not have any balance?
Author
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. It works, in REVM they don't need balance to execute |
||
| // calls will fail, this is not a problem when running in REVM. | ||
| // TODO: Figure it out why this is still needed. | ||
| let balance = Pallet::<Runtime>::evm_balance(&H160::from_slice(account.as_slice())); | ||
| if balance == 0.into() { | ||
| let mock_inner = self.inner.borrow(); | ||
|
|
||
| // Skip accounts that were explicitly dealt to via vm.deal() | ||
| if mock_inner.eth_deals.iter().any(|deal| deal.address == account) { | ||
| return; | ||
|
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. maybe we should check if the balance aligns between foundry's
Author
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. Also addressed, and we default to max if there is no deal |
||
| } | ||
|
|
||
| let pvm_balance = Pallet::<Runtime>::evm_balance(&H160::from_slice(account.as_slice())); | ||
| if pvm_balance == 0.into() { | ||
| Pallet::<Runtime>::set_evm_balance( | ||
| &H160::from_slice(account.as_slice()), | ||
| u128::MAX.into(), | ||
|
|
@@ -193,6 +204,8 @@ struct MockHandlerInner<T: frame_system::Config + pallet_revive::Config> { | |
|
|
||
| pub mocked_calls: HashMap<Address, BTreeMap<MockCallDataContext, VecDeque<MockCallReturnData>>>, | ||
| pub mocked_functions: HashMap<Address, HashMap<Bytes, Address>>, | ||
| /// Records of accounts that were explicitly dealt to via vm.deal(). | ||
| pub eth_deals: Vec<DealRecord>, | ||
|
||
| } | ||
|
|
||
| impl MockHandlerInner<Runtime> { | ||
|
|
@@ -222,6 +235,7 @@ impl MockHandlerInner<Runtime> { | |
| mocked_calls: state.mocked_calls.clone(), | ||
| callee: callee.map(|addr| H160::from_slice(addr.as_slice())).unwrap_or_default(), | ||
| mocked_functions: state.mocked_functions.clone(), | ||
| eth_deals: state.eth_deals.clone(), | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.