Skip to content

Commit

Permalink
[fix] #162: Add pytest
Browse files Browse the repository at this point in the history
Signed-off-by: Sam H. Smith <sam.henning.smith@protonmail.com>
  • Loading branch information
SamHSmith committed Apr 2, 2024
1 parent 858cff5 commit 28a88a7
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 0 deletions.
1 change: 1 addition & 0 deletions how_to_test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python -m pytest tests
58 changes: 58 additions & 0 deletions tests/test_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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()

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

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

59 changes: 59 additions & 0 deletions tests/test_asset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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()

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

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

56 changes: 56 additions & 0 deletions tests/test_domain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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()

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

0 comments on commit 28a88a7

Please sign in to comment.