From 2caac597ceb853e7b8f3684e9d48fdd3c7c90d3c Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Tue, 18 Feb 2025 22:15:56 +0000 Subject: [PATCH 1/5] test: add tracing test for evm foreign asset registrations --- ...st-trace-evm-foreign-asset-registration.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/suites/tracing-tests/test-trace-evm-foreign-asset-registration.ts diff --git a/test/suites/tracing-tests/test-trace-evm-foreign-asset-registration.ts b/test/suites/tracing-tests/test-trace-evm-foreign-asset-registration.ts new file mode 100644 index 0000000000..8d4413ff45 --- /dev/null +++ b/test/suites/tracing-tests/test-trace-evm-foreign-asset-registration.ts @@ -0,0 +1,42 @@ +import { customDevRpcRequest, describeSuite, expect } from "@moonwall/cli"; +import { + ARBITRARY_ASSET_ID, + registerForeignAsset, + RELAY_SOURCE_LOCATION_V4, + relayAssetMetadata, +} from "../../helpers"; + +describeSuite({ + id: "T16", + title: "Trace ERC20 Foreign asset creation", + foundationMethods: "dev", + testCases: ({ context, it }) => { + it({ + id: "T01", + title: "Ensure native ERC20 foreign asset creation is traceable", + timeout: 50000, + test: async function () { + const assetLocation = RELAY_SOURCE_LOCATION_V4; + const assetId = ARBITRARY_ASSET_ID; + + // Register the asset + await registerForeignAsset(context, assetId, assetLocation, relayAssetMetadata); + + const number = await context.viem().getBlockNumber(); + const traces = await customDevRpcRequest("debug_traceBlockByNumber", [ + number.toString(), + { tracer: "callTracer" }, + ]); + + expect(traces).to.toMatchSnapshot([ + { + result: { + to: "0xffffffff1fcacbd218edc0eba20fc2308c778080", + type: "CREATE", + }, + }, + ]); + }, + }); + }, +}); From ccfd1ced4e8592d70c724291bc43fc83273a9f2b Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Tue, 18 Feb 2025 22:29:04 +0000 Subject: [PATCH 2/5] Trace calls originated from pallet_ethereum_xcm force_transact_as call --- .../src/impl_moonbeam_xcm_call_tracing.rs | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/runtime/common/src/impl_moonbeam_xcm_call_tracing.rs b/runtime/common/src/impl_moonbeam_xcm_call_tracing.rs index ffddb3b88f..635d8cc4e0 100644 --- a/runtime/common/src/impl_moonbeam_xcm_call_tracing.rs +++ b/runtime/common/src/impl_moonbeam_xcm_call_tracing.rs @@ -31,14 +31,14 @@ macro_rules! impl_moonbeam_xcm_call_tracing { origin: RuntimeOrigin, ) -> CallResult { if let Ok(raw_origin) = TryInto::>::try_into(origin.clone().caller) { - match (call.clone(), raw_origin) { - ( - RuntimeCall::EthereumXcm(pallet_ethereum_xcm::Call::transact { xcm_transaction }) | - RuntimeCall::EthereumXcm(pallet_ethereum_xcm::Call::transact_through_proxy { - xcm_transaction, .. - }), - RawOrigin::Signed(account_id) - ) => { + match call.clone() { + RuntimeCall::EthereumXcm(pallet_ethereum_xcm::Call::transact { xcm_transaction }) | + RuntimeCall::EthereumXcm(pallet_ethereum_xcm::Call::transact_through_proxy { + xcm_transaction, .. + }) | + RuntimeCall::EthereumXcm(pallet_ethereum_xcm::Call::force_transact_as { + xcm_transaction, .. + }) => { use crate::EthereumXcm; use moonbeam_evm_tracer::tracer::EvmTracer; use xcm_primitives::{ @@ -52,9 +52,14 @@ macro_rules! impl_moonbeam_xcm_call_tracing { let dispatch_call = || { RuntimeCall::dispatch( call, - pallet_ethereum_xcm::Origin::XcmEthereumTransaction( - account_id.into() - ).into() + match raw_origin { + RawOrigin::Signed(account_id) => { + pallet_ethereum_xcm::Origin::XcmEthereumTransaction( + account_id.into() + ).into() + }, + origin => origin.into() + } ) }; From 0a7478b6c37f91cfa541c26d3282d50027aa7e26 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Wed, 19 Feb 2025 08:59:12 +0000 Subject: [PATCH 3/5] update test id and match condition --- .../test-trace-evm-foreign-asset-registration.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/suites/tracing-tests/test-trace-evm-foreign-asset-registration.ts b/test/suites/tracing-tests/test-trace-evm-foreign-asset-registration.ts index 8d4413ff45..b0ff655950 100644 --- a/test/suites/tracing-tests/test-trace-evm-foreign-asset-registration.ts +++ b/test/suites/tracing-tests/test-trace-evm-foreign-asset-registration.ts @@ -7,7 +7,7 @@ import { } from "../../helpers"; describeSuite({ - id: "T16", + id: "T17", title: "Trace ERC20 Foreign asset creation", foundationMethods: "dev", testCases: ({ context, it }) => { @@ -28,7 +28,7 @@ describeSuite({ { tracer: "callTracer" }, ]); - expect(traces).to.toMatchSnapshot([ + expect(traces).to.toMatchObject([ { result: { to: "0xffffffff1fcacbd218edc0eba20fc2308c778080", From 05d17cce3bd3b4c7f386646e0b76681483462a6b Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Wed, 19 Feb 2025 11:50:36 +0000 Subject: [PATCH 4/5] Add warning when the number of transactions does not match with the number of traces --- client/rpc/debug/Cargo.toml | 1 + client/rpc/debug/src/lib.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/client/rpc/debug/Cargo.toml b/client/rpc/debug/Cargo.toml index dc2944dc9c..fa67c13439 100644 --- a/client/rpc/debug/Cargo.toml +++ b/client/rpc/debug/Cargo.toml @@ -8,6 +8,7 @@ repository = { workspace = true } version = "0.1.0" [dependencies] +log = { workspace = true } futures = { workspace = true, features = [ "compat" ] } hex-literal = { workspace = true } jsonrpsee = { workspace = true, features = [ "macros", "server" ] } diff --git a/client/rpc/debug/src/lib.rs b/client/rpc/debug/src/lib.rs index 6259c6c749..c4fe13a93f 100644 --- a/client/rpc/debug/src/lib.rs +++ b/client/rpc/debug/src/lib.rs @@ -527,6 +527,17 @@ where }) .collect::>(); + let n_txs = eth_transactions_by_index.len(); + let n_traces = result.len(); + if eth_transactions_by_index.len() != result.len() { + log::warn!( + "The traces in block {:?} don't match with the number of ethereum transactions. (txs: {}, traces: {})", + request_block_id, + n_txs, + n_traces + ); + } + Ok(result) } _ => Err(internal_err( From 941e21dd795ed41607a6e1e7cd66a40a43171fb0 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Wed, 19 Feb 2025 11:58:58 +0000 Subject: [PATCH 5/5] fix changes added in previous commit --- Cargo.lock | 1 + client/rpc/debug/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 4badc1cb90..df1964ca06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6592,6 +6592,7 @@ dependencies = [ "futures 0.3.30", "hex-literal 0.4.1", "jsonrpsee", + "log", "moonbeam-client-evm-tracing", "moonbeam-rpc-core-debug", "moonbeam-rpc-core-types", diff --git a/client/rpc/debug/src/lib.rs b/client/rpc/debug/src/lib.rs index c4fe13a93f..71a70db7a8 100644 --- a/client/rpc/debug/src/lib.rs +++ b/client/rpc/debug/src/lib.rs @@ -529,7 +529,7 @@ where let n_txs = eth_transactions_by_index.len(); let n_traces = result.len(); - if eth_transactions_by_index.len() != result.len() { + if n_txs != n_traces { log::warn!( "The traces in block {:?} don't match with the number of ethereum transactions. (txs: {}, traces: {})", request_block_id,