Skip to content

Commit

Permalink
[refactor] add test framework
Browse files Browse the repository at this point in the history
Signed-off-by: alexstroke <111361420+astrokov7@users.noreply.github.com>
  • Loading branch information
Aleksandr Strokov authored and AlexStroke committed Apr 3, 2024
1 parent ac3d273 commit 495d3f4
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 154 deletions.
3 changes: 2 additions & 1 deletion how_to_test
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
python -m pytest tests
maturin build
poetry run python -m pytest tests
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ dependencies = ["fixedint==0.2.0"]

[tool.maturin]
features = ["pyo3/extension-module"]

[tool.poetry]
name = "iroha-python"
version = "0.1.0"
description = ""
authors = ["Aleksandr Strokov <busyfifer@gmail.com>"]

[tool.poetry.dependencies]
python = "^3.9.6"
allure-python-commons = "*"
pytest = "^8.1.1"
faker = "^24.4.0"
#iroha = {path = "target/wheels/iroha-0.1.0-cp39-cp39-macosx_11_0_arm64.whl"}
27 changes: 27 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import iroha
from faker import Faker

key_pair = iroha.KeyPair.from_json("""
{
"public_key": "ed01207233BFC89DCBD68C19FDE6CE6158225298EC1131B6A130D1AEB454C1AB5183C0",
"private_key": {
"digest_function": "ed25519",
"payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0"
}
}
""")

account_id = "alice@wonderland"
web_login = "mad_hatter"
password = "ilovetea"
api_url = "http://127.0.0.1:8080/"
telemetry_url = "http://127.0.0.1:8180/"

client = iroha.Client.create(
key_pair,
account_id,
web_login,
password,
api_url)

fake = Faker()
29 changes: 29 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import allure
import iroha
import pytest

from tests import client, fake


@pytest.fixture()
def GIVEN_new_domain_id():
"""Fixture to provide a new fake domain id."""
name = str(len(client.query_all_domains()))+fake.word()
with allure.step(f'GIVEN a "{name}" name'):
return name

@pytest.fixture()
def GIVEN_new_account_id(GIVEN_registered_domain):
"""Fixture to provide a new fake account id."""
name = str(len(client.query_all_accounts())) + fake.word() + '@' + GIVEN_registered_domain
with allure.step(f'GIVEN a "{name}" name'):
return name

@pytest.fixture()
def GIVEN_registered_domain(GIVEN_new_domain_id):
"""Fixture to provide registered domain in Iroha"""
with allure.step(f'GIVEN registered domain name "{GIVEN_new_domain_id}"'):
(client.submit_executable(
[iroha.Instruction
.register_domain(GIVEN_new_domain_id)]))
return GIVEN_new_domain_id
8 changes: 8 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import iroha

def generate_public_key(seed="abcd1122"):

"""
Generate a public key using Ed25519PrivateKey.
"""
return iroha.KeyGenConfiguration.default().use_seed_hex(seed).generate().public_key
98 changes: 34 additions & 64 deletions tests/test_account.py
Original file line number Diff line number Diff line change
@@ -1,88 +1,58 @@
import allure
import iroha
import time
import pytest

def start_client():
key_pair = iroha.KeyPair.from_json("""
{
"public_key": "ed01207233BFC89DCBD68C19FDE6CE6158225298EC1131B6A130D1AEB454C1AB5183C0",
"private_key": {
"digest_function": "ed25519",
"payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0"
}
}
""")

account_id = "alice@wonderland"
web_login = "mad_hatter"
password = "ilovetea"
api_url = "http://127.0.0.1:8080/"
telemetry_url = "http://127.0.0.1:8180/"

client = iroha.Client.create(
key_pair,
account_id,
web_login,
password,
api_url)
return client

def test_register_account():
client = start_client()

new_account_key_pair = iroha.KeyGenConfiguration.default().use_seed_hex("abcd1122").generate()

accounts = client.query_all_accounts_in_domain("wonderland")

print("Listing all accounts in wonderland...")
for a in accounts:
print(" - ", a,)

new_account_id = "white_rabbit_" + str(len(accounts)) + "@wonderland"

assert new_account_id not in accounts

register = iroha.Instruction.register_account(new_account_id, [new_account_key_pair.public_key])

client.submit_executable([register])
from tests import client
from tests.helpers import generate_public_key

for x in range(30):
accounts = client.query_all_accounts_in_domain("wonderland")

if new_account_id in accounts:
break

time.sleep(1)


assert new_account_id in accounts
@pytest.fixture(scope="function", autouse=True)
def story_account_register_account():
allure.dynamic.story("Account registers an account")
allure.dynamic.label("permission", "no_permission_required")

