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

chore: unify label map types to standard HashMap #6743

Merged
merged 1 commit into from
Jan 9, 2024
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
4 changes: 2 additions & 2 deletions crates/chisel/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use foundry_evm::{
traces::{CallTraceArena, TraceKind},
};
use revm::interpreter::{return_ok, InstructionResult};
use std::collections::BTreeMap;
use std::collections::HashMap;

/// The function selector of the REPL contract's entrypoint, the `run()` function.
static RUN_SELECTOR: [u8; 4] = [0xc0, 0x40, 0x62, 0x26];
Expand Down Expand Up @@ -44,7 +44,7 @@ pub struct ChiselResult {
/// Amount of gas used in the transaction
pub gas_used: u64,
/// Map of addresses to their labels
pub labeled_addresses: BTreeMap<Address, String>,
pub labeled_addresses: HashMap<Address, String>,
/// Return data
pub returned: Bytes,
/// Called address
Expand Down
10 changes: 5 additions & 5 deletions crates/evm/evm/src/executors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use revm::{
BlockEnv, Bytecode, Env, ExecutionResult, Output, ResultAndState, SpecId, TransactTo, TxEnv,
},
};
use std::collections::BTreeMap;
use std::collections::HashMap;

mod builder;
pub use builder::ExecutorBuilder;
Expand Down Expand Up @@ -593,7 +593,7 @@ pub struct ExecutionErr {
pub logs: Vec<Log>,
pub traces: Option<CallTraceArena>,
pub debug: Option<DebugArena>,
pub labels: BTreeMap<Address, String>,
pub labels: HashMap<Address, String>,
pub transactions: Option<BroadcastableTransactions>,
pub state_changeset: Option<StateChangeset>,
pub script_wallets: Vec<LocalWallet>,
Expand Down Expand Up @@ -653,7 +653,7 @@ pub struct CallResult {
/// The logs emitted during the call
pub logs: Vec<Log>,
/// The labels assigned to addresses during the call
pub labels: BTreeMap<Address, String>,
pub labels: HashMap<Address, String>,
/// The traces of the call
pub traces: Option<CallTraceArena>,
/// The coverage info collected during the call
Expand Down Expand Up @@ -698,7 +698,7 @@ pub struct RawCallResult {
/// The logs emitted during the call
pub logs: Vec<Log>,
/// The labels assigned to addresses during the call
pub labels: BTreeMap<Address, String>,
pub labels: HashMap<Address, String>,
/// The traces of the call
pub traces: Option<CallTraceArena>,
/// The coverage info collected during the call
Expand Down Expand Up @@ -735,7 +735,7 @@ impl Default for RawCallResult {
gas_refunded: 0,
stipend: 0,
logs: Vec::new(),
labels: BTreeMap::new(),
labels: HashMap::new(),
traces: None,
coverage: None,
debug: None,
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/evm/src/inspectors/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use revm::{
primitives::{BlockEnv, Env},
EVMData, Inspector,
};
use std::{collections::BTreeMap, sync::Arc};
use std::{collections::HashMap, sync::Arc};

#[derive(Clone, Debug, Default)]
#[must_use = "builders do nothing unless you call `build` on them"]
Expand Down Expand Up @@ -185,7 +185,7 @@ macro_rules! call_inspectors {
/// The collected results of [`InspectorStack`].
pub struct InspectorData {
pub logs: Vec<Log>,
pub labels: BTreeMap<Address, String>,
pub labels: HashMap<Address, String>,
pub traces: Option<CallTraceArena>,
pub debug: Option<DebugArena>,
pub coverage: Option<HitMaps>,
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/fuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use foundry_evm_coverage::HitMaps;
use foundry_evm_traces::CallTraceArena;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use std::{collections::BTreeMap, fmt};
use std::{collections::HashMap, fmt};

pub use proptest::test_runner::{Config as FuzzConfig, Reason};

Expand Down Expand Up @@ -143,7 +143,7 @@ pub struct FuzzTestResult {
pub decoded_logs: Vec<String>,

/// Labeled addresses
pub labeled_addresses: BTreeMap<Address, String>,
pub labeled_addresses: HashMap<Address, String>,

/// Exemplary traces for a fuzz run of the test function
///
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ pub struct ScriptResult {
pub traces: Traces,
pub debug: Option<Vec<DebugArena>>,
pub gas_used: u64,
pub labeled_addresses: BTreeMap<Address, String>,
pub labeled_addresses: HashMap<Address, String>,
pub transactions: Option<BroadcastableTransactions>,
pub returned: Bytes,
pub address: Option<Address>,
Expand Down
5 changes: 1 addition & 4 deletions crates/forge/bin/cmd/script/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ impl ScriptRunner {
returned: Bytes::new(),
success,
gas_used,
labeled_addresses: labeled_addresses
.into_iter()
.map(|l| (l.0, l.1))
.collect::<BTreeMap<_, _>>(),
labeled_addresses,
transactions,
logs,
traces,
Expand Down
12 changes: 6 additions & 6 deletions crates/forge/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use foundry_evm::{
};
use serde::{Deserialize, Serialize};
use std::{
collections::BTreeMap,
collections::{BTreeMap, HashMap},
fmt::{self, Write},
time::Duration,
};
Expand Down Expand Up @@ -127,7 +127,7 @@ pub struct TestResult {
pub coverage: Option<HitMaps>,

/// Labeled addresses
pub labeled_addresses: BTreeMap<Address, String>,
pub labeled_addresses: HashMap<Address, String>,

/// The debug nodes of the call
pub debug: Option<DebugArena>,
Expand Down Expand Up @@ -266,7 +266,7 @@ pub struct TestSetup {
/// Call traces of the setup
pub traces: Traces,
/// Addresses labeled during setup
pub labeled_addresses: BTreeMap<Address, String>,
pub labeled_addresses: HashMap<Address, String>,
/// The reason the setup failed, if it did
pub reason: Option<String>,
/// Coverage info during setup
Expand All @@ -278,7 +278,7 @@ impl TestSetup {
error: EvmError,
mut logs: Vec<Log>,
mut traces: Traces,
mut labeled_addresses: BTreeMap<Address, String>,
mut labeled_addresses: HashMap<Address, String>,
) -> Self {
match error {
EvmError::Execution(err) => {
Expand All @@ -301,7 +301,7 @@ impl TestSetup {
address: Address,
logs: Vec<Log>,
traces: Traces,
labeled_addresses: BTreeMap<Address, String>,
labeled_addresses: HashMap<Address, String>,
coverage: Option<HitMaps>,
) -> Self {
Self { address, logs, traces, labeled_addresses, reason: None, coverage }
Expand All @@ -310,7 +310,7 @@ impl TestSetup {
pub fn failed_with(
logs: Vec<Log>,
traces: Traces,
labeled_addresses: BTreeMap<Address, String>,
labeled_addresses: HashMap<Address, String>,
reason: String,
) -> Self {
Self {
Expand Down
8 changes: 4 additions & 4 deletions crates/forge/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl<'a> ContractRunner<'a> {
}
Err(err) => {
error!(reason=%err, contract=%address, "setUp failed");
(Vec::new(), None, BTreeMap::new(), Some(format!("setup failed: {err}")), None)
(Vec::new(), None, HashMap::new(), Some(format!("setup failed: {err}")), None)
}
};
traces.extend(setup_traces.map(|traces| (TraceKind::Setup, traces)));
Expand Down Expand Up @@ -563,7 +563,7 @@ impl<'a> ContractRunner<'a> {
let fuzzed_executor =
FuzzedExecutor::new(self.executor.clone(), runner.clone(), self.sender, fuzz_config);
let state = fuzzed_executor.build_fuzz_state();
let mut result = fuzzed_executor.fuzz(func, address, should_fail, self.errors);
let result = fuzzed_executor.fuzz(func, address, should_fail, self.errors);

let mut debug = Default::default();
let mut breakpoints = Default::default();
Expand Down Expand Up @@ -631,8 +631,8 @@ impl<'a> ContractRunner<'a> {
};

// Record logs, labels and traces
logs.append(&mut result.logs);
labeled_addresses.append(&mut result.labeled_addresses);
logs.extend(result.logs);
labeled_addresses.extend(result.labeled_addresses);
traces.extend(result.traces.map(|traces| (TraceKind::Execution, traces)));
coverage = merge_coverages(coverage, result.coverage);

Expand Down