diff --git a/tests/beekeepy_test/handle/api_tests/test_api_get_public_keys.py b/tests/beekeepy_test/handle/api_tests/test_api_get_public_keys.py index 8395e7084757d181d76a3df68c021fed176fdcd2..54ec621e9dacd229b24da1841e51388161c5392e 100644 --- a/tests/beekeepy_test/handle/api_tests/test_api_get_public_keys.py +++ b/tests/beekeepy_test/handle/api_tests/test_api_get_public_keys.py @@ -18,12 +18,12 @@ def open_and_unlock_wallet(beekeeper: Beekeeper, wallet: WalletInfo) -> None: @pytest.mark.parametrize("explicit_wallet_name", [False, True]) -def test_api_get_public_keys( +def test_api_get_public_keys_xxx( beekeeper: Beekeeper, setup_wallets: WalletsGeneratorT, explicit_wallet_name: bool ) -> None: """Test test_api_get_public_keys will test beekeeper_api.get_public_keys api call.""" # ARRANGE - wallets = setup_wallets(1, import_keys=False, keys_per_wallet=5) + wallets = setup_wallets(1, import_keys=False, keys_per_wallet=5, lock=False) wallet = wallets[0] explicit_wallet_name_param = {"wallet_name": wallet.name} if explicit_wallet_name else {} diff --git a/tests/beekeepy_test/handle/api_tests/test_api_import_key.py b/tests/beekeepy_test/handle/api_tests/test_api_import_key.py index 850e4407076712be0fa71271df9da5a1466e5f49..b9771ffdaa1ffc4a85721ebbdce0047c4f21be6c 100644 --- a/tests/beekeepy_test/handle/api_tests/test_api_import_key.py +++ b/tests/beekeepy_test/handle/api_tests/test_api_import_key.py @@ -16,7 +16,7 @@ if TYPE_CHECKING: def test_api_import_key(beekeeper: Beekeeper, setup_wallets: WalletsGeneratorT) -> None: """Test test_api_import_key will test beekeeper_api.import_key api call.""" # ARRANGE - wallets = setup_wallets(1, import_keys=False, keys_per_wallet=5) + wallets = setup_wallets(1, import_keys=False, keys_per_wallet=5, lock=False) wallet = wallets[0] # ACT & ASSERT diff --git a/tests/beekeepy_test/handle/api_tests/test_api_open.py b/tests/beekeepy_test/handle/api_tests/test_api_open.py index 25e3753acedd323fe0c5691c540183658c45d391..a31ac33f94021b25caa0144a7540964706a322f1 100644 --- a/tests/beekeepy_test/handle/api_tests/test_api_open.py +++ b/tests/beekeepy_test/handle/api_tests/test_api_open.py @@ -2,20 +2,18 @@ from __future__ import annotations from typing import TYPE_CHECKING -from local_tools.beekeepy.generators import generate_wallet_name, generate_wallet_password -from local_tools.beekeepy.models import WalletInfo - if TYPE_CHECKING: + from local_tools.beekeepy.models import WalletsGeneratorT + from beekeepy._handle import Beekeeper -def test_api_open(beekeeper: Beekeeper) -> None: +def test_api_open(beekeeper: Beekeeper, setup_wallets: WalletsGeneratorT) -> None: """Test test_api_open will test beekeeper_api.open api call.""" # ARRANGE - wallet = WalletInfo(password=generate_wallet_password(), name=generate_wallet_name()) - wallet_path = beekeeper.settings.ensured_working_directory / f"{wallet.name}.wallet" + wallet_path = beekeeper.settings.ensured_working_directory / "wallet-0.wallet" assert wallet_path.exists() is False, "Before creation there should be no wallet file." - beekeeper.api.create(wallet_name=wallet.name, password=wallet.password) + wallet = setup_wallets(1, keys_per_wallet=0)[0] # ACT beekeeper.api.open(wallet_name=wallet.name) @@ -27,11 +25,10 @@ def test_api_open(beekeeper: Beekeeper) -> None: ), "After creation wallet should be visible in beekeeper." -def test_api_reopen_already_opened(beekeeper: Beekeeper) -> None: +def test_api_reopen_already_opened(beekeeper: Beekeeper, setup_wallets: WalletsGeneratorT) -> None: """Test test_api_reopen_already_opened will try to open already opened wallet.""" # ARRANGE - wallet = WalletInfo(password=generate_wallet_password(), name=generate_wallet_name()) - beekeeper.api.create(wallet_name=wallet.name, password=wallet.password) + wallet = setup_wallets(1, keys_per_wallet=0)[0] # ACT beekeeper.api.open(wallet_name=wallet.name) @@ -42,11 +39,10 @@ def test_api_reopen_already_opened(beekeeper: Beekeeper) -> None: assert len((beekeeper.api.list_wallets()).wallets) == 1, "There should be 1 wallet opened." -def test_api_reopen_closed(beekeeper: Beekeeper) -> None: +def test_api_reopen_closed(beekeeper: Beekeeper, setup_wallets: WalletsGeneratorT) -> None: """Test test_api_reopen_closed will try to open closed wallet.""" # ARRANGE - wallet = WalletInfo(password=generate_wallet_password(), name=generate_wallet_name()) - beekeeper.api.create(wallet_name=wallet.name, password=wallet.password) + wallet = setup_wallets(1, keys_per_wallet=0)[0] # ACT beekeeper.api.open(wallet_name=wallet.name) diff --git a/tests/beekeepy_test/handle/api_tests/test_api_remove_key.py b/tests/beekeepy_test/handle/api_tests/test_api_remove_key.py index d55ede4fc3d4470feb173513910da4830e0b26bc..8ee047922250c82ae877eceb78c6bae57f34a40e 100644 --- a/tests/beekeepy_test/handle/api_tests/test_api_remove_key.py +++ b/tests/beekeepy_test/handle/api_tests/test_api_remove_key.py @@ -62,7 +62,7 @@ def test_api_remove_key_from_closed(beekeeper: Beekeeper, wallet: WalletInfo, ac def test_api_remove_key_simple_scenario(beekeeper: Beekeeper, setup_wallets: WalletsGeneratorT) -> None: """Test test_api_remove_key_simple_scenario will test simple flow of importing and removing keys.""" # ARRANGE - wallets = setup_wallets(1, import_keys=True, keys_per_wallet=5) + wallets = setup_wallets(1, import_keys=True, keys_per_wallet=5, lock=False) wallet = wallets[0] key_to_remove = wallet.accounts.pop(3) diff --git a/tests/beekeepy_test/handle/api_tests/test_api_set_timeout.py b/tests/beekeepy_test/handle/api_tests/test_api_set_timeout.py index a87ca73596c52d45dd41638e103456f51bcfe984..30c1d213b2ccadac3d1547f8eeefe8156cd99cd7 100644 --- a/tests/beekeepy_test/handle/api_tests/test_api_set_timeout.py +++ b/tests/beekeepy_test/handle/api_tests/test_api_set_timeout.py @@ -9,11 +9,9 @@ if TYPE_CHECKING: from beekeepy._handle import Beekeeper -def test_api_set_timeout(beekeeper: Beekeeper, wallet: WalletInfo) -> None: +def test_api_set_timeout(beekeeper: Beekeeper, wallet: WalletInfo) -> None: # noqa: ARG001 """Test test_api_set_timeout will test beekeeper_api.set_timeout api call.""" # ARRANGE - beekeeper.api.open(wallet_name=wallet.name) - beekeeper.api.unlock(wallet_name=wallet.name, password=wallet.password) bk_wallet = (beekeeper.api.list_wallets()).wallets[0] assert bk_wallet.unlocked is True, "Wallet should be unlocked." diff --git a/tests/beekeepy_test/handle/api_tests/test_api_unlock.py b/tests/beekeepy_test/handle/api_tests/test_api_unlock.py index 44a5514345028a7b8962b88999dd1b403599f6f2..918ba1d90c6c9f55967ab25ce9838d21ae7a2589 100644 --- a/tests/beekeepy_test/handle/api_tests/test_api_unlock.py +++ b/tests/beekeepy_test/handle/api_tests/test_api_unlock.py @@ -16,9 +16,10 @@ if TYPE_CHECKING: def test_api_unlock(beekeeper: Beekeeper, wallet: WalletInfo) -> None: """Test test_api_unlock will test beekeeper_api.unlock.""" # ARRANGE - beekeeper.api.open(wallet_name=wallet.name) + beekeeper.api.lock_all() # ACT + beekeeper.api.open(wallet_name=wallet.name) beekeeper.api.unlock(wallet_name=wallet.name, password=wallet.password) # ASSERT @@ -26,12 +27,9 @@ def test_api_unlock(beekeeper: Beekeeper, wallet: WalletInfo) -> None: assert bk_wallet.unlocked is True, "Wallet should be unlocked." -def test_api_unlock_already_unclocked_wallet(beekeeper: Beekeeper, wallet: WalletInfo) -> None: - """Test test_api_unlock_already_unclocked_wallet will try to unlock already unlocked wallet.""" +def test_api_unlock_already_unlocked_wallet(beekeeper: Beekeeper, wallet: WalletInfo) -> None: + """Test test_api_unlock_already_unlocked_wallet will try to unlock already unlocked wallet.""" # ARRANGE - beekeeper.api.open(wallet_name=wallet.name) - beekeeper.api.unlock(wallet_name=wallet.name, password=wallet.password) - bk_wallet = (beekeeper.api.list_wallets()).wallets[0] assert bk_wallet.unlocked is True, "Wallet should be unlocked." diff --git a/tests/beekeepy_test/handle/basic/test_wallet.py b/tests/beekeepy_test/handle/basic/test_wallet.py index 4c7426bd39436d3dfa369325a685ffce1475a018..6a5a66db37375bc2a2d33a547b8d53f1764eea1a 100644 --- a/tests/beekeepy_test/handle/basic/test_wallet.py +++ b/tests/beekeepy_test/handle/basic/test_wallet.py @@ -76,7 +76,7 @@ def test_timeout(beekeeper: Beekeeper, wallet: WalletInfo) -> None: check_wallets(beekeeper.api.list_wallets(), [wallet.name]) # ACT - time.sleep(timeout) + time.sleep(timeout + 1) # ASSERT check_wallets(beekeeper.api.list_wallets(), [wallet.name], unlocked=False) diff --git a/tests/beekeepy_test/handle/commandline/application_options/test_export_keys_wallet.py b/tests/beekeepy_test/handle/commandline/application_options/test_export_keys_wallet.py index 6c46b4c8323ef2b4b9a0ea39add96156f490e37e..f85e7de398caef3d94015d527e1a019c5355ff8c 100644 --- a/tests/beekeepy_test/handle/commandline/application_options/test_export_keys_wallet.py +++ b/tests/beekeepy_test/handle/commandline/application_options/test_export_keys_wallet.py @@ -53,8 +53,6 @@ def test_export_keys(beekeeper: Beekeeper) -> None: extract_path = beekeeper.settings.ensured_working_directory create = beekeeper.api.create(wallet_name=wallet_name) - beekeeper.api.open(wallet_name=wallet_name) - beekeeper.api.unlock(password=create.password, wallet_name=wallet_name) for key_pair in PRIVATE_AND_PUBLIC_KEYS: beekeeper.api.import_key(wif_key=key_pair.private_key, wallet_name=wallet_name) diff --git a/tests/beekeepy_test/handle/commandline/application_options/test_unlock_timeout.py b/tests/beekeepy_test/handle/commandline/application_options/test_unlock_timeout.py index 55e5688ea0d1c99dcf6bd942e30c99f95fc7f797..327b84d8da4af53fbc3adda718c704c35f0eebde 100644 --- a/tests/beekeepy_test/handle/commandline/application_options/test_unlock_timeout.py +++ b/tests/beekeepy_test/handle/commandline/application_options/test_unlock_timeout.py @@ -27,7 +27,7 @@ def test_unlock_time(beekeeper_not_started: Beekeeper, unlock_timeout: int) -> N check_wallet_lock(beekeeper_not_started, required_status=True) # ACT - time.sleep(unlock_timeout) + time.sleep(unlock_timeout + 1) # ASSERT check_wallet_lock(beekeeper_not_started, required_status=False) diff --git a/tests/beekeepy_test/handle/conftest.py b/tests/beekeepy_test/handle/conftest.py index bcd8b310dc35a254fb298a01cd996ce93e2e4f44..8bcc866672003f5a079493043f2b83e210d1f54d 100644 --- a/tests/beekeepy_test/handle/conftest.py +++ b/tests/beekeepy_test/handle/conftest.py @@ -61,7 +61,7 @@ def keys_to_import() -> list[AccountCredentials]: def setup_wallets(beekeeper: Beekeeper) -> WalletsGeneratorT: @wraps(setup_wallets) def __setup_wallets( - count: int, *, import_keys: bool = True, keys_per_wallet: int = 1 + count: int, *, import_keys: bool = True, keys_per_wallet: int = 1, lock: bool = True ) -> list[WalletInfoWithImportedAccounts]: wallets = [ WalletInfoWithImportedAccounts( @@ -83,6 +83,8 @@ def setup_wallets(beekeeper: Beekeeper) -> WalletsGeneratorT: if import_keys: for account in wallet.accounts: bk.api.beekeeper.import_key(wallet_name=wallet.name, wif_key=account.private_key) + if lock: + bk.api.beekeeper.close(wallet_name=wallet.name) return wallets return __setup_wallets diff --git a/tests/beekeepy_test/handle/simple_flow/test_simple_flow.py b/tests/beekeepy_test/handle/simple_flow/test_simple_flow.py index f7dd5da4d67654b788d60efda2de8533f18e1a46..ffdf96d349c400e3c706cd4a028a91a5109f2bf3 100644 --- a/tests/beekeepy_test/handle/simple_flow/test_simple_flow.py +++ b/tests/beekeepy_test/handle/simple_flow/test_simple_flow.py @@ -163,6 +163,7 @@ def create_wallets_if_needed( bk.api.create(wallet_name=wallet.name, password=wallet.password) for keys in wallet.keys: bk.api.import_key(wallet_name=wallet.name, wif_key=keys.private_key) + bk.api.lock(wallet_name=wallet.name) @pytest.mark.parametrize( diff --git a/tests/local-tools/local_tools/beekeepy/models.py b/tests/local-tools/local_tools/beekeepy/models.py index d2ead4afeb5af114e460ad8f7d9a3804a15263f3..af572094765b55e18739dc042a6d6400a4c55f8a 100644 --- a/tests/local-tools/local_tools/beekeepy/models.py +++ b/tests/local-tools/local_tools/beekeepy/models.py @@ -28,7 +28,7 @@ class WalletInfoWithImportedAccounts(WalletInfo): class WalletsGeneratorT(Protocol): def __call__( - self, count: int, *, import_keys: bool = True, keys_per_wallet: int = 1 + self, count: int, *, import_keys: bool = True, keys_per_wallet: int = 1, lock: bool = True ) -> list[WalletInfoWithImportedAccounts]: ...