Update tests and get balance method

Signed-off-by: Serhy <sergii@status.im>
This commit is contained in:
Serhy 2020-12-08 17:56:57 +02:00
parent 57c0e835e2
commit e167773258
No known key found for this signature in database
GPG Key ID: 5D7C4B9E2B6F500B
5 changed files with 24 additions and 21 deletions

View File

@ -55,18 +55,10 @@ class NetworkApi(object):
return not int(requests.request('GET', url=method, headers=self.headers).json()['result']['isError']) return not int(requests.request('GET', url=method, headers=self.headers).json()['result']['isError'])
def get_balance(self, address): def get_balance(self, address):
method = self.network_url + 'module=account&action=balance&address=0x%s&tag=latest&apikey=%s' % (address , self.api_key) address = '0x' + address
for i in range(5): balance = w3.balance_of_address(address)
try: self.log('Balance is %s Gwei' % balance)
self.log('Trying to get balance for %s, attempt %s' % (address, i + 1)) return int(balance)
balance_json = requests.request('GET', method, headers=self.headers).json()
if balance_json:
balance = balance_json["result"]
self.log('Balance is %s Gwei' % balance)
return int(balance)
except JSONDecodeError as e:
self.log(str(e))
time.sleep(5)
def get_latest_block_number(self) -> int: def get_latest_block_number(self) -> int:
method = self.network_url + 'module=proxy&action=eth_blockNumber' method = self.network_url + 'module=proxy&action=eth_blockNumber'

File diff suppressed because one or more lines are too long

View File

@ -118,7 +118,7 @@ class TestWalletManagement(SingleDeviceTestCase):
if wallet.backup_recovery_phrase_warning_text.is_element_present(): if wallet.backup_recovery_phrase_warning_text.is_element_present():
self.driver.fail("'Back up your seed phrase' warning is shown on Wallet while no funds are present") self.driver.fail("'Back up your seed phrase' warning is shown on Wallet while no funds are present")
address = wallet.get_wallet_address() address = wallet.get_wallet_address()
self.network_api.get_donate(address[2:], external_faucet=True, wait_time=60) self.network_api.get_donate(address[2:], external_faucet=True, wait_time=200)
wallet.back_button.click() wallet.back_button.click()
wallet.wait_balance_is_changed() wallet.wait_balance_is_changed()
if not wallet.backup_recovery_phrase_warning_text.is_element_present(30): if not wallet.backup_recovery_phrase_warning_text.is_element_present(30):

View File

@ -120,12 +120,13 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase):
wallet_view.just_fyi("Send transaction to new account") wallet_view.just_fyi("Send transaction to new account")
wallet_view.accounts_status_account.click() wallet_view.accounts_status_account.click()
transaction_amount = '0.05' transaction_amount = '0.002'
initial_balance = self.network_api.get_balance(status_account_address)
send_transaction = wallet_view.send_transaction(account_name=account_name, send_transaction = wallet_view.send_transaction(account_name=account_name,
amount=transaction_amount, amount=transaction_amount,
keycard=True) keycard=True)
self.network_api.wait_for_confirmation_of_transaction(status_account_address, transaction_amount) self.network_api.wait_for_confirmation_of_transaction(status_account_address, transaction_amount)
self.network_api.verify_balance_is_updated('0.1', status_account_address) self.network_api.verify_balance_is_updated(str(initial_balance), status_account_address)
wallet_view.just_fyi("Verifying previously sent transaction in new account") wallet_view.just_fyi("Verifying previously sent transaction in new account")
send_transaction.back_button.click() send_transaction.back_button.click()
@ -161,6 +162,7 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase):
send_transaction.back_button.click() send_transaction.back_button.click()
balance_of_sub_account = float(self.network_api.get_balance(sub_account_address)) / 1000000000000000000 balance_of_sub_account = float(self.network_api.get_balance(sub_account_address)) / 1000000000000000000
balance_of_status_account = float(self.network_api.get_balance(status_account_address)) / 1000000000000000000 balance_of_status_account = float(self.network_api.get_balance(status_account_address)) / 1000000000000000000
wallet_view.scan_tokens()
total_eth_from_two_accounts = float(wallet_view.get_asset_amount_by_name('ETH')) total_eth_from_two_accounts = float(wallet_view.get_asset_amount_by_name('ETH'))
expected_balance = self.network_api.get_rounded_balance(total_eth_from_two_accounts, expected_balance = self.network_api.get_rounded_balance(total_eth_from_two_accounts,
(balance_of_status_account + balance_of_sub_account)) (balance_of_status_account + balance_of_sub_account))

View File

