Skip to content
Snippets Groups Projects
Commit 380337ca authored by Krzysztof Mochocki's avatar Krzysztof Mochocki
Browse files

Fix tests because of changes in beekeeper behaviour

list_wallets -> list_created_wallets change: list_wallets does not refresh timeout and tests aware on this will fail
parent 1e9be0e0
No related branches found
No related tags found
No related merge requests found
Pipeline #118586 passed
......@@ -14,6 +14,10 @@ if TYPE_CHECKING:
from beekeepy.handle.runnable import Beekeeper
# NOTE 1: Beekeeper should not raise exception while calling close on already closed wallet or not existing wallet.
# It should be treated as a success for UX purposes.
def test_api_close(beekeeper: Beekeeper, wallet: WalletInfo) -> None:
"""Test test_api_close will test beekeeper_api.close api call."""
# ARRANGE
......@@ -51,8 +55,8 @@ def test_api_close_double_close(
beekeeper.api.close(wallet_name=wallet.name)
# ASSERT
with pytest.raises(ErrorInResponseError, match=f"Wallet not found: {wallet.name}"):
beekeeper.api.close(wallet_name=wallet.name)
# SHOULD NOT RAISE (NOTE 1)
beekeeper.api.close(wallet_name=wallet.name)
def test_api_close_not_existing_wallet(beekeeper: Beekeeper) -> None:
......@@ -61,5 +65,5 @@ def test_api_close_not_existing_wallet(beekeeper: Beekeeper) -> None:
wallet = WalletInfo(password=generate_wallet_password(), name=generate_wallet_name())
# ACT & ASSERT
with pytest.raises(ErrorInResponseError, match=f"Wallet not found: {wallet.name}"):
beekeeper.api.close(wallet_name=wallet.name)
# SHOULD NOT RAISE (NOTE 1)
beekeeper.api.close(wallet_name=wallet.name)
......@@ -12,7 +12,7 @@ if TYPE_CHECKING:
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
bk_wallet = (beekeeper.api.list_wallets()).wallets[0]
bk_wallet = (beekeeper.api.list_created_wallets()).wallets[0]
assert bk_wallet.unlocked is True, "Wallet should be unlocked."
# ACT
......@@ -20,5 +20,5 @@ def test_api_set_timeout(beekeeper: Beekeeper, wallet: WalletInfo) -> None: # n
time.sleep(1.5)
# ASSERT
bk_wallet = (beekeeper.api.list_wallets()).wallets[0]
bk_wallet = (beekeeper.api.list_created_wallets()).wallets[0]
assert bk_wallet.unlocked is False, "Wallet after timeout should be locked."
......@@ -73,13 +73,13 @@ def test_timeout(beekeeper: Beekeeper, wallet: WalletInfo) -> None:
# ASSERT
info = beekeeper.api.get_info()
assert timeout - (info.timeout_time - info.now).total_seconds() <= comparison_error_max_delta
check_wallets(beekeeper.api.list_wallets(), [wallet.name])
check_wallets(beekeeper.api.list_created_wallets(), [wallet.name])
# ACT
time.sleep(timeout + 1)
# ASSERT
check_wallets(beekeeper.api.list_wallets(), [wallet.name], unlocked=False)
check_wallets(beekeeper.api.list_created_wallets(), [wallet.name], unlocked=False)
@pytest.mark.parametrize("wallet_name", ["test", "123"])
......
......@@ -27,9 +27,6 @@ Application Options:
--export-keys-wallet "["green-wallet",
"PW5KYF9Rt4ETnuP4uheHSCm9kLbCuunf6RqeKgQ8QRoxZmGeZUhhk"]"
--notifications-endpoint arg
list of addresses, that will receive notification about in-chain
events
--unlock-interval arg (=500)
Protection against unlocking by bots. Every wrong `unlock` enables a
delay. By default 500[ms].
......@@ -62,5 +59,4 @@ Application Command Line Options:
-d [ --data-dir ] dir
Directory containing configuration file config.ini. Default location: $HOME/.beekeeper or CWD/. beekeeper
-c [ --config ] filename (="config.ini")
Configuration file name relative to data-dir
Configuration file name relative to data-dir
\ No newline at end of file
......@@ -13,7 +13,7 @@ if TYPE_CHECKING:
def check_wallet_lock(beekeeper: Beekeeper, required_status: bool) -> None:
"""Check if wallets are have required unlock status."""
response_list_wallets = beekeeper.api.list_wallets()
response_list_wallets = beekeeper.api.list_created_wallets()
for wallet in response_list_wallets.wallets:
assert wallet.unlocked == required_status
......
......@@ -34,14 +34,10 @@ def test_multiply_beekeepeer_same_storage(working_directory: Path) -> None:
assert bk1.is_running() is True, "First instance of beekeeper should launch without any problems."
# ACT & ASSERT 2
bk2 = Beekeeper(settings=settings, logger=logger)
with pytest.raises(BeekeeperFailedToStartError):
bk2.run()
assert checkers.check_for_pattern_in_file(
bk2.settings.ensured_working_directory / "stderr.log",
"Failed to lock access to wallet directory; is another `beekeeper` running?",
), "There should be an info about another instance of beekeeper locking wallet directory."
with Beekeeper(settings=settings, logger=logger) as bk2:
assert (
"opening beekeeper failed" in bk2.apis.app_status.get_app_status().statuses
), "Second instance of beekeeper should fail to start."
def test_multiply_beekeepeer_different_storage(working_directory: Path) -> None:
......@@ -76,44 +72,12 @@ def test_multiply_beekeepeer_different_storage(working_directory: Path) -> None:
), "There should be an no info about another instance of beekeeper locking wallet directory."
def get_remote_address_from_connection_file(working_dir: Path) -> HttpUrl:
connection: dict[str, str | int] = {}
with (working_dir / "beekeeper.connection").open() as file:
connection = json.load(file)
return HttpUrl(
f"{connection['address']}:{connection['port']}",
protocol=str(connection["type"]).lower(), # type: ignore[arg-type]
)
def test_beekeepers_files_generation(beekeeper: Beekeeper) -> None:
"""Test test_beekeepers_files_generation will check if beekeeper files are generated and have same content."""
# ARRANGE & ACT
wallet_dir = beekeeper.settings.ensured_working_directory
beekeeper_connection_file = wallet_dir / "beekeeper.connection"
beekeeper_pid_file = wallet_dir / "beekeeper.pid"
beekeeper_wallet_lock_file = wallet_dir / "beekeeper.wallet.lock"
# ASSERT
assert beekeeper_connection_file.exists() is True, "File 'beekeeper.connection' should exists"
assert beekeeper_pid_file.exists() is True, "File 'beekeeper.pid' should exists"
# File beekeeper.wallet.lock holds no value inside, so we need only to check is its exists.
assert beekeeper_wallet_lock_file.exists() is True, "File 'beekeeper.wallet.lock' should exists"
connection_url = get_remote_address_from_connection_file(wallet_dir)
assert connection_url is not None, "There should be connection details."
if beekeeper.http_endpoint.address == "127.0.0.1":
assert connection_url.address in [
"0.0.0.0", # noqa: S104
"127.0.0.1",
], "Address should point to localhost or all interfaces."
else:
assert connection_url.address == beekeeper.http_endpoint.address, "Host should be the same."
assert connection_url.port == beekeeper.http_endpoint.port, "Port should be the same."
assert connection_url.protocol == beekeeper.http_endpoint.protocol, "Protocol should be the same."
with Path.open(beekeeper_pid_file) as pid:
content = json.load(pid)
assert content["pid"] == str(beekeeper.pid), "Pid should be the same"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment