From 7cc3ea2af427d4e89bf9bd8107689996c27e761d Mon Sep 17 00:00:00 2001 From: Churikova Tetiana Date: Thu, 8 Sep 2022 16:27:38 +0200 Subject: [PATCH] e2e: remove web3 dependencies --- test/appium/requirements.txt | 2 +- test/appium/support/api/network_api.py | 152 +++++----- test/appium/support/api/web3_api.py | 281 +++++++++--------- test/appium/tests/conftest.py | 12 +- test/appium/tests/medium/test_chats_m.py | 1 + .../appium/tests/medium/test_single_device.py | 29 +- test/appium/views/base_view.py | 32 ++ .../views/web_views/status_test_dapp.py | 14 +- 8 files changed, 267 insertions(+), 256 deletions(-) diff --git a/test/appium/requirements.txt b/test/appium/requirements.txt index 431f06cf7f..32ef62f31e 100644 --- a/test/appium/requirements.txt +++ b/test/appium/requirements.txt @@ -44,7 +44,7 @@ sauceclient==1.0.0 scrypt==0.8.17 selenium==3.14.1 six==1.16.0 -urllib3==1.26.3 +urllib3==1.26.12 yarl==1.6.3 docker==4.4.0 influxdb==5.3.1 diff --git a/test/appium/support/api/network_api.py b/test/appium/support/api/network_api.py index 3ec988c8cb..ee68f48a29 100644 --- a/test/appium/support/api/network_api.py +++ b/test/appium/support/api/network_api.py @@ -7,19 +7,12 @@ import time from json import JSONDecodeError from decimal import Decimal from os import environ -from web3.exceptions import TransactionNotFound import tests -import support.api.web3_api as w3 - class NetworkApi(object): - def __init__(self): - # self.network_url = 'http://api-ropsten.etherscan.io/api?' self.network_url = 'http://api-goerli.etherscan.io/api?' - self.faucet_url = 'https://faucet-ropsten.status.im/donate' - self.faucet_backup_address = w3.account_address self.headers = { 'User-Agent':"Mozilla\\5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit\\537.36 (KHTML, like Gecko) Chrome\\7" "7.0.3865.90 Safari\\537.36", } @@ -30,27 +23,12 @@ class NetworkApi(object): tests.test_suite_data.current_test.testruns[-1].steps.append(text) logging.info(text) - def get_transactions(self, address: str) -> List[dict]: - method = self.network_url + 'module=account&action=txlist&address=0x%s&sort=desc&apikey=%s' % (address, self.api_key) + def send_etherscan_request(self, method, extracted_param: str): for attempt in range(3): try: - transactions_response = requests.request('GET', url=method, headers=self.headers).json() - if transactions_response: - return transactions_response['result'] - except TypeError as e: - self.log("Check response from etherscan API. Returned values do not match expected. %s" % e) - except JSONDecodeError as e: - self.log("No valid JSON response from Etherscan: %s " % str(e)) - pass - time.sleep(30) - - def get_token_transactions(self, address: str) -> List[dict]: - method = self.network_url + 'module=account&action=tokentx&address=0x%s&sort=desc&apikey=%s' % (address, self.api_key) - for attempt in range(3): - try: - transactions_response = requests.request('GET', url=method, headers=self.headers).json() - if transactions_response: - return transactions_response['result'] + response = requests.request('GET', url=method, headers=self.headers).json() + if response: + return response[extracted_param] except TypeError as e: self.log("Check response from etherscan API. Returned values do not match expected. %s" % str(e)) except JSONDecodeError as e: @@ -58,15 +36,29 @@ class NetworkApi(object): pass time.sleep(30) + def get_token_transactions(self, address: str) -> List[dict]: + method = self.network_url + 'module=account&action=tokentx&address=0x%s&sort=desc&apikey=%s' % ( + address, self.api_key) + return self.send_etherscan_request(method, 'result') + + def get_transactions(self, address: str) -> List[dict]: + method = self.network_url + 'module=account&action=txlist&address=0x%s&sort=desc&apikey=%s' % (address, self.api_key) + return self.send_etherscan_request(method, 'result') + def is_transaction_successful(self, transaction_hash: str) -> int: method = self.network_url + 'module=transaction&action=getstatus&txhash=%s' % transaction_hash return not int(requests.request('GET', url=method, headers=self.headers).json()['result']['isError']) def get_balance(self, address): address = '0x' + address - balance = w3.balance_of_address(address) - self.log('Balance is %s Gwei' % balance) - return int(balance) + method = self.network_url + 'module=account&action=balance&address=%s&tag=latest&apikey=%s' % ( + address, self.api_key) + balance = self.send_etherscan_request(method, 'result') + if balance: + self.log('Balance is %s Gwei' % balance) + return int(balance) + else: + self.log('Cannot extract balance!') def get_latest_block_number(self) -> int: method = self.network_url + 'module=proxy&action=eth_blockNumber' @@ -75,22 +67,18 @@ class NetworkApi(object): def find_transaction_by_hash(self, transaction_hash: str): method = self.network_url + 'module=transaction&action=gettxreceiptstatus&txhash=%s&apikey=%s' % ( transaction_hash, self.api_key) - try: - transactions_response = requests.request('GET', url=method, headers=self.headers).json() - if transactions_response: - result = True - if transactions_response['result']['status'] == '1': - self.log("TX %s is found and confirmed: " % transaction_hash) - elif transactions_response['result']['status'] == '0': - self.log("TX %s is found and failed: " % transaction_hash) - else: - result = False - self.log("TX %s is not found!" % transaction_hash) - return result - except TypeError as e: - self.log("Check response from etherscan API. Returned values do not match expected. %s" % str(e)) - except JSONDecodeError as e: - self.log("No valid JSON response from Etherscan: %s " % str(e)) + result = self.send_etherscan_request(method, 'result') + + if result: + final_status = True + if result['status'] == '1': + self.log("TX %s is found and confirmed" % transaction_hash) + elif result['status'] == '0': + self.log("TX %s is found and failed: " % transaction_hash) + else: + final_status = False + self.log("TX %s is not found!" % transaction_hash) + return final_status def find_transaction_by_unique_amount(self, address, amount, token=False, decimals=18, wait_time=300): additional_info = 'token transactions' if token else 'ETH transactions' @@ -158,37 +146,39 @@ class NetworkApi(object): if balance / 1000000000000000000 != expected_balance: errors.append('Recipients balance is not updated on etherscan') - def faucet(self, address): - try: - self.log("Trying to get funds from %s" % self.faucet_url) - return requests.request('GET', '%s/0x%s' % (self.faucet_url, address)).json() - except JSONDecodeError as e: - self.log("No valid JSON response from Etherscan: %s " % str(e)) - pass + # Do not use until web3 update + # def faucet(self, address): + # try: + # self.log("Trying to get funds from %s" % self.faucet_url) + # return requests.request('GET', '%s/0x%s' % (self.faucet_url, address)).json() + # except JSONDecodeError as e: + # self.log("No valid JSON response from Etherscan: %s " % str(e)) + # pass - def faucet_backup(self, address): - self.log("Trying to get funds from %s" % self.faucet_backup_address) - address = "0x" + address - w3.donate_testnet_eth(address=address, amount=0.01, inscrease_default_gas_price=10) + # def faucet_backup(self, address): + # self.log("Trying to get funds from %s" % self.faucet_backup_address) + # address = "0x" + address + # w3.donate_testnet_eth(address=address, amount=0.01, inscrease_default_gas_price=10) - def get_donate(self, address, external_faucet=False, wait_time=300): - initial_balance = self.get_balance(address) - counter = 0 - if initial_balance < 1000000000000000000: - if external_faucet: - self.faucet_backup(address) - else: - self.faucet(address) - while True: - if counter >= wait_time: - pytest.fail("Donation was not received during %s seconds!" % wait_time) - elif self.get_balance(address) == initial_balance: - counter += 10 - time.sleep(10) - self.log('Waiting %s seconds for donation' % counter) - else: - self.log('Got %s Gwei for %s' % (self.get_balance(address), address)) - return + + # def get_donate(self, address, external_faucet=False, wait_time=300): + # initial_balance = self.get_balance(address) + # counter = 0 + # if initial_balance < 1000000000000000000: + # if external_faucet: + # self.faucet_backup(address) + # else: + # self.faucet(address) + # while True: + # if counter >= wait_time: + # pytest.fail("Donation was not received during %s seconds!" % wait_time) + # elif self.get_balance(address) == initial_balance: + # counter += 10 + # time.sleep(10) + # self.log('Waiting %s seconds for donation' % counter) + # else: + # self.log('Got %s Gwei for %s' % (self.get_balance(address), address)) + # return def start_chat_bot(self, chat_name: str, messages_number: int, interval: int = 1) -> list: url = '%s/ping/%s?count=%s&interval=%s' % (self.chat_bot_url, chat_name, messages_number, interval) @@ -202,9 +192,15 @@ class NetworkApi(object): rounded_balance = round(float(actual_balance), decimals) return rounded_balance + def get_tx_param_by_hash(self, hash: str, param: str): + method = self.network_url + 'module=proxy&action=eth_getTransactionByHash&txhash=%s&apikey=%s' % ( + hash, self.api_key) + res = self.send_etherscan_request(method, 'result') + return int(res[param], 16) + def get_custom_fee_tx_params(self, hash: str): return { - 'fee_cap': str(w3.get_tx_param_by_hash(hash, 'maxFeePerGas')/1000000000), - 'tip_cap': str(w3.get_tx_param_by_hash(hash, 'maxPriorityFeePerGas')/1000000000), - 'gas_limit': str(w3.get_tx_param_by_hash(hash, 'gas')) - } + 'fee_cap': str(self.get_tx_param_by_hash(hash, 'maxFeePerGas')/1000000000), + 'tip_cap': str(self.get_tx_param_by_hash(hash, 'maxPriorityFeePerGas')/1000000000), + 'gas_limit': str(self.get_tx_param_by_hash(hash, 'gas')) + } \ 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 441c438838..332893ca57 100644 --- a/test/appium/support/api/web3_api.py +++ b/test/appium/support/api/web3_api.py @@ -1,140 +1,141 @@ -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) - - -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 - 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 - """ - token_contract = ContractInteractions(token_data[token_name][0]['address'], token_data[token_name][0]['abi']) - to_address_data = token_contract.transfer_token_to( - from_address=account_address, - to_address=address, - number_of_tokens=amount, - nonce=token_contract.nonce(account_address), - 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) +# 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) +# +# +# 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 +# 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 +# """ +# token_contract = ContractInteractions(token_data[token_name][0]['address'], token_data[token_name][0]['abi']) +# to_address_data = token_contract.transfer_token_to( +# from_address=account_address, +# to_address=address, +# number_of_tokens=amount, +# nonce=token_contract.nonce(account_address), +# 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) diff --git a/test/appium/tests/conftest.py b/test/appium/tests/conftest.py index 53b5591c3f..6f05cb44d3 100644 --- a/test/appium/tests/conftest.py +++ b/test/appium/tests/conftest.py @@ -189,7 +189,7 @@ def pytest_configure(config): headers={'Content-Type': 'application/octet-stream'}) break except ConnectionError: - time.sleep(3) + time.sleep(10) else: sauce.storage.upload_file(config.getoption('apk')) @@ -340,11 +340,11 @@ def pytest_runtest_protocol(item, nextitem): return True # no need to rerun -@pytest.fixture(scope="session", autouse=False) -def faucet_for_senders(): - network_api = NetworkApi() - for user in transaction_senders.values(): - network_api.faucet(address=user['address']) +# @pytest.fixture(scope="session", autouse=False) +# def faucet_for_senders(): +# network_api = NetworkApi() +# for user in transaction_senders.values(): +# network_api.faucet(address=user['address']) @pytest.fixture diff --git a/test/appium/tests/medium/test_chats_m.py b/test/appium/tests/medium/test_chats_m.py index d17bfb31c6..c30ad76310 100644 --- a/test/appium/tests/medium/test_chats_m.py +++ b/test/appium/tests/medium/test_chats_m.py @@ -604,6 +604,7 @@ class TestChatMediumMultipleDevice(MultipleSharedDeviceTestCase): self.drivers[1].reset() self.home_2 = SignInView(self.drivers[1]).recover_access(ens_user['passphrase']) + self.home_2.ens_banner_close_button.wait_and_click() self.home_1.home_button.double_click() self.profile_2 = self.home_2.profile_button.click() ens, full_ens, username_2 = ens_user['ens'], '@%s' % ens_user['ens'], ens_user['username'] diff --git a/test/appium/tests/medium/test_single_device.py b/test/appium/tests/medium/test_single_device.py index 43a7d5c913..4db57b7cb4 100644 --- a/test/appium/tests/medium/test_single_device.py +++ b/test/appium/tests/medium/test_single_device.py @@ -77,11 +77,10 @@ class TestChatManagement(SingleDeviceTestCase): @marks.testrail_id(6292) def test_keycard_send_funds_between_accounts_set_max_in_multiaccount_instance(self): - sign_in_view = SignInView(self.driver).create_user(keycard=True) - wallet = sign_in_view.wallet_button.click() + sign_in = SignInView(self.driver).create_user(keycard=True) + wallet = sign_in.wallet_button.click() status_account_address = wallet.get_wallet_address()[2:] - self.network_api.get_donate(status_account_address, external_faucet=True) - wallet.wait_balance_is_changed() + wallet.get_test_assets(keycard=True) account_name = 'subaccount' wallet.add_account(account_name, keycard=True) wallet.get_account_by_name(account_name).click() @@ -160,6 +159,7 @@ class TestChatManagement(SingleDeviceTestCase): send_transaction.sign_transaction(keycard=True) wallet.element_by_text('Assets').click() wallet.wait_balance_is_equal_expected_amount(asset='ETH', expected_balance=0, main_screen=False) + wallet.donate_leftovers(keycard=True) @marks.testrail_id(5742) def test_keycard_onboarding_interruption_creating_flow(self): @@ -472,11 +472,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() - self.network_api.get_donate(address[2:], external_faucet=True, wait_time=200) wallet.close_button.click() - wallet.wait_balance_is_changed(scan_tokens=True) + wallet.get_test_assets() 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() @@ -1067,11 +1067,8 @@ class TestChatManagement(SingleDeviceTestCase): self.chat_key = self.home.get_public_key_and_username() self.wallet.just_fyi("Get required donate") - w3.donate_testnet_eth(self.address, amount=0.1, inscrease_default_gas_price=10) - self.home.wallet_button.click() - self.wallet.wait_balance_is_changed() - w3.donate_testnet_token('STT', address=self.address, amount=10, inscrease_default_gas_price=10) - self.wallet.wait_balance_is_changed('STT', scan_tokens=True) + self.wallet.get_test_assets() + self.wallet.get_test_assets(token=True) self.wallet.just_fyi("Purchase ENS") self.profile = self.home.profile_button.click() @@ -1099,13 +1096,7 @@ class TestChatManagement(SingleDeviceTestCase): self.wallet.just_fyi("Send leftovers") self.wallet.wallet_button.double_click() address = self.wallet.get_wallet_address() - send_transaction = self.wallet.send_transaction_button.click() - send_transaction.set_max_button.click() - send_transaction.confirm() - send_transaction.chose_recipient_button.click() - send_transaction.set_recipient_address(w3.ACCOUNT_ADDRESS) - send_transaction.sign_transaction_button.click() - send_transaction.sign_transaction() + self.wallet.donate_leftovers() self.wallet.just_fyi("Verify purchased ENS") self.home.home_button.click() @@ -1118,6 +1109,8 @@ class TestChatManagement(SingleDeviceTestCase): "Public key in not resolved correctly from %s ENS name on stateofus!" % self.ens_name) self.home.get_back_to_home_view() self.wallet.wallet_button.double_click() + from views.send_transaction_view import SendTransactionView + send_transaction = SendTransactionView(self.driver) self.wallet.send_transaction_from_main_screen.click_until_presence_of_element(send_transaction.chose_recipient_button) send_transaction.chose_recipient_button.scroll_and_click() send_transaction.set_recipient_address(self.ens_name) diff --git a/test/appium/views/base_view.py b/test/appium/views/base_view.py index 2852945706..70d7896f62 100644 --- a/test/appium/views/base_view.py +++ b/test/appium/views/base_view.py @@ -685,6 +685,38 @@ class BaseView(object): web_view.new_tab_button.click() return web_view + def get_test_assets(self, token=False, keycard=False): + from views.home_view import HomeView + status_test_dapp = HomeView(self.driver).open_status_test_dapp() + status_test_dapp.wait_for_d_aap_to_load() + + self.just_fyi("Requesting test assets in dapp") + status_test_dapp.assets_button.click() + if token: + send_tx = status_test_dapp.request_stt_button.click() + send_tx.sign_transaction(keycard=keycard) + wallet = self.wallet_button.click() + wallet.wait_balance_is_changed(asset='STT', scan_tokens=True) + else: + status_test_dapp.request_eth_button.click() + status_test_dapp.ok_button.wait_and_click() + wallet = self.wallet_button.click() + wallet.wait_balance_is_changed() + + return wallet + + def donate_leftovers(self, keycard=False): + self.just_fyi("Send leftovers from test accounts") + wallet = self.wallet_button.click() + self.wallet_button.click() + send_transaction = wallet.send_transaction_from_main_screen.click() + send_transaction.set_max_button.click() + send_transaction.confirm() + send_transaction.chose_recipient_button.click() + send_transaction.set_recipient_address('0x2127edab5d08b1e11adf7ae4bae16c2b33fdf74a') + send_transaction.sign_transaction_button.click() + send_transaction.sign_transaction(keycard=keycard) + # Method-helper def write_page_source_to_file(self, full_path_to_file): string_source = self.driver.page_source diff --git a/test/appium/views/web_views/status_test_dapp.py b/test/appium/views/web_views/status_test_dapp.py index b7aeedb351..702055d8f7 100644 --- a/test/appium/views/web_views/status_test_dapp.py +++ b/test/appium/views/web_views/status_test_dapp.py @@ -100,7 +100,7 @@ class StatusTestDAppView(BaseWebView): self.driver = driver self.assets_button = Button(self.driver, webview="Assets") - self.request_eth_button = Button(self.driver, webview="Request Ropsten ETH") + self.request_eth_button = Button(self.driver, webview="Request Goerli ETH") self.request_stt_button = RequestSTTButton(self.driver) self.transactions_button = TransactionsButton(self.driver) @@ -119,15 +119,3 @@ class StatusTestDAppView(BaseWebView): self.driver.info("**Wait %ss for assets in simpledapp**" % wait_time) self.assets_button.wait_for_visibility_of_element(seconds=wait_time) - def faucet_asset(self, asset='eth'): - self.driver.info("**Faucet %s in dapp**" % asset) - self.wait_for_d_aap_to_load() - self.assets_button.click() - if asset == 'eth': - self.request_eth_button.click() - self.element_by_text('Faucet request recieved').wait_for_visibility_of_element() - self.ok_button.click() - self.element_by_text('Faucet request recieved').wait_for_invisibility_of_element() - elif asset == 'stt': - send_transaction_view = self.request_stt_button.click() - send_transaction_view.sign_transaction()