Skip to content

Commit 69b35fd

Browse files
committed
Merge branch 'mraszyk/sns-testing' into 'master'
add dynamic testnet for SNS testing See merge request dfinity-lab/public/ic!12521
2 parents 635dfb7 + 04bb290 commit 69b35fd

File tree

9 files changed

+210
-17
lines changed

9 files changed

+210
-17
lines changed

WORKSPACE.bazel

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -584,18 +584,17 @@ http_file(
584584
http_file(
585585
name = "nns_dapp_canister",
586586
downloaded_file_path = "nns_dapp_canister.wasm",
587-
sha256 = "8bcf768429631db5f6db372d090c58eedc9308ef623d98e0381121f598215de6",
588-
url = "https://github.com/dfinity/nns-dapp/releases/download/proposal-119296/nns-dapp.wasm",
587+
sha256 = "6af3470ef980b01eb427bdecde7d7c2c440a8c444f6c1fd6e7a39b251eceaf7a",
588+
url = "https://github.com/dfinity/nns-dapp/releases/download/proposal-122512/nns-dapp.wasm",
589589
)
590590

591-
# SNS aggregator canister (https://github.com/dfinity/nns-dapp/releases/tag/tip)
591+
# SNS aggregator canister
592592

593593
http_file(
594594
name = "sns_aggregator",
595-
downloaded_file_path = "sns_aggregator.wasm",
596-
sha256 = "428b21acccfa442101096d95f74ab8368724d0e87e14d08f21d9a3bed77b69f3",
597-
# Keep this dependency while the aggregator release process is WIP (IDX-2661)
598-
url = "https://github.com/dfinity/nns-dapp/releases/download/ci-pin/sns_aggregator2.wasm",
595+
downloaded_file_path = "sns_aggregator_dev.wasm",
596+
sha256 = "fb50fbd91ca28373a1dd9207dee7cab22b5d73fde66fe1cc8a9dac63b9549da1",
597+
url = "https://github.com/dfinity/nns-dapp/releases/download/proposal-122512/sns_aggregator_dev.wasm",
599598
)
600599

601600
# Import Python rules

rs/tests/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,10 @@ path = "testing_verification/testnets/small.rs"
559559
name = "ic-systest-small-nns"
560560
path = "testing_verification/testnets/small_nns.rs"
561561

562+
[[bin]]
563+
name = "ic-systest-sns-testing"
564+
path = "testing_verification/testnets/sns_testing.rs"
565+
562566
[[bin]]
563567
name = "ic-systest-medium"
564568
path = "testing_verification/testnets/medium.rs"

rs/tests/gix/nns_dapp_test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ fn get_html(env: &TestEnv, farm_url: &str, canister_id: Principal, dapp_anchor:
113113
}
114114

115115
pub fn test(env: TestEnv) {
116-
let (ii_canister_id, nns_dapp_canister_id) = install_ii_and_nns_dapp(&env, BOUNDARY_NODE_NAME);
116+
let (ii_canister_id, nns_dapp_canister_id) =
117+
install_ii_and_nns_dapp(&env, BOUNDARY_NODE_NAME, None);
117118
let boundary_node = env
118119
.get_deployed_boundary_node(BOUNDARY_NODE_NAME)
119120
.unwrap()

rs/tests/src/nns_dapp.rs

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ use crate::driver::{
22
boundary_node::BoundaryNodeVm,
33
test_env::TestEnv,
44
test_env_api::{
5-
HasPublicApiUrl, HasTopologySnapshot, HasWasm, IcNodeContainer, NnsCustomizations,
5+
HasPublicApiUrl, HasTopologySnapshot, HasWasm, IcNodeContainer, IcNodeSnapshot,
6+
NnsCustomizations,
67
},
78
};
89
use crate::nns::set_authorized_subnetwork_list;
10+
use crate::sns_client::add_subnet_to_sns_deploy_whitelist;
911
use crate::util::{block_on, create_canister, install_canister, runtime_from_url};
1012
use candid::Principal;
1113
use candid::{CandidType, Encode};
14+
use ic_base_types::SubnetId;
1215
use ic_ledger_core::Tokens;
1316
use ic_registry_subnet_type::SubnetType;
1417
use icp_ledger::AccountIdentifier;
@@ -19,6 +22,7 @@ use std::collections::HashMap;
1922
pub const INTERNET_IDENTITY_WASM: &str =
2023
"external/ii_test_canister/file/internet_identity_test.wasm";
2124
pub const NNS_DAPP_WASM: &str = "external/nns_dapp_canister/file/nns_dapp_canister.wasm";
25+
pub const SNS_AGGREGATOR_WASM: &str = "external/sns_aggregator/file/sns_aggregator_dev.wasm";
2226

2327
/// Init and post_upgrade arguments for NNS frontend dapp.
2428
#[derive(Debug, Default, Eq, PartialEq, CandidType, Serialize, Deserialize)]
@@ -48,7 +52,44 @@ pub fn nns_dapp_customizations() -> NnsCustomizations {
4852
}
4953
}
5054

51-
pub fn install_ii_and_nns_dapp(env: &TestEnv, boundary_node_name: &str) -> (Principal, Principal) {
55+
pub fn install_sns_aggregator(
56+
env: &TestEnv,
57+
boundary_node_name: &str,
58+
sns_node: IcNodeSnapshot,
59+
) -> Principal {
60+
let boundary_node = env
61+
.get_deployed_boundary_node(boundary_node_name)
62+
.unwrap()
63+
.get_snapshot()
64+
.unwrap();
65+
let farm_url = boundary_node.get_playnet().unwrap();
66+
67+
let sns_agent = sns_node.build_default_agent();
68+
let sns_aggregator_wasm = env.load_wasm(SNS_AGGREGATOR_WASM);
69+
let logger = env.logger();
70+
block_on(async move {
71+
let sns_aggregator_canister_id =
72+
create_canister(&sns_agent, sns_node.effective_canister_id()).await;
73+
install_canister(
74+
&sns_agent,
75+
sns_aggregator_canister_id,
76+
sns_aggregator_wasm.as_slice(),
77+
Encode!(&()).unwrap(),
78+
)
79+
.await;
80+
info!(
81+
logger,
82+
"SNS aggregator: https://{}.{}", sns_aggregator_canister_id, farm_url
83+
);
84+
sns_aggregator_canister_id
85+
})
86+
}
87+
88+
pub fn install_ii_and_nns_dapp(
89+
env: &TestEnv,
90+
boundary_node_name: &str,
91+
sns_aggregator_canister_id: Option<Principal>,
92+
) -> (Principal, Principal) {
5293
let boundary_node = env
5394
.get_deployed_boundary_node(boundary_node_name)
5495
.unwrap()
@@ -83,7 +124,7 @@ pub fn install_ii_and_nns_dapp(env: &TestEnv, boundary_node_name: &str) -> (Prin
83124
("OWN_CANISTER_ID".to_string(), nns_dapp_canister_id.to_string()),
84125
("OWN_CANISTER_URL".to_string(), format!("https://{}.{}", nns_dapp_canister_id, farm_url)),
85126
("ROBOTS".to_string(), "<meta name=\"robots\" content=\"noindex, nofollow\" />".to_string()),
86-
("SNS_AGGREGATOR_URL".to_string(), "".to_string()),
127+
("SNS_AGGREGATOR_URL".to_string(), sns_aggregator_canister_id.map(|s| format!("https://{}.{}", s, farm_url)).unwrap_or_else(|| "".to_string())),
87128
("STATIC_HOST".to_string(), https_farm_url),
88129
("WASM_CANISTER_ID".to_string(), "qaa6y-5yaaa-aaaaa-aaafa-cai".to_string())
89130
];
@@ -124,3 +165,13 @@ pub fn set_authorized_subnets(env: &TestEnv) {
124165
.unwrap();
125166
});
126167
}
168+
169+
pub fn set_sns_subnet(env: &TestEnv, subnet_id: SubnetId) {
170+
let topology = env.topology_snapshot();
171+
let nns_node = topology.root_subnet().nodes().next().unwrap();
172+
let nns_runtime = runtime_from_url(nns_node.get_public_url(), nns_node.effective_canister_id());
173+
174+
block_on(async move {
175+
add_subnet_to_sns_deploy_whitelist(&nns_runtime, subnet_id).await;
176+
});
177+
}

rs/tests/src/nns_tests/sns_aggregator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl AggregatorClient {
302302
"Validating aggregator canister's installation via public endpoint {}",
303303
app_node.get_public_url().as_str(),
304304
);
305-
let p = env.get_dependency_path("external/sns_aggregator/file/sns_aggregator.wasm");
305+
let p = env.get_dependency_path("external/sns_aggregator/file/sns_aggregator_dev.wasm");
306306
let p = std::fs::canonicalize(p.clone())
307307
.unwrap_or_else(|e| panic!("cannot obtain canonical path from {p:?}: {e:?}"));
308308
let canister_bytes = env.load_wasm(p);
@@ -401,7 +401,7 @@ pub fn validate_aggregator_data(env: TestEnv) {
401401
let swap_params = AggregatorClient::first_swap_params(
402402
&log,
403403
&http_canister,
404-
Duration::from_secs(2 * 60),
404+
Duration::from_secs(5 * 60),
405405
)
406406
.await
407407
.result()

rs/tests/src/sns_client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ pub fn oc_sns_init_payload() -> SnsInitPayload {
233233
}
234234

235235
/// Send and execute 6 proposals to add all SNS canister WASMs to the SNS WASM canister
236-
fn add_all_wasms_to_sns_wasm(env: &TestEnv, canister_wasm_strategy: NnsCanisterWasmStrategy) {
236+
pub fn add_all_wasms_to_sns_wasm(env: &TestEnv, canister_wasm_strategy: NnsCanisterWasmStrategy) {
237237
let logger = env.logger();
238238
let nns_node = env.get_first_healthy_nns_node_snapshot();
239239
let runtime = runtime_from_url(nns_node.get_public_url(), nns_node.effective_canister_id());
@@ -322,7 +322,7 @@ async fn add_principal_to_sns_deploy_whitelist(nns_api: &'_ Runtime, principal_i
322322
}
323323

324324
/// Send and execute a proposal to add the given subnet ID to the SNS subnet list
325-
async fn add_subnet_to_sns_deploy_whitelist(nns_api: &'_ Runtime, subnet_id: SubnetId) {
325+
pub async fn add_subnet_to_sns_deploy_whitelist(nns_api: &'_ Runtime, subnet_id: SubnetId) {
326326
let governance_canister = get_governance_canister(nns_api);
327327
let proposal_payload = UpdateSnsSubnetListRequest {
328328
sns_subnet_ids_to_add: vec![subnet_id.get()],

rs/tests/testing_verification/testnets/BUILD.bazel

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("//rs/tests:system_tests.bzl", "system_test")
2-
load("//rs/tests:common.bzl", "BOUNDARY_NODE_GUESTOS_RUNTIME_DEPS", "DEPENDENCIES", "GRAFANA_RUNTIME_DEPS", "GUESTOS_RUNTIME_DEPS", "MACRO_DEPENDENCIES", "NNS_CANISTER_RUNTIME_DEPS")
2+
load("//rs/tests:common.bzl", "BOUNDARY_NODE_GUESTOS_RUNTIME_DEPS", "DEPENDENCIES", "GRAFANA_RUNTIME_DEPS", "GUESTOS_RUNTIME_DEPS", "MACRO_DEPENDENCIES", "NNS_CANISTER_RUNTIME_DEPS", "SNS_CANISTER_RUNTIME_DEPS")
33

44
package(default_visibility = ["//visibility:public"])
55

@@ -60,6 +60,23 @@ system_test(
6060
deps = DEPENDENCIES + ["//rs/tests"],
6161
)
6262

63+
system_test(
64+
name = "sns_testing",
65+
flaky = False,
66+
proc_macro_deps = MACRO_DEPENDENCIES,
67+
tags = [
68+
"dynamic_testnet",
69+
"manual",
70+
],
71+
target_compatible_with = ["@platforms//os:linux"], # requires libssh that does not build on Mac OS
72+
runtime_deps = GUESTOS_RUNTIME_DEPS + NNS_CANISTER_RUNTIME_DEPS + SNS_CANISTER_RUNTIME_DEPS + BOUNDARY_NODE_GUESTOS_RUNTIME_DEPS + GRAFANA_RUNTIME_DEPS + [
73+
"@ii_test_canister//file",
74+
"@nns_dapp_canister//file",
75+
"@sns_aggregator//file",
76+
],
77+
deps = DEPENDENCIES + ["//rs/tests"],
78+
)
79+
6380
system_test(
6481
name = "medium",
6582
flaky = False,

rs/tests/testing_verification/testnets/small_nns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn setup(env: TestEnv) {
8989
.use_real_certs_and_dns()
9090
.start(&env)
9191
.expect("failed to setup BoundaryNode VM");
92-
install_ii_and_nns_dapp(&env, BOUNDARY_NODE_NAME);
92+
install_ii_and_nns_dapp(&env, BOUNDARY_NODE_NAME, None);
9393
set_authorized_subnets(&env);
9494
env.sync_prometheus_config_with_topology();
9595
await_boundary_node_healthy(&env, BOUNDARY_NODE_NAME);
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Set up a testnet for SNS testing:
2+
// single 1-node System and two 1-node Application subnets, single unassigned node, single boundary node and a p8s (with grafana) VM.
3+
// All nodes use the following resources: 4 vCPUs, 24GiB of RAM and 50 GiB disk.
4+
//
5+
// In addition to these subnets, this testnet additionally installs the NNS canisters,
6+
// the NNS and II frontend canisters (on the NNS subnet),
7+
// and SNS aggregator canister (on the SNS subnet).
8+
//
9+
// You can setup this testnet by executing the following commands:
10+
//
11+
// $ gitlab-ci/container/container-run.sh
12+
// $ ict testnet sns_testing -- --test_tmpdir=./sns_testing
13+
//
14+
// The --test_tmpdir=./sns_testing will store the test output in the specified directory.
15+
// This is useful to have access to in case you need to SSH into an IC node for example like:
16+
//
17+
// $ ssh -i sns_testing/_tmp/*/setup/ssh/authorized_priv_keys/admin admin@$ipv6
18+
//
19+
// Note that you can get the $ipv6 address of the IC node by looking for a log line like:
20+
//
21+
// Apr 11 15:34:10.175 INFO[rs/tests/src/driver/farm.rs:94:0]
22+
// VM(h2tf2-odxlp-fx5uw-kvn43-bam4h-i4xmw-th7l2-xxwvv-dxxpz-bs3so-iqe)
23+
// Host: ln1-dll10.ln1.dfinity.network
24+
// IPv6: 2a0b:21c0:4003:2:5051:85ff:feec:6864
25+
// vCPUs: 4
26+
// Memory: 25165824 KiB
27+
//
28+
// To get access to P8s and Grafana look for the following log lines:
29+
//
30+
// Apr 11 15:33:58.903 INFO[rs/tests/src/driver/prometheus_vm.rs:168:0]
31+
// Prometheus Web UI at http://prometheus.sns_testing--1681227226065.testnet.farm.dfinity.systems
32+
// Apr 11 15:33:58.903 INFO[rs/tests/src/driver/prometheus_vm.rs:169:0]
33+
// Grafana at http://grafana.sns_testing--1681227226065.testnet.farm.dfinity.systems
34+
// Apr 11 15:33:58.903 INFO[rs/tests/src/driver/prometheus_vm.rs:170:0]
35+
// IC Progress Clock at http://grafana.sns_testing--1681227226065.testnet.farm.dfinity.systems/d/ic-progress-clock/ic-progress-clock?refresh=10s&from=now-5m&to=now
36+
//
37+
// To access the NNS or II dapps look for the following log lines:
38+
//
39+
// 2023-05-03 11:06:27.948 INFO[setup:rs/tests/src/nns_dapp.rs:99:0]
40+
// Internet Identity: https://qhbym-qaaaa-aaaaa-aaafq-cai.ic0.farm.dfinity.systems
41+
// 2023-05-03 11:06:27.948 INFO[setup:rs/tests/src/nns_dapp.rs:103:0]
42+
// NNS frontend dapp: https://qsgjb-riaaa-aaaaa-aaaga-cai.ic0.farm.dfinity.systems
43+
//
44+
// Happy testing!
45+
46+
use anyhow::Result;
47+
48+
use ic_registry_subnet_type::SubnetType;
49+
use ic_tests::driver::{
50+
boundary_node::BoundaryNode,
51+
group::SystemTestGroup,
52+
ic::{InternetComputer, Subnet},
53+
prometheus_vm::{HasPrometheus, PrometheusVm},
54+
test_env::TestEnv,
55+
test_env_api::{
56+
await_boundary_node_healthy, HasTopologySnapshot, IcNodeContainer, NnsCanisterWasmStrategy,
57+
},
58+
};
59+
use ic_tests::nns_dapp::{
60+
install_ii_and_nns_dapp, install_sns_aggregator, nns_dapp_customizations,
61+
set_authorized_subnets, set_sns_subnet,
62+
};
63+
use ic_tests::orchestrator::utils::rw_message::install_nns_with_customizations_and_check_progress;
64+
use ic_tests::sns_client::add_all_wasms_to_sns_wasm;
65+
use slog::info;
66+
67+
const BOUNDARY_NODE_NAME: &str = "boundary-node-1";
68+
69+
fn main() -> Result<()> {
70+
SystemTestGroup::new()
71+
.with_setup(setup)
72+
.execute_from_args()?;
73+
Ok(())
74+
}
75+
76+
pub fn setup(env: TestEnv) {
77+
PrometheusVm::default()
78+
.start(&env)
79+
.expect("Failed to start prometheus VM");
80+
InternetComputer::new()
81+
.add_subnet(Subnet::new(SubnetType::System).add_nodes(1))
82+
.add_subnet(Subnet::new(SubnetType::Application).add_nodes(1))
83+
.add_subnet(Subnet::new(SubnetType::Application).add_nodes(1))
84+
.with_unassigned_nodes(1)
85+
.setup_and_start(&env)
86+
.expect("Failed to setup IC under test");
87+
install_nns_with_customizations_and_check_progress(
88+
env.topology_snapshot(),
89+
NnsCanisterWasmStrategy::TakeBuiltFromSources,
90+
nns_dapp_customizations(),
91+
);
92+
BoundaryNode::new(String::from(BOUNDARY_NODE_NAME))
93+
.allocate_vm(&env)
94+
.expect("Allocation of BoundaryNode failed.")
95+
.for_ic(&env, "")
96+
.use_real_certs_and_dns()
97+
.start(&env)
98+
.expect("failed to setup BoundaryNode VM");
99+
env.sync_prometheus_config_with_topology();
100+
101+
let topology = env.topology_snapshot();
102+
let mut app_subnets = topology
103+
.subnets()
104+
.filter(|s| s.subnet_type() == SubnetType::Application);
105+
let sns_subnet = app_subnets.next().unwrap();
106+
let sns_node = sns_subnet.nodes().next().unwrap();
107+
let app_subnet = app_subnets.next().unwrap();
108+
let app_node = app_subnet.nodes().next().unwrap();
109+
110+
let app_effective_canister_id = app_node.effective_canister_id();
111+
let logger = env.logger();
112+
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);
113+
114+
let sns_aggregator_canister_id = install_sns_aggregator(&env, BOUNDARY_NODE_NAME, sns_node);
115+
install_ii_and_nns_dapp(&env, BOUNDARY_NODE_NAME, Some(sns_aggregator_canister_id));
116+
set_authorized_subnets(&env);
117+
set_sns_subnet(&env, sns_subnet.subnet_id);
118+
add_all_wasms_to_sns_wasm(&env, NnsCanisterWasmStrategy::TakeBuiltFromSources);
119+
120+
await_boundary_node_healthy(&env, BOUNDARY_NODE_NAME);
121+
}

0 commit comments

Comments
 (0)