@nomicfoundation/edr 0.12.0-next.4 → 0.12.0-next.6
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/index.d.ts +27 -11
- package/package.json +8 -8
- package/src/account.rs +1 -1
- package/src/chains/generic.rs +21 -17
- package/src/chains/l1.rs +81 -76
- package/src/chains/op.rs +37 -31
- package/src/config.rs +111 -6
- package/src/context.rs +37 -56
- package/src/log.rs +2 -2
- package/src/mock/time.rs +55 -63
- package/src/mock.rs +2 -1
- package/src/provider/response.rs +4 -4
- package/src/result.rs +24 -69
- package/src/solidity_tests/l1.rs +6 -6
- package/src/solidity_tests/op.rs +4 -4
- package/src/solidity_tests/runner.rs +1 -1
- package/src/trace/exit.rs +9 -8
- package/src/trace/return_data.rs +16 -2
- package/src/trace.rs +5 -4
package/src/config.rs
CHANGED
|
@@ -2,14 +2,15 @@ use core::fmt::{Debug, Display};
|
|
|
2
2
|
use std::{
|
|
3
3
|
num::NonZeroU64,
|
|
4
4
|
path::PathBuf,
|
|
5
|
+
sync::Arc,
|
|
5
6
|
time::{Duration, SystemTime},
|
|
6
7
|
};
|
|
7
8
|
|
|
8
9
|
use edr_coverage::reporter::SyncOnCollectedCoverageCallback;
|
|
9
|
-
use
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
use edr_eip1559::{BaseFeeActivation, ConstantBaseFeeParams};
|
|
11
|
+
use edr_eth::{Bytes, HashMap, HashSet};
|
|
12
|
+
use edr_signer::{secret_key_from_str, SecretKey};
|
|
13
|
+
use edr_solidity::contract_decoder::ContractDecoder;
|
|
13
14
|
use napi::{
|
|
14
15
|
bindgen_prelude::{BigInt, Promise, Reference, Uint8Array},
|
|
15
16
|
threadsafe_function::{
|
|
@@ -20,7 +21,53 @@ use napi::{
|
|
|
20
21
|
};
|
|
21
22
|
use napi_derive::napi;
|
|
22
23
|
|
|
23
|
-
use crate::{
|
|
24
|
+
use crate::{
|
|
25
|
+
account::AccountOverride, block::BlobGas, cast::TryCast, logger::LoggerConfig,
|
|
26
|
+
precompile::Precompile, subscription::SubscriptionConfig,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/// Configuration for EIP-1559 parameters
|
|
30
|
+
#[napi(object)]
|
|
31
|
+
pub struct BaseFeeParamActivation {
|
|
32
|
+
pub activation: Either<BaseFeeActivationByBlockNumber, BaseFeeActivationByHardfork>,
|
|
33
|
+
pub max_change_denominator: BigInt,
|
|
34
|
+
pub elasticity_multiplier: BigInt,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
#[napi(object)]
|
|
38
|
+
pub struct BaseFeeActivationByBlockNumber {
|
|
39
|
+
/// The block number at which the base_fee_params is activated
|
|
40
|
+
pub block_number: BigInt,
|
|
41
|
+
}
|
|
42
|
+
#[napi(object)]
|
|
43
|
+
pub struct BaseFeeActivationByHardfork {
|
|
44
|
+
/// The hardfork at which the base_fee_params is activated
|
|
45
|
+
pub hardfork: String,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
impl TryFrom<BaseFeeParamActivation> for (BaseFeeActivation<String>, ConstantBaseFeeParams) {
|
|
49
|
+
type Error = napi::Error;
|
|
50
|
+
|
|
51
|
+
fn try_from(value: BaseFeeParamActivation) -> Result<Self, Self::Error> {
|
|
52
|
+
let base_fee_params = ConstantBaseFeeParams {
|
|
53
|
+
max_change_denominator: value.max_change_denominator.try_cast()?,
|
|
54
|
+
elasticity_multiplier: value.elasticity_multiplier.try_cast()?,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
match value.activation {
|
|
58
|
+
Either::A(BaseFeeActivationByBlockNumber { block_number }) => {
|
|
59
|
+
let activation_block_number: u64 = block_number.try_cast()?;
|
|
60
|
+
Ok((
|
|
61
|
+
BaseFeeActivation::BlockNumber(activation_block_number),
|
|
62
|
+
base_fee_params,
|
|
63
|
+
))
|
|
64
|
+
}
|
|
65
|
+
Either::B(BaseFeeActivationByHardfork { hardfork }) => {
|
|
66
|
+
Ok((BaseFeeActivation::Hardfork(hardfork), base_fee_params))
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
24
71
|
|
|
25
72
|
/// Specification of a chain with possible overrides.
|
|
26
73
|
#[napi(object)]
|
|
@@ -137,6 +184,15 @@ pub struct ProviderConfig {
|
|
|
137
184
|
pub bail_on_call_failure: bool,
|
|
138
185
|
/// Whether to return an `Err` when a `eth_sendTransaction` fails
|
|
139
186
|
pub bail_on_transaction_failure: bool,
|
|
187
|
+
/// EIP-1559 base fee parameters activations to be used to calculate the
|
|
188
|
+
/// block base fee.
|
|
189
|
+
///
|
|
190
|
+
/// Provide an ordered list of base_fee_params to be
|
|
191
|
+
/// used starting from the specified activation point (hardfork or block
|
|
192
|
+
/// number).
|
|
193
|
+
/// If not provided, the default values from the chain spec
|
|
194
|
+
/// will be used.
|
|
195
|
+
pub base_fee_config: Option<Vec<BaseFeeParamActivation>>,
|
|
140
196
|
/// The gas limit of each block
|
|
141
197
|
pub block_gas_limit: BigInt,
|
|
142
198
|
/// The chain ID of the blockchain
|
|
@@ -418,7 +474,7 @@ impl ProviderConfig {
|
|
|
418
474
|
// This is the only place in production code where it's allowed to use
|
|
419
475
|
// `DangerousSecretKeyStr`.
|
|
420
476
|
#[allow(deprecated)]
|
|
421
|
-
use
|
|
477
|
+
use edr_signer::DangerousSecretKeyStr;
|
|
422
478
|
|
|
423
479
|
static_assertions::assert_not_impl_all!(JsString: Debug, Display, serde::Serialize);
|
|
424
480
|
static_assertions::assert_not_impl_all!(JsStringUtf8: Debug, Display, serde::Serialize);
|
|
@@ -438,6 +494,11 @@ impl ProviderConfig {
|
|
|
438
494
|
})
|
|
439
495
|
.collect::<napi::Result<Vec<_>>>()?;
|
|
440
496
|
|
|
497
|
+
let base_fee_params: Option<Vec<(BaseFeeActivation<String>, ConstantBaseFeeParams)>> = self
|
|
498
|
+
.base_fee_config
|
|
499
|
+
.map(|vec| vec.into_iter().map(TryInto::try_into).collect())
|
|
500
|
+
.transpose()?;
|
|
501
|
+
|
|
441
502
|
let block_gas_limit =
|
|
442
503
|
NonZeroU64::new(self.block_gas_limit.try_cast()?).ok_or_else(|| {
|
|
443
504
|
napi::Error::new(
|
|
@@ -463,6 +524,7 @@ impl ProviderConfig {
|
|
|
463
524
|
allow_unlimited_contract_size: self.allow_unlimited_contract_size,
|
|
464
525
|
bail_on_call_failure: self.bail_on_call_failure,
|
|
465
526
|
bail_on_transaction_failure: self.bail_on_transaction_failure,
|
|
527
|
+
base_fee_params,
|
|
466
528
|
block_gas_limit,
|
|
467
529
|
chain_id: self.chain_id.try_cast()?,
|
|
468
530
|
coinbase: self.coinbase.try_cast()?,
|
|
@@ -541,3 +603,46 @@ impl From<BuildInfoAndOutput> for edr_napi_core::solidity::config::BuildInfoAndO
|
|
|
541
603
|
}
|
|
542
604
|
}
|
|
543
605
|
}
|
|
606
|
+
|
|
607
|
+
/// Result of [`resolve_configs`].
|
|
608
|
+
pub struct ConfigResolution {
|
|
609
|
+
pub contract_decoder: Arc<ContractDecoder>,
|
|
610
|
+
pub logger_config: edr_napi_core::logger::Config,
|
|
611
|
+
pub provider_config: edr_napi_core::provider::Config,
|
|
612
|
+
pub subscription_callback: edr_napi_core::subscription::Callback,
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/// Helper function for resolving the provided N-API configs.
|
|
616
|
+
pub fn resolve_configs(
|
|
617
|
+
env: &napi::Env,
|
|
618
|
+
runtime: runtime::Handle,
|
|
619
|
+
provider_config: ProviderConfig,
|
|
620
|
+
logger_config: LoggerConfig,
|
|
621
|
+
subscription_config: SubscriptionConfig,
|
|
622
|
+
tracing_config: TracingConfigWithBuffers,
|
|
623
|
+
) -> napi::Result<ConfigResolution> {
|
|
624
|
+
let provider_config = provider_config.resolve(env, runtime)?;
|
|
625
|
+
let logger_config = logger_config.resolve(env)?;
|
|
626
|
+
|
|
627
|
+
// TODO: https://github.com/NomicFoundation/edr/issues/760
|
|
628
|
+
let build_info_config = edr_solidity::artifacts::BuildInfoConfig::parse_from_buffers(
|
|
629
|
+
(&edr_napi_core::solidity::config::TracingConfigWithBuffers::from(tracing_config)).into(),
|
|
630
|
+
)
|
|
631
|
+
.map_err(|error| napi::Error::from_reason(error.to_string()))?;
|
|
632
|
+
|
|
633
|
+
let contract_decoder = ContractDecoder::new(&build_info_config).map_or_else(
|
|
634
|
+
|error| Err(napi::Error::from_reason(error.to_string())),
|
|
635
|
+
|contract_decoder| Ok(Arc::new(contract_decoder)),
|
|
636
|
+
)?;
|
|
637
|
+
|
|
638
|
+
let subscription_config = edr_napi_core::subscription::Config::from(subscription_config);
|
|
639
|
+
let subscription_callback =
|
|
640
|
+
edr_napi_core::subscription::Callback::new(env, subscription_config.subscription_callback)?;
|
|
641
|
+
|
|
642
|
+
Ok(ConfigResolution {
|
|
643
|
+
contract_decoder,
|
|
644
|
+
logger_config,
|
|
645
|
+
provider_config,
|
|
646
|
+
subscription_callback,
|
|
647
|
+
})
|
|
648
|
+
}
|
package/src/context.rs
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
use std::sync::Arc;
|
|
2
2
|
|
|
3
3
|
use edr_eth::HashMap;
|
|
4
|
-
use edr_napi_core::{
|
|
5
|
-
provider::{self, SyncProviderFactory},
|
|
6
|
-
solidity,
|
|
7
|
-
};
|
|
8
|
-
use edr_solidity::contract_decoder::ContractDecoder;
|
|
4
|
+
use edr_napi_core::{provider::SyncProviderFactory, solidity};
|
|
9
5
|
use edr_solidity_tests::{
|
|
10
6
|
decode::RevertDecoder,
|
|
11
7
|
multi_runner::{SuiteResultAndArtifactId, TestContract, TestContracts},
|
|
@@ -22,7 +18,7 @@ use napi_derive::napi;
|
|
|
22
18
|
use tracing_subscriber::{prelude::*, EnvFilter, Registry};
|
|
23
19
|
|
|
24
20
|
use crate::{
|
|
25
|
-
config::{ProviderConfig, TracingConfigWithBuffers},
|
|
21
|
+
config::{resolve_configs, ConfigResolution, ProviderConfig, TracingConfigWithBuffers},
|
|
26
22
|
logger::LoggerConfig,
|
|
27
23
|
provider::{Provider, ProviderFactory},
|
|
28
24
|
solidity_tests::{
|
|
@@ -78,25 +74,20 @@ impl EdrContext {
|
|
|
78
74
|
}
|
|
79
75
|
|
|
80
76
|
let runtime = runtime::Handle::current();
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
let contract_decoder = try_or_reject_promise!(ContractDecoder::new(&build_info_config)
|
|
96
|
-
.map_or_else(
|
|
97
|
-
|error| Err(napi::Error::from_reason(error.to_string())),
|
|
98
|
-
|contract_decoder| Ok(Arc::new(contract_decoder))
|
|
99
|
-
));
|
|
77
|
+
|
|
78
|
+
let ConfigResolution {
|
|
79
|
+
contract_decoder,
|
|
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
|
+
tracing_config
|
|
90
|
+
));
|
|
100
91
|
|
|
101
92
|
#[cfg(feature = "scenarios")]
|
|
102
93
|
let scenario_file =
|
|
@@ -106,31 +97,32 @@ impl EdrContext {
|
|
|
106
97
|
logger_config.enable,
|
|
107
98
|
)));
|
|
108
99
|
|
|
109
|
-
let
|
|
100
|
+
let factory = {
|
|
110
101
|
// TODO: https://github.com/NomicFoundation/edr/issues/760
|
|
111
102
|
// TODO: Don't block the JS event loop
|
|
112
103
|
let context = runtime.block_on(async { self.inner.lock().await });
|
|
113
104
|
|
|
114
|
-
try_or_reject_promise!(context.
|
|
115
|
-
&env,
|
|
116
|
-
&chain_type,
|
|
117
|
-
provider_config,
|
|
118
|
-
logger_config,
|
|
119
|
-
subscription_config.into(),
|
|
120
|
-
&contract_decoder,
|
|
121
|
-
))
|
|
105
|
+
try_or_reject_promise!(context.get_provider_factory(&chain_type))
|
|
122
106
|
};
|
|
123
107
|
|
|
124
108
|
runtime.clone().spawn_blocking(move || {
|
|
125
|
-
let result =
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
109
|
+
let result = factory
|
|
110
|
+
.create_provider(
|
|
111
|
+
runtime.clone(),
|
|
112
|
+
provider_config,
|
|
113
|
+
logger_config,
|
|
114
|
+
subscription_callback,
|
|
115
|
+
Arc::clone(&contract_decoder),
|
|
132
116
|
)
|
|
133
|
-
|
|
117
|
+
.map(|provider| {
|
|
118
|
+
Provider::new(
|
|
119
|
+
provider,
|
|
120
|
+
runtime,
|
|
121
|
+
contract_decoder,
|
|
122
|
+
#[cfg(feature = "scenarios")]
|
|
123
|
+
scenario_file,
|
|
124
|
+
)
|
|
125
|
+
});
|
|
134
126
|
|
|
135
127
|
deferred.resolve(|_env| result);
|
|
136
128
|
});
|
|
@@ -410,23 +402,12 @@ impl Context {
|
|
|
410
402
|
|
|
411
403
|
/// Tries to create a new provider for the provided chain type and
|
|
412
404
|
/// configuration.
|
|
413
|
-
pub fn
|
|
405
|
+
pub fn get_provider_factory(
|
|
414
406
|
&self,
|
|
415
|
-
env: &napi::Env,
|
|
416
407
|
chain_type: &str,
|
|
417
|
-
|
|
418
|
-
logger_config: edr_napi_core::logger::Config,
|
|
419
|
-
subscription_config: edr_napi_core::subscription::Config,
|
|
420
|
-
contract_decoder: &Arc<ContractDecoder>,
|
|
421
|
-
) -> napi::Result<Box<dyn provider::Builder>> {
|
|
408
|
+
) -> napi::Result<Arc<dyn SyncProviderFactory>> {
|
|
422
409
|
if let Some(factory) = self.provider_factories.get(chain_type) {
|
|
423
|
-
factory
|
|
424
|
-
env,
|
|
425
|
-
provider_config,
|
|
426
|
-
logger_config,
|
|
427
|
-
subscription_config,
|
|
428
|
-
contract_decoder.clone(),
|
|
429
|
-
)
|
|
410
|
+
Ok(Arc::clone(factory))
|
|
430
411
|
} else {
|
|
431
412
|
Err(napi::Error::new(
|
|
432
413
|
napi::Status::GenericFailure,
|
package/src/log.rs
CHANGED
|
@@ -9,8 +9,8 @@ pub struct ExecutionLog {
|
|
|
9
9
|
pub data: Uint8Array,
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
impl From<&
|
|
13
|
-
fn from(value: &
|
|
12
|
+
impl From<&edr_receipt::log::ExecutionLog> for ExecutionLog {
|
|
13
|
+
fn from(value: &edr_receipt::log::ExecutionLog) -> Self {
|
|
14
14
|
let topics = value
|
|
15
15
|
.topics()
|
|
16
16
|
.iter()
|
package/src/mock/time.rs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
use std::sync::Arc;
|
|
2
2
|
|
|
3
|
-
use edr_eth::
|
|
3
|
+
use edr_eth::B256;
|
|
4
4
|
use edr_evm::spec::RuntimeSpec;
|
|
5
|
+
use edr_evm_spec::ChainSpec;
|
|
5
6
|
use edr_generic::GenericChainSpec;
|
|
6
7
|
use edr_napi_core::logger::Logger;
|
|
7
8
|
use edr_rpc_eth::RpcSpec;
|
|
8
|
-
use edr_solidity::contract_decoder::ContractDecoder;
|
|
9
9
|
use napi::{bindgen_prelude::BigInt, tokio::runtime, Env, JsObject};
|
|
10
10
|
use napi_derive::napi;
|
|
11
11
|
|
|
12
12
|
use crate::{
|
|
13
13
|
cast::TryCast as _,
|
|
14
|
-
config::{ProviderConfig, TracingConfigWithBuffers},
|
|
14
|
+
config::{resolve_configs, ConfigResolution, ProviderConfig, TracingConfigWithBuffers},
|
|
15
15
|
logger::LoggerConfig,
|
|
16
16
|
provider::Provider,
|
|
17
17
|
subscription::SubscriptionConfig,
|
|
@@ -68,73 +68,65 @@ pub fn create_provider_with_mock_timer(
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
let runtime = runtime::Handle::current();
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
(&edr_napi_core::solidity::config::TracingConfigWithBuffers::from(tracing_config))
|
|
79
|
-
.into(),
|
|
80
|
-
)
|
|
81
|
-
.map_err(|error| napi::Error::from_reason(error.to_string()))
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
let contract_decoder = try_or_reject_promise!(ContractDecoder::new(&build_info_config)
|
|
85
|
-
.map_or_else(
|
|
86
|
-
|error| Err(napi::Error::from_reason(error.to_string())),
|
|
87
|
-
|contract_decoder| Ok(Arc::new(contract_decoder))
|
|
88
|
-
));
|
|
89
|
-
|
|
90
|
-
let subscription_config = edr_napi_core::subscription::Config::from(subscription_config);
|
|
91
|
-
let subscription_callback = try_or_reject_promise!(edr_napi_core::subscription::Callback::new(
|
|
71
|
+
|
|
72
|
+
let ConfigResolution {
|
|
73
|
+
contract_decoder,
|
|
74
|
+
logger_config,
|
|
75
|
+
provider_config,
|
|
76
|
+
subscription_callback,
|
|
77
|
+
} = try_or_reject_promise!(resolve_configs(
|
|
92
78
|
&env,
|
|
93
|
-
|
|
79
|
+
runtime.clone(),
|
|
80
|
+
provider_config,
|
|
81
|
+
logger_config,
|
|
82
|
+
subscription_config,
|
|
83
|
+
tracing_config,
|
|
94
84
|
));
|
|
95
85
|
|
|
96
|
-
let logger = try_or_reject_promise!(Logger::<
|
|
97
|
-
GenericChainSpec,
|
|
98
|
-
Arc<edr_provider::time::MockTime>,
|
|
99
|
-
>::new(logger_config, Arc::clone(&contract_decoder),));
|
|
100
|
-
|
|
101
|
-
let provider_config = try_or_reject_promise!(
|
|
102
|
-
edr_provider::ProviderConfig::<edr_eth::l1::SpecId>::try_from(provider_config)
|
|
103
|
-
);
|
|
104
|
-
|
|
105
86
|
let timer = Arc::clone(&time.inner);
|
|
106
87
|
|
|
107
88
|
runtime.clone().spawn_blocking(move || {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
|
|
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
|
+
contract_decoder.clone(),
|
|
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
|
+
};
|
|
137
128
|
|
|
129
|
+
let result = create_provider();
|
|
138
130
|
deferred.resolve(|_env| result);
|
|
139
131
|
});
|
|
140
132
|
|
package/src/mock.rs
CHANGED
|
@@ -2,6 +2,7 @@ pub mod time;
|
|
|
2
2
|
|
|
3
3
|
use std::sync::Arc;
|
|
4
4
|
|
|
5
|
+
use edr_evm_spec::EvmHaltReason;
|
|
5
6
|
use edr_napi_core::provider::SyncProvider;
|
|
6
7
|
use edr_rpc_client::jsonrpc;
|
|
7
8
|
use edr_solidity::contract_decoder::ContractDecoder;
|
|
@@ -35,7 +36,7 @@ impl SyncProvider for MockProvider {
|
|
|
35
36
|
&self,
|
|
36
37
|
_request: String,
|
|
37
38
|
_contract_decoder: Arc<ContractDecoder>,
|
|
38
|
-
) -> napi::Result<edr_napi_core::spec::Response<
|
|
39
|
+
) -> napi::Result<edr_napi_core::spec::Response<EvmHaltReason>> {
|
|
39
40
|
let response = jsonrpc::ResponseData::Success {
|
|
40
41
|
result: self.mocked_response.clone(),
|
|
41
42
|
};
|
package/src/provider/response.rs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use
|
|
1
|
+
use edr_evm_spec::EvmHaltReason;
|
|
2
2
|
use edr_napi_core::spec::SolidityTraceData;
|
|
3
3
|
use edr_solidity::contract_decoder::NestedTraceDecoder as _;
|
|
4
4
|
use napi::Either;
|
|
@@ -11,11 +11,11 @@ use crate::{
|
|
|
11
11
|
|
|
12
12
|
#[napi]
|
|
13
13
|
pub struct Response {
|
|
14
|
-
inner: edr_napi_core::spec::Response<
|
|
14
|
+
inner: edr_napi_core::spec::Response<EvmHaltReason>,
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
impl From<edr_napi_core::spec::Response<
|
|
18
|
-
fn from(value: edr_napi_core::spec::Response<
|
|
17
|
+
impl From<edr_napi_core::spec::Response<EvmHaltReason>> for Response {
|
|
18
|
+
fn from(value: edr_napi_core::spec::Response<EvmHaltReason>) -> Self {
|
|
19
19
|
Self { inner: value }
|
|
20
20
|
}
|
|
21
21
|
}
|
package/src/result.rs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
use edr_evm::trace::AfterMessage;
|
|
2
|
+
use edr_evm_spec::EvmHaltReason;
|
|
2
3
|
use napi::{
|
|
3
4
|
bindgen_prelude::{BigInt, Either3, Uint8Array},
|
|
4
5
|
Either,
|
|
@@ -16,7 +17,6 @@ pub enum SuccessReason {
|
|
|
16
17
|
Return,
|
|
17
18
|
/// The opcode `SELFDESTRUCT` was called
|
|
18
19
|
SelfDestruct,
|
|
19
|
-
EofReturnContract,
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
impl From<edr_eth::result::SuccessReason> for SuccessReason {
|
|
@@ -25,7 +25,6 @@ impl From<edr_eth::result::SuccessReason> for SuccessReason {
|
|
|
25
25
|
edr_eth::result::SuccessReason::Stop => Self::Stop,
|
|
26
26
|
edr_eth::result::SuccessReason::Return => Self::Return,
|
|
27
27
|
edr_eth::result::SuccessReason::SelfDestruct => Self::SelfDestruct,
|
|
28
|
-
edr_eth::result::SuccessReason::EofReturnContract => Self::EofReturnContract,
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
}
|
|
@@ -36,7 +35,6 @@ impl From<SuccessReason> for edr_eth::result::SuccessReason {
|
|
|
36
35
|
SuccessReason::Stop => Self::Stop,
|
|
37
36
|
SuccessReason::Return => Self::Return,
|
|
38
37
|
SuccessReason::SelfDestruct => Self::SelfDestruct,
|
|
39
|
-
SuccessReason::EofReturnContract => Self::EofReturnContract,
|
|
40
38
|
}
|
|
41
39
|
}
|
|
42
40
|
}
|
|
@@ -100,81 +98,38 @@ pub enum ExceptionalHalt {
|
|
|
100
98
|
CreateContractStartingWithEF,
|
|
101
99
|
/// EIP-3860: Limit and meter initcode. Initcode size limit exceeded.
|
|
102
100
|
CreateInitCodeSizeLimit,
|
|
103
|
-
/// Aux data overflow, new aux data is larger tha u16 max size.
|
|
104
|
-
EofAuxDataOverflow,
|
|
105
|
-
/// Aud data is smaller then already present data size.
|
|
106
|
-
EofAuxDataTooSmall,
|
|
107
|
-
/// EOF Subroutine stack overflow
|
|
108
|
-
SubRoutineStackOverflow,
|
|
109
|
-
/// Check for target address validity is only done inside subcall.
|
|
110
|
-
InvalidEXTCALLTarget,
|
|
111
101
|
}
|
|
112
102
|
|
|
113
|
-
impl From<
|
|
114
|
-
fn from(halt:
|
|
103
|
+
impl From<EvmHaltReason> for ExceptionalHalt {
|
|
104
|
+
fn from(halt: EvmHaltReason) -> Self {
|
|
115
105
|
match halt {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
edr_eth::l1::HaltReason::CreateContractStartingWithEF => {
|
|
106
|
+
EvmHaltReason::OutOfGas(..) => ExceptionalHalt::OutOfGas,
|
|
107
|
+
EvmHaltReason::OpcodeNotFound => ExceptionalHalt::OpcodeNotFound,
|
|
108
|
+
EvmHaltReason::InvalidFEOpcode => ExceptionalHalt::InvalidFEOpcode,
|
|
109
|
+
EvmHaltReason::InvalidJump => ExceptionalHalt::InvalidJump,
|
|
110
|
+
EvmHaltReason::NotActivated => ExceptionalHalt::NotActivated,
|
|
111
|
+
EvmHaltReason::StackUnderflow => ExceptionalHalt::StackUnderflow,
|
|
112
|
+
EvmHaltReason::StackOverflow => ExceptionalHalt::StackOverflow,
|
|
113
|
+
EvmHaltReason::OutOfOffset => ExceptionalHalt::OutOfOffset,
|
|
114
|
+
EvmHaltReason::CreateCollision => ExceptionalHalt::CreateCollision,
|
|
115
|
+
EvmHaltReason::PrecompileError => ExceptionalHalt::PrecompileError,
|
|
116
|
+
EvmHaltReason::NonceOverflow => ExceptionalHalt::NonceOverflow,
|
|
117
|
+
EvmHaltReason::CreateContractSizeLimit => ExceptionalHalt::CreateContractSizeLimit,
|
|
118
|
+
EvmHaltReason::CreateContractStartingWithEF => {
|
|
131
119
|
ExceptionalHalt::CreateContractStartingWithEF
|
|
132
120
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
ExceptionalHalt::SubRoutineStackOverflow
|
|
140
|
-
}
|
|
141
|
-
edr_eth::l1::HaltReason::InvalidEXTCALLTarget => ExceptionalHalt::InvalidEXTCALLTarget,
|
|
142
|
-
edr_eth::l1::HaltReason::OverflowPayment
|
|
143
|
-
| edr_eth::l1::HaltReason::StateChangeDuringStaticCall
|
|
144
|
-
| edr_eth::l1::HaltReason::CallNotAllowedInsideStatic
|
|
145
|
-
| edr_eth::l1::HaltReason::OutOfFunds
|
|
146
|
-
| edr_eth::l1::HaltReason::CallTooDeep => {
|
|
121
|
+
EvmHaltReason::CreateInitCodeSizeLimit => ExceptionalHalt::CreateInitCodeSizeLimit,
|
|
122
|
+
EvmHaltReason::OverflowPayment
|
|
123
|
+
| EvmHaltReason::StateChangeDuringStaticCall
|
|
124
|
+
| EvmHaltReason::CallNotAllowedInsideStatic
|
|
125
|
+
| EvmHaltReason::OutOfFunds
|
|
126
|
+
| EvmHaltReason::CallTooDeep => {
|
|
147
127
|
unreachable!("Internal halts that can be only found inside Inspector: {halt:?}")
|
|
148
128
|
}
|
|
149
129
|
}
|
|
150
130
|
}
|
|
151
131
|
}
|
|
152
132
|
|
|
153
|
-
impl From<ExceptionalHalt> for edr_eth::l1::HaltReason {
|
|
154
|
-
fn from(value: ExceptionalHalt) -> Self {
|
|
155
|
-
match value {
|
|
156
|
-
ExceptionalHalt::OutOfGas => Self::OutOfGas(edr_eth::l1::OutOfGasError::Basic),
|
|
157
|
-
ExceptionalHalt::OpcodeNotFound => Self::OpcodeNotFound,
|
|
158
|
-
ExceptionalHalt::InvalidFEOpcode => Self::InvalidFEOpcode,
|
|
159
|
-
ExceptionalHalt::InvalidJump => Self::InvalidJump,
|
|
160
|
-
ExceptionalHalt::NotActivated => Self::NotActivated,
|
|
161
|
-
ExceptionalHalt::StackUnderflow => Self::StackUnderflow,
|
|
162
|
-
ExceptionalHalt::StackOverflow => Self::StackOverflow,
|
|
163
|
-
ExceptionalHalt::OutOfOffset => Self::OutOfOffset,
|
|
164
|
-
ExceptionalHalt::CreateCollision => Self::CreateCollision,
|
|
165
|
-
ExceptionalHalt::PrecompileError => Self::PrecompileError,
|
|
166
|
-
ExceptionalHalt::NonceOverflow => Self::NonceOverflow,
|
|
167
|
-
ExceptionalHalt::CreateContractSizeLimit => Self::CreateContractSizeLimit,
|
|
168
|
-
ExceptionalHalt::CreateContractStartingWithEF => Self::CreateContractStartingWithEF,
|
|
169
|
-
ExceptionalHalt::CreateInitCodeSizeLimit => Self::CreateInitCodeSizeLimit,
|
|
170
|
-
ExceptionalHalt::EofAuxDataOverflow => Self::EofAuxDataOverflow,
|
|
171
|
-
ExceptionalHalt::EofAuxDataTooSmall => Self::EofAuxDataTooSmall,
|
|
172
|
-
ExceptionalHalt::SubRoutineStackOverflow => Self::SubRoutineStackOverflow,
|
|
173
|
-
ExceptionalHalt::InvalidEXTCALLTarget => Self::InvalidEXTCALLTarget,
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
133
|
/// The result when the EVM terminates due to an exceptional halt.
|
|
179
134
|
#[napi(object)]
|
|
180
135
|
pub struct HaltResult {
|
|
@@ -194,8 +149,8 @@ pub struct ExecutionResult {
|
|
|
194
149
|
pub contract_address: Option<Uint8Array>,
|
|
195
150
|
}
|
|
196
151
|
|
|
197
|
-
impl From<&AfterMessage<
|
|
198
|
-
fn from(value: &AfterMessage<
|
|
152
|
+
impl From<&AfterMessage<EvmHaltReason>> for ExecutionResult {
|
|
153
|
+
fn from(value: &AfterMessage<EvmHaltReason>) -> Self {
|
|
199
154
|
let AfterMessage {
|
|
200
155
|
execution_result,
|
|
201
156
|
contract_address,
|