mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
Fix encode-call CLI options (#868)
* Add tests. * Fix default and conflicting options. * Fix default variant. * Update tests.
This commit is contained in:
committed by
Bastian Köcher
parent
2f1c4c23fc
commit
52e3967a2d
@@ -20,7 +20,7 @@ use relay_substrate_client::Chain;
|
||||
use structopt::{clap::arg_enum, StructOpt};
|
||||
|
||||
/// Encode source chain runtime call.
|
||||
#[derive(StructOpt)]
|
||||
#[derive(StructOpt, Debug)]
|
||||
pub struct EncodeCall {
|
||||
/// A bridge instance to encode call for.
|
||||
#[structopt(possible_values = &EncodeCallBridge::variants(), case_insensitive = true)]
|
||||
@@ -43,10 +43,10 @@ pub enum Call {
|
||||
/// Make an on-chain remark (comment).
|
||||
Remark {
|
||||
/// Explicit remark payload.
|
||||
#[structopt(long, conflicts_with("remark_size"))]
|
||||
remark_payload: HexBytes,
|
||||
#[structopt(long, conflicts_with("remark-size"))]
|
||||
remark_payload: Option<HexBytes>,
|
||||
/// Remark size. If not passed, small UTF8-encoded string is generated by relay as remark.
|
||||
#[structopt(long, conflicts_with("remark_payload"))]
|
||||
#[structopt(long, conflicts_with("remark-payload"))]
|
||||
remark_size: Option<ExplicitOrMaximal<usize>>,
|
||||
},
|
||||
/// Transfer the specified `amount` of native tokens to a particular `recipient`.
|
||||
@@ -165,11 +165,11 @@ pub(crate) fn preprocess_call<Source: CliEncodeCall + CliChain, Target: CliEncod
|
||||
ref remark_size,
|
||||
ref mut remark_payload,
|
||||
} => {
|
||||
if remark_payload.0.is_empty() {
|
||||
*remark_payload = HexBytes(generate_remark_payload(
|
||||
if remark_payload.is_none() {
|
||||
*remark_payload = Some(HexBytes(generate_remark_payload(
|
||||
&remark_size,
|
||||
compute_maximal_message_arguments_size(Source::max_extrinsic_size(), Target::max_extrinsic_size()),
|
||||
));
|
||||
)));
|
||||
}
|
||||
}
|
||||
Call::Transfer { ref mut recipient, .. } => {
|
||||
@@ -246,4 +246,72 @@ mod tests {
|
||||
"0x0c00d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27de5c0"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_encode_remark_with_default_payload() {
|
||||
// given
|
||||
let mut encode_call = EncodeCall::from_iter(vec!["encode-call", "RialtoToMillau", "remark"]);
|
||||
|
||||
// when
|
||||
let hex = encode_call.encode().unwrap();
|
||||
|
||||
// then
|
||||
assert!(format!("{:?}", hex).starts_with("0x070154556e69782074696d653a"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_encode_remark_with_explicit_payload() {
|
||||
// given
|
||||
let mut encode_call = EncodeCall::from_iter(vec![
|
||||
"encode-call",
|
||||
"RialtoToMillau",
|
||||
"remark",
|
||||
"--remark-payload",
|
||||
"1234",
|
||||
]);
|
||||
|
||||
// when
|
||||
let hex = encode_call.encode().unwrap();
|
||||
|
||||
// then
|
||||
assert_eq!(format!("{:?}", hex), "0x0701081234");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_encode_remark_with_size() {
|
||||
// given
|
||||
let mut encode_call =
|
||||
EncodeCall::from_iter(vec!["encode-call", "RialtoToMillau", "remark", "--remark-size", "12"]);
|
||||
|
||||
// when
|
||||
let hex = encode_call.encode().unwrap();
|
||||
|
||||
// then
|
||||
assert_eq!(format!("{:?}", hex), "0x070130000000000000000000000000");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_disallow_both_payload_and_size() {
|
||||
// when
|
||||
let err = EncodeCall::from_iter_safe(vec![
|
||||
"encode-call",
|
||||
"RialtoToMillau",
|
||||
"remark",
|
||||
"--remark-payload",
|
||||
"1234",
|
||||
"--remark-size",
|
||||
"12",
|
||||
])
|
||||
.unwrap_err();
|
||||
|
||||
// then
|
||||
assert_eq!(err.kind, structopt::clap::ErrorKind::ArgumentConflict);
|
||||
assert_eq!(
|
||||
err.info,
|
||||
Some(vec![
|
||||
"remark-size".to_string(),
|
||||
"--remark-payload <remark-payload>".to_string()
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user