Skip to content

Commit

Permalink
chore(nns/sns): remove unnecessary mut from test functions
Browse files Browse the repository at this point in the history
  • Loading branch information
max-dfinity committed Jun 4, 2024
1 parent d389f84 commit c680ce8
Show file tree
Hide file tree
Showing 21 changed files with 358 additions and 393 deletions.
4 changes: 2 additions & 2 deletions rs/nns/integration_tests/src/canister_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);

Expand Down
20 changes: 10 additions & 10 deletions rs/nns/integration_tests/src/create_service_nervous_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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),
Expand All @@ -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!(
Expand All @@ -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),
Expand All @@ -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(
Expand Down Expand Up @@ -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,
};
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions rs/nns/integration_tests/src/cycles_minting_canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UpdateIcpXdrConversionRatePayloadReason>,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand All @@ -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!(
Expand All @@ -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!(
Expand Down
6 changes: 3 additions & 3 deletions rs/nns/integration_tests/src/governance_migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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],
Expand All @@ -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,
Expand Down
Loading

0 comments on commit c680ce8

Please sign in to comment.