@nomicfoundation/edr 0.11.3 → 0.12.0-next.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.
Files changed (46) hide show
  1. package/Cargo.toml +61 -27
  2. package/LICENSE +5 -1
  3. package/index.d.ts +875 -137
  4. package/index.js +61 -3
  5. package/package.json +20 -16
  6. package/src/account.rs +109 -32
  7. package/src/block.rs +2 -103
  8. package/src/call_override.rs +7 -7
  9. package/src/cast.rs +47 -17
  10. package/src/chains/generic.rs +51 -0
  11. package/src/chains/l1.rs +262 -0
  12. package/src/chains/op.rs +425 -0
  13. package/src/chains.rs +7 -0
  14. package/src/config.rs +537 -67
  15. package/src/context.rs +374 -17
  16. package/src/debug_trace.rs +2 -2
  17. package/src/instrument.rs +109 -0
  18. package/src/lib.rs +38 -14
  19. package/src/log.rs +12 -14
  20. package/src/logger.rs +77 -1177
  21. package/src/mock.rs +68 -0
  22. package/src/precompile.rs +50 -0
  23. package/src/provider/factory.rs +22 -0
  24. package/src/provider/response.rs +73 -0
  25. package/src/provider.rs +64 -325
  26. package/src/result.rs +60 -69
  27. package/src/scenarios.rs +11 -17
  28. package/src/serde.rs +57 -0
  29. package/src/solidity_tests/artifact.rs +184 -0
  30. package/src/solidity_tests/config.rs +725 -0
  31. package/src/solidity_tests/factory.rs +22 -0
  32. package/src/solidity_tests/l1.rs +68 -0
  33. package/src/solidity_tests/op.rs +69 -0
  34. package/src/solidity_tests/runner.rs +51 -0
  35. package/src/solidity_tests/test_results.rs +668 -0
  36. package/src/solidity_tests.rs +56 -0
  37. package/src/subscription.rs +32 -0
  38. package/src/trace/debug.rs +1 -1
  39. package/src/trace/exit.rs +12 -13
  40. package/src/trace/library_utils.rs +1 -1
  41. package/src/trace/return_data.rs +11 -11
  42. package/src/trace/solidity_stack_trace.rs +11 -8
  43. package/src/trace.rs +37 -44
  44. package/src/withdrawal.rs +4 -4
  45. package/src/provider/config.rs +0 -291
  46. package/src/subscribe.rs +0 -63
