@@ -3,18 +3,20 @@ use ic_nervous_system_common::ONE_MONTH_SECONDS;
33use 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 ;
1314use ic_sns_swap:: pb:: v1:: Lifecycle ;
1415use ic_sns_wasm:: pb:: v1:: SnsCanisterType ;
1516
1617pub 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