Skip to content

Commit 944dc9f

Browse files
authored
test: add integration tests (#87)
* feat: add integartion tests Signed-off-by: dosi <[email protected]> * test: move unit tests to separate folder Signed-off-by: dosi <[email protected]> * test: add pytest.ini with markers for unit and integration tests Signed-off-by: dosi <[email protected]> * ci: update GitHub Actions workflow and pyproject.toml for testing and configuration Signed-off-by: dosi <[email protected]> * test: remove transaction.sign() where the call is unnecessary Signed-off-by: dosi <[email protected]> * test: remove except Exception lines in integration tests Signed-off-by: dosi <[email protected]> * test: remove token deletion and dissociation where unnecessary Signed-off-by: dosi <[email protected]> --------- Signed-off-by: dosi <[email protected]>
1 parent 5ec10f6 commit 944dc9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+869
-20
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ jobs:
4343
- name: Install your package
4444
run: pip install -e .
4545

46-
- name: Run tests
46+
- name: Run integration tests
4747
env:
4848
OPERATOR_ID: ${{ steps.solo.outputs.accountId }}
4949
OPERATOR_KEY: ${{ steps.solo.outputs.privateKey }}
5050
ADMIN_KEY: ${{ steps.solo.outputs.privateKey }}
5151
PUBLIC_KEY: ${{ steps.solo.outputs.publicKey }}
5252
NETWORK: solo
5353
run: |
54-
python test.py; uv run pytest
54+
uv run pytest -m integration
55+
56+
- name: Run unit tests
57+
run: |
58+
uv run pytest -m unit

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ package-dir = "src"
5353
excludes = ["**/.pytest_cache"]
5454

5555
[tool.pytest.ini_options]
56-
pythonpath = ["src"]
56+
pythonpath = ["src", "."]
57+
testpaths = ["tests"]
5758

5859
[tool.ruff]
5960
line-length = 120

pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[pytest]
2+
markers =
3+
integration: mark a test as an integration test.
4+
unit: mark a test as a unit test.

tests/integration/__init__.py

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pytest
2+
3+
from hiero_sdk_python.query.account_balance_query import CryptoGetAccountBalanceQuery
4+
from tests.integration.utils_for_test import IntegrationTestEnv
5+
6+
7+
@pytest.mark.integration
8+
def test_integration_account_balance_query_can_execute():
9+
env = IntegrationTestEnv()
10+
11+
try:
12+
CryptoGetAccountBalanceQuery(account_id=env.operator_id).execute(env.client)
13+
finally:
14+
env.close()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pytest
2+
from hiero_sdk_python import AccountCreateTransaction
3+
from hiero_sdk_python.crypto.private_key import PrivateKey
4+
from hiero_sdk_python.hbar import Hbar
5+
from tests.integration.utils_for_test import IntegrationTestEnv
6+
7+
8+
@pytest.mark.integration
9+
def test_integration_account_create_transaction_can_execute():
10+
env = IntegrationTestEnv()
11+
12+
try:
13+
new_account_private_key = PrivateKey.generate()
14+
new_account_public_key = new_account_private_key.public_key()
15+
initial_balance = Hbar(2)
16+
17+
assert initial_balance.to_tinybars() == 200000000
18+
19+
transaction = AccountCreateTransaction(
20+
key=new_account_public_key,
21+
initial_balance=initial_balance,
22+
memo="Recipient Account"
23+
)
24+
25+
transaction.freeze_with(env.client)
26+
receipt = transaction.execute(env.client)
27+
28+
assert receipt.accountId is not None, "AccountID not found in receipt. Account may not have been created."
29+
finally:
30+
env.close()
31+
32+
33+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import pytest
2+
3+
from hiero_sdk_python.crypto.private_key import PrivateKey
4+
from hiero_sdk_python.hbar import Hbar
5+
from hiero_sdk_python.tokens.token_associate_transaction import TokenAssociateTransaction
6+
from hiero_sdk_python.tokens.token_dissociate_transaction import TokenDissociateTransaction
7+
from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction
8+
from hiero_sdk_python.response_code import ResponseCode
9+
from tests.integration.utils_for_test import IntegrationTestEnv, create_fungible_token
10+
11+
12+
@pytest.mark.integration
13+
def test_integration_token_associate_transaction_can_execute():
14+
env = IntegrationTestEnv()
15+
16+
try:
17+
new_account_private_key = PrivateKey.generate()
18+
new_account_public_key = new_account_private_key.public_key()
19+
20+
initial_balance = Hbar(2)
21+
assert initial_balance.to_tinybars() == 200000000
22+
23+
account_transaction = AccountCreateTransaction(
24+
key=new_account_public_key,
25+
initial_balance=initial_balance,
26+
memo="Recipient Account"
27+
)
28+
29+
account_transaction.freeze_with(env.client)
30+
account_receipt = account_transaction.execute(env.client)
31+
new_account_id = account_receipt.accountId
32+
33+
token_id = create_fungible_token(env)
34+
assert token_id is not None, "TokenID not found in receipt. Token may not have been created."
35+
36+
associate_transaction = TokenAssociateTransaction(
37+
account_id=new_account_id,
38+
token_ids=[token_id]
39+
)
40+
41+
associate_transaction.freeze_with(env.client)
42+
associate_transaction.sign(new_account_private_key)
43+
associate_receipt = associate_transaction.execute(env.client)
44+
45+
assert associate_receipt.status == ResponseCode.SUCCESS, f"Token association failed with status: {ResponseCode.get_name(associate_receipt.status)}"
46+
47+
dissociate_transaction = TokenDissociateTransaction(
48+
account_id=new_account_id,
49+
token_ids=[token_id]
50+
)
51+
52+
dissociate_transaction.freeze_with(env.client)
53+
dissociate_transaction.sign(new_account_private_key)
54+
dissociate_receipt = dissociate_transaction.execute(env.client)
55+
56+
assert dissociate_receipt.status == ResponseCode.SUCCESS, f"Token dissociation failed with status: {ResponseCode.get_name(dissociate_receipt.status)}"
57+
finally:
58+
env.close()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import pytest
2+
3+
from tests.integration.utils_for_test import IntegrationTestEnv, create_fungible_token, create_nft_token
4+
5+
6+
@pytest.mark.integration
7+
def test_integration_fungible_token_create_transaction_can_execute():
8+
env = IntegrationTestEnv()
9+
10+
try:
11+
token_id = create_fungible_token(env)
12+
13+
assert token_id is not None, "TokenID not found in receipt. Token may not have been created."
14+
finally:
15+
env.close()
16+
17+
18+
@pytest.mark.integration
19+
def test_integration_nft_token_create_transaction_can_execute():
20+
env = IntegrationTestEnv()
21+
22+
try:
23+
token_id = create_nft_token(env)
24+
25+
assert token_id is not None, "TokenID not found in receipt. Token may not have been created."
26+
finally:
27+
env.close()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
3+
from tests.integration.utils_for_test import IntegrationTestEnv, create_fungible_token
4+
from hiero_sdk_python.tokens.token_delete_transaction import TokenDeleteTransaction
5+
from hiero_sdk_python.response_code import ResponseCode
6+
7+
@pytest.mark.integration
8+
def test_integration_token_delete_transaction_can_execute():
9+
env = IntegrationTestEnv()
10+
11+
try:
12+
token_id = create_fungible_token(env)
13+
14+
assert token_id is not None, "TokenID not found in receipt. Token may not have been created."
15+
16+
transaction = TokenDeleteTransaction(token_id=token_id)
17+
transaction.freeze_with(env.client)
18+
receipt = transaction.execute(env.client)
19+
20+
assert receipt.status == ResponseCode.SUCCESS, f"Token deletion failed with status: {ResponseCode.get_name(receipt.status)}"
21+
finally:
22+
env.close()
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import pytest
2+
3+
from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction
4+
from hiero_sdk_python.crypto.private_key import PrivateKey
5+
from hiero_sdk_python.hbar import Hbar
6+
from hiero_sdk_python.tokens.token_associate_transaction import TokenAssociateTransaction
7+
from hiero_sdk_python.tokens.token_dissociate_transaction import TokenDissociateTransaction
8+
from hiero_sdk_python.response_code import ResponseCode
9+
from tests.integration.utils_for_test import IntegrationTestEnv, create_fungible_token
10+
11+
12+
@pytest.mark.integration
13+
def test_integration_token_dissociate_transaction_can_execute():
14+
env = IntegrationTestEnv()
15+
16+
try:
17+
new_account_private_key = PrivateKey.generate()
18+
new_account_public_key = new_account_private_key.public_key()
19+
20+
initial_balance = Hbar(2)
21+
22+
assert initial_balance.to_tinybars() == 200000000
23+
24+
account_transaction = AccountCreateTransaction(
25+
key=new_account_public_key,
26+
initial_balance=initial_balance,
27+
memo="Recipient Account"
28+
)
29+
30+
account_transaction.freeze_with(env.client)
31+
account_receipt = account_transaction.execute(env.client)
32+
new_account_id = account_receipt.accountId
33+
34+
token_id = create_fungible_token(env)
35+
36+
associate_transaction = TokenAssociateTransaction(
37+
account_id=new_account_id,
38+
token_ids=[token_id]
39+
)
40+
associate_transaction.freeze_with(env.client)
41+
associate_transaction.sign(new_account_private_key)
42+
43+
receipt = associate_transaction.execute(env.client)
44+
45+
assert receipt.status == ResponseCode.SUCCESS, f"Token association failed with status: {ResponseCode.get_name(receipt.status)}"
46+
47+
dissociate_transaction = TokenDissociateTransaction(
48+
account_id=new_account_id,
49+
token_ids=[token_id]
50+
)
51+
dissociate_transaction.freeze_with(env.client)
52+
dissociate_transaction.sign(new_account_private_key)
53+
54+
receipt = dissociate_transaction.execute(env.client)
55+
56+
assert receipt.status == ResponseCode.SUCCESS, f"Token dissociation failed with status: {ResponseCode.get_name(receipt.status)}"
57+
finally:
58+
env.close()

0 commit comments

Comments
 (0)