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

Fix duplicate keys random fail in tests

parent 253327e1
No related branches found
No related tags found
1 merge request!76Test hot fix
......@@ -11,6 +11,13 @@ if TYPE_CHECKING:
from beekeepy.handle.runnable import Beekeeper
"""
NOTE 1: Usage of sets in this tests are intentional. It is because keys to import are generated by
random.sample() function 2 times (because of 2 wallets). This means that there is a chance that
the same key will be generated for both wallets. In such case, same key will be shown once in
get_public_keys response for call without wallet name. To avoid this, we are using sets to compare keys.
"""
def open_and_unlock_wallet(beekeeper: Beekeeper, wallet: WalletInfo) -> None:
beekeeper.api.open(wallet_name=wallet.name)
......@@ -58,15 +65,13 @@ def test_api_get_public_keys_with_many_wallets(beekeeper: Beekeeper, setup_walle
wallets = setup_wallets(2, import_keys=True, keys_per_wallet=5)
wallet_1 = wallets[0]
wallet_2 = wallets[1]
all_keys = wallet_1.get_all_public_keys() + wallet_2.get_all_public_keys()
all_keys.sort()
all_keys = set(wallet_1.get_all_public_keys() + wallet_2.get_all_public_keys()) # NOTE 1
# open and and unlock wallets
open_and_unlock_wallet(wallet=wallet_1, beekeeper=beekeeper)
open_and_unlock_wallet(wallet=wallet_2, beekeeper=beekeeper)
# Get ALL public key from bk it should contain both, wallet_1_keys and wallet_2_keys
bk_pub_keys_all = [pub.public_key for pub in (beekeeper.api.get_public_keys()).keys]
bk_pub_keys_all.sort()
bk_pub_keys_all = {pub.public_key for pub in (beekeeper.api.get_public_keys()).keys} # NOTE 1
assert bk_pub_keys_all == all_keys, "All keys should be available."
# ACT & ASSERT 1
......@@ -94,16 +99,14 @@ def test_api_get_public_keys_with_many_wallets_closed(beekeeper: Beekeeper, setu
wallets = setup_wallets(2, import_keys=True, keys_per_wallet=5)
wallet_1 = wallets[0]
wallet_2 = wallets[1]
all_keys = wallet_1.get_all_public_keys() + wallet_2.get_all_public_keys()
all_keys.sort()
all_keys = set(wallet_1.get_all_public_keys() + wallet_2.get_all_public_keys()) # NOTE 1
# Open and unlock wallets
open_and_unlock_wallet(wallet=wallet_1, beekeeper=beekeeper)
open_and_unlock_wallet(wallet=wallet_2, beekeeper=beekeeper)
# Get all available public keys ()
bk_pub_keys_all = [pub.public_key for pub in (beekeeper.api.get_public_keys()).keys]
bk_pub_keys_all.sort()
bk_pub_keys_all = {pub.public_key for pub in (beekeeper.api.get_public_keys()).keys} # NOTE 1
assert bk_pub_keys_all == all_keys, "Keys from wallet 1 and wallet 2 should be available."
# ACT & ASSERT 1
......
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