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 SamHSmith committed Apr 8, 2024
1 parent dfbf752 commit 49b209a
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 166 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()
49 changes: 49 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import allure
import iroha
import pytest

from tests import client, fake
from tests.helpers import generate_public_key


@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_new_asset_id():
"""Fixture to provide a new asset id."""
asset_name = str(len(client.query_all_assets())) + fake.word()[:3].upper()
with allure.step(f'GIVEN a "{asset_name}" asset'):
return asset_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

@pytest.fixture()
def GIVEN_registered_domain_with_registered_accounts(GIVEN_registered_domain, GIVEN_new_account_id):
"""Fixture to provide domain with accounts"""
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")])]))
return GIVEN_registered_domain
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
Empty file added tests/query/__init__.py
Empty file.
32 changes: 32 additions & 0 deletions tests/query/test_query_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import allure
import time
import pytest

from tests import client

@pytest.fixture(scope="function", autouse=True)
def story_account_register_account():
allure.dynamic.story("Account queries accounts")
allure.dynamic.label("permission", "no_permission_required")

@allure.label("sdk_test_id", "query_all_accounts")
def test_query_all_accounts():
with allure.step('WHEN client queries all accounts'):
all_accounts = client.query_all_accounts()
with allure.step('THEN there should be some accounts present'):
assert len(all_accounts) > 0, "No accounts found in the system"


@allure.label("sdk_test_id", "query_all_accounts_in_domain")
def test_query_all_accounts_in_domain(
GIVEN_registered_domain_with_registered_accounts):
with allure.step(
f'WHEN client queries all accounts in domain "{GIVEN_registered_domain_with_registered_accounts}"'):
time.sleep(3)
accounts_in_domain = client.query_all_accounts_in_domain(GIVEN_registered_domain_with_registered_accounts)
with allure.step(
f'THEN the response should be a non-empty list of accounts in domain "{GIVEN_registered_domain_with_registered_accounts}"'):
assert isinstance(accounts_in_domain, list) and accounts_in_domain, \
f"Expected a non-empty list of accounts in the domain {GIVEN_registered_domain_with_registered_accounts}, got {accounts_in_domain}"


25 changes: 25 additions & 0 deletions tests/query/test_query_asset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import allure
import time
import pytest

from tests import client

@pytest.fixture(scope="function", autouse=True)
def story_account_register_account():
allure.dynamic.story("Account queries assets")
allure.dynamic.label("permission", "no_permission_required")

@pytest.mark.xfail(reason="TO DO")
@allure.label("sdk_test_id", "query_all_assets_owned_by_account")
def test_query_all_assets_owned_by_account(
GIVEN_registered_account_with_assets):
with allure.step(
f'WHEN client queries all assets owned by account "{GIVEN_registered_account_with_assets}"'):
time.sleep(3)
assets_owned_by_account = client.query_all_assets_owned_by_account(GIVEN_registered_account_with_assets)
with allure.step(
f'THEN the response should be a non-empty list of assets owned by account "{GIVEN_registered_account_with_assets}"'):
assert isinstance(assets_owned_by_account, list) and assets_owned_by_account, \
f"Expected a non-empty list of assets owned by account {GIVEN_registered_account_with_assets}, got {assets_owned_by_account}"


105 changes: 22 additions & 83 deletions tests/test_account.py
Original file line number Diff line number Diff line change
@@ -1,88 +1,27 @@
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
from tests.helpers import generate_public_key

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])
@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")

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

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

@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()
41 changes: 10 additions & 31 deletions tests/test_asset.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
import allure
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
import pytest

from tests import client

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

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

print("Listing all assets owned by alice@wonderland...")
for a in assets:
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")
Expand Down
Loading

0 comments on commit 49b209a

Please sign in to comment.