Skip to content

Commit

Permalink
Add sys txs to evm tests (#1255)
Browse files Browse the repository at this point in the history
* modify config_push_contracts

* modify call_multiple_test

* modify tests in call_tests.rs

* moving common functions to utils.rs

* minor fixes

* updated lock files

* modify tests

---------

Co-authored-by: Esad Yusuf Atik <[email protected]>
  • Loading branch information
exeokan and eyusufatik authored Oct 5, 2024
1 parent 07ec578 commit af745eb
Show file tree
Hide file tree
Showing 11 changed files with 932 additions and 518 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ revm = { workspace = true, features = ["optional_block_gas_limit", "optional_eip
sov-modules-api = { path = "../sovereign-sdk/module-system/sov-modules-api", features = ["macros"] }
sov-prover-storage-manager = { path = "../sovereign-sdk/full-node/sov-prover-storage-manager", features = ["test-utils"] }
sov-rollup-interface = { path = "../sovereign-sdk/rollup-interface", features = ["testing"] }
sov-stf-runner = { path = "../sovereign-sdk/full-node/sov-stf-runner" }
tempfile = { workspace = true }
tracing-subscriber = { workspace = true }
walkdir = "2.3.3"
Expand Down
702 changes: 488 additions & 214 deletions crates/evm/src/tests/call_tests.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crates/evm/src/tests/ef_tests/cases/blockchain_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::evm::DbAccount;
use crate::primitive_types::Block;
use crate::tests::ef_tests::models::{BlockchainTest, ForkSpec};
use crate::tests::ef_tests::{Case, Error, Suite};
use crate::tests::utils::{commit, get_evm_with_storage};
use crate::tests::utils::{commit, config_push_contracts, get_evm_with_storage};
use crate::{AccountData, Evm, EvmChainConfig, EvmConfig, RlpEvmTransaction, U256};

/// A handler for the blockchain test suite.
Expand Down Expand Up @@ -135,7 +135,7 @@ impl Case for BlockchainTestCase {
.par_bridge()
.try_for_each(|case| {
let mut evm_config = EvmConfig::default();

config_push_contracts(&mut evm_config, None);
// Set this base fee based on what's set in genesis.
let header = reth_primitives::Header {
parent_hash: case.genesis_block_header.parent_hash,
Expand Down
67 changes: 11 additions & 56 deletions crates/evm/src/tests/genesis_tests.rs
Original file line number Diff line number Diff line change
@@ -1,65 +1,19 @@
use std::collections::HashMap;

use alloy_eips::eip1559::BaseFeeParams;
use lazy_static::lazy_static;
use reth_primitives::constants::{EMPTY_RECEIPTS, EMPTY_TRANSACTIONS, ETHEREUM_BLOCK_GAS_LIMIT};
use reth_primitives::hex_literal::hex;
use reth_primitives::{
Address, Bloom, Bytes, Header, SealedHeader, B256, EMPTY_OMMER_ROOT_HASH, KECCAK_EMPTY, U256,
Address, Bloom, Bytes, Header, SealedHeader, B256, EMPTY_OMMER_ROOT_HASH, U256,
};
use revm::primitives::SpecId;
use sov_modules_api::prelude::*;

use crate::evm::primitive_types::SealedBlock;
use crate::evm::{AccountInfo, EvmChainConfig};
use crate::tests::utils::{get_evm, GENESIS_HASH, GENESIS_STATE_ROOT};
use crate::{AccountData, EvmConfig};
use crate::tests::utils::{get_evm, get_evm_test_config, GENESIS_HASH, GENESIS_STATE_ROOT};
use crate::EvmConfig;

lazy_static! {
pub(crate) static ref TEST_CONFIG: EvmConfig = EvmConfig {
data: vec![AccountData {
address: Address::from([1u8; 20]),
balance: U256::checked_mul(U256::from(1000), U256::pow(U256::from(10), U256::from(18))).unwrap(), // 1000 ETH
code_hash: KECCAK_EMPTY,
code: Bytes::default(),
nonce: 0,
storage: Default::default(),
},
AccountData {
address:Address::from([2u8; 20]),
balance: U256::checked_mul(U256::from(1000),
U256::pow(U256::from(10), U256::from(18))).unwrap(), // 1000 ETH,
code_hash: hex!("4e8ee9adb469b245e3a5a8e58e9b733aaa857a9dce1982257531db8a2700aabf").into(),
code: hex!("60606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063a223e05d1461006a578063").into(),
storage: {
let mut storage = HashMap::new();
storage.insert(U256::from(0), U256::from(0x4321));
storage.insert(
U256::from_be_slice(
&hex!("6661e9d6d8b923d5bbaab1b96e1dd51ff6ea2a93520fdc9eb75d059238b8c5e9")[..],
),
U256::from(8),
);

storage
},
nonce: 1
}],
spec: vec![(0, SpecId::BERLIN), (1, SpecId::SHANGHAI)]
.into_iter()
.collect(),
chain_id: 1000,
block_gas_limit: reth_primitives::constants::ETHEREUM_BLOCK_GAS_LIMIT,
coinbase: Address::from([3u8; 20]),
limit_contract_code_size: Some(5000),
starting_base_fee: 1000000000,
base_fee_params: BaseFeeParams::ethereum(),
timestamp: 0,
difficulty: U256::ZERO,
extra_data: Bytes::default(),
nonce: 0,
};

pub(crate) static ref GENESIS_DA_TXS_COMMITMENT: B256 = B256::from(hex!(
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
));
Expand All @@ -68,16 +22,17 @@ lazy_static! {

#[test]
fn genesis_data() {
let (evm, mut working_set) = get_evm(&TEST_CONFIG);
let config = get_evm_test_config();
let (evm, mut working_set) = get_evm(&config);

let account = &TEST_CONFIG.data[0];
let account = &config.data[0];

let db_account = evm
.accounts
.get(&account.address, &mut working_set)
.unwrap();

let contract = &TEST_CONFIG.data[1];
let contract = &config.data[1];

let contract_account = evm
.accounts
Expand Down Expand Up @@ -138,7 +93,7 @@ fn genesis_data() {

#[test]
fn genesis_cfg() {
let (evm, mut working_set) = get_evm(&TEST_CONFIG);
let (evm, mut working_set) = get_evm(&get_evm_test_config());

let cfg = evm.cfg.get(&mut working_set).unwrap();
assert_eq!(
Expand All @@ -165,7 +120,7 @@ fn genesis_cfg_missing_specs() {

#[test]
fn genesis_empty_spec_defaults_to_shanghai() {
let mut config = TEST_CONFIG.clone();
let mut config = get_evm_test_config();
config.spec.clear();
let (evm, mut working_set) = get_evm(&config);

Expand All @@ -184,7 +139,7 @@ fn genesis_cfg_cancun() {

#[test]
fn genesis_block() {
let (evm, mut working_set) = get_evm(&TEST_CONFIG);
let (evm, mut working_set) = get_evm(&get_evm_test_config());

let mut accessory_state = working_set.accessory_state();

Expand Down Expand Up @@ -238,7 +193,7 @@ fn genesis_block() {

#[test]
fn genesis_head() {
let (evm, mut working_set) = get_evm(&TEST_CONFIG);
let (evm, mut working_set) = get_evm(&get_evm_test_config());
let head = evm.head.get(&mut working_set).unwrap();

assert_eq!(head.header.parent_hash, *GENESIS_HASH);
Expand Down
80 changes: 47 additions & 33 deletions crates/evm/src/tests/hooks_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use sov_modules_api::hooks::HookSoftConfirmationInfo;
use sov_modules_api::{StateMapAccessor, StateValueAccessor, StateVecAccessor};
use sov_rollup_interface::spec::SpecId;

use super::genesis_tests::{GENESIS_DA_TXS_COMMITMENT, TEST_CONFIG};
use super::genesis_tests::GENESIS_DA_TXS_COMMITMENT;
use crate::evm::primitive_types::{
Block, BlockEnv, Receipt, SealedBlock, TransactionSignedAndRecovered,
};
use crate::tests::genesis_tests::BENEFICIARY;
use crate::tests::utils::{get_evm, GENESIS_STATE_ROOT};
use crate::tests::utils::{get_evm, get_evm_test_config, GENESIS_STATE_ROOT};
use crate::tests::DEFAULT_CHAIN_ID;
use crate::PendingTransaction;

Expand All @@ -24,7 +24,8 @@ lazy_static! {

#[test]
fn begin_soft_confirmation_hook_creates_pending_block() {
let (mut evm, mut working_set) = get_evm(&TEST_CONFIG);
let config = get_evm_test_config();
let (mut evm, mut working_set) = get_evm(&config);
let l1_fee_rate = 0;
let l2_height = 2;
let soft_confirmation_info = HookSoftConfirmationInfo {
Expand All @@ -48,15 +49,16 @@ fn begin_soft_confirmation_hook_creates_pending_block() {
coinbase: *BENEFICIARY,
timestamp: 54,
prevrandao: *DA_ROOT_HASH,
basefee: 765625000,
gas_limit: TEST_CONFIG.block_gas_limit,
basefee: 767816299,
gas_limit: config.block_gas_limit,
}
);
}

#[test]
fn end_soft_confirmation_hook_sets_head() {
let (mut evm, mut working_set) = get_evm(&TEST_CONFIG);
let config = get_evm_test_config();
let (mut evm, mut working_set) = get_evm(&get_evm_test_config());

let mut pre_state_root = [0u8; 32];
pre_state_root.copy_from_slice(GENESIS_STATE_ROOT.as_ref());
Expand Down Expand Up @@ -98,28 +100,28 @@ fn end_soft_confirmation_hook_sets_head() {
Block {
header: Header {
parent_hash: B256::from(hex!(
"3c83b326074b9430d4899991bbb06b8517315c50ca2cb17c11e1e972afce1b02"
"06c67dab6518e07a5df24039fd294e3f548026915ef1b8b6d597d421a18cc438"
)),

ommers_hash: EMPTY_OMMER_ROOT_HASH,
beneficiary: TEST_CONFIG.coinbase,
beneficiary: config.coinbase,
state_root: KECCAK_EMPTY,
transactions_root: B256::from(hex!(
"30eb5f6050df7ea18ca34cf3503f4713119315a2d3c11f892c5c8920acf816f4"
"fdf1049f7decef904ffdc7d55f8ca9c9c52ad655c8ddb7435025d86c97a253c0"
)),
receipts_root: B256::from(hex!(
"27036187b3f5e87d4306b396cf06c806da2cc9a0fef9b07c042e3b4304e01c64"
"e8271759b66c13c70ad0726ee34c9fd2574d429fd77d95f95b22f988565a1469"
)),
withdrawals_root: None,
logs_bloom: Bloom::default(),
logs_bloom: Bloom::new(hex!("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000040000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000")),
difficulty: U256::ZERO,
number: 2,
gas_limit: TEST_CONFIG.block_gas_limit,
gas_limit: config.block_gas_limit,
gas_used: 200u64,
timestamp: 54,
mix_hash: *DA_ROOT_HASH,
nonce: 0,
base_fee_per_gas: Some(765625000),
base_fee_per_gas: Some(767816299),
extra_data: Bytes::default(),
blob_gas_used: None,
excess_blob_gas: None,
Expand All @@ -128,14 +130,14 @@ fn end_soft_confirmation_hook_sets_head() {
},
l1_fee_rate: 0,
l1_hash: B256::from(DA_ROOT_HASH.0),
transactions: 0..2
transactions: 3..6
}
);
}

#[test]
fn end_soft_confirmation_hook_moves_transactions_and_receipts() {
let (mut evm, mut working_set) = get_evm(&TEST_CONFIG);
let (mut evm, mut working_set) = get_evm(&get_evm_test_config());
let l1_fee_rate = 0;
let l2_height = 2;

Expand Down Expand Up @@ -165,31 +167,42 @@ fn end_soft_confirmation_hook_moves_transactions_and_receipts() {
let tx2_hash = tx2.transaction.signed_transaction.hash;

assert_eq!(
evm.transactions
.iter(&mut working_set.accessory_state())
.collect::<Vec<_>>(),
[tx1.transaction, tx2.transaction]
evm.receipts
.get(4, &mut working_set.accessory_state())
.unwrap(),
tx1.receipt
);

assert_eq!(
evm.receipts
.iter(&mut working_set.accessory_state())
.collect::<Vec<_>>(),
[tx1.receipt, tx2.receipt]
.get(5, &mut working_set.accessory_state())
.unwrap(),
tx2.receipt
);
assert_eq!(
evm.transactions
.get(4, &mut working_set.accessory_state())
.unwrap(),
tx1.transaction
);
assert_eq!(
evm.transactions
.get(5, &mut working_set.accessory_state())
.unwrap(),
tx2.transaction
);

assert_eq!(
evm.transaction_hashes
.get(&tx1_hash, &mut working_set.accessory_state())
.unwrap(),
0
4
);

assert_eq!(
evm.transaction_hashes
.get(&tx2_hash, &mut working_set.accessory_state())
.unwrap(),
1
5
);

assert_eq!(evm.pending_transactions.len(), 0);
Expand Down Expand Up @@ -232,7 +245,8 @@ fn create_pending_transaction(hash: B256, index: u64) -> PendingTransaction {

#[test]
fn finalize_hook_creates_final_block() {
let (mut evm, mut working_set) = get_evm(&TEST_CONFIG);
let config = get_evm_test_config();
let (mut evm, mut working_set) = get_evm(&config);

// hack to get the root hash
let binding = evm
Expand Down Expand Up @@ -298,16 +312,16 @@ fn finalize_hook_creates_final_block() {
let header = Header {
parent_hash,
ommers_hash: EMPTY_OMMER_ROOT_HASH,
beneficiary: TEST_CONFIG.coinbase,
beneficiary: config.coinbase,
state_root: B256::from(root_hash),
transactions_root: B256::from(hex!(
"30eb5f6050df7ea18ca34cf3503f4713119315a2d3c11f892c5c8920acf816f4"
"fdf1049f7decef904ffdc7d55f8ca9c9c52ad655c8ddb7435025d86c97a253c0"
)),
receipts_root: B256::from(hex!(
"27036187b3f5e87d4306b396cf06c806da2cc9a0fef9b07c042e3b4304e01c64"
"e8271759b66c13c70ad0726ee34c9fd2574d429fd77d95f95b22f988565a1469"
)),
withdrawals_root: None,
logs_bloom: Bloom::default(),
logs_bloom: Bloom::new(hex!("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000040000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000")),
difficulty: U256::ZERO,
number: 2,
gas_limit: 30000000,
Expand All @@ -317,7 +331,7 @@ fn finalize_hook_creates_final_block() {
"0505050505050505050505050505050505050505050505050505050505050505"
)),
nonce: 0,
base_fee_per_gas: Some(765625000),
base_fee_per_gas: Some(767816299),
extra_data: Bytes::default(),
blob_gas_used: None,
excess_blob_gas: None,
Expand All @@ -330,7 +344,7 @@ fn finalize_hook_creates_final_block() {
header: header.seal_slow(),
l1_fee_rate: 0,
l1_hash: B256::from(DA_ROOT_HASH.0),
transactions: 0..2
transactions: 3..6
}
);

Expand All @@ -346,7 +360,7 @@ fn finalize_hook_creates_final_block() {

#[test]
fn begin_soft_confirmation_hook_appends_last_block_hashes() {
let (mut evm, mut working_set) = get_evm(&TEST_CONFIG);
let (mut evm, mut working_set) = get_evm(&get_evm_test_config());

// hack to get the root hash
let binding = evm
Expand Down
Loading

0 comments on commit af745eb

Please sign in to comment.