Skip to content

Commit

Permalink
fix: fail tests on assert failure (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec authored Dec 7, 2023
1 parent 2e4fb0a commit 2244bcb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 32 deletions.
43 changes: 24 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ foundry-debugger = { path = "crates/debugger" }

## revm
# no default features to avoid c-kzg
# Using a fork of revm as zksync-era requires the usage of sha3 0.10.6, and the latest revm uses 0.10.8
revm = { version = "3.5.0", default-features = false }
era_revm = { git="https://github.com/matter-labs/era-revm", rev = "0e0ea26106a16cfc74a2b9ec37cadd69417ae68b" }
era_revm = { git="https://github.com/matter-labs/era-revm", rev = "2662bb19427a421662a7e463cf1ed6a15da361e5" }

# We use a fork of `ethers` to gain access to a previously private variable.
# This ensures that all artifact files, freshly compiled and saved in the `output` directory, are publicly accessible.
Expand Down Expand Up @@ -195,4 +194,3 @@ ethers-signers = { git = "https://github.com/mm-zk/ethers-rs", tag = "main_publi
ethers-middleware = { git = "https://github.com/mm-zk/ethers-rs", tag = "main_public_artifact", default-features = false }
ethers-etherscan = { git = "https://github.com/mm-zk/ethers-rs", tag = "main_public_artifact", default-features = false }
ethers-solc = { git = "https://github.com/mm-zk/ethers-rs", tag = "main_public_artifact", default-features = false }

15 changes: 7 additions & 8 deletions crates/evm/src/executor/backend/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::executor::{
use alloy_primitives::{Address, B256, U256};
use revm::{
db::DatabaseRef,
primitives::{AccountInfo, Bytecode, Env, ResultAndState},
primitives::{AccountInfo, Bytecode, EVMResult, Env, ResultAndState},
Database, Inspector, JournaledState,
};
use std::borrow::Cow;
Expand Down Expand Up @@ -57,18 +57,17 @@ impl<'a> FuzzBackendWrapper<'a> {
pub fn inspect_ref<INSP>(
&mut self,
env: &mut Env,
mut inspector: INSP,
inspector: INSP,
) -> eyre::Result<ResultAndState>
where
INSP: Inspector<Self>,
{
// this is a new call to inspect with a new env, so even if we've cloned the backend
// already, we reset the initialized state
self.is_initialized = false;
match revm::evm_inner::<Self, true>(env, self, &mut inspector).transact() {
Ok(result) => Ok(result),
Err(e) => eyre::bail!("fuzz: failed to inspect: {:?}", e),
}

let result: EVMResult<DatabaseError> =
era_revm::transactions::run_era_transaction(env, self, inspector);

Ok(result.unwrap())
}

/// Returns whether there was a snapshot failure in the fuzz backend.
Expand Down
1 change: 0 additions & 1 deletion crates/evm/src/executor/inspector/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ pub struct InspectorData {
pub script_wallets: Vec<LocalWallet>,
pub chisel_state: Option<(Stack, Memory, InstructionResult)>,
}

/// An inspector that calls multiple inspectors in sequence.
///
/// If a call to an inspector returns a value other than [InstructionResult::Continue] (or
Expand Down
4 changes: 3 additions & 1 deletion crates/evm/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ impl Executor {
// execute the call
let env = self.build_test_env(from, TransactTo::Call(test_contract), calldata, value);
let call_result = self.call_raw_with_env(env)?;
self.record_env_changes(&call_result.env);
convert_call_result(abi, &func, call_result)
}

Expand Down Expand Up @@ -498,7 +499,7 @@ impl Executor {
}

// Construct a new VM with the state changeset
let mut backend = self.backend.clone_empty();
let mut backend = self.backend.clone();

// we only clone the test contract and cheatcode accounts, that's all we need to evaluate
// success
Expand Down Expand Up @@ -760,6 +761,7 @@ fn convert_executed_result(

let result = match out {
Some(Output::Call(ref data)) => data.to_owned(),
Some(Output::Create(ref data, _)) => data.to_owned(),
_ => Bytes::default(),
};

Expand Down

0 comments on commit 2244bcb

Please sign in to comment.