Skip to content

Commit

Permalink
evm tracing test (#1259)
Browse files Browse the repository at this point in the history
* evm tracing tests

* fix

* update gha

* fmt cargo
  • Loading branch information
ermalkaleci authored Jun 12, 2024
1 parent b1cd838 commit 6842af3
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/frontier-rpc-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: rustup target list --installed

- name: Build astar-collator
run: cargo build --release --locked --features manual-seal --bin astar-collator
run: cargo build --release --locked --features manual-seal,evm-tracing --bin astar-collator

- name: Clone frontier tests
run: git clone https://github.com/AstarNetwork/frontier-tests.git --depth 1
Expand Down
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions bin/collator/src/evm_tracing_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,16 @@ pub struct EvmTracingConfig {
#[derive(Debug, Parser)]
pub struct EthApiOptions {
/// Enable EVM tracing module on a non-authority node.
#[clap(
long,
conflicts_with = "collator",
conflicts_with = "validator",
value_delimiter = ','
#[cfg_attr(
not(feature = "manual-seal"),
clap(
long,
conflicts_with = "collator",
conflicts_with = "validator",
value_delimiter = ','
)
)]
#[cfg_attr(feature = "manual-seal", clap(long))]
pub ethapi: Vec<EthApi>,

/// Number of concurrent tracing tasks. Meant to be shared by both "debug" and "trace" modules.
Expand Down
32 changes: 31 additions & 1 deletion bin/collator/src/local/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ pub fn start_node(
prometheus_registry.clone(),
));

#[cfg(feature = "manual-seal")]
let (command_sink, commands_stream) = futures::channel::mpsc::channel(1024);

