Skip to content

Commit

Permalink
Migrate stable memory tests to v8 (#2303)
Browse files Browse the repository at this point in the history
This PR migrates all of the stable memory back-up tests to storage
layout v8.
  • Loading branch information
frederikrothenberger committed Feb 26, 2024
1 parent 3f7aa6b commit 27eaeb4
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 163 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
163 changes: 8 additions & 155 deletions src/internet_identity/tests/integration/archive_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,6 @@ use std::collections::HashMap;
use std::time::Duration;
use std::time::SystemTime;

fn setup_ii_from_v7(arg: Option<InternetIdentityInit>) -> (StateMachine, CanisterId) {
let env = env();
let ii_canister = install_ii_canister(&env, EMPTY_WASM.clone());
// since II by default initializes to v8, we load a v7 state
restore_compressed_stable_memory(&env, ii_canister, "stable_memory/clean_init_v7.bin.gz");
upgrade_ii_canister_with_arg(
&env,
ii_canister,
II_WASM.clone(),
arg.or(arg_with_wasm_hash(ARCHIVE_WASM.clone())),
)
.expect("II upgrade failed");
// II will migrate automatically to v8
assert_eq!(
ii_api::stats(&env, ii_canister)
.unwrap()
.storage_layout_version,
8
);
(env, ii_canister)
}

fn setup_ii_v8(arg: Option<InternetIdentityInit>) -> (StateMachine, CanisterId) {
let env = env();
let ii_canister = install_ii_canister_with_arg(
Expand All @@ -56,12 +34,6 @@ fn setup_ii_v8(arg: Option<InternetIdentityInit>) -> (StateMachine, CanisterId)
mod deployment_tests {
use super::*;

#[test]
fn should_deploy_archive_v7() {
let (env, ii_canister) = setup_ii_from_v7(None);
should_deploy_archive(&env, ii_canister);
}

#[test]
fn should_deploy_archive_v8() {
let (env, ii_canister) = setup_ii_v8(None);
Expand All @@ -74,22 +46,6 @@ mod deployment_tests {
assert!(matches!(result, DeployArchiveResult::Success(_)));
}

#[test]
fn should_deploy_archive_with_cycles_v7() {
let (env, ii_canister) = setup_ii_from_v7(Some(InternetIdentityInit {
archive_config: Some(ArchiveConfig {
module_hash: archive_wasm_hash(&ARCHIVE_WASM),
entries_buffer_limit: 0,
polling_interval_ns: 0,
entries_fetch_limit: 0,
}),
canister_creation_cycles_cost: Some(100_000_000_000), // current cost in application subnets
..InternetIdentityInit::default()
}));

should_deploy_archive_with_cycles(&env, ii_canister);
}

#[test]
fn should_deploy_archive_with_cycles_v8() {
let (env, ii_canister) = setup_ii_v8(Some(InternetIdentityInit {
Expand All @@ -115,12 +71,6 @@ mod deployment_tests {
assert_eq!(env.cycle_balance(ii_canister), 50_000_000_000);
}

#[test]
fn should_not_deploy_wrong_wasm_v7() {
let (env, ii_canister) = setup_ii_from_v7(None);
should_not_deploy_wrong_wasm(&env, ii_canister);
}

#[test]
fn should_not_deploy_wrong_wasm_v8() {
let (env, ii_canister) = setup_ii_v8(None);
Expand All @@ -136,12 +86,6 @@ mod deployment_tests {
assert!(stats.archive_info.archive_canister.is_none());
}

#[test]
fn should_not_deploy_archive_when_disabled_v7() {
let (env, ii_canister) = setup_ii_from_v7(Some(InternetIdentityInit::default()));
should_not_deploy_archive_when_disabled(&env, ii_canister);
}

#[test]
fn should_not_deploy_archive_when_disabled_v8() {
let (env, ii_canister) = setup_ii_v8(Some(InternetIdentityInit::default()));
Expand All @@ -157,12 +101,6 @@ mod deployment_tests {
assert!(stats.archive_info.archive_canister.is_none());
}

#[test]
fn should_keep_archive_module_hash_across_upgrades_v7() {
let (env, ii_canister) = setup_ii_from_v7(None);
should_keep_archive_module_hash_across_upgrades(&env, ii_canister);
}

#[test]
fn should_keep_archive_module_hash_across_upgrades_v8() {
let (env, ii_canister) = setup_ii_v8(None);
Expand All @@ -180,12 +118,6 @@ mod deployment_tests {
assert!(matches!(result, DeployArchiveResult::Success(_)));
}

#[test]
fn should_upgrade_the_archive_v7() {
let (env, ii_canister) = setup_ii_from_v7(arg_with_wasm_hash(EMPTY_WASM.clone()));
should_upgrade_the_archive(&env, ii_canister);
}

#[test]
fn should_upgrade_the_archive_v8() {
let (env, ii_canister) = setup_ii_v8(arg_with_wasm_hash(EMPTY_WASM.clone()));
Expand Down Expand Up @@ -217,12 +149,6 @@ mod deployment_tests {
assert_eq!(entries.entries.len(), 0);
}

#[test]
fn should_upgrade_archive_with_only_config_changed_v7() {
let (env, ii_canister) = setup_ii_from_v7(None);
should_upgrade_archive_with_only_config_changed(&env, ii_canister);
}

#[test]
fn should_upgrade_archive_with_only_config_changed_v8() {
let (env, ii_canister) = setup_ii_v8(None);
Expand Down Expand Up @@ -273,12 +199,6 @@ mod deployment_tests {
mod pull_entries_tests {
use super::*;

#[test]
fn should_record_anchor_operations_v7() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_from_v7(None);
should_record_anchor_operations(&env, ii_canister)
}

#[test]
fn should_record_anchor_operations_v8() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_v8(None);
Expand Down Expand Up @@ -327,15 +247,17 @@ mod pull_entries_tests {
}

#[test]
fn should_migrate_stable_memory_with_archive_buffer() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_from_v7(None);
let archive_canister = deploy_archive_via_ii(&env, ii_canister);
fn should_restore_archive_buffer_from_stable_memory_backup() -> Result<(), CallError> {
let env = env();
let ii_canister = install_ii_canister(&env, EMPTY_WASM.clone());
// re-create the archive canister with the new II to match the restored backup
env.create_canister(Some(ii_canister));

// restore stable memory backup with buffered entries in persistent state
restore_compressed_stable_memory(
&env,
ii_canister,
"stable_memory/buffered_archive_entries_v7.bin.gz",
"stable_memory/buffered_archive_entries_v8.bin.gz",
);
upgrade_ii_canister_with_arg(
&env,
Expand All @@ -350,6 +272,8 @@ mod pull_entries_tests {
.storage_layout_version,
8
);
// deploy the actual archive wasm
let archive_canister = deploy_archive_via_ii(&env, ii_canister);

let timestamp = env
.time()
Expand Down Expand Up @@ -459,12 +383,6 @@ mod pull_entries_tests {
Ok(())
}

#[test]
fn should_record_metadata_for_new_device_v7() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_from_v7(None);
should_record_metadata_for_new_device(&env, ii_canister)
}

#[test]
fn should_record_metadata_for_new_device_v8() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_v8(None);
Expand Down Expand Up @@ -516,12 +434,6 @@ mod pull_entries_tests {
Ok(())
}

#[test]
fn should_record_metadata_change_v7() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_from_v7(None);
should_record_metadata_change(&env, ii_canister)
}

#[test]
fn should_record_metadata_change_v8() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_v8(None);
Expand Down Expand Up @@ -592,12 +504,6 @@ mod pull_entries_tests {
Ok(())
}

#[test]
fn should_record_identity_metadata_replace_v7() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_from_v7(None);
should_record_identity_metadata_replace(&env, ii_canister)
}

#[test]
fn should_record_identity_metadata_replace_v8() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_v8(None);
Expand Down Expand Up @@ -659,12 +565,6 @@ mod pull_entries_tests {
Ok(())
}

#[test]
fn should_fetch_multiple_times_v7() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_from_v7(None);
should_fetch_multiple_times(&env, ii_canister)
}

#[test]
fn should_fetch_multiple_times_v8() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_v8(None);
Expand Down Expand Up @@ -701,12 +601,6 @@ mod pull_entries_tests {
Ok(())
}

#[test]
fn should_succeed_on_empty_fetch_result_v7() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_from_v7(None);
should_succeed_on_empty_fetch_result(&env, ii_canister)
}

#[test]
fn should_succeed_on_empty_fetch_result_v8() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_v8(None);
Expand Down Expand Up @@ -741,12 +635,6 @@ mod pull_entries_tests {
Ok(())
}

#[test]
fn should_report_correct_number_of_fetched_entries_v7() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_from_v7(None);
should_report_correct_number_of_fetched_entries(&env, ii_canister)
}

#[test]
fn should_report_correct_number_of_fetched_entries_v8() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_v8(None);
Expand Down Expand Up @@ -804,11 +692,6 @@ mod pull_entries_tests {
Ok(())
}

#[test]
fn should_report_archive_config_metrics_v7() {
let (env, ii_canister) = setup_ii_from_v7(None);
should_report_archive_config_metrics(&env, ii_canister)
}
#[test]
fn should_report_archive_config_metrics_v8() {
let (env, ii_canister) = setup_ii_v8(None);
Expand Down Expand Up @@ -846,11 +729,6 @@ mod pull_entries_tests {
);
}

#[test]
fn should_report_archive_entries_metrics_v7() {
let (env, ii_canister) = setup_ii_from_v7(None);
should_report_archive_entries_metrics(&env, ii_canister)
}
#[test]
fn should_report_archive_entries_metrics_v8() {
let (env, ii_canister) = setup_ii_v8(None);
Expand Down Expand Up @@ -921,11 +799,6 @@ mod pull_entries_tests {
);
}

#[test]
fn should_report_call_errors_v7() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_from_v7(None);
should_report_call_errors(&env, ii_canister)
}
#[test]
fn should_report_call_errors_v8() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_v8(None);
Expand Down Expand Up @@ -970,11 +843,6 @@ mod pull_entries_tests {
Ok(())
}

#[test]
fn should_recover_after_error_v7() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_from_v7(None);
should_recover_after_error(&env, ii_canister)
}
#[test]
fn should_recover_after_error_v8() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_v8(None);
Expand Down Expand Up @@ -1012,11 +880,6 @@ mod pull_entries_tests {
Ok(())
}

#[test]
fn should_return_entries_ordered_v7() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_from_v7(None);
should_return_entries_ordered(&env, ii_canister)
}
#[test]
fn should_return_entries_ordered_v8() -> Result<(), CallError> {
let (env, ii_canister) = setup_ii_v8(None);
Expand All @@ -1042,11 +905,6 @@ mod pull_entries_tests {
Ok(())
}

#[test]
fn should_not_allow_wrong_caller_to_fetch_entries_v7() {
let (env, ii_canister) = setup_ii_from_v7(None);
should_not_allow_wrong_caller_to_fetch_entries(&env, ii_canister);
}
#[test]
fn should_not_allow_wrong_caller_to_fetch_entries_v8() {
let (env, ii_canister) = setup_ii_v8(None);
Expand All @@ -1068,11 +926,6 @@ mod pull_entries_tests {
);
}

#[test]
fn should_not_allow_wrong_caller_to_acknowledge_entries_v7() {
let (env, ii_canister) = setup_ii_from_v7(None);
should_not_allow_wrong_caller_to_acknowledge_entries(&env, ii_canister);
}
#[test]
fn should_not_allow_wrong_caller_to_acknowledge_entries_v8() {
let (env, ii_canister) = setup_ii_v8(None);
Expand Down
Loading

0 comments on commit 27eaeb4

Please sign in to comment.