1
// Copyright 2019-2025 PureStake Inc.
2
// This file is part of Moonbeam.
3

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

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

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

            
17
//! Moonbase EVM tracing Integration Tests
18

            
19
mod common;
20

            
21
#[cfg(test)]
22
#[cfg(feature = "evm-tracing")]
23
mod tests {
24
	use super::common::*;
25

            
26
	use pallet_evm::AddressMapping;
27
	use sp_core::{H160, U256};
28

            
29
	use moonbeam_core_primitives::Header;
30
	use moonbeam_rpc_primitives_debug::runtime_decl_for_debug_runtime_api::DebugRuntimeApi;
31
	use std::str::FromStr;
32

            
33
	#[test]
34
1
	fn debug_runtime_api_trace_transaction() {
35
1
		let alith = <Runtime as pallet_evm::Config>::AddressMapping::into_account_id(
36
1
			H160::from_str("6be02d1d3665660d22ff9624b7be0551ee1ac91b")
37
1
				.expect("internal H160 is valid; qed"),
38
1
		);
39
1
		ExtBuilder::default()
40
1
			.with_balances(vec![
41
1
				(alith, 2_000 * UNIT),
42
1
				(AccountId::from(ALICE), 2_000 * UNIT),
43
1
				(AccountId::from(BOB), 1_000 * UNIT),
44
1
			])
45
1
			.build()
46
1
			.execute_with(|| {
47
1
				set_parachain_inherent_data();
48
1
				let non_eth_uxt = UncheckedExtrinsic::new_bare(
49
1
					pallet_balances::Call::<Runtime>::transfer_allow_death {
50
1
						dest: AccountId::from(BOB),
51
1
						value: 1 * UNIT,
52
1
					}
53
1
					.into(),
54
1
				);
55
1
				let transaction = ethereum_transaction(VALID_ETH_TX);
56
1
				let eth_uxt = unchecked_eth_tx(VALID_ETH_TX);
57
1
				let block = Header {
58
1
					digest: Default::default(),
59
1
					extrinsics_root: Default::default(),
60
1
					number: 1,
61
1
					parent_hash: Default::default(),
62
1
					state_root: Default::default(),
63
1
				};
64
1
				assert!(Runtime::trace_transaction(
65
1
					vec![non_eth_uxt.clone(), eth_uxt, non_eth_uxt.clone()],
66
1
					&transaction,
67
1
					&block
68
1
				)
69
1
				.is_ok());
70
1
			});
71
1
	}
72

            
73
	#[test]
74
1
	fn debug_runtime_api_trace_block() {
75
1
		let alith = <Runtime as pallet_evm::Config>::AddressMapping::into_account_id(
76
1
			H160::from_str("6be02d1d3665660d22ff9624b7be0551ee1ac91b")
77
1
				.expect("internal H160 is valid; qed"),
78
1
		);
79
1
		ExtBuilder::default()
80
1
			.with_balances(vec![
81
1
				(alith, 2_000 * UNIT),
82
1
				(AccountId::from(ALICE), 2_000 * UNIT),
83
1
				(AccountId::from(BOB), 1_000 * UNIT),
84
1
			])
85
1
			.build()
86
1
			.execute_with(|| {
87
1
				set_parachain_inherent_data();
88
1
				let non_eth_uxt = UncheckedExtrinsic::new_bare(
89
1
					pallet_balances::Call::<Runtime>::transfer_allow_death {
90
1
						dest: AccountId::from(BOB),
91
1
						value: 1 * UNIT,
92
1
					}
93
1
					.into(),
94
1
				);
95
1
				let eth_uxt = unchecked_eth_tx(VALID_ETH_TX);
96
1
				let eth_tx = ethereum_transaction(VALID_ETH_TX);
97
1
				let eth_extrinsic_hash = eth_tx.hash();
98
1
				let block = Header {
99
1
					digest: Default::default(),
100
1
					extrinsics_root: Default::default(),
101
1
					number: 1,
102
1
					parent_hash: Default::default(),
103
1
					state_root: Default::default(),
104
1
				};
105
1
				assert!(Runtime::trace_block(
106
1
					vec![non_eth_uxt.clone(), eth_uxt.clone(), non_eth_uxt, eth_uxt],
107
1
					vec![eth_extrinsic_hash, eth_extrinsic_hash],
108
1
					&block
109
1
				)
110
1
				.is_ok());
111
1
			});
112
1
	}
113

            
114
	#[test]
115
1
	fn debug_runtime_api_trace_call() {
116
1
		let block = Header {
117
1
			digest: Default::default(),
118
1
			extrinsics_root: Default::default(),
119
1
			number: 1,
120
1
			parent_hash: Default::default(),
121
1
			state_root: Default::default(),
122
1
		};
123
1
		let alith = H160::from_str("6be02d1d3665660d22ff9624b7be0551ee1ac91b")
124
1
			.expect("internal H160 is valid; qed");
125
1
		let alith_account_id =
126
1
			<Runtime as pallet_evm::Config>::AddressMapping::into_account_id(alith);
127
1
		ExtBuilder::default()
128
1
			.with_balances(vec![(alith_account_id, 100 * UNIT)])
129
1
			.build()
130
1
			.execute_with(|| {
131
1
				assert!(Runtime::trace_call(
132
1
					&block,
133
1
					alith,
134
1
					H160::random(),
135
1
					Vec::new(),
136
1
					U256::from(99),
137
1
					U256::max_value(),
138
1
					Some(U256::one()),
139
1
					Some(U256::one()),
140
1
					None,
141
1
					None,
142
1
					None,
143
1
				)
144
1
				.is_ok());
145
1
			});
146
1
	}
147
}