Skip to content

Commit

Permalink
Upgrade evm version and fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Aug 13, 2024
1 parent 9c26bdc commit 278a720
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 26 deletions.
14 changes: 5 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ derive_more = "0.99"
environmental = { version = "1.1.4", default-features = false }
ethereum = { version = "0.15.0", default-features = false }
ethereum-types = { version = "0.14.1", default-features = false }
evm = { version = "0.41.1", default-features = false }
evm = { git = "https://github.com/rust-ethereum/evm", branch = "v0.x", default-features = false }
futures = "0.3.30"
hash-db = { version = "0.16.0", default-features = false }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
Expand Down
2 changes: 1 addition & 1 deletion frame/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ pub fn new_text_ext_with_recorder(
) -> (Vec<AccountInfo>, sp_io::TestExternalities) {
let (accounts, ext) = new_test_ext_with_initial_balance(accounts_len, 10_000_000);

let root = ext.backend.root().clone();
let root = *ext.backend.root();
let db = ext.backend.into_storage();
let recorder: Recorder<Blake2Hasher> = Default::default();
let backend_with_reorder = TrieBackendBuilder::new(db, root)
Expand Down
28 changes: 14 additions & 14 deletions frame/evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub fn new_test_ext() -> TestExternalities {
pub fn new_text_ext_with_recorder() -> TestExternalities {
let text_ext = new_test_ext();

let root = text_ext.backend.root().clone();
let root = *text_ext.backend.root();
let db = text_ext.backend.into_storage();
let recorder: Recorder<Blake2Hasher> = Default::default();
let backend_with_reorder = TrieBackendBuilder::new(db, root)
Expand Down Expand Up @@ -695,24 +695,24 @@ fn metadata_empty_dont_code_gets_cached() {
// }
// }

const PROOF_TEST_BYTECODE: &'static str = "6080604052348015600e575f80fd5b506101438061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c8063d6d1ee1414610038578063eeb4e36714610054575b5f80fd5b610052600480360381019061004d91906100ba565b610072565b005b61005c61007b565b60405161006991906100f4565b60405180910390f35b805f8190555050565b5f8054905090565b5f80fd5b5f819050919050565b61009981610087565b81146100a3575f80fd5b50565b5f813590506100b481610090565b92915050565b5f602082840312156100cf576100ce610083565b5b5f6100dc848285016100a6565b91505092915050565b6100ee81610087565b82525050565b5f6020820190506101075f8301846100e5565b9291505056fea26469706673582212201114104d5a56d94d03255e0f9fa699d53db26e355fb37f735caa200d7ce5158e64736f6c634300081a0033";
const PROOF_TEST_BYTECODE: &str = "6080604052348015600e575f80fd5b506101438061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c8063d6d1ee1414610038578063eeb4e36714610054575b5f80fd5b610052600480360381019061004d91906100ba565b610072565b005b61005c61007b565b60405161006991906100f4565b60405180910390f35b805f8190555050565b5f8054905090565b5f80fd5b5f819050919050565b61009981610087565b81146100a3575f80fd5b50565b5f813590506100b481610090565b92915050565b5f602082840312156100cf576100ce610083565b5b5f6100dc848285016100a6565b91505092915050565b6100ee81610087565b82525050565b5f6020820190506101075f8301846100e5565b9291505056fea26469706673582212201114104d5a56d94d03255e0f9fa699d53db26e355fb37f735caa200d7ce5158e64736f6c634300081a0033";

#[test]
fn proof_size_create_contract() {
let proof_size =
|| -> Option<u64> { cumulus_primitives_storage_weight_reclaim::get_proof_size() };
|| -> u64 { cumulus_primitives_storage_weight_reclaim::get_proof_size().expect("ensure the proof size host function is enabled.") };

let mut test_ext_with_recorder = new_text_ext_with_recorder();
test_ext_with_recorder.execute_with(|| {
// The initial proof size should be 0
assert_eq!(proof_size(), Some(0));
assert_eq!(proof_size(), 0);
// Read the storage increases the proof size
EVM::account_basic(&H160::from_str("1000000000000000000000000000000000000002").unwrap());
assert_eq!(proof_size(), Some(583));
assert_eq!(proof_size(), 583);
AccountCodes::<Test>::get(
&H160::from_str("1000000000000000000000000000000000000001").unwrap(),
H160::from_str("1000000000000000000000000000000000000001").unwrap(),
);
assert_eq!(proof_size(), Some(799));
assert_eq!(proof_size(), 799);
});

test_ext_with_recorder.execute_with(|| {
Expand All @@ -734,15 +734,15 @@ fn proof_size_create_contract() {
)
.expect("create contract failed");
let contract_addr = res.value;
assert!(AccountCodes::<Test>::get(contract_addr).len() != 0);
assert_eq!(proof_size(), Some(1196));
assert!(!AccountCodes::<Test>::get(contract_addr).is_empty());
assert_eq!(proof_size(), 1196);
});
}

#[test]
fn proof_size_create_contract_with_low_proof_limit() {
let proof_size =
|| -> Option<u64> { cumulus_primitives_storage_weight_reclaim::get_proof_size() };
|| -> u64 { cumulus_primitives_storage_weight_reclaim::get_proof_size().expect("ensure the proof size host function is enabled.") };

let mut test_ext_with_recorder = new_text_ext_with_recorder();
test_ext_with_recorder.execute_with(|| {
Expand Down Expand Up @@ -770,7 +770,7 @@ fn proof_size_create_contract_with_low_proof_limit() {
#[test]
fn proof_size_reach_limit() {
let proof_size =
|| -> Option<u64> { cumulus_primitives_storage_weight_reclaim::get_proof_size() };
|| -> u64 { cumulus_primitives_storage_weight_reclaim::get_proof_size().expect("ensure the proof size host function is enabled.") };

let mut test_ext_with_recorder = new_text_ext_with_recorder();
// create contract run out of proof size
Expand All @@ -794,7 +794,7 @@ fn proof_size_reach_limit() {
.expect("create contract failed");
assert_eq!(res.exit_reason, ExitReason::Error(ExitError::OutOfGas));
let contract_addr = res.value;
assert!(AccountCodes::<Test>::get(contract_addr).len() == 0);
assert!(AccountCodes::<Test>::get(contract_addr).is_empty());
});

// call contract run out of proof size
Expand All @@ -817,7 +817,7 @@ fn proof_size_reach_limit() {
)
.expect("create contract failed");
let contract_addr = res.value;
assert!(AccountCodes::<Test>::get(contract_addr).len() != 0);
assert!(!AccountCodes::<Test>::get(contract_addr).is_empty());

// set_number(6)
let calldata = "d6d1ee140000000000000000000000000000000000000000000000000000000000000006";
Expand Down Expand Up @@ -866,7 +866,7 @@ fn proof_size_reach_limit() {
#[test]
fn proof_size_reach_limit_nonce_increase() {
let proof_size =
|| -> Option<u64> { cumulus_primitives_storage_weight_reclaim::get_proof_size() };
|| -> u64 { cumulus_primitives_storage_weight_reclaim::get_proof_size().expect("ensure the proof size host function is enabled.") };

let mut test_ext_with_recorder = new_text_ext_with_recorder();
test_ext_with_recorder.execute_with(|| {
Expand Down
2 changes: 1 addition & 1 deletion primitives/evm/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ mod tests {
transaction_pov: Some(TransactionPov::new(
Weight::from_parts(100, 100),
100,
Some(20),
20,
)),
is_transactional,
..Default::default()
Expand Down

0 comments on commit 278a720

Please sign in to comment.