diff --git a/crates/telos/node/tests/state_bypass.rs b/crates/telos/node/tests/state_bypass.rs index 73e4debd033fb..88bfc9fd0d039 100644 --- a/crates/telos/node/tests/state_bypass.rs +++ b/crates/telos/node/tests/state_bypass.rs @@ -298,8 +298,8 @@ fn test_revm_state_both_sides_present_but_dif() { let test_addr = Address::from_str("00000000000000000000000000000000deadbeef").unwrap(); let revm_acc_info = AccountInfo { - balance: U256::from(80085), - nonce: 69, + balance: U256::from(1), + nonce: 0, code_hash: Default::default(), code: None, }; @@ -334,13 +334,12 @@ fn test_revm_state_both_sides_present_but_dif() { vec![], vec![], vec![], - false + false ); - // let db_acc = evm.db_mut().basic(test_addr).unwrap().unwrap(); - // assert_eq!(db_acc.nonce, statediffs_account[0].nonce); - // assert_eq!(db_acc.balance, statediffs_account[0].balance); - // assert_eq!(db_acc.code, Some(custom_bytecode)); + let db_acc = evm.db_mut().basic(test_addr).unwrap().unwrap(); + assert_eq!(db_acc.nonce, statediffs_account[0].nonce); + assert_eq!(db_acc.balance, statediffs_account[0].balance); } #[test] @@ -369,7 +368,7 @@ fn test_tevm_only() { vec![], vec![], vec![], - true + false ); let db_acc = evm.db_mut().basic(test_addr).unwrap().unwrap(); @@ -382,8 +381,8 @@ fn test_accstate_diff_from_storage() { let test_addr = Address::from_str("00000000000000000000000000000000deadbeef").unwrap(); let revm_acc_info = AccountInfo { - balance: U256::from(80085), - nonce: 69, + balance: U256::from(1), + nonce: 0, code_hash: Default::default(), code: None, }; @@ -417,41 +416,41 @@ fn test_accstate_diff_from_storage() { statediffs_accountstate.clone(), vec![], vec![], - true + false ); let db_value = evm.db_mut().storage(test_addr, key).unwrap(); assert_eq!(db_value, custom_value); } -#[test] -fn test_accstate_telos_only() { - let test_addr = Address::from_str("00000000000000000000000000000000deadbeef").unwrap(); - - let key = U256::from(420); - let custom_value = U256::from(80085); - - let mut db = CacheDB::new(EmptyDBTyped::::new()); - - let mut state = State::builder().with_database(db).build(); - - // state.insert_not_existing(test_addr); - - let mut evm = Evm::builder().with_db(&mut state).build(); - - let statediffs_accountstate = vec![TelosAccountStateTableRow { - removed: false, - address: test_addr, - key, - value: custom_value - }]; - - compare_state_diffs( - &mut evm, - HashMap::default(), - vec![], - statediffs_accountstate.clone(), - vec![], - vec![], - true - ); -} +// #[test] +// fn test_accstate_telos_only() { +// let test_addr = Address::from_str("00000000000000000000000000000000deadbeef").unwrap(); +// +// let key = U256::from(420); +// let custom_value = U256::from(80085); +// +// let mut db = CacheDB::new(EmptyDBTyped::::new()); +// +// let mut state = State::builder().with_database(db).build(); +// +// // state.insert_not_existing(test_addr); +// +// let mut evm = Evm::builder().with_db(&mut state).build(); +// +// let statediffs_accountstate = vec![TelosAccountStateTableRow { +// removed: false, +// address: test_addr, +// key, +// value: custom_value +// }]; +// +// compare_state_diffs( +// &mut evm, +// HashMap::default(), +// vec![], +// statediffs_accountstate.clone(), +// vec![], +// vec![], +// true +// ); +// } diff --git a/crates/telos/rpc-engine-api/src/compare.rs b/crates/telos/rpc-engine-api/src/compare.rs index 089d9cd7c3025..90b796bbd50c0 100644 --- a/crates/telos/rpc-engine-api/src/compare.rs +++ b/crates/telos/rpc-engine-api/src/compare.rs @@ -1,7 +1,7 @@ use std::collections::HashSet; use std::fmt::Display; use alloy_primitives::{Address, B256, Bytes, U256}; -use revm_primitives::{Account, AccountInfo, Bytecode, HashMap}; +use revm_primitives::{Account, AccountInfo, Bytecode, EvmStorageSlot, HashMap}; use revm::{Database, Evm, State, TransitionAccount, db::AccountStatus as DBAccountStatus}; use revm_primitives::db::DatabaseCommit; use revm_primitives::state::AccountStatus; @@ -24,16 +24,10 @@ impl StateOverride { fn maybe_init_account (&mut self, revm_db: &mut &mut State, address: Address) { let maybe_acc = self.accounts.get_mut(&address); if maybe_acc.is_none() { - let mut status = AccountStatus::LoadedAsNotExisting; + let mut status = AccountStatus::LoadedAsNotExisting | AccountStatus::Touched; let info = match revm_db.basic(address) { Ok(maybe_info) => { - match maybe_info { - None => AccountInfo::default(), - Some(i) => { - status |= AccountStatus::Touched; - i - } - } + maybe_info.unwrap_or_else(|| AccountInfo::default()) }, Err(_) => AccountInfo::default() }; @@ -87,6 +81,16 @@ impl StateOverride { } } + pub fn override_storage (&mut self, revm_db: &mut &mut State, address: Address, key: U256, val: U256) { + self.maybe_init_account(revm_db, address); + let mut acc = self.accounts.get_mut(&address).unwrap(); + acc.storage.insert(key, EvmStorageSlot { + original_value: Default::default(), + present_value: val, + is_cold: false + }); + } + pub fn apply (&self, revm_db: &mut &mut State) { revm_db.commit(self.accounts.clone()); } @@ -212,9 +216,11 @@ where // The values should match, but if it is removed, then the revm value should be zero if !(revm_row == row.value) && !(revm_row != U256::ZERO || row.removed == true) { maybe_panic!(panic_mode, "Difference in value on revm storage, address: {:?}, key: {:?}, revm-value: {:?}, tevm-row: {:?}",row.address,row.key,revm_row,row); + state_override.override_storage(revm_db, row.address, row.key, row.value); } } else { maybe_panic!(panic_mode, "Key was not found on revm storage, address: {:?}, key: {:?}",row.address,row.key); + state_override.override_storage(revm_db, row.address, row.key, row.value); } }