Skip to content

Commit e6a516e

Browse files
authored
test(sns): Migrate upgrade qualification tests to AdvanceSnsTargetVersion (#2981)
The upgrade tests are implemented by calling `test_sns_upgrade`. This PR changes that function to use the new mechanism rather than the old. I don't think it's necessary to retain test coverage for the old mechanism. [NNS1-3441](https://dfinity.atlassian.net/browse/NNS1-3441) [NNS1-3441]: https://dfinity.atlassian.net/browse/NNS1-3441?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 20d67be commit e6a516e

File tree

7 files changed

+257
-78
lines changed

7 files changed

+257
-78
lines changed

rs/nervous_system/integration_tests/BUILD.bazel

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ rust_test_suite_with_extra_srcs(
176176
"tests/advance_target_version_upgrades_all_canisters_test.rs",
177177
"tests/upgrade_existing_sns_test.rs",
178178
"tests/deploy_fresh_sns_test.rs",
179+
"tests/sns_release_qualification_legacy.rs",
180+
"tests/sns_upgrade_test_utils_legacy.rs",
179181
],
180182
),
181183
aliases = ALIASES,
@@ -259,3 +261,21 @@ rust_test(
259261
],
260262
deps = [":nervous_system_integration_tests"] + DEPENDENCIES_WITH_TEST_FEATURES + DEV_DEPENDENCIES,
261263
)
264+
265+
rust_test(
266+
name = "sns_release_qualification_legacy",
267+
timeout = "long",
268+
srcs = [
269+
"tests/sns_release_qualification_legacy.rs",
270+
"tests/sns_upgrade_test_utils_legacy.rs",
271+
],
272+
aliases = ALIASES,
273+
data = DEV_DATA,
274+
env = DEV_ENV | {"RUST_TEST_NOCAPTURE": "1"},
275+
flaky = True,
276+
proc_macro_deps = MACRO_DEPENDENCIES + MACRO_DEV_DEPENDENCIES,
277+
tags = [
278+
"cpu:4",
279+
],
280+
deps = [":nervous_system_integration_tests"] + DEPENDENCIES_WITH_TEST_FEATURES + DEV_DEPENDENCIES,
281+
)

rs/nervous_system/integration_tests/src/pocket_ic_helpers.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,33 @@ pub fn extract_sns_canister_version(
9797
}
9898

