Skip to content
Snippets Groups Projects
Commit 1d272f21 authored by Radosław Masłowski's avatar Radosław Masłowski
Browse files

Refactor existing tests

parent e8db8f4e
No related branches found
No related tags found
1 merge request!206Implement new wallet based on beekeeper
...@@ -4,16 +4,21 @@ import logging ...@@ -4,16 +4,21 @@ import logging
import pytest import pytest
import test_tools as tt import test_tools as tt
from loguru import logger
from test_tools.__private.scope.scope_fixtures import * # noqa: F403 from test_tools.__private.scope.scope_fixtures import * # noqa: F403
from schemas.policies.policy import set_policies from schemas.policies.policy import set_policies
from schemas.policies.testnet_assets import TestnetAssets from schemas.policies.testnet_assets import TestnetAssets
@pytest.fixture(autouse=True)
def _disable_logging() -> None:
logger.disable("helpy")
def pytest_sessionstart() -> None: def pytest_sessionstart() -> None:
# Turn off unnecessary logs # Turn off unnecessary logs
logging.getLogger("urllib3.connectionpool").propagate = False logging.getLogger("urllib3.connectionpool").propagate = False
tt.logger.enable("helpy")
tt.logger.enable("test_tools") tt.logger.enable("test_tools")
......
...@@ -49,7 +49,7 @@ def prepare_witness(node: AnyNode, account: tt.Account) -> int: ...@@ -49,7 +49,7 @@ def prepare_witness(node: AnyNode, account: tt.Account) -> int:
account.name, account.name,
"https://" + account.name, "https://" + account.name,
account.public_key, account.public_key,
{"account_creation_fee": Asset.Test(3), "maximum_block_size": 65536, "sbd_interest_rate": 0}, {"account_creation_fee": Asset.Test(3), "maximum_block_size": 65536, "hbd_interest_rate": 0},
) )
# Witness schedule list is updated on a block which is a multiple of 21. After fast confirmation feature # Witness schedule list is updated on a block which is a multiple of 21. After fast confirmation feature
......
...@@ -5,32 +5,58 @@ import test_tools as tt ...@@ -5,32 +5,58 @@ import test_tools as tt
@pytest.fixture() @pytest.fixture()
def wallet(request: pytest.FixtureRequest) -> tt.Wallet: def node(request: pytest.FixtureRequest) -> tt.InitNode:
init_node = tt.InitNode() init_node = tt.InitNode()
init_node.config.plugin.append("condenser_api")
shared_file_size = request.node.get_closest_marker("node_shared_file_size") shared_file_size = request.node.get_closest_marker("node_shared_file_size")
if shared_file_size: if shared_file_size:
init_node.config.shared_file_size = shared_file_size.args[0] init_node.config.shared_file_size = shared_file_size.args[0]
init_node.run() init_node.run()
return tt.Wallet(attach_to=init_node) return init_node
@pytest.fixture()
def wallet(node: tt.InitNode) -> tt.Wallet:
return tt.Wallet(attach_to=node)
def test_keys_import_during_account_creation(wallet: tt.Wallet) -> None: def test_keys_import_during_account_creation(wallet: tt.Wallet) -> None:
accounts = wallet.create_accounts(3) accounts = wallet.create_accounts(3)
imported_private_keys = {key_pair[1] for key_pair in wallet.api.list_keys()} imported_private_keys = wallet.api.list_keys()
assert all(account.private_key in imported_private_keys for account in accounts) assert all(account.public_key in imported_private_keys for account in accounts)
@pytest.mark.node_shared_file_size("16G") @pytest.mark.node_shared_file_size("16G")
def test_creation_of_huge_number_of_accounts(wallet: tt.Wallet) -> None: def test_creation_of_huge_number_of_accounts(node: tt.InitNode, wallet: tt.Wallet) -> None:
amount_of_accounts_to_create = 200_000 amount_of_accounts_to_create = 200_000
# This is required to make possible pushing 21 trxs per block after 21'th block
wallet.api.update_witness(
witness_name="initminer",
url="https://initminer.com",
block_signing_key=tt.Account("initminer").public_key,
props={
"account_creation_fee": tt.Asset.TestT(amount=1),
"maximum_block_size": 2097152,
"hbd_interest_rate": 0,
},
)
tt.logger.info("Wait 42 blocks for change of account_creation_fee")
node.wait_for_block_with_number(42)
before = node.api.condenser.get_account_count()
accounts_before = set(wallet.list_accounts()) accounts_before = set(wallet.list_accounts())
created_accounts = wallet.create_accounts(amount_of_accounts_to_create, import_keys=False) created_accounts = wallet.create_accounts(amount_of_accounts_to_create, import_keys=False)
node.wait_number_of_blocks(20)
after = node.api.condenser.get_account_count()
accounts_after = set(wallet.list_accounts()) accounts_after = set(wallet.list_accounts())
tt.logger.info(f"{before} -> {after}")
assert len(created_accounts) == amount_of_accounts_to_create assert len(created_accounts) == amount_of_accounts_to_create
assert len(accounts_after.difference(accounts_before)) == amount_of_accounts_to_create assert len(accounts_after.difference(accounts_before)) == amount_of_accounts_to_create
...@@ -10,12 +10,12 @@ from helpy import Hf26Asset as Asset ...@@ -10,12 +10,12 @@ from helpy import Hf26Asset as Asset
@pytest.mark.parametrize("transaction_serialization", ["legacy", "hf26"]) @pytest.mark.parametrize("transaction_serialization", ["legacy", "hf26"])
def test_transaction_serialization_getter(transaction_serialization: Literal["legacy", "hf26"]) -> None: def test_transaction_serialization_getter(transaction_serialization: Literal["legacy", "hf26"]) -> None:
wallet = tt.Wallet(additional_arguments=[f"--transaction-serialization={transaction_serialization}"]) wallet = tt.OldWallet(additional_arguments=[f"--transaction-serialization={transaction_serialization}"])
assert wallet.transaction_serialization == transaction_serialization assert wallet.transaction_serialization == transaction_serialization
def test_default_serialization(node: tt.InitNode) -> None: def test_default_serialization(node: tt.InitNode) -> None:
wallet = tt.Wallet(attach_to=node) wallet = tt.OldWallet(attach_to=node)
assert wallet.transaction_serialization == "legacy" assert wallet.transaction_serialization == "legacy"
......
...@@ -2,6 +2,7 @@ from __future__ import annotations ...@@ -2,6 +2,7 @@ from __future__ import annotations
import pytest import pytest
import test_tools as tt import test_tools as tt
from test_tools.__private.exceptions import BroadcastDuringTransactionBuildingError
from helpy import Hf26Asset as Asset from helpy import Hf26Asset as Asset
...@@ -13,9 +14,9 @@ def wallet(node: tt.InitNode) -> tt.Wallet: ...@@ -13,9 +14,9 @@ def wallet(node: tt.InitNode) -> tt.Wallet:
def test_sending_transaction_with_multiple_operations(wallet: tt.Wallet) -> None: def test_sending_transaction_with_multiple_operations(wallet: tt.Wallet) -> None:
accounts_and_balances = { accounts_and_balances = {
"first": Asset.Test(100).as_legacy(), "first": Asset.Test(100),
"second": Asset.Test(200).as_legacy(), "second": Asset.Test(200),
"third": Asset.Test(300).as_legacy(), "third": Asset.Test(300),
} }
with wallet.in_single_transaction(): with wallet.in_single_transaction():
...@@ -46,7 +47,7 @@ def test_setting_broadcast_when_building_transaction(wallet: tt.Wallet) -> None: ...@@ -46,7 +47,7 @@ def test_setting_broadcast_when_building_transaction(wallet: tt.Wallet) -> None:
This test checks if when user do this, appropriate error is generated. This test checks if when user do this, appropriate error is generated.
""" """
with wallet.in_single_transaction(), pytest.raises(RuntimeError): with pytest.raises(BroadcastDuringTransactionBuildingError), wallet.in_single_transaction():
wallet.api.create_account("initminer", "alice", "{}", True) wallet.api.create_account("initminer", "alice", "{}", True)
......
...@@ -12,7 +12,7 @@ def wallet(node: tt.InitNode) -> tt.Wallet: ...@@ -12,7 +12,7 @@ def wallet(node: tt.InitNode) -> tt.Wallet:
def test_if_raise_when_parameters_are_bad(wallet: tt.Wallet) -> None: def test_if_raise_when_parameters_are_bad(wallet: tt.Wallet) -> None:
with pytest.raises(tt.exceptions.CommunicationError): with pytest.raises(RuntimeError):
wallet.api.create_account("surely", "bad", "arguments") wallet.api.create_account("surely", "bad", "arguments")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment