diff --git a/chain/chain/src/tests/simple_chain.rs b/chain/chain/src/tests/simple_chain.rs index a5e51a7dbaa..4b875f0a846 100644 --- a/chain/chain/src/tests/simple_chain.rs +++ b/chain/chain/src/tests/simple_chain.rs @@ -48,7 +48,7 @@ fn build_chain() { // cargo insta test --accept -p near-chain --features nightly -- tests::simple_chain::build_chain let hash = chain.head().unwrap().last_block_hash; if cfg!(feature = "nightly") { - insta::assert_display_snapshot!(hash, @"GargNTMFiuET32KH5uPLFwMSU8xXtvrk6aGqgkPbRZg8"); + insta::assert_display_snapshot!(hash, @"CwaiZ4AmfJSnMN9rytYwwYHCTzLioC5xcjHzNkDex1HH"); } else { insta::assert_display_snapshot!(hash, @"712T4sPbJhNWWN3bWweccECGYWbnUmGpqpKW2SJpb2k5"); } @@ -78,7 +78,7 @@ fn build_chain() { let hash = chain.head().unwrap().last_block_hash; if cfg!(feature = "nightly") { - insta::assert_display_snapshot!(hash, @"2aurKZqRfPkZ3woNjA7Kf79wq5MYz98AohTYWoBFiG7o"); + insta::assert_display_snapshot!(hash, @"Dn18HUFm149fojXpwV1dYCfjdPh56S1k233kp7vmnFeE"); } else { insta::assert_display_snapshot!(hash, @"GUAPgvPQQmhumyuFzPusg3BKtRkVLpCw4asTAWgdTLq6"); } diff --git a/core/primitives-core/Cargo.toml b/core/primitives-core/Cargo.toml index eca9aa693f8..9d9a34e5d80 100644 --- a/core/primitives-core/Cargo.toml +++ b/core/primitives-core/Cargo.toml @@ -36,12 +36,14 @@ protocol_feature_fix_staking_threshold = [] protocol_feature_fix_contract_loading_cost = [] protocol_feature_reject_blocks_with_outdated_protocol_version = [] protocol_feature_simple_nightshade_v2 = [] +protocol_feature_restrict_tla = [] nightly = [ "nightly_protocol", "protocol_feature_fix_contract_loading_cost", "protocol_feature_fix_staking_threshold", "protocol_feature_reject_blocks_with_outdated_protocol_version", + "protocol_feature_restrict_tla", "protocol_feature_simple_nightshade_v2", ] diff --git a/core/primitives-core/src/version.rs b/core/primitives-core/src/version.rs index 4d03a93a336..b91848beeb3 100644 --- a/core/primitives-core/src/version.rs +++ b/core/primitives-core/src/version.rs @@ -120,6 +120,8 @@ pub enum ProtocolFeature { RejectBlocksWithOutdatedProtocolVersions, #[cfg(feature = "protocol_feature_simple_nightshade_v2")] SimpleNightshadeV2, + #[cfg(feature = "protocol_feature_restrict_tla")] + RestrictTLA, } impl ProtocolFeature { @@ -173,6 +175,8 @@ impl ProtocolFeature { ProtocolFeature::RejectBlocksWithOutdatedProtocolVersions => 132, #[cfg(feature = "protocol_feature_simple_nightshade_v2")] ProtocolFeature::SimpleNightshadeV2 => 135, + #[cfg(feature = "protocol_feature_restrict_tla")] + ProtocolFeature::RestrictTLA => 139, } } } @@ -185,7 +189,7 @@ const STABLE_PROTOCOL_VERSION: ProtocolVersion = 63; /// Largest protocol version supported by the current binary. pub const PROTOCOL_VERSION: ProtocolVersion = if cfg!(feature = "nightly_protocol") { // On nightly, pick big enough version to support all features. - 138 + 139 } else { // Enable all stable features. STABLE_PROTOCOL_VERSION diff --git a/core/primitives/Cargo.toml b/core/primitives/Cargo.toml index 4334d4f3447..addb6b50e27 100644 --- a/core/primitives/Cargo.toml +++ b/core/primitives/Cargo.toml @@ -45,15 +45,27 @@ near-vm-runner.workspace = true [features] sandbox = [] dump_errors_schema = ["near-rpc-error-macro/dump_errors_schema"] -protocol_feature_fix_staking_threshold = ["near-primitives-core/protocol_feature_fix_staking_threshold"] -protocol_feature_fix_contract_loading_cost = ["near-primitives-core/protocol_feature_fix_contract_loading_cost"] -protocol_feature_reject_blocks_with_outdated_protocol_version = ["near-primitives-core/protocol_feature_reject_blocks_with_outdated_protocol_version"] -protocol_feature_simple_nightshade_v2 = ["near-primitives-core/protocol_feature_simple_nightshade_v2"] +protocol_feature_fix_staking_threshold = [ + "near-primitives-core/protocol_feature_fix_staking_threshold", +] +protocol_feature_fix_contract_loading_cost = [ + "near-primitives-core/protocol_feature_fix_contract_loading_cost", +] +protocol_feature_reject_blocks_with_outdated_protocol_version = [ + "near-primitives-core/protocol_feature_reject_blocks_with_outdated_protocol_version", +] +protocol_feature_simple_nightshade_v2 = [ + "near-primitives-core/protocol_feature_simple_nightshade_v2", +] +protocol_feature_restrict_tla = [ + "near-primitives-core/protocol_feature_restrict_tla", +] nightly = [ "nightly_protocol", "protocol_feature_fix_contract_loading_cost", "protocol_feature_fix_staking_threshold", "protocol_feature_reject_blocks_with_outdated_protocol_version", + "protocol_feature_restrict_tla", "protocol_feature_simple_nightshade_v2", "near-fmt/nightly", "near-primitives-core/nightly", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 29a9e6ef6c3..b0db8c4b57f 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -80,11 +80,13 @@ protocol_feature_reject_blocks_with_outdated_protocol_version = [ protocol_feature_simple_nightshade_v2 = [ "near-primitives/protocol_feature_simple_nightshade_v2", ] +protocol_feature_restrict_tla = ["nearcore/protocol_feature_restrict_tla"] nightly = [ "nightly_protocol", "protocol_feature_fix_contract_loading_cost", "protocol_feature_reject_blocks_with_outdated_protocol_version", + "protocol_feature_restrict_tla", "protocol_feature_simple_nightshade_v2", "near-actix-test-utils/nightly", "near-async/nightly", diff --git a/integration-tests/src/tests/client/process_blocks.rs b/integration-tests/src/tests/client/process_blocks.rs index f39b25d42c3..8c80f90f818 100644 --- a/integration-tests/src/tests/client/process_blocks.rs +++ b/integration-tests/src/tests/client/process_blocks.rs @@ -2296,10 +2296,11 @@ fn test_data_reset_before_state_sync() { let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); let genesis_hash = *genesis_block.hash(); + let new_account_id: AccountId = "test_account.test0".parse().unwrap(); let tx = SignedTransaction::create_account( 1, "test0".parse().unwrap(), - "test_account".parse().unwrap(), + new_account_id.clone(), NEAR_BASE, signer.public_key(), &signer, @@ -2322,7 +2323,7 @@ fn test_data_reset_before_state_sync() { &head.prev_block_hash, &head.last_block_hash, head_block.header().epoch_id(), - &QueryRequest::ViewAccount { account_id: "test_account".parse().unwrap() }, + &QueryRequest::ViewAccount { account_id: new_account_id.clone() }, ) .unwrap(); assert_matches!(response.kind, QueryResponseKind::ViewAccount(_)); @@ -2336,7 +2337,7 @@ fn test_data_reset_before_state_sync() { &head.prev_block_hash, &head.last_block_hash, head_block.header().epoch_id(), - &QueryRequest::ViewAccount { account_id: "test_account".parse().unwrap() }, + &QueryRequest::ViewAccount { account_id: new_account_id }, ); // TODO(#3742): ViewClient still has data in cache by current design. assert!(response.is_ok()); diff --git a/integration-tests/src/tests/client/state_dump.rs b/integration-tests/src/tests/client/state_dump.rs index 6dae1ce2db5..213577f672b 100644 --- a/integration-tests/src/tests/client/state_dump.rs +++ b/integration-tests/src/tests/client/state_dump.rs @@ -229,7 +229,7 @@ fn run_state_sync_with_dumped_parts( let tx = SignedTransaction::create_account( 1, "test0".parse().unwrap(), - "test_account".parse().unwrap(), + "test_account.test0".parse().unwrap(), NEAR_BASE, signer.public_key(), &signer, @@ -256,7 +256,7 @@ fn run_state_sync_with_dumped_parts( &head.prev_block_hash, &head.last_block_hash, head_block.header().epoch_id(), - &QueryRequest::ViewAccount { account_id: "test_account".parse().unwrap() }, + &QueryRequest::ViewAccount { account_id: "test_account.test0".parse().unwrap() }, ) .unwrap(); assert_matches!(response.kind, QueryResponseKind::ViewAccount(_)); @@ -360,7 +360,7 @@ fn run_state_sync_with_dumped_parts( &synced_block_tip.prev_block_hash, &synced_block_tip.last_block_hash, synced_block_header.epoch_id(), - &QueryRequest::ViewAccount { account_id: "test_account".parse().unwrap() }, + &QueryRequest::ViewAccount { account_id: "test_account.test0".parse().unwrap() }, ); if is_final_block_in_new_epoch { diff --git a/integration-tests/src/tests/runtime/test_evil_contracts.rs b/integration-tests/src/tests/runtime/test_evil_contracts.rs index e6c11c6783f..dc683a69efc 100644 --- a/integration-tests/src/tests/runtime/test_evil_contracts.rs +++ b/integration-tests/src/tests/runtime/test_evil_contracts.rs @@ -21,7 +21,7 @@ fn setup_test_contract(wasm_binary: &[u8]) -> RuntimeNode { let transaction_result = node_user .create_account( account_id, - "test_contract".parse().unwrap(), + "test_contract.alice.near".parse().unwrap(), node.signer().public_key(), TESTING_INIT_BALANCE / 2, ) @@ -29,8 +29,9 @@ fn setup_test_contract(wasm_binary: &[u8]) -> RuntimeNode { assert_eq!(transaction_result.status, FinalExecutionStatus::SuccessValue(Vec::new())); assert_eq!(transaction_result.receipts_outcome.len(), 2); - let transaction_result = - node_user.deploy_contract("test_contract".parse().unwrap(), wasm_binary.to_vec()).unwrap(); + let transaction_result = node_user + .deploy_contract("test_contract.alice.near".parse().unwrap(), wasm_binary.to_vec()) + .unwrap(); assert_eq!(transaction_result.status, FinalExecutionStatus::SuccessValue(Vec::new())); assert_eq!(transaction_result.receipts_outcome.len(), 1); @@ -51,7 +52,7 @@ fn test_evil_deep_trie() { .user() .function_call( "alice.near".parse().unwrap(), - "test_contract".parse().unwrap(), + "test_contract.alice.near".parse().unwrap(), "insert_strings", input_data.to_vec(), MAX_GAS, @@ -72,7 +73,7 @@ fn test_evil_deep_trie() { .user() .function_call( "alice.near".parse().unwrap(), - "test_contract".parse().unwrap(), + "test_contract.alice.near".parse().unwrap(), "delete_strings", input_data.to_vec(), MAX_GAS, @@ -94,7 +95,7 @@ fn test_evil_deep_recursion() { .user() .function_call( "alice.near".parse().unwrap(), - "test_contract".parse().unwrap(), + "test_contract.alice.near".parse().unwrap(), "recurse", n_bytes.clone(), MAX_GAS, @@ -116,7 +117,7 @@ fn test_evil_abort() { .user() .function_call( "alice.near".parse().unwrap(), - "test_contract".parse().unwrap(), + "test_contract.alice.near".parse().unwrap(), "abort_with_zero", vec![], MAX_GAS, diff --git a/integration-tests/src/tests/standard_cases/mod.rs b/integration-tests/src/tests/standard_cases/mod.rs index 2fe939a0bcb..adc2155847b 100644 --- a/integration-tests/src/tests/standard_cases/mod.rs +++ b/integration-tests/src/tests/standard_cases/mod.rs @@ -665,6 +665,44 @@ pub fn test_create_account_failure_already_exists(node: impl Node) { ); } +#[cfg(feature = "protocol_feature_restrict_tla")] +pub fn test_create_top_level_account(node: impl Node) { + let account_id = &node.account_id().unwrap(); + let node_user = node.user(); + let top_level_accounts = [ + "0x06012c8cf97bead5deae237070f9587f8e7a266d", + "0x5e97870f263700f46aa00d967821199b9bc5a120", + "0x0000000000000000000000000000000000000000", + "alice", + "thisisaveryverylongtoplevelaccount", + ]; + for (_, id) in top_level_accounts.iter().enumerate() { + let new_account_id = id.parse::().unwrap(); + let transaction_result = node_user + .create_account( + account_id.clone(), + new_account_id.clone(), + node.signer().public_key(), + 0, + ) + .unwrap(); + assert_eq!( + transaction_result.status, + FinalExecutionStatus::Failure( + ActionError { + index: Some(0), + kind: ActionErrorKind::CreateAccountOnlyByRegistrar { + account_id: new_account_id, + registrar_account_id: "registrar".parse().unwrap(), + predecessor_id: account_id.clone() + } + } + .into() + ) + ); + } +} + pub fn test_swap_key(node: impl Node) { let account_id = &node.account_id().unwrap(); let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519); diff --git a/integration-tests/src/tests/standard_cases/runtime.rs b/integration-tests/src/tests/standard_cases/runtime.rs index 68060498834..dc7c7750b31 100644 --- a/integration-tests/src/tests/standard_cases/runtime.rs +++ b/integration-tests/src/tests/standard_cases/runtime.rs @@ -344,3 +344,10 @@ fn test_storage_read_write_costs_runtime() { let runtime_config = node.client.as_ref().read().unwrap().runtime_config.clone(); test_storage_read_write_costs(node, runtime_config); } + +#[test] +#[cfg(feature = "protocol_feature_restrict_tla")] +fn test_create_top_level_account_runtime() { + let node = create_runtime_node(); + test_create_top_level_account(node); +} diff --git a/nearcore/Cargo.toml b/nearcore/Cargo.toml index 93d447e0e64..9a2330304c2 100644 --- a/nearcore/Cargo.toml +++ b/nearcore/Cargo.toml @@ -84,15 +84,13 @@ harness = false [features] default = ["json_rpc", "rosetta_rpc"] -performance_stats = [ - "near-performance-metrics/performance_stats", -] +performance_stats = ["near-performance-metrics/performance_stats"] c_memory_stats = ["near-performance-metrics/c_memory_stats"] test_features = [ "near-client/test_features", "near-network/test_features", "near-store/test_features", - "near-jsonrpc/test_features" + "near-jsonrpc/test_features", ] expensive_tests = [ "near-client/expensive_tests", @@ -116,7 +114,11 @@ protocol_feature_fix_contract_loading_cost = [ "near-vm-runner/protocol_feature_fix_contract_loading_cost", ] protocol_feature_simple_nightshade_v2 = [ - "near-primitives/protocol_feature_simple_nightshade_v2", + "near-primitives/protocol_feature_simple_nightshade_v2", +] +protocol_feature_restrict_tla = [ + "near-primitives/protocol_feature_restrict_tla", + "node-runtime/protocol_feature_restrict_tla", ] new_epoch_sync = [ "near-client/new_epoch_sync" @@ -127,6 +129,7 @@ nightly = [ "nightly_protocol", "protocol_feature_fix_contract_loading_cost", "protocol_feature_fix_staking_threshold", + "protocol_feature_restrict_tla", "protocol_feature_simple_nightshade_v2", "serialize_all_state_changes", "near-async/nightly", diff --git a/nearcore/src/runtime/mod.rs b/nearcore/src/runtime/mod.rs index 5df4c279af3..3f6cf02b7a7 100644 --- a/nearcore/src/runtime/mod.rs +++ b/nearcore/src/runtime/mod.rs @@ -1688,14 +1688,14 @@ mod test { ); // test1 doubles stake and the new account stakes the same, so test2 will be kicked out.` let staking_transaction = stake(1, &signer, &block_producers[0], TESTING_INIT_STAKE * 2); - let new_account = AccountId::try_from(format!("test{}", num_nodes + 1)).unwrap(); + let new_account: AccountId = "test.test1".parse().unwrap(); let new_validator = create_test_signer(new_account.as_str()); let new_signer = InMemorySigner::from_seed(new_account.clone(), KeyType::ED25519, new_account.as_ref()); let create_account_transaction = SignedTransaction::create_account( 2, block_producers[0].validator_id().clone(), - new_account, + new_account.clone(), TESTING_INIT_STAKE * 3, new_signer.public_key(), &signer, @@ -1741,7 +1741,7 @@ mod test { .iter() .map(|x| (x.0.account_id().clone(), x.1)) .collect::>(), - vec![("test3".parse().unwrap(), false), ("test1".parse().unwrap(), false)] + vec![(new_account.clone(), false), ("test1".parse().unwrap(), false)] .into_iter() .collect::>() ); @@ -1758,7 +1758,7 @@ mod test { (test2_acc.amount, test2_acc.locked), (TESTING_INIT_BALANCE - test2_stake_amount, test2_stake_amount) ); - let test3_acc = env.view_account(&"test3".parse().unwrap()); + let test3_acc = env.view_account(&new_account); // Got 3 * X, staking 2 * X of them. assert_eq!( (test3_acc.amount, test3_acc.locked), diff --git a/runtime/runtime/Cargo.toml b/runtime/runtime/Cargo.toml index 58e79b8abc3..c37b83ca308 100644 --- a/runtime/runtime/Cargo.toml +++ b/runtime/runtime/Cargo.toml @@ -32,8 +32,13 @@ near-store.workspace = true near-vm-runner.workspace = true [features] +protocol_feature_restrict_tla = [ + "near-primitives/protocol_feature_restrict_tla", +] nightly = [ "nightly_protocol", + "protocol_feature_restrict_tla", + "protocol_feature_restrict_tla", "near-chain-configs/nightly", "near-o11y/nightly", "near-primitives-core/nightly", @@ -52,10 +57,7 @@ nightly_protocol = [ ] no_cpu_compatibility_checks = ["near-vm-runner/no_cpu_compatibility_checks"] -no_cache = [ - "near-vm-runner/no_cache", - "near-store/no_cache", -] +no_cache = ["near-vm-runner/no_cache", "near-store/no_cache"] sandbox = ["near-vm-runner/sandbox"] diff --git a/runtime/runtime/src/actions.rs b/runtime/runtime/src/actions.rs index 4425be4f75d..3a42fbfff9a 100644 --- a/runtime/runtime/src/actions.rs +++ b/runtime/runtime/src/actions.rs @@ -394,11 +394,24 @@ pub(crate) fn action_create_account( account_id: &AccountId, predecessor_id: &AccountId, result: &mut ActionResult, + current_protocol_version: ProtocolVersion, ) { if account_id.is_top_level() { - if account_id.len() < account_creation_config.min_allowed_top_level_account_length as usize - && predecessor_id != &account_creation_config.registrar_account_id - { + let old_condition_for_error = account_id.len() + < account_creation_config.min_allowed_top_level_account_length as usize + && predecessor_id != &account_creation_config.registrar_account_id; + let new_condition_for_error = !account_id.is_implicit() + && predecessor_id != &account_creation_config.registrar_account_id; + let is_error = if checked_feature!( + "protocol_feature_restrict_tla", + RestrictTLA, + current_protocol_version + ) { + new_condition_for_error + } else { + old_condition_for_error + }; + if is_error { // A short top-level account ID can only be created registrar account. result.result = Err(ActionErrorKind::CreateAccountOnlyByRegistrar { account_id: account_id.clone(), @@ -407,8 +420,6 @@ pub(crate) fn action_create_account( } .into()); return; - } else { - // OK: Valid top-level Account ID } } else if !account_id.is_sub_account_of(predecessor_id) { // The sub-account can only be created by its root account. E.g. `alice.near` only by `near` @@ -970,6 +981,7 @@ mod tests { use near_primitives::transaction::CreateAccountAction; use near_primitives::trie_key::TrieKey; use near_primitives::types::{EpochId, StateChangeCause}; + use near_primitives::version::PROTOCOL_VERSION; use near_store::set_account; use near_store::test_utils::create_tries; use std::sync::Arc; @@ -993,6 +1005,7 @@ mod tests { &account_id, &predecessor_id, &mut action_result, + PROTOCOL_VERSION, ); if action_result.result.is_ok() { assert!(account.is_some()); @@ -1004,6 +1017,7 @@ mod tests { } #[test] + #[cfg(not(feature = "protocol_feature_restrict_tla"))] fn test_create_account_valid_top_level_long() { let account_id = "bob_near_long_name".parse().unwrap(); let predecessor_id = "alice.near".parse().unwrap(); @@ -1046,6 +1060,7 @@ mod tests { } #[test] + #[cfg(not(feature = "protocol_feature_restrict_tla"))] fn test_create_account_invalid_short_top_level() { let account_id = "bob".parse::().unwrap(); let predecessor_id = "near".parse::().unwrap(); @@ -1065,6 +1080,7 @@ mod tests { } #[test] + #[cfg(not(feature = "protocol_feature_restrict_tla"))] fn test_create_account_valid_short_top_level_len_allowed() { let account_id = "bob".parse().unwrap(); let predecessor_id = "near".parse().unwrap(); @@ -1072,6 +1088,37 @@ mod tests { assert!(action_result.result.is_ok()); } + #[test] + #[cfg(feature = "protocol_feature_restrict_tla")] + fn test_create_top_level_account_restriction() { + let account_ids = [ + "0x32400084c286cf3e17e7b677ea9583e60a000324", + "thisisaveryverylongtoplevelaccount", + "32400084c286cf3e17e7b677ea9583e60a000324", + "000000000000000000000000000000000000000000000000000000000000000", + ]; + for id in &account_ids { + let account_id: AccountId = id.parse().unwrap(); + let predecessor_id: AccountId = "near".parse().unwrap(); + let action_result = + test_action_create_account(account_id.clone(), predecessor_id.clone(), 32); + assert_eq!( + action_result.result, + Err(ActionError { + index: None, + kind: ActionErrorKind::CreateAccountOnlyByRegistrar { + account_id: account_id.clone(), + registrar_account_id: "registrar".parse().unwrap(), + predecessor_id: predecessor_id, + }, + }) + ); + let registrar_account_id: AccountId = "registrar".parse().unwrap(); + let action_result = test_action_create_account(account_id, registrar_account_id, 32); + assert!(action_result.result.is_ok()); + } + } + fn test_delete_large_account( account_id: &AccountId, code_hash: &CryptoHash, diff --git a/runtime/runtime/src/lib.rs b/runtime/runtime/src/lib.rs index a121b84a4bf..5aa1d73e447 100644 --- a/runtime/runtime/src/lib.rs +++ b/runtime/runtime/src/lib.rs @@ -336,6 +336,7 @@ impl Runtime { &receipt.receiver_id, &receipt.predecessor_id, &mut result, + apply_state.current_protocol_version, ); } Action::DeployContract(deploy_contract) => { diff --git a/runtime/runtime/tests/test_async_calls.rs b/runtime/runtime/tests/test_async_calls.rs index 7890e2fb96b..372889e54d1 100644 --- a/runtime/runtime/tests/test_async_calls.rs +++ b/runtime/runtime/tests/test_async_calls.rs @@ -596,14 +596,18 @@ fn test_simple_transfer() { #[test] fn test_create_account_with_transfer_and_full_key() { - let group = RuntimeGroup::new(3, 2, near_test_contracts::rs_contract()); + let group = RuntimeGroup::new_with_account_ids( + vec!["near_0".parse().unwrap(), "near_1".parse().unwrap(), "test.near_1".parse().unwrap()], + 2, + near_test_contracts::rs_contract(), + ); let signer_sender = group.signers[0].clone(); let signer_receiver = group.signers[1].clone(); let signer_new_account = group.signers[2].clone(); let data = serde_json::json!([ {"batch_create": { - "account_id": "near_2", + "account_id": "test.near_1", }, "id": 0 }, {"action_create_account": { "promise_index": 0, @@ -648,7 +652,7 @@ fn test_create_account_with_transfer_and_full_key() { assert_eq!(function_call_action.deposit, 0); } => [r1, ref0] ); - assert_receipts!(group, "near_1" => r1 @ "near_2", + assert_receipts!(group, "near_1" => r1 @ "test.near_1", ReceiptEnum::Action(ActionReceipt{actions, ..}), {}, actions, a0, Action::CreateAccount(CreateAccountAction{}), {}, @@ -669,14 +673,18 @@ fn test_create_account_with_transfer_and_full_key() { #[test] fn test_account_factory() { - let group = RuntimeGroup::new(3, 2, near_test_contracts::rs_contract()); + let group = RuntimeGroup::new_with_account_ids( + vec!["near_0".parse().unwrap(), "near_1".parse().unwrap(), "test.near_1".parse().unwrap()], + 2, + near_test_contracts::rs_contract(), + ); let signer_sender = group.signers[0].clone(); let signer_receiver = group.signers[1].clone(); let signer_new_account = group.signers[2].clone(); let data = serde_json::json!([ {"batch_create": { - "account_id": "near_2", + "account_id": "test.near_1", }, "id": 0 }, {"action_create_account": { "promise_index": 0, @@ -715,7 +723,7 @@ fn test_account_factory() { {"then": { "promise_index": 0, - "account_id": "near_2", + "account_id": "test.near_1", "method_name": "call_promise", "arguments": [ {"create": { @@ -762,11 +770,11 @@ fn test_account_factory() { => [r1, r2, ref0] ); let data_id; - assert_receipts!(group, "near_1" => r1 @ "near_2", + assert_receipts!(group, "near_1" => r1 @ "test.near_1", ReceiptEnum::Action(ActionReceipt{actions, output_data_receivers, ..}), { assert_eq!(output_data_receivers.len(), 1); data_id = output_data_receivers[0].data_id; - assert_eq!(output_data_receivers[0].receiver_id.as_ref(), "near_2"); + assert_eq!(output_data_receivers[0].receiver_id.as_ref(), "test.near_1"); }, actions, a0, Action::CreateAccount(CreateAccountAction{}), {}, @@ -790,7 +798,7 @@ fn test_account_factory() { assert_eq!(function_call_action.deposit, 0); } => [r3, ref1] ); - assert_receipts!(group, "near_1" => r2 @ "near_2", + assert_receipts!(group, "near_1" => r2 @ "test.near_1", ReceiptEnum::Action(ActionReceipt{actions, input_data_ids, ..}), { assert_eq!(input_data_ids, &[data_id]); }, @@ -800,7 +808,7 @@ fn test_account_factory() { assert_eq!(function_call_action.deposit, 0); } => [r4, ref2] ); - assert_receipts!(group, "near_2" => r3 @ "near_0", + assert_receipts!(group, "test.near_1" => r3 @ "near_0", ReceiptEnum::Action(ActionReceipt{actions, ..}), {}, actions, a0, Action::FunctionCall(function_call_action), { @@ -808,7 +816,7 @@ fn test_account_factory() { assert_eq!(function_call_action.deposit, 0); } => [ref3] ); - assert_receipts!(group, "near_2" => r4 @ "near_1", + assert_receipts!(group, "test.near_1" => r4 @ "near_1", ReceiptEnum::Action(ActionReceipt{actions, ..}), {}, actions, a0, Action::FunctionCall(function_call_action), { @@ -826,14 +834,23 @@ fn test_account_factory() { #[test] fn test_create_account_add_key_call_delete_key_delete_account() { - let group = RuntimeGroup::new(4, 3, near_test_contracts::rs_contract()); + let group = RuntimeGroup::new_with_account_ids( + vec![ + "near_0".parse().unwrap(), + "near_1".parse().unwrap(), + "near_2".parse().unwrap(), + "test.near_1".parse().unwrap(), + ], + 3, + near_test_contracts::rs_contract(), + ); let signer_sender = group.signers[0].clone(); let signer_receiver = group.signers[1].clone(); let signer_new_account = group.signers[2].clone(); let data = serde_json::json!([ {"batch_create": { - "account_id": "near_3", + "account_id": "test.near_1", }, "id": 0 }, {"action_create_account": { "promise_index": 0, @@ -906,7 +923,7 @@ fn test_create_account_add_key_call_delete_key_delete_account() { assert_eq!(function_call_action.deposit, 0); } => [r1, ref0] ); - assert_receipts!(group, "near_1" => r1 @ "near_3", + assert_receipts!(group, "near_1" => r1 @ "test.near_1", ReceiptEnum::Action(ActionReceipt{actions, ..}), {}, actions, a0, Action::CreateAccount(CreateAccountAction{}), {}, @@ -933,7 +950,7 @@ fn test_create_account_add_key_call_delete_key_delete_account() { } => [r2, r3, ref1] ); - assert_receipts!(group, "near_3" => r2 @ "near_0", + assert_receipts!(group, "test.near_1" => r2 @ "near_0", ReceiptEnum::Action(ActionReceipt{actions, ..}), {}, actions, a0, Action::FunctionCall(function_call_action), {