Skip to content

Commit

Permalink
fix two tests in vm_fast
Browse files Browse the repository at this point in the history
  • Loading branch information
montekki committed Jul 23, 2024
1 parent fa7f237 commit 8be5e6f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::{
},
};

#[ignore] // FIXME: fails on `assert_eq!(res.initial_storage_writes, basic_initial_writes)`
#[test]
fn test_l1_tx_execution() {
// In this test, we try to execute a contract deployment from L1
Expand Down
12 changes: 9 additions & 3 deletions core/lib/multivm/src/versions/vm_fast/tests/require_eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ impl VmTester {
AccountTreeId::new(L2_BASE_TOKEN_ADDRESS),
&address,
);
h256_to_u256(self.vm.world.storage.read_value(&key))
self.vm
.inner
.world_diff
.get_storage_state()
.get(&(L2_BASE_TOKEN_ADDRESS, h256_to_u256(*key.key())))
.cloned()
.unwrap_or(h256_to_u256(self.vm.world.storage.read_value(&key)))
}
}

#[ignore] // FIXME: fails on `assert_eq!(vm.get_eth_balance(beneficiary.address), U256::from(888000088))`
#[tokio::test]
/// This test deploys 'buggy' account abstraction code, and then tries accessing it both with legacy
/// and EIP712 transactions.
Expand Down Expand Up @@ -134,7 +139,8 @@ async fn test_require_eip712() {
Default::default(),
);

let transaction_request: TransactionRequest = tx_712.into();
let mut transaction_request: TransactionRequest = tx_712.into();
transaction_request.chain_id = Some(chain_id.into());

let domain = Eip712Domain::new(L2ChainId::from(chain_id));
let signature = private_account
Expand Down
79 changes: 41 additions & 38 deletions core/lib/multivm/src/versions/vm_fast/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,15 +511,6 @@ impl<S: ReadStorage> VmInterface for Vm<S> {
let pubdata_before = self.inner.world_diff.pubdata.0;

let (result, refunds) = self.run(execution_mode, track_refunds);
if matches!(execution_mode, VmExecutionMode::OneTx) {
if matches!(result, ExecutionResult::Halt { .. }) {
// Only `Halt`ed executions need a rollback; `Revert`s are correctly handled by the bootloader
// so the bootloader / system contract state should be persisted.
self.rollback_to_the_latest_snapshot();
} else {
self.pop_snapshot_no_rollback();
}
}

let events = merge_events(
self.inner.world_diff.events_after(&start),
Expand All @@ -532,37 +523,49 @@ impl<S: ReadStorage> VmInterface for Vm<S> {
.collect();
let pubdata_after = self.inner.world_diff.pubdata.0;

let logs = VmExecutionLogs {
storage_logs: self
.inner
.world_diff
.get_storage_changes_after(&start)
.map(|((address, key), change)| StorageLogWithPreviousValue {
log: StorageLog {
key: StorageKey::new(AccountTreeId::new(address), u256_to_h256(key)),
value: u256_to_h256(change.after),
kind: if change.is_initial {
StorageLogKind::InitialWrite
} else {
StorageLogKind::RepeatedWrite
},
},
previous_value: u256_to_h256(change.before.unwrap_or_default()),
})
.collect(),
events,
user_l2_to_l1_logs,
system_l2_to_l1_logs: self
.inner
.world_diff
.l2_to_l1_logs_after(&start)
.iter()
.map(|x| x.glue_into())
.collect(),
total_log_queries_count: 0, // This field is unused
};

if matches!(execution_mode, VmExecutionMode::OneTx) {
if matches!(result, ExecutionResult::Halt { .. }) {
// Only `Halt`ed executions need a rollback; `Revert`s are correctly handled by the bootloader
// so the bootloader / system contract state should be persisted.
self.rollback_to_the_latest_snapshot();
} else {
self.pop_snapshot_no_rollback();
}
}

VmExecutionResultAndLogs {
result,
logs: VmExecutionLogs {
storage_logs: self
.inner
.world_diff
.get_storage_changes_after(&start)
.map(|((address, key), change)| StorageLogWithPreviousValue {
log: StorageLog {
key: StorageKey::new(AccountTreeId::new(address), u256_to_h256(key)),
value: u256_to_h256(change.after),
kind: if change.is_initial {
StorageLogKind::InitialWrite
} else {
StorageLogKind::RepeatedWrite
},
},
previous_value: u256_to_h256(change.before.unwrap_or_default()),
})
.collect(),
events,
user_l2_to_l1_logs,
system_l2_to_l1_logs: self
.inner
.world_diff
.l2_to_l1_logs_after(&start)
.iter()
.map(|x| x.glue_into())
.collect(),
total_log_queries_count: 0, // This field is unused
},
logs,
statistics: VmExecutionStatistics {
contracts_used: 0, // TODO
cycles_used: 0, // TODO
Expand Down

0 comments on commit 8be5e6f

Please sign in to comment.