Skip to content

Commit

Permalink
NNS1-3061: Render the proposal ID in UpgradeSnsToNextVersion proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
anchpop committed May 16, 2024
1 parent 5ba1412 commit 32da77f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion rs/sns/governance/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7070,7 +7070,8 @@ mod tests {
Ok(Encode!(&GetWasmResponse {
wasm: Some(SnsWasm {
wasm: vec![9, 8, 7, 6, 5, 4, 3, 2],
canister_type: expected_canister_to_be_upgraded.into() // Governance
canister_type: expected_canister_to_be_upgraded.into(), // Governance
proposal_id: None,
})
})
.unwrap()),
Expand Down
20 changes: 18 additions & 2 deletions rs/sns/governance/src/proposal.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::sns_upgrade::{get_wasm, SnsWasm};
use crate::{
canister_control::perform_execute_generic_nervous_system_function_validate_and_render_call,
governance::{
Expand Down Expand Up @@ -1082,7 +1083,7 @@ async fn validate_and_render_upgrade_sns_to_next_version(
) -> Result<String, String> {
let UpgradeSnsParams {
next_version,
canister_type_to_upgrade: _,
canister_type_to_upgrade,
new_wasm_hash,
canister_ids_to_upgrade,
} = get_upgrade_params(env, root_canister_id, &current_version)
Expand All @@ -1094,6 +1095,18 @@ async fn validate_and_render_upgrade_sns_to_next_version(
)
})?;

let proposal_id_message = get_wasm(env, new_wasm_hash.to_vec(), canister_type_to_upgrade)
.await
.ok()
.and_then(|SnsWasm { proposal_id, .. }| proposal_id)
.map(|id| {
format!(
"## Proposal ID of the NNS proposal that blessed this WASM version: NNS Proposal {}",
id
)
})
.unwrap_or_default();

// TODO display the hashes for current version and new version
Ok(format!(
r"# Proposal to upgrade SNS to next version:
Expand All @@ -1106,6 +1119,7 @@ async fn validate_and_render_upgrade_sns_to_next_version(
## Canisters to be upgraded: {}
## Upgrade Version: {}
{proposal_id_message}
",
render_version(&current_version),
render_version(&next_version),
Expand Down Expand Up @@ -3118,7 +3132,8 @@ mod tests {
Ok(Encode!(&GetWasmResponse {
wasm: Some(SnsWasm {
wasm: vec![9, 8, 7, 6, 5, 4, 3, 2],
canister_type: expected_canister_to_be_upgraded.into() // Governance
canister_type: expected_canister_to_be_upgraded.into(), // Governance
proposal_id: Some(2),
})
})
.unwrap()),
Expand Down Expand Up @@ -3170,6 +3185,7 @@ Version {
## Canisters to be upgraded: q7t5l-saaaa-aaaaa-aah2a-cai
## Upgrade Version: 67586e98fad27da0b9968bc039a1ef34c939b9b8e523a8bef89d478608c5ecf6
## Proposal ID of the NNS proposal that blessed this WASM version: NNS Proposal 2
";
assert_eq!(actual_text, expected_text);
}
Expand Down
3 changes: 3 additions & 0 deletions rs/sns/governance/src/sns_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,12 @@ pub(crate) struct GetWasmResponse {
#[derive(candid::CandidType, candid::Deserialize, Clone, PartialEq, ::prost::Message)]
pub(crate) struct SnsWasm {
#[prost(bytes = "vec", tag = "1")]
#[serde(with = "serde_bytes")]
pub wasm: ::prost::alloc::vec::Vec<u8>,
#[prost(enumeration = "SnsCanisterType", tag = "2")]
pub canister_type: i32,
#[prost(uint64, optional, tag = "3")]
pub proposal_id: ::core::option::Option<u64>,
}
/// Copied from ic-sns-wasm
/// The type of canister a particular WASM is intended to be installed on.
Expand Down

0 comments on commit 32da77f

Please sign in to comment.