diff --git a/crates/telos/node/tests/state_bypass.rs b/crates/telos/node/tests/state_bypass.rs index b288fcc152e69..2cb9373b71be9 100644 --- a/crates/telos/node/tests/state_bypass.rs +++ b/crates/telos/node/tests/state_bypass.rs @@ -305,105 +305,79 @@ fn test_tevm_only() { assert_eq!(db_acc.balance, statediffs_account[0].balance); } -// #[test] -// 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, -// code_hash: Default::default(), -// code: None, -// }; -// -// let mut state = HashMap::new(); -// -// let mut storage = HashMap::new(); -// let key = U256::from(420); -// let value = U256::from(0); -// storage.insert(key, EvmStorageSlot { original_value: Default::default(), present_value: value, is_cold: false }); -// let custom_value = U256::from(80085); -// -// let revm_acc = Account { -// info: revm_acc_info.clone(), -// storage, -// status: AccountStatus::Touched | AccountStatus::LoadedAsNotExisting, -// }; -// state.insert(test_addr, revm_acc); -// -// // let mut transition_account = TransitionAccount::new_empty_eip161(storage); -// -// // transition_account.info = Some(revm_acc_info.clone()); -// -// // revm_state_diffs.insert(test_addr, transition_account); -// -// let mut db = CacheDB::new(EmptyDB::new()); -// -// // db.insert_account_info(test_addr, revm_acc_info); -// db.commit(state); -// -// let mut state = State::builder().with_database(db).build(); -// -// 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::new(), -// vec![], -// statediffs_accountstate.clone(), -// vec![], -// vec![] -// ); -// -// // 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)); -// } - -// #[test] -// fn test_acc_is_none_on_revm_db() { -// let test_addr = Address::from_str("00000000000000000000000000000000deadbeef").unwrap(); -// -// let mut revm_state_diffs = HashMap::new(); -// -// // let transition_account = TransitionAccount::new_empty_eip161(HashMap::new()); -// // revm_state_diffs.insert(test_addr, transition_account); -// -// let db = CacheDB::new(EmptyDB::new()); -// let refm = db.basic_ref(test_addr).unwrap(); -// -// let mut state = State::builder().with_database(db).build(); -// -// let mut evm = Evm::builder().with_db(&mut state).build(); -// -// let statediffs_account = vec![TelosAccountTableRow { -// removed: false, -// address: test_addr, -// account: "eosio".to_string(), -// nonce: 1, -// code: Default::default(), -// balance: U256::from(80085), -// }]; -// -// compare_state_diffs( -// &mut evm, -// revm_state_diffs, -// statediffs_account.clone(), -// vec![], -// vec![], -// vec![] -// ); -// -// // 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)); -// } +#[test] +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, + code_hash: Default::default(), + code: None, + }; + + let key = U256::from(420); + let value = U256::from(0); + let custom_value = U256::from(80085); + + let mut db = CacheDB::new(EmptyDB::new()); + + let mut storage = HashMap::new(); + storage.insert(key, value); + + let mut state = State::builder().with_database(db).build(); + + state.insert_account_with_storage(test_addr, revm_acc_info, storage); + + 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::new(), + vec![], + statediffs_accountstate.clone(), + vec![], + vec![] + ); + + 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(EmptyDB::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::new(), + vec![], + statediffs_accountstate.clone(), + vec![], + vec![] + ); +}