1
- use crate :: test_ethereum_tx:: {
2
- EIP1559UnsignedTransaction , EIP2930UnsignedTransaction , LegacyUnsignedTransaction ,
3
- } ;
4
1
use codec:: Encode ;
5
2
use domain_runtime_primitives:: { Balance , CheckExtrinsicsValidityError } ;
6
3
use domain_test_service:: evm_domain_test_runtime:: {
@@ -11,125 +8,27 @@ use domain_test_service::Sr25519Keyring::Ferdie;
11
8
use domain_test_service:: { construct_extrinsic_raw_payload, EvmDomainNode } ;
12
9
use ethereum:: TransactionV2 as Transaction ;
13
10
use fp_rpc:: EthereumRuntimeRPCApi ;
14
- use frame_support:: pallet_prelude:: DispatchClass ;
15
11
use pallet_ethereum:: Call ;
16
- use pallet_evm:: GasWeightMapping ;
17
12
use rand:: distributions:: { Distribution , Uniform } ;
18
13
use sc_client_api:: { HeaderBackend , StorageProof } ;
19
14
use sc_service:: { BasePath , Role } ;
20
15
use sp_api:: { ApiExt , ProvideRuntimeApi , TransactionOutcome } ;
21
16
use sp_core:: ecdsa:: Pair ;
22
- use sp_core:: { keccak_256, Pair as _, H160 , H256 , U256 } ;
17
+ use sp_core:: { keccak_256, Pair as _, U256 } ;
23
18
use sp_domains:: core_api:: DomainCoreApi ;
19
+ use sp_domains:: test_ethereum:: {
20
+ address_build, generate_eip1559_tx, generate_eip2930_tx, generate_legacy_tx, AccountInfo ,
21
+ } ;
24
22
use sp_runtime:: traits:: { Extrinsic , Zero } ;
25
23
use sp_runtime:: transaction_validity:: { InvalidTransaction , TransactionValidityError } ;
26
24
use sp_runtime:: OpaqueExtrinsic ;
27
25
use subspace_test_service:: { produce_block_with, produce_blocks, MockConsensusNode } ;
28
26
use tempfile:: TempDir ;
29
27
30
- #[ derive( Clone ) ]
31
- pub struct AccountInfo {
32
- pub address : H160 ,
33
- pub private_key : H256 ,
34
- }
35
-
36
- fn address_build ( seed_number : u128 ) -> AccountInfo {
37
- let mut seed = [ 0u8 ; 32 ] ;
38
- seed[ 0 ..16 ] . copy_from_slice ( & seed_number. to_be_bytes ( ) ) ;
39
- let private_key = H256 :: from_slice ( & seed) ;
40
- let secret_key = libsecp256k1:: SecretKey :: parse_slice ( & private_key[ ..] ) . unwrap ( ) ;
41
- let public_key = & libsecp256k1:: PublicKey :: from_secret_key ( & secret_key) . serialize ( ) [ 1 ..65 ] ;
42
- let address = H160 :: from ( H256 :: from ( keccak_256 ( public_key) ) ) ;
43
-
44
- let mut data = [ 0u8 ; 32 ] ;
45
- data[ 0 ..20 ] . copy_from_slice ( & address[ ..] ) ;
46
-
47
- AccountInfo {
48
- private_key,
49
- address,
50
- }
51
- }
52
-
53
- fn generate_legacy_tx (
54
- account_info : AccountInfo ,
55
- nonce : U256 ,
56
- action : ethereum:: TransactionAction ,
57
- input : Vec < u8 > ,
58
- gas_price : U256 ,
59
- ) -> Transaction {
60
- let limits: frame_system:: limits:: BlockWeights =
61
- <TestRuntime as frame_system:: Config >:: BlockWeights :: get ( ) ;
62
- // `limits.get(DispatchClass::Normal).max_extrinsic` is too large to use as `gas_limit`
63
- // thus use `base_extrinsic`
64
- let max_extrinsic = limits. get ( DispatchClass :: Normal ) . base_extrinsic * 1000 ;
65
- let max_extrinsic_gas =
66
- <TestRuntime as pallet_evm:: Config >:: GasWeightMapping :: weight_to_gas ( max_extrinsic) ;
67
-
68
- LegacyUnsignedTransaction {
69
- nonce,
70
- gas_price,
71
- gas_limit : U256 :: from ( max_extrinsic_gas) ,
72
- action,
73
- value : U256 :: zero ( ) ,
74
- input,
75
- }
76
- . sign ( & account_info. private_key )
77
- }
78
-
79
- fn generate_eip2930_tx (
80
- account_info : AccountInfo ,
81
- nonce : U256 ,
82
- action : ethereum:: TransactionAction ,
83
- input : Vec < u8 > ,
84
- gas_price : U256 ,
85
- ) -> Transaction {
86
- let limits: frame_system:: limits:: BlockWeights =
87
- <TestRuntime as frame_system:: Config >:: BlockWeights :: get ( ) ;
88
- // `limits.get(DispatchClass::Normal).max_extrinsic` is too large to use as `gas_limit`
89
- // thus use `base_extrinsic`
90
- let max_extrinsic = limits. get ( DispatchClass :: Normal ) . base_extrinsic * 100 ;
91
- let max_extrinsic_gas =
92
- <TestRuntime as pallet_evm:: Config >:: GasWeightMapping :: weight_to_gas ( max_extrinsic) ;
93
-
94
- EIP2930UnsignedTransaction {
95
- nonce,
96
- gas_price,
97
- gas_limit : U256 :: from ( max_extrinsic_gas) ,
98
- action,
99
- value : U256 :: one ( ) ,
100
- input,
101
- }
102
- . sign ( & account_info. private_key , None )
103
- }
104
-
105
- fn generate_eip1559_tx (
106
- account_info : AccountInfo ,
107
- nonce : U256 ,
108
- action : ethereum:: TransactionAction ,
109
- input : Vec < u8 > ,
110
- gas_price : U256 ,
111
- ) -> Transaction {
112
- let limits: frame_system:: limits:: BlockWeights =
113
- <TestRuntime as frame_system:: Config >:: BlockWeights :: get ( ) ;
114
- // `limits.get(DispatchClass::Normal).max_extrinsic` is too large to use as `gas_limit`
115
- // thus use `base_extrinsic`
116
- let max_extrinsic = limits. get ( DispatchClass :: Normal ) . base_extrinsic * 1000 ;
117
- let max_extrinsic_gas =
118
- <TestRuntime as pallet_evm:: Config >:: GasWeightMapping :: weight_to_gas ( max_extrinsic) ;
119
-
120
- EIP1559UnsignedTransaction {
121
- nonce,
122
- max_priority_fee_per_gas : U256 :: from ( 1 ) ,
123
- max_fee_per_gas : gas_price,
124
- gas_limit : U256 :: from ( max_extrinsic_gas) ,
125
- action,
126
- value : U256 :: zero ( ) ,
127
- input,
128
- }
129
- . sign ( & account_info. private_key , None )
130
- }
131
-
132
- fn generate_evm_domain_extrinsic ( tx : Transaction ) -> RuntimeUncheckedExtrinsic {
28
+ /// Generate a self-contained EVM domain extrinsic.
29
+ // This function depends on the macro-constructed `TestRuntime::RuntimeCall` enum, so it can't be
30
+ // shared via `sp_domains::test_ethereum`.
31
+ pub fn generate_evm_domain_extrinsic ( tx : Transaction ) -> RuntimeUncheckedExtrinsic {
133
32
let call = Call :: < TestRuntime > :: transact { transaction : tx } ;
134
33
fp_self_contained:: UncheckedExtrinsic :: new ( RuntimeCall :: Ethereum ( call) , None ) . unwrap ( )
135
34
}
@@ -191,7 +90,7 @@ async fn benchmark_bundle_with_evm_tx(
191
90
) ;
192
91
let extrinsic = match tx_type_to_use {
193
92
0 => {
194
- let evm_tx = generate_eip1559_tx (
93
+ let evm_tx = generate_eip1559_tx :: < TestRuntime > (
195
94
account_info. clone ( ) ,
196
95
U256 :: zero ( ) ,
197
96
ethereum:: TransactionAction :: Create ,
@@ -201,7 +100,7 @@ async fn benchmark_bundle_with_evm_tx(
201
100
generate_evm_domain_extrinsic ( evm_tx)
202
101
}
203
102
1 => {
204
- let evm_tx = generate_eip2930_tx (
103
+ let evm_tx = generate_eip2930_tx :: < TestRuntime > (
205
104
account_info. clone ( ) ,
206
105
U256 :: zero ( ) ,
207
106
ethereum:: TransactionAction :: Create ,
@@ -211,7 +110,7 @@ async fn benchmark_bundle_with_evm_tx(
211
110
generate_evm_domain_extrinsic ( evm_tx)
212
111
}
213
112
2 => {
214
- let evm_tx = generate_legacy_tx (
113
+ let evm_tx = generate_legacy_tx :: < TestRuntime > (
215
114
account_info. clone ( ) ,
216
115
U256 :: zero ( ) ,
217
116
ethereum:: TransactionAction :: Create ,
@@ -727,9 +626,9 @@ async fn test_evm_domain_block_fee() {
727
626
let tx_generators: Vec <
728
627
Box < dyn Fn ( AccountInfo , U256 , ethereum:: TransactionAction , Vec < u8 > , U256 ) -> Transaction > ,
729
628
> = vec ! [
730
- Box :: new( generate_eip2930_tx) ,
731
- Box :: new( generate_eip1559_tx) ,
732
- Box :: new( generate_legacy_tx) ,
629
+ Box :: new( generate_eip2930_tx:: < TestRuntime > ) ,
630
+ Box :: new( generate_eip1559_tx:: < TestRuntime > ) ,
631
+ Box :: new( generate_legacy_tx:: < TestRuntime > ) ,
733
632
] ;
734
633
for ( i, ( acc, tx_generator) ) in account_infos
735
634
. iter ( )
0 commit comments