Skip to content

Commit

Permalink
Create a fresh working set
Browse files Browse the repository at this point in the history
  • Loading branch information
rakanalh committed Oct 9, 2024
1 parent 4a2d871 commit 6646fba
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
16 changes: 8 additions & 8 deletions crates/evm/src/tests/queries/basic_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::tests::queries::init_evm;
#[test]
fn get_block_by_hash_test() {
// make a block
let (evm, mut working_set, _, _) = init_evm();
let (evm, mut working_set, _, _, _) = init_evm();

let result = evm.get_block_by_hash([5u8; 32].into(), Some(false), &mut working_set);

Expand All @@ -34,7 +34,7 @@ fn get_block_by_hash_test() {
#[test]
fn get_block_by_number_test() {
// make a block
let (evm, mut working_set, _, _) = init_evm();
let (evm, mut working_set, _, _, _) = init_evm();

let result = evm.get_block_by_number(
Some(BlockNumberOrTag::Number(1000)),
Expand All @@ -60,7 +60,7 @@ fn get_block_by_number_test() {
#[test]
fn get_block_receipts_test() {
// make a block
let (evm, mut working_set, _, _) = init_evm();
let (evm, mut working_set, _, _, _) = init_evm();

let result = evm.get_block_receipts(
BlockId::Number(BlockNumberOrTag::Number(1000)),
Expand Down Expand Up @@ -91,7 +91,7 @@ fn get_block_receipts_test() {

#[test]
fn get_transaction_by_block_hash_and_index_test() {
let (evm, mut working_set, _, _) = init_evm();
let (evm, mut working_set, _, _, _) = init_evm();

let result = evm.get_transaction_by_block_hash_and_index(
[0u8; 32].into(),
Expand Down Expand Up @@ -136,7 +136,7 @@ fn get_transaction_by_block_hash_and_index_test() {

#[test]
fn get_transaction_by_block_number_and_index_test() {
let (evm, mut working_set, _, _) = init_evm();
let (evm, mut working_set, _, _, _) = init_evm();

let result = evm.get_transaction_by_block_number_and_index(
BlockNumberOrTag::Number(100),
Expand Down Expand Up @@ -186,7 +186,7 @@ fn get_transaction_by_block_number_and_index_test() {

#[test]
fn get_block_transaction_count_by_hash_test() {
let (evm, mut working_set, _, _) = init_evm();
let (evm, mut working_set, _, _, _) = init_evm();

let result =
evm.eth_get_block_transaction_count_by_hash(B256::from([0u8; 32]), &mut working_set);
Expand Down Expand Up @@ -231,7 +231,7 @@ fn get_block_transaction_count_by_hash_test() {

#[test]
fn get_block_transaction_count_by_number_test() {
let (evm, mut working_set, _, _) = init_evm();
let (evm, mut working_set, _, _, _) = init_evm();

let result = evm
.eth_get_block_transaction_count_by_number(BlockNumberOrTag::Number(5), &mut working_set);
Expand All @@ -253,7 +253,7 @@ fn get_block_transaction_count_by_number_test() {

#[test]
fn call_test() {
let (evm, mut working_set, signer, _) = init_evm();
let (evm, mut working_set, _, signer, _) = init_evm();

let fail_result = evm.get_call(
TransactionRequest {
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/tests/queries/estimate_gas_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ fn test_access_list() {

#[test]
fn estimate_gas_with_varied_inputs_test() {
let (evm, mut working_set, signer, _) = init_evm();
let (evm, mut working_set, _, signer, _) = init_evm();

let simple_call_data = 0;
let simple_result =
Expand Down
19 changes: 11 additions & 8 deletions crates/evm/src/tests/queries/evm_call_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::Evm;

#[test]
fn call_contract_without_value() {
let (evm, mut working_set, signer, _) = init_evm();
let (evm, mut working_set, _, signer, _) = init_evm();

let contract = SimpleStorageContract::default();
let contract_address = Address::from_str("0xeeb03d20dae810f52111b853b31c8be6f30f4cd3").unwrap();
Expand Down Expand Up @@ -68,7 +68,7 @@ fn call_contract_without_value() {

#[test]
fn test_state_change() {
let (mut evm, mut working_set, signer, l2_height) = init_evm();
let (mut evm, mut working_set, _, signer, l2_height) = init_evm();

let balance_1 = evm.get_balance(signer.address(), None, &mut working_set);

Expand Down Expand Up @@ -114,7 +114,7 @@ fn test_state_change() {

#[test]
fn call_contract_with_value_transfer() {
let (evm, mut working_set, signer, _) = init_evm();
let (evm, mut working_set, _, signer, _) = init_evm();

let contract = SimpleStorageContract::default();
let contract_address = Address::from_str("0xeeb03d20dae810f52111b853b31c8be6f30f4cd3").unwrap();
Expand All @@ -140,7 +140,7 @@ fn call_contract_with_value_transfer() {

#[test]
fn call_contract_with_invalid_nonce() {
let (evm, mut working_set, signer, _) = init_evm();
let (evm, mut working_set, _, signer, _) = init_evm();

let contract = SimpleStorageContract::default();
let contract_address = Address::from_str("0xeeb03d20dae810f52111b853b31c8be6f30f4cd3").unwrap();
Expand Down Expand Up @@ -190,7 +190,7 @@ fn call_contract_with_invalid_nonce() {

#[test]
fn call_to_nonexistent_contract() {
let (evm, mut working_set, signer, _) = init_evm();
let (evm, mut working_set, _, signer, _) = init_evm();

let nonexistent_contract_address =
Address::from_str("0x000000000000000000000000000000000000dead").unwrap();
Expand Down Expand Up @@ -218,7 +218,7 @@ fn call_to_nonexistent_contract() {

#[test]
fn call_with_high_gas_price() {
let (evm, mut working_set, signer, _) = init_evm();
let (evm, mut working_set, _, signer, _) = init_evm();

let contract = SimpleStorageContract::default();
let contract_address = Address::from_str("0xeeb03d20dae810f52111b853b31c8be6f30f4cd3").unwrap();
Expand Down Expand Up @@ -248,7 +248,7 @@ fn call_with_high_gas_price() {

#[test]
fn test_eip1559_fields_call() {
let (evm, mut working_set, signer, _) = init_evm();
let (evm, mut working_set, _, signer, _) = init_evm();

let default_result = eth_call_eip1559(
&evm,
Expand Down Expand Up @@ -511,7 +511,7 @@ fn gas_price_call_test() {

#[test]
fn test_call_with_state_overrides() {
let (evm, mut working_set, signer, _) = init_evm();
let (evm, mut working_set, prover_storage, signer, _) = init_evm();

let contract = SimpleStorageContract::default();
let contract_address = Address::from_str("0xeeb03d20dae810f52111b853b31c8be6f30f4cd3").unwrap();
Expand Down Expand Up @@ -572,6 +572,9 @@ fn test_call_with_state_overrides() {
U256::from(15).to_be_bytes_vec()
);

// Start with a fresh working set, because the previous one was for a separate RPC call.
let mut working_set = WorkingSet::new(prover_storage);

// Get value of contract AFTER state override, this MUST be the original value.
let call_result_without_state_override = evm
.get_call(
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/tests/queries/log_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type C = DefaultContext;

#[test]
fn logs_for_filter_test() {
let (evm, mut working_set, _, _) = init_evm();
let (evm, mut working_set, _, _, _) = init_evm();

let result = evm.eth_get_logs(
Filter {
Expand Down
12 changes: 10 additions & 2 deletions crates/evm/src/tests/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::hooks::HookSoftConfirmationInfo;
use sov_modules_api::utils::generate_address;
use sov_modules_api::{Context, Module, WorkingSet};
use sov_prover_storage_manager::SnapshotManager;
use sov_rollup_interface::spec::SpecId as SovSpecId;
use sov_state::{DefaultStorageSpec, ProverStorage};

use crate::call::CallMessage;
use crate::smart_contracts::{
Expand All @@ -30,7 +32,13 @@ type C = DefaultContext;
/// Block 1 has 3 transactions
/// Block 2 has 4 transactions
/// Block 3 has 2 transactions
fn init_evm() -> (Evm<C>, WorkingSet<C>, TestSigner, u64) {
fn init_evm() -> (
Evm<C>,
WorkingSet<C>,
ProverStorage<DefaultStorageSpec, SnapshotManager>,
TestSigner,
u64,
) {
let dev_signer: TestSigner = TestSigner::new_random();

let mut config = EvmConfig {
Expand Down Expand Up @@ -206,7 +214,7 @@ fn init_evm() -> (Evm<C>, WorkingSet<C>, TestSigner, u64) {

let working_set: WorkingSet<DefaultContext> = WorkingSet::new(prover_storage.clone());

(evm, working_set, dev_signer, l2_height)
(evm, working_set, prover_storage, dev_signer, l2_height)
}

pub fn init_evm_single_block() -> (Evm<C>, WorkingSet<C>, TestSigner) {
Expand Down

0 comments on commit 6646fba

Please sign in to comment.