Skip to content

Commit

Permalink
fix: update pytests to use the new query filters
Browse files Browse the repository at this point in the history
This also fixes how an instruction failing to find a domain or an asset definition gets reported by the executor (by returning a FindError instead of a string)

Signed-off-by: ⭐️NINIKA⭐️ <[email protected]>
  • Loading branch information
DCNick3 committed Jul 22, 2024
1 parent cb91328 commit 4656ecc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 32 deletions.
16 changes: 5 additions & 11 deletions client_cli/pytests/src/client_cli/have.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def domain(expected, owned_by=None):
"""

def domain_in_domains() -> bool:
domains = iroha.list_filter(
f'{{"Identifiable": {{"Is": "{expected}"}}}}'
).domains()
domains = iroha.list_filter({"Atom": {"Id": {"Equals": expected}}}).domains()
if not expected_in_actual(expected, domains):
return False
if owned_by:
Expand All @@ -64,9 +62,7 @@ def account(expected):
"""

def account_in_accounts() -> bool:
accounts = iroha.list_filter(
f'{{"Identifiable": {{"Is": "{expected}"}}}}'
).accounts()
accounts = iroha.list_filter({"Atom": {"Id": {"Equals": expected}}}).accounts()
return expected_in_actual(expected, accounts)

return client_cli.wait_for(account_in_accounts)
Expand All @@ -82,7 +78,7 @@ def asset_definition(expected):

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

Expand All @@ -98,9 +94,7 @@ def asset(expected):
"""

def asset_in_assets() -> bool:
assets = iroha.list_filter(
f'{{"Identifiable": {{"Is": "{expected}"}}}}'
).assets()
assets = iroha.list_filter({"Atom": {"Id": {"Equals": expected}}}).assets()
return expected_in_actual(expected, assets)

return client_cli.wait_for(asset_in_assets)
Expand All @@ -117,7 +111,7 @@ def asset_has_quantity(expected_asset_id, expected_quantity):

def check_quantity() -> bool:
assets = iroha.list_filter(
f'{{"Identifiable": {{"Is": "{expected_asset_id}"}}}}'
{"Atom": {"Id": {"Equals": expected_asset_id}}}
).assets()
actual_quantity = None
for asset_item in assets:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def condition():
f"WHEN client_cli query accounts " f'in the "{domain}" domain'
):
accounts = iroha.list_filter(
{"Identifiable": {"EndsWith": f"@{domain}"}}
{"Atom": {"Id": {"DomainId": {"Equals": domain}}}}
).accounts()
with allure.step("THEN Iroha should return only accounts with this domain"):
allure.attach(
Expand All @@ -35,7 +35,7 @@ def condition():
f'WHEN client_cli query accounts with account id "{account_id}"'
):
accounts = iroha.list_filter(
{"Identifiable": {"Is": account_id}}
{"Atom": {"Id": {"Equals": account_id}}}
).accounts()
with allure.step("THEN Iroha should return only accounts with this id"):
allure.attach(
Expand Down
16 changes: 3 additions & 13 deletions client_cli/pytests/test/assets/test_assets_query_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@ def condition():
)
with allure.step(f"WHEN client_cli query assets" f'in the "{domain}" domain'):
assets = iroha.list_filter(
{
"Or": [
{"Identifiable": {"Contains": f"#{domain}#"}},
{
"And": [
{"Identifiable": {"Contains": "##"}},
{"Identifiable": {"EndsWith": f"@{domain}"}},
]
},
]
}
{"Atom": {"Id": {"DefinitionId": {"DomainId": {"Equals": domain}}}}}
).assets()
with allure.step("THEN Iroha should return only assets with this domain"):
allure.attach(
Expand All @@ -48,7 +38,7 @@ def condition():
)
with allure.step(f'WHEN client_cli query assets with name "{name}"'):
assets = iroha.list_filter(
{"Identifiable": {"StartsWith": f"{name}#"}}
{"Atom": {"Id": {"DefinitionId": {"Name": {"Equals": name}}}}}
).assets()
with allure.step("THEN Iroha should return only assets with this name"):
allure.attach(
Expand All @@ -74,7 +64,7 @@ def condition():
+ GIVEN_currently_authorized_account.domain
)
with allure.step(f'WHEN client_cli query assets with asset id "{asset_id}"'):
assets = iroha.list_filter({"Identifiable": {"Is": asset_id}}).assets()
assets = iroha.list_filter({"Atom": {"Id": {"Equals": asset_id}}}).assets()
with allure.step("THEN Iroha should return only assets with this id"):
allure.attach(
json.dumps(assets),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ def condition():
with allure.step(
f'WHEN client_cli query domains filtered by name "{domain_name}"'
):
domains = iroha.list_filter({"Identifiable": {"Is": domain_name}}).domains()
domains = iroha.list_filter(
{"Atom": {"Id": {"Equals": domain_name}}}
).domains()
with allure.step(
f'THEN Iroha should return only return domains with "{domain_name}" name'
):
Expand Down
Binary file modified configs/swarm/executor.wasm
Binary file not shown.
18 changes: 13 additions & 5 deletions smart_contract/executor/src/permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,10 @@ pub mod asset_definition {
CanRemoveKeyValueInAssetDefinition, CanSetKeyValueInAssetDefinition,
CanUnregisterAssetDefinition,
};
use iroha_smart_contract::SmartContractSingleQueryError;
use iroha_smart_contract::{
data_model::{isi::error::InstructionExecutionError, query::error::FindError},
SmartContractSingleQueryError,
};

use super::*;

Expand All @@ -430,8 +433,8 @@ pub mod asset_definition {
SmartContractSingleQueryError::Validation(e) => e,
SmartContractSingleQueryError::Single(_) => {
// assuming this can only happen due to such a domain not existing
ValidationFail::NotPermitted(alloc::format!(
"Asset definition {asset_definition_id} not found"
ValidationFail::InstructionFailed(InstructionExecutionError::Find(
FindError::AssetDefinition(asset_definition_id.clone()),
))
}
})?;
Expand Down Expand Up @@ -738,7 +741,10 @@ pub mod domain {
CanRegisterAccountInDomain, CanRegisterAssetDefinitionInDomain, CanRemoveKeyValueInDomain,
CanSetKeyValueInDomain, CanUnregisterDomain,
};
use iroha_smart_contract::SmartContractSingleQueryError;
use iroha_smart_contract::{
data_model::{isi::error::InstructionExecutionError, query::error::FindError},
SmartContractSingleQueryError,
};

use super::*;

Expand All @@ -755,7 +761,9 @@ pub mod domain {
SmartContractSingleQueryError::Validation(e) => e,
SmartContractSingleQueryError::Single(_) => {
// assuming this can only happen due to such a domain not existing
ValidationFail::NotPermitted(alloc::format!("Domain {domain_id} not found"))
ValidationFail::InstructionFailed(InstructionExecutionError::Find(
FindError::Domain(domain_id.clone()),
))
}
})
}
Expand Down

0 comments on commit 4656ecc

Please sign in to comment.