From 153c4c625e2705f5f4e34070ed1552aae11b8c85 Mon Sep 17 00:00:00 2001 From: Vladimir Pesterev <8786922+pesterev@users.noreply.github.com> Date: Tue, 7 Nov 2023 11:13:14 +0400 Subject: [PATCH] [feature] #3974: Add subcommand into iroha_client_cli to transfer domains Signed-off-by: Vladimir Pesterev <8786922+pesterev@users.noreply.github.com> --- .../pytests/src/client_cli/client_cli.py | 13 ++++--- .../test/domains/test_register_domains.py | 2 +- client_cli/src/main.rs | 36 +++++++++++++++++-- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/client_cli/pytests/src/client_cli/client_cli.py b/client_cli/pytests/src/client_cli/client_cli.py index 9e46b2b70a8..f715f31b246 100644 --- a/client_cli/pytests/src/client_cli/client_cli.py +++ b/client_cli/pytests/src/client_cli/client_cli.py @@ -246,18 +246,23 @@ def should(self, _expected): """ return self - def execute(self): + def execute(self, command=None): """ Executes the command and captures stdout and stderr. :return: The current ClientCli object. :rtype: ClientCli """ - command = '\n'.join(self.command) - with allure.step(f'{command} on the {str(self.config.torii_api_port)} peer'): + if command is None: + command = self.command + else: + command = [self.BASE_PATH] + self.BASE_FLAGS + command.split() + allure_command = ' '.join(map(str, command[3:])) + print(allure_command) + with allure.step(f'{allure_command} on the {str(self.config.torii_api_port)} peer'): try: with subprocess.Popen( - self.command, + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True diff --git a/client_cli/pytests/test/domains/test_register_domains.py b/client_cli/pytests/test/domains/test_register_domains.py index adce5246453..df921966500 100644 --- a/client_cli/pytests/test/domains/test_register_domains.py +++ b/client_cli/pytests/test/domains/test_register_domains.py @@ -15,7 +15,7 @@ def test_register_domain( GIVEN_fake_name): with allure.step( f'WHEN client_cli registers the domain name "{GIVEN_fake_name}"'): - client_cli.register().domain(GIVEN_fake_name) + client_cli.execute(f'domain register --id={GIVEN_fake_name}') with allure.step( f'THEN Iroha should have the domain name "{GIVEN_fake_name}"'): iroha.should(have.domain(GIVEN_fake_name)) diff --git a/client_cli/src/main.rs b/client_cli/src/main.rs index 20abd7859ec..d4b77222bee 100644 --- a/client_cli/src/main.rs +++ b/client_cli/src/main.rs @@ -363,11 +363,13 @@ mod domain { /// List domains #[clap(subcommand)] List(List), + /// Transfer domain + Transfer(Transfer), } impl RunArgs for Args { fn run(self, context: &mut dyn RunContext) -> Result<()> { - match_all!((self, context), { Args::Register, Args::List }) + match_all!((self, context), { Args::Register, Args::List, Args::Transfer }) } } @@ -420,6 +422,36 @@ mod domain { Ok(()) } } + + /// Transfer a domain between accounts + #[derive(Debug, StructOpt)] + pub struct Transfer { + /// Domain name as double-quited string + #[structopt(short, long)] + pub id: DomainId, + /// Account from which to transfer (in form `name@domain_name') + #[structopt(short, long)] + pub from: AccountId, + /// Account to which to transfer (in form `name@domain_name') + #[structopt(short, long)] + pub to: AccountId, + /// The JSON/JSON5 file with key-value metadata pairs + #[structopt(short, long, default_value = "")] + pub metadata: super::Metadata, + } + + impl RunArgs for Transfer { + fn run(self, context: &mut dyn RunContext) -> Result<()> { + let Self { + id, + from, + to, + metadata: Metadata(metadata), + } = self; + let transfer_domain = TransferExpr::new(from, id, to); + submit([transfer_domain], metadata, context).wrap_err("Failed to transfer domain") + } + } } mod account { @@ -774,7 +806,7 @@ mod asset { /// Account from which to transfer (in form `name@domain_name') #[structopt(short, long)] pub from: AccountId, - /// Account from which to transfer (in form `name@domain_name') + /// Account to which to transfer (in form `name@domain_name') #[structopt(short, long)] pub to: AccountId, /// Asset id to transfer (in form like `name#domain_name')