e2e: remove web3 dependencies

This commit is contained in:
Churikova Tetiana 2022-09-08 16:27:38 +02:00
parent 28963acb09
commit 7cc3ea2af4
No known key found for this signature in database
GPG Key ID: 0D4EA7B33B47E6D8
8 changed files with 267 additions and 256 deletions

View File

@ -44,7 +44,7 @@ sauceclient==1.0.0
scrypt==0.8.17 scrypt==0.8.17
selenium==3.14.1 selenium==3.14.1
six==1.16.0 six==1.16.0
urllib3==1.26.3 urllib3==1.26.12
yarl==1.6.3 yarl==1.6.3
docker==4.4.0 docker==4.4.0
influxdb==5.3.1 influxdb==5.3.1

View File

@ -7,19 +7,12 @@ import time
from json import JSONDecodeError from json import JSONDecodeError
from decimal import Decimal from decimal import Decimal
from os import environ from os import environ
from web3.exceptions import TransactionNotFound
import tests import tests
import support.api.web3_api as w3
class NetworkApi(object): class NetworkApi(object):
def __init__(self): def __init__(self):
# self.network_url = 'http://api-ropsten.etherscan.io/api?'
self.network_url = 'http://api-goerli.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 = { self.headers = {
'User-Agent':"Mozilla\\5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit\\537.36 (KHTML, like Gecko) Chrome\\7" '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", } "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) tests.test_suite_data.current_test.testruns[-1].steps.append(text)
logging.info(text) logging.info(text)
def get_transactions(self, address: str) -> List[dict]: def send_etherscan_request(self, method, extracted_param: str):
method = self.network_url + 'module=account&action=txlist&address=0x%s&sort=desc&apikey=%s' % (address, self.api_key)
for attempt in range(3): for attempt in range(3):
try: try:
transactions_response = requests.request('GET', url=method, headers=self.headers).json() response = requests.request('GET', url=method, headers=self.headers).json()
if transactions_response: if response:
return transactions_response['result'] return response[extracted_param]
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']
except TypeError as e: except TypeError as e:
self.log("Check response from etherscan API. Returned values do not match expected. %s" % str(e)) self.log("Check response from etherscan API. Returned values do not match expected. %s" % str(e))
except JSONDecodeError as e: except JSONDecodeError as e:
@ -58,15 +36,29 @@ class NetworkApi(object):
pass pass
time.sleep(30) 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: def is_transaction_successful(self, transaction_hash: str) -> int:
method = self.network_url + 'module=transaction&action=getstatus&txhash=%s' % transaction_hash 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']) return not int(requests.request('GET', url=method, headers=self.headers).json()['result']['isError'])
def get_balance(self, address): def get_balance(self, address):
address = '0x' + address address = '0x' + address
balance = w3.balance_of_address(address) 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) self.log('Balance is %s Gwei' % balance)
return int(balance) return int(balance)
else:
self.log('Cannot extract balance!')
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'
@ -75,22 +67,18 @@ class NetworkApi(object):
def find_transaction_by_hash(self, transaction_hash: str): def find_transaction_by_hash(self, transaction_hash: str):
method = self.network_url + 'module=transaction&action=gettxreceiptstatus&txhash=%s&apikey=%s' % ( method = self.network_url + 'module=transaction&action=gettxreceiptstatus&txhash=%s&apikey=%s' % (
transaction_hash, self.api_key) transaction_hash, self.api_key)
try: result = self.send_etherscan_request(method, 'result')
transactions_response = requests.request('GET', url=method, headers=self.headers).json()
if transactions_response: if result:
result = True final_status = True
if transactions_response['result']['status'] == '1': if result['status'] == '1':
self.log("TX %s is found and confirmed: " % transaction_hash) self.log("TX %s is found and confirmed" % transaction_hash)
elif transactions_response['result']['status'] == '0': elif result['status'] == '0':
self.log("TX %s is found and failed: " % transaction_hash) self.log("TX %s is found and failed: " % transaction_hash)
else: else:
result = False final_status = False
self.log("TX %s is not found!" % transaction_hash) self.log("TX %s is not found!" % transaction_hash)
return result return final_status
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))
def find_transaction_by_unique_amount(self, address, amount, token=False, decimals=18, wait_time=300): 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' additional_info = 'token transactions' if token else 'ETH transactions'
@ -158,37 +146,39 @@ class NetworkApi(object):
if balance / 1000000000000000000 != expected_balance: if balance / 1000000000000000000 != expected_balance:
errors.append('Recipients balance is not updated on etherscan') errors.append('Recipients balance is not updated on etherscan')
def faucet(self, address): # Do not use until web3 update
try: # def faucet(self, address):
self.log("Trying to get funds from %s" % self.faucet_url) # try:
return requests.request('GET', '%s/0x%s' % (self.faucet_url, address)).json() # self.log("Trying to get funds from %s" % self.faucet_url)
except JSONDecodeError as e: # return requests.request('GET', '%s/0x%s' % (self.faucet_url, address)).json()
self.log("No valid JSON response from Etherscan: %s " % str(e)) # except JSONDecodeError as e:
pass # self.log("No valid JSON response from Etherscan: %s " % str(e))
# pass
def faucet_backup(self, address): # def faucet_backup(self, address):
self.log("Trying to get funds from %s" % self.faucet_backup_address) # self.log("Trying to get funds from %s" % self.faucet_backup_address)
address = "0x" + address # address = "0x" + address
w3.donate_testnet_eth(address=address, amount=0.01, inscrease_default_gas_price=10) # 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) # def get_donate(self, address, external_faucet=False, wait_time=300):
counter = 0 # initial_balance = self.get_balance(address)
if initial_balance < 1000000000000000000: # counter = 0
if external_faucet: # if initial_balance < 1000000000000000000:
self.faucet_backup(address) # if external_faucet:
else: # self.faucet_backup(address)
self.faucet(address) # else:
while True: # self.faucet(address)
if counter >= wait_time: # while True:
pytest.fail("Donation was not received during %s seconds!" % wait_time) # if counter >= wait_time:
elif self.get_balance(address) == initial_balance: # pytest.fail("Donation was not received during %s seconds!" % wait_time)
counter += 10 # elif self.get_balance(address) == initial_balance:
time.sleep(10) # counter += 10
self.log('Waiting %s seconds for donation' % counter) # time.sleep(10)
else: # self.log('Waiting %s seconds for donation' % counter)
self.log('Got %s Gwei for %s' % (self.get_balance(address), address)) # else:
return # 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: 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) 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) rounded_balance = round(float(actual_balance), decimals)
return rounded_balance 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): def get_custom_fee_tx_params(self, hash: str):
return { return {
'fee_cap': str(w3.get_tx_param_by_hash(hash, 'maxFeePerGas')/1000000000), 'fee_cap': str(self.get_tx_param_by_hash(hash, 'maxFeePerGas')/1000000000),
'tip_cap': str(w3.get_tx_param_by_hash(hash, 'maxPriorityFeePerGas')/1000000000), 'tip_cap': str(self.get_tx_param_by_hash(hash, 'maxPriorityFeePerGas')/1000000000),
'gas_limit': str(w3.get_tx_param_by_hash(hash, 'gas')) 'gas_limit': str(self.get_tx_param_by_hash(hash, 'gas'))
} }

