Skip to content

Commit

Permalink
test: update all integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: 0x009922 <[email protected]>
  • Loading branch information
0x009922 committed Sep 26, 2024
1 parent 74047a3 commit 2cc42a2
Show file tree
Hide file tree
Showing 21 changed files with 329 additions and 437 deletions.
22 changes: 11 additions & 11 deletions crates/iroha/tests/integration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ mod asset;
mod asset_propagation;
mod events;
mod extra_functional;
// mod multisig;
// mod non_mintable;
// mod pagination;
mod multisig;
mod non_mintable;
mod pagination;
mod permissions;
mod queries;
// mod roles;
// mod set_parameter;
// mod sorting;
mod roles;
mod set_parameter;
mod sorting;
mod status_response;
// mod transfer_asset;
mod transfer_asset;
mod transfer_domain;
// mod triggers;
mod triggers;
mod tx_chain_id;
// mod tx_history;
// mod tx_rollback;
// mod upgrade;
mod tx_history;
mod tx_rollback;
mod upgrade;
31 changes: 11 additions & 20 deletions crates/iroha/tests/integration/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use iroha::{
parameter::SmartContractParameter,
prelude::*,
query::{builder::SingleQueryError, trigger::FindTriggers},
transaction::{TransactionBuilder, WasmSmartContract},
transaction::TransactionBuilder,
},
};
use iroha_test_network::*;
Expand All @@ -18,28 +18,19 @@ use nonzero_ext::nonzero;

#[test]
fn mutlisig() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(11_400).start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);

test_client.submit_all_blocking([
SetParameter::new(Parameter::SmartContract(SmartContractParameter::Fuel(
nonzero!(100_000_000_u64),
))),
SetParameter::new(Parameter::Executor(SmartContractParameter::Fuel(nonzero!(
100_000_000_u64
)))),
])?;
let (network, _rt) = NetworkBuilder::new()
.with_genesis_instruction(SetParameter::new(Parameter::SmartContract(
SmartContractParameter::Fuel(nonzero!(100_000_000_u64)),
)))
.with_genesis_instruction(SetParameter::new(Parameter::Executor(
SmartContractParameter::Fuel(nonzero!(100_000_000_u64)),
)))
.start_blocking()?;
let test_client = network.client();

let account_id = ALICE_ID.clone();
let multisig_register_trigger_id = "multisig_register".parse::<TriggerId>()?;

let wasm = iroha_wasm_builder::Builder::new("../../wasm_samples/multisig_register")
.show_output()
.build()?
.optimize()?
.into_bytes()?;
let wasm = WasmSmartContract::from_compiled(wasm);

