From f3da4eb41173cc5dcbaeacee107dbc153dd2610c Mon Sep 17 00:00:00 2001 From: Ales Tsurko Date: Thu, 16 Jun 2022 01:13:14 +0300 Subject: [PATCH] [fix] #2137: Fix the rest of the tests (cli, client, data_model) Signed-off-by: Ales Tsurko --- Cargo.lock | 2 +- cli/Cargo.toml | 2 +- cli/src/torii/tests.rs | 24 +++++++++++++++++++++++ client/tests/integration/offline_peers.rs | 3 ++- client/tests/integration/queries/role.rs | 5 +++++ data_model/tests/data_model.rs | 3 ++- 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8631f5f251c..9fdb87ffb93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1700,9 +1700,9 @@ dependencies = [ "parity-scale-codec", "serde", "serde_json", + "test_network", "thiserror", "tokio", - "unique_port", "warp", ] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index a22c070feb3..4fbb67951c5 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -63,4 +63,4 @@ thiserror = "1.0.28" color-eyre = "0.5.11" [dev-dependencies] -unique_port = "0.1.0" +test_network = { version = "=2.0.0-pre-rc.5", path = "../core/test_network" } diff --git a/cli/src/torii/tests.rs b/cli/src/torii/tests.rs index ae96f310738..1edaccc5d5b 100644 --- a/cli/src/torii/tests.rs +++ b/cli/src/torii/tests.rs @@ -22,6 +22,7 @@ use iroha_data_model::{account::GENESIS_ACCOUNT_NAME, predicate::PredicateBox, p use iroha_version::prelude::*; use tokio::time; use warp::test::WsClient; +use test_network::{generate_offset, *}; use super::{routing::*, *}; use crate::{ @@ -83,6 +84,7 @@ async fn create_torii() -> (Torii, KeyPair) { #[tokio::test(flavor = "multi_thread")] async fn create_and_start_torii() { + unique_port::set_offset(generate_offset!()).unwrap(); let (torii, _) = create_torii().await; let result = time::timeout(Duration::from_millis(50), torii.start()).await; @@ -92,6 +94,7 @@ async fn create_and_start_torii() { #[tokio::test(flavor = "multi_thread")] async fn torii_pagination() { + unique_port::set_offset(generate_offset!()).unwrap(); let (torii, keys) = create_torii().await; let get_domains = |start, limit| { @@ -312,6 +315,7 @@ fn asset_id(name: &str, account: &str) -> AssetId { #[tokio::test] async fn find_asset() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() .given(register_domain()) .given(register_account("alice")) @@ -338,6 +342,7 @@ async fn find_asset() { #[tokio::test] async fn find_asset_with_no_mint() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() .given(register_domain()) .given(register_account("alice")) @@ -360,6 +365,7 @@ async fn find_asset_with_no_mint() { #[tokio::test] async fn find_asset_with_no_asset_definition() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() .given(register_domain()) .given(register_account("alice")) @@ -382,6 +388,7 @@ async fn find_asset_with_no_asset_definition() { #[tokio::test] async fn find_asset_with_no_account() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() .given(register_domain()) // .given(register_account("alice")) @@ -404,6 +411,7 @@ async fn find_asset_with_no_account() { #[tokio::test] async fn find_asset_with_no_domain() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() // .given(register_domain()) // .given(register_account("alice")) @@ -426,6 +434,7 @@ async fn find_asset_with_no_domain() { #[tokio::test] async fn find_asset_definition() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() .given(register_domain()) .given(register_asset_definition("rose")) @@ -439,6 +448,7 @@ async fn find_asset_definition() { #[tokio::test] async fn find_asset_definition_with_no_asset_definition() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() .given(register_domain()) // .given(register_asset_definition("rose")) @@ -459,6 +469,7 @@ async fn find_asset_definition_with_no_asset_definition() { #[tokio::test] async fn find_asset_definition_with_no_domain() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() // .given(register_domain()) // .given(register_asset_definition("rose")) @@ -479,6 +490,7 @@ async fn find_asset_definition_with_no_domain() { #[tokio::test] async fn find_account() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() .given(register_domain()) .given(register_account("alice")) @@ -495,6 +507,7 @@ async fn find_account() { #[tokio::test] async fn find_account_with_no_account() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() .given(register_domain()) // .given(register_account("alice")) @@ -515,6 +528,7 @@ async fn find_account_with_no_account() { #[tokio::test] async fn find_account_with_no_domain() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() // .given(register_domain()) // .given(register_account("alice")) @@ -535,6 +549,7 @@ async fn find_account_with_no_domain() { #[tokio::test] async fn find_domain() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() .given(register_domain()) .query(QueryBox::FindDomainById(FindDomainById::new( @@ -547,6 +562,7 @@ async fn find_domain() { #[tokio::test] async fn find_domain_with_no_domain() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() // .given(register_domain()) .query(QueryBox::FindDomainById(FindDomainById::new( @@ -573,6 +589,7 @@ fn query() -> QueryBox { #[tokio::test] async fn query_with_wrong_signatory() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() .given(register_domain()) .given(register_account("alice")) @@ -601,6 +618,7 @@ async fn query_with_wrong_signature() { #[tokio::test] async fn query_with_wrong_signature_and_no_permission() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() .given(register_domain()) .given(register_account("alice")) @@ -615,6 +633,7 @@ async fn query_with_wrong_signature_and_no_permission() { #[tokio::test] async fn query_with_no_permission() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() .given(register_domain()) .given(register_account("alice")) @@ -629,6 +648,7 @@ async fn query_with_no_permission() { #[tokio::test] async fn query_with_no_permission_and_no_find() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() .given(register_domain()) // .given(register_account("alice")) @@ -643,6 +663,7 @@ async fn query_with_no_permission_and_no_find() { #[tokio::test] async fn query_with_no_find() { + unique_port::set_offset(generate_offset!()).unwrap(); QuerySet::new() .given(register_domain()) // .given(register_account("alice")) @@ -680,6 +701,7 @@ fn new_dummy() -> ValidBlock { #[tokio::test] async fn blocks_stream() { + unique_port::set_offset(generate_offset!()).unwrap(); const BLOCK_COUNT: usize = 4; let (torii, _) = create_torii().await; @@ -747,6 +769,7 @@ fn domains( #[test] fn hash_should_be_the_same() { + unique_port::set_offset(generate_offset!()).unwrap(); let key_pair = KeyPair::generate().expect("Failed to generate key pair."); let mut config = get_config( get_trusted_peers(Some(key_pair.public_key())), @@ -789,6 +812,7 @@ fn hash_should_be_the_same() { #[tokio::test] async fn test_subscription_websocket_clean_closing() { + unique_port::set_offset(generate_offset!()).unwrap(); use iroha_data_model::events::{pipeline, FilterBox}; use warp::filters::ws; diff --git a/client/tests/integration/offline_peers.rs b/client/tests/integration/offline_peers.rs index c57f4351c12..2fc5ed73c87 100644 --- a/client/tests/integration/offline_peers.rs +++ b/client/tests/integration/offline_peers.rs @@ -2,11 +2,12 @@ use iroha_client::client; use iroha_data_model::prelude::*; -use test_network::*; +use test_network::{generate_offset, *}; use tokio::runtime::Runtime; #[test] fn genesis_block_is_commited_with_some_offline_peers() { + unique_port::set_offset(generate_offset!()).unwrap(); // Given let rt = Runtime::test(); diff --git a/client/tests/integration/queries/role.rs b/client/tests/integration/queries/role.rs index 96f8b5d99f0..b9546873d13 100644 --- a/client/tests/integration/queries/role.rs +++ b/client/tests/integration/queries/role.rs @@ -21,6 +21,7 @@ fn create_role_ids() -> [::Id; 5] { #[test] fn find_roles() -> Result<()> { + unique_port::set_offset(generate_offset!()).unwrap(); let (_rt, _peer, test_client) = ::new().start_with_runtime(); wait_for_genesis_committed(&vec![test_client.clone()], 0); @@ -50,6 +51,7 @@ fn find_roles() -> Result<()> { #[test] fn find_role_ids() -> Result<()> { + unique_port::set_offset(generate_offset!()).unwrap(); let (_rt, _peer, test_client) = ::new().start_with_runtime(); wait_for_genesis_committed(&vec![test_client.clone()], 0); @@ -76,6 +78,7 @@ fn find_role_ids() -> Result<()> { #[test] fn find_role_by_id() -> Result<()> { + unique_port::set_offset(generate_offset!()).unwrap(); let (_rt, _peer, test_client) = ::new().start_with_runtime(); wait_for_genesis_committed(&vec![test_client.clone()], 0); @@ -96,6 +99,7 @@ fn find_role_by_id() -> Result<()> { #[test] fn find_unregistered_role_by_id() { + unique_port::set_offset(generate_offset!()).unwrap(); let (_rt, _peer, test_client) = ::new().start_with_runtime(); wait_for_genesis_committed(&vec![test_client.clone()], 0); @@ -113,6 +117,7 @@ fn find_unregistered_role_by_id() { #[test] fn find_roles_by_account_id() -> Result<()> { + unique_port::set_offset(generate_offset!()).unwrap(); let (_rt, _peer, test_client) = ::new().start_with_runtime(); wait_for_genesis_committed(&vec![test_client.clone()], 0); diff --git a/data_model/tests/data_model.rs b/data_model/tests/data_model.rs index 583e972cc22..11e88da58e5 100644 --- a/data_model/tests/data_model.rs +++ b/data_model/tests/data_model.rs @@ -10,7 +10,7 @@ use iroha_core::{ }; use iroha_data_model::{prelude::*, ParseError}; use small::SmallStr; -use test_network::{Peer as TestPeer, PeerBuilder, TestRuntime}; +use test_network::{generate_offset, unique_port, Peer as TestPeer, PeerBuilder, TestRuntime}; use tokio::runtime::Runtime; fn asset_id_new( @@ -143,6 +143,7 @@ mod register { #[allow(unused_must_use)] #[test] fn find_rate_and_make_exchange_isi_should_succeed() { + unique_port::set_offset(generate_offset!()).unwrap(); let kp = KeyPair::new( PublicKey::from_str( r#"ed01207233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0"#,