tests: use randomly generated seed where possible

This commit is contained in:
Anastasiya Semenkevich 2024-08-22 17:36:10 +03:00 committed by Anthony Laibe
parent ea31d1115f
commit ad68f46c5b
9 changed files with 80 additions and 58 deletions

View File

@ -32,15 +32,15 @@ class ReturningUser(UserAccount):
class ReturningUsersData(Enum): class ReturningUsersData(Enum):
RETURNING_USER_ONE = ( RETURNING_USER_ONE = (
[ [
'rail', 'witness', 'era', 'asthma', 'empty', 'cheap', 'shed', 'pond', 'skate', 'amount', 'invite', 'year' 'rail', 'witness', 'era', 'asthma', 'empty', 'cheap', 'shed', 'pond', 'skate', 'amount', 'invite', 'year'
], '0x3286c371ef648fe6232324b27ee0515f4ded24d9') ], '0x3286c371ef648fe6232324b27ee0515f4ded24d9')
RETURNING_USER_TWO = ( RETURNING_USER_TWO = (
[ [
'measure', 'cube', 'cousin', 'debris', 'slam', 'ignore', 'seven', 'hat', 'satisfy', 'frown', 'casino', 'inflict' 'measure', 'cube', 'cousin', 'debris', 'slam', 'ignore', 'seven', 'hat', 'satisfy', 'frown', 'casino',
], '0x99C096bB5F12bDe37DE9dbee8257Ebe2a5667C46') 'inflict'
], '0x99C096bB5F12bDe37DE9dbee8257Ebe2a5667C46')
WALLET_USER = ( WALLET_USER = (
[ [
'vocal', 'fruit', 'ordinary', 'meadow', 'south', 'athlete', 'inherit', 'since', 'version', 'pitch', 'vocal', 'fruit', 'ordinary', 'meadow', 'south', 'athlete', 'inherit', 'since', 'version', 'pitch',

View File

@ -1,3 +1,4 @@
import random
from enum import Enum from enum import Enum
@ -81,3 +82,13 @@ class WalletAccountPopup(Enum):
WALLET_ACCOUNT_NAME_MIN = 'Account name must be at least 5 characters' WALLET_ACCOUNT_NAME_MIN = 'Account name must be at least 5 characters'
WALLET_KEYPAIR_NAME_MIN = 'Key pair name must be at least 5 character(s)' WALLET_KEYPAIR_NAME_MIN = 'Key pair name must be at least 5 character(s)'
WALLET_KEYPAIR_MIN = 'Key pair must be at least 5 character(s)' WALLET_KEYPAIR_MIN = 'Key pair must be at least 5 character(s)'
class SeedPhrases(Enum):
TWELVE_WORDS_SEED = 'pelican chief sudden oval media rare swamp elephant lawsuit wheat knife initial'
EIGHTEEN_WORDS_SEED = 'kitten tiny cup admit cactus shrug shuffle accident century faith roof plastic beach police barely vacant sign blossom'
TWENTY_FOUR_WORDS_SEED = 'elite dinosaur flavor canoe garbage palace antique dolphin virtual mixed sand impact solution inmate hair pipe affair cage vote estate gloom lamp robust like'
@classmethod
def select_random_seed(cls):
return random.choice(list(SeedPhrases))

View File

@ -13,6 +13,7 @@ class ContextMenu(QObject):
self._context_add_watched_address_option = QObject(names.contextMenuItem_AddWatchOnly) self._context_add_watched_address_option = QObject(names.contextMenuItem_AddWatchOnly)
self._context_delete_account_option = QObject(names.contextMenuItem_Delete) self._context_delete_account_option = QObject(names.contextMenuItem_Delete)
self._context_edit_account_option = QObject(names.contextMenuItem_Edit) self._context_edit_account_option = QObject(names.contextMenuItem_Edit)
self._context_copy_address_option = QObject(names.contextMenuItem_Copy_Address)
self._context_hide_include_in_total_balance = QObject(names.contextMenuItem_HideInclude) self._context_hide_include_in_total_balance = QObject(names.contextMenuItem_HideInclude)
self._context_edit_saved_address_option = QObject(names.contextSavedAddressEdit) self._context_edit_saved_address_option = QObject(names.contextSavedAddressEdit)
self._context_delete_saved_address_option = QObject(names.contextSavedAddressDelete) self._context_delete_saved_address_option = QObject(names.contextSavedAddressDelete)
@ -58,6 +59,10 @@ class ContextMenu(QObject):
def select_edit_account_from_context_menu(self): def select_edit_account_from_context_menu(self):
self._context_edit_account_option.click() self._context_edit_account_option.click()
@allure.step('Select copy address from context menu')
def select_copy_address_from_context_menu(self):
self._context_copy_address_option.click()
@allure.step('Check delete option visibility in context menu') @allure.step('Check delete option visibility in context menu')
def is_delete_account_option_present(self): def is_delete_account_option_present(self):
return self._context_delete_account_option.is_visible return self._context_delete_account_option.is_visible

View File

@ -291,12 +291,13 @@ mainWallet_Saved_Addresses_Popup_Network_Selector_Arbitrum_network_tag = {"conta
# Context Menu # Context Menu
contextMenu_PopupItem = {"container": statusDesktop_mainWindow_overlay, "type": "PopupItem", "unnamed": 1, "visible": True} contextMenu_PopupItem = {"container": statusDesktop_mainWindow_overlay, "type": "PopupItem", "unnamed": 1, "visible": True}
contextMenuItem = {"container": statusDesktop_mainWindow_overlay, "type": "StatusBaseText", "unnamed": 1, "visible": True} contextMenuItem = {"container": statusDesktop_mainWindow_overlay, "type": "StatusBaseText", "unnamed": 1, "visible": True}
contextMenuItem_AddWatchOnly = {"container": statusDesktop_mainWindow_overlay, "enabled": True, "objectName": RegularExpression("AccountMenu-AddWatchOnlyAccountAction*"), "type": "StatusMenuItem"} contextMenuItem_AddWatchOnly = {"container": statusDesktop_mainWindow_overlay, "enabled": True, "objectName": RegularExpression("AccountMenu-AddWatchOnlyAccountAction*"), "type": "StatusMenuItem", "visible": True}
contextMenuItem_Delete = {"container": statusDesktop_mainWindow_overlay, "enabled": True, "objectName": RegularExpression("AccountMenu-DeleteAction*"), "type": "StatusMenuItem"} contextMenuItem_Delete = {"container": statusDesktop_mainWindow_overlay, "enabled": True, "objectName": RegularExpression("AccountMenu-DeleteAction*"), "type": "StatusMenuItem", "visible": True}
contextMenuItem_Edit = {"container": statusDesktop_mainWindow_overlay, "enabled": True, "objectName": RegularExpression("AccountMenu-EditAction*"), "type": "StatusMenuItem"} contextMenuItem_Edit = {"container": statusDesktop_mainWindow_overlay, "enabled": True, "objectName": RegularExpression("AccountMenu-EditAction*"), "type": "StatusMenuItem", "visible": True}
contextMenuItem_HideInclude = {"container": statusDesktop_mainWindow_overlay, "enabled": True, "objectName": RegularExpression("AccountMenu-HideFromTotalBalance*"), "type": "StatusMenuItem"} contextMenuItem_Copy_Address = {"container": statusDesktop_mainWindow_overlay, "enabled": True, "objectName": RegularExpression("AccountMenu-CopyAddressAction*"), "type": "StatusSuccessAction", "visible": True}
contextSavedAddressEdit = {"container": statusDesktop_mainWindow, "objectName": "editSavedAddress", "type": "StatusMenuItem"} contextMenuItem_HideInclude = {"container": statusDesktop_mainWindow_overlay, "enabled": True, "objectName": RegularExpression("AccountMenu-HideFromTotalBalance*"), "type": "StatusMenuItem", "visible": True}
contextSavedAddressDelete = {"container": statusDesktop_mainWindow, "objectName": "deleteSavedAddress", "type": "StatusMenuItem"} contextSavedAddressEdit = {"container": statusDesktop_mainWindow, "objectName": "editSavedAddress", "type": "StatusMenuItem", "visible": True}
contextSavedAddressDelete = {"container": statusDesktop_mainWindow, "objectName": "deleteSavedAddress", "type": "StatusMenuItem", "visible": True}
# Confirmation Popup # Confirmation Popup
confirmButton = {"container": statusDesktop_mainWindow_overlay, "objectName": RegularExpression("confirm*"), "type": "StatusButton"} confirmButton = {"container": statusDesktop_mainWindow_overlay, "objectName": RegularExpression("confirm*"), "type": "StatusButton"}

View File

@ -2,6 +2,7 @@ import time
import typing import typing
import allure import allure
import pyperclip
import configs import configs
import constants.user import constants.user
@ -134,6 +135,11 @@ class LeftPanel(QObject):
else: else:
raise ex raise ex
@allure.step('Copy address for the account in the context menu')
def copy_account_address_in_context_menu(self, account_name: str):
self._open_context_menu_for_account(account_name).select_copy_address_from_context_menu()
return str(pyperclip.paste())
class SavedAddressesView(QObject): class SavedAddressesView(QObject):

View File

@ -14,3 +14,6 @@ pytest-timeout==2.2.0
shortuuid==1.0.12 shortuuid==1.0.12
pluggy==1.2.0 pluggy==1.2.0
beautifulsoup4==4.12.3 beautifulsoup4==4.12.3
requests==2.31.0
mnemonic==0.21
zpywallet==0.6.2

View File

@ -1,5 +1,8 @@
import random import random
import string import string
from mnemonic import Mnemonic
from zpywallet import HDWallet
from zpywallet.network import EthereumMainNet
def random_name_string(): def random_name_string():
@ -19,3 +22,16 @@ def random_password_string():
def random_ens_string(): def random_ens_string():
return ''.join( return ''.join(
random.choices(string.digits + string.ascii_lowercase, k=8)) random.choices(string.digits + string.ascii_lowercase, k=8))
def random_mnemonic():
mnemo = Mnemonic("english")
words = mnemo.generate(strength=random.choice([128, 192, 256]))
return words
def get_wallet_address_from_mnemonic(mnemonic_data) -> str:
w = HDWallet.from_mnemonic(mnemonic=mnemonic_data, passphrase='', network=EthereumMainNet)
child_w = w.get_child_for_path("m/44'/60'/0'/0/0")
address_from_mnemonic = child_w.address()
return address_from_mnemonic

View File

@ -4,16 +4,16 @@ import allure
import pytest import pytest
from allure_commons._allure import step from allure_commons._allure import step
from constants import UserAccount, RandomUser from constants import RandomUser
from scripts.utils.generators import random_name_string, random_password_string
from constants.wallet import WalletSeedPhrase from constants.wallet import WalletSeedPhrase
from scripts.utils.generators import random_mnemonic
from tests.wallet_main_screen import marks from tests.wallet_main_screen import marks
import constants import constants
import driver
from gui.components.signing_phrase_popup import SigningPhrasePopup from gui.components.signing_phrase_popup import SigningPhrasePopup
from gui.components.authenticate_popup import AuthenticatePopup from gui.components.authenticate_popup import AuthenticatePopup
from gui.main_window import MainWindow from gui.main_window import MainWindow
from scripts.utils.generators import get_wallet_address_from_mnemonic
pytestmark = marks pytestmark = marks
@ -22,30 +22,23 @@ pytestmark = marks
@pytest.mark.case(703030) @pytest.mark.case(703030)
@pytest.mark.parametrize('user_account', [RandomUser()]) @pytest.mark.parametrize('user_account', [RandomUser()])
@pytest.mark.parametrize('name, color, emoji, emoji_unicode, ' @pytest.mark.parametrize('name, color, emoji, emoji_unicode, '
'new_name, new_color, new_emoji, new_emoji_unicode, seed_phrase', [ 'new_name, new_color, new_emoji, new_emoji_unicode, mnemonic_data', [
pytest.param('SPAcc24', '#2a4af5', 'sunglasses', '1f60e', pytest.param('SPAcc24', '#2a4af5', 'sunglasses', '1f60e',
'SPAcc24edited', '#216266', 'thumbsup', '1f44d', 'SPAcc24edited', '#216266', 'thumbsup', '1f44d',
'elite dinosaur flavor canoe garbage palace antique dolphin virtual mixed sand ' random_mnemonic()
'impact solution inmate hair pipe affair cage vote estate gloom lamp robust like'), )
pytest.param('SPAcc18', '#2a4af5', 'sunglasses', '1f60e',
'SPAcc18edited', '#216266', 'thumbsup', '1f44d',
'kitten tiny cup admit cactus shrug shuffle accident century faith roof plastic '
'beach police barely vacant sign blossom'),
pytest.param('SPAcc12', '#2a4af5', 'sunglasses', '1f60e',
'SPAcc12edited', '#216266', 'thumbsup', '1f44d',
'pelican chief sudden oval media rare swamp elephant lawsuit wheat knife initial')
]) ])
def test_plus_button_manage_account_from_seed_phrase(main_screen: MainWindow, user_account, def test_plus_button_manage_account_from_seed_phrase(main_screen: MainWindow, user_account,
name: str, color: str, emoji: str, emoji_unicode: str, name: str, color: str, emoji: str, emoji_unicode: str,
new_name: str, new_color: str, new_emoji: str, new_name: str, new_color: str, new_emoji: str,
new_emoji_unicode: str, new_emoji_unicode: str,
seed_phrase: str): mnemonic_data: str):
with step('Create imported seed phrase wallet account'): with step('Create imported seed phrase wallet account'):
wallet = main_screen.left_panel.open_wallet() wallet = main_screen.left_panel.open_wallet()
SigningPhrasePopup().wait_until_appears().confirm_phrase() SigningPhrasePopup().wait_until_appears().confirm_phrase()
account_popup = wallet.left_panel.open_add_account_popup() account_popup = wallet.left_panel.open_add_account_popup()
account_popup.set_name(name).set_emoji(emoji).set_color( account_popup.set_name(name).set_emoji(emoji).set_color(
color).open_add_new_account_popup().import_new_seed_phrase(seed_phrase.split()) color).open_add_new_account_popup().import_new_seed_phrase(mnemonic_data.split())
account_popup.save_changes() account_popup.save_changes()
AuthenticatePopup().wait_until_appears().authenticate(user_account.password) AuthenticatePopup().wait_until_appears().authenticate(user_account.password)
account_popup.wait_until_hidden() account_popup.wait_until_hidden()
@ -64,29 +57,11 @@ def test_plus_button_manage_account_from_seed_phrase(main_screen: MainWindow, us
if time.monotonic() - started_at > 15: if time.monotonic() - started_at > 15:
raise LookupError(f'Account {expected_account} not found in {wallet.left_panel.accounts}') raise LookupError(f'Account {expected_account} not found in {wallet.left_panel.accounts}')
with step('Edit wallet account'): with step('Verify account address from UI is correct for derived account '):
account_popup = wallet.left_panel.open_edit_account_popup_from_context_menu(name) address_in_ui = wallet.left_panel.copy_account_address_in_context_menu(name)
account_popup.set_name(new_name).set_emoji(new_emoji).set_color(new_color).save_changes() address_from_mnemonic = get_wallet_address_from_mnemonic(mnemonic_data)
assert address_in_ui == address_from_mnemonic, \
with step('Verify that the account is correctly displayed in accounts list'): f'Expected to recover {address_from_mnemonic} but got {address_in_ui}'
expected_account = constants.user.account_list_item(new_name, new_color.lower(), new_emoji_unicode)
started_at = time.monotonic()
while expected_account not in wallet.left_panel.accounts:
time.sleep(1)
if time.monotonic() - started_at > 15:
raise LookupError(f'Account {expected_account} not found in {wallet.left_panel.accounts}')
with step('Delete wallet account with agreement'):
wallet.left_panel.delete_account_from_context_menu(new_name).agree_and_confirm()
with step('Verify toast message notification when removing account'):
messages = main_screen.wait_for_notification()
assert f'"{new_name}" successfully removed' in messages, \
f"Toast message about account removal is not correct or not present. Current list of messages: {messages}"
with step('Verify that the account is not displayed in accounts list'):
assert driver.waitFor(lambda: new_name not in [account.name for account in wallet.left_panel.accounts], 10000), \
f'Account with {new_name} is still displayed even it should not be'
@allure.testcase('https://ethstatus.testrail.net/index.php?/cases/view/736371', @allure.testcase('https://ethstatus.testrail.net/index.php?/cases/view/736371',
@ -97,8 +72,7 @@ def test_plus_button_manage_account_from_seed_phrase(main_screen: MainWindow, us
'new_name, new_color, new_emoji, new_emoji_unicode, seed_phrase', [ 'new_name, new_color, new_emoji, new_emoji_unicode, seed_phrase', [
pytest.param('SPAcc24', '#2a4af5', 'sunglasses', '1f60e', pytest.param('SPAcc24', '#2a4af5', 'sunglasses', '1f60e',
'SPAcc24edited', '#216266', 'thumbsup', '1f44d', 'SPAcc24edited', '#216266', 'thumbsup', '1f44d',
'elite dinosaur flavor canoe garbage palace antique dolphin virtual mixed sand ' random_mnemonic()),
'impact solution inmate hair pipe affair cage vote estate gloom lamp robust like'),
]) ])
def test_plus_button_re_importing_seed_phrase(main_screen: MainWindow, user_account, def test_plus_button_re_importing_seed_phrase(main_screen: MainWindow, user_account,
name: str, color: str, emoji: str, emoji_unicode: str, name: str, color: str, emoji: str, emoji_unicode: str,

View File

@ -18,14 +18,21 @@ pytestmark = marks
@allure.testcase('https://ethstatus.testrail.net/index.php?/cases/view/703028', 'Manage a custom generated account') @allure.testcase('https://ethstatus.testrail.net/index.php?/cases/view/703028', 'Manage a custom generated account')
@pytest.mark.case(703028) @pytest.mark.case(703028)
@pytest.mark.parametrize('user_account', [RandomUser()]) @pytest.mark.parametrize('user_account', [RandomUser()])
@pytest.mark.parametrize('derivation_path, generated_address_index, name, color, emoji, emoji_unicode, new_name, new_color, new_emoji, new_emoji_unicode', @pytest.mark.parametrize(
[ 'derivation_path, generated_address_index, name, color, emoji, emoji_unicode, new_name, new_color, new_emoji, '
pytest.param('Ethereum', '5', 'Ethereum', '#216266', 'sunglasses', '1f60e', 'EthEdited', '#216266', 'thumbsup', '1f44d'), 'new_emoji_unicode',
pytest.param('Ethereum Testnet (Ropsten)', '10', 'Ethereum Testnet ', '#7140fd', 'sunglasses', '1f60e', 'RopstenEdited', '#216266', 'thumbsup', '1f44d'), [
pytest.param('Ethereum (Ledger)', '15', 'Ethereum Ledger', '#2a799b', 'sunglasses', '1f60e', 'LedgerEdited', '#216266', 'thumbsup', '1f44d'), pytest.param('Ethereum', '5', 'Ethereum', '#216266', 'sunglasses', '1f60e', 'EthEdited', '#216266', 'thumbsup',
pytest.param('Ethereum (Ledger Live/KeepKey)', '20', 'Ethereum Ledger Live', '#7140fd', 'sunglasses', '1f60e', 'LiveEdited', '#216266', 'thumbsup', '1f44d'), '1f44d'),
pytest.param('N/A', '95', 'Custom path', '#216266', 'sunglasses', '1f60e', 'CustomEdited', '#216266', 'thumbsup', '1f44d') pytest.param('Ethereum Testnet (Ropsten)', '10', 'Ethereum Testnet ', '#7140fd', 'sunglasses', '1f60e',
]) 'RopstenEdited', '#216266', 'thumbsup', '1f44d'),
pytest.param('Ethereum (Ledger)', '15', 'Ethereum Ledger', '#2a799b', 'sunglasses', '1f60e', 'LedgerEdited',
'#216266', 'thumbsup', '1f44d'),
pytest.param('Ethereum (Ledger Live/KeepKey)', '20', 'Ethereum Ledger Live', '#7140fd', 'sunglasses', '1f60e',
'LiveEdited', '#216266', 'thumbsup', '1f44d'),
pytest.param('N/A', '95', 'Custom path', '#216266', 'sunglasses', '1f60e', 'CustomEdited', '#216266',
'thumbsup', '1f44d')
])
def test_plus_button_manage_generated_account_custom_derivation_path(main_screen: MainWindow, user_account, def test_plus_button_manage_generated_account_custom_derivation_path(main_screen: MainWindow, user_account,
derivation_path: str, generated_address_index: int, derivation_path: str, generated_address_index: int,
name: str, color: str, emoji: str, name: str, color: str, emoji: str,
@ -40,7 +47,6 @@ def test_plus_button_manage_generated_account_custom_derivation_path(main_screen
generated_address_index, generated_address_index,
user_account.password).save_changes() user_account.password).save_changes()
with step('Verify that the account is correctly displayed in accounts list'): with step('Verify that the account is correctly displayed in accounts list'):
expected_account = constants.user.account_list_item(name, color.lower(), emoji_unicode) expected_account = constants.user.account_list_item(name, color.lower(), emoji_unicode)
started_at = time.monotonic() started_at = time.monotonic()