Skip to content

Commit

Permalink
feat: guide user to call a parachain (#316)
Browse files Browse the repository at this point in the history
* feat: guide user for calling a contract

* feat: get metadata contract from the contract path

* refactor: refactor test and validate address input

* fix: apply feedback

* feat: prompt to have another call and skip questions for queries

* refactor: use Cli module instead of cliclack

* test: unit test pop-cli crate

* test: unit contracts crate

* chore: format

* test: refactor and improve test cases

* fix: fix todos and refactor

* test: fix unit test

* feat: parse types of parameters and display it to the user in the placeholder

* refactor: error handling for pop call

* refactor: display call to be executed after guide and reorder

* refactor: when repeat call use same contract values and dont clean screen

* test: add dry-run test

* test: refactor and add more test coverage

* test: more coverage

* fix: unit test

* feat: dev mode to skip certain user prompts

* refactor: test functions, renaming and fix clippy

* refactor: improve devex of pop call contract

* test: adjust tests to refactor

* chore: reset_for_new_call fields

* fix: build contract if has not been built

* refactor: use command state (#338)

Merged set_up_call_config and guide_user_to_call_contract into a single function. Also adds short symbols for arguments.

* fix: automatically add some or none to Option argument

* test: refactor and tests

* refactor: improve code and comments

* fix: renaming and clean code

* chore: option params not mandatory

* fix: parse user inputs for Option arguments in constructor (#335)

* fix: automatically add some or none to Option argument

* fix: tests

* refactor: process_function_args

* test: update tests accordingly last changes

* fix: issue with delimiter

* test: fix unit test

* refactor: renaming and fix comments

* refactor: format types (#339)

Shows the full type representation, making it easier to see the entry format of parameter values.

* fix: logo doesn't show in README

* feat: pop call parachain prototype

* feat: dispaly arguments of extrinsic

* refactor: structure similar to pop call contract

* feat: parse all values for extrinsic/storage

* refactor: signer in common

* refactor: improve messages

* feat: call parachain ui

* fix: calls working

* refactor: remove unused code

* refactor: remove unused code

* refactor: various fixes

* refactor: various fixes

* feat: add option to include params from command line

* refactor: clean docs and refactor code

* fix: tests

* refactor: parse all the metadata again

* refactor: reorganize and clean metadata functions

* feat: display specific use cases to the user

* refactor: predefined actions

* fix: various fixes

* fix: error message not supported for complex types

* refactor: parse all metadata, including parameters at once

* refactor: clean docs and move code

* fix: format_type

* fix: parse user inputs for Option arguments (#332)

* fix: automatically add some or none to Option argument

* test: refactor and tests

* refactor: improve code and comments

* fix: renaming and clean code

* chore: option params not mandatory

* fix: parse user inputs for Option arguments in constructor (#335)

* fix: automatically add some or none to Option argument

* fix: tests

* refactor: process_function_args

* test: update tests accordingly last changes

* fix: issue with delimiter

* test: fix unit test

* refactor: renaming and fix comments

* refactor: format types (#339)

Shows the full type representation, making it easier to see the entry format of parameter values.

* fix: logo doesn't show in README

---------

Co-authored-by: Frank Bell <60948618+evilrobot-01@users.noreply.github.com>
Co-authored-by: Alejandro Martinez Andres <11448715+al3mart@users.noreply.github.com>

* test: fix unit test

* refactor: clean the way to parse and prompt parameters

* feat: add Purchase on-demand coretime use cases

* test: add skip_confirm, move when prompt for the signer and create the integration test

* test: call parachain ui unit test

* refactor: separate structs

* fmt

* test: pop-cli unit testing

* test: pop-common unit tests

* test: parse metadata unit tests

* test: refactor and test processing parameters

* test: comments and unit test in call functions

* fix: clippy warnings

* chore: fmt

* fix: solve conflicts and unit tests (#359)

* test: call parachain ui unit test

* test: pop-cli unit testing

* test: pop-common unit tests

* test: parse metadata unit tests

* test: refactor and test processing parameters

* test: comments and unit test in call functions

* fix: clippy warnings

* chore: fmt

* fix: conflicts and unit tests

* test: remove test and improve test

* feat: guide user for calling a contract

* feat: get metadata contract from the contract path

* refactor: refactor test and validate address input

* fix: apply feedback

* feat: prompt to have another call and skip questions for queries

* refactor: use Cli module instead of cliclack

* test: unit test pop-cli crate

* test: unit contracts crate

* chore: format

* test: refactor and improve test cases

* fix: fix todos and refactor

* test: fix unit test

* feat: parse types of parameters and display it to the user in the placeholder

* refactor: error handling for pop call

* refactor: display call to be executed after guide and reorder

* refactor: when repeat call use same contract values and dont clean screen

* test: add dry-run test

* test: refactor and add more test coverage

* test: more coverage

* fix: unit test

* feat: dev mode to skip certain user prompts

* refactor: test functions, renaming and fix clippy

* refactor: improve devex of pop call contract

* test: adjust tests to refactor

* chore: reset_for_new_call fields

* fix: build contract if has not been built

* refactor: use command state (#338)

Merged set_up_call_config and guide_user_to_call_contract into a single function. Also adds short symbols for arguments.

* fix: automatically add some or none to Option argument

* test: refactor and tests

* refactor: improve code and comments

* fix: renaming and clean code

* chore: option params not mandatory

* fix: parse user inputs for Option arguments in constructor (#335)

* fix: automatically add some or none to Option argument

* fix: tests

* refactor: process_function_args

* test: update tests accordingly last changes

* fix: issue with delimiter

* test: fix unit test

* refactor: renaming and fix comments

* refactor: format types (#339)

Shows the full type representation, making it easier to see the entry format of parameter values.

* feat: pop call parachain prototype

* feat: dispaly arguments of extrinsic

* refactor: structure similar to pop call contract

* feat: parse all values for extrinsic/storage

* refactor: signer in common

* refactor: improve messages

* feat: call parachain ui

* fix: calls working

* refactor: remove unused code

* refactor: remove unused code

* refactor: various fixes

* refactor: various fixes

* feat: add option to include params from command line

* refactor: clean docs and refactor code

* fix: tests

* refactor: parse all the metadata again

* refactor: reorganize and clean metadata functions

* feat: display specific use cases to the user

* refactor: predefined actions

* fix: various fixes

* fix: error message not supported for complex types

* refactor: parse all metadata, including parameters at once

* refactor: clean docs and move code

* fix: format_type

* test: fix unit test

* refactor: clean the way to parse and prompt parameters

* feat: add Purchase on-demand coretime use cases

* test: add skip_confirm, move when prompt for the signer and create the integration test

* test: call parachain ui unit test

* test: pop-cli unit testing

* test: pop-common unit tests

* test: parse metadata unit tests

* test: refactor and test processing parameters

* test: comments and unit test in call functions

* fix: clippy warnings

* chore: fmt

* feat: repeat call only if using guide UI

* fix: clippy

* refactor: various improvements

* chore: parser for pallet and extrinsic input names

* refactor: only move to pop_common the needed functions

* refactor: improve test, docs and errors

* test: fix unit tests

* fix: reset_for_new_call when extrinisc is not supported

* fix: build with parachain features

* test: wait before call parachain in integration test

* docs: minor improvements

* test: migrate find_free_port to pop_common

* test: fix increase waiting time

* test: remove unnecesary test case

* refactor: rename api with client

* refactor: naming and docs

* docs: improve docs and missing comments

* test: remove unnecesary verbose

* test: find_free_port

* docs: improve parameter documentation

* test: add missing test to sign_and_submit_extrinsic

* fix: apply feedback from auxiliar PRs, remove unnecesary clones

* docs: public modules

* refactor: clean unused params

* fix: mark all extrinsics that uses calls as parameter as unsupported

* test: fix expect_select

* docs: improve documentation

* feat: submit extrinsic from call_data (#348)

* feat: submit extrinsic from call_data

* test: unit test for initialize_api_client

* test: unit test for send_extrinsic_from_call_data

* fix: CallData struct

* fix: skip_confirm for send_extrinsic_from_call_data

* chore: clippy

* chore: fmt

* refactor: minor doc and naming changes

* refactor: remove unnecesary clones and return early when submit_extrinsic_from_call_data

* chore: fmt

* refactor: split decode_call_data logic outside sign_and_submit_extrinsic_with_call_data

* feat: parse files when the argument values are very big (#363)

* feat: parse files when the argument values are very big

* test: unit test

* chore: fmt

* feat: file logic using the command line

* fix: sequence arguments

* test: fix unit test

* refactor: remove prompting the user if input is file or value

* refactor: parse_extrinsic_arguments

* fix: CI deny

* refactor: reorder Param  derive macros

* test: fix decode_call_data_works unit test

* refactor: use Default derive macro and define constants for test values (#366)

* feat: parse files when the argument values are very big

* chore: fmt

* feat: file logic using the command line

* fix: sequence arguments

* refactor: parse_extrinsic_arguments

* refactor: use Default in pop_parachain structs

* refactor: use Default in CallParachainCommand struct

* refactor: use constant in tests

* chore: fmt and small refactor

* feat: flag sudo to wrap extrinsic (#349)

* feat: submit extrinsic from call_data

* test: unit test for initialize_api_client

* feat: wrap call into a sudo call

* test: add unit test to the new logic

* fix: skip_confirm for send_extrinsic_from_call_data

* chore: clippy

* docs: renaming and improve docs

* test: use force_transfer for testing

* fix: check if sudo exist before prompt the user

* chore: fmt

* chore: fmt

* test: fix wrong assert

* docs: improve comments and output messages

* refactor: split decode_call_data logic outside sign_and_submit_extrinsic_with_call_data

* fix: test construct_sudo_extrinsic_works and formatting

* refactor: various fixes and improvements (#367)

* refactor: sort pallets/dispatchables

* refactor: remove unnecessary async

* fix: resolve issue after rebase

* fix: more async issues after rebase

* refactor: use single constant

* refactor: terminology (#368)

* refactor: terminology

* refactor: simply pallet/function relationship

* fix: amend call_data conflicts after refactor

* refactor: improvements (#370)

* fix: add missing short arg option

* refactor: note that extrinsic wait includes finalization

* refactor: remove clones

* style: formatting

* refactor: make file prompt more generic

* refactor: add missing license headers

* style: formatting

* docs: comments

* docs: comments

* docs: comments

* refactor: reuse existing metadata

* refactor: minimise clones

* docs: comments

* refactor: naming

* docs: fix parameter doc comments

* refactor: address clippy warnings

* refactor: rename parachain with chain as the primary command and retain parachain as an alias (#373)

* refactor: rename parachain with chain in visible messages

* refactor: rename parachain with chain internal code

* chore: solve fmt after rebase

* refactor: small fix, use alias instead aliases

* refactor: rename CallParachain struct into Call

---------

Co-authored-by: Frank Bell <60948618+evilrobot-01@users.noreply.github.com>
Co-authored-by: Alejandro Martinez Andres <11448715+al3mart@users.noreply.github.com>
Co-authored-by: Daanvdplas <daanvdplas@live.nl>
  • Loading branch information
4 people committed Dec 15, 2024
1 parent d2bbc5f commit 018e8b1
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 45 deletions.
114 changes: 101 additions & 13 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ indexmap = "2.2"
toml_edit = { version = "0.22", features = ["serde"] }
symlink = "0.1"
scale-info = { version = "2.11.3", default-features = false, features = ["derive"] }
scale-value = { version = "0.16.2", default-features = false, features = ["from-string", "parser-ss58"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
serde = { version = "1.0", features = ["derive"] }
zombienet-sdk = "0.2.18"
Expand Down
40 changes: 23 additions & 17 deletions crates/pop-cli/src/commands/call/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ impl CallChainCommand {
break;
}

if !prompt_to_repeat_call ||
!cli.confirm("Do you want to perform another call?")
if !prompt_to_repeat_call
|| !cli
.confirm("Do you want to perform another call?")
.initial_value(false)
.interact()?
{
Expand Down Expand Up @@ -200,8 +201,9 @@ impl CallChainCommand {
// Resolve who is signing the extrinsic.
let suri = match self.suri.as_ref() {
Some(suri) => suri.clone(),
None =>
cli.input("Signer of the extrinsic:").default_input(DEFAULT_URI).interact()?,
None => {
cli.input("Signer of the extrinsic:").default_input(DEFAULT_URI).interact()?
},
};

return Ok(Call {
Expand All @@ -228,8 +230,9 @@ impl CallChainCommand {
None => &cli.input("Signer of the extrinsic:").default_input(DEFAULT_URI).interact()?,
};
cli.info(format!("Encoded call data: {}", call_data))?;
if !self.skip_confirm &&
!cli.confirm("Do you want to submit the extrinsic?")
if !self.skip_confirm
&& !cli
.confirm("Do you want to submit the extrinsic?")
.initial_value(true)
.interact()?
{
Expand Down Expand Up @@ -257,22 +260,24 @@ impl CallChainCommand {
// execute the call via `sudo`.
fn configure_sudo(&mut self, chain: &Chain, cli: &mut impl Cli) -> Result<()> {
match find_dispatchable_by_name(&chain.pallets, "Sudo", "sudo") {
Ok(_) =>
Ok(_) => {
if !self.sudo {
self.sudo = cli
.confirm(
"Would you like to dispatch this function call with `Root` origin?",
)
.initial_value(false)
.interact()?;
},
Err(_) =>
}
},
Err(_) => {
if self.sudo {
cli.warning(
"NOTE: sudo is not supported by the chain. Ignoring `--sudo` flag.",
)?;
self.sudo = false;
},
}
},
}
Ok(())
}
Expand All @@ -287,11 +292,11 @@ impl CallChainCommand {

// Function to check if all required fields are specified.
fn requires_user_input(&self) -> bool {
self.pallet.is_none() ||
self.function.is_none() ||
self.args.is_empty() ||
self.url.is_none() ||
self.suri.is_none()
self.pallet.is_none()
|| self.function.is_none()
|| self.args.is_empty()
|| self.url.is_none()
|| self.suri.is_none()
}

/// Replaces file arguments with their contents, leaving other arguments unchanged.
Expand Down Expand Up @@ -371,8 +376,9 @@ impl Call {
tx: DynamicPayload,
cli: &mut impl Cli,
) -> Result<()> {
if !self.skip_confirm &&
!cli.confirm("Do you want to submit the extrinsic?")
if !self.skip_confirm
&& !cli
.confirm("Do you want to submit the extrinsic?")
.initial_value(true)
.interact()?
{
Expand Down
2 changes: 1 addition & 1 deletion crates/pop-contracts/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ mod tests {
use crate::{
contracts_node_generator, dry_run_gas_estimate_instantiate, errors::Error,
instantiate_smart_contract, mock_build_process, new_environment, run_contracts_node,
set_up_deployment, testing::find_free_port, UpOpts,
set_up_deployment, UpOpts,
};
use anyhow::Result;
use pop_common::{find_free_port, set_executable_permission};
Expand Down
2 changes: 1 addition & 1 deletion crates/pop-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub use new::{create_smart_contract, is_valid_contract_name};
pub use node::{contracts_node_generator, is_chain_alive, run_contracts_node};
pub use templates::{Contract, ContractType};
pub use test::{test_e2e_smart_contract, test_smart_contract};
pub use testing::{find_free_port, mock_build_process, new_environment};
pub use testing::{mock_build_process, new_environment};
pub use up::{
dry_run_gas_estimate_instantiate, dry_run_upload, get_code_hash_from_event, get_contract_code,
get_instantiate_payload, get_upload_payload, instantiate_contract_signed,
Expand Down
2 changes: 0 additions & 2 deletions crates/pop-contracts/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ fn release_directory_by_target(tag: Option<&str>) -> Result<&'static str, Error>

#[cfg(test)]
mod tests {
use crate::testing::find_free_port;

use super::*;
use anyhow::{Error, Result};
use pop_common::find_free_port;
Expand Down
10 changes: 0 additions & 10 deletions crates/pop-contracts/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{create_smart_contract, Contract};
use anyhow::Result;
use std::{
fs::{copy, create_dir},
net::TcpListener,
path::Path,
};

Expand Down Expand Up @@ -38,12 +37,3 @@ where
copy(metadata_file, target_contract_dir.join("ink/testing.json"))?;
Ok(())
}

/// Finds an available port by binding to port 0 and retrieving the assigned port.
pub fn find_free_port() -> u16 {
TcpListener::bind("127.0.0.1:0")
.expect("Failed to bind to an available port")
.local_addr()
.expect("Failed to retrieve local address")
.port()
}
2 changes: 1 addition & 1 deletion crates/pop-contracts/src/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ mod tests {
use super::*;
use crate::{
contracts_node_generator, errors::Error, mock_build_process, new_environment,
run_contracts_node, testing::find_free_port,
run_contracts_node,
};
use anyhow::Result;
use pop_common::{find_free_port, set_executable_permission};
Expand Down

0 comments on commit 018e8b1

Please sign in to comment.