@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.
Files changed (52) hide show
  1. package/coverage.sol +38 -0
  2. package/dist/src/ts/coverage.d.ts +6 -0
  3. package/dist/src/ts/coverage.d.ts.map +1 -0
  4. package/dist/src/ts/coverage.js +51 -0
  5. package/dist/src/ts/coverage.js.map +1 -0
  6. package/index.d.ts +267 -27
  7. package/index.js +5 -2
  8. package/package.json +23 -12
  9. package/src/account.rs +0 -124
  10. package/src/block.rs +0 -28
  11. package/src/call_override.rs +0 -116
  12. package/src/cast.rs +0 -165
  13. package/src/chains/generic.rs +0 -58
  14. package/src/chains/l1.rs +0 -268
  15. package/src/chains/op.rs +0 -424
  16. package/src/chains.rs +0 -7
  17. package/src/config.rs +0 -700
  18. package/src/context.rs +0 -447
  19. package/src/contract_decoder.rs +0 -57
  20. package/src/debug_trace.rs +0 -40
  21. package/src/gas_report.rs +0 -92
  22. package/src/instrument.rs +0 -109
  23. package/src/lib.rs +0 -50
  24. package/src/log.rs +0 -28
  25. package/src/logger.rs +0 -120
  26. package/src/mock/time.rs +0 -134
  27. package/src/mock.rs +0 -71
  28. package/src/precompile.rs +0 -50
  29. package/src/provider/factory.rs +0 -22
  30. package/src/provider/response.rs +0 -73
  31. package/src/provider.rs +0 -162
  32. package/src/result.rs +0 -212
  33. package/src/scenarios.rs +0 -53
  34. package/src/serde.rs +0 -57
  35. package/src/solidity_tests/artifact.rs +0 -184
  36. package/src/solidity_tests/config.rs +0 -793
  37. package/src/solidity_tests/factory.rs +0 -22
  38. package/src/solidity_tests/l1.rs +0 -68
  39. package/src/solidity_tests/op.rs +0 -69
  40. package/src/solidity_tests/runner.rs +0 -51
  41. package/src/solidity_tests/test_results.rs +0 -736
  42. package/src/solidity_tests.rs +0 -56
  43. package/src/subscription.rs +0 -32
  44. package/src/trace/debug.rs +0 -61
  45. package/src/trace/exit.rs +0 -89
  46. package/src/trace/library_utils.rs +0 -11
  47. package/src/trace/model.rs +0 -59
  48. package/src/trace/return_data.rs +0 -96
  49. package/src/trace/solidity_stack_trace.rs +0 -869
  50. package/src/trace.rs +0 -199
  51. package/src/ts/solidity_tests.ts +0 -46
  52. package/src/withdrawal.rs +0 -49
