Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(sns): migrate SNS integration tests / init to sns-gov-api #3918

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rs/nns/sns-wasm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ DEPENDENCIES = [
"//rs/nns/handlers/root/interface",
"//rs/rust_canisters/http_types",
"//rs/sns/governance",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you able to remove the old dependency?

"//rs/sns/governance/api",
"//rs/sns/init",
"//rs/sns/root",
"//rs/types/base_types",
Expand Down
2 changes: 1 addition & 1 deletion rs/nns/sns-wasm/src/sns_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use ic_nns_handler_root_interface::{
client::NnsRootCanisterClient, ChangeCanisterControllersRequest,
ChangeCanisterControllersResult,
};
use ic_sns_governance::pb::v1::governance::Version;
use ic_sns_governance_api::pb::v1::governance::Version;
use ic_sns_init::{pb::v1::SnsInitPayload, SnsCanisterInitPayloads};
use ic_sns_root::GetSnsCanistersSummaryResponse;
use ic_types::{Cycles, SubnetId};
Expand Down
1 change: 1 addition & 0 deletions rs/nns/test_utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ BASE_DEPENDENCIES = [
"//rs/rust_canisters/dfn_protobuf",
"//rs/rust_canisters/on_wire",
"//rs/sns/governance",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question here

"//rs/sns/governance/api",
"//rs/sns/init",
"//rs/sns/swap",
"//rs/state_machine_tests",
Expand Down
63 changes: 32 additions & 31 deletions rs/nns/test_utils/src/state_test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ use ic_nns_handler_root::init::RootCanisterInitPayload;
use ic_registry_transport::pb::v1::{
RegistryGetChangesSinceRequest, RegistryGetChangesSinceResponse,
};
use ic_sns_governance::pb::v1::{
self as sns_pb, manage_neuron_response::Command as SnsCommandResponse, GetModeResponse,
use ic_sns_governance_api::pb::v1::{
self as sns_pb_api, manage_neuron_response::Command as SnsCommandResponse, GetModeResponse,
};
use ic_sns_swap::pb::v1::{GetAutoFinalizationStatusRequest, GetAutoFinalizationStatusResponse};
use ic_sns_wasm::{
Expand Down Expand Up @@ -1795,22 +1795,22 @@ pub fn sns_claim_staked_neuron(
sender: PrincipalId,
nonce: u64,
dissolve_delay: Option<u32>,
) -> sns_pb::NeuronId {
) -> sns_pb_api::NeuronId {
// Find the neuron staked
let to_subaccount = compute_neuron_staking_subaccount(sender, nonce);

// Claim the neuron on the governance canister.
let claim_response: sns_pb::ManageNeuronResponse = update_with_sender(
let claim_response: sns_pb_api::ManageNeuronResponse = update_with_sender(
machine,
governance_canister_id,
"manage_neuron",
sns_pb::ManageNeuron {
sns_pb_api::ManageNeuron {
subaccount: to_subaccount.to_vec(),
command: Some(sns_pb::manage_neuron::Command::ClaimOrRefresh(
sns_pb::manage_neuron::ClaimOrRefresh {
command: Some(sns_pb_api::manage_neuron::Command::ClaimOrRefresh(
sns_pb_api::manage_neuron::ClaimOrRefresh {
by: Some(
sns_pb::manage_neuron::claim_or_refresh::By::MemoAndController(
sns_pb::manage_neuron::claim_or_refresh::MemoAndController {
sns_pb_api::manage_neuron::claim_or_refresh::By::MemoAndController(
sns_pb_api::manage_neuron::claim_or_refresh::MemoAndController {
memo: nonce,
controller: None,
},
Expand Down Expand Up @@ -1862,21 +1862,21 @@ pub fn sns_increase_dissolve_delay(
subaccount: &[u8],
dissolve_delay: u32,
) {
let payload = sns_pb::ManageNeuron {
let payload = sns_pb_api::ManageNeuron {
subaccount: subaccount.to_vec(),
command: Some(sns_pb::manage_neuron::Command::Configure(
sns_pb::manage_neuron::Configure {
command: Some(sns_pb_api::manage_neuron::Command::Configure(
sns_pb_api::manage_neuron::Configure {
operation: Some(
sns_pb::manage_neuron::configure::Operation::IncreaseDissolveDelay(
sns_pb::manage_neuron::IncreaseDissolveDelay {
sns_pb_api::manage_neuron::configure::Operation::IncreaseDissolveDelay(
sns_pb_api::manage_neuron::IncreaseDissolveDelay {
additional_dissolve_delay_seconds: dissolve_delay,
},
),
),
},
)),
};
let increase_response: sns_pb::ManageNeuronResponse = update_with_sender(
let increase_response: sns_pb_api::ManageNeuronResponse = update_with_sender(
machine,
governance_canister_id,
"manage_neuron",
Expand Down Expand Up @@ -1905,18 +1905,18 @@ pub fn sns_make_proposal(
sns_governance_canister_id: CanisterId,
sender: PrincipalId,
// subaccount: &[u8],
neuron_id: sns_pb::NeuronId,
proposal: sns_pb::Proposal,
) -> Result<sns_pb::ProposalId, sns_pb::GovernanceError> {
neuron_id: sns_pb_api::NeuronId,
proposal: sns_pb_api::Proposal,
) -> Result<sns_pb_api::ProposalId, sns_pb_api::GovernanceError> {
let sub_account = neuron_id.subaccount().unwrap();

let manage_neuron_response: sns_pb::ManageNeuronResponse = update_with_sender(
let manage_neuron_response: sns_pb_api::ManageNeuronResponse = update_with_sender(
machine,
sns_governance_canister_id,
"manage_neuron",
sns_pb::ManageNeuron {
sns_pb_api::ManageNeuron {
subaccount: sub_account.to_vec(),
command: Some(sns_pb::manage_neuron::Command::MakeProposal(proposal)),
command: Some(sns_pb_api::manage_neuron::Command::MakeProposal(proposal)),
},
sender,
)
Expand All @@ -1940,11 +1940,12 @@ pub fn sns_governance_get_mode(
state_machine,
sns_governance_canister_id,
"get_mode",
Encode!(&sns_pb::GetMode {}).unwrap(),
Encode!(&sns_pb_api::GetMode {}).unwrap(),
)
.map_err(|e| format!("Error calling get_mode: {}", e))?;

let GetModeResponse { mode } = Decode!(&get_mode_response, sns_pb::GetModeResponse).unwrap();
let GetModeResponse { mode } =
Decode!(&get_mode_response, sns_pb_api::GetModeResponse).unwrap();

Ok(mode.unwrap())
}
Expand Down Expand Up @@ -1973,29 +1974,29 @@ pub fn sns_swap_get_auto_finalization_status(
pub fn sns_get_proposal(
machine: &StateMachine,
governance_canister_id: CanisterId,
proposal_id: sns_pb::ProposalId,
) -> Result<sns_pb::ProposalData, String> {
proposal_id: sns_pb_api::ProposalId,
) -> Result<sns_pb_api::ProposalData, String> {
let get_proposal_response = query(
machine,
governance_canister_id,
"get_proposal",
Encode!(&sns_pb::GetProposal {
Encode!(&sns_pb_api::GetProposal {
proposal_id: Some(proposal_id),
})
.unwrap(),
)
.map_err(|e| format!("Error calling get_proposal: {}", e))?;

let get_proposal_response =
Decode!(&get_proposal_response, sns_pb::GetProposalResponse).unwrap();
Decode!(&get_proposal_response, sns_pb_api::GetProposalResponse).unwrap();
match get_proposal_response
.result
.expect("Empty get_proposal_response")
{
sns_pb::get_proposal_response::Result::Error(e) => {
sns_pb_api::get_proposal_response::Result::Error(e) => {
panic!("get_proposal error: {}", e);
}
sns_pb::get_proposal_response::Result::Proposal(proposal) => Ok(proposal),
sns_pb_api::get_proposal_response::Result::Proposal(proposal) => Ok(proposal),
}
}

Expand All @@ -2004,7 +2005,7 @@ pub fn sns_get_proposal(
pub fn sns_wait_for_proposal_execution(
machine: &StateMachine,
governance: CanisterId,
proposal_id: sns_pb::ProposalId,
proposal_id: sns_pb_api::ProposalId,
) {
// We create some blocks until the proposal has finished executing (machine.tick())
let mut attempt_count = 0;
Expand Down Expand Up @@ -2032,7 +2033,7 @@ pub fn sns_wait_for_proposal_execution(
pub fn sns_wait_for_proposal_executed_or_failed(
machine: &StateMachine,
governance: CanisterId,
proposal_id: sns_pb::ProposalId,
proposal_id: sns_pb_api::ProposalId,
) {
// We create some blocks until the proposal has finished executing (machine.tick())
let mut attempt_count = 0;
Expand Down
4 changes: 4 additions & 0 deletions rs/sns/governance/api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ package(default_visibility = ["//visibility:public"])
# See rs/nervous_system/feature_test.md
DEPENDENCIES = [
# Keep sorted.
"//packages/icrc-ledger-types:icrc_ledger_types",
"//rs/ledger_suite/common/ledger_core",
"//rs/ledger_suite/icp:icp_ledger",
"//rs/nervous_system/common",
"//rs/nervous_system/proto",
"//rs/protobuf",
"//rs/types/base_types",
Expand All @@ -15,6 +18,7 @@ DEPENDENCIES = [
"@crate_index//:candid",
"@crate_index//:clap",
"@crate_index//:comparable",
"@crate_index//:hex",
"@crate_index//:itertools",
"@crate_index//:prost",
"@crate_index//:serde",
Expand Down
4 changes: 4 additions & 0 deletions rs/sns/governance/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ bytes = { workspace = true }
candid = { workspace = true }
clap = { workspace = true }
comparable = { version = "0.5", features = ["derive"] }
hex = { workspace = true }
ic-base-types = { path = "../../../types/base_types" }
ic-nervous-system-common = { path = "../../../nervous_system/common" }
ic-nervous-system-proto = { path = "../../../nervous_system/proto" }
ic-nns-common = { path = "../../../nns/common" }
ic-protobuf = { path = "../../../protobuf" }
Expand All @@ -28,3 +30,5 @@ serde = { workspace = true }
serde_bytes = { workspace = true }
strum = { workspace = true }
strum_macros = { workspace = true }
ledger_core = { path = "../../../ledger_suite/common/ledger_core" }
icrc-ledger-types = { path = "../../../packages/icrc-ledger-types" }
4 changes: 3 additions & 1 deletion rs/sns/governance/api/src/ic_sns_governance.pb.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ pub mod transfer_sns_treasury_funds {
Hash,
PartialOrd,
Ord,
::prost::Enumeration,
)]
#[repr(i32)]
pub enum TransferFrom {
Expand Down Expand Up @@ -971,7 +972,7 @@ pub mod valuation {
/// on the subnet).
///
/// Required invariant: the canister code assumes that all system parameters are always set.
#[derive(Default, candid::CandidType, candid::Deserialize, Debug, Clone, PartialEq)]
#[derive(candid::CandidType, candid::Deserialize, Debug, Clone, PartialEq)]
pub struct NervousSystemParameters {
/// The number of e8s (10E-8 of a token) that a rejected
/// proposal costs the proposer.
Expand Down Expand Up @@ -2383,6 +2384,7 @@ pub struct Account {
#[derive(
candid::CandidType,
candid::Deserialize,
strum_macros::EnumIter,
Debug,
clap::ValueEnum,
Clone,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl GovernanceCanisterInitPayloadBuilder {
pub fn new() -> Self {
Self {
proto: Governance {
parameters: Some(NervousSystemParameters::with_default_values()),
parameters: Some(NervousSystemParameters::default()),
mode: Mode::PreInitializationSwap as i32,
sns_metadata: Some(SnsMetadata {
logo: Some("data:image/png;base64,aGVsbG8gZnJvbSBkZmluaXR5IQ==".to_string()),
Expand Down Expand Up @@ -51,7 +51,7 @@ impl GovernanceCanisterInitPayloadBuilder {
}

pub fn with_mode(&mut self, mode: Mode) -> &mut Self {
self.proto.set_mode(mode);
self.proto.mode = mode as i32;
self
}

Expand Down
3 changes: 3 additions & 0 deletions rs/sns/governance/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub mod init;
pub mod nervous_system_parameters;
pub mod neuron;
pub mod pb;
mod types;

Expand Down
65 changes: 65 additions & 0 deletions rs/sns/governance/api/src/nervous_system_parameters.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use crate::pb::v1::{
DefaultFollowees, NervousSystemParameters, NeuronPermissionList, NeuronPermissionType,
VotingRewardsParameters,
};
use ic_ledger_core::tokens::TOKEN_SUBDIVIDABLE_BY;
use ic_nervous_system_common::{
DEFAULT_TRANSFER_FEE, ONE_DAY_SECONDS, ONE_MONTH_SECONDS, ONE_YEAR_SECONDS,
};

/// The number of e8s per governance token;
const E8S_PER_TOKEN: u64 = TOKEN_SUBDIVIDABLE_BY;

impl NervousSystemParameters {
/// These are the permissions that must be present in
/// `neuron_claimer_permissions`.
/// Permissions not in this list can be added after the SNS is created via a
/// proposal.
pub const REQUIRED_NEURON_CLAIMER_PERMISSIONS: &'static [NeuronPermissionType] = &[
// Without this permission, it would be impossible to transfer control
// of a neuron to a new principal.
NeuronPermissionType::ManagePrincipals,
// Without this permission, it would be impossible to vote.
NeuronPermissionType::Vote,
// Without this permission, it would be impossible to submit a proposal.
NeuronPermissionType::SubmitProposal,
];

/// Returns the default for the nervous system parameter neuron_claimer_permissions.
fn default_neuron_claimer_permissions() -> NeuronPermissionList {
NeuronPermissionList {
permissions: Self::REQUIRED_NEURON_CLAIMER_PERMISSIONS
.iter()
.map(|p| *p as i32)
.collect(),
}
}
}

impl Default for NervousSystemParameters {
fn default() -> Self {
Self {
reject_cost_e8s: Some(E8S_PER_TOKEN), // 1 governance token
neuron_minimum_stake_e8s: Some(E8S_PER_TOKEN), // 1 governance token
transaction_fee_e8s: Some(DEFAULT_TRANSFER_FEE.get_e8s()),
max_proposals_to_keep_per_action: Some(100),
initial_voting_period_seconds: Some(4 * ONE_DAY_SECONDS), // 4d
wait_for_quiet_deadline_increase_seconds: Some(ONE_DAY_SECONDS), // 1d
default_followees: Some(DefaultFollowees::default()),
max_number_of_neurons: Some(200_000),
neuron_minimum_dissolve_delay_to_vote_seconds: Some(6 * ONE_MONTH_SECONDS), // 6m
max_followees_per_function: Some(15),
max_dissolve_delay_seconds: Some(8 * ONE_YEAR_SECONDS), // 8y
max_neuron_age_for_age_bonus: Some(4 * ONE_YEAR_SECONDS), // 4y
max_number_of_proposals_with_ballots: Some(700),
neuron_claimer_permissions: Some(Self::default_neuron_claimer_permissions()),
neuron_grantable_permissions: Some(NeuronPermissionList::default()),
max_number_of_principals_per_neuron: Some(5),
voting_rewards_parameters: Some(VotingRewardsParameters::with_default_values()),
max_dissolve_delay_bonus_percentage: Some(100),
max_age_bonus_percentage: Some(25),
maturity_modulation_disabled: Some(false),
automatically_advance_target_version: Some(false),
}
}
}
Loading
Loading