@@ -17,8 +17,11 @@ use domain_test_service::evm_domain_test_runtime::{
17
17
} ;
18
18
use domain_test_service:: EcdsaKeyring :: { Alice , Bob , Charlie , Dave , Eve } ;
19
19
use domain_test_service:: Sr25519Keyring :: { self , Alice as Sr25519Alice , Ferdie } ;
20
- use domain_test_service:: { construct_extrinsic_generic, AUTO_ID_DOMAIN_ID , EVM_DOMAIN_ID } ;
20
+ use domain_test_service:: {
21
+ construct_extrinsic_generic, DomainNode , AUTO_ID_DOMAIN_ID , EVM_DOMAIN_ID ,
22
+ } ;
21
23
use ethereum:: TransactionV2 as EthereumTransaction ;
24
+ use evm_domain_test_runtime:: { Runtime as EvmRuntime , RuntimeApi as EvmRuntimeApi } ;
22
25
use fp_rpc:: EthereumRuntimeRPCApi ;
23
26
use futures:: StreamExt ;
24
27
use hex_literal:: hex;
@@ -207,8 +210,13 @@ pub fn generate_evm_account_list(
207
210
}
208
211
}
209
212
210
- #[ tokio:: test( flavor = "multi_thread" ) ]
211
- async fn test_evm_domain_create_contracts_with_allow_list ( ) {
213
+ async fn setup_evm_test_nodes (
214
+ ferdie_key : Sr25519Keyring ,
215
+ ) -> (
216
+ TempDir ,
217
+ MockConsensusNode ,
218
+ DomainNode < EvmRuntime , EvmRuntimeApi > ,
219
+ ) {
212
220
let directory = TempDir :: new ( ) . expect ( "Must be able to create temporary directory" ) ;
213
221
214
222
let mut builder = sc_cli:: LoggerBuilder :: new ( "" ) ;
@@ -220,18 +228,31 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
220
228
// Start Ferdie with Alice Key since that is the sudo key
221
229
let mut ferdie = MockConsensusNode :: run (
222
230
tokio_handle. clone ( ) ,
223
- Sr25519Alice ,
231
+ ferdie_key ,
224
232
BasePath :: new ( directory. path ( ) . join ( "ferdie" ) ) ,
225
233
) ;
226
234
227
235
// Run Alice (an evm domain)
228
- let mut alice = domain_test_service:: DomainNodeBuilder :: new (
236
+ let alice = domain_test_service:: DomainNodeBuilder :: new (
229
237
tokio_handle. clone ( ) ,
230
238
BasePath :: new ( directory. path ( ) . join ( "alice" ) ) ,
231
239
)
232
240
. build_evm_node ( Role :: Authority , Alice , & mut ferdie)
233
241
. await ;
234
242
243
+ ( directory, ferdie, alice)
244
+ }
245
+
246
+ async fn setup_evm_test_accounts (
247
+ ferdie_key : Sr25519Keyring ,
248
+ ) -> (
249
+ TempDir ,
250
+ MockConsensusNode ,
251
+ DomainNode < EvmRuntime , EvmRuntimeApi > ,
252
+ Vec < AccountInfo > ,
253
+ ) {
254
+ let ( directory, mut ferdie, mut alice) = setup_evm_test_nodes ( ferdie_key) . await ;
255
+
235
256
produce_blocks ! ( ferdie, alice, 3 ) . await . unwrap ( ) ;
236
257
237
258
// Create more accounts and fund those accounts
@@ -253,8 +274,17 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
253
274
. await
254
275
. expect ( "Failed to send extrinsic" ) ;
255
276
}
277
+
256
278
produce_blocks ! ( ferdie, alice, 3 ) . await . unwrap ( ) ;
257
279
280
+ ( directory, ferdie, alice, account_infos)
281
+ }
282
+
283
+ #[ tokio:: test( flavor = "multi_thread" ) ]
284
+ async fn test_evm_domain_create_contracts_with_allow_list_default ( ) {
285
+ let ( _directory, mut ferdie, mut alice, account_infos) =
286
+ setup_evm_test_accounts ( Sr25519Alice ) . await ;
287
+
258
288
let gas_price = alice
259
289
. client
260
290
. runtime_api ( )
@@ -263,13 +293,12 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
263
293
264
294
// Any account should be able to create contracts by default
265
295
let mut eth_nonce = U256 :: zero ( ) ;
266
- let mut eth_tx = generate_eth_domain_extrinsic (
296
+ let eth_tx = generate_eth_domain_extrinsic (
267
297
account_infos[ 0 ] . clone ( ) ,
268
298
ethereum:: TransactionAction :: Create ,
269
299
eth_nonce,
270
300
gas_price,
271
301
) ;
272
- let eth_contract_address = contract_address ( account_infos[ 0 ] . address , eth_nonce. as_u64 ( ) ) ;
273
302
eth_nonce += U256 :: one ( ) ;
274
303
275
304
let result = alice. send_extrinsic ( eth_tx) . await ;
@@ -287,7 +316,6 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
287
316
evm_nonce,
288
317
gas_price,
289
318
) ;
290
- let evm_contract_address = contract_address ( account_infos[ 1 ] . address , evm_nonce. as_u64 ( ) ) ;
291
319
evm_nonce += U256 :: one ( ) ;
292
320
293
321
let result = alice. construct_and_send_extrinsic ( evm_tx) . await ;
@@ -367,11 +395,55 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
367
395
assert_eq ! ( receipt. consensus_block_hash, consensus_block_hash) ;
368
396
369
397
produce_blocks ! ( ferdie, alice, 3 ) . await . unwrap ( ) ;
398
+ }
399
+
400
+ #[ tokio:: test( flavor = "multi_thread" ) ]
401
+ async fn test_evm_domain_create_contracts_with_allow_list_reject_all ( ) {
402
+ let ( _directory, mut ferdie, mut alice, account_infos) =
403
+ setup_evm_test_accounts ( Sr25519Alice ) . await ;
404
+
405
+ let gas_price = alice
406
+ . client
407
+ . runtime_api ( )
408
+ . gas_price ( alice. client . info ( ) . best_hash )
409
+ . unwrap ( ) ;
410
+
411
+ // Create contracts used for testing contract calls
412
+ let mut eth_nonce = U256 :: zero ( ) ;
413
+ let mut eth_tx = generate_eth_domain_extrinsic (
414
+ account_infos[ 0 ] . clone ( ) ,
415
+ ethereum:: TransactionAction :: Create ,
416
+ eth_nonce,
417
+ gas_price,
418
+ ) ;
419
+ let eth_contract_address = contract_address ( account_infos[ 0 ] . address , eth_nonce. as_u64 ( ) ) ;
420
+ eth_nonce += U256 :: one ( ) ;
421
+
422
+ alice. send_extrinsic ( eth_tx) . await . unwrap ( ) ;
423
+
424
+ let mut evm_nonce = U256 :: zero ( ) ;
425
+ let mut evm_tx = generate_evm_domain_call (
426
+ account_infos[ 1 ] . clone ( ) ,
427
+ ethereum:: TransactionAction :: Create ,
428
+ 0 ,
429
+ evm_nonce,
430
+ gas_price,
431
+ ) ;
432
+ let evm_contract_address = contract_address ( account_infos[ 1 ] . address , evm_nonce. as_u64 ( ) ) ;
433
+ evm_nonce += U256 :: one ( ) ;
434
+
435
+ alice. construct_and_send_extrinsic ( evm_tx) . await . unwrap ( ) ;
436
+
437
+ // Produce a bundle that contains just the sent extrinsics
438
+ let ( slot, _bundle) = ferdie. produce_slot_and_wait_for_bundle_submission ( ) . await ;
439
+ produce_block_with ! ( ferdie. produce_block_with_slot( slot) , alice)
440
+ . await
441
+ . unwrap ( ) ;
370
442
371
443
// set EVM contract allow list on Domain using domain sudo.
372
444
// Sudo on consensus chain will send a sudo call to domain
373
445
// once the call is executed in the domain, list will be updated.
374
- let mut allow_list = generate_evm_account_list ( & account_infos, EvmAccountList :: NoOne ) ;
446
+ let allow_list = generate_evm_account_list ( & account_infos, EvmAccountList :: NoOne ) ;
375
447
let sudo_unsigned_extrinsic = alice
376
448
. construct_unsigned_extrinsic ( evm_domain_test_runtime:: RuntimeCall :: EVMNoncetracker (
377
449
pallet_evm_tracker:: Call :: set_contract_creation_allowed_by {
@@ -555,9 +627,51 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
555
627
assert_eq ! ( receipt. consensus_block_hash, consensus_block_hash) ;
556
628
557
629
produce_blocks ! ( ferdie, alice, 3 ) . await . unwrap ( ) ;
630
+ }
631
+
632
+ #[ tokio:: test( flavor = "multi_thread" ) ]
633
+ async fn test_evm_domain_create_contracts_with_allow_list_single ( ) {
634
+ let ( _directory, mut ferdie, mut alice, account_infos) =
635
+ setup_evm_test_accounts ( Sr25519Alice ) . await ;
636
+
637
+ let gas_price = alice
638
+ . client
639
+ . runtime_api ( )
640
+ . gas_price ( alice. client . info ( ) . best_hash )
641
+ . unwrap ( ) ;
642
+
643
+ // Create contracts used for testing contract calls
644
+ let mut eth_nonce = U256 :: zero ( ) ;
645
+ let mut eth_tx = generate_eth_domain_extrinsic (
646
+ account_infos[ 0 ] . clone ( ) ,
647
+ ethereum:: TransactionAction :: Create ,
648
+ eth_nonce,
649
+ gas_price,
650
+ ) ;
651
+ eth_nonce += U256 :: one ( ) ;
652
+
653
+ alice. send_extrinsic ( eth_tx) . await . unwrap ( ) ;
654
+
655
+ let mut evm_nonce = U256 :: zero ( ) ;
656
+ let mut evm_tx = generate_evm_domain_call (
657
+ account_infos[ 1 ] . clone ( ) ,
658
+ ethereum:: TransactionAction :: Create ,
659
+ 0 ,
660
+ evm_nonce,
661
+ gas_price,
662
+ ) ;
663
+ evm_nonce += U256 :: one ( ) ;
664
+
665
+ alice. construct_and_send_extrinsic ( evm_tx) . await . unwrap ( ) ;
666
+
667
+ // Produce a bundle that contains just the sent extrinsics
668
+ let ( slot, _bundle) = ferdie. produce_slot_and_wait_for_bundle_submission ( ) . await ;
669
+ produce_block_with ! ( ferdie. produce_block_with_slot( slot) , alice)
670
+ . await
671
+ . unwrap ( ) ;
558
672
559
673
// 1 account in the allow list
560
- allow_list = generate_evm_account_list ( & account_infos, EvmAccountList :: One ) ;
674
+ let allow_list = generate_evm_account_list ( & account_infos, EvmAccountList :: One ) ;
561
675
let sudo_unsigned_extrinsic = alice
562
676
. construct_unsigned_extrinsic ( evm_domain_test_runtime:: RuntimeCall :: EVMNoncetracker (
563
677
pallet_evm_tracker:: Call :: set_contract_creation_allowed_by {
@@ -637,7 +751,7 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
637
751
638
752
// Produce a bundle that contains just the sent extrinsics
639
753
let ( slot, bundle) = ferdie. produce_slot_and_wait_for_bundle_submission ( ) . await ;
640
- assert_eq ! ( bundle. extrinsics. len( ) , 1 ) ;
754
+ assert_eq ! ( bundle. extrinsics. len( ) , 2 ) ;
641
755
produce_block_with ! ( ferdie. produce_block_with_slot( slot) , alice)
642
756
. await
643
757
. unwrap ( ) ;
@@ -745,9 +859,15 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
745
859
assert_eq ! ( receipt. consensus_block_hash, consensus_block_hash) ;
746
860
747
861
produce_blocks ! ( ferdie, alice, 3 ) . await . unwrap ( ) ;
862
+ }
863
+
864
+ #[ tokio:: test( flavor = "multi_thread" ) ]
865
+ async fn test_evm_domain_create_contracts_with_allow_list_multiple ( ) {
866
+ let ( _directory, mut ferdie, mut alice, account_infos) =
867
+ setup_evm_test_accounts ( Sr25519Alice ) . await ;
748
868
749
869
// Multiple accounts in the allow list
750
- allow_list = generate_evm_account_list ( & account_infos, EvmAccountList :: Multiple ) ;
870
+ let allow_list = generate_evm_account_list ( & account_infos, EvmAccountList :: Multiple ) ;
751
871
let sudo_unsigned_extrinsic = alice
752
872
. construct_unsigned_extrinsic ( evm_domain_test_runtime:: RuntimeCall :: EVMNoncetracker (
753
873
pallet_evm_tracker:: Call :: set_contract_creation_allowed_by {
@@ -783,7 +903,8 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
783
903
. unwrap ( ) ;
784
904
785
905
// Accounts 0-2 should be able to create contracts
786
- eth_tx = generate_eth_domain_extrinsic (
906
+ let mut eth_nonce = U256 :: zero ( ) ;
907
+ let mut eth_tx = generate_eth_domain_extrinsic (
787
908
account_infos[ 1 ] . clone ( ) ,
788
909
ethereum:: TransactionAction :: Create ,
789
910
eth_nonce,
@@ -798,7 +919,8 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
798
919
"Unexpectedly failed to send self-contained extrinsic"
799
920
) ;
800
921
801
- evm_tx = generate_evm_domain_call (
922
+ let mut evm_nonce = U256 :: zero ( ) ;
923
+ let mut evm_tx = generate_evm_domain_call (
802
924
account_infos[ 2 ] . clone ( ) ,
803
925
ethereum:: TransactionAction :: Create ,
804
926
0 ,
@@ -817,7 +939,7 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
817
939
818
940
// Produce a bundle that contains just the sent extrinsics
819
941
let ( slot, bundle) = ferdie. produce_slot_and_wait_for_bundle_submission ( ) . await ;
820
- assert_eq ! ( bundle. extrinsics. len( ) , 1 ) ;
942
+ assert_eq ! ( bundle. extrinsics. len( ) , 2 ) ;
821
943
produce_block_with ! ( ferdie. produce_block_with_slot( slot) , alice)
822
944
. await
823
945
. unwrap ( ) ;
0 commit comments