Skip to content

Commit

Permalink
enable persistance only once per test contract deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec committed Nov 19, 2024
1 parent 57db920 commit 5d6f48d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 0 additions & 6 deletions crates/evm/evm/src/executors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,6 @@ impl Executor {
#[instrument(name = "call", level = "debug", skip_all)]
pub fn call_with_env(&self, mut env: EnvWithHandlerCfg) -> eyre::Result<RawCallResult> {
let mut inspector = self.inspector().clone();
if let Some(cheatcodes) = inspector.cheatcodes.as_mut() {
cheatcodes.zk_persist_nonce_update.persist_next();
}
let mut backend = CowBackend::new_borrowed(self.backend());
let result = match &self.zk_tx {
None => backend.inspect(&mut env, &mut inspector)?,
Expand All @@ -453,9 +450,6 @@ impl Executor {
#[instrument(name = "transact", level = "debug", skip_all)]
pub fn transact_with_env(&mut self, mut env: EnvWithHandlerCfg) -> eyre::Result<RawCallResult> {
let mut inspector = self.inspector.clone();
if let Some(cheatcodes) = inspector.cheatcodes.as_mut() {
cheatcodes.zk_persist_nonce_update.persist_next();
}
let backend = &mut self.backend;
let result_and_state = match self.zk_tx.take() {
None => backend.inspect(&mut env, &mut inspector)?,
Expand Down
6 changes: 5 additions & 1 deletion crates/forge/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,16 @@ impl ContractRunner<'_> {
self.executor.deploy_create2_deployer()?;

// Test contract has already been deployed so we can migrate the database to zkEVM storage
// in the next runner execution.
// in the next runner execution. Additionally we can allow persisting the next nonce update
// to simulate EVM behavior where only the test contract deployment increments the
// nonce.
if let Some(cheatcodes) = &mut self.executor.inspector.cheatcodes {
if let Some(zk_startup_migration) = &mut cheatcodes.zk_startup_migration {
debug!("test contract deployed, allowing startup storage migration");
zk_startup_migration.allow();
}
debug!("test contract deployed, allowing persisting next nonce update");
cheatcodes.zk_persist_nonce_update.persist_next();
}

// Optionally call the `setUp` function
Expand Down
6 changes: 5 additions & 1 deletion crates/script/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,16 @@ impl ScriptRunner {
traces.extend(constructor_traces.map(|traces| (TraceKind::Deployment, traces)));

// Script has already been deployed so we can migrate the database to zkEVM storage
// in the next runner execution.
// in the next runner execution. Additionally we can allow persisting the next nonce update
// to simulate EVM behavior where only the test contract deployment increments the
// nonce.
if let Some(cheatcodes) = &mut self.executor.inspector.cheatcodes {
if let Some(zk_startup_migration) = &mut cheatcodes.zk_startup_migration {
debug!("script deployed, allowing startup storage migration");
zk_startup_migration.allow();
}
debug!("script deployed, allowing persisting next nonce update");
cheatcodes.zk_persist_nonce_update.persist_next();
}

// Optionally call the `setUp` function
Expand Down

0 comments on commit 5d6f48d

Please sign in to comment.