Skip to content

Commit

Permalink
[fix] hyperledger-iroha#2137: Fix the rest of the tests (cli, client,…
Browse files Browse the repository at this point in the history
… data_model)

Signed-off-by: Ales Tsurko <[email protected]>
  • Loading branch information
ales-tsurko committed Jun 15, 2022
1 parent dfdbb33 commit dd9aac6
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
24 changes: 24 additions & 0 deletions cli/src/torii/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -83,6 +84,7 @@ async fn create_torii() -> (Torii<World>, 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;
Expand All @@ -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| {
Expand Down Expand Up @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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"))
Expand Down Expand Up @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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())),
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion client/tests/integration/offline_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
7 changes: 6 additions & 1 deletion client/tests/integration/queries/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use eyre::Result;
use iroha_client::client;
use iroha_core::smartcontracts::isi::query::Error as QueryError;
use iroha_data_model::prelude::*;
use test_network::*;
use test_network::{generate_offset, *};

fn create_role_ids() -> [<Role as Identifiable>::Id; 5] {
[
Expand All @@ -20,6 +20,7 @@ fn create_role_ids() -> [<Role as Identifiable>::Id; 5] {

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

Expand Down Expand Up @@ -49,6 +50,7 @@ fn find_roles() -> Result<()> {

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

Expand All @@ -75,6 +77,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) = <PeerBuilder>::new().start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);

Expand All @@ -94,6 +97,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) = <PeerBuilder>::new().start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);

Expand All @@ -111,6 +115,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) = <PeerBuilder>::new().start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);

Expand Down
3 changes: 2 additions & 1 deletion data_model/tests/data_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"#,
Expand Down

0 comments on commit dd9aac6

Please sign in to comment.