Skip to content

Commit

Permalink
[refactor] migrate integration Rust tests to client cli pytests
Browse files Browse the repository at this point in the history
Signed-off-by: alexstroke <[email protected]>
  • Loading branch information
AlexStroke committed Feb 12, 2024
1 parent 2ad5f61 commit 60c9e77
Show file tree
Hide file tree
Showing 55 changed files with 761 additions and 299 deletions.
12 changes: 12 additions & 0 deletions client/tests/integration/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ use iroha_primitives::fixed::Fixed;
use serde_json::json;
use test_network::*;

#[deprecated(
since = "2.0.0-pre-rc.20",
note = "This test is deprecated and refers to test_register_asset_definitions.py"
)]
#[test]
fn client_register_asset_should_add_asset_once_but_not_twice() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(10_620).start_with_runtime();
Expand Down Expand Up @@ -89,6 +93,10 @@ fn unregister_asset_should_remove_asset_from_account() -> Result<()> {
}

#[test]
#[deprecated(
since = "2.0.0-pre-rc.20",
note = "This test is deprecated and refers to test_mint_assets.py"
)]
fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(10_000).start_with_runtime();
wait_for_genesis_committed(&[test_client.clone()], 0);
Expand Down Expand Up @@ -202,6 +210,10 @@ fn client_add_asset_with_decimal_should_increase_asset_amount() -> Result<()> {
}

#[test]
#[deprecated(
since = "2.0.0-pre-rc.20",
note = "This test is deprecated and refers to test_register_asset_definitions.py"
)]
fn client_add_asset_with_name_length_more_than_limit_should_not_commit_transaction() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(10_520).start_with_runtime();
wait_for_genesis_committed(&[test_client.clone()], 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use iroha_client::{client, data_model::prelude::*};
use iroha_config::iroha::Configuration;
use test_network::*;

#[deprecated(
since = "2.0.0-pre-rc.20",
note = "This test suite is deprecated and refers to test_register_accounts.py"
)]
#[test]
fn client_add_account_with_name_length_more_than_limit_should_not_commit_transaction() -> Result<()>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use iroha_client::{client, data_model::prelude::*};
use iroha_config::iroha::Configuration;
use test_network::*;