@allure.label("sdk_test_id", "register_account")
def test_register_account(
GIVEN_new_account_id):
with allure.step(
f'WHEN client registers the account "{GIVEN_new_account_id}"'):
(client.submit_executable(
[iroha.Instruction
.register_account(
GIVEN_new_account_id,
[generate_public_key(seed="abcd1122")])]))
time.sleep(3)
with allure.step(
f'THEN Iroha should have the "{GIVEN_new_account_id}" account'):
assert GIVEN_new_account_id in client.query_all_accounts()

def test_register_account_but_use_query_all():
client = start_client()

new_account_key_pair = iroha.KeyGenConfiguration.default().use_seed_hex("abcd1144").generate()

accounts = client.query_all_accounts()

print("Listing all accounts...")
for a in accounts:
print(" - ", a,)

new_account_id = "white_rabbit_query_all_test_" + str(len(accounts)) + "@wonderland"

assert new_account_id not in accounts

register = iroha.Instruction.register_account(new_account_id, [new_account_key_pair.public_key])

client.submit_executable([register])

for x in range(30):
accounts = client.query_all_accounts()

if new_account_id in accounts:
break

time.sleep(1)


assert new_account_id in accounts

49 changes: 11 additions & 38 deletions tests/test_asset.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,32 @@
import iroha
import time

def start_client():
key_pair = iroha.KeyPair.from_json("""
{
"public_key": "ed01207233BFC89DCBD68C19FDE6CE6158225298EC1131B6A130D1AEB454C1AB5183C0",
"private_key": {
"digest_function": "ed25519",
"payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0"
}
}
""")

account_id = "alice@wonderland"
web_login = "mad_hatter"
password = "ilovetea"
api_url = "http://127.0.0.1:8080/"
telemetry_url = "http://127.0.0.1:8180/"

client = iroha.Client.create(
key_pair,
account_id,
web_login,
password,
api_url)
return client

def test_register_account():
client = start_client()
from tests import client


def test_register_asset():
assets = client.query_all_assets_owned_by_account("alice@wonderland")

print("Listing all assets owned by alice@wonderland...")
for a in assets:
print(" - ", a,)
print(" - ", a, )

asset_definition_id = "time_" + str(len(assets)) + "#wonderland"
asset_id = "time_" + str(len(assets)) + "##alice@wonderland"

assert asset_id not in assets

register_definition = iroha.Instruction.register_asset_definition(asset_definition_id, "Quantity")

mint = iroha.Instruction.mint_asset(5, asset_id, "Quantity")

client.submit_executable([register_definition, mint])

for x in range(30):
assets = client.query_all_assets_owned_by_account("alice@wonderland")

if asset_id in assets:
break

time.sleep(1)



assert asset_id in assets

68 changes: 17 additions & 51 deletions tests/test_domain.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,22 @@
import allure
import iroha
import time
import pytest

def start_client():
key_pair = iroha.KeyPair.from_json("""
{
"public_key": "ed01207233BFC89DCBD68C19FDE6CE6158225298EC1131B6A130D1AEB454C1AB5183C0",
"private_key": {
"digest_function": "ed25519",
"payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0"
}
}
""")

account_id = "alice@wonderland"
web_login = "mad_hatter"
password = "ilovetea"
api_url = "http://127.0.0.1:8080/"
telemetry_url = "http://127.0.0.1:8180/"

client = iroha.Client.create(
key_pair,
account_id,
web_login,
password,
api_url)
return client
from tests import client

def test_register_account():
client = start_client()
@pytest.fixture(scope="function", autouse=True)
def story_account_registers_domain():
allure.dynamic.story("Account registers a domain")
allure.dynamic.label("permission", "no_permission_required")

domains = client.query_all_domains()

print("Listing all domains...")
for d in domains:
print(" - ", d,)

domain_id = "looking_glass_" + str(len(domains))

if domain_id in domains:
print("'" + domain_id +"' domain already exists.")

register = iroha.Instruction.register_domain(domain_id)

client.submit_executable([register])

for x in range(30):
domains = client.query_all_domains()

if domain_id in domains:
break

time.sleep(1)

assert domain_id in domains

@allure.label("sdk_test_id", "register_domain")
def test_register_domain(
GIVEN_new_domain_id):
with allure.step(f'WHEN client registers the domain name "{GIVEN_new_domain_id}"'):
(client.submit_executable(
[iroha.Instruction
.register_domain(GIVEN_new_domain_id)]))
time.sleep(2)
with allure.step(f'THEN Iroha should have the domain name "{GIVEN_new_domain_id}"'):
assert GIVEN_new_domain_id in client.query_all_domains()

0 comments on commit 495d3f4

Please sign in to comment.