diff --git a/frame/ethereum/src/lib.rs b/frame/ethereum/src/lib.rs index e667341c92..17ed534027 100644 --- a/frame/ethereum/src/lib.rs +++ b/frame/ethereum/src/lib.rs @@ -48,7 +48,9 @@ use frame_support::{ weights::Weight, }; use frame_system::{pallet_prelude::OriginFor, CheckWeight, WeightInfo}; -use pallet_evm::{BlockHashMapping, FeeCalculator, GasWeightMapping, Runner}; +use pallet_evm::{ + BlockHashMapping, FeeCalculator, GasWeightMapping, OnCheckEvmTransaction, Runner, +}; use sp_runtime::{ generic::DigestItem, traits::{DispatchInfoOf, Dispatchable, One, Saturating, UniqueSaturatedInto, Zero}, @@ -499,7 +501,8 @@ impl Pallet { let (base_fee, _) = T::FeeCalculator::min_gas_price(); let (who, _) = pallet_evm::Pallet::::account_basic(&origin); - let _ = CheckEvmTransaction::::new( + let mut v = CheckEvmTransaction::::new( + who.clone(), CheckEvmTransactionConfig { evm_config: T::config(), block_gas_limit: T::BlockGasLimit::get(), @@ -510,13 +513,19 @@ impl Pallet { transaction_data.clone().into(), weight_limit, proof_size_base_cost, + ); + + T::OnCheckEvmTransaction::::on_check_evm_transaction( + &mut v, &origin, ) - .validate_in_pool_for(&who) - .and_then(|v| v.with_chain_id()) - .and_then(|v| v.with_base_fee()) - .and_then(|v| v.with_balance_for(&who)) .map_err(|e| e.0)?; + v.validate_in_pool_for() + .and_then(|v| v.with_chain_id()) + .and_then(|v| v.with_base_fee()) + .and_then(|v| v.with_balance()) + .map_err(|e| e.0)?; + let priority = match ( transaction_data.gas_price, transaction_data.max_fee_per_gas, @@ -875,7 +884,8 @@ impl Pallet { _ => (None, None), }; - let _ = CheckEvmTransaction::::new( + let mut v = CheckEvmTransaction::::new( + who, CheckEvmTransactionConfig { evm_config: T::config(), block_gas_limit: T::BlockGasLimit::get(), @@ -886,13 +896,19 @@ impl Pallet { transaction_data.into(), weight_limit, proof_size_base_cost, + ); + + T::OnCheckEvmTransaction::::on_check_evm_transaction( + &mut v, &origin, ) - .validate_in_block_for(&who) - .and_then(|v| v.with_chain_id()) - .and_then(|v| v.with_base_fee()) - .and_then(|v| v.with_balance_for(&who)) .map_err(|e| TransactionValidityError::Invalid(e.0))?; + v.validate_in_block() + .and_then(|v| v.with_chain_id()) + .and_then(|v| v.with_base_fee()) + .and_then(|v| v.with_balance()) + .map_err(|e| TransactionValidityError::Invalid(e.0))?; + Ok(()) } diff --git a/frame/ethereum/src/mock.rs b/frame/ethereum/src/mock.rs index 9c22e2e347..483dc445d2 100644 --- a/frame/ethereum/src/mock.rs +++ b/frame/ethereum/src/mock.rs @@ -180,6 +180,7 @@ impl pallet_evm::Config for Test { type GasLimitPovSizeRatio = GasLimitPovSizeRatio; type Timestamp = Timestamp; type WeightInfo = (); + type OnCheckEvmTransaction> = (); } parameter_types! { diff --git a/frame/evm/precompile/dispatch/src/mock.rs b/frame/evm/precompile/dispatch/src/mock.rs index da22a34427..2d6face1d0 100644 --- a/frame/evm/precompile/dispatch/src/mock.rs +++ b/frame/evm/precompile/dispatch/src/mock.rs @@ -166,6 +166,7 @@ impl pallet_evm::Config for Test { type GasLimitPovSizeRatio = (); type Timestamp = Timestamp; type WeightInfo = (); + type OnCheckEvmTransaction> = (); } pub(crate) struct MockHandle { diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index fb3a0388f8..0d906e6ad0 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -95,10 +95,10 @@ use sp_std::{cmp::min, collections::btree_map::BTreeMap, vec::Vec}; use fp_account::AccountId20; use fp_evm::GenesisAccount; pub use fp_evm::{ - Account, CallInfo, CreateInfo, ExecutionInfoV2 as ExecutionInfo, FeeCalculator, - InvalidEvmTransactionError, IsPrecompileResult, LinearCostPrecompile, Log, Precompile, - PrecompileFailure, PrecompileHandle, PrecompileOutput, PrecompileResult, PrecompileSet, - Vicinity, + Account, CallInfo, CheckEvmTransaction, CreateInfo, ExecutionInfoV2 as ExecutionInfo, + FeeCalculator, InvalidEvmTransactionError, IsPrecompileResult, LinearCostPrecompile, Log, + Precompile, PrecompileFailure, PrecompileHandle, PrecompileOutput, PrecompileResult, + PrecompileSet, Vicinity, }; pub use self::{ @@ -177,6 +177,12 @@ pub mod pallet { fn config() -> &'static EvmConfig { &SHANGHAI_CONFIG } + + // Called when transaction info for validation is created + type OnCheckEvmTransaction>: OnCheckEvmTransaction< + Self, + E, + >; } #[pallet::call] @@ -565,7 +571,7 @@ pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; /// Type alias for negative imbalance during fees -type NegativeImbalanceOf = +pub type NegativeImbalanceOf = ::AccountId>>::NegativeImbalance; #[derive( @@ -1047,3 +1053,13 @@ impl OnCreate for Tuple { )*) } } + +pub trait OnCheckEvmTransaction> { + fn on_check_evm_transaction(v: &mut CheckEvmTransaction, origin: &H160) -> Result<(), E>; +} + +impl> OnCheckEvmTransaction for () { + fn on_check_evm_transaction(_v: &mut CheckEvmTransaction, _origin: &H160) -> Result<(), E> { + Ok(()) + } +} diff --git a/frame/evm/src/mock.rs b/frame/evm/src/mock.rs index c1e48f1f99..19809e0ce8 100644 --- a/frame/evm/src/mock.rs +++ b/frame/evm/src/mock.rs @@ -32,7 +32,8 @@ use sp_std::{boxed::Box, prelude::*, str::FromStr}; use crate::{ EnsureAddressNever, EnsureAddressRoot, FeeCalculator, IdentityAddressMapping, - IsPrecompileResult, Precompile, PrecompileHandle, PrecompileResult, PrecompileSet, + InvalidEvmTransactionError, IsPrecompileResult, Precompile, PrecompileHandle, PrecompileResult, + PrecompileSet, }; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; @@ -162,6 +163,7 @@ impl crate::Config for Test { type GasLimitPovSizeRatio = GasLimitPovSizeRatio; type Timestamp = Timestamp; type WeightInfo = (); + type OnCheckEvmTransaction> = (); } /// Example PrecompileSet with only Identity precompile. diff --git a/frame/evm/src/runner/stack.rs b/frame/evm/src/runner/stack.rs index 071b569732..477ae72776 100644 --- a/frame/evm/src/runner/stack.rs +++ b/frame/evm/src/runner/stack.rs @@ -17,6 +17,11 @@ //! EVM stack-based runner. +use crate::{ + runner::Runner as RunnerT, AccountCodes, AccountCodesMetadata, AccountStorages, AddressMapping, + BalanceOf, BlockHashMapping, Config, Error, Event, FeeCalculator, OnChargeEVMTransaction, + OnCheckEvmTransaction, OnCreate, Pallet, RunnerError, +}; use evm::{ backend::Backend as BackendT, executor::stack::{Accessed, StackExecutor, StackState as StackStateT, StackSubstateMetadata}, @@ -47,12 +52,6 @@ use fp_evm::{ ACCOUNT_STORAGE_PROOF_SIZE, IS_EMPTY_CHECK_PROOF_SIZE, WRITE_PROOF_SIZE, }; -use crate::{ - runner::Runner as RunnerT, AccountCodes, AccountCodesMetadata, AccountStorages, AddressMapping, - BalanceOf, BlockHashMapping, Config, Error, Event, FeeCalculator, OnChargeEVMTransaction, - OnCreate, Pallet, RunnerError, -}; - #[cfg(feature = "forbid-evm-reentrancy")] environmental::thread_local_impl!(static IN_EVM: environmental::RefCell = environmental::RefCell::new(false)); @@ -371,8 +370,10 @@ where let (base_fee, mut weight) = T::FeeCalculator::min_gas_price(); let (source_account, inner_weight) = Pallet::::account_basic(&source); weight = weight.saturating_add(inner_weight); + let nonce = nonce.unwrap_or(source_account.nonce); - let _ = fp_evm::CheckEvmTransaction::::new( + let mut v = fp_evm::CheckEvmTransaction::::new( + source_account, fp_evm::CheckEvmTransactionConfig { evm_config, block_gas_limit: T::BlockGasLimit::get(), @@ -384,7 +385,7 @@ where chain_id: Some(T::ChainId::get()), to: target, input, - nonce: nonce.unwrap_or(source_account.nonce), + nonce, gas_limit: gas_limit.into(), gas_price: None, max_fee_per_gas, @@ -394,11 +395,15 @@ where }, weight_limit, proof_size_base_cost, - ) - .validate_in_block_for(&source_account) - .and_then(|v| v.with_base_fee()) - .and_then(|v| v.with_balance_for(&source_account)) - .map_err(|error| RunnerError { error, weight })?; + ); + + T::OnCheckEvmTransaction::>::on_check_evm_transaction(&mut v, &source) + .map_err(|error| RunnerError { error, weight })?; + + v.validate_in_block() + .and_then(|v| v.with_base_fee()) + .and_then(|v| v.with_balance()) + .map_err(|error| RunnerError { error, weight })?; Ok(()) } diff --git a/primitives/evm/src/validation.rs b/primitives/evm/src/validation.rs index a9ea6963d1..6add6a29ec 100644 --- a/primitives/evm/src/validation.rs +++ b/primitives/evm/src/validation.rs @@ -46,6 +46,7 @@ pub struct CheckEvmTransactionConfig<'config> { #[derive(Debug)] pub struct CheckEvmTransaction<'config, E: From> { + pub who: Account, pub config: CheckEvmTransactionConfig<'config>, pub transaction: CheckEvmTransactionInput, pub weight_limit: Option, @@ -68,12 +69,14 @@ pub enum InvalidEvmTransactionError { impl<'config, E: From> CheckEvmTransaction<'config, E> { pub fn new( + who: Account, config: CheckEvmTransactionConfig<'config>, transaction: CheckEvmTransactionInput, weight_limit: Option, proof_size_base_cost: Option, ) -> Self { CheckEvmTransaction { + who, config, transaction, weight_limit, @@ -82,17 +85,17 @@ impl<'config, E: From> CheckEvmTransaction<'config, } } - pub fn validate_in_pool_for(&self, who: &Account) -> Result<&Self, E> { - if self.transaction.nonce < who.nonce { + pub fn validate_in_pool_for(&self) -> Result<&Self, E> { + if self.transaction.nonce < self.who.nonce { return Err(InvalidEvmTransactionError::TxNonceTooLow.into()); } self.validate_common() } - pub fn validate_in_block_for(&self, who: &Account) -> Result<&Self, E> { - if self.transaction.nonce > who.nonce { + pub fn validate_in_block(&self) -> Result<&Self, E> { + if self.transaction.nonce > self.who.nonce { return Err(InvalidEvmTransactionError::TxNonceTooHigh.into()); - } else if self.transaction.nonce < who.nonce { + } else if self.transaction.nonce < self.who.nonce { return Err(InvalidEvmTransactionError::TxNonceTooLow.into()); } self.validate_common() @@ -120,7 +123,7 @@ impl<'config, E: From> CheckEvmTransaction<'config, Ok(self) } - pub fn with_balance_for(&self, who: &Account) -> Result<&Self, E> { + pub fn with_balance(&self) -> Result<&Self, E> { // Get fee data from either a legacy or typed transaction input. let (max_fee_per_gas, _) = self.transaction_fee_input()?; @@ -136,7 +139,7 @@ impl<'config, E: From> CheckEvmTransaction<'config, let fee = max_fee_per_gas.saturating_mul(self.transaction.gas_limit); if self.config.is_transactional || fee > U256::zero() { let total_payment = self.transaction.value.saturating_add(fee); - if who.balance < total_payment { + if self.who.balance < total_payment { return Err(InvalidEvmTransactionError::BalanceTooLow.into()); } } @@ -146,7 +149,7 @@ impl<'config, E: From> CheckEvmTransaction<'config, // Returns the max_fee_per_gas (or gas_price for legacy txns) as well as an optional // effective_gas_price for EIP-1559 transactions. effective_gas_price represents // the total (fee + tip) that would be paid given the current base_fee. - fn transaction_fee_input(&self) -> Result<(U256, Option), E> { + pub fn transaction_fee_input(&self) -> Result<(U256, Option), E> { match ( self.transaction.gas_price, self.transaction.max_fee_per_gas, @@ -298,7 +301,7 @@ mod tests { } } - fn test_env<'config>(input: TestCase) -> CheckEvmTransaction<'config, TestError> { + fn test_env<'config>(who: Account, input: TestCase) -> CheckEvmTransaction<'config, TestError> { let TestCase { blockchain_gas_limit, blockchain_base_fee, @@ -315,6 +318,7 @@ mod tests { proof_size_base_cost, } = input; CheckEvmTransaction::::new( + who, CheckEvmTransactionConfig { evm_config: &SHANGHAI_CONFIG, block_gas_limit: blockchain_gas_limit, @@ -341,97 +345,111 @@ mod tests { // Transaction settings fn default_transaction<'config>( + who: Account, is_transactional: bool, ) -> CheckEvmTransaction<'config, TestError> { let mut input = TestCase::default(); input.is_transactional = is_transactional; - test_env(input) + test_env(who, input) } fn transaction_gas_limit_low<'config>( + who: Account, is_transactional: bool, ) -> CheckEvmTransaction<'config, TestError> { let mut input = TestCase::default(); input.gas_limit = U256::from(1u8); input.is_transactional = is_transactional; - test_env(input) + test_env(who, input) } fn transaction_gas_limit_low_proof_size<'config>( + who: Account, is_transactional: bool, ) -> CheckEvmTransaction<'config, TestError> { let mut input = TestCase::default(); input.weight_limit = Some(Weight::from_parts(1, 1)); input.proof_size_base_cost = Some(2); input.is_transactional = is_transactional; - test_env(input) + test_env(who, input) } - fn transaction_gas_limit_high<'config>() -> CheckEvmTransaction<'config, TestError> { + fn transaction_gas_limit_high<'config>( + who: Account, + ) -> CheckEvmTransaction<'config, TestError> { let mut input = TestCase::default(); input.blockchain_gas_limit = U256::from(1u8); - test_env(input) + test_env(who, input) } - fn transaction_nonce_high<'config>() -> CheckEvmTransaction<'config, TestError> { + fn transaction_nonce_high<'config>(who: Account) -> CheckEvmTransaction<'config, TestError> { let mut input = TestCase::default(); input.nonce = U256::from(10u8); - test_env(input) + test_env(who, input) } - fn transaction_invalid_chain_id<'config>() -> CheckEvmTransaction<'config, TestError> { + fn transaction_invalid_chain_id<'config>( + who: Account, + ) -> CheckEvmTransaction<'config, TestError> { let mut input = TestCase::default(); input.chain_id = Some(555u64); - test_env(input) + test_env(who, input) } fn transaction_none_fee<'config>( + who: Account, is_transactional: bool, ) -> CheckEvmTransaction<'config, TestError> { let mut input = TestCase::default(); input.max_fee_per_gas = None; input.max_priority_fee_per_gas = None; input.is_transactional = is_transactional; - test_env(input) + test_env(who, input) } fn transaction_max_fee_low<'config>( is_transactional: bool, ) -> CheckEvmTransaction<'config, TestError> { + let who = Account::default(); let mut input = TestCase::default(); input.max_fee_per_gas = Some(U256::from(1u8)); input.max_priority_fee_per_gas = None; input.is_transactional = is_transactional; - test_env(input) + test_env(who, input) } fn transaction_priority_fee_high<'config>( is_transactional: bool, ) -> CheckEvmTransaction<'config, TestError> { + let who = Account::default(); let mut input = TestCase::default(); input.max_priority_fee_per_gas = Some(U256::from(1_100_000_000)); input.is_transactional = is_transactional; - test_env(input) + test_env(who, input) } - fn transaction_max_fee_high<'config>(tip: bool) -> CheckEvmTransaction<'config, TestError> { + fn transaction_max_fee_high<'config>( + who: Account, + tip: bool, + ) -> CheckEvmTransaction<'config, TestError> { let mut input = TestCase::default(); input.max_fee_per_gas = Some(U256::from(5_000_000_000u128)); if !tip { input.max_priority_fee_per_gas = None; } - test_env(input) + test_env(who, input) } - fn legacy_transaction<'config>() -> CheckEvmTransaction<'config, TestError> { + fn legacy_transaction<'config>(who: Account) -> CheckEvmTransaction<'config, TestError> { let mut input = TestCase::default(); input.gas_price = Some(U256::from(1_000_000_000u128)); input.max_fee_per_gas = None; input.max_priority_fee_per_gas = None; - test_env(input) + test_env(who, input) } fn invalid_transaction_mixed_fees<'config>( + who: Account, is_transactional: bool, ) -> CheckEvmTransaction<'config, TestError> { let mut input = TestCase::default(); @@ -439,7 +457,7 @@ mod tests { input.gas_price = Some(U256::from(1_000_000_000u128)); input.max_priority_fee_per_gas = None; input.is_transactional = is_transactional; - test_env(input) + test_env(who, input) } // Tests @@ -450,11 +468,11 @@ mod tests { balance: U256::from(1_000_000u128), nonce: U256::zero(), }; - let test = default_transaction(true); + let test = default_transaction(who, true); // Pool - assert!(test.validate_in_pool_for(&who).is_ok()); + assert!(test.validate_in_pool_for().is_ok()); // Block - assert!(test.validate_in_block_for(&who).is_ok()); + assert!(test.validate_in_block().is_ok()); } #[test] @@ -464,13 +482,13 @@ mod tests { balance: U256::from(1_000_000u128), nonce: U256::from(1u8), }; - let test = default_transaction(true); + let test = default_transaction(who, true); // Pool - let res = test.validate_in_pool_for(&who); + let res = test.validate_in_pool_for(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::TxNonceTooLow); // Block - let res = test.validate_in_block_for(&who); + let res = test.validate_in_block(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::TxNonceTooLow); } @@ -482,8 +500,8 @@ mod tests { balance: U256::from(1_000_000u128), nonce: U256::from(1u8), }; - let test = transaction_nonce_high(); - let res = test.validate_in_pool_for(&who); + let test = transaction_nonce_high(who); + let res = test.validate_in_pool_for(); assert!(res.is_ok()); } @@ -494,8 +512,8 @@ mod tests { balance: U256::from(1_000_000u128), nonce: U256::from(1u8), }; - let test = transaction_nonce_high(); - let res = test.validate_in_block_for(&who); + let test = transaction_nonce_high(who); + let res = test.validate_in_block(); assert!(res.is_err()); } @@ -507,13 +525,13 @@ mod tests { nonce: U256::zero(), }; let is_transactional = true; - let test = transaction_gas_limit_low(is_transactional); + let test = transaction_gas_limit_low(who, is_transactional); // Pool - let res = test.validate_in_pool_for(&who); + let res = test.validate_in_pool_for(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::GasLimitTooLow); // Block - let res = test.validate_in_block_for(&who); + let res = test.validate_in_block(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::GasLimitTooLow); } @@ -526,12 +544,12 @@ mod tests { nonce: U256::zero(), }; let is_transactional = false; - let test = transaction_gas_limit_low(is_transactional); + let test = transaction_gas_limit_low(who, is_transactional); // Pool - let res = test.validate_in_pool_for(&who); + let res = test.validate_in_pool_for(); assert!(res.is_ok()); // Block - let res = test.validate_in_block_for(&who); + let res = test.validate_in_block(); assert!(res.is_ok()); } @@ -543,13 +561,13 @@ mod tests { nonce: U256::zero(), }; let is_transactional = true; - let test = transaction_gas_limit_low_proof_size(is_transactional); + let test = transaction_gas_limit_low_proof_size(who, is_transactional); // Pool - let res = test.validate_in_pool_for(&who); + let res = test.validate_in_pool_for(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::GasLimitTooLow); // Block - let res = test.validate_in_block_for(&who); + let res = test.validate_in_block(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::GasLimitTooLow); } @@ -562,12 +580,12 @@ mod tests { nonce: U256::zero(), }; let is_transactional = false; - let test = transaction_gas_limit_low_proof_size(is_transactional); + let test = transaction_gas_limit_low_proof_size(who, is_transactional); // Pool - let res = test.validate_in_pool_for(&who); + let res = test.validate_in_pool_for(); assert!(res.is_ok()); // Block - let res = test.validate_in_block_for(&who); + let res = test.validate_in_block(); assert!(res.is_ok()); } @@ -578,13 +596,13 @@ mod tests { balance: U256::from(1_000_000u128), nonce: U256::zero(), }; - let test = transaction_gas_limit_high(); + let test = transaction_gas_limit_high(who); // Pool - let res = test.validate_in_pool_for(&who); + let res = test.validate_in_pool_for(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::GasLimitTooHigh); // Block - let res = test.validate_in_block_for(&who); + let res = test.validate_in_block(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::GasLimitTooHigh); } @@ -592,7 +610,8 @@ mod tests { #[test] // Valid chain id succeeds. fn validate_chain_id_succeeds() { - let test = default_transaction(true); + let who = Account::default(); + let test = default_transaction(who, true); let res = test.with_chain_id(); assert!(res.is_ok()); } @@ -600,7 +619,8 @@ mod tests { #[test] // Invalid chain id fails. fn validate_chain_id_fails() { - let test = transaction_invalid_chain_id(); + let who = Account::default(); + let test = transaction_invalid_chain_id(who); let res = test.with_chain_id(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::InvalidChainId); @@ -609,12 +629,13 @@ mod tests { #[test] // Valid max fee per gas succeeds. fn validate_base_fee_succeeds() { + let who = Account::default(); // Transactional - let test = default_transaction(true); + let test = default_transaction(who.clone(), true); let res = test.with_base_fee(); assert!(res.is_ok()); // Non-transactional - let test = default_transaction(false); + let test = default_transaction(who, false); let res = test.with_base_fee(); assert!(res.is_ok()); } @@ -622,7 +643,8 @@ mod tests { #[test] // Transactional call with unset fee data fails. fn validate_base_fee_with_none_fee_fails() { - let test = transaction_none_fee(true); + let who = Account::default(); + let test = transaction_none_fee(who, true); let res = test.with_base_fee(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::InvalidPaymentInput); @@ -631,7 +653,8 @@ mod tests { #[test] // Non-transactional call with unset fee data succeeds. fn validate_base_fee_with_none_fee_non_transactional_succeeds() { - let test = transaction_none_fee(false); + let who = Account::default(); + let test = transaction_none_fee(who, false); let res = test.with_base_fee(); assert!(res.is_ok()); } @@ -674,12 +697,12 @@ mod tests { nonce: U256::zero(), }; // Transactional - let test = default_transaction(true); - let res = test.with_balance_for(&who); + let test = default_transaction(who.clone(), true); + let res = test.with_balance(); assert!(res.is_ok()); // Non-transactional - let test = default_transaction(false); - let res = test.with_balance_for(&who); + let test = default_transaction(who, false); + let res = test.with_balance(); assert!(res.is_ok()); } @@ -691,13 +714,13 @@ mod tests { nonce: U256::zero(), }; // Transactional - let test = default_transaction(true); - let res = test.with_balance_for(&who); + let test = default_transaction(who.clone(), true); + let res = test.with_balance(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::BalanceTooLow); // Non-transactional - let test = default_transaction(false); - let res = test.with_balance_for(&who); + let test = default_transaction(who, false); + let res = test.with_balance(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::BalanceTooLow); } @@ -709,8 +732,8 @@ mod tests { balance: U256::from(21_000_000_000_001u128), nonce: U256::zero(), }; - let test = transaction_none_fee(true); - let res = test.with_balance_for(&who); + let test = transaction_none_fee(who, true); + let res = test.with_balance(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::InvalidPaymentInput); } @@ -722,8 +745,8 @@ mod tests { balance: U256::from(0u8), nonce: U256::zero(), }; - let test = transaction_none_fee(false); - let res = test.with_balance_for(&who); + let test = transaction_none_fee(who, false); + let res = test.with_balance(); assert!(res.is_ok()); } @@ -736,8 +759,8 @@ mod tests { nonce: U256::zero(), }; let with_tip = false; - let test = transaction_max_fee_high(with_tip); - let res = test.with_balance_for(&who); + let test = transaction_max_fee_high(who, with_tip); + let res = test.with_balance(); assert!(res.is_err()); } @@ -750,8 +773,8 @@ mod tests { nonce: U256::zero(), }; let with_tip = true; - let test = transaction_max_fee_high(with_tip); - let res = test.with_balance_for(&who); + let test = transaction_max_fee_high(who, with_tip); + let res = test.with_balance(); assert!(res.is_err()); } @@ -762,8 +785,8 @@ mod tests { balance: U256::from(21_000_000_000_001u128), nonce: U256::zero(), }; - let test = legacy_transaction(); - let res = test.with_balance_for(&who); + let test = legacy_transaction(who); + let res = test.with_balance(); assert!(res.is_ok()); } @@ -774,8 +797,8 @@ mod tests { balance: U256::from(21_000_000_000_000u128), nonce: U256::zero(), }; - let test = legacy_transaction(); - let res = test.with_balance_for(&who); + let test = legacy_transaction(who); + let res = test.with_balance(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::BalanceTooLow); } @@ -789,14 +812,14 @@ mod tests { }; // Fails for transactional. let is_transactional = true; - let test = invalid_transaction_mixed_fees(is_transactional); - let res = test.with_balance_for(&who); + let test = invalid_transaction_mixed_fees(who.clone(), is_transactional); + let res = test.with_balance(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::InvalidPaymentInput); // Succeeds for non-transactional. let is_transactional = false; - let test = invalid_transaction_mixed_fees(is_transactional); - let res = test.with_balance_for(&who); + let test = invalid_transaction_mixed_fees(who, is_transactional); + let res = test.with_balance(); assert!(res.is_ok()); } @@ -805,13 +828,14 @@ mod tests { fn validate_base_fee_with_invalid_fee_input() { // Fails for transactional. let is_transactional = true; - let test = invalid_transaction_mixed_fees(is_transactional); + let who = Account::default(); + let test = invalid_transaction_mixed_fees(who.clone(), is_transactional); let res = test.with_base_fee(); assert!(res.is_err()); assert_eq!(res.unwrap_err(), TestError::InvalidPaymentInput); // Succeeds for non-transactional. let is_transactional = false; - let test = invalid_transaction_mixed_fees(is_transactional); + let test = invalid_transaction_mixed_fees(who, is_transactional); let res = test.with_base_fee(); assert!(res.is_ok()); } diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index 8b8f436ad0..6b604b4e17 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -344,6 +344,7 @@ impl pallet_evm::Config for Runtime { type GasLimitPovSizeRatio = GasLimitPovSizeRatio; type Timestamp = Timestamp; type WeightInfo = pallet_evm::weights::SubstrateWeight; + type OnCheckEvmTransaction> = (); } parameter_types! {