From e167773258969e874422a92ee856c37a50d6ced8 Mon Sep 17 00:00:00 2001 From: Serhy Date: Tue, 8 Dec 2020 17:56:57 +0200 Subject: [PATCH] Update tests and get balance method Signed-off-by: Serhy --- test/appium/support/api/network_api.py | 16 ++++------------ test/appium/support/api/web3_api.py | 9 ++++++++- .../account_management/test_wallet_management.py | 2 +- .../atomic/transactions/test_keycard_wallet.py | 6 ++++-- .../tests/atomic/transactions/test_wallet.py | 12 +++++++----- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/test/appium/support/api/network_api.py b/test/appium/support/api/network_api.py index 36dc0ecde8..34fb0a2bad 100644 --- a/test/appium/support/api/network_api.py +++ b/test/appium/support/api/network_api.py @@ -55,18 +55,10 @@ class NetworkApi(object): return not int(requests.request('GET', url=method, headers=self.headers).json()['result']['isError']) def get_balance(self, address): - method = self.network_url + 'module=account&action=balance&address=0x%s&tag=latest&apikey=%s' % (address , self.api_key) - for i in range(5): - try: - self.log('Trying to get balance for %s, attempt %s' % (address, i + 1)) - 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) + address = '0x' + address + balance = w3.balance_of_address(address) + self.log('Balance is %s Gwei' % balance) + return int(balance) def get_latest_block_number(self) -> int: method = self.network_url + 'module=proxy&action=eth_blockNumber' diff --git a/test/appium/support/api/web3_api.py b/test/appium/support/api/web3_api.py index 1f98466a4a..63986f298f 100644 --- a/test/appium/support/api/web3_api.py +++ b/test/appium/support/api/web3_api.py @@ -1,6 +1,7 @@ -from eth_utils import to_checksum_address +from eth_utils import to_checksum_address, is_address from web3.auto.infura.ropsten import w3 + token_data = {"STT": [{ "abi": '[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_amount","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"creationBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_newController","type":"address"}],"name":"changeController","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_blockNumber","type":"uint256"}],"name":"balanceOfAt","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"version","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_cloneTokenName","type":"string"},{"name":"_cloneDecimalUnits","type":"uint8"},{"name":"_cloneTokenSymbol","type":"string"},{"name":"_snapshotBlock","type":"uint256"},{"name":"_transfersEnabled","type":"bool"}],"name":"createCloneToken","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"parentToken","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_owner","type":"address"},{"name":"_amount","type":"uint256"}],"name":"generateTokens","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_blockNumber","type":"uint256"}],"name":"totalSupplyAt","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"transfersEnabled","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"parentSnapShotBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_amount","type":"uint256"},{"name":"_extraData","type":"bytes"}],"name":"approveAndCall","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_owner","type":"address"},{"name":"_amount","type":"uint256"}],"name":"destroyTokens","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"claimTokens","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"tokenFactory","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_transfersEnabled","type":"bool"}],"name":"enableTransfers","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"controller","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"inputs":[{"name":"_tokenFactory","type":"address"}],"payable":false,"type":"constructor"},{"payable":true,"type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_token","type":"address"},{"indexed":true,"name":"_controller","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"ClaimedTokens","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_cloneToken","type":"address"},{"indexed":false,"name":"_snapshotBlock","type":"uint256"}],"name":"NewCloneToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_spender","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"Approval","type":"event"}]', "address": "0xc55cF4B03948D7EBc8b9E8BAD92643703811d162"}]} @@ -66,6 +67,12 @@ class ContractInteractions(object): ) +def balance_of_address(address): + if not is_address(address): + return ("Invalid address provided") + else: + return w3.eth.getBalance(to_checksum_address(address)) + def transaction_status(hash): return w3.eth.getTransaction(transaction_hash=hash) diff --git a/test/appium/tests/atomic/account_management/test_wallet_management.py b/test/appium/tests/atomic/account_management/test_wallet_management.py index 566daee195..a05e26d12a 100644 --- a/test/appium/tests/atomic/account_management/test_wallet_management.py +++ b/test/appium/tests/atomic/account_management/test_wallet_management.py @@ -118,7 +118,7 @@ class TestWalletManagement(SingleDeviceTestCase): 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") 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.wait_balance_is_changed() if not wallet.backup_recovery_phrase_warning_text.is_element_present(30): diff --git a/test/appium/tests/atomic/transactions/test_keycard_wallet.py b/test/appium/tests/atomic/transactions/test_keycard_wallet.py index 7ac51f3837..f3b7fdcd34 100644 --- a/test/appium/tests/atomic/transactions/test_keycard_wallet.py +++ b/test/appium/tests/atomic/transactions/test_keycard_wallet.py @@ -120,12 +120,13 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase): wallet_view.just_fyi("Send transaction to new account") 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, amount=transaction_amount, keycard=True) 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") send_transaction.back_button.click() @@ -161,6 +162,7 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase): send_transaction.back_button.click() 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 + wallet_view.scan_tokens() 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, (balance_of_status_account + balance_of_sub_account)) diff --git a/test/appium/tests/atomic/transactions/test_wallet.py b/test/appium/tests/atomic/transactions/test_wallet.py index 5530f48a04..58ad897767 100644 --- a/test/appium/tests/atomic/transactions/test_wallet.py +++ b/test/appium/tests/atomic/transactions/test_wallet.py @@ -133,7 +133,7 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase): wallet_view = home_view.wallet_button.click() wallet_view.set_up_wallet() 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, recipient='0x%s' % recipient['address'], asset_name='ADI') @@ -254,12 +254,13 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase): wallet_view.just_fyi("Send transaction to new account") 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, amount=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.back_button.click() @@ -294,6 +295,7 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase): send_transaction.back_button.click() 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 + wallet_view.scan_tokens() 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, (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.click() 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) # TODO: disabled due to 10838 # 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) adi_button.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) 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))