From c680ce8528d6239f7d5669115b03ff9b24c62898 Mon Sep 17 00:00:00 2001 From: Maximilian Summe Date: Tue, 4 Jun 2024 01:08:08 +0000 Subject: [PATCH] chore(nns/sns): remove unnecessary mut from test functions --- .../integration_tests/src/canister_upgrade.rs | 4 +- .../copy_inactive_neurons_to_stable_memory.rs | 10 +- .../src/create_service_nervous_system.rs | 20 +-- .../src/cycles_minting_canister.rs | 8 +- ...ng_canister_with_exchange_rate_canister.rs | 16 +-- .../src/governance_migrations.rs | 6 +- .../src/governance_neurons.rs | 44 +++--- rs/nns/integration_tests/src/gtc.rs | 45 +++--- rs/nns/integration_tests/src/lifeline.rs | 32 ++--- .../integration_tests/src/neuron_following.rs | 130 ++++++++---------- rs/nns/integration_tests/src/neuron_voting.rs | 76 +++++----- .../src/node_provider_remuneration.rs | 88 ++++++------ rs/nns/integration_tests/src/reset_root.rs | 6 +- .../src/subnet_rental_canister.rs | 27 ++-- .../src/uninstall_canister_by_proposal.rs | 4 +- ...upgrade_canisters_with_golden_nns_state.rs | 8 +- rs/nns/test_utils/src/neuron_helpers.rs | 18 +-- rs/nns/test_utils/src/state_test_helpers.rs | 74 +++++----- .../src/initialization_flow.rs | 99 ++++++------- rs/sns/integration_tests/src/sns_treasury.rs | 22 +-- rs/sns/test_utils/src/state_test_helpers.rs | 14 +- 21 files changed, 358 insertions(+), 393 deletions(-) diff --git a/rs/nns/integration_tests/src/canister_upgrade.rs b/rs/nns/integration_tests/src/canister_upgrade.rs index 900ae365066..526137fb7a6 100644 --- a/rs/nns/integration_tests/src/canister_upgrade.rs +++ b/rs/nns/integration_tests/src/canister_upgrade.rs @@ -28,7 +28,7 @@ fn setup_state_machine_with_nns_canisters() -> StateMachine { #[test] fn upgrade_canister() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let lifeline_canister_id = CanisterId::from_u64(LIFELINE_CANISTER_INDEX_IN_NNS_SUBNET); let root_status_before = get_root_canister_status(&state_machine).unwrap(); @@ -53,7 +53,7 @@ fn upgrade_canister() { }; // make proposal with neuron 1, it has enough voting power such that the proposal will be accepted let response = - nns_governance_make_proposal(&mut state_machine, n1.principal_id, n1.neuron_id, &proposal) + nns_governance_make_proposal(&state_machine, n1.principal_id, n1.neuron_id, &proposal) .command .expect("Making NNS proposal failed"); diff --git a/rs/nns/integration_tests/src/copy_inactive_neurons_to_stable_memory.rs b/rs/nns/integration_tests/src/copy_inactive_neurons_to_stable_memory.rs index c9bc147526f..4b5f27c79a9 100644 --- a/rs/nns/integration_tests/src/copy_inactive_neurons_to_stable_memory.rs +++ b/rs/nns/integration_tests/src/copy_inactive_neurons_to_stable_memory.rs @@ -15,12 +15,12 @@ fn test_copy_inactive_neurons_to_stable_memory() { // Step 1: Prepare the world // Step 1.1: Populate StateMachine from a state_dir. - let mut state_machine = new_state_machine_with_golden_nns_state_or_panic(); + let state_machine = new_state_machine_with_golden_nns_state_or_panic(); // Step 1.2: Create a super powerful Neuron. println!("Creating super powerful Neuron."); let controller = PrincipalId::new_self_authenticating(&[1, 2, 3, 4]); - let neuron_id = nns_create_super_powerful_neuron(&mut state_machine, controller); + let neuron_id = nns_create_super_powerful_neuron(&state_machine, controller); println!("Done creating super powerful Neuron."); // Step 1.3: Install NNS governance WASM built with `feature = "test"`. In the future, `feature @@ -31,7 +31,7 @@ fn test_copy_inactive_neurons_to_stable_memory() { let new_wasm_hash = Sha256::hash(&new_wasm_content); println!("Proposing governance upgrade... "); let proposal_id = nns_propose_upgrade_nns_canister( - &mut state_machine, + &state_machine, controller, neuron_id, GOVERNANCE_CANISTER_ID, // Target, i.e. the canister that we want to upgrade. @@ -106,7 +106,7 @@ fn test_copy_inactive_neurons_to_stable_memory() { for i in 0..600 { state_machine.tick(); - last_migration = nns_get_migrations(&mut state_machine) + last_migration = nns_get_migrations(&state_machine) .copy_inactive_neurons_to_stable_memory_migration .unwrap_or_default(); @@ -141,7 +141,7 @@ fn test_copy_inactive_neurons_to_stable_memory() { assert_eq!(status, MigrationStatus::Succeeded); // Step 3.2: Assert that there is now a large number of neurons in stable memory. - let scrape = scrape_metrics(&mut state_machine, GOVERNANCE_CANISTER_ID); + let scrape = scrape_metrics(&state_machine, GOVERNANCE_CANISTER_ID); let len = get_gauge(&scrape, "governance_stable_memory_neuron_count") as u64; assert!(len > 100_000, "{}", len); diff --git a/rs/nns/integration_tests/src/create_service_nervous_system.rs b/rs/nns/integration_tests/src/create_service_nervous_system.rs index 75281c1f210..0f02a2d6281 100644 --- a/rs/nns/integration_tests/src/create_service_nervous_system.rs +++ b/rs/nns/integration_tests/src/create_service_nervous_system.rs @@ -50,7 +50,7 @@ const ONE_TRILLION: u128 = 1_000_000_000_000; fn test_several_proposals() { // Step 1: Prepare the world. - let mut state_machine = state_machine_builder_for_nns_tests().build(); + let state_machine = state_machine_builder_for_nns_tests().build(); // Step 1.1: Boot up NNS. let nns_init_payload = NnsInitPayloadsBuilder::new() @@ -81,7 +81,7 @@ fn test_several_proposals() { // Step 2.1: Make a proposal. Leave it open so that the next proposal is // foiled. - let response_1 = make_proposal(&mut state_machine, /* sns_number = */ 1); + let response_1 = make_proposal(&state_machine, /* sns_number = */ 1); let response_1 = match response_1.command { Some(manage_neuron_response::Command::MakeProposal(response_3)) => response_3, _ => panic!("First proposal failed to be submitted: {:#?}", response_1), @@ -98,7 +98,7 @@ fn test_several_proposals() { // Step 2.2: Make another proposal. This one should be foiled, because the // first proposal is still open. - let response_2 = make_proposal(&mut state_machine, 666); + let response_2 = make_proposal(&state_machine, 666); match response_2.command { Some(manage_neuron_response::Command::Error(err)) => { assert_eq!( @@ -113,13 +113,13 @@ fn test_several_proposals() { } // Step 2.3: This unblocks more proposals from being made. - execute_proposal(&mut state_machine, ProposalId { id: proposal_id_1 }); + execute_proposal(&state_machine, ProposalId { id: proposal_id_1 }); // Step 2.4: Wait for proposal_1 to finish executing. - nns_wait_for_proposal_execution(&mut state_machine, proposal_id_1); + nns_wait_for_proposal_execution(&state_machine, proposal_id_1); // Step 2.5: Finally, make a third proposal. This should now be allowed. - let response_3 = make_proposal(&mut state_machine, 3); + let response_3 = make_proposal(&state_machine, 3); let response_3 = match response_3.command { Some(manage_neuron_response::Command::MakeProposal(response_3)) => response_3, _ => panic!("First proposal failed to be submitted: {:#?}", response_3), @@ -139,7 +139,7 @@ fn test_several_proposals() { // Step 3.1: Inspect proposals. // There should only be two proposals of type CreateServiceNervousSystem. - let final_proposals = nns_list_proposals(&mut state_machine) + let final_proposals = nns_list_proposals(&state_machine) .proposal_info .into_iter() .filter_map( @@ -177,12 +177,12 @@ fn test_several_proposals() { // Step 3.2: Inspect SNS(s). - let snses = list_deployed_snses(&mut state_machine).instances; + let snses = list_deployed_snses(&state_machine).instances; assert_eq!(snses.len(), 1, "{:#?}", snses); } /// Makes a CreateServiceNervousSystem proposal using test neuron 2. -fn make_proposal(state_machine: &mut StateMachine, sns_number: u64) -> ManageNeuronResponse { +fn make_proposal(state_machine: &StateMachine, sns_number: u64) -> ManageNeuronResponse { let neuron_id = nns_common_pb::NeuronId { id: TEST_NEURON_2_ID, }; @@ -204,7 +204,7 @@ fn make_proposal(state_machine: &mut StateMachine, sns_number: u64) -> ManageNeu /// Makes test neuron 1 vote for the proposal. This should cause it to be /// adopted and executed. -fn execute_proposal(state_machine: &mut StateMachine, proposal_id: ProposalId) { +fn execute_proposal(state_machine: &StateMachine, proposal_id: ProposalId) { state_machine .execute_ingress_as( *TEST_NEURON_1_OWNER_PRINCIPAL, diff --git a/rs/nns/integration_tests/src/cycles_minting_canister.rs b/rs/nns/integration_tests/src/cycles_minting_canister.rs index 5ae4d1d6b15..a6373a6d45c 100644 --- a/rs/nns/integration_tests/src/cycles_minting_canister.rs +++ b/rs/nns/integration_tests/src/cycles_minting_canister.rs @@ -303,7 +303,7 @@ fn test_cmc_notify_create_with_settings() { let icpts = Tokens::new(100, 0).unwrap(); let neuron = get_neuron_1(); - let mut state_machine = state_machine_builder_for_nns_tests().build(); + let state_machine = state_machine_builder_for_nns_tests().build(); let nns_init_payloads = NnsInitPayloadsBuilder::new() .with_test_neurons() .with_ledger_account(account, icpts) @@ -312,7 +312,7 @@ fn test_cmc_notify_create_with_settings() { let subnet_id = state_machine.get_subnet_id(); cmc_set_default_authorized_subnetworks( - &mut state_machine, + &state_machine, vec![subnet_id], neuron.principal_id, neuron.neuron_id, @@ -428,7 +428,7 @@ fn test_cmc_cycles_create_with_settings() { let icpts = Tokens::new(100, 0).unwrap(); let neuron = get_neuron_1(); - let mut state_machine = state_machine_builder_for_nns_tests().build(); + let state_machine = state_machine_builder_for_nns_tests().build(); let nns_init_payloads = NnsInitPayloadsBuilder::new() .with_test_neurons() .with_ledger_account(account, icpts) @@ -437,7 +437,7 @@ fn test_cmc_cycles_create_with_settings() { let subnet_id = state_machine.get_subnet_id(); cmc_set_default_authorized_subnetworks( - &mut state_machine, + &state_machine, vec![subnet_id], neuron.principal_id, neuron.neuron_id, diff --git a/rs/nns/integration_tests/src/cycles_minting_canister_with_exchange_rate_canister.rs b/rs/nns/integration_tests/src/cycles_minting_canister_with_exchange_rate_canister.rs index 87bd064578f..d185b050b43 100644 --- a/rs/nns/integration_tests/src/cycles_minting_canister_with_exchange_rate_canister.rs +++ b/rs/nns/integration_tests/src/cycles_minting_canister_with_exchange_rate_canister.rs @@ -52,7 +52,7 @@ fn reinstall_mock_exchange_rate_canister( // Creates an ICP/XDR conversion rate proposal. fn propose_icp_xdr_rate( - machine: &mut StateMachine, + machine: &StateMachine, xdr_permyriad_per_icp: u64, timestamp_seconds: u64, reason: Option, @@ -330,7 +330,7 @@ fn test_enable_retrieving_rate_from_exchange_rate_canister() { #[test] fn test_disabling_and_reenabling_exchange_rate_canister_calling_via_exchange_rate_proposal() { // Step 1: Prepare the world. - let mut state_machine = state_machine_builder_for_nns_tests() + let state_machine = state_machine_builder_for_nns_tests() .with_time(GENESIS) .build(); @@ -391,12 +391,12 @@ fn test_disabling_and_reenabling_exchange_rate_canister_calling_via_exchange_rat // Step 3: Send in a proposal with a diverged rate reason. Ensure that the CMC // stops calling the mock exchange rate canister. let proposal_id = propose_icp_xdr_rate( - &mut state_machine, + &state_machine, 210_000, cmc_first_rate_timestamp_seconds + FIVE_MINUTES_SECONDS + ONE_MINUTE_SECONDS, Some(UpdateIcpXdrConversionRatePayloadReason::DivergedRate), ); - nns_wait_for_proposal_execution(&mut state_machine, proposal_id); + nns_wait_for_proposal_execution(&state_machine, proposal_id); // Check if proposal has set the rate. let response = get_icp_xdr_conversion_rate(&state_machine); @@ -423,12 +423,12 @@ fn test_disabling_and_reenabling_exchange_rate_canister_calling_via_exchange_rat // Ensure that a proposal with a OldRate reason does not reactivate the // update cycle. let proposal_id = propose_icp_xdr_rate( - &mut state_machine, + &state_machine, 200_000, cmc_first_rate_timestamp_seconds + FIVE_MINUTES_SECONDS * 2, Some(UpdateIcpXdrConversionRatePayloadReason::OldRate), ); - nns_wait_for_proposal_execution(&mut state_machine, proposal_id); + nns_wait_for_proposal_execution(&state_machine, proposal_id); let response = get_icp_xdr_conversion_rate(&state_machine); assert_eq!( @@ -450,12 +450,12 @@ fn test_disabling_and_reenabling_exchange_rate_canister_calling_via_exchange_rat // Re-enable calls to the exchange rate canister. let proposal_id = propose_icp_xdr_rate( - &mut state_machine, + &state_machine, 220_000, cmc_first_rate_timestamp_seconds + FIVE_MINUTES_SECONDS * 3, Some(UpdateIcpXdrConversionRatePayloadReason::EnableAutomaticExchangeRateUpdates), ); - nns_wait_for_proposal_execution(&mut state_machine, proposal_id); + nns_wait_for_proposal_execution(&state_machine, proposal_id); let response = get_icp_xdr_conversion_rate(&state_machine); assert_eq!( diff --git a/rs/nns/integration_tests/src/governance_migrations.rs b/rs/nns/integration_tests/src/governance_migrations.rs index 1841777e2e5..d9e70706e58 100644 --- a/rs/nns/integration_tests/src/governance_migrations.rs +++ b/rs/nns/integration_tests/src/governance_migrations.rs @@ -87,7 +87,7 @@ fn assert_neuron_indexes_lens( #[test] fn test_neuron_indexes_migrations() { - let mut state_machine = state_machine_builder_for_nns_tests().build(); + let state_machine = state_machine_builder_for_nns_tests().build(); let nns_init_payloads = NnsInitPayloadsBuilder::new().with_test_neurons().build(); setup_nns_canisters(&state_machine, nns_init_payloads); @@ -114,7 +114,7 @@ fn test_neuron_indexes_migrations() { // Follow will cause the neuron to be modified. let follow_response = nns_set_followees_for_neuron( - &mut state_machine, + &state_machine, neuron_3.principal_id, neuron_3.neuron_id, &[neuron_1.neuron_id, neuron_2.neuron_id], @@ -137,7 +137,7 @@ fn test_neuron_indexes_migrations() { // Split will cause a neuron to be created. let split_response = nns_split_neuron( - &mut state_machine, + &state_machine, neuron_1.principal_id, neuron_1.neuron_id, 500_000_000, diff --git a/rs/nns/integration_tests/src/governance_neurons.rs b/rs/nns/integration_tests/src/governance_neurons.rs index 652b6912aee..460831f51fc 100644 --- a/rs/nns/integration_tests/src/governance_neurons.rs +++ b/rs/nns/integration_tests/src/governance_neurons.rs @@ -284,11 +284,11 @@ fn test_spawn_neuron() { /// to list_neurons). #[test] fn test_neuron_controller_is_not_removed_from_principal_to_neuron_index() { - let mut state_machine = state_machine_builder_for_nns_tests().build(); + let state_machine = state_machine_builder_for_nns_tests().build(); let nns_init_payloads = NnsInitPayloadsBuilder::new().with_test_neurons().build(); setup_nns_canisters(&state_machine, nns_init_payloads); - let list_neurons_response = list_neurons(&mut state_machine, *TEST_NEURON_2_OWNER_PRINCIPAL); + let list_neurons_response = list_neurons(&state_machine, *TEST_NEURON_2_OWNER_PRINCIPAL); assert_eq!(list_neurons_response.full_neurons.len(), 1); let neuron_id = NeuronIdProto { @@ -296,7 +296,7 @@ fn test_neuron_controller_is_not_removed_from_principal_to_neuron_index() { }; let response = nns_add_hot_key( - &mut state_machine, + &state_machine, *TEST_NEURON_2_OWNER_PRINCIPAL, neuron_id, *TEST_NEURON_2_OWNER_PRINCIPAL, @@ -307,11 +307,11 @@ fn test_neuron_controller_is_not_removed_from_principal_to_neuron_index() { _ => panic!("Failed to add hot key: {:#?}", response), }; - let list_neurons_response = list_neurons(&mut state_machine, *TEST_NEURON_2_OWNER_PRINCIPAL); + let list_neurons_response = list_neurons(&state_machine, *TEST_NEURON_2_OWNER_PRINCIPAL); assert_eq!(list_neurons_response.full_neurons.len(), 1); let response = nns_remove_hot_key( - &mut state_machine, + &state_machine, *TEST_NEURON_2_OWNER_PRINCIPAL, neuron_id, *TEST_NEURON_2_OWNER_PRINCIPAL, @@ -322,7 +322,7 @@ fn test_neuron_controller_is_not_removed_from_principal_to_neuron_index() { _ => panic!("Failed to remove hot key: {:#?}", response), }; - let list_neurons_response = list_neurons(&mut state_machine, *TEST_NEURON_2_OWNER_PRINCIPAL); + let list_neurons_response = list_neurons(&state_machine, *TEST_NEURON_2_OWNER_PRINCIPAL); assert_eq!(list_neurons_response.full_neurons.len(), 1); } @@ -330,7 +330,7 @@ fn test_neuron_controller_is_not_removed_from_principal_to_neuron_index() { fn test_hotkey_can_join_and_leave_community_fund() { // Step 1: Prepare the world. - let mut state_machine = state_machine_builder_for_nns_tests().build(); + let state_machine = state_machine_builder_for_nns_tests().build(); let nns_init_payloads = NnsInitPayloadsBuilder::new().with_test_neurons().build(); setup_nns_canisters(&state_machine, nns_init_payloads); @@ -340,14 +340,14 @@ fn test_hotkey_can_join_and_leave_community_fund() { let hotkey = PrincipalId::new_user_test_id(622_907); nns_add_hot_key( - &mut state_machine, + &state_machine, *TEST_NEURON_1_OWNER_PRINCIPAL, neuron_1_id, hotkey, ); // Step 2a: Call the code under test (indirectly). To wit, is_authorized_to_configure_or_err. - let join_response = nns_join_community_fund(&mut state_machine, hotkey, neuron_1_id); + let join_response = nns_join_community_fund(&state_machine, hotkey, neuron_1_id); // Step 3a: Inspect result. Expect success. fn assert_ok(manage_neuron_response: &ManageNeuronResponse) { @@ -364,7 +364,7 @@ fn test_hotkey_can_join_and_leave_community_fund() { assert_ok(&join_response); // Step 2b: Instead of joining NF, leave it. - let leave_response = nns_leave_community_fund(&mut state_machine, hotkey, neuron_1_id); + let leave_response = nns_leave_community_fund(&state_machine, hotkey, neuron_1_id); // Step 3b: Again, expect success. assert_ok(&leave_response); @@ -373,7 +373,7 @@ fn test_hotkey_can_join_and_leave_community_fund() { // configure operations (besides Neuron Fund membership changes) by hotkey // are verboten. let add_hot_key_response = nns_add_hot_key( - &mut state_machine, + &state_machine, hotkey, neuron_1_id, PrincipalId::new_user_test_id(289_896), @@ -402,17 +402,17 @@ fn test_hotkey_can_join_and_leave_community_fund() { // Steps 2d, 3d: Controller can perform any neuron configure operation. assert_ok(&nns_join_community_fund( - &mut state_machine, + &state_machine, *TEST_NEURON_1_OWNER_PRINCIPAL, neuron_1_id, )); assert_ok(&nns_leave_community_fund( - &mut state_machine, + &state_machine, *TEST_NEURON_1_OWNER_PRINCIPAL, neuron_1_id, )); assert_ok(&nns_add_hot_key( - &mut state_machine, + &state_machine, *TEST_NEURON_1_OWNER_PRINCIPAL, neuron_1_id, PrincipalId::new_user_test_id(331_685), @@ -423,7 +423,7 @@ fn test_hotkey_can_join_and_leave_community_fund() { fn test_claim_neuron() { // Step 1: Prepare the world by setting up NNS canisters and transfer 1 ICP to a Governance // canister subaccount. - let mut state_machine = state_machine_builder_for_nns_tests().build(); + let state_machine = state_machine_builder_for_nns_tests().build(); let test_user_principal = *TEST_NEURON_1_OWNER_PRINCIPAL; let nonce = 123_456; let nns_init_payloads = NnsInitPayloadsBuilder::new() @@ -441,12 +441,11 @@ fn test_claim_neuron() { ); // Step 2: Call the code under test - claim a neuron. - let neuron_id = nns_claim_or_refresh_neuron(&mut state_machine, test_user_principal, nonce); + let neuron_id = nns_claim_or_refresh_neuron(&state_machine, test_user_principal, nonce); // Step 3.1: Inspect the claimed neuron as a full neuron. let full_neuron = - nns_governance_get_full_neuron(&mut state_machine, test_user_principal, neuron_id.id) - .unwrap(); + nns_governance_get_full_neuron(&state_machine, test_user_principal, neuron_id.id).unwrap(); assert_eq!(full_neuron.controller, Some(test_user_principal)); let created_timestamp_seconds = full_neuron.created_timestamp_seconds; assert!(created_timestamp_seconds > 0); @@ -460,12 +459,9 @@ fn test_claim_neuron() { assert_eq!(full_neuron.cached_neuron_stake_e8s, 1_000_000_000); // Step 3.2: Inspect the claimed neuron as neuron info. - let neuron_info = nns_governance_get_neuron_info( - &mut state_machine, - PrincipalId::new_anonymous(), - neuron_id.id, - ) - .unwrap(); + let neuron_info = + nns_governance_get_neuron_info(&state_machine, PrincipalId::new_anonymous(), neuron_id.id) + .unwrap(); assert_eq!(neuron_info.state, NeuronState::Dissolved as i32); assert_eq!(neuron_info.dissolve_delay_seconds, 0); assert_eq!(neuron_info.age_seconds, 0); diff --git a/rs/nns/integration_tests/src/gtc.rs b/rs/nns/integration_tests/src/gtc.rs index 291c5e441a1..dda07675158 100644 --- a/rs/nns/integration_tests/src/gtc.rs +++ b/rs/nns/integration_tests/src/gtc.rs @@ -51,7 +51,7 @@ const TEST_ECT_ACCOUNTS: &[(&str, u32); 2] = &[ /// `account_has_claimed_neurons` and `permanently_lock_account`) #[test] pub fn test_claim_neurons() { - let mut state_machine = state_machine_builder_for_nns_tests().build(); + let state_machine = state_machine_builder_for_nns_tests().build(); let mut nns_init_payload_builder = NnsInitPayloadsBuilder::new(); add_test_gtc_neurons(&mut nns_init_payload_builder); @@ -94,31 +94,31 @@ pub fn test_claim_neurons() { setup_nns_canisters(&state_machine, nns_init_payload); state_machine.set_time(SystemTime::now()); - assert_neurons_can_only_be_claimed_by_account_owner(&mut state_machine); - assert_neurons_can_only_be_donated_by_account_owner(&mut state_machine); + assert_neurons_can_only_be_claimed_by_account_owner(&state_machine); + assert_neurons_can_only_be_donated_by_account_owner(&state_machine); assert_neurons_can_be_donated( - &mut state_machine, + &state_machine, donate_account_recipient_neuron_id, &TEST_NEURON_1_OWNER_KEYPAIR, &TEST_IDENTITY_3, ); // Assert that a Seed Round (SR) investor can claim their tokens - assert_neurons_can_be_claimed(&mut state_machine, identity_1_neuron_ids, &TEST_IDENTITY_1); + assert_neurons_can_be_claimed(&state_machine, identity_1_neuron_ids, &TEST_IDENTITY_1); // Try to forward the whitelisted account. Note that this should only forward // the whitelisted account so a non-whitelisted account should still be // able to claim afterwards. assert_unclaimed_neurons_can_be_forwarded( - &mut state_machine, + &state_machine, forward_all_unclaimed_accounts_recipient_neuron_id, &TEST_NEURON_2_OWNER_KEYPAIR, ); // Assert that an Early Contributor Token holder (ECT) investor can claim their // tokens - assert_neurons_can_be_claimed(&mut state_machine, identity_2_neuron_ids, &TEST_IDENTITY_2); + assert_neurons_can_be_claimed(&state_machine, identity_2_neuron_ids, &TEST_IDENTITY_2); } /// At Genesis, calls to `claim_neurons` and `forward_all_unclaimed_accounts` @@ -126,7 +126,7 @@ pub fn test_claim_neurons() { /// they are able to be called. #[test] pub fn test_gtc_at_genesis() { - let mut state_machine = state_machine_builder_for_nns_tests().build(); + let state_machine = state_machine_builder_for_nns_tests().build(); let mut nns_init_payload_builder = NnsInitPayloadsBuilder::new(); add_test_gtc_neurons(&mut nns_init_payload_builder); @@ -147,28 +147,25 @@ pub fn test_gtc_at_genesis() { }; // Assert `claim_neurons` fails during the moratorium - let claim_neurons_response: Result, String> = claim_neurons( - &mut state_machine, - sender.get_principal_id(), - &TEST_IDENTITY_1, - ); + let claim_neurons_response: Result, String> = + claim_neurons(&state_machine, sender.get_principal_id(), &TEST_IDENTITY_1); assert!(claim_neurons_response.is_err()); // Assert that `TEST_IDENTITY_1` did not claim their neurons let account_has_claimed_neurons_response: Result = - get_gtc_account(&mut state_machine, &TEST_IDENTITY_1); + get_gtc_account(&state_machine, &TEST_IDENTITY_1); assert!(!account_has_claimed_neurons_response.unwrap().has_claimed); // Assert that `forward_all_unclaimed_accounts` fails let forward_all_unclaimed_accounts_response: Result<(), String> = - forward_whitelisted_unclaimed_accounts(&mut state_machine, &sender); + forward_whitelisted_unclaimed_accounts(&state_machine, &sender); assert!(forward_all_unclaimed_accounts_response.is_err()); } /// Assert that users can't claim other users' neurons /// /// Identity 3 tries to claim Identity 1's neurons, but fails to do so -fn assert_neurons_can_only_be_claimed_by_account_owner(state_machine: &mut StateMachine) { +fn assert_neurons_can_only_be_claimed_by_account_owner(state_machine: &StateMachine) { // Assert that one user can't claim another user's neurons let claim_neurons_response = claim_neurons( state_machine, @@ -182,7 +179,7 @@ fn assert_neurons_can_only_be_claimed_by_account_owner(state_machine: &mut State /// Assert that users can't donate other users' neurons /// /// Identity 3 tries to donate Identity 1's neurons, but fails to do so -fn assert_neurons_can_only_be_donated_by_account_owner(state_machine: &mut StateMachine) { +fn assert_neurons_can_only_be_donated_by_account_owner(state_machine: &StateMachine) { // Assert that one user can't donate another user's neurons let donate_account_response = donate_accounts( state_machine, @@ -197,7 +194,7 @@ fn assert_neurons_can_only_be_donated_by_account_owner(state_machine: &mut State /// This assumes the window after Genesis, during which the forwarding of /// unclaimed accounts is forbidden, has expired. fn assert_unclaimed_neurons_can_be_forwarded( - state_machine: &mut StateMachine, + state_machine: &StateMachine, custodian_neuron_id: NeuronId, custodian_key_pair: &ic_canister_client_sender::Ed25519KeyPair, ) { @@ -304,7 +301,7 @@ fn assert_unclaimed_neurons_can_be_forwarded( /// Assert that GTC neurons can be donated by the owner of the GTC account fn assert_neurons_can_be_donated( - state_machine: &mut StateMachine, + state_machine: &StateMachine, custodian_neuron_id: NeuronId, custodian_key_pair: &ic_canister_client_sender::Ed25519KeyPair, test_identity: &'static TestIdentity, @@ -424,7 +421,7 @@ fn assert_neurons_can_be_donated( /// Test that the given `test_identity` can claim their neurons, expected to /// be `expected_neuron_ids`. fn assert_neurons_can_be_claimed( - state_machine: &mut StateMachine, + state_machine: &StateMachine, expected_neuron_ids: Vec, test_identity: &'static TestIdentity, ) { @@ -571,7 +568,7 @@ fn get_forward_whitelisted_unclaimed_accounts_recipient_neuron_id( } fn get_gtc_account( - state_machine: &mut StateMachine, + state_machine: &StateMachine, test_identity: &TestIdentity, ) -> Result { let result = state_machine @@ -590,7 +587,7 @@ fn get_gtc_account( } fn forward_whitelisted_unclaimed_accounts( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: &Sender, ) -> Result<(), String> { let result = state_machine @@ -613,7 +610,7 @@ fn forward_whitelisted_unclaimed_accounts( } fn donate_accounts( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: PrincipalId, test_identity: &TestIdentity, ) -> Result<(), String> { @@ -634,7 +631,7 @@ fn donate_accounts( } fn claim_neurons( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: PrincipalId, test_identity: &TestIdentity, ) -> Result, String> { diff --git a/rs/nns/integration_tests/src/lifeline.rs b/rs/nns/integration_tests/src/lifeline.rs index d9ca2dd85b1..d213703ff2f 100644 --- a/rs/nns/integration_tests/src/lifeline.rs +++ b/rs/nns/integration_tests/src/lifeline.rs @@ -29,7 +29,7 @@ use std::time::Duration; #[test] fn test_submit_and_accept_root_canister_upgrade_proposal() { - let mut state_machine = state_machine_builder_for_nns_tests().build(); + let state_machine = state_machine_builder_for_nns_tests().build(); let nns_init_payloads = NnsInitPayloadsBuilder::new().with_test_neurons().build(); setup_nns_canisters(&state_machine, nns_init_payloads); @@ -87,7 +87,7 @@ fn test_submit_and_accept_root_canister_upgrade_proposal() { id: TEST_NEURON_2_ID, }; let proposal_submission_response = nns_governance_make_proposal( - &mut state_machine, + &state_machine, *TEST_NEURON_2_OWNER_PRINCIPAL, neuron_id, &proposal, @@ -104,12 +104,12 @@ fn test_submit_and_accept_root_canister_upgrade_proposal() { }; // Should have 1 pending proposals - let pending_proposals = get_pending_proposals(&mut state_machine); + let pending_proposals = get_pending_proposals(&state_machine); assert_eq!(pending_proposals.len(), 1); // Cast votes. nns_cast_vote( - &mut state_machine, + &state_machine, *TEST_NEURON_1_OWNER_PRINCIPAL, ic_nns_common::pb::v1::NeuronId { id: TEST_NEURON_1_ID, @@ -119,9 +119,9 @@ fn test_submit_and_accept_root_canister_upgrade_proposal() { ); // Wait for the proposal to be accepted and executed. - nns_wait_for_proposal_execution(&mut state_machine, proposal_id.id); + nns_wait_for_proposal_execution(&state_machine, proposal_id.id); let proposal_info = - nns_governance_get_proposal_info_as_anonymous(&mut state_machine, proposal_id.id); + nns_governance_get_proposal_info_as_anonymous(&state_machine, proposal_id.id); assert_eq!( proposal_info.status(), ProposalStatus::Executed, @@ -130,7 +130,7 @@ fn test_submit_and_accept_root_canister_upgrade_proposal() { ); // No proposals should be pending now. - let pending_proposals = get_pending_proposals(&mut state_machine); + let pending_proposals = get_pending_proposals(&state_machine); assert_eq!(pending_proposals, vec![]); // check root status again let root_status = get_root_canister_status(&state_machine).unwrap(); @@ -156,7 +156,7 @@ fn test_submit_and_accept_root_canister_upgrade_proposal() { #[test] fn test_submit_and_accept_forced_root_canister_upgrade_proposal() { - let mut state_machine = state_machine_builder_for_nns_tests().build(); + let state_machine = state_machine_builder_for_nns_tests().build(); let nns_init_payloads = NnsInitPayloadsBuilder::new().with_test_neurons().build(); setup_nns_canisters(&state_machine, nns_init_payloads); @@ -187,7 +187,7 @@ fn test_submit_and_accept_forced_root_canister_upgrade_proposal() { id: TEST_NEURON_2_ID, }; let proposal_submission_response = nns_governance_make_proposal( - &mut state_machine, + &state_machine, *TEST_NEURON_2_OWNER_PRINCIPAL, neuron_id, &proposal, @@ -205,12 +205,12 @@ fn test_submit_and_accept_forced_root_canister_upgrade_proposal() { }; // Should have 1 pending proposals - let pending_proposals = get_pending_proposals(&mut state_machine); + let pending_proposals = get_pending_proposals(&state_machine); assert_eq!(pending_proposals.len(), 1); // Cast votes. nns_cast_vote( - &mut state_machine, + &state_machine, *TEST_NEURON_1_OWNER_PRINCIPAL, ic_nns_common::pb::v1::NeuronId { id: TEST_NEURON_1_ID, @@ -219,9 +219,9 @@ fn test_submit_and_accept_forced_root_canister_upgrade_proposal() { Vote::Yes, ); // Wait for the proposal to be accepted and executed. - nns_wait_for_proposal_execution(&mut state_machine, proposal_id.id); + nns_wait_for_proposal_execution(&state_machine, proposal_id.id); let proposal_info = - nns_governance_get_proposal_info_as_anonymous(&mut state_machine, proposal_id.id); + nns_governance_get_proposal_info_as_anonymous(&state_machine, proposal_id.id); assert_eq!( proposal_info.status(), ProposalStatus::Executed, @@ -230,7 +230,7 @@ fn test_submit_and_accept_forced_root_canister_upgrade_proposal() { ); // No proposals should be pending now. - let pending_proposals = get_pending_proposals(&mut state_machine); + let pending_proposals = get_pending_proposals(&state_machine); assert_eq!(pending_proposals, vec![]); // check root status again @@ -243,7 +243,7 @@ fn test_submit_and_accept_forced_root_canister_upgrade_proposal() { #[test] fn test_lifeline_canister_restarts_root_on_stop_canister_timeout() { - let mut state_machine = state_machine_builder_for_nns_tests().build(); + let state_machine = state_machine_builder_for_nns_tests().build(); let nns_init_payloads = NnsInitPayloadsBuilder::new().with_test_neurons().build(); setup_nns_canisters(&state_machine, nns_init_payloads); @@ -287,7 +287,7 @@ fn test_lifeline_canister_restarts_root_on_stop_canister_timeout() { id: TEST_NEURON_1_ID, }; nns_governance_make_proposal( - &mut state_machine, + &state_machine, *TEST_NEURON_1_OWNER_PRINCIPAL, neuron_id, &proposal, diff --git a/rs/nns/integration_tests/src/neuron_following.rs b/rs/nns/integration_tests/src/neuron_following.rs index 5f3aac4b585..ad29c247c86 100644 --- a/rs/nns/integration_tests/src/neuron_following.rs +++ b/rs/nns/integration_tests/src/neuron_following.rs @@ -37,35 +37,35 @@ fn setup_state_machine_with_nns_canisters() -> StateMachine { #[test] fn follow_another() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let n2 = get_neuron_2(); // neuron 1 follows neuron 2 - set_followees_on_topic(&mut state_machine, &n1, &[n2.neuron_id], VALID_TOPIC); + set_followees_on_topic(&state_machine, &n1, &[n2.neuron_id], VALID_TOPIC); } #[test] fn follow_itself() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); // cycles are allowed; neurons can follow themselves - set_followees_on_topic(&mut state_machine, &n1, &[n1.neuron_id], VALID_TOPIC); + set_followees_on_topic(&state_machine, &n1, &[n1.neuron_id], VALID_TOPIC); } #[test] fn follow_on_invalid_topic() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let n2 = get_neuron_2(); // neurons cannot follow another neuron on an invalid topic let result = nns_set_followees_for_neuron( - &mut state_machine, + &state_machine, n1.principal_id, n1.neuron_id, &[n2.neuron_id], @@ -82,14 +82,14 @@ fn follow_on_invalid_topic() { #[test] fn unauthorized_neuron_cannot_follow_neuron() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let unauthorized_neuron = get_unauthorized_neuron(); // the unauthorized neuron cannot follow n1 let result = nns_set_followees_for_neuron( - &mut state_machine, + &state_machine, unauthorized_neuron.principal_id, unauthorized_neuron.neuron_id, &[n1.neuron_id], @@ -105,14 +105,14 @@ fn unauthorized_neuron_cannot_follow_neuron() { #[test] fn nonexistent_neuron_cannot_follow_neuron() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let nonexistent_neuron = get_nonexistent_neuron(); // the non-existing neuron cannot follow a neuron let result = nns_set_followees_for_neuron( - &mut state_machine, + &state_machine, nonexistent_neuron.principal_id, nonexistent_neuron.neuron_id, &[n1.neuron_id], @@ -128,14 +128,14 @@ fn nonexistent_neuron_cannot_follow_neuron() { #[test] fn neuron_follow_nonexistent_neuron() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let nonexistent_neuron = get_nonexistent_neuron(); // neurons are allowed to follow nonexistent neurons set_followees_on_topic( - &mut state_machine, + &state_machine, &n1, &[nonexistent_neuron.neuron_id], VALID_TOPIC, @@ -144,20 +144,20 @@ fn neuron_follow_nonexistent_neuron() { #[test] fn unfollow_all_in_a_topic() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let n2 = get_neuron_2(); // n1 follows n2 - set_followees_on_topic(&mut state_machine, &n1, &[n2.neuron_id], VALID_TOPIC); + set_followees_on_topic(&state_machine, &n1, &[n2.neuron_id], VALID_TOPIC); // n1 unfollows all (n2) - clear_followees_on_topic(&mut state_machine, &n1, VALID_TOPIC); + clear_followees_on_topic(&state_machine, &n1, VALID_TOPIC); } #[test] fn follow_existing_and_nonexistent_neurons() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let n2 = get_neuron_2(); @@ -165,7 +165,7 @@ fn follow_existing_and_nonexistent_neurons() { // n1 can follow a mix of existent and nonexistent neurons set_followees_on_topic( - &mut state_machine, + &state_machine, &n1, &[nonexistent_neuron.neuron_id, n2.neuron_id], VALID_TOPIC, @@ -174,14 +174,14 @@ fn follow_existing_and_nonexistent_neurons() { #[test] fn follow_same_neuron_multiple_times() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let n2 = get_neuron_2(); // neurons can follow the same neuron multiple times set_followees_on_topic( - &mut state_machine, + &state_machine, &n1, &[n2.neuron_id, n2.neuron_id, n2.neuron_id], VALID_TOPIC, @@ -190,64 +190,64 @@ fn follow_same_neuron_multiple_times() { #[test] fn vote_propagation_with_following() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let n2 = get_neuron_2(); let n3 = get_neuron_3(); // make a proposal via n2 before setting up followees - let proposal_id = submit_proposal(&mut state_machine, &n2); + let proposal_id = submit_proposal(&state_machine, &n2); - let votes = get_yes_votes(&mut state_machine, &proposal_id); + let votes = get_yes_votes(&state_machine, &proposal_id); assert_eq!(votes, VOTING_POWER_NEURON_2); - let ballot_n2 = check_ballots(&mut state_machine, &proposal_id, &n2); + let ballot_n2 = check_ballots(&state_machine, &proposal_id, &n2); assert_eq!(ballot_n2, (VOTING_POWER_NEURON_2, Vote::Yes)); // make n1 follow n2 set_followees_on_topic( - &mut state_machine, + &state_machine, &n1, &[n2.neuron_id], NETWORK_CANISTER_MANAGEMENT_TOPIC, ); // voting doesn't get propagated by mutating the following graph - let votes = get_yes_votes(&mut state_machine, &proposal_id); + let votes = get_yes_votes(&state_machine, &proposal_id); assert_eq!(votes, VOTING_POWER_NEURON_2); - let ballot_n1 = check_ballots(&mut state_machine, &proposal_id, &n1); + let ballot_n1 = check_ballots(&state_machine, &proposal_id, &n1); assert_eq!(ballot_n1, (VOTING_POWER_NEURON_1, Vote::Unspecified)); - let ballot_n2 = check_ballots(&mut state_machine, &proposal_id, &n2); + let ballot_n2 = check_ballots(&state_machine, &proposal_id, &n2); assert_eq!(ballot_n2, (VOTING_POWER_NEURON_2, Vote::Yes)); // re-vote explicitly, still no change nns_cast_vote( - &mut state_machine, + &state_machine, n2.principal_id, n2.neuron_id, proposal_id.0, Vote::Yes, ); - let votes = get_yes_votes(&mut state_machine, &proposal_id); + let votes = get_yes_votes(&state_machine, &proposal_id); assert_eq!(votes, VOTING_POWER_NEURON_2); // n1 needs to vote explicitly nns_cast_vote( - &mut state_machine, + &state_machine, n1.principal_id, n1.neuron_id, proposal_id.0, Vote::Yes, ); - let votes = get_yes_votes(&mut state_machine, &proposal_id); + let votes = get_yes_votes(&state_machine, &proposal_id); assert_eq!(votes, 1_544_404_516); - let ballot_n1 = check_ballots(&mut state_machine, &proposal_id, &n1); + let ballot_n1 = check_ballots(&state_machine, &proposal_id, &n1); assert_eq!(ballot_n1, (VOTING_POWER_NEURON_1, Vote::Yes)); // make n3 follow n2 set_followees_on_topic( - &mut state_machine, + &state_machine, &n3, &[n2.neuron_id], NETWORK_CANISTER_MANAGEMENT_TOPIC, @@ -255,7 +255,7 @@ fn vote_propagation_with_following() { // make n2 follow n1 set_followees_on_topic( - &mut state_machine, + &state_machine, &n2, &[n1.neuron_id], NETWORK_CANISTER_MANAGEMENT_TOPIC, @@ -263,24 +263,24 @@ fn vote_propagation_with_following() { // now n1 and n2 follow each other (circle), and n3 follows n2 // make another proposal via n2 now that followees are set up - let proposal_id = submit_proposal(&mut state_machine, &n2); + let proposal_id = submit_proposal(&state_machine, &n2); // verify that all three neurons did vote - let votes = get_yes_votes(&mut state_machine, &proposal_id); + let votes = get_yes_votes(&state_machine, &proposal_id); assert_eq!( votes, VOTING_POWER_NEURON_1 + VOTING_POWER_NEURON_2 + VOTING_POWER_NEURON_3 ); - let ballot_n1 = check_ballots(&mut state_machine, &proposal_id, &n1); + let ballot_n1 = check_ballots(&state_machine, &proposal_id, &n1); assert_eq!(ballot_n1, (VOTING_POWER_NEURON_1, Vote::Yes)); - let ballot_n2 = check_ballots(&mut state_machine, &proposal_id, &n2); + let ballot_n2 = check_ballots(&state_machine, &proposal_id, &n2); assert_eq!(ballot_n2, (VOTING_POWER_NEURON_2, Vote::Yes)); - let ballot_n3 = check_ballots(&mut state_machine, &proposal_id, &n3); + let ballot_n3 = check_ballots(&state_machine, &proposal_id, &n3); assert_eq!(ballot_n3, (VOTING_POWER_NEURON_3, Vote::Yes)); // split n1 and build a follow chain like this: // n2 -> n1a -> n3 -> n1 - let n1a_id = split_neuron(&mut state_machine, &n1, 500_000_000); + let n1a_id = split_neuron(&state_machine, &n1, 500_000_000); let n1a = TestNeuronOwner { neuron_id: n1a_id, principal_id: n1.principal_id, @@ -288,28 +288,28 @@ fn vote_propagation_with_following() { // make n2 follow n1a set_followees_on_topic( - &mut state_machine, + &state_machine, &n2, &[n1a.neuron_id], NETWORK_CANISTER_MANAGEMENT_TOPIC, ); // at this point n2 is not influential - let influential = get_neuron_ids(&mut state_machine, n1a.principal_id); + let influential = get_neuron_ids(&state_machine, n1a.principal_id); assert_eq!(influential.len(), 2); assert!(influential.contains(&n1a.neuron_id.id)); assert!(influential.contains(&n1.neuron_id.id)); // same following, different topic set_followees_on_topic( - &mut state_machine, + &state_machine, &n2, &[n1a.neuron_id], NEURON_MANAGEMENT_TOPIC, ); // at this point n2 becomes influential (a `NeuronManagement` follower to n1a) - let influential = get_neuron_ids(&mut state_machine, n1a.principal_id); + let influential = get_neuron_ids(&state_machine, n1a.principal_id); assert_eq!(influential.len(), 3); assert!(influential.contains(&n1a.neuron_id.id)); assert!(influential.contains(&n1.neuron_id.id)); @@ -317,13 +317,13 @@ fn vote_propagation_with_following() { // change following, in `NeuronManagement` topic set_followees_on_topic( - &mut state_machine, + &state_machine, &n3, &[n1a.neuron_id], NEURON_MANAGEMENT_TOPIC, ); // at this point n3 becomes influential (a `NeuronManagement` follower to n1a) - let influential = get_neuron_ids(&mut state_machine, n1a.principal_id); + let influential = get_neuron_ids(&state_machine, n1a.principal_id); assert_eq!(influential.len(), 4); assert!(influential.contains(&n1a.neuron_id.id)); assert!(influential.contains(&n1.neuron_id.id)); @@ -332,28 +332,28 @@ fn vote_propagation_with_following() { // change following, in `NeuronManagement` topic set_followees_on_topic( - &mut state_machine, + &state_machine, &n2, &[n3.neuron_id], NEURON_MANAGEMENT_TOPIC, ); // at this point n2 ceases to be influential (as a `NeuronManagement` follower // to n1a) - let influential = get_neuron_ids(&mut state_machine, n1a.principal_id); + let influential = get_neuron_ids(&state_machine, n1a.principal_id); assert_eq!(influential.len(), 3); assert!(influential.contains(&n1a.neuron_id.id)); assert!(influential.contains(&n1.neuron_id.id)); assert!(influential.contains(&n3.neuron_id.id)); set_followees_on_topic( - &mut state_machine, + &state_machine, &n1a, &[n3.neuron_id], NETWORK_CANISTER_MANAGEMENT_TOPIC, ); set_followees_on_topic( - &mut state_machine, + &state_machine, &n3, &[n1.neuron_id], NETWORK_CANISTER_MANAGEMENT_TOPIC, @@ -361,29 +361,25 @@ fn vote_propagation_with_following() { // fire off a new proposal by n1, and see all neurons voting // immediately along the chain - let proposal_id = submit_proposal(&mut state_machine, &n1); + let proposal_id = submit_proposal(&state_machine, &n1); // verify that all four neurons did vote - let votes = get_yes_votes(&mut state_machine, &proposal_id); + let votes = get_yes_votes(&state_machine, &proposal_id); assert_eq!( votes, 702_002_052 + 701_988_012 + VOTING_POWER_NEURON_2 + VOTING_POWER_NEURON_3 ); - let ballot_n1 = check_ballots(&mut state_machine, &proposal_id, &n1); + let ballot_n1 = check_ballots(&state_machine, &proposal_id, &n1); assert_eq!(ballot_n1, (702_002_052, Vote::Yes)); - let ballot_n1a = check_ballots(&mut state_machine, &proposal_id, &n1a); + let ballot_n1a = check_ballots(&state_machine, &proposal_id, &n1a); assert_eq!(ballot_n1a, (701_988_012, Vote::Yes)); - let ballot_n2 = check_ballots(&mut state_machine, &proposal_id, &n2); + let ballot_n2 = check_ballots(&state_machine, &proposal_id, &n2); assert_eq!(ballot_n2, (VOTING_POWER_NEURON_2, Vote::Yes)); - let ballot_n3 = check_ballots(&mut state_machine, &proposal_id, &n3); + let ballot_n3 = check_ballots(&state_machine, &proposal_id, &n3); assert_eq!(ballot_n3, (VOTING_POWER_NEURON_3, Vote::Yes)); } -fn split_neuron( - state_machine: &mut StateMachine, - neuron: &TestNeuronOwner, - amount: u64, -) -> NeuronId { +fn split_neuron(state_machine: &StateMachine, neuron: &TestNeuronOwner, amount: u64) -> NeuronId { let response = nns_split_neuron(state_machine, neuron.principal_id, neuron.neuron_id, amount); if let Command::Split(resp) = response.command.unwrap() { resp.created_neuron_id.unwrap() @@ -393,7 +389,7 @@ fn split_neuron( } fn check_ballots( - state_machine: &mut StateMachine, + state_machine: &StateMachine, proposal_id: &ProposalId, neuron: &TestNeuronOwner, ) -> (u64, Vote) { @@ -404,7 +400,7 @@ fn check_ballots( (ballot.voting_power, Vote::try_from(ballot.vote).unwrap()) } -fn get_yes_votes(state_machine: &mut StateMachine, proposal_id: &ProposalId) -> u64 { +fn get_yes_votes(state_machine: &StateMachine, proposal_id: &ProposalId) -> u64 { let info = nns_governance_get_proposal_info_as_anonymous(state_machine, proposal_id.0); match info.latest_tally { Some(Tally { yes, .. }) => yes, @@ -412,11 +408,7 @@ fn get_yes_votes(state_machine: &mut StateMachine, proposal_id: &ProposalId) -> } } -fn clear_followees_on_topic( - state_machine: &mut StateMachine, - neuron: &TestNeuronOwner, - topic: i32, -) { +fn clear_followees_on_topic(state_machine: &StateMachine, neuron: &TestNeuronOwner, topic: i32) { let result = nns_set_followees_for_neuron( state_machine, neuron.principal_id, @@ -436,7 +428,7 @@ fn clear_followees_on_topic( /// make neuron follow the neurons in followees fn set_followees_on_topic( - state_machine: &mut StateMachine, + state_machine: &StateMachine, neuron: &TestNeuronOwner, followees: &[NeuronId], topic: i32, diff --git a/rs/nns/integration_tests/src/neuron_voting.rs b/rs/nns/integration_tests/src/neuron_voting.rs index 956a8d8ae4b..00a392e8bda 100644 --- a/rs/nns/integration_tests/src/neuron_voting.rs +++ b/rs/nns/integration_tests/src/neuron_voting.rs @@ -30,11 +30,11 @@ fn setup_state_machine_with_nns_canisters() -> StateMachine { #[test] fn unauthorized_neuron_cannot_create_proposal() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let unauthorized_neuron = get_unauthorized_neuron(); let proposal = get_some_proposal(); let response = nns_governance_make_proposal( - &mut state_machine, + &state_machine, unauthorized_neuron.principal_id, unauthorized_neuron.neuron_id, &proposal, @@ -48,11 +48,11 @@ fn unauthorized_neuron_cannot_create_proposal() { #[test] fn unauthorized_neuron_cannot_vote_on_nonexistent_proposal() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let unauthorized_neuron = get_unauthorized_neuron(); let response = nns_cast_vote( - &mut state_machine, + &state_machine, unauthorized_neuron.principal_id, unauthorized_neuron.neuron_id, INVALID_PROPOSAL_ID, @@ -67,11 +67,11 @@ fn unauthorized_neuron_cannot_vote_on_nonexistent_proposal() { #[test] fn anonymous_principal_cannot_vote_on_nonexistent_proposal() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let response = nns_cast_vote( - &mut state_machine, + &state_machine, PrincipalId::new_anonymous(), n1.neuron_id, INVALID_PROPOSAL_ID, @@ -86,12 +86,12 @@ fn anonymous_principal_cannot_vote_on_nonexistent_proposal() { #[test] fn anonymous_principal_cannot_vote_on_existent_proposal() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); - let proposal_id = submit_proposal(&mut state_machine, &n1); + let proposal_id = submit_proposal(&state_machine, &n1); let response = nns_cast_vote( - &mut state_machine, + &state_machine, PrincipalId::new_anonymous(), n1.neuron_id, proposal_id.0, @@ -106,11 +106,11 @@ fn anonymous_principal_cannot_vote_on_existent_proposal() { #[test] fn neuron_cannot_vote_on_nonexistent_proposal() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let response = nns_cast_vote( - &mut state_machine, + &state_machine, n1.principal_id, n1.neuron_id, INVALID_PROPOSAL_ID, @@ -125,13 +125,13 @@ fn neuron_cannot_vote_on_nonexistent_proposal() { #[test] fn propose_and_vote_with_other_neuron() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let n2 = get_neuron_2(); - let proposal_id = submit_proposal(&mut state_machine, &n1); + let proposal_id = submit_proposal(&state_machine, &n1); let response = nns_cast_vote( - &mut state_machine, + &state_machine, n2.principal_id, n2.neuron_id, proposal_id.0, @@ -145,14 +145,14 @@ fn propose_and_vote_with_other_neuron() { #[test] fn proposer_neuron_cannot_vote_explicitly() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); - let proposal_id = submit_proposal(&mut state_machine, &n1); + let proposal_id = submit_proposal(&state_machine, &n1); // neuron 1 already implicitly voted when submitting the proposal let response = nns_cast_vote( - &mut state_machine, + &state_machine, n1.principal_id, n1.neuron_id, proposal_id.0, @@ -167,14 +167,14 @@ fn proposer_neuron_cannot_vote_explicitly() { #[test] fn neuron_cannot_vote_twice() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let n2 = get_neuron_2(); - let proposal_id = submit_proposal(&mut state_machine, &n1); + let proposal_id = submit_proposal(&state_machine, &n1); // vote once with neuron 2 let response_1 = nns_cast_vote( - &mut state_machine, + &state_machine, n2.principal_id, n2.neuron_id, proposal_id.0, @@ -187,7 +187,7 @@ fn neuron_cannot_vote_twice() { // vote again with neuron 2 let response_2 = nns_cast_vote( - &mut state_machine, + &state_machine, n2.principal_id, n2.neuron_id, proposal_id.0, @@ -202,13 +202,13 @@ fn neuron_cannot_vote_twice() { #[test] fn nonexistent_neuron_cannot_vote() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let nonexistent_neuron = get_nonexistent_neuron(); - let proposal_id = submit_proposal(&mut state_machine, &n1); + let proposal_id = submit_proposal(&state_machine, &n1); let response = nns_cast_vote( - &mut state_machine, + &state_machine, nonexistent_neuron.principal_id, nonexistent_neuron.neuron_id, proposal_id.0, @@ -223,13 +223,13 @@ fn nonexistent_neuron_cannot_vote() { #[test] fn cannot_submit_proposals_with_insufficient_funds() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n3 = get_neuron_3(); let proposal = get_some_proposal(); // neuron 3 does not have enough funds to submit proposal. when proposal gets rejected, it needs to cover reject_cost_e8s. See also NNS1-297. let response = - nns_governance_make_proposal(&mut state_machine, n3.principal_id, n3.neuron_id, &proposal) + nns_governance_make_proposal(&state_machine, n3.principal_id, n3.neuron_id, &proposal) .command .expect("Making NNS proposal failed"); @@ -239,14 +239,14 @@ fn cannot_submit_proposals_with_insufficient_funds() { #[test] fn can_vote_on_proposal_with_insufficient_funds() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n2 = get_neuron_2(); let n3 = get_neuron_3(); // however, proposal can be voted on even when the voting neuron has insufficient funds for submitting proposals - let proposal_id = submit_proposal(&mut state_machine, &n2); + let proposal_id = submit_proposal(&state_machine, &n2); let response = nns_cast_vote( - &mut state_machine, + &state_machine, n3.principal_id, n3.neuron_id, proposal_id.0, @@ -260,20 +260,20 @@ fn can_vote_on_proposal_with_insufficient_funds() { #[test] fn failed_proposal_causes_reject_cost_deduction_for_proposer() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let n2 = get_neuron_2(); let n2_funds_before = - nns_governance_get_full_neuron(&mut state_machine, n2.principal_id, n2.neuron_id.id) + nns_governance_get_full_neuron(&state_machine, n2.principal_id, n2.neuron_id.id) .expect("Could not retrieve neuron info") .stake_e8s(); - let proposal_id = submit_proposal(&mut state_machine, &n2); + let proposal_id = submit_proposal(&state_machine, &n2); // vote "no" with heavy neuron 1 to cause the proposal to fail let response = nns_cast_vote( - &mut state_machine, + &state_machine, n1.principal_id, n1.neuron_id, proposal_id.0, @@ -285,7 +285,7 @@ fn failed_proposal_causes_reject_cost_deduction_for_proposer() { assert_eq!(response, Command::RegisterVote(RegisterVoteResponse {})); let n2_funds_after = - nns_governance_get_full_neuron(&mut state_machine, n2.principal_id, n2.neuron_id.id) + nns_governance_get_full_neuron(&state_machine, n2.principal_id, n2.neuron_id.id) .expect("Could not retrieve neuron info") .stake_e8s(); @@ -294,13 +294,13 @@ fn failed_proposal_causes_reject_cost_deduction_for_proposer() { #[test] fn cannot_vote_on_future_proposal() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); let n1 = get_neuron_1(); let n2 = get_neuron_2(); let future_proposal_id = ProposalId(1); let response = nns_cast_vote( - &mut state_machine, + &state_machine, n1.principal_id, n1.neuron_id, future_proposal_id.0, @@ -312,10 +312,10 @@ fn cannot_vote_on_future_proposal() { assert_matches!(response, Command::Error(ref err) if err.error_type() == ErrorType::NotFound); assert_matches!(response, Command::Error(ref err) if err.error_message.contains("Can't find proposal")); - let proposal_id = submit_proposal(&mut state_machine, &n2); + let proposal_id = submit_proposal(&state_machine, &n2); assert_eq!(proposal_id, future_proposal_id); - let pending_proposals = get_pending_proposals(&mut state_machine); + let pending_proposals = get_pending_proposals(&state_machine); let proposal = pending_proposals .iter() .find(|p| p.id == Some(ic_nns_common::pb::v1::ProposalId { id: proposal_id.0 })) diff --git a/rs/nns/integration_tests/src/node_provider_remuneration.rs b/rs/nns/integration_tests/src/node_provider_remuneration.rs index 43e99c636c5..e992bd5ba88 100644 --- a/rs/nns/integration_tests/src/node_provider_remuneration.rs +++ b/rs/nns/integration_tests/src/node_provider_remuneration.rs @@ -72,7 +72,7 @@ impl NodeInfo { #[test] fn test_automated_node_provider_remuneration() { - let mut state_machine = state_machine_builder_for_nns_tests().build(); + let state_machine = state_machine_builder_for_nns_tests().build(); let nns_init_payload = NnsInitPayloadsBuilder::new() .with_initial_invariant_compliant_mutations() @@ -80,8 +80,8 @@ fn test_automated_node_provider_remuneration() { .build(); setup_nns_canisters(&state_machine, nns_init_payload); - add_data_centers(&mut state_machine); - add_node_rewards_table(&mut state_machine); + add_data_centers(&state_machine); + add_node_rewards_table(&state_machine); // Define the set of node operators and node providers let node_info_1 = NodeInfo::new( @@ -140,14 +140,14 @@ fn test_automated_node_provider_remuneration() { let node_operator_id_4 = *TEST_USER7_PRINCIPAL; // Add Node Providers - add_node_provider(&mut state_machine, node_info_1.provider.clone()); - add_node_provider(&mut state_machine, node_info_2.provider.clone()); - add_node_provider(&mut state_machine, node_info_3.provider.clone()); + add_node_provider(&state_machine, node_info_1.provider.clone()); + add_node_provider(&state_machine, node_info_2.provider.clone()); + add_node_provider(&state_machine, node_info_3.provider.clone()); // Add Node Operator 1 let rewardable_nodes_1 = btreemap! { "default".to_string() => 10 }; add_node_operator( - &mut state_machine, + &state_machine, &node_info_1.operator_id, &node_info_1.provider_id, "AN1", @@ -161,7 +161,7 @@ fn test_automated_node_provider_remuneration() { "small".to_string() => 17, }; add_node_operator( - &mut state_machine, + &state_machine, &node_info_2.operator_id, &node_info_2.provider_id, "BC1", @@ -176,7 +176,7 @@ fn test_automated_node_provider_remuneration() { "storage_upgrade".to_string() => 4, }; add_node_operator( - &mut state_machine, + &state_machine, &node_info_3.operator_id, &node_info_3.provider_id, "FM1", @@ -190,7 +190,7 @@ fn test_automated_node_provider_remuneration() { "small".to_string() => 6, }; add_node_operator( - &mut state_machine, + &state_machine, &node_operator_id_4, &node_info_1.provider_id, "BC1", @@ -199,11 +199,11 @@ fn test_automated_node_provider_remuneration() { ); // Set the average conversion rate - set_average_icp_xdr_conversion_rate(&mut state_machine, 155_000); + set_average_icp_xdr_conversion_rate(&state_machine, 155_000); // Call get_monthly_node_provider_rewards assert the value is as expected let monthly_node_provider_rewards_result: Result = - nns_get_monthly_node_provider_rewards(&mut state_machine); + nns_get_monthly_node_provider_rewards(&state_machine); let monthly_node_provider_rewards = monthly_node_provider_rewards_result.unwrap(); assert_eq!(monthly_node_provider_rewards.rewards.len(), 3); @@ -218,37 +218,37 @@ fn test_automated_node_provider_remuneration() { .contains(&expected_node_provider_reward_3)); // Assert account balances are 0 - assert_account_balance(&mut state_machine, node_info_1.provider_account, 0); - assert_account_balance(&mut state_machine, node_info_2.provider_account, 0); - assert_account_balance(&mut state_machine, node_info_3.provider_account, 0); + assert_account_balance(&state_machine, node_info_1.provider_account, 0); + assert_account_balance(&state_machine, node_info_2.provider_account, 0); + assert_account_balance(&state_machine, node_info_3.provider_account, 0); // Assert there is no most recent monthly Node Provider reward - let most_recent_rewards = nns_get_most_recent_monthly_node_provider_rewards(&mut state_machine); + let most_recent_rewards = nns_get_most_recent_monthly_node_provider_rewards(&state_machine); assert!(most_recent_rewards.is_none()); // Submit and execute proposal to pay NPs via Registry-driven rewards - reward_node_providers_via_registry(&mut state_machine); + reward_node_providers_via_registry(&state_machine); // Assert account balances are as expected assert_account_balance( - &mut state_machine, + &state_machine, node_info_1.provider_account, expected_node_provider_reward_1.amount_e8s, ); assert_account_balance( - &mut state_machine, + &state_machine, node_info_2.provider_account, expected_node_provider_reward_2.amount_e8s, ); assert_account_balance( - &mut state_machine, + &state_machine, node_info_3.provider_account, expected_node_provider_reward_3.amount_e8s, ); // Assert the most recent monthly Node Provider reward was set as expected let mut most_recent_rewards = - nns_get_most_recent_monthly_node_provider_rewards(&mut state_machine).unwrap(); + nns_get_most_recent_monthly_node_provider_rewards(&state_machine).unwrap(); let np_rewards_from_proposal_timestamp = most_recent_rewards.timestamp; assert!(most_recent_rewards @@ -266,7 +266,7 @@ fn test_automated_node_provider_remuneration() { for _ in 0..5 { state_machine.advance_time(Duration::from_secs(60)); let most_recent_rewards = - nns_get_most_recent_monthly_node_provider_rewards(&mut state_machine).unwrap(); + nns_get_most_recent_monthly_node_provider_rewards(&state_machine).unwrap(); if most_recent_rewards.timestamp != np_rewards_from_proposal_timestamp { rewards_were_triggered = true; break; @@ -280,19 +280,19 @@ fn test_automated_node_provider_remuneration() { // Assert account balances haven't changed assert_account_balance( - &mut state_machine, + &state_machine, node_info_1.provider_account, expected_node_provider_reward_1.amount_e8s, ); assert_account_balance( - &mut state_machine, + &state_machine, node_info_2.provider_account, expected_node_provider_reward_2.amount_e8s, ); assert_account_balance( - &mut state_machine, + &state_machine, node_info_3.provider_account, expected_node_provider_reward_3.amount_e8s, ); @@ -301,7 +301,7 @@ fn test_automated_node_provider_remuneration() { // NP rewards paid a different reward than the proposal-based reward. let average_icp_xdr_conversion_rate_for_automated_rewards = 345_000; set_average_icp_xdr_conversion_rate( - &mut state_machine, + &state_machine, average_icp_xdr_conversion_rate_for_automated_rewards, ); @@ -313,7 +313,7 @@ fn test_automated_node_provider_remuneration() { for _ in 0..10 { state_machine.advance_time(Duration::from_secs(60)); most_recent_rewards = - nns_get_most_recent_monthly_node_provider_rewards(&mut state_machine).unwrap(); + nns_get_most_recent_monthly_node_provider_rewards(&state_machine).unwrap(); np_rewards_from_automation_timestamp = most_recent_rewards.timestamp; if np_rewards_from_automation_timestamp == np_rewards_from_proposal_timestamp { continue; @@ -375,32 +375,32 @@ fn test_automated_node_provider_remuneration() { // Assert additional rewards have been transferred to the Node Provider accounts assert_account_balance( - &mut state_machine, + &state_machine, node_info_1.provider_account, expected_node_provider_reward_1.amount_e8s + expected_automated_rewards_e8s_1, ); assert_account_balance( - &mut state_machine, + &state_machine, node_info_2.provider_account, expected_node_provider_reward_2.amount_e8s + expected_automated_rewards_e8s_2, ); assert_account_balance( - &mut state_machine, + &state_machine, node_info_3.provider_account, expected_node_provider_reward_3.amount_e8s + expected_automated_rewards_e8s_3, ); - let actual_minimum_xdr_permyriad_per_icp = - nns_get_network_economics_parameters(&mut state_machine).minimum_icp_xdr_rate - * NetworkEconomics::ICP_XDR_RATE_TO_BASIS_POINT_MULTIPLIER; + let actual_minimum_xdr_permyriad_per_icp = nns_get_network_economics_parameters(&state_machine) + .minimum_icp_xdr_rate + * NetworkEconomics::ICP_XDR_RATE_TO_BASIS_POINT_MULTIPLIER; // Set a new average conversion that is far below the `actual_minimum_xdr_permyriad_per_icp` // to trigger the limit. let average_icp_xdr_conversion_rate_for_automated_rewards = 1; set_average_icp_xdr_conversion_rate( - &mut state_machine, + &state_machine, average_icp_xdr_conversion_rate_for_automated_rewards, ); @@ -411,7 +411,7 @@ fn test_automated_node_provider_remuneration() { for _ in 0..10 { state_machine.advance_time(Duration::from_secs(60)); most_recent_rewards = - nns_get_most_recent_monthly_node_provider_rewards(&mut state_machine).unwrap(); + nns_get_most_recent_monthly_node_provider_rewards(&state_machine).unwrap(); np_rewards_from_automation_timestamp = most_recent_rewards.timestamp; if np_rewards_from_automation_timestamp == np_rewards_from_proposal_timestamp { continue; @@ -468,7 +468,7 @@ fn test_automated_node_provider_remuneration() { } /// Helper function for making NNS proposals for this test -fn submit_nns_proposal(state_machine: &mut StateMachine, action: Action) { +fn submit_nns_proposal(state_machine: &StateMachine, action: Action) { let response = nns_governance_make_proposal( state_machine, Sender::from_keypair(&TEST_NEURON_1_OWNER_KEYPAIR).get_principal_id(), @@ -508,7 +508,7 @@ fn submit_nns_proposal(state_machine: &mut StateMachine, action: Action) { /// Set the average ICP/XDR conversion rate fn set_average_icp_xdr_conversion_rate( - state_machine: &mut StateMachine, + state_machine: &StateMachine, average_icp_xdr_conversion_rate: u64, ) { // Add conversion rate proposals for the past 31 days. @@ -545,7 +545,7 @@ fn set_average_icp_xdr_conversion_rate( /// Submit and execute a proposal to set the given conversion rate fn set_icp_xdr_conversion_rate( - state_machine: &mut StateMachine, + state_machine: &StateMachine, payload: UpdateIcpXdrConversionRatePayload, ) { // If we do this via proposal (which will be removed in the future) we cannot set it @@ -562,7 +562,7 @@ fn set_icp_xdr_conversion_rate( } /// Assert the given account has the given token balance on the Ledger -fn assert_account_balance(state_machine: &mut StateMachine, account: AccountIdentifier, e8s: u64) { +fn assert_account_balance(state_machine: &StateMachine, account: AccountIdentifier, e8s: u64) { let user_balance: Tokens = ledger_account_balance( state_machine, LEDGER_CANISTER_ID, @@ -576,7 +576,7 @@ fn assert_account_balance(state_machine: &mut StateMachine, account: AccountIden /// Submit and execute a RewardNodeProviders proposal with the `use_registry_derived_rewards` /// flag set to `true`. This causes Node Providers to be rewarded with the rewards returned /// by Governance's `get_monthly_node_provider_rewards` method. -fn reward_node_providers_via_registry(state_machine: &mut StateMachine) { +fn reward_node_providers_via_registry(state_machine: &StateMachine) { submit_nns_proposal( state_machine, Action::RewardNodeProviders(RewardNodeProviders { @@ -587,7 +587,7 @@ fn reward_node_providers_via_registry(state_machine: &mut StateMachine) { } /// Add test Data Centers to the Registry -fn add_data_centers(state_machine: &mut StateMachine) { +fn add_data_centers(state_machine: &StateMachine) { let data_centers = vec![ DataCenterRecord { id: "AN1".into(), @@ -623,7 +623,7 @@ fn add_data_centers(state_machine: &mut StateMachine) { } /// Add a test rewards table to the Registry -fn add_node_rewards_table(state_machine: &mut StateMachine) { +fn add_node_rewards_table(state_machine: &StateMachine) { let new_entries = btreemap! { "EU".to_string() => NodeRewardRates { rates: btreemap!{ @@ -678,7 +678,7 @@ fn add_node_rewards_table(state_machine: &mut StateMachine) { ); } -fn add_node_provider(state_machine: &mut StateMachine, node_provider: NodeProvider) { +fn add_node_provider(state_machine: &StateMachine, node_provider: NodeProvider) { submit_nns_proposal( state_machine, Action::AddOrRemoveNodeProvider(AddOrRemoveNodeProvider { @@ -689,7 +689,7 @@ fn add_node_provider(state_machine: &mut StateMachine, node_provider: NodeProvid /// Submit and execute a proposal to add the given node operator fn add_node_operator( - state_machine: &mut StateMachine, + state_machine: &StateMachine, no_id: &PrincipalId, np_id: &PrincipalId, dc_id: &str, diff --git a/rs/nns/integration_tests/src/reset_root.rs b/rs/nns/integration_tests/src/reset_root.rs index f67fd9043a6..d5557a4ca85 100644 --- a/rs/nns/integration_tests/src/reset_root.rs +++ b/rs/nns/integration_tests/src/reset_root.rs @@ -19,7 +19,7 @@ use ic_nns_test_utils::{ #[test] fn test_reset_root_with_governance_proposal() { - let mut state_machine = state_machine_builder_for_nns_tests().build(); + let state_machine = state_machine_builder_for_nns_tests().build(); let nns_init_payloads = NnsInitPayloadsBuilder::new().with_test_neurons().build(); setup_nns_canisters(&state_machine, nns_init_payloads); @@ -49,7 +49,7 @@ fn test_reset_root_with_governance_proposal() { ); let response = nns_governance_make_proposal( - &mut state_machine, + &state_machine, *TEST_NEURON_1_OWNER_PRINCIPAL, neuron_id, &proposal, @@ -63,7 +63,7 @@ fn test_reset_root_with_governance_proposal() { ), }; - nns_wait_for_proposal_execution(&mut state_machine, proposal_id.id); + nns_wait_for_proposal_execution(&state_machine, proposal_id.id); // Assert the root canister was upgraded assert_eq!( diff --git a/rs/nns/integration_tests/src/subnet_rental_canister.rs b/rs/nns/integration_tests/src/subnet_rental_canister.rs index 88b6490404a..02c1354969a 100644 --- a/rs/nns/integration_tests/src/subnet_rental_canister.rs +++ b/rs/nns/integration_tests/src/subnet_rental_canister.rs @@ -21,8 +21,7 @@ use ic_nns_test_utils::{ setup_subnet_rental_canister_with_correct_canister_id, state_machine_builder_for_nns_tests, }, }; -use ic_state_machine_tests::StateMachine; -use ic_state_machine_tests::WasmResult; +use ic_state_machine_tests::{StateMachine, WasmResult}; use ic_types::Time; use ic_xrc_types::{Asset, AssetClass, ExchangeRateMetadata}; use icp_ledger::{ @@ -178,7 +177,7 @@ fn send_icp_to_rent_subnet(machine: &StateMachine, user_principal_id: PrincipalI } fn check_balance( - machine: &mut StateMachine, + machine: &StateMachine, owner: PrincipalId, subaccount: Option, ) -> Tokens { @@ -205,7 +204,7 @@ fn check_balance( /// In the end, this results in no rental requests, and renter gets their money back. #[test] fn subnet_rental_request_lifecycle() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); setup_mock_exchange_rate_canister(&state_machine, 5_000_000_000); let price1 = get_todays_price(&state_machine); @@ -258,7 +257,7 @@ fn subnet_rental_request_lifecycle() { }; // Make proposal with small neuron. It does not have enough voting power such that the proposal would be adopted immediately. let cmd = nns_governance_make_proposal( - &mut state_machine, + &state_machine, small_neuron.principal_id, small_neuron.neuron_id, &proposal, @@ -288,12 +287,12 @@ fn subnet_rental_request_lifecycle() { // the proposal should not be decided yet as it was proposed by the small neuron let proposal_info = - nns_governance_get_proposal_info_as_anonymous(&mut state_machine, proposal_id.id); + nns_governance_get_proposal_info_as_anonymous(&state_machine, proposal_id.id); assert_eq!(proposal_info.decided_timestamp_seconds, 0); // large neuron votes and thus the proposal should be executed now let response = nns_cast_vote( - &mut state_machine, + &state_machine, large_neuron.principal_id, large_neuron.neuron_id, proposal_id.id, @@ -305,7 +304,7 @@ fn subnet_rental_request_lifecycle() { response, CommandResponse::RegisterVote(RegisterVoteResponse {}) ); - nns_wait_for_proposal_execution(&mut state_machine, proposal_id.id); + nns_wait_for_proposal_execution(&state_machine, proposal_id.id); // check that the rental request has been created let raw_rental_requests = state_machine @@ -354,7 +353,7 @@ fn subnet_rental_request_lifecycle() { assert_eq!(initial_cost_icp, price3); // test user aborts rental request and gets refund - let balance_before = check_balance(&mut state_machine, renter, None); + let balance_before = check_balance(&state_machine, renter, None); state_machine .execute_ingress_as( renter, @@ -363,7 +362,7 @@ fn subnet_rental_request_lifecycle() { Encode!(&()).unwrap(), ) .unwrap(); - let balance_after = check_balance(&mut state_machine, renter, None); + let balance_after = check_balance(&state_machine, renter, None); assert_eq!( balance_before.get_e8s() + refundable_icp.get_e8s(), balance_after.get_e8s() + DEFAULT_TRANSFER_FEE.get_e8s(), @@ -386,7 +385,7 @@ fn subnet_rental_request_lifecycle() { #[test] fn test_renting_a_subnet_without_paying_fails() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); setup_mock_exchange_rate_canister(&state_machine, 25_000_000_000); @@ -408,7 +407,7 @@ fn test_renting_a_subnet_without_paying_fails() { }; // Make proposal with large neuron. It has enough voting power such that the proposal will be adopted immediately. let cmd = nns_governance_make_proposal( - &mut state_machine, + &state_machine, large_neuron.principal_id, large_neuron.neuron_id, &proposal, @@ -421,9 +420,9 @@ fn test_renting_a_subnet_without_paying_fails() { }; // the proposal is expected to fail since the user did not make the initial transfer - nns_wait_for_proposal_failure(&mut state_machine, proposal_id.id); + nns_wait_for_proposal_failure(&state_machine, proposal_id.id); let proposal_info = - nns_governance_get_proposal_info_as_anonymous(&mut state_machine, proposal_id.id); + nns_governance_get_proposal_info_as_anonymous(&state_machine, proposal_id.id); assert!(proposal_info .failure_reason .unwrap() diff --git a/rs/nns/integration_tests/src/uninstall_canister_by_proposal.rs b/rs/nns/integration_tests/src/uninstall_canister_by_proposal.rs index 2b1f98511a4..c629000968e 100644 --- a/rs/nns/integration_tests/src/uninstall_canister_by_proposal.rs +++ b/rs/nns/integration_tests/src/uninstall_canister_by_proposal.rs @@ -42,7 +42,7 @@ fn setup_state_machine_with_nns_canisters() -> StateMachine { #[test] fn uninstall_canister_by_proposal() { - let mut state_machine = setup_state_machine_with_nns_canisters(); + let state_machine = setup_state_machine_with_nns_canisters(); // Pick some installed nns canister for testing let canister_id = CanisterId::from_u64(LIFELINE_CANISTER_INDEX_IN_NNS_SUBNET); // Confirm that canister exists and has some code installed (module_hash is Some) @@ -64,7 +64,7 @@ fn uninstall_canister_by_proposal() { let n1 = get_neuron_1(); // Execute a proposal let response = - nns_governance_make_proposal(&mut state_machine, n1.principal_id, n1.neuron_id, &proposal) + nns_governance_make_proposal(&state_machine, n1.principal_id, n1.neuron_id, &proposal) .command .expect("Making NNS proposal failed"); let _proposal_id = match response { diff --git a/rs/nns/integration_tests/src/upgrade_canisters_with_golden_nns_state.rs b/rs/nns/integration_tests/src/upgrade_canisters_with_golden_nns_state.rs index 44ff42201a6..32e5b596b2e 100644 --- a/rs/nns/integration_tests/src/upgrade_canisters_with_golden_nns_state.rs +++ b/rs/nns/integration_tests/src/upgrade_canisters_with_golden_nns_state.rs @@ -146,12 +146,12 @@ fn test_upgrade_canisters_with_golden_nns_state() { // Step 1.1: Load golden nns state into a StateMachine. // TODO: Use PocketIc instead of StateMachine. - let mut state_machine = new_state_machine_with_golden_nns_state_or_panic(); + let state_machine = new_state_machine_with_golden_nns_state_or_panic(); // Step 1.2: Create a super powerful Neuron. println!("Creating super powerful Neuron."); let neuron_controller = PrincipalId::new_self_authenticating(&[1, 2, 3, 4]); - let neuron_id = nns_create_super_powerful_neuron(&mut state_machine, neuron_controller); + let neuron_id = nns_create_super_powerful_neuron(&state_machine, neuron_controller); println!("Done creating super powerful Neuron."); let mut repetition_number = 1; @@ -201,7 +201,7 @@ fn test_upgrade_canisters_with_golden_nns_state() { nns_canister_name, repetition_number, ); let _proposal_id = nns_propose_upgrade_nns_canister( - &mut state_machine, + &state_machine, neuron_controller, neuron_id, *canister_id, @@ -211,7 +211,7 @@ fn test_upgrade_canisters_with_golden_nns_state() { // Step 3: Verify result(s): In a short while, the canister should // be running the new code. wait_for_canister_upgrade_to_succeed( - &mut state_machine, + &state_machine, *canister_id, wasm_hash, nns_canister_upgrade.controller_principal_id(), diff --git a/rs/nns/test_utils/src/neuron_helpers.rs b/rs/nns/test_utils/src/neuron_helpers.rs index d4f93504c6f..3ef8544db49 100644 --- a/rs/nns/test_utils/src/neuron_helpers.rs +++ b/rs/nns/test_utils/src/neuron_helpers.rs @@ -4,10 +4,12 @@ use ic_nervous_system_common_test_keys::{ TEST_NEURON_1_OWNER_PRINCIPAL, TEST_NEURON_2_OWNER_PRINCIPAL, TEST_NEURON_3_OWNER_PRINCIPAL, }; use ic_nns_common::{pb::v1::NeuronId, types::ProposalId}; -use ic_nns_governance::init::{TEST_NEURON_1_ID, TEST_NEURON_2_ID, TEST_NEURON_3_ID}; -use ic_nns_governance::pb::v1::{ - manage_neuron_response::Command, proposal::Action, ExecuteNnsFunction, Neuron, NnsFunction, - Proposal, +use ic_nns_governance::{ + init::{TEST_NEURON_1_ID, TEST_NEURON_2_ID, TEST_NEURON_3_ID}, + pb::v1::{ + manage_neuron_response::Command, proposal::Action, ExecuteNnsFunction, Neuron, NnsFunction, + Proposal, + }, }; use ic_state_machine_tests::StateMachine; use std::collections::HashMap; @@ -77,7 +79,7 @@ pub fn get_some_proposal() -> Proposal { } } -pub fn submit_proposal(state_machine: &mut StateMachine, neuron: &TestNeuronOwner) -> ProposalId { +pub fn submit_proposal(state_machine: &StateMachine, neuron: &TestNeuronOwner) -> ProposalId { let proposal = get_some_proposal(); let response = nns_governance_make_proposal( state_machine, @@ -95,7 +97,7 @@ pub fn submit_proposal(state_machine: &mut StateMachine, neuron: &TestNeuronOwne } } -pub fn get_all_test_neurons(state_machine: &mut StateMachine) -> Vec { +pub fn get_all_test_neurons(state_machine: &StateMachine) -> Vec { let mut neurons = vec![]; // Get Test Neuron 1 @@ -110,9 +112,7 @@ pub fn get_all_test_neurons(state_machine: &mut StateMachine) -> Vec { neurons } -pub fn get_test_neurons_maturity_snapshot( - state_machine: &mut StateMachine, -) -> HashMap { +pub fn get_test_neurons_maturity_snapshot(state_machine: &StateMachine) -> HashMap { get_all_test_neurons(state_machine) .iter() .map(|neuron| (neuron.id.unwrap(), neuron.maturity_e8s_equivalent)) diff --git a/rs/nns/test_utils/src/state_test_helpers.rs b/rs/nns/test_utils/src/state_test_helpers.rs index 1a583efc70a..8c87099ef8f 100644 --- a/rs/nns/test_utils/src/state_test_helpers.rs +++ b/rs/nns/test_utils/src/state_test_helpers.rs @@ -268,7 +268,7 @@ pub fn query_with_sender( } pub fn scrape_metrics( - state_machine: &mut StateMachine, + state_machine: &StateMachine, canister_id: CanisterId, ) -> prometheus_parse::Scrape { let http_response = make_http_request( @@ -318,7 +318,7 @@ pub fn get_sample(scrape: &prometheus_parse::Scrape, name: &str) -> prometheus_p } pub fn make_http_request( - state_machine: &mut StateMachine, + state_machine: &StateMachine, canister_id: CanisterId, request: &HttpRequest, ) -> HttpResponse { @@ -691,7 +691,7 @@ pub fn setup_nns_canisters_with_features( setup_nns_sns_wasms_with_correct_canister_id(machine, init_payloads.sns_wasms); } -pub fn mint_icp(state_machine: &mut StateMachine, destination: AccountIdentifier, amount: Tokens) { +pub fn mint_icp(state_machine: &StateMachine, destination: AccountIdentifier, amount: Tokens) { // Construct request. let mut transfer_request = vec![]; SendArgs { @@ -727,7 +727,7 @@ pub fn mint_icp(state_machine: &mut StateMachine, destination: AccountIdentifier } pub fn nns_governance_get_full_neuron( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: PrincipalId, neuron_id: u64, ) -> Result { @@ -753,7 +753,7 @@ pub fn nns_governance_get_full_neuron( } pub fn nns_governance_get_neuron_info( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: PrincipalId, neuron_id: u64, ) -> Result { @@ -779,14 +779,14 @@ pub fn nns_governance_get_neuron_info( } pub fn nns_governance_get_proposal_info_as_anonymous( - state_machine: &mut StateMachine, + state_machine: &StateMachine, proposal_id: u64, ) -> ProposalInfo { nns_governance_get_proposal_info(state_machine, proposal_id, PrincipalId::new_anonymous()) } pub fn nns_governance_get_proposal_info( - state_machine: &mut StateMachine, + state_machine: &StateMachine, proposal_id: u64, sender: PrincipalId, ) -> ProposalInfo { @@ -842,7 +842,7 @@ pub fn nns_send_icp_to_claim_or_refresh_neuron( #[must_use] fn manage_neuron( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: PrincipalId, neuron_id: NeuronId, command: nns_governance_pb::manage_neuron::Command, @@ -890,7 +890,7 @@ impl NnsManageNeuronCommand for nns_governance_pb::manage_neuron::Configure { } fn nns_configure_neuron( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: PrincipalId, neuron_id: NeuronId, operation: nns_governance_pb::manage_neuron::configure::Operation, @@ -921,7 +921,7 @@ fn nns_configure_neuron( #[must_use] pub fn nns_create_super_powerful_neuron( - state_machine: &mut StateMachine, + state_machine: &StateMachine, controller: PrincipalId, ) -> NeuronId { let memo = 0xCAFE_F00D; @@ -956,7 +956,7 @@ pub fn nns_create_super_powerful_neuron( #[must_use] pub fn nns_claim_or_refresh_neuron( - state_machine: &mut StateMachine, + state_machine: &StateMachine, controller: PrincipalId, memo: u64, ) -> NeuronId { @@ -999,7 +999,7 @@ pub fn nns_claim_or_refresh_neuron( } pub fn nns_increase_dissolve_delay( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: PrincipalId, neuron_id: NeuronId, additional_dissolve_delay_seconds: u64, @@ -1023,7 +1023,7 @@ pub fn nns_increase_dissolve_delay( #[must_use] pub fn nns_propose_upgrade_nns_canister( - state_machine: &mut StateMachine, + state_machine: &StateMachine, neuron_controller: PrincipalId, proposer_neuron_id: NeuronId, target_canister_id: CanisterId, @@ -1101,7 +1101,7 @@ fn slice_to_hex(slice: &[u8]) -> String { } pub fn wait_for_canister_upgrade_to_succeed( - state_machine: &mut StateMachine, + state_machine: &StateMachine, canister_id: CanisterId, new_wasm_hash: &[u8; 32], // For most NNS canisters, ROOT_CANISTER_ID would be passed here (modulo conversion). @@ -1166,7 +1166,7 @@ pub fn wait_for_canister_upgrade_to_succeed( } pub fn nns_cast_vote( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: PrincipalId, neuron_id: NeuronId, proposal_id: u64, @@ -1181,7 +1181,7 @@ pub fn nns_cast_vote( } pub fn nns_split_neuron( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: PrincipalId, neuron_id: NeuronId, amount: u64, @@ -1191,7 +1191,7 @@ pub fn nns_split_neuron( manage_neuron(state_machine, sender, neuron_id, command) } -pub fn get_neuron_ids(state_machine: &mut StateMachine, sender: PrincipalId) -> Vec { +pub fn get_neuron_ids(state_machine: &StateMachine, sender: PrincipalId) -> Vec { let result = state_machine .execute_ingress_as( sender, @@ -1208,7 +1208,7 @@ pub fn get_neuron_ids(state_machine: &mut StateMachine, sender: PrincipalId) -> Decode!(&result, Vec).unwrap() } -pub fn get_pending_proposals(state_machine: &mut StateMachine) -> Vec { +pub fn get_pending_proposals(state_machine: &StateMachine) -> Vec { let result = state_machine .execute_ingress( GOVERNANCE_CANISTER_ID, @@ -1225,7 +1225,7 @@ pub fn get_pending_proposals(state_machine: &mut StateMachine) -> Vec ManageNeuronResponse { @@ -1237,7 +1237,7 @@ pub fn nns_join_community_fund( } pub fn nns_leave_community_fund( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: PrincipalId, neuron_id: NeuronId, ) -> ManageNeuronResponse { @@ -1249,7 +1249,7 @@ pub fn nns_leave_community_fund( } pub fn nns_governance_make_proposal( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: PrincipalId, neuron_id: NeuronId, proposal: &Proposal, @@ -1260,7 +1260,7 @@ pub fn nns_governance_make_proposal( } pub fn nns_add_hot_key( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: PrincipalId, neuron_id: NeuronId, new_hot_key: PrincipalId, @@ -1275,7 +1275,7 @@ pub fn nns_add_hot_key( } pub fn nns_set_followees_for_neuron( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: PrincipalId, neuron_id: NeuronId, followees: &[NeuronId], @@ -1293,7 +1293,7 @@ pub fn nns_set_followees_for_neuron( } pub fn nns_remove_hot_key( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: PrincipalId, neuron_id: NeuronId, hot_key_to_remove: PrincipalId, @@ -1308,7 +1308,7 @@ pub fn nns_remove_hot_key( } pub fn nns_stake_maturity( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sender: PrincipalId, neuron_id: NeuronId, percentage_to_stake: Option, @@ -1320,7 +1320,7 @@ pub fn nns_stake_maturity( manage_neuron(state_machine, sender, neuron_id, command) } -pub fn nns_get_migrations(state_machine: &mut StateMachine) -> Migrations { +pub fn nns_get_migrations(state_machine: &StateMachine) -> Migrations { let reply = query( state_machine, GOVERNANCE_CANISTER_ID, @@ -1332,7 +1332,7 @@ pub fn nns_get_migrations(state_machine: &mut StateMachine) -> Migrations { Decode!(&reply, Migrations).unwrap() } -pub fn nns_list_proposals(state_machine: &mut StateMachine) -> ListProposalInfoResponse { +pub fn nns_list_proposals(state_machine: &StateMachine) -> ListProposalInfoResponse { let result = state_machine .execute_ingress( GOVERNANCE_CANISTER_ID, @@ -1351,7 +1351,7 @@ pub fn nns_list_proposals(state_machine: &mut StateMachine) -> ListProposalInfoR /// Return the monthly Node Provider rewards pub fn nns_get_monthly_node_provider_rewards( - state_machine: &mut StateMachine, + state_machine: &StateMachine, ) -> Result { let result = state_machine .execute_ingress( @@ -1373,7 +1373,7 @@ pub fn nns_get_monthly_node_provider_rewards( /// Return the most recent monthly Node Provider rewards pub fn nns_get_most_recent_monthly_node_provider_rewards( - state_machine: &mut StateMachine, + state_machine: &StateMachine, ) -> Option { let result = state_machine .execute_ingress( @@ -1396,7 +1396,7 @@ pub fn nns_get_most_recent_monthly_node_provider_rewards( Decode!(&result, Option).unwrap() } -pub fn nns_get_network_economics_parameters(state_machine: &mut StateMachine) -> NetworkEconomics { +pub fn nns_get_network_economics_parameters(state_machine: &StateMachine) -> NetworkEconomics { let result = state_machine .execute_ingress( GOVERNANCE_CANISTER_ID, @@ -1415,7 +1415,7 @@ pub fn nns_get_network_economics_parameters(state_machine: &mut StateMachine) -> Decode!(&result, NetworkEconomics).unwrap() } -pub fn list_deployed_snses(state_machine: &mut StateMachine) -> ListDeployedSnsesResponse { +pub fn list_deployed_snses(state_machine: &StateMachine) -> ListDeployedSnsesResponse { let result = state_machine .execute_ingress( SNS_WASM_CANISTER_ID, @@ -1432,7 +1432,7 @@ pub fn list_deployed_snses(state_machine: &mut StateMachine) -> ListDeployedSnse Decode!(&result, ListDeployedSnsesResponse).unwrap() } -pub fn list_neurons(state_machine: &mut StateMachine, sender: PrincipalId) -> ListNeuronsResponse { +pub fn list_neurons(state_machine: &StateMachine, sender: PrincipalId) -> ListNeuronsResponse { let result = state_machine .execute_ingress_as( sender, @@ -1456,7 +1456,7 @@ pub fn list_neurons(state_machine: &mut StateMachine, sender: PrincipalId) -> Li /// Returns when the proposal has been executed. A proposal is considered to be /// executed when executed_timestamp_seconds > 0. -pub fn nns_wait_for_proposal_execution(machine: &mut StateMachine, proposal_id: u64) { +pub fn nns_wait_for_proposal_execution(machine: &StateMachine, proposal_id: u64) { // We create some blocks until the proposal has finished executing (machine.tick()) let mut attempt_count = 0; let mut last_proposal = None; @@ -1486,7 +1486,7 @@ pub fn nns_wait_for_proposal_execution(machine: &mut StateMachine, proposal_id: /// Returns when the proposal has failed execution. A proposal is considered to be /// executed when failed_timestamp_seconds > 0. -pub fn nns_wait_for_proposal_failure(machine: &mut StateMachine, proposal_id: u64) { +pub fn nns_wait_for_proposal_failure(machine: &StateMachine, proposal_id: u64) { // We create some blocks until the proposal has finished failing (machine.tick()) let mut last_proposal = None; for _ in 0..50 { @@ -1542,7 +1542,7 @@ pub fn sns_stake_neuron( } pub fn ledger_account_balance( - state_machine: &mut StateMachine, + state_machine: &StateMachine, ledger_canister_id: CanisterId, request: &BinaryAccountBalanceArgs, ) -> Tokens { @@ -1772,7 +1772,7 @@ pub fn sns_make_proposal( /// Call the get_mode method. pub fn sns_governance_get_mode( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sns_governance_canister_id: CanisterId, ) -> Result { let get_mode_response = query( @@ -1927,7 +1927,7 @@ pub fn get_icp_xdr_conversion_rate( } pub fn cmc_set_default_authorized_subnetworks( - machine: &mut StateMachine, + machine: &StateMachine, subnets: Vec, sender: PrincipalId, neuron_id: NeuronId, diff --git a/rs/sns/integration_tests/src/initialization_flow.rs b/rs/sns/integration_tests/src/initialization_flow.rs index de736ebf1af..4e9f51b74af 100644 --- a/rs/sns/integration_tests/src/initialization_flow.rs +++ b/rs/sns/integration_tests/src/initialization_flow.rs @@ -1,7 +1,6 @@ use candid::Nat; use ic_base_types::{CanisterId, PrincipalId}; -use ic_nervous_system_common::ONE_DAY_SECONDS; -use ic_nervous_system_common::{ExplosiveTokens, E8, ONE_TRILLION}; +use ic_nervous_system_common::{ExplosiveTokens, E8, ONE_DAY_SECONDS, ONE_TRILLION}; use ic_nervous_system_common_test_keys::TEST_NEURON_1_OWNER_PRINCIPAL; use ic_nervous_system_proto::pb::v1::{ Canister, Duration, GlobalTimeOfDay, Image, Percentage, Tokens, @@ -247,7 +246,7 @@ impl SnsInitializationFlowTestSetup { }; let response = - nns_governance_make_proposal(&mut self.state_machine, sender, neuron_id, &proposal); + nns_governance_make_proposal(&self.state_machine, sender, neuron_id, &proposal); match response.command { Some(manage_neuron_response::Command::MakeProposal(make_proposal_response)) => { @@ -313,7 +312,7 @@ fn test_one_proposal_sns_initialization_success_with_neurons_fund_participation( let mut sns_initialization_flow_test = SnsInitializationFlowTestSetup::default_setup(); let initial_nns_neurons_maturity_snapshot = - get_test_neurons_maturity_snapshot(&mut sns_initialization_flow_test.state_machine); + get_test_neurons_maturity_snapshot(&sns_initialization_flow_test.state_machine); let initial_sns_wasm_cycles_balance = get_canister_status_from_root( &sns_initialization_flow_test.state_machine, @@ -323,7 +322,7 @@ fn test_one_proposal_sns_initialization_success_with_neurons_fund_participation( // There should be no SNSes deployed. assert_eq!( - list_deployed_snses(&mut sns_initialization_flow_test.state_machine).instances, + list_deployed_snses(&sns_initialization_flow_test.state_machine).instances, vec![] ); @@ -347,15 +346,12 @@ fn test_one_proposal_sns_initialization_success_with_neurons_fund_participation( ); // Wait for the proposal to be executed, and therefore the SNS to be deployed - nns_wait_for_proposal_execution( - &mut sns_initialization_flow_test.state_machine, - proposal_id.id, - ); + nns_wait_for_proposal_execution(&sns_initialization_flow_test.state_machine, proposal_id.id); // Step 2: Inspect the newly created SNS // Assert the SNS was created and get its info - let snses = list_deployed_snses(&mut sns_initialization_flow_test.state_machine).instances; + let snses = list_deployed_snses(&sns_initialization_flow_test.state_machine).instances; assert_eq!(snses.len(), 1); let test_sns = snses.first().unwrap(); @@ -420,7 +416,7 @@ fn test_one_proposal_sns_initialization_success_with_neurons_fund_participation( // Assert the sns governance canister should be in PreInitializationSwap mode let sns_governance_mode = sns_governance_get_mode( - &mut sns_initialization_flow_test.state_machine, + &sns_initialization_flow_test.state_machine, canister_id_or_panic(test_sns.governance_canister_id), ) .unwrap(); @@ -429,7 +425,7 @@ fn test_one_proposal_sns_initialization_success_with_neurons_fund_participation( // Assert that the maturity was decremented from the NNS Neurons and properly recorded // in the swap canister. let current_nns_neurons_maturity_snapshot = - get_test_neurons_maturity_snapshot(&mut sns_initialization_flow_test.state_machine); + get_test_neurons_maturity_snapshot(&sns_initialization_flow_test.state_machine); let cf_participants = list_community_fund_participants( &sns_initialization_flow_test.state_machine, @@ -473,7 +469,7 @@ fn test_one_proposal_sns_initialization_success_with_neurons_fund_participation( let participant = sns_initialization_flow_test.funded_principals[i]; let response = participate_in_swap( - &mut sns_initialization_flow_test.state_machine, + &sns_initialization_flow_test.state_machine, canister_id_or_panic(test_sns.swap_canister_id), participant, ExplosiveTokens::from_e8s(direct_participant_amount_e8s), @@ -499,7 +495,7 @@ fn test_one_proposal_sns_initialization_success_with_neurons_fund_participation( // SNS Governance should now be in normal mode let sns_governance_mode = sns_governance_get_mode( - &mut sns_initialization_flow_test.state_machine, + &sns_initialization_flow_test.state_machine, canister_id_or_panic(test_sns.governance_canister_id), ) .unwrap(); @@ -570,7 +566,7 @@ fn test_one_proposal_sns_initialization_success_with_neurons_fund_participation( .map(|cf_participant| cf_participant.hotkey_principal.clone()) .collect::>(); let neurons = sns_governance_list_neurons( - &mut sns_initialization_flow_test.state_machine, + &sns_initialization_flow_test.state_machine, canister_id_or_panic(test_sns.governance_canister_id), &ListNeurons::default(), ) @@ -598,7 +594,7 @@ fn test_one_proposal_sns_initialization_success_without_neurons_fund_participati let mut sns_initialization_flow_test = SnsInitializationFlowTestSetup::default_setup(); let initial_nns_neurons_maturity_snapshot = - get_test_neurons_maturity_snapshot(&mut sns_initialization_flow_test.state_machine); + get_test_neurons_maturity_snapshot(&sns_initialization_flow_test.state_machine); let initial_sns_wasm_cycles_balance = get_canister_status_from_root( &sns_initialization_flow_test.state_machine, @@ -608,7 +604,7 @@ fn test_one_proposal_sns_initialization_success_without_neurons_fund_participati // There should be no SNSes deployed. assert_eq!( - list_deployed_snses(&mut sns_initialization_flow_test.state_machine).instances, + list_deployed_snses(&sns_initialization_flow_test.state_machine).instances, vec![] ); @@ -648,15 +644,12 @@ fn test_one_proposal_sns_initialization_success_without_neurons_fund_participati ); // Wait for the proposal to be executed, and therefore the SNS to be deployed - nns_wait_for_proposal_execution( - &mut sns_initialization_flow_test.state_machine, - proposal_id.id, - ); + nns_wait_for_proposal_execution(&sns_initialization_flow_test.state_machine, proposal_id.id); // Step 2: Inspect the newly created SNS // Assert the SNS was created and get its info - let snses = list_deployed_snses(&mut sns_initialization_flow_test.state_machine).instances; + let snses = list_deployed_snses(&sns_initialization_flow_test.state_machine).instances; assert_eq!(snses.len(), 1); let test_sns = snses.first().unwrap(); @@ -673,7 +666,7 @@ fn test_one_proposal_sns_initialization_success_without_neurons_fund_participati // Assert that the cf neurons have not had their maturity decremented. let post_execution_nns_neurons_maturity_snapshot = - get_test_neurons_maturity_snapshot(&mut sns_initialization_flow_test.state_machine); + get_test_neurons_maturity_snapshot(&sns_initialization_flow_test.state_machine); assert_eq!( initial_nns_neurons_maturity_snapshot, post_execution_nns_neurons_maturity_snapshot @@ -729,7 +722,7 @@ fn test_one_proposal_sns_initialization_success_without_neurons_fund_participati // Assert the sns governance canister should be in PreInitializationSwap mode let sns_governance_mode = sns_governance_get_mode( - &mut sns_initialization_flow_test.state_machine, + &sns_initialization_flow_test.state_machine, canister_id_or_panic(test_sns.governance_canister_id), ) .unwrap(); @@ -773,7 +766,7 @@ fn test_one_proposal_sns_initialization_success_without_neurons_fund_participati let participant = sns_initialization_flow_test.funded_principals[i]; let response = participate_in_swap( - &mut sns_initialization_flow_test.state_machine, + &sns_initialization_flow_test.state_machine, canister_id_or_panic(test_sns.swap_canister_id), participant, ExplosiveTokens::from_e8s(direct_participant_amount_e8s), @@ -799,7 +792,7 @@ fn test_one_proposal_sns_initialization_success_without_neurons_fund_participati // SNS Governance should now be in normal mode let sns_governance_mode = sns_governance_get_mode( - &mut sns_initialization_flow_test.state_machine, + &sns_initialization_flow_test.state_machine, canister_id_or_panic(test_sns.governance_canister_id), ) .unwrap(); @@ -831,7 +824,7 @@ fn test_one_proposal_sns_initialization_fails_to_initialize_and_returns_dapps_an let mut sns_initialization_flow_test = SnsInitializationFlowTestSetup::default_setup(); let initial_nns_neurons_maturity_snapshot = - get_test_neurons_maturity_snapshot(&mut sns_initialization_flow_test.state_machine); + get_test_neurons_maturity_snapshot(&sns_initialization_flow_test.state_machine); let initial_sns_wasm_cycles_balance = get_canister_status_from_root( &sns_initialization_flow_test.state_machine, @@ -841,7 +834,7 @@ fn test_one_proposal_sns_initialization_fails_to_initialize_and_returns_dapps_an // There should be no SNSes deployed. assert_eq!( - list_deployed_snses(&mut sns_initialization_flow_test.state_machine).instances, + list_deployed_snses(&sns_initialization_flow_test.state_machine).instances, vec![] ); @@ -886,20 +879,17 @@ fn test_one_proposal_sns_initialization_fails_to_initialize_and_returns_dapps_an ); // Wait for the proposal to fail due to SNS deployment failure - nns_wait_for_proposal_failure( - &mut sns_initialization_flow_test.state_machine, - proposal_id.id, - ); + nns_wait_for_proposal_failure(&sns_initialization_flow_test.state_machine, proposal_id.id); // Step 2: Inspect the system // Assert that no SNS was created - let snses = list_deployed_snses(&mut sns_initialization_flow_test.state_machine).instances; + let snses = list_deployed_snses(&sns_initialization_flow_test.state_machine).instances; assert_eq!(snses.len(), 0); // Assert that the cf neurons have not had their maturity refunded. let post_execution_nns_neurons_maturity_snapshot = - get_test_neurons_maturity_snapshot(&mut sns_initialization_flow_test.state_machine); + get_test_neurons_maturity_snapshot(&sns_initialization_flow_test.state_machine); assert_eq!( initial_nns_neurons_maturity_snapshot, post_execution_nns_neurons_maturity_snapshot @@ -940,7 +930,7 @@ fn test_one_proposal_sns_initialization_failed_swap_returns_neurons_fund_and_dap let mut sns_initialization_flow_test = SnsInitializationFlowTestSetup::default_setup(); let initial_nns_neurons_maturity_snapshot = - get_test_neurons_maturity_snapshot(&mut sns_initialization_flow_test.state_machine); + get_test_neurons_maturity_snapshot(&sns_initialization_flow_test.state_machine); let initial_sns_wasm_cycles_balance = get_canister_status_from_root( &sns_initialization_flow_test.state_machine, @@ -950,7 +940,7 @@ fn test_one_proposal_sns_initialization_failed_swap_returns_neurons_fund_and_dap // There should be no SNSes deployed. assert_eq!( - list_deployed_snses(&mut sns_initialization_flow_test.state_machine).instances, + list_deployed_snses(&sns_initialization_flow_test.state_machine).instances, vec![] ); @@ -974,15 +964,12 @@ fn test_one_proposal_sns_initialization_failed_swap_returns_neurons_fund_and_dap ); // Wait for the proposal to be executed, and therefore the SNS to be deployed - nns_wait_for_proposal_execution( - &mut sns_initialization_flow_test.state_machine, - proposal_id.id, - ); + nns_wait_for_proposal_execution(&sns_initialization_flow_test.state_machine, proposal_id.id); // Step 2: Inspect the newly created SNS // Assert the SNS was created and get its info - let snses = list_deployed_snses(&mut sns_initialization_flow_test.state_machine).instances; + let snses = list_deployed_snses(&sns_initialization_flow_test.state_machine).instances; assert_eq!(snses.len(), 1); let test_sns = snses.first().unwrap(); @@ -1047,7 +1034,7 @@ fn test_one_proposal_sns_initialization_failed_swap_returns_neurons_fund_and_dap // Assert the sns governance canister should be in PreInitializationSwap mode let sns_governance_mode = sns_governance_get_mode( - &mut sns_initialization_flow_test.state_machine, + &sns_initialization_flow_test.state_machine, canister_id_or_panic(test_sns.governance_canister_id), ) .unwrap(); @@ -1056,7 +1043,7 @@ fn test_one_proposal_sns_initialization_failed_swap_returns_neurons_fund_and_dap // Assert that the maturity was decremented from the NNS Neurons and properly recorded // in the swap canister. let current_nns_neurons_maturity_snapshot = - get_test_neurons_maturity_snapshot(&mut sns_initialization_flow_test.state_machine); + get_test_neurons_maturity_snapshot(&sns_initialization_flow_test.state_machine); let cf_participants = list_community_fund_participants( &sns_initialization_flow_test.state_machine, @@ -1105,7 +1092,7 @@ fn test_one_proposal_sns_initialization_failed_swap_returns_neurons_fund_and_dap let participant = sns_initialization_flow_test.funded_principals[i]; let response = participate_in_swap( - &mut sns_initialization_flow_test.state_machine, + &sns_initialization_flow_test.state_machine, canister_id_or_panic(test_sns.swap_canister_id), participant, ExplosiveTokens::from_e8s(direct_participant_amount_e8s), @@ -1128,7 +1115,7 @@ fn test_one_proposal_sns_initialization_failed_swap_returns_neurons_fund_and_dap // SNS Governance should now be in normal mode let sns_governance_mode = sns_governance_get_mode( - &mut sns_initialization_flow_test.state_machine, + &sns_initialization_flow_test.state_machine, canister_id_or_panic(test_sns.governance_canister_id), ) .unwrap(); @@ -1143,7 +1130,7 @@ fn test_one_proposal_sns_initialization_failed_swap_returns_neurons_fund_and_dap // Assert that the maturity was refunded to the NNS Neurons. let current_nns_neurons_maturity_snapshot = - get_test_neurons_maturity_snapshot(&mut sns_initialization_flow_test.state_machine); + get_test_neurons_maturity_snapshot(&sns_initialization_flow_test.state_machine); assert_eq!( initial_nns_neurons_maturity_snapshot, @@ -1173,7 +1160,7 @@ fn test_one_proposal_sns_initialization_supports_multiple_open_swaps() { // There should be no SNSes deployed. assert_eq!( - list_deployed_snses(&mut sns_initialization_flow_test.state_machine).instances, + list_deployed_snses(&sns_initialization_flow_test.state_machine).instances, vec![] ); @@ -1188,15 +1175,12 @@ fn test_one_proposal_sns_initialization_supports_multiple_open_swaps() { ); // Wait for the proposal to be executed, and therefore the SNS to be deployed - nns_wait_for_proposal_execution( - &mut sns_initialization_flow_test.state_machine, - proposal_id.id, - ); + nns_wait_for_proposal_execution(&sns_initialization_flow_test.state_machine, proposal_id.id); // Step 2: Inspect the newly created SNS // Assert the SNS was created and get its info - let snses = list_deployed_snses(&mut sns_initialization_flow_test.state_machine).instances; + let snses = list_deployed_snses(&sns_initialization_flow_test.state_machine).instances; assert_eq!(snses.len(), 1); let test_sns_1 = snses.first().unwrap(); @@ -1230,7 +1214,7 @@ fn test_one_proposal_sns_initialization_supports_multiple_open_swaps() { // Assert that you can participate in the first Swap, but do not let it commit let participant = sns_initialization_flow_test.funded_principals[0]; let response = participate_in_swap( - &mut sns_initialization_flow_test.state_machine, + &sns_initialization_flow_test.state_machine, canister_id_or_panic(test_sns_1.swap_canister_id), participant, ExplosiveTokens::from_e8s(E8), @@ -1247,15 +1231,12 @@ fn test_one_proposal_sns_initialization_supports_multiple_open_swaps() { ); // Wait for the proposal to be executed, and therefore the SNS to be deployed - nns_wait_for_proposal_execution( - &mut sns_initialization_flow_test.state_machine, - proposal_id.id, - ); + nns_wait_for_proposal_execution(&sns_initialization_flow_test.state_machine, proposal_id.id); // Step 4: Inspect the second SNS // Assert the SNS was created and get its info - let snses = list_deployed_snses(&mut sns_initialization_flow_test.state_machine).instances; + let snses = list_deployed_snses(&sns_initialization_flow_test.state_machine).instances; assert_eq!(snses.len(), 2); let test_sns_2 = snses.last().unwrap(); @@ -1289,7 +1270,7 @@ fn test_one_proposal_sns_initialization_supports_multiple_open_swaps() { // Assert that you can participate in the second Swap let participant = sns_initialization_flow_test.funded_principals[0]; let response = participate_in_swap( - &mut sns_initialization_flow_test.state_machine, + &sns_initialization_flow_test.state_machine, canister_id_or_panic(test_sns_2.swap_canister_id), participant, ExplosiveTokens::from_e8s(E8), diff --git a/rs/sns/integration_tests/src/sns_treasury.rs b/rs/sns/integration_tests/src/sns_treasury.rs index 56f78496dda..2511b59fe98 100644 --- a/rs/sns/integration_tests/src/sns_treasury.rs +++ b/rs/sns/integration_tests/src/sns_treasury.rs @@ -113,7 +113,7 @@ lazy_static! { /// /// The swap establishes that 1 SNS token is worth slightly less than 1 ICP. fn new_treasury_scenario( - state_machine: &mut StateMachine, + state_machine: &StateMachine, ) -> (/* whale */ SnsNeuronId, SnsTestCanisterIds) { let start_time = SystemTime::UNIX_EPOCH .checked_add(Duration::from_secs(START_TIMESTAMP_SECONDS)) @@ -282,9 +282,9 @@ fn test_sns_treasury_can_transfer_funds_via_proposals() { // Step 1: Prepare the world. state_test_helpers::reduce_state_machine_logging_unless_env_set(); - let mut state_machine = state_machine_builder_for_sns_tests().build(); + let state_machine = state_machine_builder_for_sns_tests().build(); - let (whale_neuron_id, sns_test_canister_ids) = new_treasury_scenario(&mut state_machine); + let (whale_neuron_id, sns_test_canister_ids) = new_treasury_scenario(&state_machine); let SnsTestCanisterIds { governance_canister_id, @@ -519,9 +519,9 @@ fn test_transfer_sns_treasury_funds_proposals_that_are_too_big_get_blocked_at_su // tokens that proposals can transfer from the treasury. state_test_helpers::reduce_state_machine_logging_unless_env_set(); - let mut state_machine = state_machine_builder_for_sns_tests().build(); + let state_machine = state_machine_builder_for_sns_tests().build(); - let (whale_neuron_id, sns_test_canister_ids) = new_treasury_scenario(&mut state_machine); + let (whale_neuron_id, sns_test_canister_ids) = new_treasury_scenario(&state_machine); let SnsTestCanisterIds { governance_canister_id, @@ -690,9 +690,9 @@ fn test_transfer_sns_treasury_funds_upper_bound_is_enforced_at_execution() { // Step 1: Prepare the world. state_test_helpers::reduce_state_machine_logging_unless_env_set(); - let mut state_machine = state_machine_builder_for_sns_tests().build(); + let state_machine = state_machine_builder_for_sns_tests().build(); - let (whale_neuron_id, sns_test_canister_ids) = new_treasury_scenario(&mut state_machine); + let (whale_neuron_id, sns_test_canister_ids) = new_treasury_scenario(&state_machine); let SnsTestCanisterIds { governance_canister_id, @@ -780,7 +780,7 @@ fn test_transfer_sns_treasury_funds_upper_bound_is_enforced_at_execution() { // Make the second proposal pass. sns_cast_vote( - &mut state_machine, + &state_machine, governance_canister_id, *COUNTERWEIGHT, counterweight_neuron_id.clone(), @@ -791,7 +791,7 @@ fn test_transfer_sns_treasury_funds_upper_bound_is_enforced_at_execution() { // Make the first proposal pass. sns_cast_vote( - &mut state_machine, + &state_machine, governance_canister_id, *COUNTERWEIGHT, counterweight_neuron_id, @@ -857,9 +857,9 @@ fn sns_can_mint_funds_via_proposals() { // Step 1: Prepare the world. state_test_helpers::reduce_state_machine_logging_unless_env_set(); - let mut state_machine = state_machine_builder_for_sns_tests().build(); + let state_machine = state_machine_builder_for_sns_tests().build(); - let (whale_neuron_id, sns_test_canister_ids) = new_treasury_scenario(&mut state_machine); + let (whale_neuron_id, sns_test_canister_ids) = new_treasury_scenario(&state_machine); let SnsTestCanisterIds { governance_canister_id, diff --git a/rs/sns/test_utils/src/state_test_helpers.rs b/rs/sns/test_utils/src/state_test_helpers.rs index 68c7772ca03..ae97ef2b67f 100644 --- a/rs/sns/test_utils/src/state_test_helpers.rs +++ b/rs/sns/test_utils/src/state_test_helpers.rs @@ -181,7 +181,7 @@ pub fn setup_sns_canisters( } pub fn sns_governance_list_neurons( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sns_governance_canister_id: CanisterId, request: &ListNeurons, ) -> ListNeuronsResponse { @@ -205,7 +205,7 @@ pub fn sns_governance_list_neurons( } pub fn sns_governance_get_nervous_system_parameters( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sns_governance_canister_id: CanisterId, ) -> NervousSystemParameters { let result = state_machine @@ -229,7 +229,7 @@ pub fn sns_governance_get_nervous_system_parameters( #[must_use] fn manage_neuron( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sns_governance_canister_id: CanisterId, sender: PrincipalId, neuron_id: NeuronId, @@ -257,7 +257,7 @@ fn manage_neuron( } pub fn sns_cast_vote( - state_machine: &mut StateMachine, + state_machine: &StateMachine, sns_governance_canister_id: CanisterId, sender: PrincipalId, neuron_id: NeuronId, @@ -279,7 +279,7 @@ pub fn sns_cast_vote( } pub fn participate_in_swap( - state_machine: &mut StateMachine, + state_machine: &StateMachine, swap_canister_id: CanisterId, participant_principal_id: PrincipalId, amount: ExplosiveTokens, @@ -361,7 +361,7 @@ pub fn init_canister( } pub fn send_participation_funds( - state_machine: &mut StateMachine, + state_machine: &StateMachine, swap_canister_id: CanisterId, participant_principal_id: PrincipalId, amount: ExplosiveTokens, @@ -400,7 +400,7 @@ pub fn send_participation_funds( } pub fn swap_get_state( - state_machine: &mut StateMachine, + state_machine: &StateMachine, swap_canister_id: CanisterId, request: &swap_pb::GetStateRequest, ) -> swap_pb::GetStateResponse {