Skip to content

Commit

Permalink
[fix] hyperledger-iroha#2137: Refactor with new version of unique_por…
Browse files Browse the repository at this point in the history
…t crate

Signed-off-by: Ales Tsurko <[email protected]>
  • Loading branch information
ales-tsurko committed Jun 22, 2022
1 parent f3da4eb commit 891e532
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 123 deletions.
17 changes: 15 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ color-eyre = "0.5.11"

[dev-dependencies]
test_network = { version = "=2.0.0-pre-rc.5", path = "../core/test_network" }
unique_port = "0.2.0"
49 changes: 25 additions & 24 deletions cli/src/torii/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ use iroha_core::{
};
use iroha_data_model::{account::GENESIS_ACCOUNT_NAME, predicate::PredicateBox, prelude::*};
use iroha_version::prelude::*;
// use test_network::*;
use tokio::time;
use unique_port::generate_unique_start_port;
use warp::test::WsClient;
use test_network::{generate_offset, *};

use super::{routing::*, *};
use crate::{
Expand Down Expand Up @@ -84,7 +85,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();
unique_port::set_port_index(generate_unique_start_port!());
let (torii, _) = create_torii().await;

let result = time::timeout(Duration::from_millis(50), torii.start()).await;
Expand All @@ -94,7 +95,7 @@ async fn create_and_start_torii() {

#[tokio::test(flavor = "multi_thread")]
async fn torii_pagination() {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
let (torii, keys) = create_torii().await;

let get_domains = |start, limit| {
Expand Down Expand Up @@ -315,7 +316,7 @@ fn asset_id(name: &str, account: &str) -> AssetId {

#[tokio::test]
async fn find_asset() {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
.given(register_domain())
.given(register_account("alice"))
Expand All @@ -342,7 +343,7 @@ async fn find_asset() {

#[tokio::test]
async fn find_asset_with_no_mint() {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
.given(register_domain())
.given(register_account("alice"))
Expand All @@ -365,7 +366,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();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
.given(register_domain())
.given(register_account("alice"))
Expand All @@ -388,7 +389,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();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
.given(register_domain())
// .given(register_account("alice"))
Expand All @@ -411,7 +412,7 @@ async fn find_asset_with_no_account() {

#[tokio::test]
async fn find_asset_with_no_domain() {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
// .given(register_domain())
// .given(register_account("alice"))
Expand All @@ -434,7 +435,7 @@ async fn find_asset_with_no_domain() {

#[tokio::test]
async fn find_asset_definition() {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
.given(register_domain())
.given(register_asset_definition("rose"))
Expand All @@ -448,7 +449,7 @@ async fn find_asset_definition() {

#[tokio::test]
async fn find_asset_definition_with_no_asset_definition() {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
.given(register_domain())
// .given(register_asset_definition("rose"))
Expand All @@ -469,7 +470,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();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
// .given(register_domain())
// .given(register_asset_definition("rose"))
Expand All @@ -490,7 +491,7 @@ async fn find_asset_definition_with_no_domain() {

#[tokio::test]
async fn find_account() {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
.given(register_domain())
.given(register_account("alice"))
Expand All @@ -507,7 +508,7 @@ async fn find_account() {

#[tokio::test]
async fn find_account_with_no_account() {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
.given(register_domain())
// .given(register_account("alice"))
Expand All @@ -528,7 +529,7 @@ async fn find_account_with_no_account() {

#[tokio::test]
async fn find_account_with_no_domain() {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
// .given(register_domain())
// .given(register_account("alice"))
Expand All @@ -549,7 +550,7 @@ async fn find_account_with_no_domain() {

#[tokio::test]
async fn find_domain() {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
.given(register_domain())
.query(QueryBox::FindDomainById(FindDomainById::new(
Expand All @@ -562,7 +563,7 @@ async fn find_domain() {

#[tokio::test]
async fn find_domain_with_no_domain() {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
// .given(register_domain())
.query(QueryBox::FindDomainById(FindDomainById::new(
Expand All @@ -589,7 +590,7 @@ fn query() -> QueryBox {

#[tokio::test]
async fn query_with_wrong_signatory() {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
.given(register_domain())
.given(register_account("alice"))
Expand Down Expand Up @@ -618,7 +619,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();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
.given(register_domain())
.given(register_account("alice"))
Expand All @@ -633,7 +634,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();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
.given(register_domain())
.given(register_account("alice"))
Expand All @@ -648,7 +649,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();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
.given(register_domain())
// .given(register_account("alice"))
Expand All @@ -663,7 +664,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();
unique_port::set_port_index(generate_unique_start_port!());
QuerySet::new()
.given(register_domain())
// .given(register_account("alice"))
Expand Down Expand Up @@ -701,7 +702,7 @@ fn new_dummy() -> ValidBlock {

#[tokio::test]
async fn blocks_stream() {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
const BLOCK_COUNT: usize = 4;

let (torii, _) = create_torii().await;
Expand Down Expand Up @@ -769,7 +770,7 @@ fn domains(

#[test]
fn hash_should_be_the_same() {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
let key_pair = KeyPair::generate().expect("Failed to generate key pair.");
let mut config = get_config(
get_trusted_peers(Some(key_pair.public_key())),
Expand Down Expand Up @@ -812,7 +813,7 @@ fn hash_should_be_the_same() {

#[tokio::test]
async fn test_subscription_websocket_clean_closing() {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
use iroha_data_model::events::{pipeline, FilterBox};
use warp::filters::ws;

Expand Down
1 change: 1 addition & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ iroha_permissions_validators = { version = "=2.0.0-pre-rc.5", path = "../permiss
iroha = { path = "../cli", features = ["dev-telemetry", "telemetry"] }

test_network = { version = "=2.0.0-pre-rc.5", path = "../core/test_network" }
unique_port = "0.2.0"

parity-scale-codec = { version = "2.3.1", default-features = false, features = ["derive"] }
tokio = { version = "1.6.0", features = ["rt", "rt-multi-thread"]}
Expand Down
5 changes: 3 additions & 2 deletions client/tests/integration/add_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use std::thread;
use eyre::Result;
use iroha_client::client;
use iroha_data_model::prelude::*;
use test_network::{generate_offset, *};
use test_network::*;
use unique_port::generate_unique_start_port;

#[test]
fn client_add_account_with_name_length_more_than_limit_should_not_commit_transaction() -> Result<()>
{
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
let (_rt, _peer, test_client) = <PeerBuilder>::new().start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);

Expand Down
11 changes: 6 additions & 5 deletions client/tests/integration/add_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ use std::{str::FromStr as _, thread};
use eyre::Result;
use iroha_client::client;
use iroha_data_model::{fixed::Fixed, prelude::*};
use test_network::{generate_offset, *};
use test_network::*;
use unique_port::generate_unique_start_port;

use super::Configuration;

#[test]
fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount() -> Result<()> {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
let (_rt, _peer, mut test_client) = <PeerBuilder>::new().start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);

Expand Down Expand Up @@ -43,7 +44,7 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount() ->

#[test]
fn client_add_big_asset_quantity_to_existing_asset_should_increase_asset_amount() -> Result<()> {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
let (_rt, _peer, mut test_client) = <PeerBuilder>::new().start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);

Expand Down Expand Up @@ -75,7 +76,7 @@ fn client_add_big_asset_quantity_to_existing_asset_should_increase_asset_amount(

#[test]
fn client_add_asset_with_decimal_should_increase_asset_amount() -> Result<()> {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
let (_rt, _peer, mut test_client) = <PeerBuilder>::new().start_with_runtime();

// Given
Expand Down Expand Up @@ -128,7 +129,7 @@ fn client_add_asset_with_decimal_should_increase_asset_amount() -> Result<()> {

#[test]
fn client_add_asset_with_name_length_more_than_limit_should_not_commit_transaction() -> Result<()> {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
let (_rt, _peer, test_client) = <PeerBuilder>::new().start_with_runtime();
let pipeline_time = Configuration::pipeline_time();

Expand Down
5 changes: 3 additions & 2 deletions client/tests/integration/add_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use std::thread;
use eyre::Result;
use iroha_client::client;
use iroha_data_model::prelude::*;
use test_network::{generate_offset, *};
use test_network::*;
use unique_port::generate_unique_start_port;

use super::Configuration;

#[test]
fn client_add_domain_with_name_length_more_than_limit_should_not_commit_transaction() -> Result<()>
{
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
let (_rt, _peer, test_client) = <PeerBuilder>::new().start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);
let pipeline_time = Configuration::pipeline_time();
Expand Down
5 changes: 3 additions & 2 deletions client/tests/integration/asset_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ use eyre::Result;
use iroha_client::client;
use iroha_core::prelude::*;
use iroha_data_model::prelude::*;
use test_network::{generate_offset, *};
use test_network::*;
use unique_port::generate_unique_start_port;

use super::Configuration;

#[test]
fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount_on_another_peer(
) -> Result<()> {
unique_port::set_offset(generate_offset!()).unwrap();
unique_port::set_port_index(generate_unique_start_port!());
// Given
let (_rt, network, iroha_client) = <Network>::start_test_with_runtime(4, 1);
wait_for_genesis_committed(&network.clients(), 0);
Expand Down
Loading

0 comments on commit 891e532

Please sign in to comment.