@@ -0,0 +1,22 @@
1
+ use std::sync::Arc;
2
+
3
+ use edr_napi_core::solidity::SyncTestRunnerFactory;
4
+ use napi_derive::napi;
5
+
6
+ #[napi]
7
+ pub struct SolidityTestRunnerFactory {
8
+ inner: Arc<dyn SyncTestRunnerFactory>,
9
+ }
10
+
11
+ impl SolidityTestRunnerFactory {
12
+ /// Returns a reference to the inner test runner factory.
13
+ pub fn as_inner(&self) -> &Arc<dyn SyncTestRunnerFactory> {
14
+ &self.inner
15
+ }
16
+ }
17
+
18
+ impl From<Arc<dyn SyncTestRunnerFactory>> for SolidityTestRunnerFactory {
19
+ fn from(inner: Arc<dyn SyncTestRunnerFactory>) -> Self {
20
+ Self { inner }
21
+ }
22
+ }
@@ -0,0 +1,68 @@
1
+ use std::{collections::BTreeMap, sync::Arc};
2
+
3
+ use edr_eth::Bytes;
4
+ use edr_napi_core::solidity::{
5
+ config::{TestRunnerConfig, TracingConfigWithBuffers},
6
+ SyncTestRunner, SyncTestRunnerFactory,
7
+ };
8
+ use edr_solidity::artifacts::ArtifactId;
9
+ use edr_solidity_tests::{
10
+ contracts::ContractsByArtifact, decode::RevertDecoder, evm_context::L1EvmBuilder,
11
+ multi_runner::TestContract, revm::context::TxEnv, MultiContractRunner,
12
+ };
13
+ use napi::tokio;
14
+ use napi_derive::napi;
15
+
16
+ use crate::solidity_tests::{factory::SolidityTestRunnerFactory, runner::LazyContractDecoder};
17
+
18
+ struct L1TestRunnerFactory;
19
+
20
+ impl SyncTestRunnerFactory for L1TestRunnerFactory {
21
+ fn create_test_runner(
22
+ &self,
23
+ runtime: tokio::runtime::Handle,
24
+ config: TestRunnerConfig,
25
+ contracts: BTreeMap<ArtifactId, TestContract>,
26
+ known_contracts: ContractsByArtifact,
27
+ libs_to_deploy: Vec<Bytes>,
28
+ revert_decoder: RevertDecoder,
29
+ tracing_config: TracingConfigWithBuffers,
30
+ ) -> napi::Result<Box<dyn SyncTestRunner>> {
31
+ let contract_decoder = LazyContractDecoder::new(tracing_config);
32
+
33
+ let runner = tokio::task::block_in_place(|| {
34
+ runtime
35
+ .block_on(MultiContractRunner::<
36
+ edr_eth::l1::BlockEnv,
37
+ (),
38
+ L1EvmBuilder,
39
+ edr_eth::l1::HaltReason,
40
+ edr_eth::l1::SpecId,
41
+ _,
42
+ edr_eth::l1::InvalidTransaction,
43
+ TxEnv,
44
+ >::new(
45
+ config.try_into()?,
46
+ contracts,
47
+ known_contracts,
48
+ libs_to_deploy,
49
+ contract_decoder,
50
+ revert_decoder,
51
+ ))
52
+ .map_err(|err| {
53
+ napi::Error::new(
54
+ napi::Status::GenericFailure,
55
+ format!("Failed to create multi contract runner: {err}"),
56
+ )
57
+ })
58
+ })?;
59
+
60
+ Ok(Box::new(runner))
61
+ }
62
+ }
63
+
64
+ #[napi(catch_unwind)]
65
+ pub fn l1_solidity_test_runner_factory() -> SolidityTestRunnerFactory {
66
+ let factory: Arc<dyn SyncTestRunnerFactory> = Arc::new(L1TestRunnerFactory);
67
+ factory.into()
68
+ }
@@ -0,0 +1,69 @@
1
+ use std::{collections::BTreeMap, sync::Arc};
2
+
3
+ use edr_eth::Bytes;
4
+ use edr_napi_core::solidity::{
5
+ config::{TestRunnerConfig, TracingConfigWithBuffers},
6
+ SyncTestRunner, SyncTestRunnerFactory,
7
+ };
8
+ use edr_op::solidity_tests::OpEvmBuilder;
9
+ use edr_solidity::artifacts::ArtifactId;
10
+ use edr_solidity_tests::{
11
+ contracts::ContractsByArtifact, decode::RevertDecoder, multi_runner::TestContract,
12
+ MultiContractRunner,
13
+ };
14
+ use napi::tokio;
15
+ use napi_derive::napi;
16
+
17
+ use crate::solidity_tests::{factory::SolidityTestRunnerFactory, runner::LazyContractDecoder};
18
+
19
+ struct OpTestRunnerFactory;
20
+
21
+ impl SyncTestRunnerFactory for OpTestRunnerFactory {
22
+ fn create_test_runner(
23
+ &self,
24
+ runtime: tokio::runtime::Handle,
25
+ config: TestRunnerConfig,
26
+ contracts: BTreeMap<ArtifactId, TestContract>,
27
+ known_contracts: ContractsByArtifact,
28
+ libs_to_deploy: Vec<Bytes>,
29
+ revert_decoder: RevertDecoder,
30
+ tracing_config: TracingConfigWithBuffers,
31
+ ) -> napi::Result<Box<dyn SyncTestRunner>> {
32
+ let contract_decoder = LazyContractDecoder::new(tracing_config);
33
+
34
+ let runner = tokio::task::block_in_place(|| {
35
+ runtime
36
+ .block_on(MultiContractRunner::<
37
+ edr_eth::l1::BlockEnv,
38
+ _,
39
+ OpEvmBuilder,
40
+ edr_op::OpHaltReason,
41
+ edr_op::OpSpecId,
42
+ _,
43
+ edr_op::transaction::InvalidTransaction,
44
+ edr_op::transaction::OpTxEnv<edr_eth::l1::TxEnv>,
45
+ >::new(
46
+ config.try_into()?,
47
+ contracts,
48
+ known_contracts,
49
+ libs_to_deploy,
50
+ contract_decoder,
51
+ revert_decoder,
52
+ ))
53
+ .map_err(|err| {
54
+ napi::Error::new(
55
+ napi::Status::GenericFailure,
56
+ format!("Failed to create multi contract runner: {err}"),
57
+ )
58
+ })
59
+ })?;
60
+
61
+ Ok(Box::new(runner))
62
+ }
63
+ }
64
+
65
+ #[napi(catch_unwind)]
66
+ pub fn op_solidity_test_runner_factory() -> SolidityTestRunnerFactory {
67
+ let factory: Arc<dyn SyncTestRunnerFactory> = Arc::new(OpTestRunnerFactory);
68
+ factory.into()
69
+ }
@@ -0,0 +1,51 @@
1
+ use std::sync::{Mutex, OnceLock};
2
+
3
+ use edr_eth::spec::HaltReasonTrait;
4
+ use edr_napi_core::solidity::config::TracingConfigWithBuffers;
5
+ use edr_solidity::{
6
+ artifacts::BuildInfoConfigWithBuffers,
7
+ contract_decoder::{ContractDecoder, ContractDecoderError, NestedTraceDecoder},
8
+ nested_trace::NestedTrace,
9
+ };
10
+
11
+ /// Only parses the tracing config which is very expensive if the contract
12
+ /// decoder is used.
13
+ #[derive(Debug)]
14
+ pub(crate) struct LazyContractDecoder {
15
+ // We need the `Mutex`, because `Uint8Array` is not `Sync`
16
+ tracing_config: Mutex<TracingConfigWithBuffers>,
17
+ // Storing the result so that we can propagate the error
18
+ contract_decoder: OnceLock<Result<ContractDecoder, ContractDecoderError>>,
19
+ }
20
+
21
+ impl LazyContractDecoder {
22
+ pub fn new(tracing_config: TracingConfigWithBuffers) -> Self {
23
+ Self {
24
+ tracing_config: Mutex::new(tracing_config),
25
+ contract_decoder: OnceLock::new(),
26
+ }
27
+ }
28
+ }
29
+
30
+ impl<HaltReasonT: HaltReasonTrait> NestedTraceDecoder<HaltReasonT> for LazyContractDecoder {
31
+ fn try_to_decode_nested_trace(
32
+ &self,
33
+ nested_trace: NestedTrace<HaltReasonT>,
34
+ ) -> Result<NestedTrace<HaltReasonT>, ContractDecoderError> {
35
+ self.contract_decoder
36
+ .get_or_init(|| {
37
+ let tracing_config = self
38
+ .tracing_config
39
+ .lock()
40
+ .expect("Can't get poisoned, because only called once");
41
+ edr_solidity::artifacts::BuildInfoConfig::parse_from_buffers(
42
+ BuildInfoConfigWithBuffers::from(&*tracing_config),
43
+ )
44
+ .map_err(|err| ContractDecoderError::Initialization(err.to_string()))
45
+ .and_then(|config| ContractDecoder::new(&config))
46
+ })
47
+ .as_ref()
48
+ .map_err(Clone::clone)
49
+ .and_then(|decoder| decoder.try_to_decode_nested_trace(nested_trace))
50
+ }
51
+ }