@ -133,7 +133,7 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase):
wallet_view = home_view.wallet_button.click() wallet_view = home_view.wallet_button.click()
wallet_view.set_up_wallet() wallet_view.set_up_wallet()
wallet_view.accounts_status_account.click() wallet_view.accounts_status_account.click()
amount = '0.0%s' % str(random.randint(10000, 99999)) + '1' amount = '0.000%s' % str(random.randint(10000, 99999)) + '1'
wallet_view.send_transaction(amount=amount, wallet_view.send_transaction(amount=amount,
recipient='0x%s' % recipient['address'], recipient='0x%s' % recipient['address'],
asset_name='ADI') asset_name='ADI')
@ -254,12 +254,13 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase):
wallet_view.just_fyi("Send transaction to new account") wallet_view.just_fyi("Send transaction to new account")
wallet_view.accounts_status_account.click() wallet_view.accounts_status_account.click()
initial_balance = self.network_api.get_balance(status_account_address)
transaction_amount = '0.0%s' % str(random.randint(10000, 99999)) + '1' transaction_amount = '0.000%s' % str(random.randint(10000, 99999)) + '1'
wallet_view.send_transaction(account_name=account_name, wallet_view.send_transaction(account_name=account_name,
amount=transaction_amount) amount=transaction_amount)
self.network_api.wait_for_confirmation_of_transaction(status_account_address, transaction_amount) self.network_api.wait_for_confirmation_of_transaction(status_account_address, transaction_amount)
self.network_api.verify_balance_is_updated('0.1', status_account_address) self.network_api.verify_balance_is_updated(str(initial_balance), status_account_address)
wallet_view.just_fyi("Verifying previously sent transaction in new account") wallet_view.just_fyi("Verifying previously sent transaction in new account")
wallet_view.back_button.click() wallet_view.back_button.click()
@ -294,6 +295,7 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase):
send_transaction.back_button.click() send_transaction.back_button.click()
balance_of_sub_account = float(self.network_api.get_balance(sub_account_address)) / 1000000000000000000 balance_of_sub_account = float(self.network_api.get_balance(sub_account_address)) / 1000000000000000000
balance_of_status_account = float(self.network_api.get_balance(status_account_address)) / 1000000000000000000 balance_of_status_account = float(self.network_api.get_balance(status_account_address)) / 1000000000000000000
wallet_view.scan_tokens()
total_eth_from_two_accounts = float(wallet_view.get_asset_amount_by_name('ETH')) total_eth_from_two_accounts = float(wallet_view.get_asset_amount_by_name('ETH'))
expected_balance = self.network_api.get_rounded_balance(total_eth_from_two_accounts, expected_balance = self.network_api.get_rounded_balance(total_eth_from_two_accounts,
(balance_of_status_account + balance_of_sub_account)) (balance_of_status_account + balance_of_sub_account))
@ -466,7 +468,7 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase):
wallet_view.accounts_status_account.scroll_to_element(direction='up') wallet_view.accounts_status_account.scroll_to_element(direction='up')
wallet_view.accounts_status_account.click() wallet_view.accounts_status_account.click()
recipient = "0x" + basic_user['address'] recipient = "0x" + basic_user['address']
amount = '0.0%s' % str(random.randint(10000, 99999)) + '1' amount = '0.000%s' % str(random.randint(10000, 99999)) + '1'
wallet_view.send_transaction(asset_name=symbol, amount=amount, recipient=recipient) wallet_view.send_transaction(asset_name=symbol, amount=amount, recipient=recipient)
# TODO: disabled due to 10838 # TODO: disabled due to 10838
# transactions_view = wallet_view.transaction_history_button.click() # transactions_view = wallet_view.transaction_history_button.click()
@ -606,7 +608,7 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase):
send_transaction.select_asset_button.click_until_presence_of_element(send_transaction.eth_asset_in_select_asset_bottom_sheet_button) send_transaction.select_asset_button.click_until_presence_of_element(send_transaction.eth_asset_in_select_asset_bottom_sheet_button)
adi_button.click() adi_button.click()
send_transaction.amount_edit_box.click() send_transaction.amount_edit_box.click()
amount = '0.0%s' % str(random.randint(100000, 999999)) + '1' amount = '0.000%s' % str(random.randint(100000, 999999)) + '1'
send_transaction.amount_edit_box.set_value(amount) send_transaction.amount_edit_box.set_value(amount)
if not send_transaction.element_by_text(errors['send_transaction_screen']['too_precise']).is_element_displayed(): if not send_transaction.element_by_text(errors['send_transaction_screen']['too_precise']).is_element_displayed():
self.errors.append(warning % (errors['send_transaction_screen']['too_precise'], screen)) self.errors.append(warning % (errors['send_transaction_screen']['too_precise'], screen))