File diff suppressed because one or more lines are too long

View File

@ -189,7 +189,7 @@ def pytest_configure(config):
headers={'Content-Type': 'application/octet-stream'}) headers={'Content-Type': 'application/octet-stream'})
break break
except ConnectionError: except ConnectionError:
time.sleep(3) time.sleep(10)
else: else:
sauce.storage.upload_file(config.getoption('apk')) sauce.storage.upload_file(config.getoption('apk'))
@ -340,11 +340,11 @@ def pytest_runtest_protocol(item, nextitem):
return True # no need to rerun return True # no need to rerun
@pytest.fixture(scope="session", autouse=False) # @pytest.fixture(scope="session", autouse=False)
def faucet_for_senders(): # def faucet_for_senders():
network_api = NetworkApi() # network_api = NetworkApi()
for user in transaction_senders.values(): # for user in transaction_senders.values():
network_api.faucet(address=user['address']) # network_api.faucet(address=user['address'])
@pytest.fixture @pytest.fixture

View File

@ -604,6 +604,7 @@ class TestChatMediumMultipleDevice(MultipleSharedDeviceTestCase):
self.drivers[1].reset() self.drivers[1].reset()
self.home_2 = SignInView(self.drivers[1]).recover_access(ens_user['passphrase']) 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.home_1.home_button.double_click()
self.profile_2 = self.home_2.profile_button.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'] ens, full_ens, username_2 = ens_user['ens'], '@%s' % ens_user['ens'], ens_user['username']

View File

