Skip to content

Commit

Permalink
fix(tests): correctly list asset definitions in CLI tests
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic authored and nxsaken committed Jul 12, 2024
1 parent 001f4a7 commit 7182916
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 87 deletions.
12 changes: 7 additions & 5 deletions client_cli/pytests/src/client_cli/client_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def asset(self, asset_definition=None, account=None, value_of_type=None):
self.command.insert(2, "asset")
if asset_definition and account and value_of_type:
self.command.append(
"--asset-id="
"--id="
+ asset_definition.name
+ "#"
+ asset_definition.domain
Expand Down Expand Up @@ -198,7 +198,7 @@ def transfer(self, asset, source_account, target_account, quantity: str):
self.command.append("transfer")
self.command.append("--to=" + repr(target_account))
self.command.append(
"--asset-id="
"--id="
+ asset.name
+ "#"
+ asset.domain
Expand Down Expand Up @@ -226,7 +226,7 @@ def burn(self, account, asset, quantity: str):
self.command.append("asset")
self.command.append("burn")
self.command.append(
"--asset-id="
"--id="
+ asset.name
+ "#"
+ asset.domain
Expand All @@ -239,7 +239,7 @@ def burn(self, account, asset, quantity: str):
self.execute()
return self

def definition(self, asset: str, domain: str, type_: str):
def asset_definition(self, asset: str, domain: str, type_: str):
"""
Executes the 'definition' command for the given asset, domain, and value type.
Expand All @@ -252,7 +252,9 @@ def definition(self, asset: str, domain: str, type_: str):
:return: The current ClientCli object.
:rtype: ClientCli
"""
self.command.append("--definition-id=" + asset + "#" + domain)
self.command.insert(2, "definition")
self.command.insert(2, "asset")
self.command.append("--id=" + asset + "#" + domain)
self.command.append("--type=" + type_)
self.execute()
return self
Expand Down
3 changes: 1 addition & 2 deletions client_cli/pytests/src/client_cli/have.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ def asset_definition(expected):
:param expected: The expected asset definition object.
:return: True if the asset definition is present, False otherwise.
"""
expected_domain = expected.split("#")[1]

def asset_definition_in_asset_definitions() -> bool:
asset_definitions = iroha.list_filter(
f'{{"Identifiable": {{"Is": "{expected_domain}"}}}}'
f'{{"Identifiable": {{"Is": "{expected}"}}}}'
).asset_definitions()
return expected_in_actual(expected, asset_definitions)

Expand Down
17 changes: 9 additions & 8 deletions client_cli/pytests/src/client_cli/iroha.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,17 @@ def asset_definitions(self) -> Dict[str, str]:
:return: Dict of asset definitions ids with there value type.
:rtype: Dict[str, str]
"""
self._execute_command("domain")
self.command.insert(2, "definition")
self._execute_command("asset")

if self.stdout is not None:
domains = json.loads(self.stdout)
asset_defs = json.loads(self.stdout)

asset_definitions = {}
for domain in domains:
asset_defs = domain.get("asset_definitions")
for asset_def in asset_defs.values():
type_ = asset_def.get("type_")
if type_:
asset_definitions[asset_def["id"]] = type_
for asset_def in asset_defs:
type_ = asset_def.get("type_")
if type_:
asset_definitions[asset_def["id"]] = type_
return asset_definitions
else:
return {}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_register_asset_definition_with_numeric_type(
f'with "{GIVEN_numeric_type}" value type'
f'in the "{GIVEN_registered_domain.name}" domain'
):
client_cli.register().asset().definition(
client_cli.register().asset_definition(
asset=GIVEN_fake_asset_name,
domain=GIVEN_registered_domain.name,
type_=GIVEN_numeric_type,
Expand All @@ -42,7 +42,7 @@ def test_register_asset_definition_with_store_type(
f'with "{GIVEN_store_type}" value type'
f'in the "{GIVEN_registered_domain.name}" domain'
):
client_cli.register().asset().definition(
client_cli.register().asset_definition(
asset=GIVEN_fake_asset_name,
domain=GIVEN_registered_domain.name,
type_=GIVEN_store_type,
Expand All @@ -64,7 +64,7 @@ def test_register_asset_with_existing_name(
f'with the same name "{GIVEN_registered_asset_definition_with_numeric_type.name}"'
f'in the "{GIVEN_registered_asset_definition_with_numeric_type.domain}" domain'
):
client_cli.register().asset().definition(
client_cli.register().asset_definition(
asset=GIVEN_registered_asset_definition_with_numeric_type.name,
domain=GIVEN_registered_asset_definition_with_numeric_type.domain,
type_=GIVEN_registered_asset_definition_with_numeric_type.type_,
Expand All @@ -82,7 +82,7 @@ def test_register_asset_with_empty_name(GIVEN_registered_domain):
"WHEN client_cli tries to register an asset definition with an empty name"
f'in the "{GIVEN_registered_domain.name}" domain'
):
client_cli.register().asset().definition(
client_cli.register().asset_definition(
asset="", domain=GIVEN_registered_domain.name, type_="Numeric"
)
with allure.step(f'THEN сlient_cli should have the asset error: "{Stderr.EMPTY}"'):
Expand All @@ -96,7 +96,7 @@ def test_register_asset_with_not_existing_domain(
with allure.step(
"WHEN client_cli tries to register an asset definition with not existing domain"
):
client_cli.register().asset().definition(
client_cli.register().asset_definition(
asset=GIVEN_fake_asset_name,
domain=GIVEN_not_existing_name,
type_=GIVEN_numeric_type,
Expand All @@ -112,7 +112,7 @@ def test_register_asset_with_too_long_type(
with allure.step(
"WHEN client_cli tries to register an asset definition with too long value type"
):
client_cli.register().asset().definition(
client_cli.register().asset_definition(
asset=GIVEN_fake_asset_name,
domain=GIVEN_registered_domain.name,
type_="coin",
Expand Down
8 changes: 4 additions & 4 deletions client_cli/pytests/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def GIVEN_currently_account_quantity_with_two_quantity_of_asset(
f'GIVEN the asset_definition "{name}" '
f'in the "{GIVEN_currently_authorized_account.domain}" domain'
):
client_cli.register().asset().definition(
client_cli.register().asset_definition(
asset=asset.definition.name,
domain=asset.definition.domain,
type_=asset.definition.type_,
Expand Down Expand Up @@ -140,7 +140,7 @@ def GIVEN_numeric_asset_for_account(
with allure.step(
f'GIVEN the asset_definition "{asset_def.name}" ' f'in the "{domain}" domain'
):
client_cli.register().asset().definition(
client_cli.register().asset_definition(
asset=asset.definition.name,
domain=asset.definition.domain,
type_=asset.definition.type_,
Expand Down Expand Up @@ -168,7 +168,7 @@ def GIVEN_registered_asset_definition_with_numeric_type(
f'GIVEN the asset_definition "{GIVEN_fake_asset_name}" '
f'in the "{GIVEN_registered_domain.name}" domain'
):
client_cli.register().asset().definition(
client_cli.register().asset_definition(
asset=asset_def.name,
domain=asset_def.domain,
type_=asset_def.type_,
Expand Down Expand Up @@ -212,7 +212,7 @@ def GIVEN_registered_asset_definition_with_store_type(
f'GIVEN the asset_definition "{GIVEN_fake_asset_name}" '
f'in the "{GIVEN_registered_domain.name}" domain'
):
client_cli.register().asset().definition(
client_cli.register().asset_definition(
asset=asset_def.name,
domain=asset_def.domain,
type=asset_def.type,
Expand Down
Loading

0 comments on commit 7182916

Please sign in to comment.