diff --git a/how_to_test b/how_to_test index 4a338aa9..d764237e 100644 --- a/how_to_test +++ b/how_to_test @@ -1 +1,2 @@ -python -m pytest tests +maturin build +poetry run python -m pytest tests \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index b0a0bc2f..e6ef2447 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] + +[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"} diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..10d30e22 --- /dev/null +++ b/tests/__init__.py @@ -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() \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..f36bd71c --- /dev/null +++ b/tests/conftest.py @@ -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 \ No newline at end of file diff --git a/tests/helpers.py b/tests/helpers.py new file mode 100644 index 00000000..fbf3a816 --- /dev/null +++ b/tests/helpers.py @@ -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 \ No newline at end of file diff --git a/tests/test_account.py b/tests/test_account.py index 69a55c19..914e2691 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -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 \ No newline at end of file diff --git a/tests/test_asset.py b/tests/test_asset.py index 30e3241e..3b3e1450 100644 --- a/tests/test_asset.py +++ b/tests/test_asset.py @@ -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 - \ No newline at end of file diff --git a/tests/test_domain.py b/tests/test_domain.py index e180026c..a9c6df8a 100644 --- a/tests/test_domain.py +++ b/tests/test_domain.py @@ -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 - \ No newline at end of file +@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()