Skip to content

Commit

Permalink
feat(evm): use completely separated storage sections in multifork (#2301
Browse files Browse the repository at this point in the history
)

* refactor: completely separate fork states

* refactor: turn fuzz wrapper into cow

* refactor: add subroutine to trait

* feat: track subroutine

* copy sender and receiver

* test: extend fork test

* fix: initialize accounts on setup

* test: add create select test

* Update evm/src/executor/backend/fuzz.rs

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>

* update docs

* fix: clone cheat code address and add traces

* test: add another test

* introduce persistent accounts

* feat: add persistent cheatcodes

* add persistent tests

* test: add persistent test

* feat: add revert error multifork diagnostic

* feat: better diagnostic

* docs

* feat: fork revert diagnostic

* test: remove uncommented left over

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
  • Loading branch information
mattsse and gakonst authored Jul 30, 2022
1 parent f4161ac commit af3c9d3
Show file tree
Hide file tree
Showing 19 changed files with 1,058 additions and 439 deletions.
9 changes: 8 additions & 1 deletion evm/src/executor/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::HashMap;
///
/// This is the same address as the one used in DappTools's HEVM.
/// `address(bytes20(uint160(uint256(keccak256('hevm cheat code')))))`
pub static CHEATCODE_ADDRESS: Address = H160([
pub const CHEATCODE_ADDRESS: Address = H160([
0x71, 0x09, 0x70, 0x9E, 0xcf, 0xa9, 0x1a, 0x80, 0x62, 0x6f, 0xf3, 0x98, 0x9d, 0x68, 0xf6, 0x7f,
0x5b, 0x1d, 0xd1, 0x2d,
]);
Expand Down Expand Up @@ -95,6 +95,13 @@ ethers::contract::abigen!(
createSelectFork(string)(uint256)
selectFork(uint256)
activeFork()(uint256)
makePersistent(address)
makePersistent(address,address)
makePersistent(address,address,address)
makePersistent(address[])
revokePersistent(address)
revokePersistent(address[])
isPersistent(address)(bool)
rollFork(uint256)
rollFork(uint256,uint256)
rpcUrl(string)(string)
Expand Down
45 changes: 45 additions & 0 deletions evm/src/executor/backend/diagnostic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use crate::{
executor::{backend::LocalForkId, inspector::Cheatcodes},
Address,
};
use foundry_common::fmt::UIfmt;

/// Represents possible diagnostic cases on revert
#[derive(Debug, Clone)]
pub enum RevertDiagnostic {
/// The `contract` does not exist on the `active` fork but exist on other fork(s)
ContractExistsOnOtherForks {
contract: Address,
active: LocalForkId,
available_on: Vec<LocalForkId>,
},
ContractDoesNotExist {
contract: Address,
active: LocalForkId,
},
}

// === impl RevertDiagnostic ===

impl RevertDiagnostic {
/// Converts the diagnostic to a readable error message
pub fn to_error_msg(&self, cheats: &Cheatcodes) -> String {
let get_label = |addr| cheats.labels.get(addr).cloned().unwrap_or_else(|| addr.pretty());

match self {
RevertDiagnostic::ContractExistsOnOtherForks { contract, active, available_on } => {
let contract_label = get_label(contract);

format!(
r#"Contract {} does not exists on active fork with id `{}`
But exists on non active forks: `{:?}`"#,
contract_label, active, available_on
)
}
RevertDiagnostic::ContractDoesNotExist { contract, .. } => {
let contract_label = get_label(contract);
format!("Contract {} does not exists", contract_label)
}
}
}
}
Loading

0 comments on commit af3c9d3

Please sign in to comment.