Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix debugging #445

Merged
merged 1 commit into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions cli/src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,36 +81,36 @@ impl Cmd for RunArgs {
let needs_setup = abi.functions().any(|func| func.name == "setUp");

let cfg = crate::utils::sputnik_cfg(&self.opts.compiler.evm_version);
let vicinity = self.evm_opts.vicinity()?;
let backend = self.evm_opts.backend(&vicinity)?;
let vicinity = evm_opts.vicinity()?;
let backend = evm_opts.backend(&vicinity)?;

// need to match on the backend type
let result = match backend {
BackendKind::Simple(ref backend) => {
let runner = ContractRunner::new(
&self.evm_opts,
&evm_opts,
&cfg,
backend,
&abi,
bytecode,
Some(self.evm_opts.sender),
Some(evm_opts.sender),
);
runner.run_test(&func, needs_setup, Some(&known_contracts))?
}
BackendKind::Shared(ref backend) => {
let runner = ContractRunner::new(
&self.evm_opts,
&evm_opts,
&cfg,
backend,
&abi,
bytecode,
Some(self.evm_opts.sender),
Some(evm_opts.sender),
);
runner.run_test(&func, needs_setup, Some(&known_contracts))?
}
};

if self.evm_opts.debug {
if evm_opts.debug {
// 4. Boot up debugger
let source_code: BTreeMap<u32, String> = sources
.iter()
Expand All @@ -137,9 +137,7 @@ impl Cmd for RunArgs {
})
.collect();

// let calls = evm.debug_calls();
// TODO: How should we instantiate this now that we don't have an EVM?
let calls: Vec<DebugArena> = vec![];
let calls: Vec<DebugArena> = result.debug_calls.expect("Debug must be enabled by now");
println!("debugging");
let index = if needs_setup && calls.len() > 1 { 1 } else { 0 };
let mut flattened = Vec::new();
Expand Down
10 changes: 8 additions & 2 deletions forge/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use ethers::{
abi::{Abi, Function, Token},
types::{Address, Bytes},
};
use evm_adapters::call_tracing::CallTraceArena;

use evm_adapters::{
call_tracing::CallTraceArena,
fuzz::{FuzzTestResult, FuzzedCases, FuzzedExecutor},
sputnik::cheatcodes::debugger::DebugArena,
Evm, EvmError,
};
use eyre::{Context, Result};
Expand Down Expand Up @@ -71,6 +71,10 @@ pub struct TestResult {

/// Identified contracts
pub identified_contracts: Option<BTreeMap<Address, (String, Abi)>>,

/// Debug Steps
#[serde(skip)]
pub debug_calls: Option<Vec<DebugArena>>,
}

impl TestResult {
Expand Down Expand Up @@ -319,6 +323,7 @@ impl<'a, B: Backend + Clone + Send + Sync> ContractRunner<'a, B> {
kind: TestKind::Standard(gas_used),
traces,
identified_contracts,
debug_calls: if evm.state().debug_enabled { Some(evm.debug_calls()) } else { None },
})
}

Expand Down Expand Up @@ -411,6 +416,7 @@ impl<'a, B: Backend + Clone + Send + Sync> ContractRunner<'a, B> {
kind: TestKind::Fuzz(cases),
traces,
identified_contracts,
debug_calls: if evm.state().debug_enabled { Some(evm.debug_calls()) } else { None },
})
}

Expand Down