From 36ebb23ebc3897a9410e2436b66f632cd1d83500 Mon Sep 17 00:00:00 2001 From: Mykhailo Lohachov Date: Thu, 24 Oct 2024 15:55:38 +0900 Subject: [PATCH] refactor: remove module-based api from client (#5184) Signed-off-by: Lohachov Mykhailo --- crates/iroha/src/client.rs | 128 ------------------ crates/iroha/tests/asset.rs | 19 ++- crates/iroha/tests/asset_propagation.rs | 7 +- .../multiple_blocks_created.rs | 2 +- crates/iroha/tests/extra_functional/normal.rs | 2 +- .../tests/extra_functional/offline_peers.rs | 2 +- .../tests/extra_functional/restart_peer.rs | 2 +- .../tests/extra_functional/unregister_peer.rs | 2 +- crates/iroha/tests/multisig.rs | 5 +- crates/iroha/tests/non_mintable.rs | 11 +- crates/iroha/tests/pagination.rs | 8 +- crates/iroha/tests/permissions.rs | 16 +-- crates/iroha/tests/queries/account.rs | 6 +- crates/iroha/tests/queries/mod.rs | 2 +- crates/iroha/tests/queries/query_errors.rs | 2 +- crates/iroha/tests/queries/role.rs | 10 +- crates/iroha/tests/roles.rs | 19 ++- crates/iroha/tests/set_parameter.rs | 13 +- crates/iroha/tests/sorting.rs | 16 +-- crates/iroha/tests/transfer_asset.rs | 19 ++- crates/iroha/tests/transfer_domain.rs | 7 +- .../iroha/tests/triggers/by_call_trigger.rs | 2 +- crates/iroha/tests/triggers/data_trigger.rs | 2 +- crates/iroha/tests/triggers/mod.rs | 2 +- crates/iroha/tests/triggers/time_trigger.rs | 2 +- .../iroha/tests/triggers/trigger_rollback.rs | 2 +- crates/iroha/tests/tx_history.rs | 7 +- crates/iroha/tests/tx_rollback.rs | 8 +- crates/iroha/tests/upgrade.rs | 16 +-- crates/iroha_cli/src/main.rs | 19 +-- crates/iroha_data_model/src/query/mod.rs | 2 +- 31 files changed, 101 insertions(+), 259 deletions(-) diff --git a/crates/iroha/src/client.rs b/crates/iroha/src/client.rs index ecdd1da2e25..8a31b09f7f7 100644 --- a/crates/iroha/src/client.rs +++ b/crates/iroha/src/client.rs @@ -972,134 +972,6 @@ mod blocks_api { pub type AsyncBlockStream = stream_api::AsyncStream; } -pub mod account { - //! Module with queries for account - use super::*; - - /// Construct a query to get all accounts - pub const fn all() -> FindAccounts { - FindAccounts - } - - /// Construct a query to get all accounts containing specified asset - pub fn all_with_asset(asset_definition_id: AssetDefinitionId) -> FindAccountsWithAsset { - FindAccountsWithAsset::new(asset_definition_id) - } -} - -pub mod asset { - //! Module with queries for assets - use super::*; - - /// Construct a query to get all assets - pub const fn all() -> FindAssets { - FindAssets - } - - /// Construct a query to get all asset definitions - pub const fn all_definitions() -> FindAssetsDefinitions { - FindAssetsDefinitions - } -} - -pub mod block { - //! Module with queries related to blocks - - use super::*; - - /// Construct a query to find all blocks - pub const fn all() -> FindBlocks { - FindBlocks - } - - /// Construct a query to find all block headers - pub const fn all_headers() -> FindBlockHeaders { - FindBlockHeaders - } -} - -pub mod domain { - //! Module with queries for domains - use super::*; - - /// Construct a query to get all domains - pub const fn all() -> FindDomains { - FindDomains - } -} - -pub mod transaction { - //! Module with queries for transactions - - use super::*; - - /// Construct a query to find all transactions - pub fn all() -> FindTransactions { - FindTransactions - } -} - -pub mod trigger { - //! Module with queries for triggers - use super::*; - - /// Construct a query to get all active trigger ids - pub fn all_ids() -> FindActiveTriggerIds { - FindActiveTriggerIds - } -} - -pub mod permission { - //! Module with queries for permission tokens - use super::*; - - /// Construct a query to get all [`Permission`] granted - /// to account with given [`Id`][AccountId] - pub fn by_account_id(account_id: AccountId) -> FindPermissionsByAccountId { - FindPermissionsByAccountId::new(account_id) - } -} - -pub mod role { - //! Module with queries for roles - use super::*; - - /// Construct a query to retrieve all roles - pub const fn all() -> FindRoles { - FindRoles - } - - /// Construct a query to retrieve all role ids - pub const fn all_ids() -> FindRoleIds { - FindRoleIds - } - - /// Construct a query to retrieve all roles for an account - pub fn by_account_id(account_id: AccountId) -> FindRolesByAccountId { - FindRolesByAccountId::new(account_id) - } -} - -pub mod parameter { - //! Module with queries for config parameters - use super::*; - - /// Construct a query to retrieve all config parameters - pub const fn all() -> FindParameters { - FindParameters - } -} - -pub mod executor { - //! Queries for executor entities - use super::*; - - /// Retrieve executor data model - pub const fn data_model() -> FindExecutorDataModel { - FindExecutorDataModel - } -} - #[cfg(test)] mod tests { use iroha_primitives::small::SmallStr; diff --git a/crates/iroha/tests/asset.rs b/crates/iroha/tests/asset.rs index e605b0c3432..faf5f71fcc0 100644 --- a/crates/iroha/tests/asset.rs +++ b/crates/iroha/tests/asset.rs @@ -1,6 +1,5 @@ use eyre::Result; use iroha::{ - client, crypto::KeyPair, data_model::{ asset::{AssetId, AssetType, AssetValue}, @@ -41,7 +40,7 @@ fn client_register_asset_should_add_asset_once_but_not_twice() -> Result<()> { // Registering an asset to an account which doesn't have one // should result in asset being created let asset = test_client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(account_id)) .execute_all()? .into_iter() @@ -76,7 +75,7 @@ fn unregister_asset_should_remove_asset_from_account() -> Result<()> { // Check for asset to be registered let assets = test_client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(account_id.clone())) .execute_all()?; @@ -88,7 +87,7 @@ fn unregister_asset_should_remove_asset_from_account() -> Result<()> { // ... and check that it is removed after Unregister let assets = test_client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(account_id.clone())) .execute_all()?; @@ -125,7 +124,7 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount() -> test_client.submit_transaction_blocking(&tx)?; let asset = test_client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(account_id)) .execute_all()? .into_iter() @@ -159,7 +158,7 @@ fn client_add_big_asset_quantity_to_existing_asset_should_increase_asset_amount( test_client.submit_transaction_blocking(&tx)?; let asset = test_client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(account_id)) .execute_all()? .into_iter() @@ -194,7 +193,7 @@ fn client_add_asset_with_decimal_should_increase_asset_amount() -> Result<()> { test_client.submit_transaction_blocking(&tx)?; let asset = test_client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(account_id.clone())) .execute_all()? .into_iter() @@ -215,7 +214,7 @@ fn client_add_asset_with_decimal_should_increase_asset_amount() -> Result<()> { test_client.submit_blocking(mint)?; let asset = test_client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(account_id)) .execute_all()? .into_iter() @@ -339,7 +338,7 @@ fn transfer_asset_definition() { .expect("Failed to submit transaction"); let asset_definition = test_client - .query(client::asset::all_definitions()) + .query(FindAssetsDefinitions::new()) .filter_with(|asset_definition| asset_definition.id.eq(asset_definition_id.clone())) .execute_single() .expect("Failed to execute Iroha Query"); @@ -354,7 +353,7 @@ fn transfer_asset_definition() { .expect("Failed to submit transaction"); let asset_definition = test_client - .query(client::asset::all_definitions()) + .query(FindAssetsDefinitions::new()) .filter_with(|asset_definition| asset_definition.id.eq(asset_definition_id)) .execute_single() .expect("Failed to execute Iroha Query"); diff --git a/crates/iroha/tests/asset_propagation.rs b/crates/iroha/tests/asset_propagation.rs index 342152e2dcc..fb8ed7403b7 100644 --- a/crates/iroha/tests/asset_propagation.rs +++ b/crates/iroha/tests/asset_propagation.rs @@ -1,8 +1,5 @@ use eyre::Result; -use iroha::{ - client, - data_model::{parameter::BlockParameter, prelude::*}, -}; +use iroha::data_model::{parameter::BlockParameter, prelude::*}; use iroha_test_network::*; use iroha_test_samples::gen_account_in; use nonzero_ext::nonzero; @@ -46,7 +43,7 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount_on_a // Then let asset = peer_b .client() - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(account_id)) .execute_all()? .into_iter() diff --git a/crates/iroha/tests/extra_functional/multiple_blocks_created.rs b/crates/iroha/tests/extra_functional/multiple_blocks_created.rs index 43ff51ec13a..e99f5bc26fb 100644 --- a/crates/iroha/tests/extra_functional/multiple_blocks_created.rs +++ b/crates/iroha/tests/extra_functional/multiple_blocks_created.rs @@ -97,7 +97,7 @@ async fn multiple_blocks_created() -> Result<()> { let definition = asset_definition_id.clone(); let assets = spawn_blocking(move || { client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| { asset.id.account.eq(account_id) & asset.id.definition_id.eq(definition) }) diff --git a/crates/iroha/tests/extra_functional/normal.rs b/crates/iroha/tests/extra_functional/normal.rs index 09daf1f2d4d..198564e51c8 100644 --- a/crates/iroha/tests/extra_functional/normal.rs +++ b/crates/iroha/tests/extra_functional/normal.rs @@ -43,7 +43,7 @@ fn transactions_should_be_applied() -> Result<()> { iroha.submit_blocking(mint_asset)?; iroha - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.eq(asset_id)) .execute_single()?; diff --git a/crates/iroha/tests/extra_functional/offline_peers.rs b/crates/iroha/tests/extra_functional/offline_peers.rs index 33344eb66d6..430b45b6349 100644 --- a/crates/iroha/tests/extra_functional/offline_peers.rs +++ b/crates/iroha/tests/extra_functional/offline_peers.rs @@ -45,7 +45,7 @@ async fn genesis_block_is_committed_with_some_offline_peers() -> Result<()> { .client(); spawn_blocking(move || -> Result<()> { let assets = client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(alice_id)) .execute_all()?; let asset = assets diff --git a/crates/iroha/tests/extra_functional/restart_peer.rs b/crates/iroha/tests/extra_functional/restart_peer.rs index b6681c4b645..7e0091d5e23 100644 --- a/crates/iroha/tests/extra_functional/restart_peer.rs +++ b/crates/iroha/tests/extra_functional/restart_peer.rs @@ -54,7 +54,7 @@ async fn restarted_peer_should_restore_its_state() -> Result<()> { let client = peer_b.client(); let asset = spawn_blocking(move || { client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(ALICE_ID.clone())) .execute_all() }) diff --git a/crates/iroha/tests/extra_functional/unregister_peer.rs b/crates/iroha/tests/extra_functional/unregister_peer.rs index 8593b49fa06..23c023394cd 100644 --- a/crates/iroha/tests/extra_functional/unregister_peer.rs +++ b/crates/iroha/tests/extra_functional/unregister_peer.rs @@ -98,7 +98,7 @@ async fn find_asset( let client = client.clone(); let asset = spawn_blocking(move || { client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(account_id.clone())) .execute_all() }) diff --git a/crates/iroha/tests/multisig.rs b/crates/iroha/tests/multisig.rs index 9d1e82767b3..a4cc6f6f14b 100644 --- a/crates/iroha/tests/multisig.rs +++ b/crates/iroha/tests/multisig.rs @@ -3,7 +3,6 @@ use std::collections::BTreeMap; use executor_custom_data_model::multisig::{MultisigArgs, MultisigRegisterArgs}; use eyre::Result; use iroha::{ - client, crypto::KeyPair, data_model::{ asset::{AssetDefinition, AssetDefinitionId}, @@ -120,7 +119,7 @@ fn mutlisig() -> Result<()> { // Check that asset definition isn't created yet let err = test_client - .query(client::asset::all_definitions()) + .query(FindAssetsDefinitions::new()) .filter_with(|asset_definition| asset_definition.id.eq(asset_definition_id.clone())) .execute_single() .expect_err("asset definition shouldn't be created before enough votes are collected"); @@ -138,7 +137,7 @@ fn mutlisig() -> Result<()> { // Check that new asset definition was created and multisig account is owner let asset_definition = test_client - .query(client::asset::all_definitions()) + .query(FindAssetsDefinitions::new()) .filter_with(|asset_definition| asset_definition.id.eq(asset_definition_id.clone())) .execute_single() .expect("asset definition should be created after enough votes are collected"); diff --git a/crates/iroha/tests/non_mintable.rs b/crates/iroha/tests/non_mintable.rs index 15e446e118d..dab0592a53d 100644 --- a/crates/iroha/tests/non_mintable.rs +++ b/crates/iroha/tests/non_mintable.rs @@ -1,8 +1,5 @@ use eyre::Result; -use iroha::{ - client, - data_model::{isi::InstructionBox, prelude::*}, -}; +use iroha::data_model::{isi::InstructionBox, prelude::*}; use iroha_test_network::*; use iroha_test_samples::ALICE_ID; @@ -33,7 +30,7 @@ fn non_mintable_asset_can_be_minted_once_but_not_twice() -> Result<()> { // We can register and mint the non-mintable token test_client.submit_transaction_blocking(&tx)?; assert!(test_client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(account_id.clone())) .execute_all()? .iter() @@ -72,7 +69,7 @@ fn non_mintable_asset_cannot_be_minted_if_registered_with_non_zero_value() -> Re register_asset.clone().into(), ])?; assert!(test_client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(account_id.clone())) .execute_all()? .iter() @@ -116,7 +113,7 @@ fn non_mintable_asset_can_be_minted_if_registered_with_zero_value() -> Result<() mint.into(), ])?; assert!(test_client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(account_id.clone())) .execute_all()? .iter() diff --git a/crates/iroha/tests/pagination.rs b/crates/iroha/tests/pagination.rs index 72eb240afd8..b0be0fb713e 100644 --- a/crates/iroha/tests/pagination.rs +++ b/crates/iroha/tests/pagination.rs @@ -1,6 +1,6 @@ use eyre::Result; use iroha::{ - client::{asset, Client}, + client::Client, data_model::{asset::AssetDefinition, prelude::*}, }; use iroha_test_network::*; @@ -14,7 +14,7 @@ fn limits_should_work() -> Result<()> { register_assets(&client)?; let vec = client - .query(asset::all_definitions()) + .query(FindAssetsDefinitions::new()) .with_pagination(Pagination { limit: Some(nonzero!(7_u64)), offset: 1, @@ -32,7 +32,7 @@ fn reported_length_should_be_accurate() -> Result<()> { register_assets(&client)?; let mut iter = client - .query(asset::all_definitions()) + .query(FindAssetsDefinitions::new()) .with_pagination(Pagination { limit: Some(nonzero!(7_u64)), offset: 1, @@ -66,7 +66,7 @@ fn fetch_size_should_work() -> Result<()> { register_assets(&client)?; let query = QueryWithParams::new( - QueryWithFilter::new(asset::all_definitions(), CompoundPredicate::PASS).into(), + QueryWithFilter::new(FindAssetsDefinitions::new(), CompoundPredicate::PASS).into(), QueryParams::new( Pagination { limit: Some(nonzero!(7_u64)), diff --git a/crates/iroha/tests/permissions.rs b/crates/iroha/tests/permissions.rs index 3bb8ea0d8a8..13559c9c5fd 100644 --- a/crates/iroha/tests/permissions.rs +++ b/crates/iroha/tests/permissions.rs @@ -2,7 +2,7 @@ use std::time::Duration; use eyre::Result; use iroha::{ - client::{self, Client}, + client::Client, crypto::KeyPair, data_model::{ permission::Permission, prelude::*, role::RoleId, @@ -48,7 +48,7 @@ async fn genesis_transactions_are_validated_by_executor() { fn get_assets(iroha: &Client, id: &AccountId) -> Vec { iroha - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(id.clone())) .execute_all() .expect("Failed to execute request.") @@ -178,14 +178,14 @@ fn account_can_query_only_its_own_domain() -> Result<()> { // Alice can query the domain in which her account exists. assert!(client - .query(client::domain::all()) + .query(FindDomains::new()) .filter_with(|domain| domain.id.eq(domain_id)) .execute_single() .is_ok()); // Alice cannot query other domains. assert!(client - .query(client::domain::all()) + .query(FindDomains::new()) .filter_with(|domain| domain.id.eq(new_domain_id)) .execute_single() .is_err()); @@ -390,7 +390,7 @@ fn associated_permissions_removed_on_unregister() { // check that bob indeed have granted permission assert!(iroha - .query(client::permission::by_account_id(bob_id.clone())) + .query(FindPermissionsByAccountId::new(bob_id.clone())) .execute_all() .expect("failed to get permissions for bob") .into_iter() @@ -406,7 +406,7 @@ fn associated_permissions_removed_on_unregister() { // check that permission is removed from bob assert!(!iroha - .query(client::permission::by_account_id(bob_id)) + .query(FindPermissionsByAccountId::new(bob_id)) .execute_all() .expect("failed to get permissions for bob") .into_iter() @@ -440,7 +440,7 @@ fn associated_permissions_removed_from_role_on_unregister() { // check that role indeed have permission assert!(iroha - .query(client::role::all()) + .query(FindRoles::new()) .filter_with(|role| role.id.eq(role_id.clone())) .execute_single() .expect("failed to get role") @@ -457,7 +457,7 @@ fn associated_permissions_removed_from_role_on_unregister() { // check that permission is removed from role assert!(!iroha - .query(client::role::all()) + .query(FindRoles::new()) .filter_with(|role| role.id.eq(role_id.clone())) .execute_single() .expect("failed to get role") diff --git a/crates/iroha/tests/queries/account.rs b/crates/iroha/tests/queries/account.rs index cb9327ecc9d..adc64c8156b 100644 --- a/crates/iroha/tests/queries/account.rs +++ b/crates/iroha/tests/queries/account.rs @@ -19,7 +19,7 @@ fn find_accounts_with_asset() -> Result<()> { // Checking results before all let received_asset_definition = test_client - .query(client::asset::all_definitions()) + .query(FindAssetsDefinitions::new()) .filter_with(|asset_definition| asset_definition.id.eq(definition_id.clone())) .execute_single()?; @@ -58,7 +58,7 @@ fn find_accounts_with_asset() -> Result<()> { // Checking results let received_asset_definition = test_client - .query(client::asset::all_definitions()) + .query(FindAssetsDefinitions::new()) .filter_with(|asset_definition| asset_definition.id.eq(definition_id.clone())) .execute_single()?; @@ -69,7 +69,7 @@ fn find_accounts_with_asset() -> Result<()> { ); let found_accounts = test_client - .query(client::account::all_with_asset(definition_id)) + .query(FindAccountsWithAsset::new(definition_id)) .execute_all()?; let found_ids = found_accounts .into_iter() diff --git a/crates/iroha/tests/queries/mod.rs b/crates/iroha/tests/queries/mod.rs index bb7c70ac7a1..7f7f1ad5373 100644 --- a/crates/iroha/tests/queries/mod.rs +++ b/crates/iroha/tests/queries/mod.rs @@ -19,7 +19,7 @@ fn too_big_fetch_size_is_not_allowed() { let client = network.client(); let err = client - .query(client::asset::all()) + .query(FindAssets::new()) .with_fetch_size(FetchSize::new(Some(MAX_FETCH_SIZE.checked_add(1).unwrap()))) .execute() .expect_err("Should fail"); diff --git a/crates/iroha/tests/queries/query_errors.rs b/crates/iroha/tests/queries/query_errors.rs index a7af9fd2260..233b14e5805 100644 --- a/crates/iroha/tests/queries/query_errors.rs +++ b/crates/iroha/tests/queries/query_errors.rs @@ -11,7 +11,7 @@ fn non_existent_account_is_specific_error() { let client = network.client(); let err = client - .query(client::account::all()) + .query(FindAccounts::new()) .filter_with(|account| account.id.eq(gen_account_in("regalia").0)) .execute_single() .expect_err("Should error"); diff --git a/crates/iroha/tests/queries/role.rs b/crates/iroha/tests/queries/role.rs index dde318bbc5a..37219d8af75 100644 --- a/crates/iroha/tests/queries/role.rs +++ b/crates/iroha/tests/queries/role.rs @@ -38,7 +38,7 @@ fn find_roles() -> Result<()> { // Checking results let found_role_ids = test_client - .query(client::role::all()) + .query(FindRoles::new()) .execute_all()? .into_iter(); @@ -69,7 +69,7 @@ fn find_role_ids() -> Result<()> { let role_ids = HashSet::from(role_ids); // Checking results - let found_role_ids = test_client.query(client::role::all_ids()).execute_all()?; + let found_role_ids = test_client.query(FindRoleIds::new()).execute_all()?; let found_role_ids = found_role_ids.into_iter().collect::>(); assert!(role_ids.is_subset(&found_role_ids)); @@ -90,7 +90,7 @@ fn find_role_by_id() -> Result<()> { test_client.submit_blocking(register_role)?; let found_role = test_client - .query(client::role::all()) + .query(FindRoles::new()) .filter_with(|role| role.id.eq(role_id)) .execute_single()?; @@ -108,7 +108,7 @@ fn find_unregistered_role_by_id() { let role_id: RoleId = "root".parse().expect("Valid"); let found_role = test_client - .query(client::role::all()) + .query(FindRoles::new()) .filter_with(|role| role.id.eq(role_id)) .execute_single(); @@ -146,7 +146,7 @@ fn find_roles_by_account_id() -> Result<()> { // Checking results let found_role_ids = test_client - .query(client::role::by_account_id(alice_id)) + .query(FindRolesByAccountId::new(alice_id)) .execute_all()?; let found_role_ids = found_role_ids.into_iter().collect::>(); diff --git a/crates/iroha/tests/roles.rs b/crates/iroha/tests/roles.rs index 437e2ccfeab..829f98bdb37 100644 --- a/crates/iroha/tests/roles.rs +++ b/crates/iroha/tests/roles.rs @@ -1,9 +1,6 @@ use executor_custom_data_model::permissions::CanControlDomainLives; use eyre::Result; -use iroha::{ - client, - data_model::{prelude::*, transaction::error::TransactionRejectionReason}, -}; +use iroha::data_model::{prelude::*, transaction::error::TransactionRejectionReason}; use iroha_executor_data_model::permission::account::CanModifyAccountMetadata; use iroha_test_network::*; use iroha_test_samples::{gen_account_in, ALICE_ID}; @@ -66,7 +63,7 @@ fn register_and_grant_role_for_metadata_access() -> Result<()> { // Making request to find Alice's roles let found_role_ids = test_client - .query(client::role::by_account_id(alice_id)) + .query(FindRolesByAccountId::new(alice_id)) .execute_all()?; assert!(found_role_ids.contains(&role_id)); @@ -99,7 +96,7 @@ fn unregistered_role_removed_from_account() -> Result<()> { // Check that Mouse has root role let found_mouse_roles = test_client - .query(client::role::by_account_id(mouse_id.clone())) + .query(FindRolesByAccountId::new(mouse_id.clone())) .execute_all()?; assert!(found_mouse_roles.contains(&role_id)); @@ -109,7 +106,7 @@ fn unregistered_role_removed_from_account() -> Result<()> { // Check that Mouse doesn't have the root role let found_mouse_roles = test_client - .query(client::role::by_account_id(mouse_id.clone())) + .query(FindRolesByAccountId::new(mouse_id.clone())) .execute_all()?; assert!(!found_mouse_roles.contains(&role_id)); @@ -169,7 +166,7 @@ fn role_permissions_are_deduplicated() { .expect("failed to register role"); let role = test_client - .query(client::role::all()) + .query(FindRoles::new()) .filter_with(|role| role.id.eq(role_id)) .execute_single() .expect("failed to find role"); @@ -224,7 +221,7 @@ fn grant_revoke_role_permissions() -> Result<()> { // Alice can't modify Mouse's metadata without proper permission assert!(!test_client - .query(client::permission::by_account_id(alice_id.clone())) + .query(FindPermissionsByAccountId::new(alice_id.clone())) .execute_all()? .iter() .any(|permission| { @@ -241,7 +238,7 @@ fn grant_revoke_role_permissions() -> Result<()> { .sign(mouse_keypair.private_key()); test_client.submit_transaction_blocking(&grant_role_permission_tx)?; assert!(test_client - .query(client::role::by_account_id(alice_id.clone())) + .query(FindRolesByAccountId::new(alice_id.clone())) .execute_all()? .iter() .any(|account_role_id| *account_role_id == role_id)); @@ -253,7 +250,7 @@ fn grant_revoke_role_permissions() -> Result<()> { .sign(mouse_keypair.private_key()); test_client.submit_transaction_blocking(&revoke_role_permission_tx)?; assert!(!test_client - .query(client::permission::by_account_id(alice_id.clone())) + .query(FindPermissionsByAccountId::new(alice_id.clone())) .execute_all()? .iter() .any(|permission| { diff --git a/crates/iroha/tests/set_parameter.rs b/crates/iroha/tests/set_parameter.rs index af366ffc93b..f06fc3c704a 100644 --- a/crates/iroha/tests/set_parameter.rs +++ b/crates/iroha/tests/set_parameter.rs @@ -1,10 +1,7 @@ use eyre::Result; -use iroha::{ - client, - data_model::{ - parameter::{BlockParameter, Parameter, Parameters}, - prelude::*, - }, +use iroha::data_model::{ + parameter::{BlockParameter, Parameter, Parameters}, + prelude::*, }; use iroha_test_network::*; use nonzero_ext::nonzero; @@ -18,7 +15,7 @@ fn can_change_parameter_value() -> Result<()> { .start_blocking()?; let test_client = network.client(); - let old_params: Parameters = test_client.query_single(client::parameter::all())?; + let old_params: Parameters = test_client.query_single(FindParameters::new())?; assert_eq!(old_params.block.max_transactions, nonzero!(16u64)); let new_value = nonzero!(32u64); @@ -26,7 +23,7 @@ fn can_change_parameter_value() -> Result<()> { BlockParameter::MaxTransactions(new_value), )))?; - let params = test_client.query_single(client::parameter::all())?; + let params = test_client.query_single(FindParameters::new())?; assert_eq!(params.block.max_transactions, new_value); Ok(()) diff --git a/crates/iroha/tests/sorting.rs b/crates/iroha/tests/sorting.rs index 3bf941afcd5..9921a42a218 100644 --- a/crates/iroha/tests/sorting.rs +++ b/crates/iroha/tests/sorting.rs @@ -2,7 +2,7 @@ use std::collections::HashSet; use eyre::{Result, WrapErr as _}; use iroha::{ - client::{self, QueryResult}, + client::QueryResult, crypto::KeyPair, data_model::{ account::Account, name::Name, prelude::*, @@ -77,7 +77,7 @@ fn correct_pagination_assets_after_creating_new_one() { .expect("Valid"); let queried_assets = test_client - .query(client::asset::all()) + .query(FindAssets::new()) .filter(xor_filter.clone()) .with_pagination(pagination) .with_sorting(sorting.clone()) @@ -102,7 +102,7 @@ fn correct_pagination_assets_after_creating_new_one() { .expect("Valid"); let queried_assets = test_client - .query(client::asset::all()) + .query(FindAssets::new()) .filter(xor_filter) .with_pagination(pagination) .with_sorting(sorting) @@ -152,7 +152,7 @@ fn correct_sorting_of_entities() { .expect("Valid"); let res = test_client - .query(client::asset::all_definitions()) + .query(FindAssetsDefinitions::new()) .with_sorting(Sorting::by_metadata_key(sort_by_metadata_key.clone())) .filter_with(|asset_definition| asset_definition.id.name.starts_with("xor_")) .execute_all() @@ -202,7 +202,7 @@ fn correct_sorting_of_entities() { .expect("Valid"); let res = test_client - .query(client::account::all()) + .query(FindAccounts::new()) .with_sorting(Sorting::by_metadata_key(sort_by_metadata_key.clone())) .filter_with(|account| account.id.domain_id.eq(domain_id)) .execute_all() @@ -238,7 +238,7 @@ fn correct_sorting_of_entities() { .expect("Valid"); let res = test_client - .query(client::domain::all()) + .query(FindDomains::new()) .with_sorting(Sorting::by_metadata_key(sort_by_metadata_key.clone())) .filter_with(|domain| domain.id.name.starts_with("neverland")) .execute_all() @@ -274,7 +274,7 @@ fn correct_sorting_of_entities() { .expect("Valid"); let res = test_client - .query(client::domain::all()) + .query(FindDomains::new()) .with_sorting(Sorting::by_metadata_key(sort_by_metadata_key)) .filter_with(|domain| domain.id.name.starts_with("neverland_")) .execute() @@ -340,7 +340,7 @@ fn sort_only_elements_which_have_sorting_key() -> Result<()> { .wrap_err("Failed to register accounts")?; let res = test_client - .query(client::account::all()) + .query(FindAccounts::new()) .with_sorting(Sorting::by_metadata_key(sort_by_metadata_key)) .filter_with(|account| account.id.domain_id.eq(domain_id)) .execute_all() diff --git a/crates/iroha/tests/transfer_asset.rs b/crates/iroha/tests/transfer_asset.rs index aed42d95995..0384b297058 100644 --- a/crates/iroha/tests/transfer_asset.rs +++ b/crates/iroha/tests/transfer_asset.rs @@ -1,12 +1,9 @@ -use iroha::{ - client, - data_model::{ - account::{Account, AccountId}, - asset::{Asset, AssetDefinition}, - isi::{Instruction, InstructionBox}, - prelude::*, - Registered, - }, +use iroha::data_model::{ + account::{Account, AccountId}, + asset::{Asset, AssetDefinition}, + isi::{Instruction, InstructionBox}, + prelude::*, + Registered, }; use iroha_test_network::*; use iroha_test_samples::{gen_account_in, ALICE_ID}; @@ -58,7 +55,7 @@ fn simulate_transfer_store_asset() { .submit_blocking(transfer_asset) .expect("Failed to transfer asset."); assert!(iroha - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(mouse_id.clone())) .execute_all() .unwrap() @@ -112,7 +109,7 @@ fn simulate_transfer( .submit_blocking(transfer_asset) .expect("Failed to transfer asset."); assert!(iroha - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(mouse_id.clone())) .execute_all() .unwrap() diff --git a/crates/iroha/tests/transfer_domain.rs b/crates/iroha/tests/transfer_domain.rs index 0c9250e0512..e7cfaa0f2a5 100644 --- a/crates/iroha/tests/transfer_domain.rs +++ b/crates/iroha/tests/transfer_domain.rs @@ -1,6 +1,5 @@ use eyre::Result; use iroha::{ - client, crypto::KeyPair, data_model::{prelude::*, transaction::error::TransactionRejectionReason}, }; @@ -331,7 +330,7 @@ fn domain_owner_transfer() -> Result<()> { test_client.submit_blocking(Register::account(bob))?; let domain = test_client - .query(client::domain::all()) + .query(FindDomains::new()) .filter_with(|domain| domain.id.eq(kingdom_id.clone())) .execute_single()?; @@ -346,7 +345,7 @@ fn domain_owner_transfer() -> Result<()> { .expect("Failed to submit transaction"); let domain = test_client - .query(client::domain::all()) + .query(FindDomains::new()) .filter_with(|domain| domain.id.eq(kingdom_id.clone())) .execute_single()?; assert_eq!(domain.owned_by(), &bob_id); @@ -381,7 +380,7 @@ fn not_allowed_to_transfer_other_user_domain() -> Result<()> { let client = network.client(); let domain = client - .query(client::domain::all()) + .query(FindDomains::new()) .filter_with(|domain| domain.id.eq(foo_domain.clone())) .execute_single()?; assert_eq!(domain.owned_by(), &user1); diff --git a/crates/iroha/tests/triggers/by_call_trigger.rs b/crates/iroha/tests/triggers/by_call_trigger.rs index edebfc6e868..c9f6344c2c0 100644 --- a/crates/iroha/tests/triggers/by_call_trigger.rs +++ b/crates/iroha/tests/triggers/by_call_trigger.rs @@ -313,7 +313,7 @@ fn only_account_with_permission_can_register_trigger() -> Result<()> { test_client.submit_blocking(Register::account(rabbit_account))?; test_client - .query(client::account::all()) + .query(FindAccounts::new()) .filter_with(|account| account.id.eq(rabbit_account_id.clone())) .execute_single() .expect("Account not found"); diff --git a/crates/iroha/tests/triggers/data_trigger.rs b/crates/iroha/tests/triggers/data_trigger.rs index b882356b21c..d571d2b414d 100644 --- a/crates/iroha/tests/triggers/data_trigger.rs +++ b/crates/iroha/tests/triggers/data_trigger.rs @@ -14,7 +14,7 @@ fn must_execute_both_triggers() -> Result<()> { let get_asset_value = |iroha: &client::Client, asset_id: AssetId| -> Numeric { match *iroha - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.eq(asset_id)) .execute_single() .unwrap() diff --git a/crates/iroha/tests/triggers/mod.rs b/crates/iroha/tests/triggers/mod.rs index 329e0f06ecb..7dbe855dd12 100644 --- a/crates/iroha/tests/triggers/mod.rs +++ b/crates/iroha/tests/triggers/mod.rs @@ -18,7 +18,7 @@ mod trigger_rollback; fn get_asset_value(client: &Client, asset_id: AssetId) -> Numeric { let asset = client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.eq(asset_id)) .execute_single() .unwrap(); diff --git a/crates/iroha/tests/triggers/time_trigger.rs b/crates/iroha/tests/triggers/time_trigger.rs index ce870abce33..62903a303b4 100644 --- a/crates/iroha/tests/triggers/time_trigger.rs +++ b/crates/iroha/tests/triggers/time_trigger.rs @@ -195,7 +195,7 @@ fn mint_nft_for_every_user_every_1_sec() -> Result<()> { let start_pattern = "nft_number_"; let end_pattern = format!("_for_{}#{}", account_id.signatory(), account_id.domain()); let assets = test_client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(account_id.clone())) .execute_all()?; let count: u64 = assets diff --git a/crates/iroha/tests/triggers/trigger_rollback.rs b/crates/iroha/tests/triggers/trigger_rollback.rs index 9d807c326e3..1e1711ce8ac 100644 --- a/crates/iroha/tests/triggers/trigger_rollback.rs +++ b/crates/iroha/tests/triggers/trigger_rollback.rs @@ -37,7 +37,7 @@ fn failed_trigger_revert() -> Result<()> { //Then let query_result = client - .query(client::asset::all_definitions()) + .query(FindAssetsDefinitions::new()) .execute_all()?; assert!(query_result .iter() diff --git a/crates/iroha/tests/tx_history.rs b/crates/iroha/tests/tx_history.rs index adcafebcf4d..8522db1f96b 100644 --- a/crates/iroha/tests/tx_history.rs +++ b/crates/iroha/tests/tx_history.rs @@ -1,8 +1,5 @@ use eyre::Result; -use iroha::{ - client::transaction, - data_model::{prelude::*, query::parameters::Pagination}, -}; +use iroha::data_model::{prelude::*, query::parameters::Pagination}; use iroha_test_network::*; use iroha_test_samples::ALICE_ID; use nonzero_ext::nonzero; @@ -42,7 +39,7 @@ fn client_has_rejected_and_accepted_txs_should_return_tx_history() -> Result<()> } let transactions = client - .query(transaction::all()) + .query(FindTransactions::new()) .filter_with(|tx| tx.transaction.value.authority.eq(account_id.clone())) .with_pagination(Pagination { limit: Some(nonzero!(50_u64)), diff --git a/crates/iroha/tests/tx_rollback.rs b/crates/iroha/tests/tx_rollback.rs index 4c11cf5531e..d7b8c42bbee 100644 --- a/crates/iroha/tests/tx_rollback.rs +++ b/crates/iroha/tests/tx_rollback.rs @@ -1,5 +1,5 @@ use eyre::Result; -use iroha::{client, data_model::prelude::*}; +use iroha::data_model::prelude::*; use iroha_test_network::*; use iroha_test_samples::ALICE_ID; @@ -21,16 +21,14 @@ fn client_sends_transaction_with_invalid_instruction_should_not_see_any_changes( //Then; let query_result = client - .query(client::asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.account.eq(account_id)) .execute_all()?; assert!(query_result .iter() .all(|asset| *asset.id().definition() != wrong_asset_definition_id)); - let definition_query_result = client - .query(client::asset::all_definitions()) - .execute_all()?; + let definition_query_result = client.query(FindAssetsDefinitions::new()).execute_all()?; assert!(definition_query_result .iter() .all(|asset| *asset.id() != wrong_asset_definition_id)); diff --git a/crates/iroha/tests/upgrade.rs b/crates/iroha/tests/upgrade.rs index cadffa048e4..4e456510dec 100644 --- a/crates/iroha/tests/upgrade.rs +++ b/crates/iroha/tests/upgrade.rs @@ -2,7 +2,7 @@ use executor_custom_data_model::permissions::CanControlDomainLives; use eyre::Result; use futures_util::TryStreamExt as _; use iroha::{ - client::{self, Client}, + client::Client, data_model::{ parameter::{Parameter, SmartContractParameter}, prelude::*, @@ -81,7 +81,7 @@ fn executor_upgrade_should_run_migration() -> Result<()> { // Check that Alice has permission to unregister Wonderland let alice_id = ALICE_ID.clone(); let alice_permissions = client - .query(client::permission::by_account_id(alice_id.clone())) + .query(FindPermissionsByAccountId::new(alice_id.clone())) .execute_all()?; let can_unregister_domain = CanUnregisterDomain { domain: "wonderland".parse()?, @@ -108,7 +108,7 @@ fn executor_upgrade_should_run_migration() -> Result<()> { // Check that Alice has `CanControlDomainLives` permission let alice_permissions = client - .query(client::permission::by_account_id(alice_id.clone())) + .query(FindPermissionsByAccountId::new(alice_id.clone())) .execute_all()?; let can_control_domain_lives = CanControlDomainLives; assert!(alice_permissions.iter().any(|permission| { @@ -143,7 +143,7 @@ fn executor_upgrade_should_revoke_removed_permissions() -> Result<()> { // Check that `TEST_ROLE` has permission assert!(client - .query(client::role::all()) + .query(FindRoles::new()) .execute_all()? .into_iter() .find(|role| role.id == test_role_id) @@ -158,7 +158,7 @@ fn executor_upgrade_should_revoke_removed_permissions() -> Result<()> { // Check that Alice has permission let alice_id = ALICE_ID.clone(); assert!(client - .query(client::permission::by_account_id(alice_id.clone())) + .query(FindPermissionsByAccountId::new(alice_id.clone())) .execute_all()? .iter() .any(|permission| { @@ -176,7 +176,7 @@ fn executor_upgrade_should_revoke_removed_permissions() -> Result<()> { // Check that `TEST_ROLE` doesn't have permission assert!(!client - .query(client::role::all()) + .query(FindRoles::new()) .execute_all()? .into_iter() .find(|role| role.id == test_role_id) @@ -190,7 +190,7 @@ fn executor_upgrade_should_revoke_removed_permissions() -> Result<()> { // Check that Alice doesn't have permission assert!(!client - .query(client::permission::by_account_id(alice_id.clone())) + .query(FindPermissionsByAccountId::new(alice_id.clone())) .execute_all()? .iter() .any(|permission| { @@ -306,7 +306,7 @@ fn migration_fail_should_not_cause_any_effects() { let assert_domain_does_not_exist = |client: &Client, domain_id: &DomainId| { assert!( client - .query(client::domain::all()) + .query(FindDomains::new()) .filter_with(|domain| domain.id.eq(domain_id.clone())) .execute_single_opt() .expect("Query failed") diff --git a/crates/iroha_cli/src/main.rs b/crates/iroha_cli/src/main.rs index 6afb8ee7033..7da333bf27e 100644 --- a/crates/iroha_cli/src/main.rs +++ b/crates/iroha_cli/src/main.rs @@ -374,8 +374,6 @@ mod blocks { } mod domain { - use iroha::client; - use super::*; /// Arguments for domain subcommand @@ -430,7 +428,7 @@ mod domain { fn run(self, context: &mut dyn RunContext) -> Result<()> { let client = context.client_from_config(); - let query = client.query(client::domain::all()); + let query = client.query(FindDomains::new()); let query = match self { List::All => query, @@ -545,8 +543,6 @@ mod domain { mod account { use std::fmt::Debug; - use iroha::client::{self}; - use super::{Permission as DataModelPermission, *}; /// subcommands for account subcommand @@ -606,7 +602,7 @@ mod account { fn run(self, context: &mut dyn RunContext) -> Result<()> { let client = context.client_from_config(); - let query = client.query(client::account::all()); + let query = client.query(FindAccounts::new()); let query = match self { List::All => query, @@ -686,10 +682,7 @@ mod account { } mod asset { - use iroha::{ - client::{self, asset}, - data_model::name::Name, - }; + use iroha::data_model::name::Name; use super::*; @@ -799,7 +792,7 @@ mod asset { fn run(self, context: &mut dyn RunContext) -> Result<()> { let client = context.client_from_config(); - let query = client.query(client::asset::all_definitions()); + let query = client.query(FindAssetsDefinitions::new()); let query = match self { List::All => query, @@ -911,7 +904,7 @@ mod asset { let Self { id: asset_id } = self; let client = context.client_from_config(); let asset = client - .query(asset::all()) + .query(FindAssets::new()) .filter_with(|asset| asset.id.eq(asset_id)) .execute_single() .wrap_err("Failed to get asset.")?; @@ -933,7 +926,7 @@ mod asset { fn run(self, context: &mut dyn RunContext) -> Result<()> { let client = context.client_from_config(); - let query = client.query(client::asset::all()); + let query = client.query(FindAssets::new()); let query = match self { List::All => query, diff --git a/crates/iroha_data_model/src/query/mod.rs b/crates/iroha_data_model/src/query/mod.rs index c2ed143790f..ea9f06dc433 100644 --- a/crates/iroha_data_model/src/query/mod.rs +++ b/crates/iroha_data_model/src/query/mod.rs @@ -751,7 +751,7 @@ pub mod asset { #[derive(Copy, Display)] #[display(fmt = "Find all asset definitions")] #[ffi_type] - pub struct FindAssetsDefinitions; // TODO: Should it be renamed to [`FindAllAssetDefinitions`? + pub struct FindAssetsDefinitions; /// [`FindAssetQuantityById`] Iroha Query gets [`AssetId`] as input and finds [`Asset::quantity`] /// value if [`Asset`] is presented in Iroha Peer.