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
//! Moonriver 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 * MOVR),
42
1
				(AccountId::from(ALICE), 2_000 * MOVR),
43
1
				(AccountId::from(BOB), 1_000 * MOVR),
44
1
			])
45
1
			.build()
46
1
			.execute_with(|| {
47
1
				let non_eth_uxt = UncheckedExtrinsic::new_bare(
48
1
					pallet_balances::Call::<Runtime>::transfer_allow_death {
49
1
						dest: AccountId::from(BOB),
50
1
						value: 1 * MOVR,
51
1
					}
52
1
					.into(),
53
1
				);
54
1
				let transaction = ethereum_transaction(VALID_ETH_TX);
55
1
				let eth_uxt = unchecked_eth_tx(VALID_ETH_TX);
56
1
				let block = Header {
57
1
					digest: Default::default(),
58
1
					extrinsics_root: Default::default(),
59
1
					number: 1,
60
1
					parent_hash: Default::default(),
61
1
					state_root: Default::default(),
62
1
				};
63
1
				assert!(Runtime::trace_transaction(
64
1
					vec![non_eth_uxt.clone(), eth_uxt, non_eth_uxt.clone()],
65
1
					&transaction,
66
1
					&block
67
1
				)
68
1
				.is_ok());
69
1
			});
70
1
	}
71

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

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