Skip to content

Commit

Permalink
[feature] #3974: Add subcommand into iroha_client_cli to transfer dom…
Browse files Browse the repository at this point in the history
…ains

Signed-off-by: Vladimir Pesterev <[email protected]>
  • Loading branch information
pesterev committed Nov 14, 2023
1 parent e9c6fe4 commit 2c539ab
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 10 deletions.
13 changes: 9 additions & 4 deletions client_cli/pytests/src/client_cli/client_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions client_cli/pytests/src/client_cli/iroha.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def should(self, _expected):
"""
return self

def domains(self) -> List[str]:
def domains(self) -> Dict[str, Dict]:
"""
Retrieve domains from the Iroha network and return then as list of ids.
Expand All @@ -52,8 +52,8 @@ def domains(self) -> List[str]:
"""
self._execute_command('domain')
domains = json.loads(self.stdout)
domains = [domain["id"] for domain in domains]
return domains
domains_dict = { domain["id"]: domain for domain in domains }
return domains_dict

def accounts(self) -> List[str]:
"""
Expand Down
2 changes: 1 addition & 1 deletion client_cli/pytests/test/domains/test_register_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
30 changes: 30 additions & 0 deletions client_cli/pytests/test/domains/test_transfer_domains.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import allure

from src.client_cli import client_cli, iroha
import json

@allure.label('sdk_test_id', 'transfer_domain_successfully')
def test_transfer_domain_successfully(
GIVEN_currently_authorized_account,
GIVEN_new_one_existing_account,
GIVEN_new_one_existing_domain,
):
with allure.step(
f'WHEN client_cli transfers this domain from {GIVEN_currently_authorized_account} to {GIVEN_new_one_existing_account}'):
client_cli.execute(f'domain transfer --from={GIVEN_currently_authorized_account} --to={GIVEN_new_one_existing_account} --id={GIVEN_new_one_existing_domain.name}')
with allure.step(
f'THEN {GIVEN_new_one_existing_account} should own this domain {GIVEN_new_one_existing_domain}'):
def condition():
owned_by = GIVEN_new_one_existing_account
domain_name = GIVEN_new_one_existing_domain.name
with allure.step(
f'WHEN client_cli query domains filtered by name "{domain_name}"'):
domains = iroha.list_filter(f'{{"Identifiable": {{"Is": "{domain_name}"}}}}').domains()
with allure.step(
f'THEN Iroha should return only return domains with "{domain_name}" name'):
allure.attach(
json.dumps(domains),
name='domains',
attachment_type=allure.attachment_type.JSON)
return len(domains) != 0 and all(domains[key]["id"] == domain_name and domains[key]["owned_by"] == owned_by for key in domains)
client_cli.wait_for(condition)
36 changes: 34 additions & 2 deletions client_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 2c539ab

Please sign in to comment.