Skip to content

Commit

Permalink
add traces to test fails
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Nov 17, 2023
1 parent a497506 commit ef4cdcf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
17 changes: 8 additions & 9 deletions crates/forge/tests/it/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ use foundry_evm::{
decode::decode_console_logs, inspectors::CheatsConfig, revm::primitives::SpecId,
};
use foundry_test_utils::Filter;
use std::{
collections::BTreeMap,
path::{Path, PathBuf},
};
use itertools::Itertools;
use std::{collections::BTreeMap, path::Path};

/// How to execute a a test run
pub struct TestConfig {
Expand Down Expand Up @@ -82,11 +80,12 @@ impl TestConfig {
let outcome = if self.should_fail { "fail" } else { "pass" };

eyre::bail!(
"Test {} did not {} as expected.\nReason: {:?}\nLogs:\n{}",
"Test {} did not {} as expected.\nReason: {:?}\nLogs:\n{}\n\nTraces:\n{}",
test_name,
outcome,
result.reason,
logs.join("\n")
logs.join("\n"),
result.traces.iter().map(|(_, a)| a).format("\n"),
)
}
}
Expand Down Expand Up @@ -136,14 +135,14 @@ pub(crate) fn init_tracing() {
.try_init();
}

pub fn manifest_root() -> PathBuf {
pub fn manifest_root() -> &'static Path {
let mut root = Path::new(env!("CARGO_MANIFEST_DIR"));
// need to check here where we're executing the test from, if in `forge` we need to also allow
// `testdata`
if root.ends_with("forge") {
root = root.parent().unwrap();
}
root.to_path_buf()
root
}

/// Builds a base runner
Expand All @@ -161,7 +160,7 @@ pub async fn runner() -> MultiContractRunner {
/// Builds a non-tracing runner
pub async fn runner_with_config(mut config: Config) -> MultiContractRunner {
config.rpc_endpoints = rpc_endpoints();
config.allow_paths.push(manifest_root());
config.allow_paths.push(manifest_root().to_path_buf());

let root = &PROJECT.paths.root;
let opts = &*EVM_OPTS;
Expand Down
1 change: 1 addition & 0 deletions crates/forge/tests/it/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub static EVM_OPTS: Lazy<EvmOpts> = Lazy::new(|| EvmOpts {
sender: Config::DEFAULT_SENDER,
initial_balance: U256::MAX,
ffi: true,
verbosity: 3,
..Default::default()
});

Expand Down
8 changes: 4 additions & 4 deletions testdata/foundry.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[profile.default]
solc = "0.8.19"
solc = "0.8.18"
block_base_fee_per_gas = 0
block_coinbase = "0x0000000000000000000000000000000000000000"
block_difficulty = 0
Expand Down Expand Up @@ -36,10 +36,10 @@ remappings = ["ds-test/=lib/ds-test/src/"]
sender = "0x00a329c0648769a73afac7f9381e08fb43dbea72"
sizes = false
sparse_mode = false
src = "src"
test = "test"
src = "./"
test = "./"
tx_origin = "0x00a329c0648769a73afac7f9381e08fb43dbea72"
verbosity = 0
verbosity = 3
via_ir = false
fs_permissions = [{ access = "read-write", path = "./" }]

Expand Down

0 comments on commit ef4cdcf

Please sign in to comment.