Skip to content

Commit d303ece

Browse files
committed
e2e: wallet tests added
1 parent da25280 commit d303ece

File tree

11 files changed

+784
-436
lines changed

11 files changed

+784
-436
lines changed

test/appium/support/api/network_api.py

+51-60
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,66 @@
11
import logging
2+
import time
3+
from decimal import Decimal
4+
from json import JSONDecodeError
5+
from os import environ
26
from typing import List
37

48
import pytest
59
import requests
6-
import time
7-
from json import JSONDecodeError
8-
from decimal import Decimal
9-
from os import environ
10+
from selenium.common import TimeoutException
11+
1012
import tests
1113

1214

13-
class NetworkApi(object):
15+
class NetworkApi:
1416
def __init__(self):
15-
self.network_url = 'http://api-goerli.etherscan.io/api?'
16-
self.headers = {
17-
'User-Agent':"Mozilla\\5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit\\537.36 (KHTML, like Gecko) Chrome\\7"
18-
"7.0.3865.90 Safari\\537.36", }
19-
self.chat_bot_url = 'http://offsite.chat:8099'
17+
self.network_url = 'http://api-sepolia.etherscan.io/api'
2018
self.api_key = environ.get('ETHERSCAN_API_KEY')
2119

2220
def log(self, text: str):
2321
tests.test_suite_data.current_test.testruns[-1].steps.append(text)
2422
logging.info(text)
2523

26-
def send_etherscan_request(self, method, extracted_param: str):
27-
for attempt in range(3):
28-
try:
29-
response = requests.request('GET', url=method, headers=self.headers).json()
30-
if response:
31-
return response[extracted_param]
32-
except TypeError as e:
33-
self.log("Check response from etherscan API. Returned values do not match expected. %s" % str(e))
34-
except JSONDecodeError as e:
35-
self.log("No valid JSON response from Etherscan: %s " % str(e))
36-
pass
37-
time.sleep(30)
24+
def send_etherscan_request(self, params):
25+
params['apikey'] = self.api_key
26+
try:
27+
response = requests.get(url=self.network_url, params=params).json()
28+
if response:
29+
return response['result']
30+
except TypeError as e:
31+
self.log("Check response from etherscan API. Returned values do not match expected. %s" % str(e))
32+
except JSONDecodeError as e:
33+
self.log("No valid JSON response from Etherscan: %s " % str(e))
34+
pass
3835

3936
def get_token_transactions(self, address: str) -> List[dict]:
40-
method = self.network_url + 'module=account&action=tokentx&address=0x%s&sort=desc&apikey=%s' % (
41-
address, self.api_key)
42-
return self.send_etherscan_request(method, 'result')
37+
params = {'module': 'account', 'action': 'tokentx', 'address': address, 'sort': 'desc'}
38+
return self.send_etherscan_request(params)
4339

4440
def get_transactions(self, address: str) -> List[dict]:
45-
method = self.network_url + 'module=account&action=txlist&address=0x%s&sort=desc&apikey=%s' % (address, self.api_key)
46-
return self.send_etherscan_request(method, 'result')
41+
params = {'module': 'account', 'action': 'txlist', 'address': address, 'sort': 'desc'}
42+
return self.send_etherscan_request(params)
4743

4844
def is_transaction_successful(self, transaction_hash: str) -> int:
49-
method = self.network_url + 'module=transaction&action=getstatus&txhash=%s' % transaction_hash
50-
return not int(requests.request('GET', url=method, headers=self.headers).json()['result']['isError'])
51-
52-
def get_balance(self, address):
53-
address = '0x' + address
54-
method = self.network_url + 'module=account&action=balance&address=%s&tag=latest&apikey=%s' % (
55-
address, self.api_key)
56-
balance = self.send_etherscan_request(method, 'result')
45+
params = {'module': 'transaction', 'action': 'getstatus', 'txhash': transaction_hash}
46+
return not int(self.send_etherscan_request(params)['isError'])
47+
48+
def get_balance(self, address: str):
49+
params = {'module': 'account', 'action': 'balance', 'address': address, 'tag': 'latest'}
50+
balance = self.send_etherscan_request(params)
5751
if balance:
5852
self.log('Balance is %s Gwei' % balance)
5953
return int(balance)
6054
else:
6155
self.log('Cannot extract balance!')
6256

6357
def get_latest_block_number(self) -> int:
64-
method = self.network_url + 'module=proxy&action=eth_blockNumber'
65-
return int(requests.request('GET', url=method).json()['result'], 0)
58+
params = {'module': 'proxy', 'action': 'eth_blockNumber'}
59+
return int(self.send_etherscan_request(params), 0)
6660

6761
def find_transaction_by_hash(self, transaction_hash: str):
68-
method = self.network_url + 'module=transaction&action=gettxreceiptstatus&txhash=%s&apikey=%s' % (
69-
transaction_hash, self.api_key)
70-
result = self.send_etherscan_request(method, 'result')
62+
params = {'module': 'transaction', 'action': 'gettxreceiptstatus', 'txhash': transaction_hash}
63+
result = self.send_etherscan_request(params)
7164

