Skip to content

Commit

Permalink
[fix] Fix transfer domain pytest
Browse files Browse the repository at this point in the history
Signed-off-by: alexstroke <[email protected]>
  • Loading branch information
AlexStroke committed Nov 16, 2023
1 parent 2c539ab commit 9423953
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
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
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
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
42 changes: 19 additions & 23 deletions client_cli/pytests/test/domains/test_transfer_domains.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
import allure
import pytest

from src.client_cli import client_cli, iroha
import json
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_successfully(
GIVEN_currently_authorized_account,
GIVEN_new_one_existing_account,
GIVEN_new_one_existing_domain,
def test_transfer_domain(
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}')
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 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)
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))

0 comments on commit 9423953

Please sign in to comment.