@@ -1,869 +0,0 @@
1
- //! Naive rewrite of `hardhat-network/stack-traces/solidity-stack-traces.ts`
2
- //! from Hardhat.
3
-
4
- use std::convert::Infallible;
5
-
6
- use edr_primitives::{hex, U256};
7
- use napi::bindgen_prelude::{BigInt, Either25, FromNapiValue, ToNapiValue, Uint8Array, Undefined};
8
- use napi_derive::napi;
9
- use serde::{Serialize, Serializer};
10
-
11
- use super::model::ContractFunctionType;
12
- use crate::{cast::TryCast, trace::u256_to_bigint};
13
-
14
- #[napi]
15
- #[repr(u8)]
16
- #[allow(non_camel_case_types)] // intentionally mimicks the original case in TS
17
- #[allow(clippy::upper_case_acronyms)]
18
- #[derive(PartialEq, Eq, PartialOrd, Ord, strum::FromRepr, strum::IntoStaticStr, Serialize)]
19
- pub enum StackTraceEntryType {
20
- CALLSTACK_ENTRY = 0,
21
- UNRECOGNIZED_CREATE_CALLSTACK_ENTRY,
22
- UNRECOGNIZED_CONTRACT_CALLSTACK_ENTRY,
23
- PRECOMPILE_ERROR,
24
- REVERT_ERROR,
25
- PANIC_ERROR,
26
- CUSTOM_ERROR,
27
- FUNCTION_NOT_PAYABLE_ERROR,
28
- INVALID_PARAMS_ERROR,
29
- FALLBACK_NOT_PAYABLE_ERROR,
30
- FALLBACK_NOT_PAYABLE_AND_NO_RECEIVE_ERROR,
31
- UNRECOGNIZED_FUNCTION_WITHOUT_FALLBACK_ERROR, /* TODO: Should trying to call a
32
- * private/internal be a special case of
33
- * this? */
34
- MISSING_FALLBACK_OR_RECEIVE_ERROR,
35
- RETURNDATA_SIZE_ERROR,
36
- NONCONTRACT_ACCOUNT_CALLED_ERROR,
37
- CALL_FAILED_ERROR,
38
- DIRECT_LIBRARY_CALL_ERROR,
39
- UNRECOGNIZED_CREATE_ERROR,
40
- UNRECOGNIZED_CONTRACT_ERROR,
41
- OTHER_EXECUTION_ERROR,
42
- // This is a special case to handle a regression introduced in solc 0.6.3
43
- // For more info: https://github.com/ethereum/solidity/issues/9006
44
- UNMAPPED_SOLC_0_6_3_REVERT_ERROR,
45
- CONTRACT_TOO_LARGE_ERROR,
46
- INTERNAL_FUNCTION_CALLSTACK_ENTRY,
47
- CONTRACT_CALL_RUN_OUT_OF_GAS_ERROR,
48
- CHEATCODE_ERROR,
49
- }
50
-
51
- #[napi(catch_unwind)]
52
- pub fn stack_trace_entry_type_to_string(val: StackTraceEntryType) -> &'static str {
53
- val.into()
54
- }
55
-
56
- #[napi]
57
- pub const FALLBACK_FUNCTION_NAME: &str = "<fallback>";
58
- #[napi]
59
- pub const RECEIVE_FUNCTION_NAME: &str = "<receive>";
60
- #[napi]
61
- pub const CONSTRUCTOR_FUNCTION_NAME: &str = "constructor";
62
- #[napi]
63
- pub const UNRECOGNIZED_FUNCTION_NAME: &str = "<unrecognized-selector>";
64
- #[napi]
65
- pub const UNKNOWN_FUNCTION_NAME: &str = "<unknown>";
66
- #[napi]
67
- pub const PRECOMPILE_FUNCTION_NAME: &str = "<precompile>";
68
- #[napi]
69
- pub const UNRECOGNIZED_CONTRACT_NAME: &str = "<UnrecognizedContract>";
70
-
71
- #[napi(object)]
72
- #[derive(Clone, PartialEq, Serialize)]
73
- pub struct SourceReference {
74
- pub source_name: String,
75
- pub source_content: String,
76
- pub contract: Option<String>,
77
- pub function: Option<String>,
78
- pub line: u32,
79
- // [number, number] tuple
80
- pub range: Vec<u32>,
81
- }
82
-
83
- impl From<edr_solidity::solidity_stack_trace::SourceReference> for SourceReference {
84
- fn from(value: edr_solidity::solidity_stack_trace::SourceReference) -> Self {
85
- let (range_start, range_end) = value.range;
86
- Self {
87
- source_name: value.source_name,
88
- source_content: value.source_content,
89
- contract: value.contract,
90
- function: value.function,
91
- line: value.line,
92
- range: vec![range_start, range_end],
93
- }
94
- }
95
- }
96
-
97
- /// A [`StackTraceEntryType`] constant that is convertible to/from a
98
- /// `napi_value`.
99
- ///
100
- /// Since Rust does not allow constants directly as members, we use this wrapper
101
- /// to allow the `StackTraceEntryType` to be used as a member of an interface
102
- /// when defining the N-API bindings.
103
- // NOTE: It's currently not possible to use an enum as const generic parameter,
104
- // so we use the underlying `u8` repr used by the enum.
105
- #[derive(Clone, Copy)]
106
- pub struct StackTraceEntryTypeConst<const ENTRY_TYPE: u8>;
107
- impl<const ENTRY_TYPE: u8> FromNapiValue for StackTraceEntryTypeConst<ENTRY_TYPE> {
108
- unsafe fn from_napi_value(
109
- env: napi::sys::napi_env,
110
- napi_val: napi::sys::napi_value,
111
- ) -> napi::Result<Self> {
112
- // SAFETY: The safety concern is propagated in the function signature.
113
- let inner: u8 = unsafe { FromNapiValue::from_napi_value(env, napi_val) }?;
114
-
115
- if inner != ENTRY_TYPE {
116
- return Err(napi::Error::new(
117
- napi::Status::InvalidArg,
118
- format!("Expected StackTraceEntryType value: {ENTRY_TYPE}, got: {inner}"),
119
- ));
120
- }
121
-
122
- Ok(StackTraceEntryTypeConst)
123
- }
124
- }
125
- impl<const ENTRY_TYPE: u8> ToNapiValue for StackTraceEntryTypeConst<ENTRY_TYPE> {
126
- unsafe fn to_napi_value(
127
- env: napi::sys::napi_env,
128
- _val: Self,
129
- ) -> napi::Result<napi::sys::napi_value> {
130
- // SAFETY: The safety concern is propagated in the function signature.
131
- unsafe { u8::to_napi_value(env, ENTRY_TYPE) }
132
- }
133
- }
134
-
135
- impl<const ENTRY_TYPE: u8> Serialize for StackTraceEntryTypeConst<ENTRY_TYPE> {
136
- fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
137
- where
138
- S: serde::Serializer,
139
- {
140
- let inner = StackTraceEntryType::from_repr(ENTRY_TYPE).ok_or_else(|| {
141
- serde::ser::Error::custom(format!("Invalid StackTraceEntryType value: {ENTRY_TYPE}"))
142
- })?;
143
-
144
- inner.serialize(serializer)
145
- }
146
- }
147
-
148
- #[napi(object)]
149
- #[derive(Clone, Serialize)]
150
- pub struct CallstackEntryStackTraceEntry {
151
- #[napi(js_name = "type", ts_type = "StackTraceEntryType.CALLSTACK_ENTRY")]
152
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::CALLSTACK_ENTRY as u8 }>,
153
- pub source_reference: SourceReference,
154
- pub function_type: ContractFunctionType,
155
- }
156
-
157
- impl From<CallstackEntryStackTraceEntry> for SolidityStackTraceEntry {
158
- fn from(val: CallstackEntryStackTraceEntry) -> Self {
159
- Either25::A(val)
160
- }
161
- }
162
-
163
- #[napi(object)]
164
- #[derive(Clone, Serialize)]
165
- pub struct UnrecognizedCreateCallstackEntryStackTraceEntry {
166
- #[napi(
167
- js_name = "type",
168
- ts_type = "StackTraceEntryType.UNRECOGNIZED_CREATE_CALLSTACK_ENTRY"
169
- )]
170
- pub type_: StackTraceEntryTypeConst<
171
- { StackTraceEntryType::UNRECOGNIZED_CREATE_CALLSTACK_ENTRY as u8 },
172
- >,
173
- pub source_reference: Option<Undefined>,
174
- }
175
-
176
- impl From<UnrecognizedCreateCallstackEntryStackTraceEntry> for SolidityStackTraceEntry {
177
- fn from(val: UnrecognizedCreateCallstackEntryStackTraceEntry) -> Self {
178
- Either25::B(val)
179
- }
180
- }
181
-
182
- #[napi(object)]
183
- #[derive(Clone, Serialize)]
184
- pub struct UnrecognizedContractCallstackEntryStackTraceEntry {
185
- #[napi(
186
- js_name = "type",
187
- ts_type = "StackTraceEntryType.UNRECOGNIZED_CONTRACT_CALLSTACK_ENTRY"
188
- )]
189
- pub type_: StackTraceEntryTypeConst<
190
- { StackTraceEntryType::UNRECOGNIZED_CONTRACT_CALLSTACK_ENTRY as u8 },
191
- >,
192
- #[serde(serialize_with = "serialize_uint8array_to_hex")]
193
- pub address: Uint8Array,
194
- pub source_reference: Option<Undefined>,
195
- }
196
-
197
- impl From<UnrecognizedContractCallstackEntryStackTraceEntry> for SolidityStackTraceEntry {
198
- fn from(val: UnrecognizedContractCallstackEntryStackTraceEntry) -> Self {
199
- Either25::C(val)
200
- }
201
- }
202
-
203
- #[napi(object)]
204
- #[derive(Clone, Serialize)]
205
- pub struct PrecompileErrorStackTraceEntry {
206
- #[napi(js_name = "type", ts_type = "StackTraceEntryType.PRECOMPILE_ERROR")]
207
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::PRECOMPILE_ERROR as u8 }>,
208
- pub precompile: u32,
209
- pub source_reference: Option<Undefined>,
210
- }
211
-
212
- impl From<PrecompileErrorStackTraceEntry> for SolidityStackTraceEntry {
213
- fn from(val: PrecompileErrorStackTraceEntry) -> Self {
214
- Either25::D(val)
215
- }
216
- }
217
-
218
- #[napi(object)]
219
- #[derive(Clone, Serialize)]
220
- pub struct RevertErrorStackTraceEntry {
221
- #[napi(js_name = "type", ts_type = "StackTraceEntryType.REVERT_ERROR")]
222
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::REVERT_ERROR as u8 }>,
223
- #[serde(serialize_with = "serialize_uint8array_to_hex")]
224
- pub return_data: Uint8Array,
225
- pub source_reference: SourceReference,
226
- pub is_invalid_opcode_error: bool,
227
- }
228
-
229
- impl From<RevertErrorStackTraceEntry> for SolidityStackTraceEntry {
230
- fn from(val: RevertErrorStackTraceEntry) -> Self {
231
- Either25::E(val)
232
- }
233
- }
234
-
235
- #[napi(object)]
236
- #[derive(Clone, Serialize)]
237
- pub struct PanicErrorStackTraceEntry {
238
- #[napi(js_name = "type", ts_type = "StackTraceEntryType.PANIC_ERROR")]
239
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::PANIC_ERROR as u8 }>,
240
- #[serde(serialize_with = "serialize_evm_value_bigint_using_u256")]
241
- pub error_code: BigInt,
242
- pub source_reference: Option<SourceReference>,
243
- }
244
-
245
- impl From<PanicErrorStackTraceEntry> for SolidityStackTraceEntry {
246
- fn from(val: PanicErrorStackTraceEntry) -> Self {
247
- Either25::F(val)
248
- }
249
- }
250
-
251
- #[napi(object)]
252
- #[derive(Clone, Serialize)]
253
- pub struct CustomErrorStackTraceEntry {
254
- #[napi(js_name = "type", ts_type = "StackTraceEntryType.CUSTOM_ERROR")]
255
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::CUSTOM_ERROR as u8 }>,
256
- // unlike RevertErrorStackTraceEntry, this includes the message already parsed
257
- pub message: String,
258
- pub source_reference: SourceReference,
259
- }
260
-
261
- impl From<CustomErrorStackTraceEntry> for SolidityStackTraceEntry {
262
- fn from(val: CustomErrorStackTraceEntry) -> Self {
263
- Either25::G(val)
264
- }
265
- }
266
-
267
- #[napi(object)]
268
- #[derive(Clone, Serialize)]
269
- pub struct FunctionNotPayableErrorStackTraceEntry {
270
- #[napi(
271
- js_name = "type",
272
- ts_type = "StackTraceEntryType.FUNCTION_NOT_PAYABLE_ERROR"
273
- )]
274
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::FUNCTION_NOT_PAYABLE_ERROR as u8 }>,
275
- #[serde(serialize_with = "serialize_evm_value_bigint_using_u256")]
276
- pub value: BigInt,
277
- pub source_reference: SourceReference,
278
- }
279
-
280
- impl From<FunctionNotPayableErrorStackTraceEntry> for SolidityStackTraceEntry {
281
- fn from(val: FunctionNotPayableErrorStackTraceEntry) -> Self {
282
- Either25::H(val)
283
- }
284
- }
285
-
286
- #[napi(object)]
287
- #[derive(Clone, Serialize)]
288
- pub struct InvalidParamsErrorStackTraceEntry {
289
- #[napi(js_name = "type", ts_type = "StackTraceEntryType.INVALID_PARAMS_ERROR")]
290
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::INVALID_PARAMS_ERROR as u8 }>,
291
- pub source_reference: SourceReference,
292
- }
293
-
294
- impl From<InvalidParamsErrorStackTraceEntry> for SolidityStackTraceEntry {
295
- fn from(val: InvalidParamsErrorStackTraceEntry) -> Self {
296
- Either25::I(val)
297
- }
298
- }
299
-
300
- #[napi(object)]
301
- #[derive(Clone, Serialize)]
302
- pub struct FallbackNotPayableErrorStackTraceEntry {
303
- #[napi(
304
- js_name = "type",
305
- ts_type = "StackTraceEntryType.FALLBACK_NOT_PAYABLE_ERROR"
306
- )]
307
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::FALLBACK_NOT_PAYABLE_ERROR as u8 }>,
308
- #[serde(serialize_with = "serialize_evm_value_bigint_using_u256")]
309
- pub value: BigInt,
310
- pub source_reference: SourceReference,
311
- }
312
-
313
- impl From<FallbackNotPayableErrorStackTraceEntry> for SolidityStackTraceEntry {
314
- fn from(val: FallbackNotPayableErrorStackTraceEntry) -> Self {
315
- Either25::J(val)
316
- }
317
- }
318
-
319
- #[napi(object)]
320
- #[derive(Clone, Serialize)]
321
- pub struct FallbackNotPayableAndNoReceiveErrorStackTraceEntry {
322
- #[napi(
323
- js_name = "type",
324
- ts_type = "StackTraceEntryType.FALLBACK_NOT_PAYABLE_AND_NO_RECEIVE_ERROR"
325
- )]
326
- pub type_: StackTraceEntryTypeConst<
327
- { StackTraceEntryType::FALLBACK_NOT_PAYABLE_AND_NO_RECEIVE_ERROR as u8 },
328
- >,
329
- #[serde(serialize_with = "serialize_evm_value_bigint_using_u256")]
330
- pub value: BigInt,
331
- pub source_reference: SourceReference,
332
- }
333
-
334
- impl From<FallbackNotPayableAndNoReceiveErrorStackTraceEntry> for SolidityStackTraceEntry {
335
- fn from(val: FallbackNotPayableAndNoReceiveErrorStackTraceEntry) -> Self {
336
- Either25::K(val)
337
- }
338
- }
339
-
340
- #[napi(object)]
341
- #[derive(Clone, Serialize)]
342
- pub struct UnrecognizedFunctionWithoutFallbackErrorStackTraceEntry {
343
- #[napi(
344
- js_name = "type",
345
- ts_type = "StackTraceEntryType.UNRECOGNIZED_FUNCTION_WITHOUT_FALLBACK_ERROR"
346
- )]
347
- pub type_: StackTraceEntryTypeConst<
348
- { StackTraceEntryType::UNRECOGNIZED_FUNCTION_WITHOUT_FALLBACK_ERROR as u8 },
349
- >,
350
- pub source_reference: SourceReference,
351
- }
352
-
353
- impl From<UnrecognizedFunctionWithoutFallbackErrorStackTraceEntry> for SolidityStackTraceEntry {
354
- fn from(val: UnrecognizedFunctionWithoutFallbackErrorStackTraceEntry) -> Self {
355
- Either25::L(val)
356
- }
357
- }
358
-
359
- #[napi(object)]
360
- #[derive(Clone, Serialize)]
361
- pub struct MissingFallbackOrReceiveErrorStackTraceEntry {
362
- #[napi(
363
- js_name = "type",
364
- ts_type = "StackTraceEntryType.MISSING_FALLBACK_OR_RECEIVE_ERROR"
365
- )]
366
- pub type_:
367
- StackTraceEntryTypeConst<{ StackTraceEntryType::MISSING_FALLBACK_OR_RECEIVE_ERROR as u8 }>,
368
- pub source_reference: SourceReference,
369
- }
370
-
371
- impl From<MissingFallbackOrReceiveErrorStackTraceEntry> for SolidityStackTraceEntry {
372
- fn from(val: MissingFallbackOrReceiveErrorStackTraceEntry) -> Self {
373
- Either25::M(val)
374
- }
375
- }
376
-
377
- #[napi(object)]
378
- #[derive(Clone, Serialize)]
379
- pub struct ReturndataSizeErrorStackTraceEntry {
380
- #[napi(
381
- js_name = "type",
382
- ts_type = "StackTraceEntryType.RETURNDATA_SIZE_ERROR"
383
- )]
384
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::RETURNDATA_SIZE_ERROR as u8 }>,
385
- pub source_reference: SourceReference,
386
- }
387
-
388
- impl From<ReturndataSizeErrorStackTraceEntry> for SolidityStackTraceEntry {
389
- fn from(val: ReturndataSizeErrorStackTraceEntry) -> Self {
390
- Either25::N(val)
391
- }
392
- }
393
-
394
- #[napi(object)]
395
- #[derive(Clone, Serialize)]
396
- pub struct NonContractAccountCalledErrorStackTraceEntry {
397
- #[napi(
398
- js_name = "type",
399
- ts_type = "StackTraceEntryType.NONCONTRACT_ACCOUNT_CALLED_ERROR"
400
- )]
401
- pub type_:
402
- StackTraceEntryTypeConst<{ StackTraceEntryType::NONCONTRACT_ACCOUNT_CALLED_ERROR as u8 }>,
403
- pub source_reference: SourceReference,
404
- }
405
-
406
- impl From<NonContractAccountCalledErrorStackTraceEntry> for SolidityStackTraceEntry {
407
- fn from(val: NonContractAccountCalledErrorStackTraceEntry) -> Self {
408
- Either25::O(val)
409
- }
410
- }
411
-
412
- #[napi(object)]
413
- #[derive(Clone, Serialize)]
414
- pub struct CallFailedErrorStackTraceEntry {
415
- #[napi(js_name = "type", ts_type = "StackTraceEntryType.CALL_FAILED_ERROR")]
416
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::CALL_FAILED_ERROR as u8 }>,
417
- pub source_reference: SourceReference,
418
- }
419
-
420
- impl From<CallFailedErrorStackTraceEntry> for SolidityStackTraceEntry {
421
- fn from(val: CallFailedErrorStackTraceEntry) -> Self {
422
- Either25::P(val)
423
- }
424
- }
425
-
426
- #[napi(object)]
427
- #[derive(Clone, Serialize)]
428
- pub struct DirectLibraryCallErrorStackTraceEntry {
429
- #[napi(
430
- js_name = "type",
431
- ts_type = "StackTraceEntryType.DIRECT_LIBRARY_CALL_ERROR"
432
- )]
433
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::DIRECT_LIBRARY_CALL_ERROR as u8 }>,
434
- pub source_reference: SourceReference,
435
- }
436
-
437
- impl From<DirectLibraryCallErrorStackTraceEntry> for SolidityStackTraceEntry {
438
- fn from(val: DirectLibraryCallErrorStackTraceEntry) -> Self {
439
- Either25::Q(val)
440
- }
441
- }
442
-
443
- #[napi(object)]
444
- #[derive(Clone, Serialize)]
445
- pub struct UnrecognizedCreateErrorStackTraceEntry {
446
- #[napi(
447
- js_name = "type",
448
- ts_type = "StackTraceEntryType.UNRECOGNIZED_CREATE_ERROR"
449
- )]
450
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::UNRECOGNIZED_CREATE_ERROR as u8 }>,
451
- #[serde(serialize_with = "serialize_uint8array_to_hex")]
452
- pub return_data: Uint8Array,
453
- pub source_reference: Option<Undefined>,
454
- pub is_invalid_opcode_error: bool,
455
- }
456
-
457
- impl From<UnrecognizedCreateErrorStackTraceEntry> for SolidityStackTraceEntry {
458
- fn from(val: UnrecognizedCreateErrorStackTraceEntry) -> Self {
459
- Either25::R(val)
460
- }
461
- }
462
-
463
- #[napi(object)]
464
- #[derive(Clone, Serialize)]
465
- pub struct UnrecognizedContractErrorStackTraceEntry {
466
- #[napi(
467
- js_name = "type",
468
- ts_type = "StackTraceEntryType.UNRECOGNIZED_CONTRACT_ERROR"
469
- )]
470
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::UNRECOGNIZED_CONTRACT_ERROR as u8 }>,
471
- #[serde(serialize_with = "serialize_uint8array_to_hex")]
472
- pub address: Uint8Array,
473
- #[serde(serialize_with = "serialize_uint8array_to_hex")]
474
- pub return_data: Uint8Array,
475
- pub source_reference: Option<Undefined>,
476
- pub is_invalid_opcode_error: bool,
477
- }
478
-
479
- impl From<UnrecognizedContractErrorStackTraceEntry> for SolidityStackTraceEntry {
480
- fn from(val: UnrecognizedContractErrorStackTraceEntry) -> Self {
481
- Either25::S(val)
482
- }
483
- }
484
-
485
- #[napi(object)]
486
- #[derive(Clone, Serialize)]
487
- pub struct OtherExecutionErrorStackTraceEntry {
488
- #[napi(
489
- js_name = "type",
490
- ts_type = "StackTraceEntryType.OTHER_EXECUTION_ERROR"
491
- )]
492
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::OTHER_EXECUTION_ERROR as u8 }>,
493
- pub source_reference: Option<SourceReference>,
494
- }
495
-
496
- impl From<OtherExecutionErrorStackTraceEntry> for SolidityStackTraceEntry {
497
- fn from(val: OtherExecutionErrorStackTraceEntry) -> Self {
498
- Either25::T(val)
499
- }
500
- }
501
-
502
- #[napi(object)]
503
- #[derive(Clone, Serialize)]
504
- pub struct UnmappedSolc063RevertErrorStackTraceEntry {
505
- #[napi(
506
- js_name = "type",
507
- ts_type = "StackTraceEntryType.UNMAPPED_SOLC_0_6_3_REVERT_ERROR"
508
- )]
509
- pub type_:
510
- StackTraceEntryTypeConst<{ StackTraceEntryType::UNMAPPED_SOLC_0_6_3_REVERT_ERROR as u8 }>,
511
- pub source_reference: Option<SourceReference>,
512
- }
513
-
514
- impl From<UnmappedSolc063RevertErrorStackTraceEntry> for SolidityStackTraceEntry {
515
- fn from(val: UnmappedSolc063RevertErrorStackTraceEntry) -> Self {
516
- Either25::U(val)
517
- }
518
- }
519
-
520
- #[napi(object)]
521
- #[derive(Clone, Serialize)]
522
- pub struct ContractTooLargeErrorStackTraceEntry {
523
- #[napi(
524
- js_name = "type",
525
- ts_type = "StackTraceEntryType.CONTRACT_TOO_LARGE_ERROR"
526
- )]
527
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::CONTRACT_TOO_LARGE_ERROR as u8 }>,
528
- pub source_reference: Option<SourceReference>,
529
- }
530
-
531
- impl From<ContractTooLargeErrorStackTraceEntry> for SolidityStackTraceEntry {
532
- fn from(val: ContractTooLargeErrorStackTraceEntry) -> Self {
533
- Either25::V(val)
534
- }
535
- }
536
-
537
- #[napi(object)]
538
- #[derive(Clone, Serialize)]
539
- pub struct InternalFunctionCallStackEntry {
540
- #[napi(
541
- js_name = "type",
542
- ts_type = "StackTraceEntryType.INTERNAL_FUNCTION_CALLSTACK_ENTRY"
543
- )]
544
- pub type_:
545
- StackTraceEntryTypeConst<{ StackTraceEntryType::INTERNAL_FUNCTION_CALLSTACK_ENTRY as u8 }>,
546
- pub pc: u32,
547
- pub source_reference: SourceReference,
548
- }
549
-
550
- impl From<InternalFunctionCallStackEntry> for SolidityStackTraceEntry {
551
- fn from(val: InternalFunctionCallStackEntry) -> Self {
552
- Either25::W(val)
553
- }
554
- }
555
-
556
- #[napi(object)]
557
- #[derive(Clone, Serialize)]
558
- pub struct ContractCallRunOutOfGasError {
559
- #[napi(
560
- js_name = "type",
561
- ts_type = "StackTraceEntryType.CONTRACT_CALL_RUN_OUT_OF_GAS_ERROR"
562
- )]
563
- pub type_:
564
- StackTraceEntryTypeConst<{ StackTraceEntryType::CONTRACT_CALL_RUN_OUT_OF_GAS_ERROR as u8 }>,
565
- pub source_reference: Option<SourceReference>,
566
- }
567
-
568
- impl From<ContractCallRunOutOfGasError> for SolidityStackTraceEntry {
569
- fn from(val: ContractCallRunOutOfGasError) -> Self {
570
- Either25::X(val)
571
- }
572
- }
573
-
574
- #[napi(object)]
575
- #[derive(Clone, Serialize)]
576
- pub struct CheatcodeErrorStackTraceEntry {
577
- #[napi(js_name = "type", ts_type = "StackTraceEntryType.CHEATCODE_ERROR")]
578
- pub type_: StackTraceEntryTypeConst<{ StackTraceEntryType::CHEATCODE_ERROR as u8 }>,
579
- // The parsed cheatcode error message that can be displayed to the user
580
- pub message: String,
581
- pub source_reference: SourceReference,
582
- }
583
-
584
- impl From<CheatcodeErrorStackTraceEntry> for SolidityStackTraceEntry {
585
- fn from(val: CheatcodeErrorStackTraceEntry) -> Self {
586
- Either25::Y(val)
587
- }
588
- }
589
-
590
- #[allow(dead_code)]
591
- // NOTE: This ported directly from JS for completeness and is used in the Rust
592
- // side of the bindings. However, napi-rs does not support exporting Rust type
593
- // aliases to the index.d.ts file, and it does not store the type definitions
594
- // when expanding the macros, so to use it we would have to specify this type
595
- // literally (all 26 lines of it) at every #[napi]-exported function, which is
596
- // not ideal.
597
- // Rather, we just bite the bullet for now and use the type alias directly
598
- // (which falls back to `any` as it's not recognized in the context of the
599
- // index.d.ts file) until we finish the porting work.
600
- pub type SolidityStackTraceEntry = Either25<
601
- CallstackEntryStackTraceEntry,
602
- UnrecognizedCreateCallstackEntryStackTraceEntry,
603
- UnrecognizedContractCallstackEntryStackTraceEntry,
604
- PrecompileErrorStackTraceEntry,
605
- RevertErrorStackTraceEntry,
606
- PanicErrorStackTraceEntry,
607
- CustomErrorStackTraceEntry,
608
- FunctionNotPayableErrorStackTraceEntry,
609
- InvalidParamsErrorStackTraceEntry,
610
- FallbackNotPayableErrorStackTraceEntry,
611
- FallbackNotPayableAndNoReceiveErrorStackTraceEntry,
612
- UnrecognizedFunctionWithoutFallbackErrorStackTraceEntry,
613
- MissingFallbackOrReceiveErrorStackTraceEntry,
614
- ReturndataSizeErrorStackTraceEntry,
615
- NonContractAccountCalledErrorStackTraceEntry,
616
- CallFailedErrorStackTraceEntry,
617
- DirectLibraryCallErrorStackTraceEntry,
618
- UnrecognizedCreateErrorStackTraceEntry,
619
- UnrecognizedContractErrorStackTraceEntry,
620
- OtherExecutionErrorStackTraceEntry,
621
- UnmappedSolc063RevertErrorStackTraceEntry,
622
- ContractTooLargeErrorStackTraceEntry,
623
- InternalFunctionCallStackEntry,
624
- ContractCallRunOutOfGasError,
625
- CheatcodeErrorStackTraceEntry,
626
- >;
627
-
628
- impl TryCast<SolidityStackTraceEntry> for edr_solidity::solidity_stack_trace::StackTraceEntry {
629
- type Error = Infallible;
630
-
631
- fn try_cast(self) -> Result<SolidityStackTraceEntry, Self::Error> {
632
- use edr_solidity::solidity_stack_trace::StackTraceEntry;
633
- let result = match self {
634
- StackTraceEntry::CallstackEntry {
635
- source_reference,
636
- function_type,
637
- } => CallstackEntryStackTraceEntry {
638
- type_: StackTraceEntryTypeConst,
639
- source_reference: source_reference.into(),
640
- function_type: function_type.into(),
641
- }
642
- .into(),
643
- StackTraceEntry::UnrecognizedCreateCallstackEntry => {
644
- UnrecognizedCreateCallstackEntryStackTraceEntry {
645
- type_: StackTraceEntryTypeConst,
646
- source_reference: None,
647
- }
648
- .into()
649
- }
650
- StackTraceEntry::UnrecognizedContractCallstackEntry { address } => {
651
- UnrecognizedContractCallstackEntryStackTraceEntry {
652
- type_: StackTraceEntryTypeConst,
653
- address: Uint8Array::with_data_copied(address),
654
- source_reference: None,
655
- }
656
- .into()
657
- }
658
- StackTraceEntry::PrecompileError { precompile } => PrecompileErrorStackTraceEntry {
659
- type_: StackTraceEntryTypeConst,
660
- precompile,
661
- source_reference: None,
662
- }
663
- .into(),
664
- StackTraceEntry::RevertError {
665
- return_data,
666
- source_reference,
667
- is_invalid_opcode_error,
668
- } => RevertErrorStackTraceEntry {
669
- type_: StackTraceEntryTypeConst,
670
- return_data: return_data.into(),
671
- source_reference: source_reference.into(),
672
- is_invalid_opcode_error,
673
- }
674
- .into(),
675
- StackTraceEntry::PanicError {
676
- error_code,
677
- source_reference,
678
- } => PanicErrorStackTraceEntry {
679
- type_: StackTraceEntryTypeConst,
680
- error_code: u256_to_bigint(&error_code),
681
- source_reference: source_reference.map(std::convert::Into::into),
682
- }
683
- .into(),
684
- StackTraceEntry::CheatCodeError {
685
- message,
686
- source_reference,
687
- } => CheatcodeErrorStackTraceEntry {
688
- type_: StackTraceEntryTypeConst,
689
- message,
690
- source_reference: source_reference.into(),
691
- }
692
- .into(),
693
- StackTraceEntry::CustomError {
694
- message,
695
- source_reference,
696
- } => CustomErrorStackTraceEntry {
697
- type_: StackTraceEntryTypeConst,
698
- message,
699
- source_reference: source_reference.into(),
700
- }
701
- .into(),
702
- StackTraceEntry::FunctionNotPayableError {
703
- value,
704
- source_reference,
705
- } => FunctionNotPayableErrorStackTraceEntry {
706
- type_: StackTraceEntryTypeConst,
707
- value: u256_to_bigint(&value),
708
- source_reference: source_reference.into(),
709
- }
710
- .into(),
711
- StackTraceEntry::InvalidParamsError { source_reference } => {
712
- InvalidParamsErrorStackTraceEntry {
713
- type_: StackTraceEntryTypeConst,
714
- source_reference: source_reference.into(),
715
- }
716
- .into()
717
- }
718
- StackTraceEntry::FallbackNotPayableError {
719
- value,
720
- source_reference,
721
- } => FallbackNotPayableErrorStackTraceEntry {
722
- type_: StackTraceEntryTypeConst,
723
- value: u256_to_bigint(&value),
724
- source_reference: source_reference.into(),
725
- }
726
- .into(),
727
- StackTraceEntry::FallbackNotPayableAndNoReceiveError {
728
- value,
729
- source_reference,
730
- } => FallbackNotPayableAndNoReceiveErrorStackTraceEntry {
731
- type_: StackTraceEntryTypeConst,
732
- value: u256_to_bigint(&value),
733
- source_reference: source_reference.into(),
734
- }
735
- .into(),
736
- StackTraceEntry::UnrecognizedFunctionWithoutFallbackError { source_reference } => {
737
- UnrecognizedFunctionWithoutFallbackErrorStackTraceEntry {
738
- type_: StackTraceEntryTypeConst,
739
- source_reference: source_reference.into(),
740
- }
741
- .into()
742
- }
743
- StackTraceEntry::MissingFallbackOrReceiveError { source_reference } => {
744
- MissingFallbackOrReceiveErrorStackTraceEntry {
745
- type_: StackTraceEntryTypeConst,
746
- source_reference: source_reference.into(),
747
- }
748
- .into()
749
- }
750
- StackTraceEntry::ReturndataSizeError { source_reference } => {
751
- ReturndataSizeErrorStackTraceEntry {
752
- type_: StackTraceEntryTypeConst,
753
- source_reference: source_reference.into(),
754
- }
755
- .into()
756
- }
757
- StackTraceEntry::NoncontractAccountCalledError { source_reference } => {
758
- NonContractAccountCalledErrorStackTraceEntry {
759
- type_: StackTraceEntryTypeConst,
760
- source_reference: source_reference.into(),
761
- }
762
- .into()
763
- }
764
- StackTraceEntry::CallFailedError { source_reference } => {
765
- CallFailedErrorStackTraceEntry {
766
- type_: StackTraceEntryTypeConst,
767
- source_reference: source_reference.into(),
768
- }
769
- .into()
770
- }
771
- StackTraceEntry::DirectLibraryCallError { source_reference } => {
772
- DirectLibraryCallErrorStackTraceEntry {
773
- type_: StackTraceEntryTypeConst,
774
- source_reference: source_reference.into(),
775
- }
776
- .into()
777
- }
778
- StackTraceEntry::UnrecognizedCreateError {
779
- return_data,
780
- is_invalid_opcode_error,
781
- } => UnrecognizedCreateErrorStackTraceEntry {
782
- type_: StackTraceEntryTypeConst,
783
- return_data: return_data.into(),
784
- is_invalid_opcode_error,
785
- source_reference: None,
786
- }
787
- .into(),
788
- StackTraceEntry::UnrecognizedContractError {
789
- address,
790
- return_data,
791
- is_invalid_opcode_error,
792
- } => UnrecognizedContractErrorStackTraceEntry {
793
- type_: StackTraceEntryTypeConst,
794
- address: Uint8Array::with_data_copied(address),
795
- return_data: return_data.into(),
796
- is_invalid_opcode_error,
797
- source_reference: None,
798
- }
799
- .into(),
800
- StackTraceEntry::OtherExecutionError { source_reference } => {
801
- OtherExecutionErrorStackTraceEntry {
802
- type_: StackTraceEntryTypeConst,
803
- source_reference: source_reference.map(std::convert::Into::into),
804
- }
805
- .into()
806
- }
807
- StackTraceEntry::UnmappedSolc0_6_3RevertError { source_reference } => {
808
- UnmappedSolc063RevertErrorStackTraceEntry {
809
- type_: StackTraceEntryTypeConst,
810
- source_reference: source_reference.map(std::convert::Into::into),
811
- }
812
- .into()
813
- }
814
- StackTraceEntry::ContractTooLargeError { source_reference } => {
815
- ContractTooLargeErrorStackTraceEntry {
816
- type_: StackTraceEntryTypeConst,
817
- source_reference: source_reference.map(std::convert::Into::into),
818
- }
819
- .into()
820
- }
821
- StackTraceEntry::InternalFunctionCallstackEntry {
822
- pc,
823
- source_reference,
824
- } => InternalFunctionCallStackEntry {
825
- type_: StackTraceEntryTypeConst,
826
- pc,
827
- source_reference: source_reference.into(),
828
- }
829
- .into(),
830
- StackTraceEntry::ContractCallRunOutOfGasError { source_reference } => {
831
- ContractCallRunOutOfGasError {
832
- type_: StackTraceEntryTypeConst,
833
- source_reference: source_reference.map(std::convert::Into::into),
834
- }
835
- .into()
836
- }
837
- };
838
- Ok(result)
839
- }
840
- }
841
-
842
- #[allow(dead_code)]
843
- // Same as above, but for the `SolidityStackTrace` type.
844
- pub type SolidityStackTrace = Vec<SolidityStackTraceEntry>;
845
-
846
- const _: () = {
847
- const fn assert_to_from_napi_value<T: FromNapiValue + ToNapiValue>() {}
848
- assert_to_from_napi_value::<SolidityStackTraceEntry>();
849
- };
850
-
851
- /// Serializes a [`BigInt`] that represents an EVM value as a
852
- /// [`edr_primitives::U256`].
853
- fn serialize_evm_value_bigint_using_u256<S>(bigint: &BigInt, s: S) -> Result<S::Ok, S::Error>
854
- where
855
- S: Serializer,
856
- {
857
- let val = U256::from_limbs_slice(&bigint.words);
858
-
859
- val.serialize(s)
860
- }
861
-
862
- fn serialize_uint8array_to_hex<S>(uint8array: &Uint8Array, s: S) -> Result<S::Ok, S::Error>
863
- where
864
- S: Serializer,
865
- {
866
- let hex = hex::encode(uint8array.as_ref());
867
-
868
- hex.serialize(s)
869
- }