Skip to content

Commit

Permalink
feat: guide user for calling a contract
Browse files Browse the repository at this point in the history
feat: get metadata contract from the contract path

refactor: refactor test and validate address input

test: unit test pop-cli crate

test: unit contracts crate

test: refactor and improve test cases

fix: fix todos and refactor

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

test: more coverage

refactor: test functions, renaming and fix clippy

fix: build contract if has not been built

fix: automatically add some or none to Option argument

test: refactor and tests

refactor: improve code and comments

fix: renaming and clean code

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

* fix: automatically add some or none to Option argument

* fix: tests

test: update tests accordingly last changes

fix: issue with delimiter

test: fix unit test

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

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: parse metadata unit tests

fix: clippy warnings

chore: fmt

feat: guide user for calling a contract

feat: get metadata contract from the contract path

refactor: refactor test and validate address input

test: unit test pop-cli crate

test: unit contracts crate

test: refactor and improve test cases

fix: fix todos and refactor

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

test: more coverage

refactor: test functions, renaming and fix clippy

fix: automatically add some or none to Option argument

test: refactor and tests

refactor: improve code and comments

fix: renaming and clean code

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

* fix: automatically add some or none to Option argument

* fix: tests

test: update tests accordingly last changes

test: fix unit test

feat: pop call parachain prototype

feat: parse all values for extrinsic/storage

refactor: signer in common

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

fix: various fixes

fix: error message not supported for complex types

refactor: clean docs and move code

fix: format_type

test: fix unit test

refactor: clean the way to parse and prompt parameters

test: parse metadata unit tests

fix: clippy warnings

chore: fmt

feat: repeat call only if using guide UI

fix: clippy

chore: parser for pallet and extrinsic input names

refactor: only move to pop_common the needed functions

refactor: improve test, docs and errors

docs: minor improvements

test: migrate find_free_port to pop_common

test: find_free_port

test: add missing test to sign_and_submit_extrinsic

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: 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

feat: events call parachain

docs: add comment

show alex

remove old test code

refactor: generic sign and submit

refactor: remove unnecessary function

style: generic name

fix: spinner
  • Loading branch information
AlexD10S authored and Daanvdplas committed Dec 17, 2024
1 parent e99f719 commit ffb0393
Show file tree
Hide file tree
Showing 11 changed files with 402 additions and 53 deletions.
27 changes: 27 additions & 0 deletions Cargo.lock

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

41 changes: 27 additions & 14 deletions crates/pop-cli/src/commands/call/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use clap::Args;
use pop_parachains::{
construct_extrinsic, construct_sudo_extrinsic, decode_call_data, encode_call_data,
find_dispatchable_by_name, find_pallet_by_name, parse_chain_metadata, set_up_client,
sign_and_submit_extrinsic, sign_and_submit_extrinsic_with_call_data, supported_actions, Action,
DynamicPayload, Function, OnlineClient, Pallet, Param, SubstrateConfig,
sign_and_submit_extrinsic, supported_actions, Action, CallData, DynamicPayload, Function,
OnlineClient, Pallet, Param, SubstrateConfig,
};
use url::Url;

