Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] #3974: Add subcommand into iroha_client_cli to transfer domains #4031

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions client/tests/integration/domain_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ fn domain_owner_trigger_permissions() -> Result<()> {
Ok(())
}

#[deprecated(
since = "2.0.0-pre-rc.20",
note = "This test suite is deprecated, use test_transfer_domains.py instead"
)]
#[ignore = "migrated to client cli python tests"]
#[test]
fn domain_owner_transfer() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(11_100).start_with_runtime();
Expand Down
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
15 changes: 12 additions & 3 deletions client_cli/pytests/src/client_cli/have.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,26 @@ def expected_in_actual(expected, actual) -> bool:
return expected in actual


def domain(expected):
def domain(expected, owned_by=None):
"""
Check if the expected domain is present in the list of domains.
Optionally checks if the domain is owned by a specific owner.

:param expected: The expected domain object.
:return: True if the domain is present, False otherwise.
:param owned_by: The owner of the domain, default is None.
:return: True if the domain is present (and owned by the specified owner if provided), False otherwise.
"""

def domain_in_domains() -> bool:
domains = iroha.list_filter(f'{{"Identifiable": {{"Is": "{expected}"}}}}').domains()
return expected_in_actual(expected, domains)
if not expected_in_actual(expected, domains):
return False
if owned_by:
domain_info = domains.get(expected)
if not domain_info or domain_info.get('owned_by') != str(owned_by):
return False

return True

return client_cli.wait_for(domain_in_domains)

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
3 changes: 3 additions & 0 deletions client_cli/pytests/test/domains/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
GIVEN_string_with_reserved_character,
GIVEN_string_with_whitespaces,
GIVEN_existing_domain_with_uppercase_letter,
GIVEN_currently_authorized_account,
GIVEN_new_one_existing_account,
GIVEN_public_key,
before_each)

@pytest.fixture(scope="function", autouse=True)
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
26 changes: 26 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,26 @@
import allure
import pytest

from src.client_cli import client_cli, iroha, have

@pytest.fixture(scope="function", autouse=True)
def story_account_transfers_domain():
allure.dynamic.story('Account transfers a domain')
allure.dynamic.label('permission', 'no_permission_required')

@allure.label('sdk_test_id', 'transfer_domain_successfully')
def test_transfer_domain(
GIVEN_currently_authorized_account,
GIVEN_new_one_existing_account,
GIVEN_new_one_existing_domain,
):
with allure.step(
f'WHEN {GIVEN_currently_authorized_account} transfers domains '
f'to {GIVEN_new_one_existing_account}'):
client_cli.execute(f'domain transfer '
f'--from={GIVEN_currently_authorized_account} '
f'--to={GIVEN_new_one_existing_account} '
f'--id={GIVEN_new_one_existing_domain.name}')
with allure.step(
f'THEN {GIVEN_new_one_existing_account} should own {GIVEN_new_one_existing_domain}'):
iroha.should(have.domain(GIVEN_new_one_existing_domain.name, owned_by=GIVEN_new_one_existing_account))
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,
pesterev marked this conversation as resolved.
Show resolved Hide resolved
}

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
Loading