From e0b5b88199fd85ce3dc4bbb2bc52cb0487b1a188 Mon Sep 17 00:00:00 2001 From: Vladimir Druzhinin <128374224+StateOf-Vlado@users.noreply.github.com> Date: Fri, 15 Sep 2023 06:17:07 +0200 Subject: [PATCH] Testnet mode and account order (#105) Co-authored-by: Valentina Novgorodtceva --- test/e2e/constants/user.py | 1 + .../generated_account_icon.png | Bin 0 -> 1964 bytes .../watch_only_account_icon.png | Bin 0 -> 2179 bytes .../components/wallet/testnet_mode_banner.py | 8 ++ .../components/wallet/testnet_mode_popup.py | 26 ++++ .../components/wallet/wallet_toast_message.py | 18 +++ test/e2e/gui/objects_map/component_names.py | 13 ++ test/e2e/gui/objects_map/settings_names.py | 12 ++ test/e2e/gui/screens/settings.py | 104 ++++++++++++++- .../test_wallet_manage_accounts.py | 6 +- .../tests/test_wallet/test_wallet_settings.py | 120 ++++++++++++++++++ 11 files changed, 306 insertions(+), 2 deletions(-) create mode 100644 test/e2e/ext/vp/test_wallet/test_wallet_settings/test_change_account_order_by_drag_and_drop/generated_account_icon.png create mode 100644 test/e2e/ext/vp/test_wallet/test_wallet_settings/test_change_account_order_by_drag_and_drop/watch_only_account_icon.png create mode 100644 test/e2e/gui/components/wallet/testnet_mode_banner.py create mode 100644 test/e2e/gui/components/wallet/testnet_mode_popup.py create mode 100644 test/e2e/gui/components/wallet/wallet_toast_message.py create mode 100644 test/e2e/tests/test_wallet/test_wallet_settings.py diff --git a/test/e2e/constants/user.py b/test/e2e/constants/user.py index d865e5aa4f..231fde5b8c 100644 --- a/test/e2e/constants/user.py +++ b/test/e2e/constants/user.py @@ -24,3 +24,4 @@ UserCommunityInfo = namedtuple('CommunityInfo', ['name', 'description', 'members UserChannel = namedtuple('Channel', ['name', 'image', 'selected']) account_list_item = namedtuple('AccountListItem', ['name', 'color', 'emoji']) +wallet_account_list_item = namedtuple('WalletAccountListItem', ['name', 'icon', 'object']) diff --git a/test/e2e/ext/vp/test_wallet/test_wallet_settings/test_change_account_order_by_drag_and_drop/generated_account_icon.png b/test/e2e/ext/vp/test_wallet/test_wallet_settings/test_change_account_order_by_drag_and_drop/generated_account_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..7e081253305745d79da5e5bc45b701584a0f112c GIT binary patch literal 1964 zcmY*ac|6mP8(-RwVbdn$PFp#04HY5B`pi&>O6E$IISbz*uV24Ep6B`J{d(Td>v=uz_mgza9tRVX7XyJnFdJ*YNl?}Q z35bv&@6FXU27yFKHh|>?7txAl@t{Z3aw3bneDZ(7KhOC4``@w9O}ExWb5%2s%DX@$ zj$2%bcfx$IgwsU}RNbBRbS$z!Fd7s{6}9z_56diiF6E8!vWJ}h#(k@y9c1CwT`|r0 zzCm8#m*1EvnD^J{UcezK*ZqjNr0MRZl#7>wC*CPQkH=HsC5JbnHui6>&77L* znky5A%4VHHcYQx?m`*J?W9~c>9X9oC=X}}ix6VpwAG7fqSZ$ECIMLbmNQ7xzjeZ9# zYGZo*Yn;9T>xd-cM$yLVe4hl_Ba#;~Pmjc2b(299l8{sKt;iYw=LyBQ2K}37iB+CF za1vxn!+c|YW8(4!&#Ib7uQOYU(LFjO`=-W}GW*A-%lNj_ND5P^kR=kedYye+MKR@M zRzkk5LdN7$kJ4HTWlOY+Y(9oWH1GX+7o*9fWhxs7y^LDqqia678$}K#;|-j)$fmIX zxI(CKae3b4rjnVrCKiZL1loM^PRy=9sv)Xw?q?+n0M7GTY^UmxYAs|72ZbEVUf-`) zZ_)s&um)H~TfFKc2ZK}mD>5-O7YlF;%8PiPQ~ty-e7Vz?MFGGTy>t_UMY_*M5Z4KAl2U)^`AuN_EC!Tb#MJS1QB+I4tabDZ z>q`7=?5&KGIyWynmuqPAjU|*-=e(y=ejX%qD2{ks6PpVQP{*ucYsqD=CVOr6Ki5#q ztGn5n)P1yrxrEk>8{+(0$TvX09kOoP?u;@N!t%`K-_@P`Vv?m(6#O|a>Kcbj9ZrUL zNZxV!U4lMAM4t{}-hCP~3kwubux>l?$t_gxqLwhnjM6BdHXLsQ z656w4n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+*Zq4}hj zGNS(=1Z~Ai6-zI@iR?c9hwXbMaAqTS?H8KdIm?ha%);ZnsW>J{XV2hAT*OadiLc^F zoPP6OaQfWI&y<~IYY1X3ASo8>c!B@rlHSW#JNzntRP-bAO?`gGB&&upj~gn#dqZQfg?i!e zzO1^rh_#A^N8)bYxt+{oV>R zAfALuj)?A|ir(3_2x5B`cD6<#_#p{JazbL0mz3blg^6oNWlNH)HJjDJwU(AlRk+Le z@5fVb$L@~KbKPFQf1(o(bj;D<$Mx4)3jA{0i>ly>z7m8CmfGh7rpq>%Y<9#SJ{JHh LGka7O(g*)<$L}r7 literal 0 HcmV?d00001 diff --git a/test/e2e/gui/components/wallet/testnet_mode_banner.py b/test/e2e/gui/components/wallet/testnet_mode_banner.py new file mode 100644 index 0000000000..daaa372a80 --- /dev/null +++ b/test/e2e/gui/components/wallet/testnet_mode_banner.py @@ -0,0 +1,8 @@ +from gui.elements.qt.object import QObject +from gui.elements.qt.button import Button + + +class TestnetModeBanner(QObject): + def __init__(self): + super(TestnetModeBanner, self).__init__('mainWindow_testnetBanner_ModuleWarning') + self._turn_off_button = Button('mainWindow_Turn_off_Button') diff --git a/test/e2e/gui/components/wallet/testnet_mode_popup.py b/test/e2e/gui/components/wallet/testnet_mode_popup.py new file mode 100644 index 0000000000..5b1aa6fec1 --- /dev/null +++ b/test/e2e/gui/components/wallet/testnet_mode_popup.py @@ -0,0 +1,26 @@ +import allure + +from gui.components.base_popup import BasePopup +from gui.elements.qt.button import Button + + +class TestnetModePopup(BasePopup): + def __init__(self): + super(TestnetModePopup, self).__init__() + self._cancel_button = Button('add_StatusButton') + self._turn_on_button = Button('turn_on_testnet_mode_StatusButton') + self._turn_off_button = Button('turn_off_testnet_mode_StatusButton') + + @allure.step('Choose turn on option') + def turn_on_testnet_mode(self): + self._turn_on_button.click() + self.wait_until_hidden() + + @allure.step('Choose turn off option') + def turn_off_testnet_mode(self): + self._turn_off_button.click() + self.wait_until_hidden() + + def cancel(self): + self._cancel_button.click() + self.wait_until_hidden() diff --git a/test/e2e/gui/components/wallet/wallet_toast_message.py b/test/e2e/gui/components/wallet/wallet_toast_message.py new file mode 100644 index 0000000000..cbd19bc7f2 --- /dev/null +++ b/test/e2e/gui/components/wallet/wallet_toast_message.py @@ -0,0 +1,18 @@ +import allure + +from driver import objects_access +from gui.elements.qt.object import QObject + + +class WalletToastMessage(QObject): + + def __init__(self): + super(WalletToastMessage, self).__init__('ephemeralNotificationList_StatusToastMessage') + self._wallet_toast_messages_list = QObject('mainWallet_Ephemeral_Notification_List') + + @allure.step('Check message at the bottom') + def get_toast_message(self, name: str): + for item in objects_access.walk_children(self._wallet_toast_messages_list.object): + if getattr(item, 'text', '') == name: + return item + raise LookupError(f'Wallet toast message: {name} not found') diff --git a/test/e2e/gui/objects_map/component_names.py b/test/e2e/gui/objects_map/component_names.py index d03f8c5363..8d72be3410 100644 --- a/test/e2e/gui/objects_map/component_names.py +++ b/test/e2e/gui/objects_map/component_names.py @@ -250,3 +250,16 @@ mainWallet_AddEditAccountPopup_SPWord = {"container": mainWallet_AddEditAccountP mainWallet_AddEditAccountPopup_12WordsButton = {"container": mainWallet_AddEditAccountPopup_Content, "objectName": "12SeedButton", "type": "StatusSwitchTabButton"} mainWallet_AddEditAccountPopup_18WordsButton = {"container": mainWallet_AddEditAccountPopup_Content, "objectName": "18SeedButton", "type": "StatusSwitchTabButton"} mainWallet_AddEditAccountPopup_24WordsButton = {"container": mainWallet_AddEditAccountPopup_Content, "objectName": "24SeedButton", "type": "StatusSwitchTabButton"} + +# Testnet mode popup +turn_on_testnet_mode_StatusButton = {"checkable": False, "container": statusDesktop_mainWindow_overlay, "id": "acceptBtn", "text": "Turn on testnet mode", "type": "StatusButton", "unnamed": 1, "visible": True} +turn_off_testnet_mode_StatusButton = {"checkable": False, "container": statusDesktop_mainWindow_overlay, "id": "acceptBtn", "text": "Turn off testnet mode", "type": "StatusButton", "unnamed": 1, "visible": True} +add_StatusButton = {"checkable": False, "container": statusDesktop_mainWindow_overlay, "type": "StatusButton", "unnamed": 1, "visible": True} + +# Testnet mode banner +mainWindow_testnetBanner_ModuleWarning = {"container": statusDesktop_mainWindow, "objectName": "testnetBanner", "type": "ModuleWarning", "visible": True} +mainWindow_Turn_off_Button = {"checkable": False, "container": statusDesktop_mainWindow, "id": "button", "text": "Turn off", "type": "Button", "unnamed": 1, "visible": True} + +# Wallet toast message +mainWallet_Ephemeral_Notification_List = {"container": statusDesktop_mainWindow, "objectName": "ephemeralNotificationList", "type": "StatusListView"} +ephemeralNotificationList_StatusToastMessage = {"container": mainWallet_Ephemeral_Notification_List, "type": "StatusToastMessage", "unnamed": 1, "visible": True} diff --git a/test/e2e/gui/objects_map/settings_names.py b/test/e2e/gui/objects_map/settings_names.py index f7b2b3676f..6804ab0230 100644 --- a/test/e2e/gui/objects_map/settings_names.py +++ b/test/e2e/gui/objects_map/settings_names.py @@ -40,3 +40,15 @@ importRestoreKeycard_StatusListItem = {"container": settingsContentBase_ScrollVi importFromKeycard_StatusListItem = {"container": settingsContentBase_ScrollView, "objectName": "importFromKeycard", "type": "StatusListItem", "visible": True} checkWhatsNewKeycard_StatusListItem = {"container": settingsContentBase_ScrollView, "objectName": "checkWhatsNewKeycard", "type": "StatusListItem", "visible": True} factoryResetKeycard_StatusListItem = {"container": settingsContentBase_ScrollView, "objectName": "factoryResetKeycard", "type": "StatusListItem", "visible": True} + +# Wallet Settings View +mainWindow_WalletView = {"container": statusDesktop_mainWindow, "type": "WalletView", "unnamed": 1, "visible": True} +settings_Wallet_MainView_Networks = {"container": statusDesktop_mainWindow, "objectName": "networksItem", "type": "StatusListItem"} +settingsContentBaseScrollView_accountOrderItem_StatusListItem = {"container": settingsContentBase_ScrollView, "objectName": "accountOrderItem", "type": "StatusListItem", "visible": True} +settingsContentBaseScrollView_WalletNetworkDelegate = {"container": settingsContentBase_ScrollView, "type": "WalletNetworkDelegate", "unnamed": 1, "visible": True} +settingsContentBaseScrollView_StatusListItem = {"container": settingsContentBase_ScrollView, "type": "StatusListItem", "unnamed": 1, "visible": True} +settings_Wallet_NetworksView_TestNet_Toggle = {"container": statusDesktop_mainWindow, "objectName": "testnetModeSwitch", "type": "StatusSwitch"} +settingsContentBaseScrollView_Goerli_testnet_active_StatusBaseText = {"container": settingsContentBase_ScrollView, "type": "StatusBaseText", "unnamed": 1, "visible": True} +settingsContentBaseScrollView_accountsList_StatusListView = {"container": settingsContentBase_ScrollView, "id": "accountsList", "type": "StatusListView", "unnamed": 1, "visible": True} +settingsContentBaseScrollView_draggableDelegate_StatusDraggableListItem = {"checkable": False, "container": settingsContentBase_ScrollView, "id": "draggableDelegate", "type": "StatusDraggableListItem", "unnamed": 1, "visible": True} +settingsContentBaseScrollView_accountOrderView_AccountOrderView = {"container": settingsContentBase_ScrollView, "id": "accountOrderView", "type": "AccountOrderView", "unnamed": 1, "visible": True} diff --git a/test/e2e/gui/screens/settings.py b/test/e2e/gui/screens/settings.py index a62184c732..640f0cb03a 100644 --- a/test/e2e/gui/screens/settings.py +++ b/test/e2e/gui/screens/settings.py @@ -5,10 +5,11 @@ import allure import configs.timeouts import driver -from constants import UserCommunityInfo +from constants import UserCommunityInfo, wallet_account_list_item from driver import objects_access from driver.objects_access import walk_children from gui.components.settings.send_contact_request_popup import SendContactRequest +from gui.components.wallet.testnet_mode_popup import TestnetModePopup from gui.elements.qt.button import Button from gui.elements.qt.list import List from gui.elements.qt.object import QObject @@ -39,6 +40,11 @@ class LeftPanel(QObject): self._open_settings(12) return CommunitiesSettingsView() + @allure.step('Open wallet settings') + def open_wallet_settings(self): + self._open_settings(4) + return WalletSettingsView() + class SettingsScreen(QObject): @@ -204,3 +210,99 @@ class KeycardSettingsView(QObject): configs.timeouts.UI_LOAD_TIMEOUT_MSEC ), f'Check whats new keycard button not visible' assert driver.waitFor(lambda: self._factory_reset_keycard_button.is_visible, configs.timeouts.UI_LOAD_TIMEOUT_MSEC ), f'Factory reset keycard button not visible' + + +class WalletSettingsView(QObject): + + def __init__(self): + super().__init__('mainWindow_WalletView') + self._wallet_network_button = Button('settings_Wallet_MainView_Networks') + self._account_order_button = Button('settingsContentBaseScrollView_accountOrderItem_StatusListItem') + + @allure.step('Open networks in wallet settings') + def open_networks(self): + self._wallet_network_button.click() + return NetworkWalletSettings().wait_until_appears() + + @allure.step('Open account order in wallet settings') + def open_account_order(self): + self._account_order_button.click() + return EditAccountOrderSettings().wait_until_appears() + + +class NetworkWalletSettings(WalletSettingsView): + + def __init__(self): + super(NetworkWalletSettings, self).__init__() + self._wallet_networks_item = QObject('settingsContentBaseScrollView_WalletNetworkDelegate') + self._testnet_text_item = QObject('settingsContentBaseScrollView_Goerli_testnet_active_StatusBaseText') + self._testnet_mode_button = Button('settings_Wallet_NetworksView_TestNet_Toggle') + + @property + @allure.step('Get wallet networks items') + def networks_names(self) -> typing.List[str]: + return [str(network.title) for network in driver.findAllObjects(self._wallet_networks_item.real_name)] + + @property + @allure.step('Get amount of testnet active items') + def testnet_items_amount(self) -> int: + items_amount = 0 + for item in driver.findAllObjects(self._testnet_text_item.real_name): + if item.text == 'Goerli testnet active': + items_amount += 1 + return items_amount + + @allure.step('Switch testnet mode') + def switch_testnet_mode(self): + self._testnet_mode_button.click() + return TestnetModePopup().wait_until_appears() + + @allure.step('Check state of testnet mode switch') + def get_testnet_mode_button_checked_state(self): + return self._testnet_mode_button.is_checked + + +class EditAccountOrderSettings(WalletSettingsView): + + def __init__(self): + super(EditAccountOrderSettings, self).__init__() + self._account_item = QObject('settingsContentBaseScrollView_draggableDelegate_StatusDraggableListItem') + self._accounts_list = QObject('statusDesktop_mainWindow') + + @property + @allure.step('Get accounts') + def accounts(self) -> typing.List[wallet_account_list_item]: + _accounts = [] + for account_item in driver.findAllObjects(self._account_item.real_name): + element = QObject(name='', real_name=driver.objectMap.realName(account_item)) + name = str(account_item.title) + icon = None + for child in objects_access.walk_children(account_item): + if getattr(child, 'objectName', '') == 'identicon': + icon = Image(driver.objectMap.realName(child)) + break + _accounts.append(wallet_account_list_item(name, icon, element)) + + return sorted(_accounts, key=lambda account: account.object.y) + + @allure.step('Get account in accounts list') + def _get_account_item(self, name: str): + for obj in driver.findAllObjects(self._account_item.real_name): + if getattr(obj, 'title', '') == name: + return obj + raise LookupError(f'Account item: {name} not found') + + @allure.step('Get eye icon on watch-only account') + def get_eye_icon(self, name: str): + for child in objects_access.walk_children(self._get_account_item(name)): + if getattr(child, 'objectName', '') == 'show-icon': + return child + raise LookupError(f'Eye icon not found on {name} account item') + + @allure.step('Drag account to change the order') + def drag_account(self, name: str, index: int): + assert driver.waitFor(lambda: len([account for account in self.accounts if account.name == name]) == 1), \ + 'Account not found or found more then one' + bounds = [account for account in self.accounts if account.name == name][0].object.bounds + d_bounds = self.accounts[index].object.bounds + driver.mouse.press_and_move(self._accounts_list.object, bounds.x, bounds.y, d_bounds.x, d_bounds.y) diff --git a/test/e2e/tests/test_wallet/test_wallet_manage_accounts.py b/test/e2e/tests/test_wallet/test_wallet_manage_accounts.py index b616523b4b..0b6d9b7a88 100644 --- a/test/e2e/tests/test_wallet/test_wallet_manage_accounts.py +++ b/test/e2e/tests/test_wallet/test_wallet_manage_accounts.py @@ -3,13 +3,17 @@ import time import allure import pytest from allure import step -from gui.components.wallet.authenticate_popup import AuthenticatePopup import constants import driver from gui.components.signing_phrase_popup import SigningPhrasePopup +from gui.components.wallet.authenticate_popup import AuthenticatePopup +from gui.components.wallet.testnet_mode_banner import TestnetModeBanner +from gui.components.wallet.wallet_toast_message import WalletToastMessage from gui.main_window import MainWindow from gui.screens.settings import KeycardSettingsView +from scripts.tools import image + pytestmark = allure.suite("Wallet") diff --git a/test/e2e/tests/test_wallet/test_wallet_settings.py b/test/e2e/tests/test_wallet/test_wallet_settings.py new file mode 100644 index 0000000000..a2d813d031 --- /dev/null +++ b/test/e2e/tests/test_wallet/test_wallet_settings.py @@ -0,0 +1,120 @@ +import allure +import pytest +from allure import step + +import configs +import driver +from gui.components.signing_phrase_popup import SigningPhrasePopup +from gui.components.wallet.authenticate_popup import AuthenticatePopup +from gui.components.wallet.testnet_mode_banner import TestnetModeBanner +from gui.components.wallet.wallet_toast_message import WalletToastMessage +from gui.main_window import MainWindow +from scripts.tools import image + + +@allure.testcase('https://ethstatus.testrail.net/index.php?/cases/view/703505', 'Network: Testnet switching') +@pytest.mark.case(703505) +@pytest.mark.parametrize('first_network, second_network, third_network, message_turned_on, message_turned_off', [ + pytest.param('Mainnet', 'Optimism', 'Arbitrum', 'Testnet mode turned on', 'Testnet mode turned off') + ]) +def test_switch_testnet_mode(main_screen: MainWindow, first_network: str, second_network: str, third_network: str, + message_turned_on: str, message_turned_off: str): + with step('Started to turn on Testnet mode but cancel it'): + networks = main_screen.left_panel.open_settings().left_panel.open_wallet_settings().open_networks() + assert networks.get_testnet_mode_button_checked_state() is False + networks.switch_testnet_mode().cancel() + + with step('Verify that Testnet mode not turned on'): + assert networks.get_testnet_mode_button_checked_state() is False + + with step('Turn on Testnet mode'): + networks.switch_testnet_mode().turn_on_testnet_mode() + + with step('Verify that Testnet mode turned on'): + WalletToastMessage().get_toast_message(message_turned_on) + TestnetModeBanner().wait_until_appears() + assert networks.get_testnet_mode_button_checked_state() is True + + with step('Verify that all networks are in the list and text for testnet active is shown on each'): + assert networks.testnet_items_amount == 3 + assert driver.waitFor( + lambda: first_network in networks.networks_names, + configs.timeouts.UI_LOAD_TIMEOUT_MSEC), f'Network: {first_network} not found' + assert driver.waitFor( + lambda: second_network in networks.networks_names, + configs.timeouts.UI_LOAD_TIMEOUT_MSEC), f'Network: {second_network} not found' + assert driver.waitFor( + lambda: third_network in networks.networks_names, + configs.timeouts.UI_LOAD_TIMEOUT_MSEC), f'Network: {third_network} not found' + + with step('Turn off Testnet mode in wallet settings'): + networks.switch_testnet_mode().turn_off_testnet_mode() + + with step('Verify that Testnet mode turned off'): + WalletToastMessage().get_toast_message(message_turned_off) + TestnetModeBanner().wait_until_hidden() + assert networks.get_testnet_mode_button_checked_state() is False + + +@allure.testcase('https://ethstatus.testrail.net/index.php?/cases/view/703415', 'Account order: account order could be changed with drag&drop') +@pytest.mark.case(703415) +@pytest.mark.parametrize('address, default_name, name, color, emoji, second_name, second_color, second_emoji', [ + pytest.param('0xea123F7beFF45E3C9fdF54B324c29DBdA14a639A', 'Status account', + 'WatchOnly', '#2a4af5', 'sunglasses', 'Generated', '#216266', 'thumbsup') + ]) +def test_change_account_order_by_drag_and_drop(main_screen: MainWindow, user_account, address: str, default_name, + name: str, color: str, emoji: str, second_name: str , second_color: str, + second_emoji: str): + with step('Create watch-only wallet account'): + wallet = main_screen.left_panel.open_wallet() + SigningPhrasePopup().wait_until_appears().confirm_phrase() + account_popup = wallet.left_panel.open_add_account_popup() + account_popup.set_name(name).set_emoji(emoji).set_color(color).set_origin_eth_address(address).save() + account_popup.wait_until_hidden() + + with step('Create generated wallet account'): + account_popup = wallet.left_panel.open_add_account_popup() + account_popup.set_name(second_name).set_emoji(second_emoji).set_color(second_color).save() + AuthenticatePopup().wait_until_appears().authenticate(user_account.password) + account_popup.wait_until_hidden() + + with step('Verify accounts in wallet settings'): + account_order = main_screen.left_panel.open_settings().left_panel.open_wallet_settings().open_account_order() + with step('Account order is correct'): + assert account_order.accounts[0].name == default_name + assert account_order.accounts[1].name == name + assert account_order.accounts[2].name == second_name + with step('Eye icon is displayed on watch-only account'): + account_order.get_eye_icon(name) + with step('Icons on accounts are correct'): + image.compare(account_order.accounts[1].icon, 'watch_only_account_icon.png') + image.compare(account_order.accounts[2].icon, 'generated_account_icon.png') + + with step('Drag first account to the end of the list'): + account_order.drag_account(default_name, 2) + + with step('Verify the account order'): + with step('Account order is correct in wallet settings'): + assert driver.waitFor(lambda: account_order.accounts[0].name == name) + assert driver.waitFor(lambda: account_order.accounts[1].name == second_name) + assert driver.waitFor(lambda: account_order.accounts[2].name == default_name) + with step('Account order is correct in wallet'): + wallet = main_screen.left_panel.open_wallet() + assert driver.waitFor(lambda: wallet.left_panel.accounts[0].name == name) + assert driver.waitFor(lambda: wallet.left_panel.accounts[1].name == second_name) + assert driver.waitFor(lambda: wallet.left_panel.accounts[2].name == default_name) + + with step('Drag second account to the top of the list'): + account_order = main_screen.left_panel.open_settings().left_panel.open_wallet_settings().open_account_order() + account_order.drag_account(second_name, 0) + + with step('Verify the account order'): + with step('Account order is correct in wallet settings'): + assert driver.waitFor(lambda: account_order.accounts[0].name == second_name) + assert driver.waitFor(lambda: account_order.accounts[1].name == name) + assert driver.waitFor(lambda: account_order.accounts[2].name == default_name) + with step('Account order is correct in wallet'): + wallet = main_screen.left_panel.open_wallet() + assert driver.waitFor(lambda: wallet.left_panel.accounts[0].name == second_name) + assert driver.waitFor(lambda: wallet.left_panel.accounts[1].name == name) + assert driver.waitFor(lambda: wallet.left_panel.accounts[2].name == default_name)