@ -77,11 +77,10 @@ class TestChatManagement(SingleDeviceTestCase):
@marks.testrail_id(6292) @marks.testrail_id(6292)
def test_keycard_send_funds_between_accounts_set_max_in_multiaccount_instance(self): def test_keycard_send_funds_between_accounts_set_max_in_multiaccount_instance(self):
sign_in_view = SignInView(self.driver).create_user(keycard=True) sign_in = SignInView(self.driver).create_user(keycard=True)
wallet = sign_in_view.wallet_button.click() wallet = sign_in.wallet_button.click()
status_account_address = wallet.get_wallet_address()[2:] status_account_address = wallet.get_wallet_address()[2:]
self.network_api.get_donate(status_account_address, external_faucet=True) wallet.get_test_assets(keycard=True)
wallet.wait_balance_is_changed()
account_name = 'subaccount' account_name = 'subaccount'
wallet.add_account(account_name, keycard=True) wallet.add_account(account_name, keycard=True)
wallet.get_account_by_name(account_name).click() wallet.get_account_by_name(account_name).click()
@ -160,6 +159,7 @@ class TestChatManagement(SingleDeviceTestCase):
send_transaction.sign_transaction(keycard=True) send_transaction.sign_transaction(keycard=True)
wallet.element_by_text('Assets').click() wallet.element_by_text('Assets').click()
wallet.wait_balance_is_equal_expected_amount(asset='ETH', expected_balance=0, main_screen=False) wallet.wait_balance_is_equal_expected_amount(asset='ETH', expected_balance=0, main_screen=False)
wallet.donate_leftovers(keycard=True)
@marks.testrail_id(5742) @marks.testrail_id(5742)
def test_keycard_onboarding_interruption_creating_flow(self): 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(): 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=200)
wallet.close_button.click() 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): 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") self.driver.fail("'Back up your seed phrase' warning is not shown on Wallet with funds")
wallet.donate_leftovers()
profile = wallet.get_profile_view() profile = wallet.get_profile_view()
wallet.backup_recovery_phrase_warning_text.click() wallet.backup_recovery_phrase_warning_text.click()
profile.backup_recovery_phrase() profile.backup_recovery_phrase()
@ -1067,11 +1067,8 @@ class TestChatManagement(SingleDeviceTestCase):
self.chat_key = self.home.get_public_key_and_username() self.chat_key = self.home.get_public_key_and_username()
self.wallet.just_fyi("Get required donate") self.wallet.just_fyi("Get required donate")
w3.donate_testnet_eth(self.address, amount=0.1, inscrease_default_gas_price=10) self.wallet.get_test_assets()
self.home.wallet_button.click() self.wallet.get_test_assets(token=True)
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.just_fyi("Purchase ENS") self.wallet.just_fyi("Purchase ENS")
self.profile = self.home.profile_button.click() self.profile = self.home.profile_button.click()
@ -1099,13 +1096,7 @@ class TestChatManagement(SingleDeviceTestCase):
self.wallet.just_fyi("Send leftovers") self.wallet.just_fyi("Send leftovers")
self.wallet.wallet_button.double_click() self.wallet.wallet_button.double_click()
address = self.wallet.get_wallet_address() address = self.wallet.get_wallet_address()
send_transaction = self.wallet.send_transaction_button.click() self.wallet.donate_leftovers()
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.just_fyi("Verify purchased ENS") self.wallet.just_fyi("Verify purchased ENS")
self.home.home_button.click() 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) "Public key in not resolved correctly from %s ENS name on stateofus!" % self.ens_name)
self.home.get_back_to_home_view() self.home.get_back_to_home_view()
self.wallet.wallet_button.double_click() 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) 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.chose_recipient_button.scroll_and_click()
send_transaction.set_recipient_address(self.ens_name) send_transaction.set_recipient_address(self.ens_name)

View File

@ -685,6 +685,38 @@ class BaseView(object):
web_view.new_tab_button.click() web_view.new_tab_button.click()
return web_view 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 # Method-helper
def write_page_source_to_file(self, full_path_to_file): def write_page_source_to_file(self, full_path_to_file):
string_source = self.driver.page_source string_source = self.driver.page_source

View File

@ -100,7 +100,7 @@ class StatusTestDAppView(BaseWebView):
self.driver = driver self.driver = driver
self.assets_button = Button(self.driver, webview="Assets") 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.request_stt_button = RequestSTTButton(self.driver)
self.transactions_button = TransactionsButton(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.driver.info("**Wait %ss for assets in simpledapp**" % wait_time)
self.assets_button.wait_for_visibility_of_element(seconds=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()