Skip to content

Commit 2b4d99b

Browse files
committed
Simple REVM test runner (#788)
* refactor: nuke `evm-adapters` * refactor: simple revm test runner Current features: - Can run unit tests - Works with both revert-type tests and DSTest-type tests - Collects logs, albeit not for reverting tests - Integrated with config and CLI flags Disabled features: - Gas reports - Tracing - Cheatcodes - Fuzzing - Log decoding - Forking mode - Hardhat-style `console.log`, since those require us to decode calls to a specific address (HH does not emit logs) - The debugger In addition to this, I've disabled some tests that could never pass under the current circumstances, but that should be adjusted and re-enabled when their respective features are implemented (such as fuzz tests) * refactor: adjust CLI to new runner API * feat: log collector inspector * feat: hardhat logs * chore: lint * refactor: extract hh log converter to helper fn * refactor: return single test result if setup fails * build: use upstream revm
1 parent 2316100 commit 2b4d99b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1529
-10662
lines changed

Cargo.lock

Lines changed: 317 additions & 546 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[workspace]
22
members = [
3-
"evm-adapters",
43
"utils",
54
"cast",
65
"forge",

cli/Cargo.toml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ foundry-utils = { path = "../utils" }
2626
forge = { path = "../forge" }
2727
foundry-config = { path = "../config" }
2828
cast = { path = "../cast" }
29-
evm-adapters = { path = "../evm-adapters" }
30-
ui = { path = "../ui" }
29+
# TODO: Re-enable when ported
30+
#ui = { path = "../ui" }
3131
dunce = "1.0.2"
3232
# ethers = "0.5"
3333
ethers = { git = "https://github.com/gakonst/ethers-rs", default-features = false }
@@ -46,9 +46,6 @@ rayon = "1.5.1"
4646
serde = "1.0.133"
4747
futures = "0.3.17"
4848

49-
## EVM Implementations
50-
# evm = { version = "0.30.1" }
51-
sputnik = { package = "evm", git = "https://github.com/rust-blockchain/evm", default-features = false, features = ["std"], optional = true }
5249
proptest = "1.0.0"
5350
glob = "0.3.0"
5451
semver = "1.0.5"
@@ -67,17 +64,11 @@ pretty_assertions = "1.0.0"
6764
toml = "0.5"
6865

6966
[features]
70-
default = ["sputnik-evm", "rustls"]
67+
default = ["rustls"]
7168
solc-asm = ["ethers/solc-sha2-asm"]
7269
rustls = ["ethers/rustls"]
7370
openssl = ["ethers/openssl"]
7471

75-
sputnik-evm = [
76-
"sputnik",
77-
"evm-adapters/sputnik",
78-
"evm-adapters/sputnik-helpers",
79-
]
80-
8172
integration-tests = []
8273

8374
[[bin]]

cli/src/cmd/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ pub mod fmt;
4646
pub mod init;
4747
pub mod install;
4848
pub mod remappings;
49-
pub mod run;
49+
// TODO: Re-enable when ported
50+
//pub mod run;
5051
pub mod snapshot;
5152
pub mod test;
5253
pub mod verify;

cli/src/cmd/test.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ use crate::{
77
use ansi_term::Colour;
88
use clap::{AppSettings, Parser};
99
use ethers::solc::{ArtifactOutput, Project};
10-
use evm_adapters::{
11-
call_tracing::ExecutionInfo, evm_opts::EvmOpts, gas_report::GasReport, sputnik::helpers::vm,
12-
};
1310
use forge::{MultiContractRunnerBuilder, TestFilter, TestResult};
1411
use foundry_config::{figment::Figment, Config};
1512
use regex::Regex;
@@ -335,11 +332,12 @@ fn test<A: ArtifactOutput + 'static>(
335332
println!("{}", res);
336333
Ok(TestOutcome::new(results, allow_failure))
337334
} else {
338-
// Dapptools-style printing of test results
339-
let mut gas_report = GasReport::new(gas_reports.1);
335+
// TODO: Re-enable when ported
336+
//let mut gas_report = GasReport::new(gas_reports.1);
340337
let (tx, rx) = channel::<(String, BTreeMap<String, TestResult>)>();
341338
let known_contracts = runner.known_contracts.clone();
342-
let execution_info = runner.execution_info.clone();
339+
// TODO: Re-enable when ported
340+
//let execution_info = runner.execution_info.clone();
343341

344342
let handle = thread::spawn(move || {
345343
while let Ok((contract_name, tests)) = rx.recv() {
@@ -360,7 +358,8 @@ fn test<A: ArtifactOutput + 'static>(
360358
println!(" {}", log);
361359
}
362360
}
363-
if verbosity > 2 {
361+
// TODO: Re-enable this when traces are ported
362+
/*if verbosity > 2 {
364363
if let (Some(traces), Some(identified_contracts)) =
365364
(&result.traces, &result.identified_contracts)
366365
{
@@ -415,7 +414,7 @@ fn test<A: ArtifactOutput + 'static>(
415414
}
416415
}
417416
}
418-
}
417+
}*/
419418
if add_newline {
420419
println!();
421420
}
@@ -427,7 +426,8 @@ fn test<A: ArtifactOutput + 'static>(
427426

428427
handle.join().unwrap();
429428

430-
if gas_reporting {
429+
// TODO: Re-enable when ported
430+
/*if gas_reporting {
431431
for tests in results.values() {
432432
for result in tests.values() {
433433
if let (Some(traces), Some(identified_contracts)) =
@@ -439,7 +439,7 @@ fn test<A: ArtifactOutput + 'static>(
439439
}
440440
gas_report.finalize();
441441
println!("{}", gas_report);
442-
}
442+
}*/
443443
Ok(TestOutcome::new(results, allow_failure))
444444
}
445445
}

cli/src/forge.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ fn main() -> eyre::Result<()> {
3636
cmd.run()?;
3737
}
3838
}
39-
Subcommands::Run(cmd) => {
40-
cmd.run()?;
41-
}
39+
// TODO: Re-enable when ported
40+
//Subcommands::Run(cmd) => {
41+
// cmd.run()?;
42+
//}
4243
Subcommands::VerifyContract(args) => {
4344
utils::block_on(cmd::verify::run_verify(&args))?;
4445
}

cli/src/opts/evm.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! cli arguments for configuring the evm settings
22
use clap::Parser;
33
use ethers::types::{Address, U256};
4-
use evm_adapters::evm_opts::EvmType;
54
use foundry_config::{
65
figment::{
76
self,
@@ -27,7 +26,7 @@ use serde::Serialize;
2726
//
2827
// ```ignore
2928
// use foundry_config::Config;
30-
// use evm_adapter::EvmOpts;
29+
// use forge::executor::opts::EvmOpts;
3130
// # fn t(args: EvmArgs) {
3231
// let figment = Config::figment_with_root(".").merge(args);
3332
// let opts = figment.extract::<EvmOpts>().unwrap()
@@ -40,14 +39,6 @@ pub struct EvmArgs {
4039
#[serde(flatten)]
4140
pub env: EnvArgs,
4241

43-
#[clap(
44-
long,
45-
short,
46-
help = "the EVM type you want to use (e.g. sputnik)",
47-
default_value = "sputnik"
48-
)]
49-
pub evm_type: EvmType,
50-
5142
#[clap(help = "fetch state over a remote instead of starting from empty state", long, short)]
5243
#[clap(alias = "rpc-url")]
5344
#[serde(rename = "eth_rpc_url", skip_serializing_if = "Option::is_none")]
@@ -153,5 +144,4 @@ pub struct EnvArgs {
153144
#[clap(help = "the block.gaslimit value during EVM execution", long)]
154145
#[serde(skip_serializing_if = "Option::is_none")]
155146
pub block_gas_limit: Option<u64>,
156-
// TODO: Add configuration option for base fee.
157147
}

cli/src/opts/forge.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::cmd::{
1212
init::InitArgs,
1313
install::InstallArgs,
1414
remappings::RemappingArgs,
15-
run::RunArgs,
1615
snapshot, test,
1716
verify::{VerifyArgs, VerifyCheckArgs},
1817
};
@@ -46,10 +45,10 @@ pub enum Subcommands {
4645
#[clap(alias = "b")]
4746
Build(BuildArgs),
4847

49-
#[clap(about = "Run a single smart contract as a script")]
50-
#[clap(alias = "r")]
51-
Run(RunArgs),
52-
48+
// TODO: Re-enable when ported
49+
//#[clap(about = "Run a single smart contract as a script")]
50+
//#[clap(alias = "r")]
51+
//Run(RunArgs),
5352
#[clap(alias = "u", about = "Fetches all upstream lib changes")]
5453
Update {
5554
#[clap(

cli/src/utils.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::{future::Future, str::FromStr, time::Duration};
22

33
use ethers::{solc::EvmVersion, types::U256};
4-
#[cfg(feature = "sputnik-evm")]
5-
use sputnik::Config;
64

5+
use forge::executor::SpecId;
76
// reexport all `foundry_config::utils`
87
#[doc(hidden)]
98
pub use foundry_config::utils::*;
@@ -28,12 +27,11 @@ pub fn subscriber() {
2827
.init();
2928
}
3029

31-
#[cfg(feature = "sputnik-evm")]
32-
pub fn sputnik_cfg(evm: &EvmVersion) -> Config {
30+
pub fn evm_spec(evm: &EvmVersion) -> SpecId {
3331
match evm {
34-
EvmVersion::Istanbul => Config::istanbul(),
35-
EvmVersion::Berlin => Config::berlin(),
36-
EvmVersion::London => Config::london(),
32+
EvmVersion::Istanbul => SpecId::ISTANBUL,
33+
EvmVersion::Berlin => SpecId::BERLIN,
34+
EvmVersion::London => SpecId::LONDON,
3735
_ => panic!("Unsupported EVM version"),
3836
}
3937
}

cli/tests/cmd.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
//! Contains various tests for checking forge's commands
22
use ansi_term::Colour;
33
use ethers::solc::{artifacts::Metadata, ConfigurableContractArtifact};
4-
use evm_adapters::evm_opts::{EvmOpts, EvmType};
4+
use forge::executor::opts::EvmOpts;
55
use foundry_cli_test_utils::{
66
ethers_solc::{remappings::Remapping, PathStyle},
77
forgetest, forgetest_ignore, forgetest_init, pretty_eq,
88
util::{pretty_err, read_string, TestCommand, TestProject},
99
};
1010
use foundry_config::{parse_with_profile, BasicConfig, Config, OptimizerDetails};
1111
use pretty_assertions::assert_eq;
12-
use std::{
13-
env::{self},
14-
fs,
15-
str::FromStr,
16-
};
12+
use std::{env, fs, str::FromStr};
1713

1814
// import forge utils as mod
1915
#[allow(unused)]
@@ -219,9 +215,7 @@ forgetest_init!(can_get_evm_opts, |prj: TestProject, mut cmd: TestCommand| {
219215
assert!(config.ffi);
220216

221217
cmd.set_env("FOUNDRY_ETH_RPC_URL", url);
222-
let figment = Config::figment_with_root(prj.root())
223-
.merge(("evm_type", EvmType::Sputnik))
224-
.merge(("debug", false));
218+
let figment = Config::figment_with_root(prj.root()).merge(("debug", false));
225219
let evm_opts: EvmOpts = figment.extract().unwrap();
226220
assert_eq!(evm_opts.fork_url, Some(url.to_string()));
227221
});

evm-adapters/README.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

evm-adapters/src/blocking_provider.rs

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
 (0)