Skip to content

Commit

Permalink
fix: cli required changes introduced by PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Daanvdplas committed Dec 4, 2024
1 parent 39b26ed commit f0bc925
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 94 deletions.
66 changes: 2 additions & 64 deletions crates/pop-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ impl traits::Cli for Cli {

/// A confirmation prompt using cliclack.
struct Confirm(cliclack::Confirm);

impl traits::Confirm for Confirm {
/// Sets the initially selected value.
fn initial_value(mut self, initial_value: bool) -> Self {
Expand All @@ -145,47 +146,11 @@ impl traits::Confirm for Confirm {
fn interact(&mut self) -> Result<bool> {
self.0.interact()
}
/// Sets the initially selected value.
fn initial_value(mut self, initial_value: bool) -> Self {
self.0 = self.0.initial_value(initial_value);
self
}
}

/// A input prompt using cliclack.
struct Input(cliclack::Input);
impl traits::Input for Input {
/// Sets the default value for the input.
fn default_input(mut self, value: &str) -> Self {
self.0 = self.0.default_input(value);
self
}
/// Starts the prompt interaction.
fn interact(&mut self) -> Result<String> {
self.0.interact()
}
/// Sets the placeholder (hint) text for the input.
fn placeholder(mut self, placeholder: &str) -> Self {
self.0 = self.0.placeholder(placeholder);
self
}
/// Sets whether the input is required.
fn required(mut self, required: bool) -> Self {
self.0 = self.0.required(required);
self
}
/// Sets a validation callback for the input that is called when the user submits.
fn validate(
mut self,
validator: impl Fn(&String) -> std::result::Result<(), &'static str> + 'static,
) -> Self {
self.0 = self.0.validate(validator);
self
}
}

/// A input prompt using cliclack.
struct Input(cliclack::Input);
impl traits::Input for Input {
/// Sets the default value for the input.
fn default_input(mut self, value: &str) -> Self {
Expand Down Expand Up @@ -242,22 +207,7 @@ impl<T: Clone + Eq> traits::MultiSelect<T> for MultiSelect<T> {
struct Select<T: Clone + Eq>(cliclack::Select<T>);

impl<T: Clone + Eq> traits::Select<T> for Select<T> {
/// Starts the prompt interaction.
fn interact(&mut self) -> Result<T> {
self.0.interact()
}

/// Adds an item to the selection prompt.
fn item(mut self, value: T, label: impl Display, hint: impl Display) -> Self {
self.0 = self.0.item(value, label, hint);
self
}
}

/// A select prompt using cliclack.
struct Select<T: Clone + Eq>(cliclack::Select<T>);

impl<T: Clone + Eq> traits::Select<T> for Select<T> {
/// Sets the initially selected value.
fn initial_value(mut self, initial_value: T) -> Self {
self.0 = self.0.initial_value(initial_value);
self
Expand Down Expand Up @@ -355,18 +305,6 @@ pub(crate) mod tests {
self
}

pub(crate) fn expect_select<T>(
mut self,
prompt: impl Display,
required: Option<bool>,
collect: bool,
items: Option<Vec<(String, String)>>,
item: usize,
) -> Self {
self.select_expectation = Some((prompt.to_string(), required, collect, items, item));
self
}

pub(crate) fn expect_success(mut self, message: impl Display) -> Self {
self.success_expectations.push(message.to_string());
self
Expand Down
63 changes: 33 additions & 30 deletions crates/pop-cli/src/commands/call/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ mod tests {
"Do you want to perform another call using the existing smart contract?",
true,
)
.expect_select::<PathBuf>(
.expect_select(
"Select the message to call:",
Some(false),
true,
Expand Down Expand Up @@ -669,26 +669,27 @@ mod tests {
];
// The inputs are processed in reverse order.
let mut cli = MockCli::new()
.expect_input("Signer calling the contract:", "//Alice".into())
.expect_select::<PathBuf>(
.expect_select(
"Select the message to call:",
Some(false),
true,
Some(items),
1, // "get" message
)
.expect_input(
"Provide the on-chain contract address:",
"15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".into(),
"Where is your project or contract artifact located?",
temp_dir.path().join("testing").display().to_string(),
)
.expect_input(
"Where is your contract deployed?",
"wss://rpc1.paseo.popnetwork.xyz".into(),
)
.expect_input(
"Where is your project or contract artifact located?",
temp_dir.path().join("testing").display().to_string(),
).expect_info(format!(
"Provide the on-chain contract address:",
"15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".into(),
)
.expect_input("Signer calling the contract:", "//Alice".into())
.expect_info(format!(
"pop call contract --path {} --contract 15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm --message get --url wss://rpc1.paseo.popnetwork.xyz/ --suri //Alice",
temp_dir.path().join("testing").display().to_string(),
));
Expand Down Expand Up @@ -750,31 +751,32 @@ mod tests {
// The inputs are processed in reverse order.
let mut cli = MockCli::new()
.expect_confirm("Do you want to execute the call? (Selecting 'No' will perform a dry run)", true)
.expect_input("Signer calling the contract:", "//Alice".into())
.expect_input("Enter the proof size limit:", "".into()) // Only if call
.expect_input("Enter the gas limit:", "".into()) // Only if call
.expect_input("Value to transfer to the call:", "50".into()) // Only if payable
.expect_input("Enter the value for the parameter: number", "2".into()) // Args for specific_flip
.expect_input("Enter the value for the parameter: new_value", "true".into()) // Args for specific_flip
.expect_select::<PathBuf>(
.expect_select(
"Select the message to call:",
Some(false),
true,
Some(items),
2, // "specific_flip" message
)
.expect_input(
"Provide the on-chain contract address:",
"15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".into(),
"Where is your project or contract artifact located?",
temp_dir.path().join("testing").display().to_string(),
)
.expect_input(
"Where is your contract deployed?",
"wss://rpc1.paseo.popnetwork.xyz".into(),
)
.expect_input(
"Where is your project or contract artifact located?",
temp_dir.path().join("testing").display().to_string(),
).expect_info(format!(
"Provide the on-chain contract address:",
"15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".into(),
)
.expect_input("Enter the value for the parameter: new_value", "true".into()) // Args for specific_flip
.expect_input("Enter the value for the parameter: number", "2".into()) // Args for specific_flip
.expect_input("Value to transfer to the call:", "50".into()) // Only if payable
.expect_input("Enter the gas limit:", "".into()) // Only if call
.expect_input("Enter the proof size limit:", "".into()) // Only if call
.expect_input("Signer calling the contract:", "//Alice".into())
.expect_info(format!(
"pop call contract --path {} --contract 15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm --message specific_flip --args \"true\", \"2\" --value 50 --url wss://rpc1.paseo.popnetwork.xyz/ --suri //Alice --execute",
temp_dir.path().join("testing").display().to_string(),
));
Expand Down Expand Up @@ -837,29 +839,30 @@ mod tests {
];
// The inputs are processed in reverse order.
let mut cli = MockCli::new()
.expect_input("Signer calling the contract:", "//Alice".into())
.expect_input("Value to transfer to the call:", "50".into()) // Only if payable
.expect_input("Enter the value for the parameter: number", "2".into()) // Args for specific_flip
.expect_input("Enter the value for the parameter: new_value", "true".into()) // Args for specific_flip
.expect_select::<PathBuf>(
.expect_select(
"Select the message to call:",
Some(false),
true,
Some(items),
2, // "specific_flip" message
)
.expect_input(
"Provide the on-chain contract address:",
"15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".into(),
"Where is your project or contract artifact located?",
temp_dir.path().join("testing").display().to_string(),
)
.expect_input(
"Where is your contract deployed?",
"wss://rpc1.paseo.popnetwork.xyz".into(),
)
.expect_input(
"Where is your project or contract artifact located?",
temp_dir.path().join("testing").display().to_string(),
).expect_info(format!(
"Provide the on-chain contract address:",
"15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm".into(),
)
.expect_input("Enter the value for the parameter: new_value", "true".into()) // Args for specific_flip
.expect_input("Enter the value for the parameter: number", "2".into()) // Args for specific_flip
.expect_input("Value to transfer to the call:", "50".into()) // Only if payable
.expect_input("Signer calling the contract:", "//Alice".into())
.expect_info(format!(
"pop call contract --path {} --contract 15XausWjFLBBFLDXUSBRfSfZk25warm4wZRV4ZxhZbfvjrJm --message specific_flip --args \"true\", \"2\" --value 50 --url wss://rpc1.paseo.popnetwork.xyz/ --suri //Alice --execute",
temp_dir.path().join("testing").display().to_string(),
));
Expand Down

0 comments on commit f0bc925

Please sign in to comment.