diff --git a/frame/ethereum/src/tests/eip1559.rs b/frame/ethereum/src/tests/eip1559.rs index 03edf8414b..073ceb79fd 100644 --- a/frame/ethereum/src/tests/eip1559.rs +++ b/frame/ethereum/src/tests/eip1559.rs @@ -19,7 +19,7 @@ use super::*; use evm::{ExitReason, ExitRevert, ExitSucceed}; -use fp_ethereum::ValidatedTransaction; +use fp_ethereum::{TransactionData, ValidatedTransaction}; use frame_support::{dispatch::DispatchClass, traits::Get, weights::Weight}; use pallet_evm::{AddressMapping, GasWeightMapping}; @@ -585,3 +585,39 @@ fn proof_size_weight_limit_validation_works() { ); }); } + +#[test] +fn proof_size_base_cost_should_keep_the_same_in_execution_and_estimate() { + let (pairs, mut ext) = new_test_ext(1); + let alice = &pairs[0]; + + ext.execute_with(|| { + let raw_tx = EIP1559UnsignedTransaction { + nonce: U256::zero(), + max_priority_fee_per_gas: U256::zero(), + max_fee_per_gas: U256::zero(), + gas_limit: U256::from(21_000), + action: ethereum::TransactionAction::Create, + value: U256::from(100), + input: vec![9; 100], + }; + + let tx_data: TransactionData = (&raw_tx.sign(&alice.private_key, Some(100))).into(); + let estimate_tx_data = TransactionData::new( + raw_tx.action, + raw_tx.input, + raw_tx.nonce, + raw_tx.gas_limit, + None, + Some(raw_tx.max_fee_per_gas), + Some(raw_tx.max_priority_fee_per_gas), + raw_tx.value, + Some(100), + vec![], + ); + assert_eq!( + estimate_tx_data.proof_size_base_cost(), + tx_data.proof_size_base_cost() + ); + }); +} diff --git a/frame/ethereum/src/tests/eip2930.rs b/frame/ethereum/src/tests/eip2930.rs index 772823a878..7eb800bda1 100644 --- a/frame/ethereum/src/tests/eip2930.rs +++ b/frame/ethereum/src/tests/eip2930.rs @@ -19,7 +19,7 @@ use super::*; use evm::{ExitReason, ExitRevert, ExitSucceed}; -use fp_ethereum::ValidatedTransaction; +use fp_ethereum::{TransactionData, ValidatedTransaction}; use frame_support::{ dispatch::{DispatchClass, GetDispatchInfo}, weights::Weight, @@ -511,3 +511,38 @@ fn proof_size_weight_limit_validation_works() { ); }); } + +#[test] +fn proof_size_base_cost_should_keep_the_same_in_execution_and_estimate() { + let (pairs, mut ext) = new_test_ext(1); + let alice = &pairs[0]; + + ext.execute_with(|| { + let raw_tx = EIP2930UnsignedTransaction { + nonce: U256::zero(), + gas_price: U256::zero(), + gas_limit: U256::from(21_000), + action: ethereum::TransactionAction::Create, + value: U256::from(100), + input: vec![9; 100], + }; + + let tx_data: TransactionData = (&raw_tx.sign(&alice.private_key, Some(100))).into(); + let estimate_tx_data = TransactionData::new( + raw_tx.action, + raw_tx.input, + raw_tx.nonce, + raw_tx.gas_limit, + Some(raw_tx.gas_price), + None, + None, + raw_tx.value, + Some(100), + vec![], + ); + assert_eq!( + estimate_tx_data.proof_size_base_cost(), + tx_data.proof_size_base_cost() + ); + }); +} diff --git a/frame/ethereum/src/tests/legacy.rs b/frame/ethereum/src/tests/legacy.rs index 48532a33b0..4b630e78d3 100644 --- a/frame/ethereum/src/tests/legacy.rs +++ b/frame/ethereum/src/tests/legacy.rs @@ -19,7 +19,7 @@ use super::*; use evm::{ExitReason, ExitRevert, ExitSucceed}; -use fp_ethereum::ValidatedTransaction; +use fp_ethereum::{TransactionData, ValidatedTransaction}; use frame_support::{ dispatch::{DispatchClass, GetDispatchInfo}, weights::Weight, @@ -511,3 +511,38 @@ fn proof_size_weight_limit_validation_works() { ); }); } + +#[test] +fn proof_size_base_cost_should_keep_the_same_in_execution_and_estimate() { + let (pairs, mut ext) = new_test_ext(1); + let alice = &pairs[0]; + + ext.execute_with(|| { + let raw_tx = LegacyUnsignedTransaction { + nonce: U256::zero(), + gas_price: U256::zero(), + gas_limit: U256::from(21_000), + action: ethereum::TransactionAction::Create, + value: U256::from(100), + input: vec![9; 100], + }; + + let tx_data: TransactionData = (&raw_tx.sign(&alice.private_key)).into(); + let estimate_tx_data = TransactionData::new( + raw_tx.action, + raw_tx.input, + raw_tx.nonce, + raw_tx.gas_limit, + Some(raw_tx.gas_price), + None, + None, + raw_tx.value, + Some(100), + vec![], + ); + assert_eq!( + estimate_tx_data.proof_size_base_cost(), + tx_data.proof_size_base_cost() + ); + }); +}