7265
if result:
7366
final_status = True
@@ -86,13 +79,14 @@ def find_transaction_by_unique_amount(self, address, amount, token=False, decima
8679
while True:
8780
if counter >= wait_time:
8881
for entry in range(0, 5):
89-
self.log('Transaction #%s, amount is %s' %(entry+1, float(int(transactions[entry]['value']) / 10 ** decimals)))
82+
self.log('Transaction #%s, amount is %s' % (
83+
entry + 1, float(int(transactions[entry]['value']) / 10 ** decimals)))
9084
self.log(str(transactions[entry]))
9185
pytest.fail(
9286
'Transaction with amount %s is not found in list of %s, address is %s during %ss' %
9387
(amount, additional_info, address, wait_time))
9488
else:
95-
self.log("Finding tx in %s, attempt #%s" % (additional_info, str(int(counter / 30)+1)))
89+
self.log("Finding tx in %s, attempt #%s" % (additional_info, str(int(counter / 30) + 1)))
9690
try:
9791
if token:
9892
transactions = self.get_token_transactions(address)
@@ -126,7 +120,8 @@ def wait_for_confirmation_of_transaction(self, address, amount, confirmations=6,
126120
if int(transaction['confirmations']) >= confirmations:
127121
return
128122
time.sleep(20)
129-
pytest.fail('Transaction with amount %s was not confirmed, address is %s, still has %s confirmations' % (amount, address, int(transaction['confirmations'])))
123+
pytest.fail('Transaction with amount %s was not confirmed, address is %s, still has %s confirmations' % (
124+
amount, address, int(transaction['confirmations'])))
130125

131126
def verify_balance_is_updated(self, initial_balance, recipient_address, wait_time=360):
132127
counter = 0
@@ -141,10 +136,13 @@ def verify_balance_is_updated(self, initial_balance, recipient_address, wait_tim
141136
self.log('Balance is updated!')
142137
return
143138

144-
def verify_balance_is(self, expected_balance: int, recipient_address: str, errors: list):
145-
balance = self.get_balance(recipient_address)
146-
if balance / 1000000000000000000 != expected_balance:
147-
errors.append('Recipients balance is not updated on etherscan')
139+
def wait_for_balance_to_be(self, address: str, expected_balance: int, less: bool = True):
140+
for _ in range(5):
141+
balance = self.get_balance(address) / 1000000000000000000
142+
if (less and balance < expected_balance) or (not less and balance > expected_balance):
143+
return
144+
time.sleep(10)
145+
raise TimeoutException('Balance is not updated on Etherscan')
148146

149147
# Do not use until web3 update
150148
# def faucet(self, address):
@@ -160,7 +158,6 @@ def verify_balance_is(self, expected_balance: int, recipient_address: str, error
160158
# address = "0x" + address
161159
# w3.donate_testnet_eth(address=address, amount=0.01, inscrease_default_gas_price=10)
162160

163-
164161
# def get_donate(self, address, external_faucet=False, wait_time=300):
165162
# initial_balance = self.get_balance(address)
166163
# counter = 0
@@ -180,27 +177,21 @@ def verify_balance_is(self, expected_balance: int, recipient_address: str, error
180177
# self.log('Got %s Gwei for %s' % (self.get_balance(address), address))
181178
# return
182179

183-
def start_chat_bot(self, chat_name: str, messages_number: int, interval: int = 1) -> list:
184-
url = '%s/ping/%s?count=%s&interval=%s' % (self.chat_bot_url, chat_name, messages_number, interval)
185-
text = requests.request('GET', url).text
186-
return [i.split(maxsplit=5)[-1].strip('*') for i in text.splitlines()]
187-
188180
def get_rounded_balance(self, fetched_balance, actual_balance):
189181
fetched_balance, actual_balance = str(fetched_balance), str(actual_balance)
190182
# get actual number of decimals on account balance
191183
decimals = abs(Decimal(fetched_balance).as_tuple().exponent)
192184
rounded_balance = round(float(actual_balance), decimals)
193185
return rounded_balance
194186

195-
def get_tx_param_by_hash(self, hash: str, param: str):
196-
method = self.network_url + 'module=proxy&action=eth_getTransactionByHash&txhash=%s&apikey=%s' % (
197-
hash, self.api_key)
198-
res = self.send_etherscan_request(method, 'result')
187+
def get_tx_param_by_hash(self, transaction_hash: str, param: str):
188+
params = {'module': 'proxy', 'action': 'eth_getTransactionByHash', 'txhash': transaction_hash}
189+
res = self.send_etherscan_request(params)
199190
return int(res[param], 16)
200191

201192
def get_custom_fee_tx_params(self, hash: str):
202193
return {
203-
'fee_cap': str(self.get_tx_param_by_hash(hash, 'maxFeePerGas')/1000000000),
204-
'tip_cap': str(self.get_tx_param_by_hash(hash, 'maxPriorityFeePerGas')/1000000000),
194+
'fee_cap': str(self.get_tx_param_by_hash(hash, 'maxFeePerGas') / 1000000000),
195+
'tip_cap': str(self.get_tx_param_by_hash(hash, 'maxPriorityFeePerGas') / 1000000000),
205196
'gas_limit': str(self.get_tx_param_by_hash(hash, 'gas'))
206-
}
197+
}

test/appium/support/testrail_report.py

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def get_regression_cases(self):
129129
test_cases['pr']['community_multiple'] = 50982
130130
test_cases['pr']['activity_centre_contact_request'] = 50984
131131
test_cases['pr']['activity_centre_other'] = 51005
132+
test_cases['pr']['wallet'] = 59443
132133

133134
## Nightly e2e
134135
# test_cases['nightly']['activity_center'] = 736

test/appium/tests/activity_center/test_activity_center.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def prepare_devices(self):
2525
self.profile_1, self.profile_2 = self.home_1.get_profile_view(), self.home_2.get_profile_view()
2626
self.public_key_1 = self.home_1.get_public_key()
2727
self.profile_link_2 = self.home_2.get_link_to_profile()
28-
self.home_2.close_share_tab_button.click_until_absense_of_element(self.home_2.link_to_profile_text)
28+
self.home_2.close_share_tab_button.click_until_absense_of_element(self.home_2.share_qr_code_info_text)
2929
[home.navigate_back_to_home_view() for home in self.homes]
3030
[home.chats_tab.click() for home in self.homes]
3131

0 commit comments

Comments
 (0)