let rpc_extensions_builder = {
let client = client.clone();
let network = network.clone();
Expand Down Expand Up @@ -376,7 +379,7 @@ pub fn start_node(
overrides: overrides.clone(),
enable_evm_rpc: true, // enable EVM RPC for dev node by default
#[cfg(feature = "manual-seal")]
command_sink: None,
command_sink: Some(command_sink.clone()),
};

crate::rpc::create_full(
Expand Down Expand Up @@ -415,6 +418,33 @@ pub fn start_node(

let slot_duration = sc_consensus_aura::slot_duration(&*client)?;

#[cfg(feature = "manual-seal")]
let aura = sc_consensus_manual_seal::run_manual_seal(
sc_consensus_manual_seal::ManualSealParams {
block_import,
env: proposer_factory,
client: client.clone(),
pool: transaction_pool.clone(),
commands_stream,
select_chain,
consensus_data_provider: Some(Box::new(
sc_consensus_manual_seal::consensus::aura::AuraConsensusDataProvider::new(
client.clone(),
),
)),
create_inherent_data_providers: move |_, ()| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
let slot =
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration.clone(),
);
Ok((slot, timestamp))
},
},
);

#[cfg(not(feature = "manual-seal"))]
let aura = sc_consensus_aura::start_aura::<AuraPair, _, _, _, _, _, _, _, _, _, _>(
StartAuraParams {
slot_duration,
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ astar-test-utils = { workspace = true }
shibuya-runtime = { workspace = true, optional = true }
shiden-runtime = { workspace = true, optional = true }

# evm-tracing tests
ethereum = { workspace = true, features = ["with-codec"], optional = true }
fp-rpc = { workspace = true, optional = true }
moonbeam-rpc-primitives-debug = { workspace = true, optional = true }
pallet-ethereum = { workspace = true, optional = true }

[features]
default = ["std"]
std = [
Expand All @@ -64,3 +70,13 @@ std = [
shibuya = ["shibuya-runtime"]
shiden = ["shiden-runtime"]
astar = ["astar-runtime"]

evm-tracing = [
"shibuya-runtime?/evm-tracing",
"shiden-runtime?/evm-tracing",
"astar-runtime?/evm-tracing",
"ethereum",
"pallet-ethereum",
"moonbeam-rpc-primitives-debug",
"fp-rpc",
]
117 changes: 117 additions & 0 deletions tests/integration/src/evm_tracing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// This file is part of Astar.

// Copyright (C) Stake Technologies Pte.Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later

// Astar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Astar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

#[cfg(test)]
#[cfg(feature = "evm-tracing")]
mod tests {
use crate::setup::*;

use astar_primitives::Header;
use fp_rpc::ConvertTransaction;
use moonbeam_rpc_primitives_debug::runtime_decl_for_debug_runtime_api::DebugRuntimeApi;

// A valid signed Alice transfer.
pub const VALID_ETH_TX: &str =
"02f869820501808085e8d4a51000825208943cd0a705a2dc65e5b1e1205896baa2be8a07c6e00180c\
001a061087911e877a5802142a89a40d231d50913db399eb50839bb2d04e612b22ec8a01aa313efdf2\
793bea76da6813bda611444af16a6207a8cfef2d9c8aa8f8012f7";

// An invalid signed Alice transfer with a gas limit artifically set to 0.
pub const INVALID_ETH_TX: &str =
"f8628085174876e800809412cb274aad8251c875c0bf6872b67d9983e53fdd01801ba011110796057\
0e2d49fcc2afbc582e1abd3eeb027242b92abcebcec7cdefab63ea001732f6fac84acdd5b096554230\
75003e7f07430652c3d6722e18f50b3d34e29";

pub struct TransactionConverter;

impl ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {
fn convert_transaction(
&self,
transaction: pallet_ethereum::Transaction,
) -> UncheckedExtrinsic {
UncheckedExtrinsic::new_unsigned(
pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),
)
}
}

pub fn unchecked_eth_tx(raw_hex_tx: &str) -> UncheckedExtrinsic {
let converter = TransactionConverter;
converter.convert_transaction(ethereum_transaction(raw_hex_tx))
}

pub fn ethereum_transaction(raw_hex_tx: &str) -> pallet_ethereum::Transaction {
let bytes = hex::decode(raw_hex_tx).expect("Transaction bytes.");
let transaction = ethereum::EnvelopedDecodable::decode(&bytes[..]);
assert!(transaction.is_ok());
transaction.unwrap()
}

#[test]
fn debug_runtime_api_trace_transaction() {
new_test_ext().execute_with(|| {
let non_eth_uxt = UncheckedExtrinsic::new_unsigned(
pallet_balances::Call::<Runtime>::transfer_allow_death {
dest: MultiAddress::Id(AccountId::from(BOB)),
value: 1 * UNIT,
}
.into(),
);
let transaction = ethereum_transaction(VALID_ETH_TX);
let eth_uxt = unchecked_eth_tx(VALID_ETH_TX);
let block = Header {
digest: Default::default(),
extrinsics_root: Default::default(),
number: 1,
parent_hash: Default::default(),
state_root: Default::default(),
};
assert_ok!(Runtime::trace_transaction(
vec![non_eth_uxt.clone(), eth_uxt, non_eth_uxt.clone()],
&transaction,
));
});
}

#[test]
fn debug_runtime_api_trace_block() {
new_test_ext().execute_with(|| {
let non_eth_uxt = UncheckedExtrinsic::new_unsigned(
pallet_balances::Call::<Runtime>::transfer_allow_death {
dest: MultiAddress::Id(AccountId::from(BOB)),
value: 1 * UNIT,
}
.into(),
);
let eth_uxt = unchecked_eth_tx(VALID_ETH_TX);
let eth_tx = ethereum_transaction(VALID_ETH_TX);
let eth_extrinsic_hash = eth_tx.hash();
let block = Header {
digest: Default::default(),
extrinsics_root: Default::default(),
number: 1,
parent_hash: Default::default(),
state_root: Default::default(),
};
assert_ok!(Runtime::trace_block(
vec![non_eth_uxt.clone(), eth_uxt.clone(), non_eth_uxt, eth_uxt],
vec![eth_extrinsic_hash, eth_extrinsic_hash],
));
});
}
}
3 changes: 3 additions & 0 deletions tests/integration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ mod assets_chain_extensions;

#[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))]
mod oracle;

#[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))]
mod evm_tracing;

0 comments on commit 6842af3

Please sign in to comment.