Skip to content

Commit

Permalink
Add a command to merge maturity (#48)
Browse files Browse the repository at this point in the history
* Add a command to merge maturity

* test added

* wording

* fix test

Co-authored-by: Christian Müller <[email protected]>
Co-authored-by: Christian Müller <[email protected]>
  • Loading branch information
3 people authored Sep 22, 2021
1 parent f919b7c commit 6bcc82e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quill"
version = "0.2.6"
version = "0.2.7"
authors = ["DFINITY Team"]
edition = "2018"

Expand Down
27 changes: 26 additions & 1 deletion src/commands/neuron_manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,18 @@ pub struct Split {
pub amount_e8s: u64,
}

#[derive(candid::CandidType)]
pub struct MergeMaturity {
pub percentage_to_merge: u32,
}

#[derive(CandidType)]
pub enum Command {
Configure(Configure),
Disburse(Disburse),
Spawn(Spawn),
Split(Split),
MergeMaturity(MergeMaturity),
}

#[derive(CandidType)]
Expand Down Expand Up @@ -112,9 +118,13 @@ pub struct ManageOpts {
#[clap(long)]
spawn: bool,

/// Split off the given number of ICP from a neuron
/// Split off the given number of ICP from a neuron.
#[clap(long)]
split: Option<u64>,

/// Merge the percentage (between 1 and 100) of the maturity of a neuron into the current stake.
#[clap(long)]
merge_maturity: Option<u32>,
}

pub async fn exec(
Expand Down Expand Up @@ -211,6 +221,21 @@ pub async fn exec(
msgs.push(args);
};

if let Some(percentage_to_merge) = opts.merge_maturity {
if percentage_to_merge == 0 || percentage_to_merge > 100 {
return Err(anyhow!(
"Percentage to merge must be a number from 1 to 100"
));
}
let args = Encode!(&ManageNeuron {
id,
command: Some(Command::MergeMaturity(MergeMaturity {
percentage_to_merge
}))
})?;
msgs.push(args);
};

if msgs.is_empty() {
return Err(anyhow!("No instructions provided"));
}
Expand Down
1 change: 1 addition & 0 deletions tests/commands/neuron-manage-merge-maturity.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../target/debug/quill --pem-file - neuron-manage 65 --merge-maturity 100 | ../target/debug/quill send --dry-run -
15 changes: 15 additions & 0 deletions tests/outputs/neuron-manage-merge-maturity.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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 {
id = opt record { id = 65 };
command = opt variant {
MergeMaturity = record { percentage_to_merge = 100 }
};
neuron_id_or_subaccount = null;
},
)
2 changes: 2 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ for f in `ls -1 ./commands/| sort -n`; do
>&2 echo "Test case $f failed."
>&2 echo "Expected output:"
>&2 cat "$expected"
>&2 echo
>&2 echo "Generated output:"
>&2 cat "$out"
>&2 echo
exit 1
fi
tests=$((tests + 1))
Expand Down

0 comments on commit 6bcc82e

Please sign in to comment.