Skip to content

Commit ee8c646

Browse files
committed
Split a long test
1 parent 8360d4c commit ee8c646

File tree

1 file changed

+137
-15
lines changed
  • domains/client/domain-operator/src

1 file changed

+137
-15
lines changed

domains/client/domain-operator/src/tests.rs

+137-15
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ use domain_test_service::evm_domain_test_runtime::{
1717
};
1818
use domain_test_service::EcdsaKeyring::{Alice, Bob, Charlie, Dave, Eve};
1919
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+
};
2123
use ethereum::TransactionV2 as EthereumTransaction;
24+
use evm_domain_test_runtime::{Runtime as EvmRuntime, RuntimeApi as EvmRuntimeApi};
2225
use fp_rpc::EthereumRuntimeRPCApi;
2326
use futures::StreamExt;
2427
use hex_literal::hex;
@@ -207,8 +210,13 @@ pub fn generate_evm_account_list(
207210
}
208211
}
209212

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+
) {
212220
let directory = TempDir::new().expect("Must be able to create temporary directory");
213221

214222
let mut builder = sc_cli::LoggerBuilder::new("");
@@ -220,18 +228,31 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
220228
// Start Ferdie with Alice Key since that is the sudo key
221229
let mut ferdie = MockConsensusNode::run(
222230
tokio_handle.clone(),
223-
Sr25519Alice,
231+
ferdie_key,
224232
BasePath::new(directory.path().join("ferdie")),
225233
);
226234

227235
// Run Alice (an evm domain)
228-
let mut alice = domain_test_service::DomainNodeBuilder::new(
236+
let alice = domain_test_service::DomainNodeBuilder::new(
229237
tokio_handle.clone(),
230238
BasePath::new(directory.path().join("alice")),
231239
)
232240
.build_evm_node(Role::Authority, Alice, &mut ferdie)
233241
.await;
234242

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+
235256
produce_blocks!(ferdie, alice, 3).await.unwrap();
236257

237258
// Create more accounts and fund those accounts
@@ -253,8 +274,17 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
253274
.await
254275
.expect("Failed to send extrinsic");
255276
}
277+
256278
produce_blocks!(ferdie, alice, 3).await.unwrap();
257279

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+
258288
let gas_price = alice
259289
.client
260290
.runtime_api()
@@ -263,13 +293,12 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
263293

264294
// Any account should be able to create contracts by default
265295
let mut eth_nonce = U256::zero();
266-
let mut eth_tx = generate_eth_domain_extrinsic(
296+
let eth_tx = generate_eth_domain_extrinsic(
267297
account_infos[0].clone(),
268298
ethereum::TransactionAction::Create,
269299
eth_nonce,
270300
gas_price,
271301
);
272-
let eth_contract_address = contract_address(account_infos[0].address, eth_nonce.as_u64());
273302
eth_nonce += U256::one();
274303

275304
let result = alice.send_extrinsic(eth_tx).await;
@@ -287,7 +316,6 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
287316
evm_nonce,
288317
gas_price,
289318
);
290-
let evm_contract_address = contract_address(account_infos[1].address, evm_nonce.as_u64());
291319
evm_nonce += U256::one();
292320

293321
let result = alice.construct_and_send_extrinsic(evm_tx).await;
@@ -367,11 +395,55 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
367395
assert_eq!(receipt.consensus_block_hash, consensus_block_hash);
368396

369397
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();
370442

371443
// set EVM contract allow list on Domain using domain sudo.
372444
// Sudo on consensus chain will send a sudo call to domain
373445
// 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);
375447
let sudo_unsigned_extrinsic = alice
376448
.construct_unsigned_extrinsic(evm_domain_test_runtime::RuntimeCall::EVMNoncetracker(
377449
pallet_evm_tracker::Call::set_contract_creation_allowed_by {
@@ -555,9 +627,51 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
555627
assert_eq!(receipt.consensus_block_hash, consensus_block_hash);
556628

557629
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();
558672

559673
// 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);
561675
let sudo_unsigned_extrinsic = alice
562676
.construct_unsigned_extrinsic(evm_domain_test_runtime::RuntimeCall::EVMNoncetracker(
563677
pallet_evm_tracker::Call::set_contract_creation_allowed_by {
@@ -637,7 +751,7 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
637751

638752
// Produce a bundle that contains just the sent extrinsics
639753
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);
641755
produce_block_with!(ferdie.produce_block_with_slot(slot), alice)
642756
.await
643757
.unwrap();
@@ -745,9 +859,15 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
745859
assert_eq!(receipt.consensus_block_hash, consensus_block_hash);
746860

747861
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;
748868

749869
// 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);
751871
let sudo_unsigned_extrinsic = alice
752872
.construct_unsigned_extrinsic(evm_domain_test_runtime::RuntimeCall::EVMNoncetracker(
753873
pallet_evm_tracker::Call::set_contract_creation_allowed_by {
@@ -783,7 +903,8 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
783903
.unwrap();
784904

785905
// 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(
787908
account_infos[1].clone(),
788909
ethereum::TransactionAction::Create,
789910
eth_nonce,
@@ -798,7 +919,8 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
798919
"Unexpectedly failed to send self-contained extrinsic"
799920
);
800921

801-
evm_tx = generate_evm_domain_call(
922+
let mut evm_nonce = U256::zero();
923+
let mut evm_tx = generate_evm_domain_call(
802924
account_infos[2].clone(),
803925
ethereum::TransactionAction::Create,
804926
0,
@@ -817,7 +939,7 @@ async fn test_evm_domain_create_contracts_with_allow_list() {
817939

818940
// Produce a bundle that contains just the sent extrinsics
819941
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);
821943
produce_block_with!(ferdie.produce_block_with_slot(slot), alice)
822944
.await
823945
.unwrap();

0 commit comments

Comments
 (0)