diff --git a/Cargo.lock b/Cargo.lock index 6614a06b2ad5..9c5f35b25cbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9632,6 +9632,7 @@ dependencies = [ "ic-nns-common", "ic-nns-constants", "ic-nns-governance-api", + "ic-nns-governance-init", "ic-nns-governance-protobuf-generator", "ic-nns-gtc-accounts", "ic-protobuf", @@ -9694,6 +9695,22 @@ dependencies = [ "strum_macros 0.26.2", ] +[[package]] +name = "ic-nns-governance-init" +version = "0.9.0" +dependencies = [ + "csv", + "ic-base-types", + "ic-nervous-system-common", + "ic-nervous-system-common-build-metadata", + "ic-nervous-system-common-test-keys", + "ic-nns-common", + "ic-nns-governance-api", + "icp-ledger", + "rand 0.8.5", + "rand_chacha 0.3.1", +] + [[package]] name = "ic-nns-governance-protobuf-generator" version = "0.9.0" @@ -9843,7 +9860,7 @@ dependencies = [ "ic-interfaces-registry", "ic-nns-common", "ic-nns-constants", - "ic-nns-governance", + "ic-nns-governance-api", "ic-nns-test-utils", "ic-registry-local-store", "ic-registry-proto-data-provider", @@ -9914,6 +9931,7 @@ dependencies = [ "ic-nns-common", "ic-nns-constants", "ic-nns-governance", + "ic-nns-governance-init", "ic-nns-gtc", "ic-nns-handler-root", "ic-nns-test-utils", @@ -9989,6 +10007,7 @@ dependencies = [ "ic-nns-common", "ic-nns-constants", "ic-nns-governance", + "ic-nns-governance-init", "ic-nns-gtc", "ic-nns-gtc-accounts", "ic-nns-handler-lifeline-interface", diff --git a/Cargo.toml b/Cargo.toml index cce186dedece..4299ec1c0e1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -185,6 +185,8 @@ members = [ "rs/nns/common/protobuf_generator", "rs/nns/cmc", "rs/nns/governance", + "rs/nns/governance/api", + "rs/nns/governance/init", "rs/nns/governance/protobuf_generator", "rs/nns/handlers/lifeline/impl", "rs/nns/handlers/lifeline/interface", diff --git a/rs/nns/governance/BUILD.bazel b/rs/nns/governance/BUILD.bazel index 27315d1294b1..2ce926192b43 100644 --- a/rs/nns/governance/BUILD.bazel +++ b/rs/nns/governance/BUILD.bazel @@ -79,6 +79,7 @@ DEPENDENCIES = BASE_DEPENDENCIES + [ "//rs/nns/governance/api", "//rs/nns/sns-wasm", "//rs/sns/init", + "//rs/nns/governance/init", "//rs/sns/swap", ] @@ -88,6 +89,7 @@ DEPENDENCIES_WITH_TEST_FEATURES = BASE_DEPENDENCIES + [ "//rs/nns/sns-wasm:sns-wasm--test_feature", "//rs/sns/init:init--test_feature", "//rs/sns/swap:swap--test_feature", + "//rs/nns/governance/init:init--test_feature", ] MACRO_DEPENDENCIES = [ diff --git a/rs/nns/governance/Cargo.toml b/rs/nns/governance/Cargo.toml index 28bc816a0a0c..d9c120248dd1 100644 --- a/rs/nns/governance/Cargo.toml +++ b/rs/nns/governance/Cargo.toml @@ -55,6 +55,7 @@ ic-nns-common = { path = "../common" } ic-nns-constants = { path = "../constants" } ic-nns-gtc-accounts = { path = "../gtc_accounts" } ic-nns-governance-api = { path = "./api" } +ic-nns-governance-init = { path = "./init" } ic-protobuf = { path = "../../protobuf" } ic-sns-init = { path = "../../sns/init" } # This is just for a couple of PB definitions. ic-sns-root = { path = "../../sns/root" } # This is just for a couple of PB definitions. diff --git a/rs/nns/governance/api/src/pb.rs b/rs/nns/governance/api/src/pb.rs index 3d3105e057ff..d6387ddf9763 100644 --- a/rs/nns/governance/api/src/pb.rs +++ b/rs/nns/governance/api/src/pb.rs @@ -1,9 +1,19 @@ -use crate::pb::v1::{governance_error::ErrorType, GovernanceError}; +use crate::pb::v1::{ + governance_error::ErrorType, GovernanceError, NetworkEconomics, NeuronsFundEconomics, + NeuronsFundMatchedFundingCurveCoefficients, XdrConversionRate, +}; +use ic_nervous_system_proto::pb::v1::{Decimal, Percentage}; +use icp_ledger::{DEFAULT_TRANSFER_FEE, TOKEN_SUBDIVIDABLE_BY}; #[allow(clippy::all)] #[path = "./ic_nns_governance.pb.v1.rs"] pub mod v1; +/// The number of e8s per ICP; +const E8S_PER_ICP: u64 = TOKEN_SUBDIVIDABLE_BY; +// TODO get this from nervous_system/common/consts after we migrate consts out of nervous_system/common +pub const ONE_DAY_SECONDS: u64 = 24 * 60 * 60; + impl GovernanceError { pub fn new(error_type: ErrorType) -> Self { Self { @@ -19,3 +29,69 @@ impl GovernanceError { } } } + +impl NeuronsFundEconomics { + /// The default values for network economics (until we initialize it). + /// Can't implement Default since it conflicts with Prost's. + /// The values here are computed under the assumption that 1 XDR = 0.75 USD. See also: + /// https://dashboard.internetcomputer.org/proposal/124822 + pub fn with_default_values() -> Self { + Self { + max_theoretical_neurons_fund_participation_amount_xdr: Some(Decimal { + human_readable: Some("750_000.0".to_string()), + }), + neurons_fund_matched_funding_curve_coefficients: Some( + NeuronsFundMatchedFundingCurveCoefficients { + contribution_threshold_xdr: Some(Decimal { + human_readable: Some("75_000.0".to_string()), + }), + one_third_participation_milestone_xdr: Some(Decimal { + human_readable: Some("225_000.0".to_string()), + }), + full_participation_milestone_xdr: Some(Decimal { + human_readable: Some("375_000.0".to_string()), + }), + }, + ), + minimum_icp_xdr_rate: Some(Percentage { + basis_points: Some(10_000), // 1:1 + }), + maximum_icp_xdr_rate: Some(Percentage { + basis_points: Some(1_000_000), // 1:100 + }), + } + } +} + +impl NetworkEconomics { + /// The multiplier applied to minimum_icp_xdr_rate to convert the XDR unit to basis_points + pub const ICP_XDR_RATE_TO_BASIS_POINT_MULTIPLIER: u64 = 100; + + // The default values for network economics (until we initialize it). + // Can't implement Default since it conflicts with Prost's. + pub fn with_default_values() -> Self { + Self { + reject_cost_e8s: E8S_PER_ICP, // 1 ICP + neuron_management_fee_per_proposal_e8s: 1_000_000, // 0.01 ICP + neuron_minimum_stake_e8s: E8S_PER_ICP, // 1 ICP + neuron_spawn_dissolve_delay_seconds: ONE_DAY_SECONDS * 7, // 7 days + maximum_node_provider_rewards_e8s: 1_000_000 * 100_000_000, // 1M ICP + minimum_icp_xdr_rate: 100, // 1 XDR + transaction_fee_e8s: DEFAULT_TRANSFER_FEE.get_e8s(), + max_proposals_to_keep_per_topic: 100, + neurons_fund_economics: Some(NeuronsFundEconomics::with_default_values()), + } + } +} + +impl XdrConversionRate { + /// This constructor should be used only at canister creation, and not, e.g., after upgrades. + /// The reason this function exists is because `Default::default` is already defined by prost. + /// However, the Governance canister relies on the fields of this structure being `Some`. + pub fn with_default_values() -> Self { + Self { + timestamp_seconds: Some(0), + xdr_permyriad_per_icp: Some(10_000), + } + } +} diff --git a/rs/nns/governance/init/BUILD.bazel b/rs/nns/governance/init/BUILD.bazel new file mode 100644 index 000000000000..c52b7a7f874a --- /dev/null +++ b/rs/nns/governance/init/BUILD.bazel @@ -0,0 +1,58 @@ +load("@rules_rust//rust:defs.bzl", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +# See rs/nervous_system/feature_test.md +BASE_DEPENDENCIES = [ + # Keep sorted. + "//rs/nervous_system/common", + "//rs/nervous_system/common/test_keys", + "//rs/nns/common", + "//rs/rosetta-api/icp_ledger", + "//rs/types/base_types", + "@crate_index//:csv", + "@crate_index//:rand", + "@crate_index//:rand_chacha", +] + +# Each target declared in this file may choose either these (release-ready) +# dependencies (`DEPENDENCIES`), or `DEPENDENCIES_WITH_TEST_FEATURES` feature previews. +DEPENDENCIES = BASE_DEPENDENCIES + [ + "//rs/nns/governance/api", +] + +DEPENDENCIES_WITH_TEST_FEATURES = BASE_DEPENDENCIES + [ + "//rs/nns/governance/api:api--test_feature", +] + +MACRO_DEPENDENCIES = [ + # Keep sorted. +] + +ALIASES = {} + +rust_library( + name = "init", + srcs = glob( + ["src/**/*.rs"], + exclude = ["**/*tests.rs"], + ), + aliases = ALIASES, + crate_name = "ic_nns_governance_init", + proc_macro_deps = MACRO_DEPENDENCIES, + version = "0.9.0", + deps = DEPENDENCIES, +) + +rust_library( + name = "init--test_feature", + srcs = glob( + ["src/**/*.rs"], + exclude = ["**/*tests.rs"], + ), + aliases = ALIASES, + crate_name = "ic_nns_governance_init", + proc_macro_deps = MACRO_DEPENDENCIES, + version = "0.9.0", + deps = DEPENDENCIES_WITH_TEST_FEATURES, +) diff --git a/rs/nns/governance/init/Cargo.toml b/rs/nns/governance/init/Cargo.toml new file mode 100644 index 000000000000..3fe69e591c7a --- /dev/null +++ b/rs/nns/governance/init/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "ic-nns-governance-init" +version.workspace = true +authors.workspace = true +edition.workspace = true +description.workspace = true +documentation.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +path = "src/lib.rs" + +[dependencies] +ic-base-types = { path = "../../../types/base_types" } +ic-nervous-system-common = { path = "../../../nervous_system/common" } +ic-nervous-system-common-test-keys = { path = "../../../nervous_system/common/test_keys" } +ic-nervous-system-common-build-metadata = { path = "../../../nervous_system/common/build_metadata" } +ic-nns-common = { path = "../../common" } +ic-nns-governance-api = { path = "../api" } +icp-ledger = { path = "../../../rosetta-api/icp_ledger" } +rand = { workspace = true } +rand_chacha = { workspace = true } + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +csv = "1.1" diff --git a/rs/nns/governance/src/init.rs b/rs/nns/governance/init/src/lib.rs similarity index 97% rename from rs/nns/governance/src/init.rs rename to rs/nns/governance/init/src/lib.rs index a4ce4939dd5b..c61aec170d9b 100644 --- a/rs/nns/governance/src/init.rs +++ b/rs/nns/governance/init/src/lib.rs @@ -1,8 +1,4 @@ #[cfg(not(target_arch = "wasm32"))] -use crate::pb::v1::{neuron::DissolveState, neuron::Followees, Topic}; -#[cfg(not(target_arch = "wasm32"))] -use ic_nervous_system_common::ledger; -#[cfg(not(target_arch = "wasm32"))] use icp_ledger::Subaccount; #[cfg(not(target_arch = "wasm32"))] use rand::{RngCore, SeedableRng}; @@ -11,11 +7,11 @@ use rand_chacha::ChaCha20Rng; #[cfg(not(target_arch = "wasm32"))] use std::path::Path; -use crate::pb::v1::{ - Governance, NetworkEconomics, Neuron, XdrConversionRate as XdrConversionRatePb, -}; use ic_base_types::PrincipalId; use ic_nns_common::types::NeuronId; +use ic_nns_governance_api::pb::v1::{ + Governance, NetworkEconomics, Neuron, XdrConversionRate as XdrConversionRatePb, +}; // To update or add more, add print statements to `with_test_neurons` to print // the generated neuron IDs and copy the printed IDs here. @@ -97,6 +93,7 @@ impl GovernanceCanisterInitPayloadBuilder { TEST_NEURON_1_ID, TEST_NEURON_1_OWNER_PRINCIPAL, TEST_NEURON_2_ID, TEST_NEURON_2_OWNER_PRINCIPAL, TEST_NEURON_3_ID, TEST_NEURON_3_OWNER_PRINCIPAL, }; + use ic_nns_governance_api::pb::v1::{neuron::DissolveState, Neuron}; let mut neuron1 = { let neuron_id = NeuronIdProto::from(self.new_neuron_id()); @@ -210,6 +207,13 @@ impl GovernanceCanisterInitPayloadBuilder { use ic_nns_common::pb::v1::NeuronId as NeuronIdProto; use csv::ReaderBuilder; + use ic_base_types::PrincipalId; + use ic_nervous_system_common::ledger; + use ic_nns_common::types::NeuronId; + use ic_nns_governance_api::pb::v1::{ + neuron::{DissolveState, Followees}, + Neuron, Topic, + }; use std::str::FromStr; let mut reader = ReaderBuilder::new() diff --git a/rs/nns/governance/src/governance/tests/neurons_fund.rs b/rs/nns/governance/src/governance/tests/neurons_fund.rs index f6a949d729ee..755ec9ad6580 100644 --- a/rs/nns/governance/src/governance/tests/neurons_fund.rs +++ b/rs/nns/governance/src/governance/tests/neurons_fund.rs @@ -1,10 +1,13 @@ use super::*; -use crate::init::GovernanceCanisterInitPayloadBuilder; -use crate::pb::v1::create_service_nervous_system::SwapParameters; -use crate::test_utils::{MockEnvironment, StubCMC, StubIcpLedger}; +use crate::{ + pb::v1::create_service_nervous_system::SwapParameters, + test_utils::{MockEnvironment, StubCMC, StubIcpLedger}, +}; use assert_matches::assert_matches; use ic_nervous_system_common::E8; use ic_nervous_system_proto::pb::v1 as pb; +use ic_nns_governance_api::pb::v1 as pb_api; +use ic_nns_governance_init::GovernanceCanisterInitPayloadBuilder; use maplit::btreemap; use test_data::CREATE_SERVICE_NERVOUS_SYSTEM_WITH_MATCHED_FUNDING; @@ -16,13 +19,13 @@ fn proposal_passes_if_not_too_many_nf_neurons_can_occur() { .with_test_neurons_fund_neurons(500_000 * E8) .build(); governance_proto.proposals = btreemap! { - 123 => ProposalData { + 123_u64 => ProposalData { id: Some(proposal_id), ..ProposalData::default() - } + }.into() }; let mut governance = Governance::new( - governance_proto, + governance_proto.into(), Box::::default(), Box::new(StubIcpLedger {}), Box::new(StubCMC {}), @@ -72,7 +75,7 @@ fn proposal_fails_if_too_many_nf_neurons_can_occur() { }) .unwrap(); let neurons = (0..num_neurons_fund_neurons) - .map(|id| NeuronProto { + .map(|id| pb_api::Neuron { id: Some(NeuronId { id }), ..proto_neuron.clone() }) @@ -82,13 +85,13 @@ fn proposal_fails_if_too_many_nf_neurons_can_occur() { .build() }; governance_proto.proposals = btreemap! { - 123 => ProposalData { + 123_u64 => ProposalData { id: Some(proposal_id), ..ProposalData::default() - } + }.into() }; let mut governance = Governance::new( - governance_proto, + governance_proto.into(), Box::::default(), Box::new(StubIcpLedger {}), Box::new(StubCMC {}), @@ -123,13 +126,13 @@ fn proposal_fails_if_no_nf_neurons_exist() { let create_service_nervous_system = CREATE_SERVICE_NERVOUS_SYSTEM_WITH_MATCHED_FUNDING.clone(); let mut governance_proto = GovernanceCanisterInitPayloadBuilder::new().build(); governance_proto.proposals = btreemap! { - 123 => ProposalData { + 123_u64 => ProposalData { id: Some(proposal_id), ..ProposalData::default() - } + }.into() }; let mut governance = Governance::new( - governance_proto, + governance_proto.into(), Box::::default(), Box::new(StubIcpLedger {}), Box::new(StubCMC {}), diff --git a/rs/nns/governance/src/lib.rs b/rs/nns/governance/src/lib.rs index 34d33fe8e703..8b680b33ff50 100644 --- a/rs/nns/governance/src/lib.rs +++ b/rs/nns/governance/src/lib.rs @@ -155,7 +155,6 @@ mod garbage_collection; pub mod governance; pub mod governance_proto_builder; mod heap_governance_data; -pub mod init; mod known_neuron_index; mod migrations; mod neuron; diff --git a/rs/nns/governance/tests/governance.rs b/rs/nns/governance/tests/governance.rs index 98718d0edd70..1132e960cb96 100644 --- a/rs/nns/governance/tests/governance.rs +++ b/rs/nns/governance/tests/governance.rs @@ -2,7 +2,6 @@ //! are defi data_source: (), timestamp_seconds: ()ned as small but //! complex/weird configurations of neurons and proposals against which several //! tests are run. - use crate::fake::{ DAPP_CANISTER_ID, DEVELOPER_PRINCIPAL_ID, NODE_PROVIDER_REWARD, SNS_GOVERNANCE_CANISTER_ID, SNS_LEDGER_ARCHIVE_CANISTER_ID, SNS_LEDGER_CANISTER_ID, SNS_LEDGER_INDEX_CANISTER_ID, @@ -55,7 +54,6 @@ use ic_nns_governance::{ REWARD_DISTRIBUTION_PERIOD_SECONDS, WAIT_FOR_QUIET_DEADLINE_INCREASE_SECONDS, }, governance_proto_builder::GovernanceProtoBuilder, - init::GovernanceCanisterInitPayloadBuilder, pb::v1::{ add_or_remove_node_provider::Change, governance::{GovernanceCachedMetrics, GovernanceCachedMetricsChange, MigrationsDesc}, @@ -94,6 +92,7 @@ use ic_nns_governance::{ }, proposals::create_service_nervous_system::ExecutedCreateServiceNervousSystemProposal, }; +use ic_nns_governance_init::GovernanceCanisterInitPayloadBuilder; use ic_sns_init::pb::v1::SnsInitPayload; use ic_sns_root::{GetSnsCanistersSummaryRequest, GetSnsCanistersSummaryResponse}; use ic_sns_swap::pb::v1::{ @@ -6094,11 +6093,16 @@ async fn test_not_for_profit_neurons() { Topic::NeuronManagement as i32, Followees { followees: vec![normal_neuron.id.unwrap()], - }, + } + .into(), ); - let (_, mut gov) = - governance_with_neurons(&init_neurons.values().cloned().collect::>()); + let (_, mut gov) = governance_with_neurons( + &init_neurons + .values() + .map(|n| n.clone().into()) + .collect::>(), + ); let not_for_profit_neuron = init_neurons[&25].clone(); @@ -6169,8 +6173,12 @@ fn test_hot_keys_cant_change_followees_of_manage_neuron_topic() { .hot_keys .push(*second_neuron.controller.as_ref().unwrap()); - let (_, mut gov) = - governance_with_neurons(&init_neurons.values().cloned().collect::>()); + let (_, mut gov) = governance_with_neurons( + &init_neurons + .values() + .map(|n| n.clone().into()) + .collect::>(), + ); let first_neuron = init_neurons[&25].clone(); @@ -6234,8 +6242,12 @@ fn test_add_and_remove_hot_key() { let mut builder = GovernanceCanisterInitPayloadBuilder::new(); let init_neurons = &mut builder.add_all_neurons_from_csv_file(&p).proto.neurons; - let (_, mut gov) = - governance_with_neurons(&init_neurons.values().cloned().collect::>()); + let (_, mut gov) = governance_with_neurons( + &init_neurons + .values() + .map(|n| n.clone().into()) + .collect::>(), + ); let neuron = init_neurons[&25].clone(); let new_controller = init_neurons[&42].controller.unwrap(); @@ -6313,13 +6325,17 @@ fn test_manage_and_reward_node_providers() { let voter_pid = *init_neurons[&42].controller.as_ref().unwrap(); let voter_neuron = init_neurons[&42].id.unwrap(); - init_neurons.get_mut(&42).unwrap().dissolve_state = Some(DissolveState::DissolveDelaySeconds( - MIN_DISSOLVE_DELAY_FOR_VOTE_ELIGIBILITY_SECONDS, - )); + init_neurons.get_mut(&42).unwrap().dissolve_state = Some( + DissolveState::DissolveDelaySeconds(MIN_DISSOLVE_DELAY_FOR_VOTE_ELIGIBILITY_SECONDS).into(), + ); let np_pid = PrincipalId::new_self_authenticating(&[14]); - let (driver, mut gov) = - governance_with_neurons(&init_neurons.values().cloned().collect::>()); + let (driver, mut gov) = governance_with_neurons( + &init_neurons + .values() + .map(|n| n.clone().into()) + .collect::>(), + ); println!( "Ledger {:?}\n", @@ -6659,15 +6675,19 @@ fn test_manage_and_reward_multiple_node_providers() { let voter_pid = *init_neurons[&42].controller.as_ref().unwrap(); let voter_neuron = init_neurons[&42].id.unwrap(); - init_neurons.get_mut(&42).unwrap().dissolve_state = Some(DissolveState::DissolveDelaySeconds( - MIN_DISSOLVE_DELAY_FOR_VOTE_ELIGIBILITY_SECONDS, - )); + init_neurons.get_mut(&42).unwrap().dissolve_state = Some( + DissolveState::DissolveDelaySeconds(MIN_DISSOLVE_DELAY_FOR_VOTE_ELIGIBILITY_SECONDS).into(), + ); let np_pid_0 = PrincipalId::new_self_authenticating(&[14]); let np_pid_1 = PrincipalId::new_self_authenticating(&[15]); let np_pid_2 = PrincipalId::new_self_authenticating(&[16]); - let (driver, mut gov) = - governance_with_neurons(&init_neurons.values().cloned().collect::>()); + let (driver, mut gov) = governance_with_neurons( + &init_neurons + .values() + .map(|n| n.clone().into()) + .collect::>(), + ); println!( "Ledger {:?}\n", @@ -7029,11 +7049,15 @@ fn test_network_economics_proposal() { let voter_pid = *init_neurons[&42].controller.as_ref().unwrap(); let voter_neuron = init_neurons[&42].id.unwrap(); - init_neurons.get_mut(&42).unwrap().dissolve_state = Some(DissolveState::DissolveDelaySeconds( - MIN_DISSOLVE_DELAY_FOR_VOTE_ELIGIBILITY_SECONDS, - )); - let (_, mut gov) = - governance_with_neurons(&init_neurons.values().cloned().collect::>()); + init_neurons.get_mut(&42).unwrap().dissolve_state = Some( + DissolveState::DissolveDelaySeconds(MIN_DISSOLVE_DELAY_FOR_VOTE_ELIGIBILITY_SECONDS).into(), + ); + let (_, mut gov) = governance_with_neurons( + &init_neurons + .values() + .map(|n| n.clone().into()) + .collect::>(), + ); gov.heap_data.economics.as_mut().unwrap().reject_cost_e8s = 1234; gov.heap_data @@ -7138,11 +7162,15 @@ fn test_default_followees() { let voter_pid = *init_neurons[&42].controller.as_ref().unwrap(); let voter_neuron = init_neurons[&42].id.unwrap(); - init_neurons.get_mut(&42).unwrap().dissolve_state = Some(DissolveState::DissolveDelaySeconds( - MIN_DISSOLVE_DELAY_FOR_VOTE_ELIGIBILITY_SECONDS, - )); - let (mut driver, mut gov) = - governance_with_neurons(&init_neurons.values().cloned().collect::>()); + init_neurons.get_mut(&42).unwrap().dissolve_state = Some( + DissolveState::DissolveDelaySeconds(MIN_DISSOLVE_DELAY_FOR_VOTE_ELIGIBILITY_SECONDS).into(), + ); + let (mut driver, mut gov) = governance_with_neurons( + &init_neurons + .values() + .map(|n| n.clone().into()) + .collect::>(), + ); let default_followees = hashmap![ Topic::Unspecified as i32 => Followees { followees: vec![voter_neuron]}, diff --git a/rs/nns/governance/tests/init.rs b/rs/nns/governance/tests/init.rs index e4e4a0229b34..fcf57d3c7f65 100644 --- a/rs/nns/governance/tests/init.rs +++ b/rs/nns/governance/tests/init.rs @@ -1,4 +1,5 @@ -use ic_nns_governance::{init::GovernanceCanisterInitPayloadBuilder, pb::v1::Topic}; +use ic_nns_governance_api::pb::v1::Topic; +use ic_nns_governance_init::GovernanceCanisterInitPayloadBuilder; use std::path::PathBuf; #[test] diff --git a/rs/nns/init/BUILD.bazel b/rs/nns/init/BUILD.bazel index 62517a41053e..e30b5edad970 100644 --- a/rs/nns/init/BUILD.bazel +++ b/rs/nns/init/BUILD.bazel @@ -8,7 +8,7 @@ DEPENDENCIES = [ "//rs/interfaces/registry", "//rs/nns/common", "//rs/nns/constants", - "//rs/nns/governance", + "//rs/nns/governance/api", "//rs/nns/test_utils", "//rs/registry/local_store", "//rs/registry/proto_data_provider", diff --git a/rs/nns/init/Cargo.toml b/rs/nns/init/Cargo.toml index d481fca81675..0cd6ca479a6b 100644 --- a/rs/nns/init/Cargo.toml +++ b/rs/nns/init/Cargo.toml @@ -19,7 +19,7 @@ ic-registry-transport = { path = "../../registry/transport" } ic-nns-test-utils = { path = "../../nns/test_utils" } ic-nns-common = { path = "../common" } ic-nns-constants = { path = "../constants" } -ic-nns-governance = { path = "../governance" } +ic-nns-governance-api = { path = "../governance/api" } ic-test-identity = { path = "../../test_utilities/identity" } ic-sys = { path = "../../sys" } icp-ledger = { path = "../../rosetta-api/icp_ledger" } diff --git a/rs/nns/init/src/get_neuron_ids.rs b/rs/nns/init/src/get_neuron_ids.rs index 0195bb831cbb..8335aa9157d3 100644 --- a/rs/nns/init/src/get_neuron_ids.rs +++ b/rs/nns/init/src/get_neuron_ids.rs @@ -1,4 +1,4 @@ -use ic_nns_governance::pb::v1::Governance as GovernanceProto; +use ic_nns_governance_api::pb::v1::Governance as GovernanceProto; use prost::Message; use std::fs; diff --git a/rs/nns/init/src/main.rs b/rs/nns/init/src/main.rs index 89fa5603acc0..487867ab00f9 100644 --- a/rs/nns/init/src/main.rs +++ b/rs/nns/init/src/main.rs @@ -4,7 +4,7 @@ use ic_base_types::{PrincipalId, SubnetId}; use ic_canister_client::{Agent, HttpClientConfig, Sender}; use ic_nns_common::pb::v1::NeuronId; use ic_nns_constants::REGISTRY_CANISTER_ID; -use ic_nns_governance::pb::v1::Governance as GovernanceProto; +use ic_nns_governance_api::pb::v1::Governance as GovernanceProto; use ic_nns_init::{make_hsm_sender, set_up_env_vars_for_all_canisters}; use ic_nns_test_utils::{ common::{NnsInitPayloads, NnsInitPayloadsBuilder}, diff --git a/rs/nns/integration_tests/BUILD.bazel b/rs/nns/integration_tests/BUILD.bazel index 663a09904ef2..84c01a7d96d5 100644 --- a/rs/nns/integration_tests/BUILD.bazel +++ b/rs/nns/integration_tests/BUILD.bazel @@ -62,7 +62,6 @@ BASE_DEPENDENCIES = [ "@crate_index//:ic-xrc-types", "@crate_index//:maplit", "@crate_index//:rand", - # "@crate_index//:randomkit", "@crate_index//:rustc-hash", "@crate_index//:serde", "@crate_index//:serde_bytes", @@ -76,6 +75,7 @@ BASE_DEPENDENCIES = [ DEPENDENCIES = BASE_DEPENDENCIES + [ "//rs/sns/init", "//rs/nns/governance", + "//rs/nns/governance/init", "//rs/nns/sns-wasm", "//rs/nns/handlers/root/impl:root", "//rs/sns/swap", @@ -91,6 +91,7 @@ DEPENDENCIES = BASE_DEPENDENCIES + [ DEPENDENCIES_WITH_TEST_FEATURES = BASE_DEPENDENCIES + [ "//rs/sns/init:init--test_feature", "//rs/nns/governance:governance--test_feature", + "//rs/nns/governance/init:init--test_feature", "//rs/nns/sns-wasm:sns-wasm--test_feature", "//rs/nns/handlers/root/impl:root--test_feature", "//rs/sns/swap:swap--test_feature", diff --git a/rs/nns/integration_tests/Cargo.toml b/rs/nns/integration_tests/Cargo.toml index 0d64edabb5b5..978f61b0be4a 100644 --- a/rs/nns/integration_tests/Cargo.toml +++ b/rs/nns/integration_tests/Cargo.toml @@ -49,6 +49,7 @@ ic-nervous-system-common = { path = "../../nervous_system/common" } ic-nervous-system-runtime = { path = "../../nervous_system/runtime" } ic-nns-common = { path = "../common" } ic-nns-governance = { path = "../governance" } +ic-nns-governance-init = { path = "../governance/init" } ic-sns-root = { path = "../../sns/root" } ic-sns-swap = { path = "../../sns/swap" } ic-stable-structures = { workspace = true } diff --git a/rs/nns/integration_tests/src/bad_input.rs b/rs/nns/integration_tests/src/bad_input.rs index 0a52df4e48b7..b06971c0a441 100644 --- a/rs/nns/integration_tests/src/bad_input.rs +++ b/rs/nns/integration_tests/src/bad_input.rs @@ -5,7 +5,8 @@ use assert_matches::assert_matches; use dfn_candid::candid; use ic_base_types::PrincipalId; use ic_nns_common::types::ProposalId; -use ic_nns_governance::{init::GovernanceCanisterInitPayloadBuilder, pb::v1::ProposalInfo}; +use ic_nns_governance::pb::v1::ProposalInfo; +use ic_nns_governance_init::GovernanceCanisterInitPayloadBuilder; use ic_nns_test_utils::itest_helpers::{ set_up_governance_canister, state_machine_test_on_nns_subnet, }; @@ -16,7 +17,7 @@ fn test_skipping_quota() { state_machine_test_on_nns_subnet(|runtime| async move { let canister = set_up_governance_canister( &runtime, - GovernanceCanisterInitPayloadBuilder::new().build(), + GovernanceCanisterInitPayloadBuilder::new().build().into(), ) .await; @@ -50,7 +51,7 @@ fn test_bad_proposal_id_candid_type() { state_machine_test_on_nns_subnet(|runtime| async move { let canister = set_up_governance_canister( &runtime, - GovernanceCanisterInitPayloadBuilder::new().build(), + GovernanceCanisterInitPayloadBuilder::new().build().into(), ) .await; @@ -72,7 +73,7 @@ fn test_bad_proposal_id_candid_encoding() { state_machine_test_on_nns_subnet(|runtime| async move { let canister = set_up_governance_canister( &runtime, - GovernanceCanisterInitPayloadBuilder::new().build(), + GovernanceCanisterInitPayloadBuilder::new().build().into(), ) .await; @@ -94,7 +95,7 @@ fn test_inexistent_proposal_id_is_not_a_bad_input() { state_machine_test_on_nns_subnet(|runtime| async move { let canister = set_up_governance_canister( &runtime, - GovernanceCanisterInitPayloadBuilder::new().build(), + GovernanceCanisterInitPayloadBuilder::new().build().into(), ) .await; diff --git a/rs/nns/integration_tests/src/governance_get_build_metadata_test.rs b/rs/nns/integration_tests/src/governance_get_build_metadata_test.rs index 27765a8bebcf..8899f57aa59f 100644 --- a/rs/nns/integration_tests/src/governance_get_build_metadata_test.rs +++ b/rs/nns/integration_tests/src/governance_get_build_metadata_test.rs @@ -33,6 +33,7 @@ fn get_build_metadata_test() { not_for_profit: true, ..Default::default() } + .into() ), None, "There is more than one neuron with the same id." diff --git a/rs/nns/integration_tests/src/governance_neurons.rs b/rs/nns/integration_tests/src/governance_neurons.rs index 7fdb9d77b314..78ec34898dcd 100644 --- a/rs/nns/integration_tests/src/governance_neurons.rs +++ b/rs/nns/integration_tests/src/governance_neurons.rs @@ -63,6 +63,7 @@ fn test_merge_neurons_and_simulate_merge_neurons() { not_for_profit: true, ..Default::default() } + .into() ), None, "There is more than one neuron with the same id." @@ -178,6 +179,7 @@ fn test_spawn_neuron() { maturity_e8s_equivalent: 1_000_000_000, // Equivalent to 10 ICP ..Default::default() } + .into() ), None, "There is more than one neuron with the same id." diff --git a/rs/nns/integration_tests/src/governance_time_warp.rs b/rs/nns/integration_tests/src/governance_time_warp.rs index 27bce66d7292..3e6ff8ced34e 100644 --- a/rs/nns/integration_tests/src/governance_time_warp.rs +++ b/rs/nns/integration_tests/src/governance_time_warp.rs @@ -55,7 +55,8 @@ fn test_time_warp() { kyc_verified: true, ..Default::default() - }, + } + .into(), ); assert_eq!( pre_existing_neuron, None, diff --git a/rs/nns/integration_tests/src/governance_upgrade.rs b/rs/nns/integration_tests/src/governance_upgrade.rs index 849d3803f13e..7db3d44d0b4f 100644 --- a/rs/nns/integration_tests/src/governance_upgrade.rs +++ b/rs/nns/integration_tests/src/governance_upgrade.rs @@ -18,13 +18,11 @@ use ic_nns_common::pb::v1::NeuronId as NeuronIdProto; use ic_nns_constants::{ GOVERNANCE_CANISTER_ID, GOVERNANCE_CANISTER_INDEX_IN_NNS_SUBNET, ROOT_CANISTER_ID, }; -use ic_nns_governance::{ - init::GovernanceCanisterInitPayloadBuilder, - pb::v1::{ - manage_neuron::{configure, Command, Configure, NeuronIdOrSubaccount, RemoveHotKey}, - ManageNeuron, ManageNeuronResponse, - }, +use ic_nns_governance::pb::v1::{ + manage_neuron::{configure, Command, Configure, NeuronIdOrSubaccount, RemoveHotKey}, + ManageNeuron, ManageNeuronResponse, }; +use ic_nns_governance_init::GovernanceCanisterInitPayloadBuilder; use ic_nns_test_utils::{ common::NnsInitPayloadsBuilder, itest_helpers::{install_governance_canister, state_machine_test_on_nns_subnet}, @@ -58,7 +56,7 @@ fn test_upgrade_after_state_shrink() { .create_canister_at_id_max_cycles_with_retries(GOVERNANCE_CANISTER_ID.get()) .await .unwrap(); - install_governance_canister(&mut canister, governance_proto).await; + install_governance_canister(&mut canister, governance_proto.into()).await; // First let's do a self-upgrade canister.stop().await.unwrap(); diff --git a/rs/nns/integration_tests/src/gtc.rs b/rs/nns/integration_tests/src/gtc.rs index 0c63aa62f9f3..261c3a60e15f 100644 --- a/rs/nns/integration_tests/src/gtc.rs +++ b/rs/nns/integration_tests/src/gtc.rs @@ -525,9 +525,14 @@ pub fn add_test_gtc_neurons(payload_builder: &mut NnsInitPayloadsBuilder) { payload_builder .genesis_token .add_ect_neurons(TEST_ECT_ACCOUNTS); - payload_builder - .governance - .add_gtc_neurons(payload_builder.genesis_token.get_gtc_neurons()); + payload_builder.governance.add_gtc_neurons( + payload_builder + .genesis_token + .get_gtc_neurons() + .into_iter() + .map(|n| n.into()) + .collect(), + ); payload_builder .genesis_token .add_forward_whitelist(&[TEST_IDENTITY_4.gtc_address]); diff --git a/rs/nns/integration_tests/src/network_economics.rs b/rs/nns/integration_tests/src/network_economics.rs index 9a1c33684b97..5015ab4b0273 100644 --- a/rs/nns/integration_tests/src/network_economics.rs +++ b/rs/nns/integration_tests/src/network_economics.rs @@ -14,7 +14,7 @@ fn test_get_network_economics() { }; let mut nns_builder = NnsInitPayloadsBuilder::new(); - nns_builder.governance.proto.economics = Some(network_economics.clone()); + nns_builder.governance.proto.economics = Some(network_economics.clone().into()); let nns_init_payload = nns_builder.build(); let nns_canisters = NnsCanisters::set_up(&runtime, nns_init_payload).await; diff --git a/rs/nns/integration_tests/src/wait_for_quiet.rs b/rs/nns/integration_tests/src/wait_for_quiet.rs index adfb164096d0..37927ca0f885 100644 --- a/rs/nns/integration_tests/src/wait_for_quiet.rs +++ b/rs/nns/integration_tests/src/wait_for_quiet.rs @@ -49,7 +49,8 @@ fn test_deadline_is_extended_with_wait_for_quiet() { cached_neuron_stake_e8s: 200_000_000, dissolve_state: Some(DissolveState::DissolveDelaySeconds(ONE_DAY_SECONDS * 365)), ..Default::default() - }, + } + .into(), ); let nns_init_payload = nns_init_payload_builder.build(); diff --git a/rs/nns/test_utils/BUILD.bazel b/rs/nns/test_utils/BUILD.bazel index ea94314c8105..57af9f29853d 100644 --- a/rs/nns/test_utils/BUILD.bazel +++ b/rs/nns/test_utils/BUILD.bazel @@ -66,6 +66,7 @@ BASE_DEPENDENCIES = [ # dependencies (`DEPENDENCIES`), or `DEPENDENCIES_WITH_TEST_FEATURES` feature previews. DEPENDENCIES = BASE_DEPENDENCIES + [ "//rs/nns/governance", + "//rs/nns/governance/init", "//rs/nns/gtc", "//rs/nns/sns-wasm", "//rs/nns/handlers/root/impl:root", @@ -76,6 +77,7 @@ DEPENDENCIES = BASE_DEPENDENCIES + [ DEPENDENCIES_WITH_TEST_FEATURES = BASE_DEPENDENCIES + [ "//rs/nns/governance:governance--test_feature", + "//rs/nns/governance/init:init--test_feature", "//rs/nns/gtc:gtc--test_feature", "//rs/nns/sns-wasm:sns-wasm--test_feature", "//rs/nns/handlers/root/impl:root--test_feature", diff --git a/rs/nns/test_utils/Cargo.toml b/rs/nns/test_utils/Cargo.toml index 96e8794ee3f5..ef83176094d1 100644 --- a/rs/nns/test_utils/Cargo.toml +++ b/rs/nns/test_utils/Cargo.toml @@ -38,6 +38,7 @@ ic-nervous-system-root = { path = "../../nervous_system/root" } ic-nns-common = { path = "../common" } ic-nns-constants = { path = "../constants" } ic-nns-governance = { path = "../governance" } +ic-nns-governance-init = { path = "../governance/init" } ic-nns-gtc = { path = "../gtc" } ic-nns-gtc-accounts = { path = "../gtc_accounts" } ic-nns-handler-root = { path = "../handlers/root/impl" } diff --git a/rs/nns/test_utils/src/common.rs b/rs/nns/test_utils/src/common.rs index becf7c3e21d8..d345f239bc95 100644 --- a/rs/nns/test_utils/src/common.rs +++ b/rs/nns/test_utils/src/common.rs @@ -10,10 +10,8 @@ use ic_nns_common::init::{LifelineCanisterInitPayload, LifelineCanisterInitPaylo use ic_nns_constants::{ ALL_NNS_CANISTER_IDS, GOVERNANCE_CANISTER_ID, LEDGER_CANISTER_ID, ROOT_CANISTER_ID, }; -use ic_nns_governance::{ - init::GovernanceCanisterInitPayloadBuilder, - pb::v1::{Governance, NetworkEconomics, Neuron}, -}; +use ic_nns_governance::pb::v1::{Governance, NetworkEconomics, Neuron}; +use ic_nns_governance_init::GovernanceCanisterInitPayloadBuilder; use ic_nns_gtc::{init::GenesisTokenCanisterInitPayloadBuilder, pb::v1::Gtc}; use ic_nns_gtc_accounts::{ECT_ACCOUNTS, SEED_ROUND_ACCOUNTS}; use ic_nns_handler_root::init::{RootCanisterInitPayload, RootCanisterInitPayloadBuilder}; @@ -140,7 +138,8 @@ impl NnsInitPayloadsBuilder { } pub fn with_additional_neurons(&mut self, neurons: Vec) -> &mut Self { - self.governance.with_additional_neurons(neurons); + self.governance + .with_additional_neurons(neurons.into_iter().map(|n| n.into()).collect()); self } @@ -153,7 +152,7 @@ impl NnsInitPayloadsBuilder { } pub fn with_governance_proto(&mut self, proto: Governance) -> &mut Self { - self.governance.with_governance_proto(proto); + self.governance.with_governance_proto(proto.into()); self } @@ -182,15 +181,22 @@ impl NnsInitPayloadsBuilder { self.genesis_token.add_sr_neurons(SEED_ROUND_ACCOUNTS); self.genesis_token.add_ect_neurons(ECT_ACCOUNTS); + let default_followees = self + .governance + .proto + .default_followees + .iter() + .map(|(id, followees)| (*id, followees.clone().into())) + .collect(); + let gtc_neurons = self .genesis_token .get_gtc_neurons() .into_iter() .map(|mut neuron| { - neuron - .followees - .clone_from(&self.governance.proto.default_followees); - neuron + neuron.followees.clone_from(&default_followees); + // convert for our init that uses api types + neuron.into() }) .collect(); @@ -231,7 +237,8 @@ impl NnsInitPayloadsBuilder { } pub fn with_network_economics(&mut self, network_economics: NetworkEconomics) -> &mut Self { - self.governance.with_network_economics(network_economics); + self.governance + .with_network_economics(network_economics.into()); self } @@ -265,7 +272,7 @@ impl NnsInitPayloadsBuilder { } NnsInitPayloads { registry: self.registry.build(), - governance: self.governance.build(), + governance: self.governance.build().into(), ledger: self.ledger.clone(), root: self.root.build(), cycles_minting: self.cycles_minting.clone(), diff --git a/rs/nns/test_utils/src/neuron_helpers.rs b/rs/nns/test_utils/src/neuron_helpers.rs index d9df192b5e73..37735fd9ed9f 100644 --- a/rs/nns/test_utils/src/neuron_helpers.rs +++ b/rs/nns/test_utils/src/neuron_helpers.rs @@ -5,12 +5,9 @@ use ic_nervous_system_common_test_keys::{ TEST_NEURON_2_OWNER_PRINCIPAL, TEST_NEURON_3_ID, TEST_NEURON_3_OWNER_PRINCIPAL, }; use ic_nns_common::{pb::v1::NeuronId, types::ProposalId}; -use ic_nns_governance::{ - self, - pb::v1::{ - manage_neuron_response::Command, proposal::Action, ExecuteNnsFunction, Neuron, NnsFunction, - Proposal, - }, +use ic_nns_governance::pb::v1::{ + manage_neuron_response::Command, proposal::Action, ExecuteNnsFunction, Neuron, NnsFunction, + Proposal, }; use ic_state_machine_tests::StateMachine; use std::collections::HashMap; diff --git a/rs/sns/init/src/lib.rs b/rs/sns/init/src/lib.rs index 02ac3ee7438e..633876cca974 100644 --- a/rs/sns/init/src/lib.rs +++ b/rs/sns/init/src/lib.rs @@ -9,8 +9,7 @@ use ic_icrc1_index_ng::{IndexArg, InitArg}; use ic_icrc1_ledger::{InitArgsBuilder as LedgerInitArgsBuilder, LedgerArgument}; use ic_ledger_canister_core::archive::ArchiveOptions; use ic_ledger_core::Tokens; -use ic_nervous_system_common::ledger_validation; -use ic_nervous_system_common::{DEFAULT_TRANSFER_FEE, E8}; +use ic_nervous_system_common::{ledger_validation, DEFAULT_TRANSFER_FEE, E8}; use ic_nervous_system_proto::pb::v1::{Canister, Countries}; use ic_nns_constants::{ CYCLES_MINTING_CANISTER_ID, EXCHANGE_RATE_CANISTER_ID, GENESIS_TOKEN_CANISTER_ID, diff --git a/rs/tests/src/nns_tests/sns_deployment.rs b/rs/tests/src/nns_tests/sns_deployment.rs index 5c4da311fe38..86c13b6c611f 100644 --- a/rs/tests/src/nns_tests/sns_deployment.rs +++ b/rs/tests/src/nns_tests/sns_deployment.rs @@ -1,12 +1,11 @@ -use std::collections::{BTreeSet, HashMap}; -use std::str::FromStr; -use std::time::Duration; -use std::time::Instant; - -use candid::Decode; -use candid::{Nat, Principal}; -use ic_agent::Agent; -use ic_agent::{agent::EnvelopeContent, Identity, Signature}; +use std::{ + collections::{BTreeSet, HashMap}, + str::FromStr, + time::{Duration, Instant}, +}; + +use candid::{Decode, Nat, Principal}; +use ic_agent::{agent::EnvelopeContent, Agent, Identity, Signature}; use ic_base_types::PrincipalId; use ic_canister_client_sender::ed25519_public_key_to_der; use ic_icrc1_test_utils::KeyPairGenerator; @@ -15,61 +14,62 @@ use ic_nervous_system_common::E8; use ic_nervous_system_proto::pb::v1::Canister; use ic_nns_governance::pb::v1::CreateServiceNervousSystem; use ic_rosetta_test_utils::EdKeypair; -use ic_system_test_driver::canister_agent::{CanisterAgent, HasCanisterAgentCapability}; -use ic_system_test_driver::canister_api::{ - CallMode, CanisterHttpRequestProvider, Icrc1RequestProvider, Icrc1TransferRequest, - NnsDappRequestProvider, Request, Response, SnsRequestProvider, -}; -use ic_system_test_driver::canister_requests; -use ic_system_test_driver::driver::farm::HostFeature; -use ic_system_test_driver::driver::prometheus_vm::{HasPrometheus, PrometheusVm}; -use ic_system_test_driver::driver::test_env::TestEnv; -use ic_system_test_driver::driver::test_env_api::IcNodeSnapshot; -use ic_system_test_driver::driver::test_env_api::NnsCanisterWasmStrategy; -use ic_system_test_driver::driver::test_env_api::TEST_USER1_STARTING_TOKENS; -use ic_system_test_driver::driver::test_env_api::{ - GetFirstHealthyNodeSnapshot, HasPublicApiUrl, HasTopologySnapshot, NnsCustomizations, -}; -use ic_system_test_driver::generic_workload_engine::engine::Engine; -use ic_system_test_driver::generic_workload_engine::metrics::{ - LoadTestMetrics, LoadTestOutcome, RequestOutcome, +use ic_system_test_driver::{ + canister_agent::{CanisterAgent, HasCanisterAgentCapability}, + canister_api::{ + CallMode, CanisterHttpRequestProvider, Icrc1RequestProvider, Icrc1TransferRequest, + NnsDappRequestProvider, Request, Response, SnsRequestProvider, + }, + canister_requests, + driver::{ + farm::HostFeature, + prometheus_vm::{HasPrometheus, PrometheusVm}, + test_env::TestEnv, + test_env_api::{ + GetFirstHealthyNodeSnapshot, HasPublicApiUrl, HasTopologySnapshot, IcNodeSnapshot, + NnsCanisterWasmStrategy, NnsCustomizations, TEST_USER1_STARTING_TOKENS, + }, + }, + generic_workload_engine::{ + engine::Engine, + metrics::{LoadTestMetrics, LoadTestOutcome, RequestOutcome}, + }, + sns_client::openchat_create_service_nervous_system_proposal, + types::{CanisterStatusResult, CreateCanisterResult}, + util::UniversalCanister, }; -use ic_system_test_driver::sns_client::openchat_create_service_nervous_system_proposal; -use ic_system_test_driver::types::CanisterStatusResult; -use ic_system_test_driver::types::CreateCanisterResult; -use ic_system_test_driver::util::UniversalCanister; use rosetta_core::models::RosettaSupportedKeyPair; use ic_sns_governance::pb::v1::governance::Mode; -use ic_sns_swap::pb::v1::{new_sale_ticket_response, Lifecycle}; -use ic_sns_swap::swap::principal_to_subaccount; -use ic_types::Cycles; -use ic_types::Height; -use ic_universal_canister::management; -use ic_universal_canister::wasm; +use ic_sns_swap::{ + pb::v1::{new_sale_ticket_response, Lifecycle}, + swap::principal_to_subaccount, +}; +use ic_types::{Cycles, Height}; +use ic_universal_canister::{management, wasm}; use icp_ledger::{AccountIdentifier, Subaccount}; use icrc_ledger_agent::Icrc1Agent; -use icrc_ledger_types::icrc1::account::Account; -use icrc_ledger_types::icrc1::transfer::TransferArg; +use icrc_ledger_types::icrc1::{account::Account, transfer::TransferArg}; use serde::{Deserialize, Serialize}; use slog::info; use tokio::runtime::Builder; use ic_consensus_system_test_utils::rw_message::install_nns_with_customizations_and_check_progress; -use ic_system_test_driver::sns_client::{SnsClient, SNS_SALE_PARAM_MIN_PARTICIPANT_ICP_E8S}; -use ic_system_test_driver::util::{assert_create_agent_with_identity, block_on}; +use ic_system_test_driver::{ + sns_client::{SnsClient, SNS_SALE_PARAM_MIN_PARTICIPANT_ICP_E8S}, + util::{assert_create_agent_with_identity, block_on}, +}; -use ic_system_test_driver::driver::ic::{ - AmountOfMemoryKiB, ImageSizeGiB, InternetComputer, NrOfVCPUs, Subnet, VmResources, +use ic_system_test_driver::driver::{ + ic::{AmountOfMemoryKiB, ImageSizeGiB, InternetComputer, NrOfVCPUs, Subnet, VmResources}, + test_env::TestEnvAttribute, }; -use ic_system_test_driver::driver::test_env::TestEnvAttribute; use ic_nervous_system_common_test_keys::{TEST_USER1_KEYPAIR, TEST_USER1_PRINCIPAL}; use ic_nns_constants::{LEDGER_CANISTER_ID, ROOT_CANISTER_ID}; use ic_registry_subnet_type::SubnetType; -use crate::nns_tests::neurons_fund::NnsNfNeuron; -use crate::nns_tests::sns_aggregator::AggregatorClient; +use crate::nns_tests::{neurons_fund::NnsNfNeuron, sns_aggregator::AggregatorClient}; const WORKLOAD_GENERATION_DURATION: Duration = Duration::from_secs(60); @@ -276,7 +276,7 @@ pub fn workload_static_testnet_sale_bot(env: TestEnv) { /// that the tests are using realistic parameters. /// /// The NNS will be initialized with only the "test" neurons. -/// (See [`ic_nns_governance::init::GovernanceCanisterInitPayloadBuilder::with_test_neurons`].) +/// (See [`ic_nns_governance_init::GovernanceCanisterInitPayloadBuilder::with_test_neurons`].) pub fn setup_with_oc_parameters( env: TestEnv, sale_participants: Vec, @@ -1280,27 +1280,27 @@ async fn create_one_sale_participant( // 4. Call sns.get_buyer_state { - let request = sns_request_provider - .get_buyer_state(Some(participant.principal_id), CallMode::Update); - canister_agent.call_with_retries( - request, - SNS_ENDPOINT_RETRY_TIMEOUT, - SNS_ENDPOINT_RETRY_BACKOFF, - None, - ) + let request = sns_request_provider + .get_buyer_state(Some(participant.principal_id), CallMode::Update); + canister_agent.call_with_retries( + request, + SNS_ENDPOINT_RETRY_TIMEOUT, + SNS_ENDPOINT_RETRY_BACKOFF, + None, + ) } - .await - .check_response(|response| { - let response_amount = response.buyer_state.unwrap().icp.unwrap().amount_e8s; - if response_amount >= contribution { - Ok(()) - } else { - Err(anyhow::anyhow!("get_buyer_state: response ICP amount {response_amount:?} below the minimum amount {contribution:?}")) - } - }) - .with_workflow_position(4) - .push_outcome_display_error(outcome) - .result()?; + .await + .check_response(|response| { + let response_amount = response.buyer_state.unwrap().icp.unwrap().amount_e8s; + if response_amount >= contribution { + Ok(()) + } else { + Err(anyhow::anyhow!("get_buyer_state: response ICP amount {response_amount:?} below the minimum amount {contribution:?}")) + } + }) + .with_workflow_position(4) + .push_outcome_display_error(outcome) + .result()?; // 5. Check that the ticket has been deleted via swap.get_open_ticket {