Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion rs/nns/sns-wasm/src/sns_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1940,14 +1940,15 @@ impl UpgradePath {
.or_default()
.entry(from)
{
Entry::Occupied(occupied) => {
Entry::Occupied(mut occupied) => {
println!(
"Special Entry for {} from {:?} to {:?} is being overwritten with new value {:?}",
sns_governance_canister_id,
occupied.key(),
occupied.get(),
to
);
occupied.insert(to);
}
Entry::Vacant(vacant) => {
vacant.insert(to);
Expand Down Expand Up @@ -5646,4 +5647,45 @@ mod test {
);
}
}

#[test]
fn test_insert_sns_specific_upgrade_path_entry_overwrites_existing_entry() {
let sns_governance_canister_id = CanisterId::from_u64(1000);
let from_version = SnsVersion {
governance_wasm_hash: vec![1],
..Default::default()
};
let first_to_version = SnsVersion {
governance_wasm_hash: vec![2],
..Default::default()
};
let second_to_version = SnsVersion {
governance_wasm_hash: vec![3],
..Default::default()
};

let mut upgrade_path = UpgradePath::default();
upgrade_path.insert_sns_specific_upgrade_path_entry(
from_version.clone(),
first_to_version.clone(),
sns_governance_canister_id,
);
assert_eq!(
upgrade_path.get_next_version(from_version.clone(), sns_governance_canister_id.get()),
Some(first_to_version)
);

// Run code under test: reconfigure the same `from_version` entry with a new target.
upgrade_path.insert_sns_specific_upgrade_path_entry(
from_version.clone(),
second_to_version.clone(),
sns_governance_canister_id,
);

// The entry must reflect the new target, not the stale first one.
assert_eq!(
upgrade_path.get_next_version(from_version, sns_governance_canister_id.get()),
Some(second_to_version)
);
}
}
5 changes: 5 additions & 0 deletions rs/nns/sns-wasm/unreleased_changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ on the process that this file is part of, see

## Fixed

* `insert_sns_specific_upgrade_path_entry` now actually replaces an
SNS-specific emergency upgrade step when called again for the same SNS
and starting version, instead of silently keeping the old step while
reporting success.

## Security
Loading