let wasm = crate::build_wasm("../../wasm_samples/multisig_register");
let trigger = Trigger::new(
multisig_register_trigger_id.clone(),
Action::new(
Expand Down
85 changes: 36 additions & 49 deletions crates/iroha/tests/integration/non_mintable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use iroha_test_samples::ALICE_ID;

#[test]
fn non_mintable_asset_can_be_minted_once_but_not_twice() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(10_625).start_with_runtime();
wait_for_genesis_committed(&[test_client.clone()], 0);
let (network, _rt) = NetworkBuilder::new().start_blocking()?;
let test_client = network.client();

// Given
let account_id = ALICE_ID.clone();
Expand All @@ -31,41 +31,28 @@ fn non_mintable_asset_can_be_minted_once_but_not_twice() -> Result<()> {
let tx = test_client.build_transaction(instructions, metadata);

// We can register and mint the non-mintable token
test_client.submit_transaction(&tx)?;
test_client.poll(|client| {
let assets = client
.query(client::asset::all())
.filter_with(|asset| asset.id.account.eq(account_id.clone()))
.execute_all()?;
Ok(assets.iter().any(|asset| {
test_client.submit_transaction_blocking(&tx)?;
assert!(test_client
.query(client::asset::all())
.filter_with(|asset| asset.id.account.eq(account_id.clone()))
.execute_all()?
.iter()
.any(|asset| {
*asset.id().definition() == asset_definition_id
&& *asset.value() == AssetValue::Numeric(numeric!(200))
}))
})?;
}));

// We can submit the request to mint again.
test_client.submit_all([mint])?;

// However, this will fail
assert!(test_client
.poll(|client| {
let assets = client
.query(client::asset::all())
.filter_with(|asset| asset.id.account.eq(account_id.clone()))
.execute_all()?;
Ok(assets.iter().any(|asset| {
*asset.id().definition() == asset_definition_id
&& *asset.value() == AssetValue::Numeric(numeric!(400))
}))
})
.is_err());
assert!(test_client.submit_all_blocking([mint]).is_err());

Ok(())
}

#[test]
fn non_mintable_asset_cannot_be_minted_if_registered_with_non_zero_value() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(10_610).start_with_runtime();
wait_for_genesis_committed(&[test_client.clone()], 0);
let (network, _rt) = NetworkBuilder::new().start_blocking()?;
let test_client = network.client();

// Given
let account_id = ALICE_ID.clone();
Expand All @@ -80,18 +67,19 @@ fn non_mintable_asset_cannot_be_minted_if_registered_with_non_zero_value() -> Re
let register_asset = Register::asset(Asset::new(asset_id.clone(), 1_u32));

// We can register the non-mintable token
test_client
.submit_all::<InstructionBox>([create_asset.into(), register_asset.clone().into()])?;
test_client.poll(|client| {
let assets = client
.query(client::asset::all())
.filter_with(|asset| asset.id.account.eq(account_id.clone()))
.execute_all()?;
Ok(assets.iter().any(|asset| {
test_client.submit_all_blocking::<InstructionBox>([
create_asset.into(),
register_asset.clone().into(),
])?;
assert!(test_client
.query(client::asset::all())
.filter_with(|asset| asset.id.account.eq(account_id.clone()))
.execute_all()?
.iter()
.any(|asset| {
*asset.id().definition() == asset_definition_id
&& *asset.value() == AssetValue::Numeric(numeric!(1))
}))
})?;
}));

// But only once
assert!(test_client.submit_blocking(register_asset).is_err());
Expand All @@ -105,8 +93,8 @@ fn non_mintable_asset_cannot_be_minted_if_registered_with_non_zero_value() -> Re

#[test]
fn non_mintable_asset_can_be_minted_if_registered_with_zero_value() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(10_630).start_with_runtime();
wait_for_genesis_committed(&[test_client.clone()], 0);
let (network, _rt) = NetworkBuilder::new().start_blocking()?;
let test_client = network.client();

// Given
let account_id = ALICE_ID.clone();
Expand All @@ -122,21 +110,20 @@ fn non_mintable_asset_can_be_minted_if_registered_with_zero_value() -> Result<()
let mint = Mint::asset_numeric(1u32, asset_id);

// We can register the non-mintable token wih zero value and then mint it
test_client.submit_all::<InstructionBox>([
test_client.submit_all_blocking::<InstructionBox>([
create_asset.into(),
register_asset.into(),
mint.into(),
])?;
test_client.poll(|client| {
let assets = client
.query(client::asset::all())
.filter_with(|asset| asset.id.account.eq(account_id.clone()))
.execute_all()?;

Ok(assets.iter().any(|asset| {
assert!(test_client
.query(client::asset::all())
.filter_with(|asset| asset.id.account.eq(account_id.clone()))
.execute_all()?
.iter()
.any(|asset| {
*asset.id().definition() == asset_definition_id
&& *asset.value() == AssetValue::Numeric(numeric!(1))
}))
})?;
}));

Ok(())
}
12 changes: 6 additions & 6 deletions crates/iroha/tests/integration/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use nonzero_ext::nonzero;

#[test]
fn limits_should_work() -> Result<()> {
let (_rt, _peer, client) = <PeerBuilder>::new().with_port(10_690).start_with_runtime();
wait_for_genesis_committed(&vec![client.clone()], 0);
let (network, _rt) = NetworkBuilder::new().start_blocking()?;
let client = network.client();

register_assets(&client)?;

Expand All @@ -26,8 +26,8 @@ fn limits_should_work() -> Result<()> {

#[test]
fn reported_length_should_be_accurate() -> Result<()> {
let (_rt, _peer, client) = <PeerBuilder>::new().with_port(11_200).start_with_runtime();
wait_for_genesis_committed(&vec![client.clone()], 0);
let (network, _rt) = NetworkBuilder::new().start_blocking()?;
let client = network.client();

register_assets(&client)?;

Expand Down Expand Up @@ -60,8 +60,8 @@ fn fetch_size_should_work() -> Result<()> {
QueryWithFilter, QueryWithParams,
};

let (_rt, _peer, client) = <PeerBuilder>::new().with_port(11_120).start_with_runtime();
wait_for_genesis_committed(&vec![client.clone()], 0);
let (network, _rt) = NetworkBuilder::new().start_blocking()?;
let client = network.client();

register_assets(&client)?;

Expand Down
36 changes: 16 additions & 20 deletions crates/iroha/tests/integration/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use serde_json::json;

#[test]
fn register_empty_role() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(10_695).start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);
let (network, _rt) = NetworkBuilder::new().start_blocking()?;
let test_client = network.client();

let role_id = "root".parse().expect("Valid");
let register_role = Register::role(Role::new(role_id));
Expand All @@ -35,10 +35,8 @@ fn register_empty_role() -> Result<()> {
/// @s8sato added: This test represents #2081 case.
#[test]
fn register_and_grant_role_for_metadata_access() -> Result<()> {
let chain_id = ChainId::from("00000000-0000-0000-0000-000000000000");

let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(10_700).start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);
let (network, _rt) = NetworkBuilder::new().start_blocking()?;
let test_client = network.client();

let alice_id = ALICE_ID.clone();
let (mouse_id, mouse_keypair) = gen_account_in("wonderland");
Expand All @@ -61,7 +59,7 @@ fn register_and_grant_role_for_metadata_access() -> Result<()> {

// Mouse grants role to Alice
let grant_role = Grant::role(role_id.clone(), alice_id.clone());
let grant_role_tx = TransactionBuilder::new(chain_id, mouse_id.clone())
let grant_role_tx = TransactionBuilder::new(network.chain_id(), mouse_id.clone())
.with_instructions([grant_role])
.sign(mouse_keypair.private_key());
test_client.submit_transaction_blocking(&grant_role_tx)?;
Expand All @@ -85,8 +83,8 @@ fn register_and_grant_role_for_metadata_access() -> Result<()> {

#[test]
fn unregistered_role_removed_from_account() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(10_705).start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);
let (network, _rt) = NetworkBuilder::new().start_blocking()?;
let test_client = network.client();

let role_id: RoleId = "root".parse().expect("Valid");
let alice_id = ALICE_ID.clone();
Expand Down Expand Up @@ -127,8 +125,8 @@ fn unregistered_role_removed_from_account() -> Result<()> {

#[test]
fn role_with_invalid_permissions_is_not_accepted() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(11_025).start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);
let (network, _rt) = NetworkBuilder::new().start_blocking()?;
let test_client = network.client();

let role_id = "ACCESS_TO_ACCOUNT_METADATA".parse()?;
let role = Role::new(role_id).add_permission(CanControlDomainLives);
Expand All @@ -155,8 +153,8 @@ fn role_with_invalid_permissions_is_not_accepted() -> Result<()> {
// so that they don't get deduplicated eagerly but rather in the executor
// This way, if the executor compares permissions just as JSON strings, the test will fail
fn role_permissions_are_deduplicated() {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(11_235).start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);
let (network, _rt) = NetworkBuilder::new().start_blocking().unwrap();
let test_client = network.client();

let allow_alice_to_transfer_rose_1 = Permission::new(
"CanTransferUserAsset".parse().unwrap(),
Expand Down Expand Up @@ -194,10 +192,8 @@ fn role_permissions_are_deduplicated() {

#[test]
fn grant_revoke_role_permissions() -> Result<()> {
let chain_id = ChainId::from("00000000-0000-0000-0000-000000000000");

let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(11_245).start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);
let (network, _rt) = NetworkBuilder::new().start_blocking()?;
let test_client = network.client();

let alice_id = ALICE_ID.clone();
let (mouse_id, mouse_keypair) = gen_account_in("wonderland");
Expand All @@ -219,7 +215,7 @@ fn grant_revoke_role_permissions() -> Result<()> {

// Mouse grants role to Alice
let grant_role = Grant::role(role_id.clone(), alice_id.clone());
let grant_role_tx = TransactionBuilder::new(chain_id.clone(), mouse_id.clone())
let grant_role_tx = TransactionBuilder::new(network.chain_id(), mouse_id.clone())
.with_instructions([grant_role])
.sign(mouse_keypair.private_key());
test_client.submit_transaction_blocking(&grant_role_tx)?;
Expand Down Expand Up @@ -251,7 +247,7 @@ fn grant_revoke_role_permissions() -> Result<()> {
.expect_err("shouldn't be able to modify metadata");

// Alice can modify Mouse's metadata after permission is granted to role
let grant_role_permission_tx = TransactionBuilder::new(chain_id.clone(), mouse_id.clone())
let grant_role_permission_tx = TransactionBuilder::new(network.chain_id(), mouse_id.clone())
.with_instructions([grant_role_permission])
.sign(mouse_keypair.private_key());
test_client.submit_transaction_blocking(&grant_role_permission_tx)?;
Expand All @@ -266,7 +262,7 @@ fn grant_revoke_role_permissions() -> Result<()> {
test_client.submit_blocking(set_key_value.clone())?;

// Alice can't modify Mouse's metadata after permission is removed from role
let revoke_role_permission_tx = TransactionBuilder::new(chain_id.clone(), mouse_id)
let revoke_role_permission_tx = TransactionBuilder::new(network.chain_id(), mouse_id)
.with_instructions([revoke_role_permission])
.sign(mouse_keypair.private_key());
test_client.submit_transaction_blocking(&revoke_role_permission_tx)?;
Expand Down
6 changes: 4 additions & 2 deletions crates/iroha/tests/integration/set_parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ use iroha_test_network::*;

#[test]
fn can_change_parameter_value() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(11_135).start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);
let (network, _rt) = NetworkBuilder::new()
.with_default_pipeline_time()
.start_blocking()?;
let test_client = network.client();

let old_params: Parameters = test_client.query_single(client::parameter::all())?;
assert_eq!(
Expand Down
Loading

0 comments on commit 2cc42a2

Please sign in to comment.