#[deprecated(
since = "2.0.0-pre-rc.20",
note = "This test suite is deprecated and refers totest_register_domains.py"
)]
#[test]
fn client_add_domain_with_name_length_more_than_limit_should_not_commit_transaction() -> Result<()>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ use iroha_client::{
use iroha_config::iroha::Configuration;
use test_network::*;

#[deprecated(
since = "2.0.0-pre-rc.20",
note = "This test is deprecated and refers to test_mint_asset.py"
)]
#[test]
fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount_on_another_peer(
) -> Result<()> {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use iroha_client::data_model::Level;
use test_network::*;

#[deprecated(
since = "2.0.0-pre-rc.20",
note = "This test is meaningless since it doesn't test anything useful"
)]
#[ignore = "ignore, more in #4094"]
#[test]
fn config_endpoints() {
const NEW_LOG_LEVEL: Level = Level::ERROR;
Expand Down
7 changes: 7 additions & 0 deletions client/tests/integration/extra_functional/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod connected_peers;
mod deprecated_config;
mod multiple_blocks_created;
mod offline_peers;
mod restart_peer;
mod unregister_peer;
mod unstable_network;
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 5 additions & 12 deletions client/tests/integration/mod.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
mod add_account;
mod add_domain;
mod asset;
mod asset_propagation;
mod burn_public_keys;
mod config;
mod connected_peers;
mod domain_owner;
mod deprecated_add_account;
mod deprecated_add_domain;
mod deprecated_asset_propagation;
mod domain_owner_permissions;
mod events;
mod multiple_blocks_created;
mod extra_functional;
mod multisignature_account;
mod multisignature_transaction;
mod non_mintable;
mod offline_peers;
mod pagination;
mod permissions;
mod queries;
mod query_errors;
mod restart_peer;
mod roles;
mod set_parameter;
mod sorting;
mod transfer_asset;
mod triggers;
mod tx_history;
mod tx_rollback;
mod unregister_peer;
mod unstable_network;
mod upgrade;
1 change: 1 addition & 0 deletions client/tests/integration/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use test_network::*;

mod account;
mod asset;
mod query_errors;
mod role;

#[test]
Expand Down
File renamed without changes.
10 changes: 9 additions & 1 deletion client/tests/integration/transfer_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use iroha_client::{
use iroha_primitives::fixed::Fixed;
use test_network::*;

#[deprecated(
since = "2.0.0-pre-rc.20",
note = "This test suite is deprecated and refers to test_tranfer_assets.py"
)]
#[test]
fn simulate_transfer_quantity() {
simulate_transfer(
Expand Down Expand Up @@ -42,8 +46,12 @@ fn simulate_transfer_fixed() {
)
}

#[deprecated(
since = "2.0.0-pre-rc.20",
note = "This test suite is deprecated, use test_tranfer_assets.py instead"
)]
#[ignore = "migrated to client cli python tests"]
#[test]
#[ignore = "long"]
#[should_panic(expected = "insufficient funds")]
fn simulate_insufficient_funds() {
simulate_transfer(
Expand Down
5 changes: 3 additions & 2 deletions client_cli/pytests/common/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class Stderr(Enum):
INVALID_VALUE_TYPE = 'Matching variant not found'
RESERVED_CHARACTER = 'The `@` character is reserved for `account@domain` constructs,' \
' `#` — for `asset#domain` and `$` — for `trigger$domain`.'
WHITESPACES = "White space not allowed"
WHITESPACES = 'White space not allowed'
INSUFFICIENT_FUNDS = 'Not enough quantity to transfer/burn'


class ReservedChars(Enum):
Expand All @@ -40,6 +41,6 @@ class ValueTypes(Enum):
"""
QUANTITY = 'Quantity' # unsigned 32-bit integer
STORE = 'Store' #storing key-values in object's metadata
# BIG_QUANTITY = 'BigQuantity' unsigned 128-bit integer
BIG_QUANTITY = 'BigQuantity' #unsigned 128-bit integer
# FIXED = 'Fixed' 64-bit fixed-precision number with
# nine significant digits after the decimal point
54 changes: 53 additions & 1 deletion client_cli/pytests/common/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,65 @@
"""

import binascii
import json
import os
import random
import re
import string

from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey

from common.consts import ReservedChars, fake


def extract_hash(stdout):
"""
Extracts a SHA-256 hash from the given string.
:param stdout: The string from which to extract the hash.
:return: The extracted hash if found, otherwise None.
"""
if not isinstance(stdout, str) or not stdout.strip():
return None
pattern = r'"([A-Fa-f0-9]{64})"'
match = re.search(pattern, stdout)
return match.group(1) if match else None

def get_peers_config_files(path_to_configs):
"""
Returns a list of config file paths from the given directory.
"""
config_files = []
for entry in os.listdir(path_to_configs):
if entry.endswith('.json') and 'config_to_peer' in entry:
config_files.append(os.path.join(path_to_configs, entry))
return config_files

def read_isi_from_json(file_path):
"""
Reads ISI instruction from a JSON file.
:param file_path: Path to the JSON file containing ISI instruction.
:return: Dictionary with ISI instruction.
"""
with open(file_path, 'r', encoding='utf-8') as file:
isi_data = json.load(file)
return isi_data


def write_isi_to_json(isi_data, file_path):
"""
Writes ISI instruction to a JSON file.
:param isi_data: Dictionary with ISI instruction.
:param file_path: Path to save the JSON file.
"""
if not isinstance(isi_data, list):
isi_data = [isi_data]
with open(file_path, 'w', encoding='utf-8') as file:
json.dump(isi_data, file, indent=4)

def generate_random_string_with_reserved_char():
"""
Generate a random string with a reserved character.
Expand Down Expand Up @@ -55,7 +106,8 @@ def generate_random_string_without_reserved_chars(length):
"""
Generate a random string with the specified length, excluding reserved characters.
"""
allowed_chars = [c for c in [*string.ascii_letters, *string.digits] if c not in ReservedChars.ALL.value]
allowed_chars = \
[c for c in [*string.ascii_letters, *string.digits] if c not in ReservedChars.ALL.value]
return generate_random_string(length, allowed_chars)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[{
"Unregister": {
"Asset": {
"object_id": "rose#alice@wonderland"
}
}
}]
2 changes: 2 additions & 0 deletions client_cli/pytests/common/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import os

from dotenv import load_dotenv

load_dotenv()
Expand All @@ -17,6 +18,7 @@

PATH_CONFIG_CLIENT_CLI = os.path.join(ROOT_DIR, "config.json")
CLIENT_CLI_PATH = os.path.join(ROOT_DIR, "iroha_client_cli")
PEERS_CONFIGS_PATH = os.path.join(ROOT_DIR, "peers_configs")

PORT_MIN = int(os.getenv('TORII_API_PORT_MIN', '8080'))
PORT_MAX = int(os.getenv('TORII_API_PORT_MAX', '8083'))
3 changes: 2 additions & 1 deletion client_cli/pytests/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from dataclasses import dataclass


@dataclass
class Account:
"""
Expand All @@ -17,7 +18,7 @@ class Account:
"""
name: str
domain: str
public_key: str
public_key: str = None

def __repr__(self):
return f"{self.name}@{self.domain}"
4 changes: 4 additions & 0 deletions client_cli/pytests/models/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from dataclasses import dataclass


@dataclass
class AssetDefinition:
"""
Expand Down Expand Up @@ -39,10 +40,13 @@ class Asset:
:param definition: The asset definition of the asset.
:type definition: AssetDefinition
:param account: The account of the asset.
:type definition: str
:param value: The value of the asset.
:type value: str
"""
definition: AssetDefinition
account: str
value: str

def __repr__(self):
Expand Down
1 change: 1 addition & 0 deletions client_cli/pytests/models/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from dataclasses import dataclass


@dataclass
class Domain:
"""
Expand Down
2 changes: 1 addition & 1 deletion client_cli/pytests/src/client_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This module initializes the Iroha client and configuration using environment variables.
"""

from common.settings import PATH_CONFIG_CLIENT_CLI, PORT_MIN, PORT_MAX
from common.settings import PATH_CONFIG_CLIENT_CLI, PORT_MAX, PORT_MIN
from src.client_cli.client_cli import ClientCli
from src.client_cli.configuration import Config
from src.client_cli.iroha import Iroha
Expand Down
Loading

0 comments on commit 60c9e77

Please sign in to comment.