From 9a1f0a337e66b631e66c7bec855b11d594a5f3b0 Mon Sep 17 00:00:00 2001 From: Churikova Tetiana Date: Fri, 23 Sep 2022 10:55:36 +0200 Subject: [PATCH] e2e: web3 --- test/appium/requirements.txt | 15 +- test/appium/support/api/web3_api.py | 224 ++++++++---------- .../appium/tests/medium/test_single_device.py | 14 +- test/appium/views/base_view.py | 4 +- test/appium/views/wallet_view.py | 2 +- 5 files changed, 119 insertions(+), 140 deletions(-) diff --git a/test/appium/requirements.txt b/test/appium/requirements.txt index 32ef62f31e..0008d8f650 100644 --- a/test/appium/requirements.txt +++ b/test/appium/requirements.txt @@ -11,8 +11,6 @@ cytoolz==0.12.0 emoji==0.5.0 eth-hash==0.3.2 eth-keys -eth-utils==1.10.0 -ethereum==2.3.2 execnet==1.7.1 future==0.18.2 flaky==3.7.0 @@ -26,7 +24,7 @@ numpy==1.23.0 pbkdf2==1.3 Pillow==8.1.0 py==1.10.0 -py-ecc==5.1.0 +py-ecc==6.0.0 pycryptodome==3.9.9 pyethash==0.1.27 pyparsing==2.4.7 @@ -39,7 +37,7 @@ pytz==2020.4 PyYAML==5.4 repoze.lru==0.7 requests==2.25.1 -rlp==1.2.0 +rlp==3.0.0 sauceclient==1.0.0 scrypt==0.8.17 selenium==3.14.1 @@ -48,5 +46,10 @@ urllib3==1.26.12 yarl==1.6.3 docker==4.4.0 influxdb==5.3.1 -web3==5.30.0 -imagehash \ No newline at end of file +web3==6.0.0b5 +imagehash +hexbytes==0.2.2 +eth-account==0.7.0 +lru-dict==1.1.7 +websockets==10.3 +websocket-client==1.3.2 \ No newline at end of file diff --git a/test/appium/support/api/web3_api.py b/test/appium/support/api/web3_api.py index 332893ca57..f36f9757b8 100644 --- a/test/appium/support/api/web3_api.py +++ b/test/appium/support/api/web3_api.py @@ -1,128 +1,95 @@ -# NOT USABLE UNTIL web3 upgrade to align with python 3.10 -# from eth_utils import to_checksum_address, is_address -# from web3.auto.infura.goerli import w3 -# from ens import ENS -# -# -# 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": "0x3D6AFAA395C31FCd391fE3D562E75fe9E8ec7E6a"}]} -# -# ACCOUNT_PRIVATE_KEY = '0x5507f8c5c12707770c12fd0fae5d012b947d61f43b9203ae67916e703fd12ad7' -# ACCOUNT_ADDRESS = '0xE2363E6e91d1a29d82C2c695fa8fa2e3Fa5d55eA' -# -# -# class Account(object): -# -# def __init__(self, account_private_key): -# self.pk = account_private_key -# -# @property -# def account_address(self): -# return w3.eth.account.from_key(self.pk).address -# -# @property -# def nonce(self): -# return w3.eth.getTransactionCount(self.account_address) -# -# @property -# def balance(self): -# return w3.eth.getBalance(self.account_address) -# -# def send_eth(self, to_address, eth_value, gas_price_increment=0): -# signed_txn = w3.eth.account.sign_transaction(dict( -# nonce=self.nonce, -# gasPrice=w3.eth.gasPrice + gas_price_increment * 1000000000, -# gas=21000, -# to=to_address, -# value=int(eth_value * 10 ** 18), -# data=b'', -# ), -# self.pk, -# ) -# w3.eth.sendRawTransaction(signed_txn.rawTransaction) -# return w3.toHex(w3.sha3(signed_txn.rawTransaction)) -# -# -# class ContractInteractions(object): -# -# def __init__(self, contract_address, abi): -# self.contract = w3.eth.contract(address=contract_address, abi=abi) -# -# @property -# def decimals(self): -# return self.contract.functions.decimals().call() -# -# def balance_of(self, account_address): -# return self.contract.functions.balanceOf(account_address).call() -# -# def nonce(self, account_address): -# return w3.eth.getTransactionCount(account_address) -# -# def transfer_token_to(self, from_address, to_address, number_of_tokens, nonce, gas_price_increment=0): -# gas_price = w3.eth.gasPrice + gas_price_increment * 1000000000 -# token_value = int(number_of_tokens * 10 ** self.decimals) -# return self.contract.functions.transfer(to_address, token_value, ).buildTransaction({ -# 'from': from_address, -# 'gasPrice': gas_price, -# 'gas': 600000, -# 'nonce': nonce} -# ) -# -# -# 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(hash) -# -# -# def get_tx_param_by_hash(hash: str, param: str): -# return getattr(w3.eth.getTransaction(hash), param) -# -# -# def to_checksumed_address(address): -# return to_checksum_address(address) -# -# -# def current_gas_price(): -# return str(w3.eth.gasPrice / 1000000000) -# -# -# def sign_transaction(tx_data, pk): -# return w3.eth.account.signTransaction(tx_data, pk) -# -# -# def broadcast_signed_tx(signed_txn): -# w3.eth.sendRawTransaction(signed_txn.rawTransaction) -# return w3.toHex(w3.sha3(signed_txn.rawTransaction)) -# -# -# def get_address_from_ens(ens_name, is_stateofus=True): -# # Not working on Goerli -# ns = ENS.fromWeb3(w3) -# ENS.fromWeb3() -# eth_address = ns.address('%s.stateofus.eth' % ens_name) if is_stateofus is True else ns.address(ens_name) -# return eth_address if eth_address else None -# -# -# account = Account(ACCOUNT_PRIVATE_KEY) -# account_address = account.account_address -# -# -# def donate_testnet_eth(address=str(), amount=float(), inscrease_default_gas_price=int()): -# """ -# address: address where to send ETH to -# amount: amount in Ether form -# inscrease_default_gas_price: specify GWEI value (int) if you want to speed up transaction pick up -# """ -# return account.send_eth(address, amount, inscrease_default_gas_price) -# -# +from web3.auto.infura.goerli 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": "0x3D6AFAA395C31FCd391fE3D562E75fe9E8ec7E6a"}]} + +ACCOUNT_PRIVATE_KEY = '0x5507f8c5c12707770c12fd0fae5d012b947d61f43b9203ae67916e703fd12ad7' +ACCOUNT_ADDRESS = '0xE2363E6e91d1a29d82C2c695fa8fa2e3Fa5d55eA' + + +class Account(object): + + def __init__(self, account_private_key): + self.pk = account_private_key + + @property + def account_address(self): + return w3.eth.account.from_key(self.pk).address + + @property + def nonce(self): + return w3.eth.get_transaction_count(self.account_address) + + @property + def balance(self): + return w3.eth.get_balance(self.account_address) + + def send_eth(self, to_address, eth_value, gas_price_increment=0): + signed_txn = w3.eth.account.sign_transaction(dict( + nonce=self.nonce, + gasPrice=w3.eth.gas_price + gas_price_increment * 1000000000, + gas=21000, + to=to_address, + value=int(eth_value * 10 ** 18), + data=b'', + ), + self.pk, + ) + return w3.eth.send_raw_transaction(signed_txn.rawTransaction) + + +class ContractInteractions(object): + + def __init__(self, contract_address, abi): + self.contract = w3.eth.contract(address=contract_address, abi=abi) + + @property + def decimals(self): + return self.contract.functions.decimals().call() + + def balance_of(self, account_address): + return self.contract.functions.balanceOf(account_address).call() + + def nonce(self, account_address): + return w3.eth.get_transaction_count(account_address) + + def transfer_token_to(self, from_address, to_address, number_of_tokens, nonce, gas_price_increment=0): + gas_price = w3.eth.gas_price + gas_price_increment * 1000000000 + token_value = int(number_of_tokens * 10 ** self.decimals) + return self.contract.functions.transfer(to_address, token_value, ).buildTransaction({ + 'from': from_address, + 'gasPrice': gas_price, + 'gas': 600000, + 'nonce': nonce} + ) + + +def transaction_status(hash): + return w3.eth.get_transaction(hash) + + +def current_gas_price(): + return str(w3.eth.gas_price / 1000000000) + + +def sign_transaction(tx_data, pk): + return w3.eth.account.signTransaction(tx_data, pk) + + +account = Account(ACCOUNT_PRIVATE_KEY) +account_address = account.account_address + + +def donate_testnet_eth(address=str(), amount=float(), inscrease_default_gas_price=int()): + """ + address: address where to send ETH to + amount: amount in Ether form + inscrease_default_gas_price: specify GWEI value (int) if you want to speed up transaction pick up + """ + return account.send_eth(address, amount, inscrease_default_gas_price) + + # def donate_testnet_token(token_name=str(), address=str(), amount=float(), inscrease_default_gas_price=int()): # """ # token_name: token 'name' value you want to send taken from token_data @@ -139,3 +106,10 @@ # gas_price_increment=inscrease_default_gas_price) # signed_tx = sign_transaction(tx_data=to_address_data, pk=account.pk) # return broadcast_signed_tx(signed_tx) +# +# def get_tx_param_by_hash(hash: str, param: str): +# return getattr(w3.eth.get_transaction(hash), param) +# +# def broadcast_signed_tx(signed_txn): +# w3.eth.send_raw_transaction(signed_txn.rawTransaction) +# return w3.toHex(w3.sha3(signed_txn.rawTransaction)) \ No newline at end of file diff --git a/test/appium/tests/medium/test_single_device.py b/test/appium/tests/medium/test_single_device.py index 03ce4180bb..a1a4836939 100644 --- a/test/appium/tests/medium/test_single_device.py +++ b/test/appium/tests/medium/test_single_device.py @@ -80,7 +80,8 @@ class TestChatManagement(SingleDeviceTestCase): sign_in = SignInView(self.driver).create_user(keycard=True) wallet = sign_in.wallet_button.click() status_account_address = wallet.get_wallet_address()[2:] - wallet.get_test_assets(keycard=True) + w3.donate_testnet_eth('0x%s' % status_account_address, 0.05) + wallet.wallet_button.double_click() account_name = 'subaccount' wallet.add_account(account_name, keycard=True) wallet.get_account_by_name(account_name).click() @@ -472,11 +473,11 @@ class TestChatManagement(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() - wallet.close_button.click() - wallet.get_test_assets() + self.click = wallet.close_button.click() + w3.donate_testnet_eth(address, 0.0001) + wallet.wait_balance_is_changed() if not wallet.backup_recovery_phrase_warning_text.is_element_present(30): self.driver.fail("'Back up your seed phrase' warning is not shown on Wallet with funds") - wallet.donate_leftovers() profile = wallet.get_profile_view() wallet.backup_recovery_phrase_warning_text.click() profile.backup_recovery_phrase() @@ -1064,10 +1065,11 @@ class TestChatManagement(SingleDeviceTestCase): self.ens_name = 'purchased%s' % self.home.get_random_chat_name() self.wallet = self.home.wallet_button.click() self.address = self.wallet.get_wallet_address() + w3.donate_testnet_eth(self.address, 0.1) + self.wallet.wait_balance_is_changed() self.chat_key = self.home.get_public_key_and_username() - self.wallet.just_fyi("Get required donate") - self.wallet.get_test_assets() + self.wallet.just_fyi("Get required STT") self.wallet.get_test_assets(token=True) self.wallet.just_fyi("Purchase ENS") diff --git a/test/appium/views/base_view.py b/test/appium/views/base_view.py index 70d7896f62..6eb61fe8cb 100644 --- a/test/appium/views/base_view.py +++ b/test/appium/views/base_view.py @@ -353,8 +353,8 @@ class BaseView(object): if element == 'home': element = self.home_button while not element.is_element_present(1) and counter <= attempts: + self.driver.press_keycode(4) try: - self.driver.press_keycode(4) element.is_element_present(5) return self except (NoSuchElementException, TimeoutException): @@ -713,7 +713,7 @@ class BaseView(object): send_transaction.set_max_button.click() send_transaction.confirm() send_transaction.chose_recipient_button.click() - send_transaction.set_recipient_address('0x2127edab5d08b1e11adf7ae4bae16c2b33fdf74a') + send_transaction.set_recipient_address('0xE2363E6e91d1a29d82C2c695fa8fa2e3Fa5d55eA') send_transaction.sign_transaction_button.click() send_transaction.sign_transaction(keycard=keycard) diff --git a/test/appium/views/wallet_view.py b/test/appium/views/wallet_view.py index 6a976ed1fe..6a050d6739 100644 --- a/test/appium/views/wallet_view.py +++ b/test/appium/views/wallet_view.py @@ -175,7 +175,7 @@ class WalletView(BaseView): self.accounts_status_account.scroll_to_element(direction='up') return - def wait_balance_is_changed(self, asset='ETH', initial_balance=0, wait_time=120, scan_tokens=False, navigate_to_home=True): + def wait_balance_is_changed(self, asset='ETH', initial_balance=0, wait_time=180, scan_tokens=False, navigate_to_home=True): self.driver.info('Waiting %ss for %s updated balance' % (wait_time, asset)) counter = 0 while True: