Skip to content

Commit 25862e4

Browse files
committed
Create ContractsDataStore only once
1 parent 2643a34 commit 25862e4

File tree

5 files changed

+10
-18
lines changed

5 files changed

+10
-18
lines changed

crates/debugging/src/contracts_data_store.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::hash::Hash;
1414

1515
/// Data structure containing information about contracts,
1616
/// including their ABI, names, selectors and programs that will be used to create a [`Trace`](crate::Trace).
17+
#[derive(Clone)]
1718
pub struct ContractsDataStore {
1819
abi: HashMap<ClassHash, Vec<AbiEntry>>,
1920
contract_names: HashMap<ClassHash, ContractName>,

crates/debugging/src/trace/context.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::Components;
22
use crate::contracts_data_store::ContractsDataStore;
3-
use cheatnet::forking::data::ForkData;
4-
use cheatnet::runtime_extensions::forge_runtime_extension::contracts_data::ContractsData;
53

64
/// Context is a structure that holds the necessary data for creating a [`Trace`](crate::Trace).
75
pub struct Context {
@@ -12,12 +10,7 @@ pub struct Context {
1210
impl Context {
1311
/// Creates a new instance of [`Context`] from a given `cheatnet` [`ContractsData`], [`ForkData`] and [`Components`].
1412
#[must_use]
15-
pub fn new(
16-
contracts_data: &ContractsData,
17-
fork_data: &ForkData,
18-
components: Components,
19-
) -> Self {
20-
let contracts_data_store = ContractsDataStore::new(contracts_data, fork_data);
13+
pub fn new(contracts_data_store: ContractsDataStore, components: Components) -> Self {
2114
Self {
2215
contracts_data_store,
2316
components,

crates/forge-runner/src/debugging/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@ mod args;
22
mod component;
33
mod trace_verbosity;
44

5-
use cheatnet::forking::data::ForkData;
6-
use cheatnet::runtime_extensions::forge_runtime_extension::contracts_data::ContractsData;
75
use cheatnet::trace_data::CallTrace;
86

97
pub use args::TraceArgs;
8+
use debugging::ContractsDataStore;
109
pub use trace_verbosity::TraceVerbosity;
1110

1211
#[must_use]
1312
pub fn build_debugging_trace(
1413
call_trace: &CallTrace,
15-
contracts_data: &ContractsData,
14+
contracts_data_store: &ContractsDataStore,
1615
trace_args: &TraceArgs,
1716
test_name: String,
18-
fork_data: &ForkData,
1917
) -> Option<debugging::Trace> {
2018
let components = trace_args.to_components()?;
21-
let context = debugging::Context::new(contracts_data, fork_data, components);
19+
let context = debugging::Context::new(contracts_data_store.clone(), components);
2220
Some(debugging::Trace::new(call_trace, &context, test_name))
2321
}

crates/forge-runner/src/running.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use cheatnet::runtime_extensions::forge_runtime_extension::{
3030
};
3131
use cheatnet::state::{BlockInfoReader, CheatnetState, EncounteredErrors, ExtendedStateReader};
3232
use cheatnet::trace_data::CallTrace;
33+
use debugging::ContractsDataStore;
3334
use execution::finalize_execution;
3435
use hints::hints_by_representation;
3536
use rand::prelude::StdRng;
@@ -435,10 +436,9 @@ fn extract_test_case_summary(
435436
test_statistics: (),
436437
debugging_trace: build_debugging_trace(
437438
&run_error.call_trace.borrow(),
438-
contracts_data,
439+
&ContractsDataStore::new(contracts_data, &run_error.fork_data),
439440
trace_args,
440441
case.name.clone(),
441-
&run_error.fork_data,
442442
),
443443
}
444444
}

crates/forge-runner/src/test_case_summary.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,19 +294,19 @@ impl TestCaseSummary<Single> {
294294
) -> Self {
295295
let name = test_case.name.clone();
296296

297+
let contracts_data_store = ContractsDataStore::new(contracts_data, &fork_data);
297298
let debugging_trace = build_debugging_trace(
298299
&call_trace.borrow(),
299-
contracts_data,
300+
&contracts_data_store,
300301
trace_args,
301302
name.clone(),
302-
&fork_data,
303303
);
304304

305305
let gas_info = SingleTestGasInfo::new(gas_used);
306306
let gas_info = if gas_report_enabled {
307307
gas_info.get_with_report_data(
308308
&call_trace.borrow(),
309-
&ContractsDataStore::new(contracts_data, &fork_data),
309+
&contracts_data_store,
310310
)
311311
} else {
312312
gas_info

0 commit comments

Comments
 (0)