Expand Down Expand Up @@ -62,7 +62,12 @@ impl CallChainCommand {
// Execute the call if call_data is provided.
if let Some(call_data) = self.call_data.as_ref() {
if let Err(e) = self
.submit_extrinsic_from_call_data(&chain.client, call_data, &mut cli::Cli)
.submit_extrinsic_from_call_data(
&chain.client,
&chain.url,
call_data,
&mut cli::Cli,
)
.await
{
display_message(&e.to_string(), false, &mut cli::Cli)?;
Expand Down Expand Up @@ -90,7 +95,7 @@ impl CallChainCommand {
};

// Sign and submit the extrinsic.
if let Err(e) = call.submit_extrinsic(&chain.client, xt, &mut cli).await {
if let Err(e) = call.submit_extrinsic(&chain.client, &chain.url, xt, &mut cli).await {
display_message(&e.to_string(), false, &mut cli)?;
break;
}
Expand Down Expand Up @@ -213,6 +218,7 @@ impl CallChainCommand {
async fn submit_extrinsic_from_call_data(
&self,
client: &OnlineClient<SubstrateConfig>,
url: &Url,
call_data: &str,
cli: &mut impl Cli,
) -> Result<()> {
Expand All @@ -238,11 +244,11 @@ impl CallChainCommand {
spinner.start("Signing and submitting the extrinsic and then waiting for finalization, please be patient...");
let call_data_bytes =
decode_call_data(call_data).map_err(|err| anyhow!("{}", format!("{err:?}")))?;
let result = sign_and_submit_extrinsic_with_call_data(client, call_data_bytes, suri)
let result = sign_and_submit_extrinsic(client, url, CallData::new(call_data_bytes), suri)
.await
.map_err(|err| anyhow!("{}", format!("{err:?}")))?;

spinner.stop(format!("Extrinsic submitted successfully with hash: {:?}", result));
spinner.stop(result);
display_message("Call complete.", true, cli)?;
Ok(())
}
Expand Down Expand Up @@ -361,6 +367,7 @@ impl Call {
async fn submit_extrinsic(
&mut self,
client: &OnlineClient<SubstrateConfig>,
url: &Url,
tx: DynamicPayload,
cli: &mut impl Cli,
) -> Result<()> {
Expand All @@ -378,11 +385,10 @@ impl Call {
}
let spinner = cliclack::spinner();
spinner.start("Signing and submitting the extrinsic and then waiting for finalization, please be patient...");
let result = sign_and_submit_extrinsic(client, tx, &self.suri)
let result = sign_and_submit_extrinsic(client, url, tx, &self.suri)
.await
.map_err(|err| anyhow!("{}", format!("{err:?}")))?;

spinner.stop(format!("Extrinsic submitted with hash: {:?}", result));
spinner.stop(result);
Ok(())
}

Expand Down Expand Up @@ -754,19 +760,21 @@ mod tests {
.expect_confirm("Do you want to submit the extrinsic?", false)
.expect_outro_cancel("Extrinsic for `remark` was not submitted.");
let xt = call_config.prepare_extrinsic(&client, &mut cli)?;
call_config.submit_extrinsic(&client, xt, &mut cli).await?;
call_config
.submit_extrinsic(&client, &Url::parse(POP_NETWORK_TESTNET_URL)?, xt, &mut cli)
.await?;

cli.verify()
}

#[tokio::test]
async fn user_cancel_submit_extrinsic_from_call_data_works() -> Result<()> {
let client = set_up_client("wss://rpc1.paseo.popnetwork.xyz").await?;
let client = set_up_client(POP_NETWORK_TESTNET_URL).await?;
let call_config = CallChainCommand {
pallet: None,
function: None,
args: vec![].to_vec(),
url: Some(Url::parse("wss://rpc1.paseo.popnetwork.xyz")?),
url: Some(Url::parse(POP_NETWORK_TESTNET_URL)?),
suri: None,
skip_confirm: false,
call_data: Some("0x00000411".to_string()),
Expand All @@ -777,7 +785,12 @@ mod tests {
.expect_confirm("Do you want to submit the extrinsic?", false)
.expect_outro_cancel("Extrinsic with call data 0x00000411 was not submitted.");
call_config
.submit_extrinsic_from_call_data(&client, "0x00000411", &mut cli)
.submit_extrinsic_from_call_data(
&client,
&Url::parse(POP_NETWORK_TESTNET_URL)?,
"0x00000411",
&mut cli,
)
.await?;

cli.verify()
Expand Down Expand Up @@ -809,7 +822,7 @@ mod tests {
"Would you like to dispatch this function call with `Root` origin?",
true,
);
call_config.url = Some(Url::parse("wss://rpc1.paseo.popnetwork.xyz")?);
call_config.url = Some(Url::parse(POP_NETWORK_TESTNET_URL)?);
let chain = call_config.configure_chain(&mut cli).await?;
call_config.configure_sudo(&chain, &mut cli)?;
assert!(call_config.sudo);
Expand Down
5 changes: 4 additions & 1 deletion crates/pop-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ repository.workspace = true
[dependencies]
anyhow.workspace = true
cargo_toml.workspace = true
contract-build.workspace = true
contract-extrinsics.workspace = true
duct.workspace = true
flate2.workspace = true
git2.workspace = true
git2_credentials.workspace = true
ink_env.workspace = true
regex.workspace = true
reqwest.workspace = true
scale-info.workspace = true
Expand All @@ -27,9 +30,9 @@ tar.workspace = true
tempfile.workspace = true
thiserror.workspace = true
tokio.workspace = true
toml.workspace = true
toml_edit.workspace = true
url.workspace = true
toml.workspace = true

[dev-dependencies]
mockito.workspace = true
Expand Down
11 changes: 11 additions & 0 deletions crates/pop-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use std::net::TcpListener;

use std::net::TcpListener;

pub use build::Profile;
pub use errors::Error;
pub use git::{Git, GitHub, Release};
Expand Down Expand Up @@ -73,6 +75,15 @@ pub fn find_free_port() -> u16 {
.port()
}

/// Provides functionality for making calls to parachains or smart contracts.
pub mod call {
// Note: parsing events after calling a chain is done using cargo contract logic. This could be
// refactored in the future.
pub use contract_build::Verbosity;
pub use contract_extrinsics::{DisplayEvents, TokenMetadata};
pub use ink_env::DefaultEnvironment;
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
2 changes: 2 additions & 0 deletions crates/pop-contracts/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use sp_weights::Weight;
use std::path::PathBuf;
use url::Url;

pub mod metadata;

/// Attributes for the `call` command.
pub struct CallOpts {
/// Path to the contract build directory.
Expand Down
4 changes: 3 additions & 1 deletion crates/pop-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ mod utils;

pub use build::{build_smart_contract, is_supported, Verbosity};
pub use call::{
call_smart_contract, dry_run_call, dry_run_gas_estimate_call, set_up_call, CallOpts,
call_smart_contract, dry_run_call, dry_run_gas_estimate_call,
metadata::{get_messages, Message},
set_up_call, CallOpts,
};
pub use new::{create_smart_contract, is_valid_contract_name};
pub use node::{contracts_node_generator, is_chain_alive, run_contracts_node};
Expand Down
7 changes: 4 additions & 3 deletions crates/pop-contracts/src/utils/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,18 @@ pub fn process_function_args<P>(
where
P: AsRef<Path>,
{
let parsed_args = args.into_iter().map(|arg| arg.replace(",", "")).collect::<Vec<String>>();
let function = match function_type {
FunctionType::Message => get_message(path, label)?,
FunctionType::Constructor => get_constructor(path, label)?,
};
if args.len() != function.args.len() {
if parsed_args.len() != function.args.len() {
return Err(Error::IncorrectArguments {
expected: function.args.len(),
provided: args.len(),
provided: parsed_args.len(),
});
}
Ok(args
Ok(parsed_args
.into_iter()
.zip(&function.args)
.map(|(arg, param)| match (param.type_name.starts_with("Option<"), arg.is_empty()) {
Expand Down
Loading

0 comments on commit ffb0393

Please sign in to comment.