2023-11-02 13:51:38 +00:00
|
|
|
import time
|
|
|
|
import typing
|
|
|
|
|
|
|
|
import allure
|
|
|
|
|
2023-11-10 11:34:49 +00:00
|
|
|
import configs
|
2023-11-02 13:51:38 +00:00
|
|
|
import driver
|
2023-11-16 10:48:04 +00:00
|
|
|
from constants import wallet_account_list_item
|
2023-11-02 13:51:38 +00:00
|
|
|
from gui.components.base_popup import BasePopup
|
2023-11-16 10:48:04 +00:00
|
|
|
from gui.components.emoji_popup import EmojiPopup
|
2023-11-02 13:51:38 +00:00
|
|
|
from gui.elements.button import Button
|
2023-11-15 16:28:11 +00:00
|
|
|
from gui.elements.check_box import CheckBox
|
2023-11-02 13:51:38 +00:00
|
|
|
from gui.elements.object import QObject
|
2023-11-08 14:33:16 +00:00
|
|
|
from gui.elements.text_edit import TextEdit
|
2023-11-02 13:51:38 +00:00
|
|
|
from gui.elements.text_label import TextLabel
|
2024-02-13 09:04:24 +00:00
|
|
|
from gui.objects_map import names
|
2023-11-02 13:51:38 +00:00
|
|
|
|
|
|
|
|
2023-11-08 14:33:16 +00:00
|
|
|
class KeycardPopup(BasePopup):
|
2023-11-02 13:51:38 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
2024-02-13 09:04:24 +00:00
|
|
|
self._keycard_image = QObject(names.img_Image)
|
|
|
|
self._keycard_popup_header = TextLabel(names.headerTitle)
|
|
|
|
self._keycard_instruction_text = TextLabel(names.keycard_reader_instruction_text)
|
|
|
|
self._next_button = Button(names.nextStatusButton)
|
|
|
|
self._reveal_seed_phrase_button = Button(names.revealSeedPhraseButton)
|
|
|
|
self._seed_phrase_panel = QObject(names.seedPhraseWordAtIndex_Placeholder)
|
|
|
|
self._seed_phrase_first_word_component = QObject(names.word0_StatusInput)
|
|
|
|
self._seed_phrase_second_word_component = QObject(names.word1_StatusInput)
|
|
|
|
self._seed_phrase_third_word_component = QObject(names.word2_StatusInput)
|
|
|
|
self._seed_phrase_word_text_edit = TextEdit(names.statusSeedPhraseInputField_TextEdit)
|
|
|
|
self._seed_phrase_12_words_button = Button(names.switchTabBar_12_words_StatusSwitchTabButton)
|
|
|
|
self._seed_phrase_18_words_button = Button(names.switchTabBar_18_words_StatusSwitchTabButton)
|
|
|
|
self._seed_phrase_24_words_button = Button(names.switchTabBar_24_words_StatusSwitchTabButton)
|
|
|
|
self._field_object = QObject(names.edit_TextEdit)
|
|
|
|
self._keypair_item = QObject(names.o_KeyPairItem)
|
|
|
|
self._keypair_on_keycard_item = QObject(names.o_KeyPairUnknownItem)
|
|
|
|
self._keypair_tag = QObject(names.o_StatusListItemTag)
|
|
|
|
self._selection_box = QObject(names.radioButton_StatusRadioButton)
|
|
|
|
self._keycard_init = QObject(names.o_KeycardInit)
|
|
|
|
self._cancel_button = Button(names.cancel_StatusButton)
|
2023-11-15 16:28:11 +00:00
|
|
|
self._understand_keypair_deleted_checkbox = CheckBox(
|
2024-02-13 09:04:24 +00:00
|
|
|
names.i_understand_the_key_pair_on_this_Keycard_will_be_deleted_StatusCheckBox)
|
|
|
|
self._emoji_button = QObject(names.statusSmartIdenticonLetter_StatusLetterIdenticon)
|
|
|
|
self._secondary_button = Button(names.secondary_StatusButton)
|
|
|
|
self._color_radiobutton = QObject(names.color_StatusColorRadioButton)
|
2023-11-02 13:51:38 +00:00
|
|
|
|
|
|
|
@property
|
2023-11-13 10:46:48 +00:00
|
|
|
@allure.step('Get keycard image source path')
|
|
|
|
def keycard_image_source_path(self) -> str:
|
|
|
|
return str(self._keycard_image.object.source.path)
|
2023-11-02 13:51:38 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@allure.step('Get keycard popup header')
|
|
|
|
def keycard_header(self) -> str:
|
2024-07-19 06:43:44 +00:00
|
|
|
return str(self._keycard_popup_header.text)
|
2023-11-02 13:51:38 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@allure.step('Get keycard instructions')
|
|
|
|
def keycard_instructions(self) -> typing.List[str]:
|
|
|
|
return [str(getattr(instruction, 'text', '')) for instruction in
|
|
|
|
driver.findAllObjects(self._keycard_instruction_text.real_name)]
|
|
|
|
|
|
|
|
@property
|
|
|
|
@allure.step('Get all text fields')
|
|
|
|
def get_text_fields(self) -> typing.List[str]:
|
|
|
|
return driver.findAllObjects(self._field_object.real_name)
|
|
|
|
|
|
|
|
@property
|
|
|
|
@allure.step('Get seed phrases list')
|
|
|
|
def get_seed_phrases(self) -> typing.List[str]:
|
|
|
|
phrases = []
|
|
|
|
for phrase_n in range(1, 13):
|
|
|
|
object_name = f'SeedPhraseWordAtIndex-{phrase_n}'
|
|
|
|
self._seed_phrase_panel.real_name['objectName'] = object_name
|
|
|
|
phrases.append(str(self._seed_phrase_panel.object.textEdit.input.edit.text))
|
|
|
|
return phrases
|
|
|
|
|
|
|
|
@property
|
2023-11-10 11:34:49 +00:00
|
|
|
@allure.step('Get keycard name in keypair')
|
|
|
|
def keypair_name(self) -> str:
|
2023-11-02 13:51:38 +00:00
|
|
|
return self._keypair_item.object.title
|
|
|
|
|
2023-11-16 10:48:04 +00:00
|
|
|
@property
|
|
|
|
@allure.step('Get accounts on keycard')
|
|
|
|
def account_tags(self) -> typing.List[wallet_account_list_item]:
|
|
|
|
_account_tags = []
|
|
|
|
for account_tag_item in driver.findAllObjects(self._keypair_tag.real_name):
|
2024-02-13 09:04:24 +00:00
|
|
|
element = QObject(real_name=driver.objectMap.realName(account_tag_item))
|
2023-11-16 10:48:04 +00:00
|
|
|
name = str(account_tag_item.title)
|
|
|
|
icon_emoji = str(account_tag_item.asset.emoji)
|
|
|
|
icon_color = str(account_tag_item.bgColor.name)
|
|
|
|
_account_tags.append(wallet_account_list_item(name, icon_color, icon_emoji, element))
|
|
|
|
return sorted(_account_tags, key=lambda account: account.object.x)
|
|
|
|
|
2023-11-02 13:51:38 +00:00
|
|
|
@property
|
2023-11-10 11:34:49 +00:00
|
|
|
@allure.step('Get info title in keypair')
|
|
|
|
def keypair_info_title(self) -> str:
|
|
|
|
return self._keypair_item.object.beneathTagsTitle
|
|
|
|
|
|
|
|
@property
|
|
|
|
@allure.step('Get account name in keypair')
|
|
|
|
def keypair_account_name(self) -> str:
|
2024-07-19 06:43:44 +00:00
|
|
|
return str(self._keypair_tag.object.title)
|
2023-11-02 13:51:38 +00:00
|
|
|
|
|
|
|
@property
|
2023-11-10 11:34:49 +00:00
|
|
|
@allure.step('Get account color in keypair')
|
|
|
|
def keypair_account_color(self) -> str:
|
|
|
|
return str(self._keypair_tag.object.bgColor.name)
|
|
|
|
|
|
|
|
@property
|
2023-11-16 10:48:04 +00:00
|
|
|
@allure.step('Get account emoji in keypair')
|
|
|
|
def keypair_account_emoji(self) -> str:
|
|
|
|
return str(self._keypair_tag.object.asset.emoji)
|
2023-11-10 11:34:49 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@allure.step('Get selection box "checked" state')
|
|
|
|
def is_keypair_selection_box_checked(self) -> bool:
|
|
|
|
return self._selection_box.object.checked
|
|
|
|
|
2023-11-10 15:30:47 +00:00
|
|
|
@property
|
|
|
|
@allure.step('Get keycard name in accounts on keycard section')
|
|
|
|
def keypair_on_keycard_name(self) -> str:
|
|
|
|
return str(self._keypair_on_keycard_item.object.keyPairName)
|
|
|
|
|
2023-11-10 11:34:49 +00:00
|
|
|
@property
|
|
|
|
@allure.step('Get next button "enabled" state')
|
|
|
|
def is_next_button_enabled(self) -> bool:
|
|
|
|
return driver.waitForObjectExists(self._next_button.real_name, configs.timeouts.UI_LOAD_TIMEOUT_MSEC).enabled
|
|
|
|
|
|
|
|
@allure.step('Click selection box on profile keypair')
|
|
|
|
def click_selection_box_on_keypair(self):
|
|
|
|
self._selection_box.click()
|
|
|
|
return self
|
2023-11-02 13:51:38 +00:00
|
|
|
|
|
|
|
@allure.step('Set pin')
|
2023-11-17 14:54:57 +00:00
|
|
|
def input_pin_or_puk(self, pin):
|
2024-07-19 06:43:44 +00:00
|
|
|
for i in range(7):
|
|
|
|
driver.nativeType(pin)
|
2023-11-02 13:51:38 +00:00
|
|
|
|
|
|
|
@allure.step('Click Next button')
|
|
|
|
def click_next(self):
|
|
|
|
self._next_button.click()
|
|
|
|
time.sleep(1)
|
|
|
|
return self
|
|
|
|
|
|
|
|
@allure.step('Click reveal seed phrase button')
|
|
|
|
def reveal_seed_phrase(self):
|
|
|
|
self._reveal_seed_phrase_button.click()
|
|
|
|
return self
|
|
|
|
|
|
|
|
@allure.step('Confirm first word in seed phrase')
|
|
|
|
def confirm_first_word(self, seed_phrase: typing.List[str]):
|
|
|
|
word_index = int(str(self._seed_phrase_first_word_component.object.label).split('Word #')[1])
|
|
|
|
seed_word = seed_phrase[word_index - 1]
|
|
|
|
driver.type(self.get_text_fields[0], seed_word)
|
|
|
|
return self
|
|
|
|
|
|
|
|
@allure.step('Confirm second word in seed phrase')
|
|
|
|
def confirm_second_word(self, seed_phrase: typing.List[str]):
|
|
|
|
word_index = int(str(self._seed_phrase_second_word_component.object.label).split('Word #')[1])
|
|
|
|
seed_word = seed_phrase[word_index - 1]
|
|
|
|
driver.type(self.get_text_fields[1], seed_word)
|
|
|
|
return self
|
|
|
|
|
|
|
|
@allure.step('Confirm third word in seed phrase')
|
|
|
|
def confirm_third_word(self, seed_phrase: typing.List[str]):
|
|
|
|
word_index = int(str(self._seed_phrase_third_word_component.object.label).split('Word #')[1])
|
|
|
|
seed_word = seed_phrase[word_index - 1]
|
|
|
|
driver.type(self.get_text_fields[2], seed_word)
|
|
|
|
return self
|
|
|
|
|
|
|
|
@allure.step('Name keycard')
|
|
|
|
def name_keycard(self, name: str):
|
|
|
|
driver.type(self.get_text_fields[0], name)
|
2023-11-16 10:48:04 +00:00
|
|
|
self.click_next()
|
|
|
|
return self
|
|
|
|
|
|
|
|
@allure.step('Add another account')
|
|
|
|
def add_account(self):
|
2023-11-17 14:54:57 +00:00
|
|
|
self._secondary_button.click()
|
2023-11-10 11:34:49 +00:00
|
|
|
return self
|
2023-11-02 13:51:38 +00:00
|
|
|
|
|
|
|
@allure.step('Name account')
|
|
|
|
def name_account(self, name: str):
|
|
|
|
driver.type(self.get_text_fields[0], name)
|
2023-11-10 11:34:49 +00:00
|
|
|
return self
|
2023-11-02 13:51:38 +00:00
|
|
|
|
2023-11-16 10:48:04 +00:00
|
|
|
@allure.step('Set emoji for account')
|
|
|
|
def set_emoji(self, value: str):
|
|
|
|
self._emoji_button.click()
|
|
|
|
EmojiPopup().wait_until_appears().select(value)
|
|
|
|
return self
|
|
|
|
|
|
|
|
@allure.step('Set color for account')
|
|
|
|
def set_color(self, value: str):
|
|
|
|
if 'radioButtonColor' in self._color_radiobutton.real_name.keys():
|
|
|
|
del self._color_radiobutton.real_name['radioButtonColor']
|
|
|
|
colors = [str(item.radioButtonColor) for item in driver.findAllObjects(self._color_radiobutton.real_name)]
|
|
|
|
assert value in colors, f'Color {value} not found in {colors}'
|
|
|
|
self._color_radiobutton.real_name['radioButtonColor'] = value
|
|
|
|
self._color_radiobutton.click()
|
|
|
|
return self
|
|
|
|
|
2023-11-02 13:51:38 +00:00
|
|
|
@allure.step('Create keycard account with seed phrase')
|
|
|
|
def create_keycard_account_with_seed_phrase(self, keycard_name: str, account_name: str):
|
2023-11-16 10:48:04 +00:00
|
|
|
self.confirm_seed_phrase()
|
|
|
|
self.name_keycard(keycard_name)
|
|
|
|
self.name_account(account_name).click_next()
|
2023-11-10 11:34:49 +00:00
|
|
|
|
2023-11-16 10:48:04 +00:00
|
|
|
@allure.step('Confirm seed phrase')
|
|
|
|
def confirm_seed_phrase(self):
|
2023-11-02 13:51:38 +00:00
|
|
|
time.sleep(1)
|
|
|
|
self.click_next().reveal_seed_phrase()
|
|
|
|
seed_phrases = self.get_seed_phrases
|
|
|
|
self.click_next()
|
|
|
|
self.confirm_first_word(seed_phrases).confirm_second_word(seed_phrases).confirm_third_word(seed_phrases)
|
|
|
|
self.click_next()
|
2023-11-16 10:48:04 +00:00
|
|
|
return self
|
2023-11-08 14:33:16 +00:00
|
|
|
|
2023-11-10 11:34:49 +00:00
|
|
|
@allure.step('Name keycard and account')
|
|
|
|
def name_keycard_and_account(self, keycard_name, account_name):
|
2023-11-17 14:54:44 +00:00
|
|
|
self.name_keycard(keycard_name)
|
2023-11-10 11:34:49 +00:00
|
|
|
self.name_account(account_name).click_next()
|
|
|
|
|
2023-11-08 14:33:16 +00:00
|
|
|
@allure.step('Import keycard via seed phrase')
|
|
|
|
def import_keycard_via_seed_phrase(self, seed_phrase_words: list, pin: str, keycard_name: str, account_name: str):
|
2023-11-10 11:34:49 +00:00
|
|
|
self.input_seed_phrase(seed_phrase_words)
|
2023-11-17 14:54:57 +00:00
|
|
|
self.input_pin_or_puk(pin)
|
|
|
|
self.input_pin_or_puk(pin)
|
2023-11-10 11:34:49 +00:00
|
|
|
self.click_next()
|
2023-11-13 10:46:48 +00:00
|
|
|
self.name_keycard_and_account(keycard_name, account_name)
|
2023-11-10 11:34:49 +00:00
|
|
|
|
2023-11-10 15:30:47 +00:00
|
|
|
@allure.step('Input seed phrase')
|
2023-11-10 11:34:49 +00:00
|
|
|
def input_seed_phrase(self, seed_phrase_words: list):
|
2023-11-08 14:33:16 +00:00
|
|
|
if len(seed_phrase_words) == 12:
|
|
|
|
self._seed_phrase_12_words_button.click()
|
|
|
|
elif len(seed_phrase_words) == 18:
|
|
|
|
self._seed_phrase_18_words_button.click()
|
|
|
|
elif len(seed_phrase_words) == 24:
|
|
|
|
self._seed_phrase_24_words_button.click()
|
|
|
|
else:
|
|
|
|
raise RuntimeError("Wrong amount of seed words", len(seed_phrase_words))
|
|
|
|
for count, word in enumerate(seed_phrase_words, start=1):
|
2024-07-19 06:43:44 +00:00
|
|
|
self._seed_phrase_word_text_edit.real_name['objectName'] = f'enterSeedPhraseInputField{count}'
|
2023-11-08 14:33:16 +00:00
|
|
|
self._seed_phrase_word_text_edit.text = word
|
|
|
|
self.click_next()
|
2023-11-10 15:30:47 +00:00
|
|
|
|
|
|
|
@allure.step('Click cancel button')
|
|
|
|
def cancel(self):
|
|
|
|
self._cancel_button.click()
|
2023-11-15 16:28:11 +00:00
|
|
|
|
|
|
|
@allure.step('Confirm that understand that keypair will be deleted in checkbox')
|
|
|
|
def confirm_keypair_will_be_deleted(self, value: bool):
|
|
|
|
self._understand_keypair_deleted_checkbox.set(value)
|
2023-11-17 14:54:57 +00:00
|
|
|
|
|
|
|
@allure.step('Click Unlock using PUK')
|
|
|
|
def click_unlock_puk(self):
|
|
|
|
self._secondary_button.click()
|
|
|
|
return self
|