@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/instrument.rs
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
use edr_instrument::coverage::{self, Version};
|
|
2
|
-
use napi::bindgen_prelude::Uint8Array;
|
|
3
|
-
use napi_derive::napi;
|
|
4
|
-
|
|
5
|
-
#[napi(object)]
|
|
6
|
-
pub struct InstrumentationResult {
|
|
7
|
-
/// The generated source code with coverage instrumentation.
|
|
8
|
-
#[napi(readonly)]
|
|
9
|
-
pub source: String,
|
|
10
|
-
/// The metadata for each instrumented code segment.
|
|
11
|
-
#[napi(readonly)]
|
|
12
|
-
pub metadata: Vec<InstrumentationMetadata>,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
impl TryFrom<edr_instrument::coverage::InstrumentationResult> for InstrumentationResult {
|
|
16
|
-
type Error = usize;
|
|
17
|
-
|
|
18
|
-
fn try_from(
|
|
19
|
-
value: edr_instrument::coverage::InstrumentationResult,
|
|
20
|
-
) -> Result<Self, Self::Error> {
|
|
21
|
-
let metadata = value
|
|
22
|
-
.metadata
|
|
23
|
-
.into_iter()
|
|
24
|
-
.map(InstrumentationMetadata::try_from)
|
|
25
|
-
.collect::<Result<Vec<_>, _>>()?;
|
|
26
|
-
|
|
27
|
-
Ok(InstrumentationResult {
|
|
28
|
-
source: value.source,
|
|
29
|
-
metadata,
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
#[napi(object)]
|
|
35
|
-
pub struct InstrumentationMetadata {
|
|
36
|
-
/// The tag that identifies the instrumented code. Tags are
|
|
37
|
-
/// deterministically generated from the source code, source id, and
|
|
38
|
-
/// Solidity version.
|
|
39
|
-
#[napi(readonly)]
|
|
40
|
-
pub tag: Uint8Array,
|
|
41
|
-
/// The kind of instrumented code. Currently, the only supported kind
|
|
42
|
-
/// is "statement".
|
|
43
|
-
#[napi(readonly)]
|
|
44
|
-
pub kind: String,
|
|
45
|
-
/// The starting position of the instrumented code - including trivia such
|
|
46
|
-
/// as whitespace - in the source code, in UTF-16 code units.
|
|
47
|
-
#[napi(readonly)]
|
|
48
|
-
pub start_utf16: i64,
|
|
49
|
-
/// The ending position of the instrumented code - including trivia such as
|
|
50
|
-
/// whitespace - in the source code, in UTF-16 code units.
|
|
51
|
-
#[napi(readonly)]
|
|
52
|
-
pub end_utf16: i64,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
impl TryFrom<edr_instrument::coverage::InstrumentationMetadata> for InstrumentationMetadata {
|
|
56
|
-
type Error = usize;
|
|
57
|
-
|
|
58
|
-
fn try_from(
|
|
59
|
-
value: edr_instrument::coverage::InstrumentationMetadata,
|
|
60
|
-
) -> Result<Self, Self::Error> {
|
|
61
|
-
let start_utf16 = value
|
|
62
|
-
.start_utf16
|
|
63
|
-
.try_into()
|
|
64
|
-
.map_err(|_error| value.start_utf16)?;
|
|
65
|
-
let end_utf16 = value
|
|
66
|
-
.end_utf16
|
|
67
|
-
.try_into()
|
|
68
|
-
.map_err(|_error| value.end_utf16)?;
|
|
69
|
-
|
|
70
|
-
Ok(InstrumentationMetadata {
|
|
71
|
-
tag: Uint8Array::with_data_copied(value.tag),
|
|
72
|
-
kind: value.kind.to_owned(),
|
|
73
|
-
start_utf16,
|
|
74
|
-
end_utf16,
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/// Adds per-statement coverage instrumentation to the given Solidity source
|
|
80
|
-
/// code.
|
|
81
|
-
#[napi(catch_unwind)]
|
|
82
|
-
pub fn add_statement_coverage_instrumentation(
|
|
83
|
-
source_code: String,
|
|
84
|
-
source_id: String,
|
|
85
|
-
solidity_version: String,
|
|
86
|
-
coverage_library_path: String,
|
|
87
|
-
) -> napi::Result<InstrumentationResult> {
|
|
88
|
-
let solidity_version = Version::parse(&solidity_version).map_err(|error| {
|
|
89
|
-
napi::Error::new(
|
|
90
|
-
napi::Status::InvalidArg,
|
|
91
|
-
format!("Invalid Solidity version: {error}"),
|
|
92
|
-
)
|
|
93
|
-
})?;
|
|
94
|
-
|
|
95
|
-
let instrumented = coverage::instrument_code(
|
|
96
|
-
&source_code,
|
|
97
|
-
&source_id,
|
|
98
|
-
solidity_version,
|
|
99
|
-
&coverage_library_path,
|
|
100
|
-
)
|
|
101
|
-
.map_err(|error| napi::Error::new(napi::Status::GenericFailure, error))?;
|
|
102
|
-
|
|
103
|
-
instrumented.try_into().map_err(|location| {
|
|
104
|
-
napi::Error::new(
|
|
105
|
-
napi::Status::GenericFailure,
|
|
106
|
-
format!("Cannot represent source locations in JavaScript: {location}."),
|
|
107
|
-
)
|
|
108
|
-
})
|
|
109
|
-
}
|
package/src/lib.rs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// #![warn(missing_docs)]
|
|
2
|
-
|
|
3
|
-
//! NAPI bindings for EDR's core types.
|
|
4
|
-
|
|
5
|
-
#[global_allocator]
|
|
6
|
-
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
|
7
|
-
|
|
8
|
-
mod account;
|
|
9
|
-
mod block;
|
|
10
|
-
/// Types for overriding a call.
|
|
11
|
-
pub mod call_override;
|
|
12
|
-
/// Types for casting N-API types to Rust types.
|
|
13
|
-
pub mod cast;
|
|
14
|
-
/// Supported chain types.
|
|
15
|
-
pub mod chains;
|
|
16
|
-
/// Types for configuration.
|
|
17
|
-
pub mod config;
|
|
18
|
-
/// Types related to an EDR N-API context.
|
|
19
|
-
pub mod context;
|
|
20
|
-
/// Types for decoding smart contract data.
|
|
21
|
-
pub mod contract_decoder;
|
|
22
|
-
mod debug_trace;
|
|
23
|
-
pub mod gas_report;
|
|
24
|
-
/// Types and functions related to code coverage instrumentation.
|
|
25
|
-
pub mod instrument;
|
|
26
|
-
/// Types for EVM execution logs.
|
|
27
|
-
pub mod log;
|
|
28
|
-
/// Types for an RPC request logger.
|
|
29
|
-
pub mod logger;
|
|
30
|
-
/// Types for mocking provider behavior.
|
|
31
|
-
#[cfg(feature = "test-mock")]
|
|
32
|
-
pub mod mock;
|
|
33
|
-
/// Types for precompiles.
|
|
34
|
-
pub mod precompile;
|
|
35
|
-
/// Types for Ethereum RPC providers.
|
|
36
|
-
pub mod provider;
|
|
37
|
-
/// Types for EVM execution results.
|
|
38
|
-
pub mod result;
|
|
39
|
-
/// Types relating to benchmark scenarios.
|
|
40
|
-
#[cfg(feature = "scenarios")]
|
|
41
|
-
pub mod scenarios;
|
|
42
|
-
mod serde;
|
|
43
|
-
/// Solidity test runner.
|
|
44
|
-
pub mod solidity_tests;
|
|
45
|
-
/// Types for subscribing to events.
|
|
46
|
-
pub mod subscription;
|
|
47
|
-
/// Types for EVM traces.
|
|
48
|
-
pub mod trace;
|
|
49
|
-
/// Types related to Ethereum withdrawals.
|
|
50
|
-
pub mod withdrawal;
|
package/src/log.rs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
use napi::bindgen_prelude::Uint8Array;
|
|
2
|
-
use napi_derive::napi;
|
|
3
|
-
|
|
4
|
-
/// Ethereum execution log.
|
|
5
|
-
#[napi(object)]
|
|
6
|
-
pub struct ExecutionLog {
|
|
7
|
-
pub address: Uint8Array,
|
|
8
|
-
pub topics: Vec<Uint8Array>,
|
|
9
|
-
pub data: Uint8Array,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
impl From<&edr_receipt::log::ExecutionLog> for ExecutionLog {
|
|
13
|
-
fn from(value: &edr_receipt::log::ExecutionLog) -> Self {
|
|
14
|
-
let topics = value
|
|
15
|
-
.topics()
|
|
16
|
-
.iter()
|
|
17
|
-
.map(Uint8Array::with_data_copied)
|
|
18
|
-
.collect();
|
|
19
|
-
|
|
20
|
-
let data = Uint8Array::with_data_copied(&value.data.data);
|
|
21
|
-
|
|
22
|
-
Self {
|
|
23
|
-
address: Uint8Array::with_data_copied(value.address),
|
|
24
|
-
topics,
|
|
25
|
-
data,
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
package/src/logger.rs
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
use std::sync::{mpsc::channel, Arc};
|
|
2
|
-
|
|
3
|
-
use edr_napi_core::logger::LoggerError;
|
|
4
|
-
use edr_primitives::Bytes;
|
|
5
|
-
use napi::{
|
|
6
|
-
threadsafe_function::{
|
|
7
|
-
ErrorStrategy, ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode,
|
|
8
|
-
},
|
|
9
|
-
JsFunction, Status,
|
|
10
|
-
};
|
|
11
|
-
use napi_derive::napi;
|
|
12
|
-
|
|
13
|
-
#[napi(object)]
|
|
14
|
-
pub struct LoggerConfig {
|
|
15
|
-
/// Whether to enable the logger.
|
|
16
|
-
pub enable: bool,
|
|
17
|
-
#[napi(ts_type = "(inputs: ArrayBuffer[]) => string[]")]
|
|
18
|
-
pub decode_console_log_inputs_callback: JsFunction,
|
|
19
|
-
#[napi(ts_type = "(message: string, replace: boolean) => void")]
|
|
20
|
-
pub print_line_callback: JsFunction,
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
impl LoggerConfig {
|
|
24
|
-
/// Resolves the logger config, converting it to a
|
|
25
|
-
/// `edr_napi_core::logger::Config`.
|
|
26
|
-
pub fn resolve(self, env: &napi::Env) -> napi::Result<edr_napi_core::logger::Config> {
|
|
27
|
-
let mut decode_console_log_inputs_callback: ThreadsafeFunction<_, ErrorStrategy::Fatal> =
|
|
28
|
-
self.decode_console_log_inputs_callback
|
|
29
|
-
.create_threadsafe_function(0, |ctx: ThreadSafeCallContext<Vec<Bytes>>| {
|
|
30
|
-
let inputs = ctx.env.create_array_with_length(ctx.value.len()).and_then(
|
|
31
|
-
|mut inputs| {
|
|
32
|
-
for (idx, input) in ctx.value.into_iter().enumerate() {
|
|
33
|
-
ctx.env
|
|
34
|
-
.create_arraybuffer_with_data(input.to_vec())
|
|
35
|
-
.and_then(|input| {
|
|
36
|
-
inputs.set_element(idx as u32, input.into_raw())
|
|
37
|
-
})?;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
Ok(inputs)
|
|
41
|
-
},
|
|
42
|
-
)?;
|
|
43
|
-
|
|
44
|
-
Ok(vec![inputs])
|
|
45
|
-
})?;
|
|
46
|
-
|
|
47
|
-
// Maintain a weak reference to the function to avoid blocking the event loop
|
|
48
|
-
// from exiting.
|
|
49
|
-
decode_console_log_inputs_callback.unref(env)?;
|
|
50
|
-
|
|
51
|
-
let decode_console_log_inputs_fn = Arc::new(move |console_log_inputs| {
|
|
52
|
-
let (sender, receiver) = channel();
|
|
53
|
-
|
|
54
|
-
let status = decode_console_log_inputs_callback.call_with_return_value(
|
|
55
|
-
console_log_inputs,
|
|
56
|
-
ThreadsafeFunctionCallMode::Blocking,
|
|
57
|
-
move |decoded_inputs: Vec<String>| {
|
|
58
|
-
sender.send(decoded_inputs).map_err(|_error| {
|
|
59
|
-
napi::Error::new(
|
|
60
|
-
Status::GenericFailure,
|
|
61
|
-
"Failed to send result from decode_console_log_inputs",
|
|
62
|
-
)
|
|
63
|
-
})
|
|
64
|
-
},
|
|
65
|
-
);
|
|
66
|
-
assert_eq!(status, Status::Ok);
|
|
67
|
-
|
|
68
|
-
receiver
|
|
69
|
-
.recv()
|
|
70
|
-
.expect("Receive can only fail if the channel is closed")
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
let mut print_line_callback: ThreadsafeFunction<_, ErrorStrategy::Fatal> = self
|
|
74
|
-
.print_line_callback
|
|
75
|
-
.create_threadsafe_function(0, |ctx: ThreadSafeCallContext<(String, bool)>| {
|
|
76
|
-
// String
|
|
77
|
-
let message = ctx.env.create_string_from_std(ctx.value.0)?;
|
|
78
|
-
|
|
79
|
-
// bool
|
|
80
|
-
let replace = ctx.env.get_boolean(ctx.value.1)?;
|
|
81
|
-
|
|
82
|
-
Ok(vec![message.into_unknown(), replace.into_unknown()])
|
|
83
|
-
})?;
|
|
84
|
-
|
|
85
|
-
// Maintain a weak reference to the function to avoid blocking the event loop
|
|
86
|
-
// from exiting.
|
|
87
|
-
print_line_callback.unref(env)?;
|
|
88
|
-
|
|
89
|
-
let print_line_fn = Arc::new(move |message, replace| {
|
|
90
|
-
let (sender, receiver) = channel();
|
|
91
|
-
|
|
92
|
-
let status = print_line_callback.call_with_return_value(
|
|
93
|
-
(message, replace),
|
|
94
|
-
ThreadsafeFunctionCallMode::Blocking,
|
|
95
|
-
move |()| {
|
|
96
|
-
sender.send(()).map_err(|_error| {
|
|
97
|
-
napi::Error::new(
|
|
98
|
-
Status::GenericFailure,
|
|
99
|
-
"Failed to send result from decode_console_log_inputs",
|
|
100
|
-
)
|
|
101
|
-
})
|
|
102
|
-
},
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
let () = receiver.recv().unwrap();
|
|
106
|
-
|
|
107
|
-
if status == napi::Status::Ok {
|
|
108
|
-
Ok(())
|
|
109
|
-
} else {
|
|
110
|
-
Err(LoggerError::PrintLine)
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
Ok(edr_napi_core::logger::Config {
|
|
115
|
-
enable: self.enable,
|
|
116
|
-
decode_console_log_inputs_fn,
|
|
117
|
-
print_line_fn,
|
|
118
|
-
})
|
|
119
|
-
}
|
|
120
|
-
}
|
package/src/mock/time.rs
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
use std::sync::Arc;
|
|
2
|
-
|
|
3
|
-
use edr_evm::spec::RuntimeSpec;
|
|
4
|
-
use edr_evm_spec::ChainSpec;
|
|
5
|
-
use edr_generic::GenericChainSpec;
|
|
6
|
-
use edr_napi_core::logger::Logger;
|
|
7
|
-
use edr_primitives::B256;
|
|
8
|
-
use edr_rpc_spec::RpcSpec;
|
|
9
|
-
use napi::{bindgen_prelude::BigInt, tokio::runtime, Env, JsObject};
|
|
10
|
-
use napi_derive::napi;
|
|
11
|
-
|
|
12
|
-
use crate::{
|
|
13
|
-
cast::TryCast as _,
|
|
14
|
-
config::{resolve_configs, ConfigResolution, ProviderConfig},
|
|
15
|
-
contract_decoder::ContractDecoder,
|
|
16
|
-
logger::LoggerConfig,
|
|
17
|
-
provider::Provider,
|
|
18
|
-
subscription::SubscriptionConfig,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
#[napi]
|
|
22
|
-
pub struct MockTime {
|
|
23
|
-
inner: Arc<edr_provider::time::MockTime>,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
#[napi]
|
|
27
|
-
impl MockTime {
|
|
28
|
-
#[doc = "Creates a new instance of `MockTime` with the current time."]
|
|
29
|
-
#[napi(factory, catch_unwind)]
|
|
30
|
-
pub fn now() -> Self {
|
|
31
|
-
Self {
|
|
32
|
-
inner: Arc::new(edr_provider::time::MockTime::now()),
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
#[doc = "Adds the specified number of seconds to the current time."]
|
|
37
|
-
#[napi(catch_unwind)]
|
|
38
|
-
pub fn add_seconds(&self, seconds: BigInt) -> napi::Result<()> {
|
|
39
|
-
let seconds = seconds.try_cast()?;
|
|
40
|
-
|
|
41
|
-
self.inner.add_seconds(seconds);
|
|
42
|
-
Ok(())
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
#[doc = "Creates a provider with a mock timer."]
|
|
47
|
-
#[doc = "For testing purposes."]
|
|
48
|
-
#[napi(catch_unwind, ts_return_type = "Promise<Provider>")]
|
|
49
|
-
pub fn create_provider_with_mock_timer(
|
|
50
|
-
env: Env,
|
|
51
|
-
provider_config: ProviderConfig,
|
|
52
|
-
logger_config: LoggerConfig,
|
|
53
|
-
subscription_config: SubscriptionConfig,
|
|
54
|
-
contract_decoder: &ContractDecoder,
|
|
55
|
-
time: &MockTime,
|
|
56
|
-
) -> napi::Result<JsObject> {
|
|
57
|
-
let (deferred, promise) = env.create_deferred()?;
|
|
58
|
-
|
|
59
|
-
macro_rules! try_or_reject_promise {
|
|
60
|
-
($expr:expr) => {
|
|
61
|
-
match $expr {
|
|
62
|
-
Ok(value) => value,
|
|
63
|
-
Err(error) => {
|
|
64
|
-
deferred.reject(error);
|
|
65
|
-
return Ok(promise);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
let runtime = runtime::Handle::current();
|
|
72
|
-
|
|
73
|
-
let ConfigResolution {
|
|
74
|
-
logger_config,
|
|
75
|
-
provider_config,
|
|
76
|
-
subscription_callback,
|
|
77
|
-
} = try_or_reject_promise!(resolve_configs(
|
|
78
|
-
&env,
|
|
79
|
-
runtime.clone(),
|
|
80
|
-
provider_config,
|
|
81
|
-
logger_config,
|
|
82
|
-
subscription_config,
|
|
83
|
-
));
|
|
84
|
-
|
|
85
|
-
let contract_decoder = Arc::clone(contract_decoder.as_inner());
|
|
86
|
-
let timer = Arc::clone(&time.inner);
|
|
87
|
-
|
|
88
|
-
runtime.clone().spawn_blocking(move || {
|
|
89
|
-
// Using a closure to limit the scope, allowing us to use `?` for error
|
|
90
|
-
// handling. This is necessary because the result of the closure is used
|
|
91
|
-
// to resolve the deferred promise.
|
|
92
|
-
let create_provider = move || -> napi::Result<Provider> {
|
|
93
|
-
let logger = Logger::<GenericChainSpec, Arc<edr_provider::time::MockTime>>::new(
|
|
94
|
-
logger_config,
|
|
95
|
-
Arc::clone(&contract_decoder),
|
|
96
|
-
)?;
|
|
97
|
-
|
|
98
|
-
let provider_config =
|
|
99
|
-
edr_provider::ProviderConfig::<edr_chain_l1::Hardfork>::try_from(provider_config)?;
|
|
100
|
-
|
|
101
|
-
let provider =
|
|
102
|
-
edr_provider::Provider::<GenericChainSpec, Arc<edr_provider::time::MockTime>>::new(
|
|
103
|
-
runtime.clone(),
|
|
104
|
-
Box::new(logger),
|
|
105
|
-
Box::new(move |event| {
|
|
106
|
-
let event = edr_napi_core::subscription::SubscriptionEvent::new::<
|
|
107
|
-
<GenericChainSpec as RuntimeSpec>::Block,
|
|
108
|
-
<GenericChainSpec as RpcSpec>::RpcBlock<B256>,
|
|
109
|
-
<GenericChainSpec as ChainSpec>::SignedTransaction,
|
|
110
|
-
>(event);
|
|
111
|
-
|
|
112
|
-
subscription_callback.call(event);
|
|
113
|
-
}),
|
|
114
|
-
provider_config,
|
|
115
|
-
Arc::clone(&contract_decoder),
|
|
116
|
-
timer,
|
|
117
|
-
)
|
|
118
|
-
.map_err(|error| napi::Error::from_reason(error.to_string()))?;
|
|
119
|
-
|
|
120
|
-
Ok(Provider::new(
|
|
121
|
-
Arc::new(provider),
|
|
122
|
-
runtime,
|
|
123
|
-
contract_decoder,
|
|
124
|
-
#[cfg(feature = "scenarios")]
|
|
125
|
-
None,
|
|
126
|
-
))
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
let result = create_provider();
|
|
130
|
-
deferred.resolve(|_env| result);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
Ok(promise)
|
|
134
|
-
}
|
package/src/mock.rs
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
pub mod time;
|
|
2
|
-
|
|
3
|
-
use std::sync::Arc;
|
|
4
|
-
|
|
5
|
-
use edr_evm_spec::EvmHaltReason;
|
|
6
|
-
use edr_napi_core::provider::SyncProvider;
|
|
7
|
-
use edr_rpc_client::jsonrpc;
|
|
8
|
-
use edr_solidity::contract_decoder::ContractDecoder;
|
|
9
|
-
use napi::tokio::runtime;
|
|
10
|
-
use napi_derive::napi;
|
|
11
|
-
|
|
12
|
-
use crate::{context::EdrContext, provider::Provider};
|
|
13
|
-
|
|
14
|
-
/// A mock provider that always returns the given mocked response.
|
|
15
|
-
pub struct MockProvider {
|
|
16
|
-
mocked_response: serde_json::Value,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
impl MockProvider {
|
|
20
|
-
pub fn new(mocked_response: serde_json::Value) -> Self {
|
|
21
|
-
Self { mocked_response }
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
impl SyncProvider for MockProvider {
|
|
26
|
-
fn handle_request(
|
|
27
|
-
&self,
|
|
28
|
-
_request: String,
|
|
29
|
-
_contract_decoder: Arc<ContractDecoder>,
|
|
30
|
-
) -> napi::Result<edr_napi_core::spec::Response<EvmHaltReason>> {
|
|
31
|
-
let response = jsonrpc::ResponseData::Success {
|
|
32
|
-
result: self.mocked_response.clone(),
|
|
33
|
-
};
|
|
34
|
-
edr_napi_core::spec::marshal_response_data(response)
|
|
35
|
-
.map(|data| edr_napi_core::spec::Response {
|
|
36
|
-
solidity_trace: None,
|
|
37
|
-
data,
|
|
38
|
-
traces: Vec::new(),
|
|
39
|
-
})
|
|
40
|
-
.map_err(|error| napi::Error::new(napi::Status::GenericFailure, error.to_string()))
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
fn set_call_override_callback(
|
|
44
|
-
&self,
|
|
45
|
-
_call_override_callback: Arc<dyn edr_provider::SyncCallOverride>,
|
|
46
|
-
) {
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
fn set_verbose_tracing(&self, _enabled: bool) {}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
#[napi]
|
|
53
|
-
impl EdrContext {
|
|
54
|
-
#[doc = "Creates a mock provider, which always returns the given response."]
|
|
55
|
-
#[doc = "For testing purposes."]
|
|
56
|
-
#[napi]
|
|
57
|
-
pub fn create_mock_provider(
|
|
58
|
-
&self,
|
|
59
|
-
mocked_response: serde_json::Value,
|
|
60
|
-
) -> napi::Result<Provider> {
|
|
61
|
-
let provider = Provider::new(
|
|
62
|
-
Arc::new(MockProvider::new(mocked_response)),
|
|
63
|
-
runtime::Handle::current(),
|
|
64
|
-
Arc::new(ContractDecoder::default()),
|
|
65
|
-
#[cfg(feature = "scenarios")]
|
|
66
|
-
None,
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
Ok(provider)
|
|
70
|
-
}
|
|
71
|
-
}
|
package/src/precompile.rs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
use edr_evm::precompile::{self, PrecompileFn, PrecompileWithAddress};
|
|
2
|
-
use edr_primitives::Address;
|
|
3
|
-
use napi::bindgen_prelude::Uint8Array;
|
|
4
|
-
use napi_derive::napi;
|
|
5
|
-
|
|
6
|
-
#[napi]
|
|
7
|
-
#[derive(Clone)]
|
|
8
|
-
pub struct Precompile {
|
|
9
|
-
address: Address,
|
|
10
|
-
precompile_fn: PrecompileFn,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
impl Precompile {
|
|
14
|
-
pub fn new(address: Address, precompile_fn: PrecompileFn) -> Self {
|
|
15
|
-
Self {
|
|
16
|
-
address,
|
|
17
|
-
precompile_fn,
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/// Returns the address and precompile function as a tuple.
|
|
22
|
-
pub fn to_tuple(&self) -> (Address, PrecompileFn) {
|
|
23
|
-
(self.address, self.precompile_fn)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
impl From<PrecompileWithAddress> for Precompile {
|
|
28
|
-
fn from(value: PrecompileWithAddress) -> Self {
|
|
29
|
-
Self {
|
|
30
|
-
address: value.0,
|
|
31
|
-
precompile_fn: value.1,
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
#[napi]
|
|
37
|
-
impl Precompile {
|
|
38
|
-
/// Returns the address of the precompile.
|
|
39
|
-
#[napi(catch_unwind, getter)]
|
|
40
|
-
pub fn address(&self) -> Uint8Array {
|
|
41
|
-
Uint8Array::with_data_copied(self.address)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/// [RIP-7212](https://github.com/ethereum/RIPs/blob/master/RIPS/rip-7212.md#specification)
|
|
46
|
-
/// secp256r1 precompile.
|
|
47
|
-
#[napi(catch_unwind)]
|
|
48
|
-
pub fn precompile_p256_verify() -> Precompile {
|
|
49
|
-
Precompile::from(precompile::secp256r1::P256VERIFY)
|
|
50
|
-
}
|
package/src/provider/factory.rs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
use std::sync::Arc;
|
|
2
|
-
|
|
3
|
-
use edr_napi_core::provider::SyncProviderFactory;
|
|
4
|
-
use napi_derive::napi;
|
|
5
|
-
|
|
6
|
-
#[napi]
|
|
7
|
-
pub struct ProviderFactory {
|
|
8
|
-
inner: Arc<dyn SyncProviderFactory>,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
impl ProviderFactory {
|
|
12
|
-
/// Returns a reference to the inner provider factory.
|
|
13
|
-
pub fn as_inner(&self) -> &Arc<dyn SyncProviderFactory> {
|
|
14
|
-
&self.inner
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
impl From<Arc<dyn SyncProviderFactory>> for ProviderFactory {
|
|
19
|
-
fn from(inner: Arc<dyn SyncProviderFactory>) -> Self {
|
|
20
|
-
Self { inner }
|
|
21
|
-
}
|
|
22
|
-
}
|
package/src/provider/response.rs
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
use edr_evm_spec::EvmHaltReason;
|
|
2
|
-
use edr_napi_core::spec::SolidityTraceData;
|
|
3
|
-
use edr_solidity::contract_decoder::NestedTraceDecoder as _;
|
|
4
|
-
use napi::Either;
|
|
5
|
-
use napi_derive::napi;
|
|
6
|
-
|
|
7
|
-
use crate::{
|
|
8
|
-
cast::TryCast,
|
|
9
|
-
trace::{solidity_stack_trace::SolidityStackTrace, RawTrace},
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
#[napi]
|
|
13
|
-
pub struct Response {
|
|
14
|
-
inner: edr_napi_core::spec::Response<EvmHaltReason>,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
impl From<edr_napi_core::spec::Response<EvmHaltReason>> for Response {
|
|
18
|
-
fn from(value: edr_napi_core::spec::Response<EvmHaltReason>) -> Self {
|
|
19
|
-
Self { inner: value }
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
#[napi]
|
|
24
|
-
impl Response {
|
|
25
|
-
#[doc = "Returns the response data as a JSON string or a JSON object."]
|
|
26
|
-
#[napi(catch_unwind, getter)]
|
|
27
|
-
pub fn data(&self) -> Either<String, serde_json::Value> {
|
|
28
|
-
self.inner.data.clone()
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Rust port of https://github.com/NomicFoundation/hardhat/blob/c20bf195a6efdc2d74e778b7a4a7799aac224841/packages/hardhat-core/src/internal/hardhat-network/provider/provider.ts#L590
|
|
32
|
-
#[doc = "Compute the error stack trace. Return the stack trace if it can be decoded, otherwise returns none. Throws if there was an error computing the stack trace."]
|
|
33
|
-
#[napi(catch_unwind)]
|
|
34
|
-
pub fn stack_trace(&self) -> napi::Result<Option<SolidityStackTrace>> {
|
|
35
|
-
let Some(SolidityTraceData {
|
|
36
|
-
trace,
|
|
37
|
-
contract_decoder,
|
|
38
|
-
}) = &self.inner.solidity_trace
|
|
39
|
-
else {
|
|
40
|
-
return Ok(None);
|
|
41
|
-
};
|
|
42
|
-
let nested_trace = edr_solidity::nested_tracer::convert_trace_messages_to_nested_trace(
|
|
43
|
-
trace.as_ref().clone(),
|
|
44
|
-
)
|
|
45
|
-
.map_err(|err| napi::Error::from_reason(err.to_string()))?;
|
|
46
|
-
|
|
47
|
-
if let Some(vm_trace) = nested_trace {
|
|
48
|
-
let decoded_trace = contract_decoder
|
|
49
|
-
.try_to_decode_nested_trace(vm_trace)
|
|
50
|
-
.map_err(|err| napi::Error::from_reason(err.to_string()))?;
|
|
51
|
-
let stack_trace = edr_solidity::solidity_tracer::get_stack_trace(decoded_trace)
|
|
52
|
-
.map_err(|err| napi::Error::from_reason(err.to_string()))?;
|
|
53
|
-
let stack_trace = stack_trace
|
|
54
|
-
.into_iter()
|
|
55
|
-
.map(TryCast::try_cast)
|
|
56
|
-
.collect::<Result<Vec<_>, _>>()?;
|
|
57
|
-
|
|
58
|
-
Ok(Some(stack_trace))
|
|
59
|
-
} else {
|
|
60
|
-
Ok(None)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
#[doc = "Returns the raw traces of executed contracts. This maybe contain zero or more traces."]
|
|
65
|
-
#[napi(catch_unwind, getter)]
|
|
66
|
-
pub fn traces(&self) -> Vec<RawTrace> {
|
|
67
|
-
self.inner
|
|
68
|
-
.traces
|
|
69
|
-
.iter()
|
|
70
|
-
.map(|trace| RawTrace::from(trace.clone()))
|
|
71
|
-
.collect()
|
|
72
|
-
}
|
|
73
|
-
}
|