Skip to content

Commit

Permalink
Make test that correctly emulates storage diff
Browse files Browse the repository at this point in the history
  • Loading branch information
guilledk committed Oct 14, 2024
1 parent 074a67d commit eb176ef
Showing 1 changed file with 76 additions and 102 deletions.
178 changes: 76 additions & 102 deletions crates/telos/node/tests/state_bypass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![]
);
}

0 comments on commit eb176ef

Please sign in to comment.