Skip to content

Commit

Permalink
test: set eip2935 contract code for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
onbjerg committed Aug 26, 2024
1 parent 6bcb9f0 commit 596bc48
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ where
mod tests {
use super::*;
use alloy_eips::{
eip2935::HISTORY_STORAGE_ADDRESS,
eip2935::{HISTORY_STORAGE_ADDRESS, HISTORY_STORAGE_CODE},
eip4788::{BEACON_ROOTS_ADDRESS, BEACON_ROOTS_CODE, SYSTEM_ADDRESS},
eip7002::{WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS, WITHDRAWAL_REQUEST_PREDEPLOY_CODE},
};
Expand All @@ -479,7 +479,9 @@ mod tests {
database::StateProviderDatabase, test_utils::StateProviderTest, TransitionState,
};
use reth_testing_utils::generators::{self, sign_tx_with_key_pair};
use revm_primitives::{b256, fixed_bytes, Bytes, BLOCKHASH_SERVE_WINDOW};
use revm_primitives::{
b256, fixed_bytes, Bytes, BLOCKHASH_SERVE_WINDOW, BLOCKHASH_STORAGE_ADDRESS,
};
use secp256k1::{Keypair, Secp256k1};
use std::collections::HashMap;

Expand Down Expand Up @@ -867,11 +869,26 @@ mod tests {
assert_eq!(parent_beacon_block_root_storage, U256::from(0x69));
}

/// Create a state provider with blockhashes and the EIP-2935 system contract.
fn create_state_provider_with_block_hashes(latest_block: u64) -> StateProviderTest {
let mut db = StateProviderTest::default();
for block_number in 0..=latest_block {
db.insert_block_hash(block_number, keccak256(block_number.to_string()));
}

let blockhashes_contract_account = Account {
balance: U256::ZERO,
bytecode_hash: Some(keccak256(HISTORY_STORAGE_CODE.clone())),
nonce: 1,
};

db.insert_account(
HISTORY_STORAGE_ADDRESS,
blockhashes_contract_account,
Some(HISTORY_STORAGE_CODE.clone()),
HashMap::new(),
);

db
}

Expand Down Expand Up @@ -917,9 +934,9 @@ mod tests {
// ensure that the block hash was *not* written to storage, since this is before the fork
// was activated
//
// we load the account first, which should also not exist, because revm expects it to be
// we load the account first, because revm expects it to be
// loaded
assert!(executor.state_mut().basic(HISTORY_STORAGE_ADDRESS).unwrap().is_none());
executor.state_mut().basic(HISTORY_STORAGE_ADDRESS).unwrap();
assert!(executor
.state_mut()
.storage(HISTORY_STORAGE_ADDRESS, U256::ZERO)
Expand Down Expand Up @@ -967,9 +984,9 @@ mod tests {
// ensure that the block hash was *not* written to storage, since there are no blocks
// preceding genesis
//
// we load the account first, which should also not exist, because revm expects it to be
// we load the account first, because revm expects it to be
// loaded
assert!(executor.state_mut().basic(HISTORY_STORAGE_ADDRESS).unwrap().is_none());
executor.state_mut().basic(HISTORY_STORAGE_ADDRESS).unwrap();
assert!(executor
.state_mut()
.storage(HISTORY_STORAGE_ADDRESS, U256::ZERO)
Expand Down Expand Up @@ -1139,7 +1156,10 @@ mod tests {
);

// nothing should be written as the genesis has no ancestors
assert!(executor.state_mut().basic(HISTORY_STORAGE_ADDRESS).unwrap().is_none());
//
// we load the account first, because revm expects it to be
// loaded
executor.state_mut().basic(HISTORY_STORAGE_ADDRESS).unwrap();
assert!(executor
.state_mut()
.storage(HISTORY_STORAGE_ADDRESS, U256::ZERO)
Expand Down

0 comments on commit 596bc48

Please sign in to comment.