@nomicfoundation/edr 0.12.0-next.8 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage.sol +38 -0
- package/dist/src/ts/coverage.d.ts +6 -0
- package/dist/src/ts/coverage.d.ts.map +1 -0
- package/dist/src/ts/coverage.js +51 -0
- package/dist/src/ts/coverage.js.map +1 -0
- package/index.d.ts +267 -27
- package/index.js +5 -2
- package/package.json +23 -12
- package/src/account.rs +0 -124
- package/src/block.rs +0 -28
- package/src/call_override.rs +0 -116
- package/src/cast.rs +0 -165
- package/src/chains/generic.rs +0 -58
- package/src/chains/l1.rs +0 -268
- package/src/chains/op.rs +0 -424
- package/src/chains.rs +0 -7
- package/src/config.rs +0 -700
- package/src/context.rs +0 -447
- package/src/contract_decoder.rs +0 -57
- package/src/debug_trace.rs +0 -40
- package/src/gas_report.rs +0 -92
- package/src/instrument.rs +0 -109
- package/src/lib.rs +0 -50
- package/src/log.rs +0 -28
- package/src/logger.rs +0 -120
- package/src/mock/time.rs +0 -134
- package/src/mock.rs +0 -71
- package/src/precompile.rs +0 -50
- package/src/provider/factory.rs +0 -22
- package/src/provider/response.rs +0 -73
- package/src/provider.rs +0 -162
- package/src/result.rs +0 -212
- package/src/scenarios.rs +0 -53
- package/src/serde.rs +0 -57
- package/src/solidity_tests/artifact.rs +0 -184
- package/src/solidity_tests/config.rs +0 -793
- package/src/solidity_tests/factory.rs +0 -22
- package/src/solidity_tests/l1.rs +0 -68
- package/src/solidity_tests/op.rs +0 -69
- package/src/solidity_tests/runner.rs +0 -51
- package/src/solidity_tests/test_results.rs +0 -736
- package/src/solidity_tests.rs +0 -56
- package/src/subscription.rs +0 -32
- package/src/trace/debug.rs +0 -61
- package/src/trace/exit.rs +0 -89
- package/src/trace/library_utils.rs +0 -11
- package/src/trace/model.rs +0 -59
- package/src/trace/return_data.rs +0 -96
- package/src/trace/solidity_stack_trace.rs +0 -869
- package/src/trace.rs +0 -199
- package/src/ts/solidity_tests.ts +0 -46
- package/src/withdrawal.rs +0 -49
package/src/context.rs
DELETED
|
@@ -1,447 +0,0 @@
|
|
|
1
|
-
use std::sync::Arc;
|
|
2
|
-
|
|
3
|
-
use edr_napi_core::{provider::SyncProviderFactory, solidity};
|
|
4
|
-
use edr_primitives::HashMap;
|
|
5
|
-
use edr_solidity_tests::{
|
|
6
|
-
decode::RevertDecoder,
|
|
7
|
-
multi_runner::{SuiteResultAndArtifactId, TestContract, TestContracts},
|
|
8
|
-
TestFilterConfig,
|
|
9
|
-
};
|
|
10
|
-
use napi::{
|
|
11
|
-
threadsafe_function::{
|
|
12
|
-
ErrorStrategy, ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode,
|
|
13
|
-
},
|
|
14
|
-
tokio::{runtime, sync::Mutex as AsyncMutex},
|
|
15
|
-
Env, JsFunction, JsObject,
|
|
16
|
-
};
|
|
17
|
-
use napi_derive::napi;
|
|
18
|
-
use tracing_subscriber::{prelude::*, EnvFilter, Registry};
|
|
19
|
-
|
|
20
|
-
use crate::{
|
|
21
|
-
config::{resolve_configs, ConfigResolution, ProviderConfig, TracingConfigWithBuffers},
|
|
22
|
-
contract_decoder::ContractDecoder,
|
|
23
|
-
logger::LoggerConfig,
|
|
24
|
-
provider::{Provider, ProviderFactory},
|
|
25
|
-
solidity_tests::{
|
|
26
|
-
artifact::{Artifact, ArtifactId},
|
|
27
|
-
config::SolidityTestRunnerConfigArgs,
|
|
28
|
-
factory::SolidityTestRunnerFactory,
|
|
29
|
-
test_results::{SolidityTestResult, SuiteResult},
|
|
30
|
-
LinkingOutput,
|
|
31
|
-
},
|
|
32
|
-
subscription::SubscriptionConfig,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
#[napi]
|
|
36
|
-
pub struct EdrContext {
|
|
37
|
-
inner: Arc<AsyncMutex<Context>>,
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
#[napi]
|
|
41
|
-
impl EdrContext {
|
|
42
|
-
/// Creates a new [`EdrContext`] instance. Should only be called once!
|
|
43
|
-
#[napi(catch_unwind, constructor)]
|
|
44
|
-
pub fn new() -> napi::Result<Self> {
|
|
45
|
-
let context = Context::new()?;
|
|
46
|
-
|
|
47
|
-
Ok(Self {
|
|
48
|
-
inner: Arc::new(AsyncMutex::new(context)),
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/// Constructs a new provider with the provided configuration.
|
|
53
|
-
#[napi(catch_unwind, ts_return_type = "Promise<Provider>")]
|
|
54
|
-
pub fn create_provider(
|
|
55
|
-
&self,
|
|
56
|
-
env: Env,
|
|
57
|
-
chain_type: String,
|
|
58
|
-
provider_config: ProviderConfig,
|
|
59
|
-
logger_config: LoggerConfig,
|
|
60
|
-
subscription_config: SubscriptionConfig,
|
|
61
|
-
contract_decoder: &ContractDecoder,
|
|
62
|
-
) -> napi::Result<JsObject> {
|
|
63
|
-
let (deferred, promise) = env.create_deferred()?;
|
|
64
|
-
|
|
65
|
-
macro_rules! try_or_reject_promise {
|
|
66
|
-
($expr:expr) => {
|
|
67
|
-
match $expr {
|
|
68
|
-
Ok(value) => value,
|
|
69
|
-
Err(error) => {
|
|
70
|
-
deferred.reject(error);
|
|
71
|
-
return Ok(promise);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
let runtime = runtime::Handle::current();
|
|
78
|
-
|
|
79
|
-
let ConfigResolution {
|
|
80
|
-
logger_config,
|
|
81
|
-
provider_config,
|
|
82
|
-
subscription_callback,
|
|
83
|
-
} = try_or_reject_promise!(resolve_configs(
|
|
84
|
-
&env,
|
|
85
|
-
runtime.clone(),
|
|
86
|
-
provider_config,
|
|
87
|
-
logger_config,
|
|
88
|
-
subscription_config,
|
|
89
|
-
));
|
|
90
|
-
|
|
91
|
-
#[cfg(feature = "scenarios")]
|
|
92
|
-
let scenario_file =
|
|
93
|
-
try_or_reject_promise!(runtime.clone().block_on(crate::scenarios::scenario_file(
|
|
94
|
-
chain_type.clone(),
|
|
95
|
-
provider_config.clone(),
|
|
96
|
-
logger_config.enable,
|
|
97
|
-
)));
|
|
98
|
-
|
|
99
|
-
let factory = {
|
|
100
|
-
// TODO: https://github.com/NomicFoundation/edr/issues/760
|
|
101
|
-
// TODO: Don't block the JS event loop
|
|
102
|
-
let context = runtime.block_on(async { self.inner.lock().await });
|
|
103
|
-
|
|
104
|
-
try_or_reject_promise!(context.get_provider_factory(&chain_type))
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
let contract_decoder = Arc::clone(contract_decoder.as_inner());
|
|
108
|
-
runtime.clone().spawn_blocking(move || {
|
|
109
|
-
let result = factory
|
|
110
|
-
.create_provider(
|
|
111
|
-
runtime.clone(),
|
|
112
|
-
provider_config,
|
|
113
|
-
logger_config,
|
|
114
|
-
subscription_callback,
|
|
115
|
-
Arc::clone(&contract_decoder),
|
|
116
|
-
)
|
|
117
|
-
.map(|provider| {
|
|
118
|
-
Provider::new(
|
|
119
|
-
provider,
|
|
120
|
-
runtime,
|
|
121
|
-
contract_decoder,
|
|
122
|
-
#[cfg(feature = "scenarios")]
|
|
123
|
-
scenario_file,
|
|
124
|
-
)
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
deferred.resolve(|_env| result);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
Ok(promise)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/// Registers a new provider factory for the provided chain type.
|
|
134
|
-
#[napi(catch_unwind)]
|
|
135
|
-
pub async fn register_provider_factory(
|
|
136
|
-
&self,
|
|
137
|
-
chain_type: String,
|
|
138
|
-
factory: &ProviderFactory,
|
|
139
|
-
) -> napi::Result<()> {
|
|
140
|
-
let mut context = self.inner.lock().await;
|
|
141
|
-
context.register_provider_factory(chain_type, factory.as_inner().clone());
|
|
142
|
-
Ok(())
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
#[napi(catch_unwind)]
|
|
146
|
-
pub async fn register_solidity_test_runner_factory(
|
|
147
|
-
&self,
|
|
148
|
-
chain_type: String,
|
|
149
|
-
factory: &SolidityTestRunnerFactory,
|
|
150
|
-
) -> napi::Result<()> {
|
|
151
|
-
let mut context = self.inner.lock().await;
|
|
152
|
-
context.register_solidity_test_runner(chain_type, factory.as_inner().clone());
|
|
153
|
-
Ok(())
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/// Executes Solidity tests
|
|
157
|
-
///
|
|
158
|
-
/// The function will return a promise that resolves to a
|
|
159
|
-
/// [`SolidityTestResult`].
|
|
160
|
-
///
|
|
161
|
-
/// Arguments:
|
|
162
|
-
/// - `chainType`: the same chain type that was passed to
|
|
163
|
-
/// `registerProviderFactory`.
|
|
164
|
-
/// - `artifacts`: the project's compilation output artifacts. It's
|
|
165
|
-
/// important to include include all artifacts here, otherwise cheatcodes
|
|
166
|
-
/// that access artifacts and other functionality (e.g. auto-linking, gas
|
|
167
|
-
/// reports) can break.
|
|
168
|
-
/// - `testSuites`: the test suite ids that specify which test suites to
|
|
169
|
-
/// execute. The test suite artifacts must be present in `artifacts`.
|
|
170
|
-
/// - `configArgs`: solidity test runner configuration. See the struct docs
|
|
171
|
-
/// for details.
|
|
172
|
-
/// - `tracingConfig`: the build infos used for stack trace generation.
|
|
173
|
-
/// These are lazily parsed and it's important that they're passed as
|
|
174
|
-
/// Uint8 arrays for performance.
|
|
175
|
-
/// - `onTestSuiteCompletedCallback`: The progress callback will be called
|
|
176
|
-
/// with the results of each test suite as soon as it finished executing.
|
|
177
|
-
#[allow(clippy::too_many_arguments)]
|
|
178
|
-
#[napi(catch_unwind, ts_return_type = "Promise<SolidityTestResult>")]
|
|
179
|
-
pub fn run_solidity_tests(
|
|
180
|
-
&self,
|
|
181
|
-
env: Env,
|
|
182
|
-
chain_type: String,
|
|
183
|
-
artifacts: Vec<Artifact>,
|
|
184
|
-
test_suites: Vec<ArtifactId>,
|
|
185
|
-
config_args: SolidityTestRunnerConfigArgs,
|
|
186
|
-
tracing_config: TracingConfigWithBuffers,
|
|
187
|
-
#[napi(ts_arg_type = "(result: SuiteResult) => void")]
|
|
188
|
-
on_test_suite_completed_callback: JsFunction,
|
|
189
|
-
) -> napi::Result<JsObject> {
|
|
190
|
-
let (deferred, promise) = env.create_deferred()?;
|
|
191
|
-
|
|
192
|
-
let on_test_suite_completed_callback: ThreadsafeFunction<_, ErrorStrategy::Fatal> =
|
|
193
|
-
match on_test_suite_completed_callback.create_threadsafe_function(
|
|
194
|
-
// Unbounded queue size
|
|
195
|
-
0,
|
|
196
|
-
|ctx: ThreadSafeCallContext<SuiteResult>| Ok(vec![ctx.value]),
|
|
197
|
-
) {
|
|
198
|
-
Ok(value) => value,
|
|
199
|
-
Err(error) => {
|
|
200
|
-
deferred.reject(error);
|
|
201
|
-
return Ok(promise);
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
let test_filter: Arc<TestFilterConfig> =
|
|
206
|
-
Arc::new(match config_args.try_get_test_filter() {
|
|
207
|
-
Ok(test_filter) => test_filter,
|
|
208
|
-
Err(error) => {
|
|
209
|
-
deferred.reject(error);
|
|
210
|
-
return Ok(promise);
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
let runtime = runtime::Handle::current();
|
|
215
|
-
let config = match config_args.resolve(&env, runtime.clone()) {
|
|
216
|
-
Ok(config) => config,
|
|
217
|
-
Err(error) => {
|
|
218
|
-
deferred.reject(error);
|
|
219
|
-
return Ok(promise);
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
let context = self.inner.clone();
|
|
224
|
-
runtime.clone().spawn(async move {
|
|
225
|
-
macro_rules! try_or_reject_deferred {
|
|
226
|
-
($expr:expr) => {
|
|
227
|
-
match $expr {
|
|
228
|
-
Ok(value) => value,
|
|
229
|
-
Err(error) => {
|
|
230
|
-
deferred.reject(error);
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
let factory = {
|
|
237
|
-
let context = context.lock().await;
|
|
238
|
-
try_or_reject_deferred!(context.solidity_test_runner_factory(&chain_type).await)
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
let linking_output =
|
|
242
|
-
try_or_reject_deferred!(LinkingOutput::link(&config.project_root, artifacts));
|
|
243
|
-
|
|
244
|
-
// Build revert decoder from ABIs of all artifacts.
|
|
245
|
-
let abis = linking_output
|
|
246
|
-
.known_contracts
|
|
247
|
-
.iter()
|
|
248
|
-
.map(|(_, contract)| &contract.abi);
|
|
249
|
-
|
|
250
|
-
let revert_decoder = RevertDecoder::new().with_abis(abis);
|
|
251
|
-
|
|
252
|
-
let test_suites = try_or_reject_deferred!(test_suites
|
|
253
|
-
.into_iter()
|
|
254
|
-
.map(edr_solidity::artifacts::ArtifactId::try_from)
|
|
255
|
-
.collect::<Result<Vec<_>, _>>());
|
|
256
|
-
|
|
257
|
-
let contracts = try_or_reject_deferred!(test_suites
|
|
258
|
-
.iter()
|
|
259
|
-
.map(|artifact_id| {
|
|
260
|
-
let contract_data = linking_output
|
|
261
|
-
.known_contracts
|
|
262
|
-
.get(artifact_id)
|
|
263
|
-
.ok_or_else(|| {
|
|
264
|
-
napi::Error::new(
|
|
265
|
-
napi::Status::GenericFailure,
|
|
266
|
-
format!("Unknown contract: {}", artifact_id.identifier()),
|
|
267
|
-
)
|
|
268
|
-
})?;
|
|
269
|
-
|
|
270
|
-
let bytecode = contract_data.bytecode.clone().ok_or_else(|| {
|
|
271
|
-
napi::Error::new(
|
|
272
|
-
napi::Status::GenericFailure,
|
|
273
|
-
format!(
|
|
274
|
-
"No bytecode for test suite contract: {}",
|
|
275
|
-
artifact_id.identifier()
|
|
276
|
-
),
|
|
277
|
-
)
|
|
278
|
-
})?;
|
|
279
|
-
|
|
280
|
-
let test_contract = TestContract {
|
|
281
|
-
abi: contract_data.abi.clone(),
|
|
282
|
-
bytecode,
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
Ok((artifact_id.clone(), test_contract))
|
|
286
|
-
})
|
|
287
|
-
.collect::<napi::Result<TestContracts>>());
|
|
288
|
-
|
|
289
|
-
let include_traces = config.include_traces.into();
|
|
290
|
-
|
|
291
|
-
let runtime_for_factory = runtime.clone();
|
|
292
|
-
let test_runner = try_or_reject_deferred!(runtime
|
|
293
|
-
.clone()
|
|
294
|
-
.spawn_blocking(move || {
|
|
295
|
-
factory.create_test_runner(
|
|
296
|
-
runtime_for_factory,
|
|
297
|
-
config,
|
|
298
|
-
contracts,
|
|
299
|
-
linking_output.known_contracts,
|
|
300
|
-
linking_output.libs_to_deploy,
|
|
301
|
-
revert_decoder,
|
|
302
|
-
tracing_config.into(),
|
|
303
|
-
)
|
|
304
|
-
})
|
|
305
|
-
.await
|
|
306
|
-
.expect("Failed to join test runner factory thread"));
|
|
307
|
-
|
|
308
|
-
let runtime_for_runner = runtime.clone();
|
|
309
|
-
let test_result = try_or_reject_deferred!(runtime
|
|
310
|
-
.clone()
|
|
311
|
-
.spawn_blocking(move || {
|
|
312
|
-
test_runner.run_tests(
|
|
313
|
-
runtime_for_runner,
|
|
314
|
-
test_filter,
|
|
315
|
-
Arc::new(
|
|
316
|
-
move |SuiteResultAndArtifactId {
|
|
317
|
-
artifact_id,
|
|
318
|
-
result,
|
|
319
|
-
}| {
|
|
320
|
-
let suite_result =
|
|
321
|
-
SuiteResult::new(artifact_id, result, include_traces);
|
|
322
|
-
|
|
323
|
-
let status = on_test_suite_completed_callback
|
|
324
|
-
.call(suite_result, ThreadsafeFunctionCallMode::Blocking);
|
|
325
|
-
|
|
326
|
-
// This should always succeed since we're using an unbounded queue.
|
|
327
|
-
// We add an assertion for
|
|
328
|
-
// completeness.
|
|
329
|
-
assert_eq!(
|
|
330
|
-
status,
|
|
331
|
-
napi::Status::Ok,
|
|
332
|
-
"Failed to call on_test_suite_completed_callback with status: {status}"
|
|
333
|
-
);
|
|
334
|
-
},
|
|
335
|
-
),
|
|
336
|
-
)
|
|
337
|
-
})
|
|
338
|
-
.await
|
|
339
|
-
.expect("Failed to join test runner thread"));
|
|
340
|
-
|
|
341
|
-
deferred.resolve(move |_env| Ok(SolidityTestResult::from(test_result)));
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
Ok(promise)
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
pub struct Context {
|
|
349
|
-
provider_factories: HashMap<String, Arc<dyn SyncProviderFactory>>,
|
|
350
|
-
solidity_test_runner_factories: HashMap<String, Arc<dyn solidity::SyncTestRunnerFactory>>,
|
|
351
|
-
#[cfg(feature = "tracing")]
|
|
352
|
-
_tracing_write_guard: tracing_flame::FlushGuard<std::io::BufWriter<std::fs::File>>,
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
impl Context {
|
|
356
|
-
/// Creates a new [`Context`] instance. Should only be called once!
|
|
357
|
-
pub fn new() -> napi::Result<Self> {
|
|
358
|
-
let fmt_layer = tracing_subscriber::fmt::layer()
|
|
359
|
-
.with_file(true)
|
|
360
|
-
.with_line_number(true)
|
|
361
|
-
.with_thread_ids(true)
|
|
362
|
-
.with_target(false)
|
|
363
|
-
.with_level(true)
|
|
364
|
-
.with_filter(EnvFilter::from_default_env());
|
|
365
|
-
|
|
366
|
-
let subscriber = Registry::default().with(fmt_layer);
|
|
367
|
-
|
|
368
|
-
#[cfg(feature = "tracing")]
|
|
369
|
-
let (flame_layer, guard) = {
|
|
370
|
-
let (flame_layer, guard) = tracing_flame::FlameLayer::with_file("tracing.folded")
|
|
371
|
-
.map_err(|err| {
|
|
372
|
-
napi::Error::new(
|
|
373
|
-
napi::Status::GenericFailure,
|
|
374
|
-
format!("Failed to create tracing.folded file with error: {err:?}"),
|
|
375
|
-
)
|
|
376
|
-
})?;
|
|
377
|
-
|
|
378
|
-
let flame_layer = flame_layer.with_empty_samples(false);
|
|
379
|
-
(flame_layer, guard)
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
#[cfg(feature = "tracing")]
|
|
383
|
-
let subscriber = subscriber.with(flame_layer);
|
|
384
|
-
|
|
385
|
-
if let Err(error) = tracing::subscriber::set_global_default(subscriber) {
|
|
386
|
-
println!(
|
|
387
|
-
"Failed to set global tracing subscriber with error: {error}\n\
|
|
388
|
-
Please only initialize EdrContext once per process to avoid this error."
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
Ok(Self {
|
|
393
|
-
provider_factories: HashMap::new(),
|
|
394
|
-
solidity_test_runner_factories: HashMap::new(),
|
|
395
|
-
#[cfg(feature = "tracing")]
|
|
396
|
-
_tracing_write_guard: guard,
|
|
397
|
-
})
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/// Registers a new provider factory for the provided chain type.
|
|
401
|
-
pub fn register_provider_factory(
|
|
402
|
-
&mut self,
|
|
403
|
-
chain_type: String,
|
|
404
|
-
factory: Arc<dyn SyncProviderFactory>,
|
|
405
|
-
) {
|
|
406
|
-
self.provider_factories.insert(chain_type, factory);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
pub fn register_solidity_test_runner(
|
|
410
|
-
&mut self,
|
|
411
|
-
chain_type: String,
|
|
412
|
-
factory: Arc<dyn solidity::SyncTestRunnerFactory>,
|
|
413
|
-
) {
|
|
414
|
-
self.solidity_test_runner_factories
|
|
415
|
-
.insert(chain_type, factory);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/// Tries to create a new provider for the provided chain type and
|
|
419
|
-
/// configuration.
|
|
420
|
-
pub fn get_provider_factory(
|
|
421
|
-
&self,
|
|
422
|
-
chain_type: &str,
|
|
423
|
-
) -> napi::Result<Arc<dyn SyncProviderFactory>> {
|
|
424
|
-
if let Some(factory) = self.provider_factories.get(chain_type) {
|
|
425
|
-
Ok(Arc::clone(factory))
|
|
426
|
-
} else {
|
|
427
|
-
Err(napi::Error::new(
|
|
428
|
-
napi::Status::GenericFailure,
|
|
429
|
-
"Provider for provided chain type does not exist",
|
|
430
|
-
))
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
pub async fn solidity_test_runner_factory(
|
|
435
|
-
&self,
|
|
436
|
-
chain_type: &str,
|
|
437
|
-
) -> napi::Result<Arc<dyn solidity::SyncTestRunnerFactory>> {
|
|
438
|
-
if let Some(factory) = self.solidity_test_runner_factories.get(chain_type) {
|
|
439
|
-
Ok(Arc::clone(factory))
|
|
440
|
-
} else {
|
|
441
|
-
Err(napi::Error::new(
|
|
442
|
-
napi::Status::GenericFailure,
|
|
443
|
-
"Solidity test runner for provided chain type does not exist",
|
|
444
|
-
))
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
package/src/contract_decoder.rs
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
use std::sync::Arc;
|
|
2
|
-
|
|
3
|
-
use napi_derive::napi;
|
|
4
|
-
|
|
5
|
-
use crate::config::TracingConfigWithBuffers;
|
|
6
|
-
|
|
7
|
-
#[napi]
|
|
8
|
-
pub struct ContractDecoder {
|
|
9
|
-
inner: Arc<edr_solidity::contract_decoder::ContractDecoder>,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
#[napi]
|
|
13
|
-
impl ContractDecoder {
|
|
14
|
-
#[doc = "Creates an empty instance."]
|
|
15
|
-
#[napi(constructor, catch_unwind)]
|
|
16
|
-
// Following TS convention for the constructor without arguments to be `new()`.
|
|
17
|
-
#[allow(clippy::new_without_default)]
|
|
18
|
-
pub fn new() -> Self {
|
|
19
|
-
Self {
|
|
20
|
-
inner: Arc::new(edr_solidity::contract_decoder::ContractDecoder::default()),
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
#[doc = "Creates a new instance with the provided configuration."]
|
|
25
|
-
#[napi(factory, catch_unwind)]
|
|
26
|
-
pub fn with_contracts(config: TracingConfigWithBuffers) -> napi::Result<Self> {
|
|
27
|
-
let build_info_config = edr_solidity::artifacts::BuildInfoConfig::parse_from_buffers(
|
|
28
|
-
(&edr_napi_core::solidity::config::TracingConfigWithBuffers::from(config)).into(),
|
|
29
|
-
)
|
|
30
|
-
.map_err(|error| napi::Error::from_reason(error.to_string()))?;
|
|
31
|
-
|
|
32
|
-
let contract_decoder =
|
|
33
|
-
edr_solidity::contract_decoder::ContractDecoder::new(&build_info_config).map_or_else(
|
|
34
|
-
|error| Err(napi::Error::from_reason(error.to_string())),
|
|
35
|
-
|contract_decoder| Ok(Arc::new(contract_decoder)),
|
|
36
|
-
)?;
|
|
37
|
-
|
|
38
|
-
Ok(Self {
|
|
39
|
-
inner: contract_decoder,
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
impl ContractDecoder {
|
|
45
|
-
/// Returns a reference to the inner contract decoder.
|
|
46
|
-
pub fn as_inner(&self) -> &Arc<edr_solidity::contract_decoder::ContractDecoder> {
|
|
47
|
-
&self.inner
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
impl From<Arc<edr_solidity::contract_decoder::ContractDecoder>> for ContractDecoder {
|
|
52
|
-
fn from(contract_decoder: Arc<edr_solidity::contract_decoder::ContractDecoder>) -> Self {
|
|
53
|
-
Self {
|
|
54
|
-
inner: contract_decoder,
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
package/src/debug_trace.rs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
use std::collections::HashMap;
|
|
2
|
-
|
|
3
|
-
use napi::bindgen_prelude::{BigInt, Uint8Array};
|
|
4
|
-
use napi_derive::napi;
|
|
5
|
-
|
|
6
|
-
// False positive: imported by HH2
|
|
7
|
-
#[allow(dead_code)]
|
|
8
|
-
#[napi(object)]
|
|
9
|
-
pub struct DebugTraceResult {
|
|
10
|
-
pub pass: bool,
|
|
11
|
-
pub gas_used: BigInt,
|
|
12
|
-
pub output: Option<Uint8Array>,
|
|
13
|
-
pub struct_logs: Vec<DebugTraceLogItem>,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
#[napi(object)]
|
|
17
|
-
pub struct DebugTraceLogItem {
|
|
18
|
-
/// Program Counter
|
|
19
|
-
pub pc: BigInt,
|
|
20
|
-
// Op code
|
|
21
|
-
pub op: u8,
|
|
22
|
-
/// Gas left before executing this operation as hex number.
|
|
23
|
-
pub gas: String,
|
|
24
|
-
/// Gas cost of this operation as hex number.
|
|
25
|
-
pub gas_cost: String,
|
|
26
|
-
/// Array of all values (hex numbers) on the stack
|
|
27
|
-
pub stack: Option<Vec<String>>,
|
|
28
|
-
/// Depth of the call stack
|
|
29
|
-
pub depth: BigInt,
|
|
30
|
-
/// Size of memory array
|
|
31
|
-
pub mem_size: BigInt,
|
|
32
|
-
/// Name of the operation
|
|
33
|
-
pub op_name: String,
|
|
34
|
-
/// Description of an error as a hex string.
|
|
35
|
-
pub error: Option<String>,
|
|
36
|
-
/// Array of all allocated values as hex strings.
|
|
37
|
-
pub memory: Option<Vec<String>>,
|
|
38
|
-
/// Map of all stored values with keys and values encoded as hex strings.
|
|
39
|
-
pub storage: Option<HashMap<String, String>>,
|
|
40
|
-
}
|
package/src/gas_report.rs
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
use std::collections::HashMap;
|
|
2
|
-
|
|
3
|
-
use napi::bindgen_prelude::BigInt;
|
|
4
|
-
use napi_derive::napi;
|
|
5
|
-
|
|
6
|
-
#[napi(object)]
|
|
7
|
-
pub struct GasReport {
|
|
8
|
-
pub contracts: HashMap<String, ContractGasReport>,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
#[napi(object)]
|
|
12
|
-
pub struct ContractGasReport {
|
|
13
|
-
pub deployments: Vec<DeploymentGasReport>,
|
|
14
|
-
pub functions: HashMap<String, Vec<FunctionGasReport>>,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
#[napi]
|
|
18
|
-
pub enum GasReportExecutionStatus {
|
|
19
|
-
Success,
|
|
20
|
-
Revert,
|
|
21
|
-
Halt,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
#[napi(object)]
|
|
25
|
-
pub struct DeploymentGasReport {
|
|
26
|
-
pub gas: BigInt,
|
|
27
|
-
pub size: BigInt,
|
|
28
|
-
pub status: GasReportExecutionStatus,
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
#[napi(object)]
|
|
32
|
-
pub struct FunctionGasReport {
|
|
33
|
-
pub gas: BigInt,
|
|
34
|
-
pub status: GasReportExecutionStatus,
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
impl From<edr_gas_report::GasReport> for GasReport {
|
|
38
|
-
fn from(value: edr_gas_report::GasReport) -> Self {
|
|
39
|
-
Self {
|
|
40
|
-
contracts: value
|
|
41
|
-
.into_inner()
|
|
42
|
-
.into_iter()
|
|
43
|
-
.map(|(k, v)| (k, v.into()))
|
|
44
|
-
.collect(),
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
impl From<edr_gas_report::ContractGasReport> for ContractGasReport {
|
|
50
|
-
fn from(value: edr_gas_report::ContractGasReport) -> Self {
|
|
51
|
-
Self {
|
|
52
|
-
deployments: value.deployments.into_iter().map(Into::into).collect(),
|
|
53
|
-
functions: value
|
|
54
|
-
.functions
|
|
55
|
-
.into_iter()
|
|
56
|
-
.map(|(k, v)| {
|
|
57
|
-
let function_reports = v.into_iter().map(FunctionGasReport::from).collect();
|
|
58
|
-
(k, function_reports)
|
|
59
|
-
})
|
|
60
|
-
.collect(),
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
impl From<edr_gas_report::GasReportExecutionStatus> for GasReportExecutionStatus {
|
|
66
|
-
fn from(value: edr_gas_report::GasReportExecutionStatus) -> Self {
|
|
67
|
-
match value {
|
|
68
|
-
edr_gas_report::GasReportExecutionStatus::Success => Self::Success,
|
|
69
|
-
edr_gas_report::GasReportExecutionStatus::Revert => Self::Revert,
|
|
70
|
-
edr_gas_report::GasReportExecutionStatus::Halt => Self::Halt,
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
impl From<edr_gas_report::DeploymentGasReport> for DeploymentGasReport {
|
|
76
|
-
fn from(value: edr_gas_report::DeploymentGasReport) -> Self {
|
|
77
|
-
Self {
|
|
78
|
-
gas: BigInt::from(value.gas),
|
|
79
|
-
size: BigInt::from(value.size),
|
|
80
|
-
status: value.status.into(),
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
impl From<edr_gas_report::FunctionGasReport> for FunctionGasReport {
|
|
86
|
-
fn from(value: edr_gas_report::FunctionGasReport) -> Self {
|
|
87
|
-
Self {
|
|
88
|
-
gas: BigInt::from(value.gas),
|
|
89
|
-
status: value.status.into(),
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|