Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Dec 12, 2023
1 parent 99f8c40 commit 4424482
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 3 deletions.
38 changes: 37 additions & 1 deletion frame/ethereum/src/tests/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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()
);
});
}
37 changes: 36 additions & 1 deletion frame/ethereum/src/tests/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
);
});
}
37 changes: 36 additions & 1 deletion frame/ethereum/src/tests/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
);
});
}

0 comments on commit 4424482

Please sign in to comment.