Skip to content

Commit

Permalink
Merge branch 'mraszyk/src-testnet' into 'master'
Browse files Browse the repository at this point in the history
chore: add testnet for Subnet Rental Canister

 

See merge request dfinity-lab/public/ic!19296
  • Loading branch information
mraszyk committed May 16, 2024
2 parents 0c0213d + 8a3ea16 commit 7dcdaa1
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 17 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions rs/tests/gix/nns_dapp_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use ic_tests::driver::{
test_env_api::{retry, secs, HasTopologySnapshot, NnsCanisterWasmStrategy},
};
use ic_tests::nns_dapp::{
install_ii_and_nns_dapp, nns_dapp_customizations, set_authorized_subnets,
install_ii_nns_dapp_and_subnet_rental, nns_dapp_customizations, set_authorized_subnets,
};
use ic_tests::orchestrator::utils::rw_message::install_nns_with_customizations_and_check_progress;
use ic_tests::retry_with_msg;
Expand Down Expand Up @@ -121,7 +121,7 @@ fn get_html(env: &TestEnv, farm_url: &str, canister_id: Principal, dapp_anchor:

pub fn test(env: TestEnv) {
let (ii_canister_id, nns_dapp_canister_id) =
install_ii_and_nns_dapp(&env, BOUNDARY_NODE_NAME, None);
install_ii_nns_dapp_and_subnet_rental(&env, BOUNDARY_NODE_NAME, None);
let boundary_node = env
.get_deployed_boundary_node(BOUNDARY_NODE_NAME)
.unwrap()
Expand Down
51 changes: 43 additions & 8 deletions rs/tests/src/nns_dapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ use crate::driver::{
NnsCustomizations,
},
};
use crate::nns::set_authorized_subnetwork_list;
use crate::nns::{set_authorized_subnetwork_list, update_xdr_per_icp};
use crate::sns_client::add_subnet_to_sns_deploy_whitelist;
use crate::util::{block_on, create_canister, install_canister, runtime_from_url};
use candid::Principal;
use candid::{CandidType, Encode};
use ic_base_types::SubnetId;
use ic_icrc1_ledger::{InitArgsBuilder, LedgerArgument};
use ic_ledger_core::Tokens;
use ic_nns_constants::SUBNET_RENTAL_CANISTER_ID;
use ic_registry_subnet_type::SubnetType;
use icp_ledger::AccountIdentifier;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -47,6 +48,13 @@ pub struct CanisterArguments {
pub schema: Option<SchemaLabel>,
}

/// Initializes the ICP ledger canister with 1e9 ICP on an account
/// controlled by a secret key with the following PEM file:
/// -----BEGIN EC PRIVATE KEY-----
/// MHQCAQEEICJxApEbuZznKFpV+VKACRK30i6+7u5Z13/DOl18cIC+oAcGBSuBBAAK
/// oUQDQgAEPas6Iag4TUx+Uop+3NhE6s3FlayFtbwdhRVjvOar0kPTfE/N8N6btRnd
/// 74ly5xXEBNSXiENyxhEuzOZrIWMCNQ==
/// -----END EC PRIVATE KEY-----
pub fn nns_dapp_customizations() -> NnsCustomizations {
let mut ledger_balances = HashMap::new();
ledger_balances.insert(
Expand Down Expand Up @@ -107,7 +115,11 @@ pub fn install_sns_aggregator(
})
}

pub fn install_ii_and_nns_dapp(
/// Installs II, NNS dapp, and Subnet Rental Canister.
/// The Subnet Rental Canister is installed since otherwise
/// the canister ID of the ckETH ledger (required by the NNS dapp)
/// would conflict with the Subnet Rental Canister ID on mainnet.
pub fn install_ii_nns_dapp_and_subnet_rental(
env: &TestEnv,
boundary_node_name: &str,
sns_aggregator_canister_id: Option<Principal>,
Expand All @@ -119,23 +131,29 @@ pub fn install_ii_and_nns_dapp(
.unwrap();
let farm_url = boundary_node.get_playnet().unwrap();
let https_farm_url = format!("https://{}", farm_url);
let topology = env.topology_snapshot();

// deploy the II canister
let topology = env.topology_snapshot();
let nns_node = topology.root_subnet().nodes().next().unwrap();
let nns_agent = nns_node.build_default_agent();

let ii_canister_id =
nns_node.create_and_install_canister_with_arg(INTERNET_IDENTITY_WASM, None);

// create the NNS dapp canister so that its canister ID is allocated
// and the Subnet Rental Canister gets its mainnet canister ID in the next step
// it can't be installed yet since we need to get the ckETH ledger canister ID first
let nns_agent = nns_node.build_default_agent();
let nns_dapp_canister_id =
block_on(
async move { create_canister(&nns_agent, nns_node.effective_canister_id()).await },
);

// deploy the Subnet Rental Canister
let nns_node = topology.root_subnet().nodes().next().unwrap();
let nns_agent = nns_node.build_default_agent();

nns_node.create_and_install_canister_with_arg(SUBNET_RENTAL_CANISTER_WASM, None);
let subnet_rental_canister_id =
nns_node.create_and_install_canister_with_arg(SUBNET_RENTAL_CANISTER_WASM, None);
assert_eq!(subnet_rental_canister_id, SUBNET_RENTAL_CANISTER_ID.into());

// deploy the ckETH ledger canister (ICRC1-ledger with "ckETH" as token symbol and name) required by NNS dapp
let cketh_init_args = InitArgsBuilder::for_tests()
.with_token_symbol("ckETH".to_string())
.with_token_name("ckETH".to_string())
Expand All @@ -145,6 +163,8 @@ pub fn install_ii_and_nns_dapp(
Some(Encode!(&(LedgerArgument::Init(cketh_init_args))).unwrap()),
);

// now that we know all required canister IDs, install the NNS dapp
let nns_agent = nns_node.build_default_agent();
let nns_dapp_wasm = env.load_wasm(NNS_DAPP_WASM);
let logger = env.logger();
block_on(async move {
Expand Down Expand Up @@ -191,6 +211,21 @@ pub fn install_ii_and_nns_dapp(
})
}

pub fn set_icp_xdr_exchange_rate(env: &TestEnv, xdr_permyriad_per_icp: u64) {
let topology = env.topology_snapshot();
let nns_node = topology.root_subnet().nodes().next().unwrap();
let nns = runtime_from_url(nns_node.get_public_url(), nns_node.effective_canister_id());
let timestamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs();
block_on(async move {
update_xdr_per_icp(&nns, timestamp, xdr_permyriad_per_icp)
.await
.unwrap();
});
}

pub fn set_authorized_subnets(env: &TestEnv) {
let topology = env.topology_snapshot();
let nns_node = topology.root_subnet().nodes().next().unwrap();
Expand Down
24 changes: 24 additions & 0 deletions rs/tests/testing_verification/testnets/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,30 @@ system_test(
deps = DEPENDENCIES + ["//rs/tests"],
)

system_test(
name = "src_testing",
flaky = False,
proc_macro_deps = MACRO_DEPENDENCIES,
tags = [
"dynamic_testnet",
"manual",
],
target_compatible_with = ["@platforms//os:linux"], # requires libssh that does not build on Mac OS
runtime_deps = GUESTOS_RUNTIME_DEPS + NNS_CANISTER_RUNTIME_DEPS + SNS_CANISTER_RUNTIME_DEPS + BOUNDARY_NODE_GUESTOS_RUNTIME_DEPS + GRAFANA_RUNTIME_DEPS + [
"//rs/rosetta-api/icrc1/ledger:ledger_canister.wasm.gz",
"//rs/rosetta-api/tvl/xrc_mock:xrc_mock_canister.wasm.gz",
"@ii_dev_canister//file",
"@nns_dapp_canister//file",
"@sns_aggregator//file",
"@subnet_rental_canister//file",
],
deps = DEPENDENCIES + [
"//rs/rosetta-api/tvl/xrc_mock",
"//rs/tests",
"@crate_index//:ic-xrc-types",
],
)

# recovered_mainnet_nns is a manual system-test that deploys an IC with a NNS that is recovered from the latest mainnet state.
system_test(
name = "recovered_mainnet_nns",
Expand Down
9 changes: 9 additions & 0 deletions rs/tests/testing_verification/testnets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ documentation.workspace = true

[dependencies]
anyhow = { workspace = true }
candid = { workspace = true }
ic-base-types = { path = "../../../types/base_types" }
ic-registry-subnet-features = { path = "../../../registry/subnet_features" }
ic-registry-subnet-type = { path = "../../../registry/subnet_type" }
tests = { path = "../.." }
ic-mainnet-nns-recovery = { path = "../../nns/ic_mainnet_nns_recovery" }
ic-xrc-types = "1.0.0"
slog = { workspace = true }
xrc-mock = { path = "../../../rosetta-api/tvl/xrc_mock" }

[[bin]]
name = "large"
Expand Down Expand Up @@ -44,3 +49,7 @@ path = "small.rs"
[[bin]]
name = "sns_testing"
path = "sns_testing.rs"

[[bin]]
name = "src_testing"
path = "src_testing.rs"
28 changes: 25 additions & 3 deletions rs/tests/testing_verification/testnets/large.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ use ic_tests::driver::{
},
};
use ic_tests::nns_dapp::{
install_ii_and_nns_dapp, install_sns_aggregator, nns_dapp_customizations,
set_authorized_subnets, set_sns_subnet,
install_ii_nns_dapp_and_subnet_rental, install_sns_aggregator, nns_dapp_customizations,
set_authorized_subnets, set_icp_xdr_exchange_rate, set_sns_subnet,
};
use ic_tests::orchestrator::utils::rw_message::install_nns_with_customizations_and_check_progress;
use ic_tests::sns_client::add_all_wasms_to_sns_wasm;
Expand All @@ -73,9 +73,12 @@ fn main() -> Result<()> {
}

pub fn setup(env: TestEnv) {
// start p8s for metrics and dashboards
PrometheusVm::default()
.start(&env)
.expect("Failed to start prometheus VM");

// set up IC overriding the default resources to be more powerful
let vm_resources = VmResources {
vcpus: Some(NrOfVCPUs::new(64)),
memory_kibibytes: Some(AmountOfMemoryKiB::new(480 << 20)),
Expand All @@ -91,12 +94,21 @@ pub fn setup(env: TestEnv) {
}
ic.setup_and_start(&env)
.expect("Failed to setup IC under test");

// set up NNS canisters
install_nns_with_customizations_and_check_progress(
env.topology_snapshot(),
NnsCanisterWasmStrategy::TakeBuiltFromSources,
nns_dapp_customizations(),
);

// sets the exchange rate to 12 XDR per 1 ICP
set_icp_xdr_exchange_rate(&env, 12_0000);

// sets the exchange rate to 12 XDR per 1 ICP
set_authorized_subnets(&env);

// deploys the boundary node(s)
let mut farm_url: Option<String> = None;
for i in 0..NUM_BN {
let bn_name = format!("boundary-node-{}", i);
Expand All @@ -117,20 +129,30 @@ pub fn setup(env: TestEnv) {
}
}
env.sync_with_prometheus_by_name("", farm_url);

for i in 0..NUM_BN {
let bn_name = format!("boundary-node-{}", i);
await_boundary_node_healthy(&env, &bn_name);
if i == 0 {
// pick an SNS subnet among the application subnets
let topology = env.topology_snapshot();
let mut app_subnets = topology
.subnets()
.filter(|s| s.subnet_type() == SubnetType::Application);
let sns_subnet = app_subnets.next().unwrap();

// install the SNS aggregator canister onto the SNS subnet
let sns_node = sns_subnet.nodes().next().unwrap();
let sns_aggregator_canister_id = install_sns_aggregator(&env, &bn_name, sns_node);
install_ii_and_nns_dapp(&env, &bn_name, Some(sns_aggregator_canister_id));

// register the SNS subnet with the NNS
set_sns_subnet(&env, sns_subnet.subnet_id);

// upload SNS canister WASMs to the SNS-W canister
add_all_wasms_to_sns_wasm(&env, NnsCanisterWasmStrategy::TakeBuiltFromSources);

// install II, NNS dapp, and Subnet Rental Canister
install_ii_nns_dapp_and_subnet_rental(&env, &bn_name, Some(sns_aggregator_canister_id));
}
}
}
4 changes: 2 additions & 2 deletions rs/tests/testing_verification/testnets/small_nns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use ic_tests::driver::{
test_env_api::{await_boundary_node_healthy, HasTopologySnapshot, NnsCanisterWasmStrategy},
};
use ic_tests::nns_dapp::{
install_ii_and_nns_dapp, nns_dapp_customizations, set_authorized_subnets,
install_ii_nns_dapp_and_subnet_rental, nns_dapp_customizations, set_authorized_subnets,
};
use ic_tests::orchestrator::utils::rw_message::install_nns_with_customizations_and_check_progress;

Expand Down Expand Up @@ -82,7 +82,7 @@ pub fn setup(env: TestEnv) {
.use_real_certs_and_dns()
.start(&env)
.expect("failed to setup BoundaryNode VM");
install_ii_and_nns_dapp(&env, BOUNDARY_NODE_NAME, None);
install_ii_nns_dapp_and_subnet_rental(&env, BOUNDARY_NODE_NAME, None);
set_authorized_subnets(&env);
let boundary_node = env
.get_deployed_boundary_node(BOUNDARY_NODE_NAME)
Expand Down
8 changes: 6 additions & 2 deletions rs/tests/testing_verification/testnets/sns_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use ic_tests::driver::{
},
};
use ic_tests::nns_dapp::{
install_ii_and_nns_dapp, install_sns_aggregator, nns_dapp_customizations,
install_ii_nns_dapp_and_subnet_rental, install_sns_aggregator, nns_dapp_customizations,
set_authorized_subnets, set_sns_subnet,
};
use ic_tests::orchestrator::utils::rw_message::install_nns_with_customizations_and_check_progress;
Expand Down Expand Up @@ -110,7 +110,11 @@ pub fn setup(env: TestEnv) {
info!(logger, "Use {} as effective canister ID when creating canisters for your dapp, e.g., using --provisional-create-canister-effective-canister-id {} with DFX", app_effective_canister_id, app_effective_canister_id);

let sns_aggregator_canister_id = install_sns_aggregator(&env, BOUNDARY_NODE_NAME, sns_node);
install_ii_and_nns_dapp(&env, BOUNDARY_NODE_NAME, Some(sns_aggregator_canister_id));
install_ii_nns_dapp_and_subnet_rental(
&env,
BOUNDARY_NODE_NAME,
Some(sns_aggregator_canister_id),
);
set_authorized_subnets(&env);
set_sns_subnet(&env, sns_subnet.subnet_id);
add_all_wasms_to_sns_wasm(&env, NnsCanisterWasmStrategy::TakeBuiltFromSources);
Expand Down
Loading

0 comments on commit 7dcdaa1

Please sign in to comment.