Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
feat: allow specifying canister post-upgrade arg in candid format (#36)
Browse files Browse the repository at this point in the history
* feat: allow specifying canister post-upgrade arg in candid format

Co-authored-by: Martin Raszyk <martin.raszyk@dfinity.org>
  • Loading branch information
mraszyk and mraszyk committed Feb 6, 2023
1 parent ea22f38 commit 3e23f9a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/commands/make_upgrade_canister_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
};
use anyhow::{Context, Error};
use candid::Encode;
use candid::IDLArgs;
use candid::Principal;
use clap::Parser;
use ic_base_types::PrincipalId;
Expand Down Expand Up @@ -45,8 +46,13 @@ pub struct MakeUpgradeCanisterProposalOpts {
#[clap(long)]
wasm_path: String,

/// Path to the file containing argument to post-upgrade method of the new canister WASM.
/// Argument to post-upgrade method of the new canister WASM. The argument must be formatted as a string
/// wrapped candid record.
#[clap(long)]
canister_upgrade_arg: Option<String>,

/// Path to the binary file containing argument to post-upgrade method of the new canister WASM.
#[clap(long, conflicts_with("canister-upgrade-arg"))]
canister_upgrade_arg_path: Option<String>,
}

Expand All @@ -62,16 +68,21 @@ pub fn exec(
summary,
target_canister_id,
wasm_path,
canister_upgrade_arg,
canister_upgrade_arg_path,
} = opts;

let target_canister_id = PrincipalId(Principal::from_text(target_canister_id)?);
let wasm = std::fs::read(wasm_path).context("Unable to read --wasm-path.")?;
let canister_upgrade_arg = match canister_upgrade_arg_path {
Some(path) => {
let canister_upgrade_arg = match (canister_upgrade_arg, canister_upgrade_arg_path) {
(Some(arg), _) => {
let parsed_arg: IDLArgs = arg.parse()?;
Some(parsed_arg.to_bytes()?)
}
(_, Some(path)) => {
Some(std::fs::read(path).context("Unable to read --canister-upgrade-arg-path.")?)
}
None => None,
_ => None,
};

// (Dynamically) come up with a summary if one wasn't provided.
Expand Down
18 changes: 18 additions & 0 deletions tests/commands/make-upgrade-canister-proposal-with-arg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PROPOSER_NEURON_ID=83a7d2b12f654ff58335e5a2512ccae0d7839c744b1807a47c96f5b9f3969069

#$ didc encode '(record {major=2:nat32; minor=3:nat32;})' --format blob
#blob "DIDL\01l\02\b9\fa\ee\18y\b5\f6\a1Cy\01\00\02\00\00\00\03\00\00\00"

${CARGO_TARGET_DIR:-../target}/debug/sns-quill \
--canister-ids-file=./canister_ids.json \
--pem-file=- \
make-upgrade-canister-proposal \
--wasm-path=outputs/canister.wasm \
--canister-upgrade-arg "(record {major=2:nat32; minor=3:nat32;})" \
--target-canister-id=pycv5-3jbbb-ccccc-ddddd-cai \
$PROPOSER_NEURON_ID \
| ${CARGO_TARGET_DIR:-../target}/debug/sns-quill \
send \
--dry-run \
-

25 changes: 25 additions & 0 deletions tests/outputs/make-upgrade-canister-proposal-with-arg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Sending message with

Call type: update
Sender: fdsgv-62ihb-nbiqv-xgic5-iefsv-3cscz-tmbzv-63qd5-vh43v-dqfrt-pae
Canister id: rrkah-fqaaa-aaaaa-aaaaq-cai
Method name: manage_neuron
Arguments: (
record {
subaccount = blob "\83\a7\d2\b1/eO\f5\835\e5\a2Q,\ca\e0\d7\83\9ctK\18\07\a4|\96\f5\b9\f3\96\90i";
command = opt variant {
MakeProposal = record {
url = "";
title = "Upgrade Canister";
action = opt variant {
UpgradeSnsControlledCanister = record {
new_canister_wasm = blob "\00asm\01\00\00\00";
canister_id = opt principal "pycv5-3jbbb-ccccc-ddddd-cai";
canister_upgrade_arg = opt blob "DIDL\01l\02\b9\fa\ee\18y\b5\f6\a1Cy\01\00\02\00\00\00\03\00\00\00";
}
};
summary = "Upgrade canister:\n\n ID: pycv5-3jbbb-ccccc-ddddd-cai\n\n WASM:\n length: 8\n fingerprint: 93a44bbb96c751218e4c00d479e4c14358122a389acca16205b1e4d0dc5f9476";
}
};
},
)

0 comments on commit 3e23f9a

Please sign in to comment.