9999
/// Creates a new PocketIc instance with NNS and SNS and application subnet
100-
pub async fn pocket_ic_for_sns_tests_with_mainnet_versions() -> PocketIc {
100+
pub async fn pocket_ic_for_sns_tests_with_mainnet_versions() -> (PocketIc, SnsWasms) {
101101
let pocket_ic = PocketIcBuilder::new()
102102
.with_nns_subnet()
103103
.with_sns_subnet()
104104
.build_async()
105105
.await;
106106

107107
// Install the (mainnet) NNS canisters.
108-
let with_mainnet_nns_canisters = true;
109-
install_nns_canisters(&pocket_ic, vec![], with_mainnet_nns_canisters, None, vec![]).await;
108+
{
109+
let with_mainnet_nns_canisters = true;
110+
install_nns_canisters(&pocket_ic, vec![], with_mainnet_nns_canisters, None, vec![]).await;
111+
}
110112

111113
// Publish (mainnet) SNS Wasms to SNS-W.
112-
let with_mainnet_sns_wasms = true;
113-
add_wasms_to_sns_wasm(&pocket_ic, with_mainnet_sns_wasms)
114-
.await
115-
.unwrap();
114+
let initial_sns_version = {
115+
let with_mainnet_sns_canisters = true;
116+
let deployed_sns_starting_info =
117+
add_wasms_to_sns_wasm(&pocket_ic, with_mainnet_sns_canisters)
118+
.await
119+
.unwrap();
120+
deployed_sns_starting_info
121+
.into_iter()
122+
.map(|(canister_type, (_, wasm))| (canister_type, wasm))
123+
.collect::<BTreeMap<_, _>>()
124+
};
116125

117-
pocket_ic
126+
(pocket_ic, initial_sns_version)
118127
}
119128

120129
pub async fn install_canister(

rs/nervous_system/integration_tests/tests/deploy_fresh_sns_test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ async fn test_deploy_fresh_sns() {
3434
.collect();
3535

3636
eprintln!("1. Prepare the world (use mainnet WASMs for all NNS and SNS canisters) ...");
37-
let pocket_ic = pocket_ic_helpers::pocket_ic_for_sns_tests_with_mainnet_versions().await;
37+
let (pocket_ic, _initial_sns_version) =
38+
pocket_ic_helpers::pocket_ic_for_sns_tests_with_mainnet_versions().await;
3839

3940
eprintln!("Install the test dapp ...");
4041
for dapp_canister_id in dapp_canister_ids.clone() {

rs/nervous_system/integration_tests/tests/sns_release_qualification.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ async fn test_deployment_swap_upgrade() {
8585

8686
/// Upgrade Tests
8787
88-
// TODO[NNS1-3433]: Enable this test after the SNS Governance canister published to SNS-W on mainnet
89-
// TODO[NNS1-3433]: starts upgrading its Swap.
9088
#[ignore]
9189
#[tokio::test]
9290
async fn test_upgrade_swap() {
@@ -110,7 +108,8 @@ pub async fn test_sns_deployment(
110108
nns_canisters_to_upgrade: Vec<CanisterId>, // should use constants from nns/constants to make this easy to track
111109
sns_canisters_to_upgrade: Vec<SnsCanisterType>,
112110
) {
113-
let pocket_ic = pocket_ic_helpers::pocket_ic_for_sns_tests_with_mainnet_versions().await;
111+
let (pocket_ic, _initial_sns_version) =
112+
pocket_ic_helpers::pocket_ic_for_sns_tests_with_mainnet_versions().await;
114113

115114
let create_service_nervous_system = CreateServiceNervousSystemBuilder::default()
116115
.with_governance_parameters_neuron_minimum_dissolve_delay_to_vote(ONE_MONTH_SECONDS * 6)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use ic_sns_wasm::pb::v1::SnsCanisterType;
2+
3+
mod sns_upgrade_test_utils_legacy;
4+
use sns_upgrade_test_utils_legacy::test_sns_upgrade_legacy;
5+
6+
/// Legacy upgrade Tests
7+
///
8+
#[tokio::test]
9+
async fn test_upgrade_swap() {
10+
test_sns_upgrade_legacy(vec![SnsCanisterType::Swap]).await;
11+
}
12+
13+
#[tokio::test]
14+
async fn test_upgrade_sns_gov_root() {
15+
test_sns_upgrade_legacy(vec![SnsCanisterType::Root, SnsCanisterType::Governance]).await;
16+
}
17+
18+
#[tokio::test]
19+
async fn test_upgrade_upgrade_sns_gov_root() {
20+
test_sns_upgrade_legacy(vec![SnsCanisterType::Governance, SnsCanisterType::Root]).await;
21+
}

rs/nervous_system/integration_tests/tests/sns_upgrade_test_utils.rs

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@ use ic_nervous_system_common::ONE_MONTH_SECONDS;
33
use ic_nervous_system_integration_tests::{
44
create_service_nervous_system_builder::CreateServiceNervousSystemBuilder,
55
pocket_ic_helpers,
6-
pocket_ic_helpers::{add_wasm_via_nns_proposal, nns, sns},
7-
};
8-
use ic_nns_test_utils::sns_wasm::{
9-
build_archive_sns_wasm, build_governance_sns_wasm, build_index_ng_sns_wasm,
10-
build_ledger_sns_wasm, build_root_sns_wasm, build_swap_sns_wasm, create_modified_sns_wasm,
11-
ensure_sns_wasm_gzipped,
6+
pocket_ic_helpers::{
7+
await_with_timeout, hash_sns_wasms, nns, sns,
8+
sns::governance::{
9+
EXPECTED_UPGRADE_DURATION_MAX_SECONDS, EXPECTED_UPGRADE_STEPS_REFRESH_MAX_SECONDS,
10+
},
11+
},
1212
};
13+
use ic_sns_governance::governance::UPGRADE_STEPS_INTERVAL_REFRESH_BACKOFF_SECONDS;
1314
use ic_sns_swap::pb::v1::Lifecycle;
1415
use ic_sns_wasm::pb::v1::SnsCanisterType;
1516

1617
pub async fn test_sns_upgrade(sns_canisters_to_upgrade: Vec<SnsCanisterType>) {
17-
let pocket_ic = pocket_ic_helpers::pocket_ic_for_sns_tests_with_mainnet_versions().await;
18+
let (pocket_ic, initial_sns_version) =
19+
pocket_ic_helpers::pocket_ic_for_sns_tests_with_mainnet_versions().await;
1820

1921
eprintln!("Creating SNS ...");
2022
let create_service_nervous_system = CreateServiceNervousSystemBuilder::default()
@@ -40,51 +42,6 @@ pub async fn test_sns_upgrade(sns_canisters_to_upgrade: Vec<SnsCanisterType>) {
4042
)
4143
.await;
4244

43-
eprintln!("Adding all WASMs ...");
44-
for canister_type in &sns_canisters_to_upgrade {
45-
let wasm = match canister_type {
46-
SnsCanisterType::Root => build_root_sns_wasm(),
47-
SnsCanisterType::Governance => build_governance_sns_wasm(),
48-
SnsCanisterType::Ledger => build_ledger_sns_wasm(),
49-
SnsCanisterType::Swap => build_swap_sns_wasm(),
50-
SnsCanisterType::Index => build_index_ng_sns_wasm(),
51-
SnsCanisterType::Unspecified => {
52-
panic!("Where did you get this canister type from?")
53-
}
54-
SnsCanisterType::Archive => build_archive_sns_wasm(),
55-
};
56-
57-
let wasm = ensure_sns_wasm_gzipped(wasm);
58-
let proposal_info = add_wasm_via_nns_proposal(&pocket_ic, wasm).await.unwrap();
59-
assert_eq!(proposal_info.failure_reason, None);
60-
}
61-
62-
eprintln!("Adding all WASMs with custom metadata ...");
63-
for canister_type in &sns_canisters_to_upgrade {
64-
let wasm = match canister_type {
65-
// Second upgrade with modified wasms
66-
SnsCanisterType::Root => create_modified_sns_wasm(&build_root_sns_wasm(), Some(42)),
67-
SnsCanisterType::Governance => {
68-
create_modified_sns_wasm(&build_governance_sns_wasm(), Some(42))
69-
}
70-
SnsCanisterType::Ledger => create_modified_sns_wasm(&build_ledger_sns_wasm(), Some(42)),
71-
SnsCanisterType::Swap => create_modified_sns_wasm(&build_swap_sns_wasm(), Some(42)),
72-
SnsCanisterType::Index => {
73-
create_modified_sns_wasm(&build_index_ng_sns_wasm(), Some(42))
74-
}
75-
SnsCanisterType::Unspecified => {
76-
panic!("Where did you get this canister type from?")
77-
}
78-
SnsCanisterType::Archive => {
79-
create_modified_sns_wasm(&build_archive_sns_wasm(), Some(42))
80-
}
81-
};
82-
83-
let wasm = ensure_sns_wasm_gzipped(wasm);
84-
let proposal_info = add_wasm_via_nns_proposal(&pocket_ic, wasm).await.unwrap();
85-
assert_eq!(proposal_info.failure_reason, None);
86-
}
87-
8845
// Only spawn an archive if we're testing it
8946
if sns_canisters_to_upgrade.contains(&SnsCanisterType::Archive) {
9047
eprintln!("Testing if the Archive canister is spawned ...");
@@ -109,19 +66,62 @@ pub async fn test_sns_upgrade(sns_canisters_to_upgrade: Vec<SnsCanisterType>) {
10966
)
11067
.await;
11168

112-
// Every canister we are testing has two upgrades. We are just making sure the counts match
113-
for canister_type in &sns_canisters_to_upgrade {
114-
eprintln!(
115-
"1st upgrade_sns_to_next_version_and_assert_change {:?} ...",
116-
canister_type
117-
);
118-
sns::upgrade_sns_to_next_version_and_assert_change(&pocket_ic, &sns, *canister_type).await;
119-
}
120-
for canister_type in sns_canisters_to_upgrade {
121-
eprintln!(
122-
"2nd upgrade_sns_to_next_version_and_assert_change {:?} ...",
123-
canister_type
124-
);
125-
sns::upgrade_sns_to_next_version_and_assert_change(&pocket_ic, &sns, canister_type).await;
69+
let mut latest_sns_version = initial_sns_version;
70+
71+
for upgrade_pass in 0..2 {
72+
eprintln!("Upgrade pass {}", upgrade_pass);
73+
74+
eprintln!("Adding all WASMs ...");
75+
for canister_type in &sns_canisters_to_upgrade {
76+
eprintln!("modify_and_add_wasm for {:?} ...", canister_type);
77+
latest_sns_version = nns::sns_wasm::modify_and_add_wasm(
78+
&pocket_ic,
79+
latest_sns_version,
80+
*canister_type,
81+
upgrade_pass,
82+
)
83+
.await;
84+
}
85+
86+
eprintln!("wait for the upgrade steps to be refreshed ...");
87+
let latest_sns_version_hash = hash_sns_wasms(&latest_sns_version);
88+
await_with_timeout(
89+
&pocket_ic,
90+
UPGRADE_STEPS_INTERVAL_REFRESH_BACKOFF_SECONDS
91+
..EXPECTED_UPGRADE_STEPS_REFRESH_MAX_SECONDS,
92+
|pocket_ic| async {
93+
sns::governance::try_get_upgrade_journal(pocket_ic, sns.governance.canister_id)
94+
.await
95+
.ok()
96+
.and_then(|journal| journal.upgrade_steps)
97+
.and_then(|upgrade_steps| upgrade_steps.versions.last().cloned())
98+
},
99+
&Some(latest_sns_version_hash.clone()),
100+
)
101+
.await
102+
.unwrap();
103+
104+
eprintln!("advance the target version to the latest version. ...");
105+
sns::governance::propose_to_advance_sns_target_version(
106+
&pocket_ic,
107+
sns.governance.canister_id,
108+
)
109+
.await
110+
.unwrap();
111+
112+
eprintln!("wait for the upgrade to happen ...");
113+
await_with_timeout(
114+
&pocket_ic,
115+
0..EXPECTED_UPGRADE_DURATION_MAX_SECONDS,
116+
|pocket_ic| async {
117+
let journal =
118+
sns::governance::try_get_upgrade_journal(pocket_ic, sns.governance.canister_id)
119+
.await;
120+
journal.ok().and_then(|journal| journal.deployed_version)
121+
},
122+
&Some(latest_sns_version_hash.clone()),
123+
)
124+
.await
125+
.unwrap();
126126
}
127127
}

0 commit comments

Comments
 (0)