mirror of
https://github.com/status-im/status-react.git
synced 2025-01-11 03:26:31 +00:00
Added test for verification tokens data using api.ethplorer.io
Signed-off-by: yevh-berdnyk <ie.berdnyk@gmail.com>
This commit is contained in:
parent
00cd7c8578
commit
69610e41ad
@ -7,18 +7,20 @@ from tests import info
|
|||||||
class NetworkApi:
|
class NetworkApi:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.url = 'http://api-ropsten.etherscan.io/api?'
|
self.etherscan_url = 'http://api-ropsten.etherscan.io/api?'
|
||||||
|
self.faucet_url = 'http://51.15.45.169:3001/donate'
|
||||||
|
self.chat_bot_url = 'http://offsite.chat:8099'
|
||||||
|
|
||||||
def get_transactions(self, address: str) -> dict:
|
def get_transactions(self, address: str) -> dict:
|
||||||
method = self.url + 'module=account&action=txlist&address=0x%s&sort=desc' % address
|
method = self.etherscan_url + 'module=account&action=txlist&address=0x%s&sort=desc' % address
|
||||||
return requests.request('GET', url=method).json()['result']
|
return requests.request('GET', url=method).json()['result']
|
||||||
|
|
||||||
def is_transaction_successful(self, transaction_hash: str) -> int:
|
def is_transaction_successful(self, transaction_hash: str) -> int:
|
||||||
method = self.url + 'module=transaction&action=getstatus&txhash=%s' % transaction_hash
|
method = self.etherscan_url + 'module=transaction&action=getstatus&txhash=%s' % transaction_hash
|
||||||
return not int(requests.request('GET', url=method).json()['result']['isError'])
|
return not int(requests.request('GET', url=method).json()['result']['isError'])
|
||||||
|
|
||||||
def get_balance(self, address):
|
def get_balance(self, address):
|
||||||
method = self.url + 'module=account&action=balance&address=0x%s&tag=latest' % address
|
method = self.etherscan_url + 'module=account&action=balance&address=0x%s&tag=latest' % address
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
try:
|
try:
|
||||||
return int(requests.request('GET', method).json()["result"])
|
return int(requests.request('GET', method).json()["result"])
|
||||||
@ -66,7 +68,7 @@ class NetworkApi:
|
|||||||
return
|
return
|
||||||
|
|
||||||
def faucet(self, address):
|
def faucet(self, address):
|
||||||
return requests.request('GET', 'http://51.15.45.169:3001/donate/0x%s' % address).json()
|
return requests.request('GET', '%s/0x%s' % (self.faucet_url, address)).json()
|
||||||
|
|
||||||
def get_donate(self, address, wait_time=300):
|
def get_donate(self, address, wait_time=300):
|
||||||
initial_balance = self.get_balance(address)
|
initial_balance = self.get_balance(address)
|
||||||
@ -84,11 +86,7 @@ class NetworkApi:
|
|||||||
info('Got %s for %s' % (response["amount_eth"], address))
|
info('Got %s for %s' % (response["amount_eth"], address))
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_ethereum_price_in_usd(self) -> float:
|
|
||||||
url = 'https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD'
|
|
||||||
return float(requests.request('GET', url).json()['USD'])
|
|
||||||
|
|
||||||
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 = 'http://offsite.chat:8099/ping/%s?count=%s&interval=%s' % (chat_name, messages_number, interval)
|
url = '%s/ping/%s?count=%s&interval=%s' % (self.chat_bot_url, chat_name, messages_number, interval)
|
||||||
text = requests.request('GET', url).text
|
text = requests.request('GET', url).text
|
||||||
return [i.split(maxsplit=5)[-1].strip('*') for i in text.splitlines()]
|
return [i.split(maxsplit=5)[-1].strip('*') for i in text.splitlines()]
|
11
test/appium/support/api/third_parties_api.py
Normal file
11
test/appium/support/api/third_parties_api.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def get_ethereum_price_in_usd() -> float:
|
||||||
|
url = 'https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD'
|
||||||
|
return float(requests.request('GET', url).json()['USD'])
|
||||||
|
|
||||||
|
|
||||||
|
def get_token_info(address: str):
|
||||||
|
url = 'http://api.ethplorer.io/getTokenInfo/%s?apiKey=freekey' % address
|
||||||
|
return requests.request('GET', url).json()
|
@ -5,7 +5,7 @@ import subprocess
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from support.message_reliability_report import create_one_to_one_chat_report, create_public_chat_report
|
from support.message_reliability_report import create_one_to_one_chat_report, create_public_chat_report
|
||||||
from support.network_api import NetworkApi
|
from support.api.network_api import NetworkApi
|
||||||
from os import environ
|
from os import environ
|
||||||
from appium import webdriver
|
from appium import webdriver
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
@ -202,11 +202,10 @@ class SauceMultipleDeviceTestCase(AbstractTestCase):
|
|||||||
cls.loop.close()
|
cls.loop.close()
|
||||||
|
|
||||||
|
|
||||||
environments = {'local': LocalMultipleDeviceTestCase,
|
environment = LocalMultipleDeviceTestCase if pytest.config.getoption('env') == 'local' else SauceMultipleDeviceTestCase
|
||||||
'sauce': SauceMultipleDeviceTestCase}
|
|
||||||
|
|
||||||
|
|
||||||
class MultipleDeviceTestCase(environments[pytest.config.getoption('env')]):
|
class MultipleDeviceTestCase(environment):
|
||||||
|
|
||||||
def setup_method(self, method):
|
def setup_method(self, method):
|
||||||
super(MultipleDeviceTestCase, self).setup_method(method)
|
super(MultipleDeviceTestCase, self).setup_method(method)
|
||||||
|
@ -32,7 +32,7 @@ def pytest_addoption(parser):
|
|||||||
parser.addoption('--env',
|
parser.addoption('--env',
|
||||||
action='store',
|
action='store',
|
||||||
default='sauce',
|
default='sauce',
|
||||||
help='Specify environment: local/sauce')
|
help='Specify environment: local/sauce/api')
|
||||||
parser.addoption('--log',
|
parser.addoption('--log',
|
||||||
action='store',
|
action='store',
|
||||||
default=False,
|
default=False,
|
||||||
@ -90,25 +90,26 @@ def pytest_configure(config):
|
|||||||
if config.getoption('log'):
|
if config.getoption('log'):
|
||||||
import logging
|
import logging
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
test_suite_data.apk_name = ([i for i in [i for i in config.getoption('apk').split('/')
|
if config.getoption('env') != 'api':
|
||||||
if '.apk' in i]])[0]
|
test_suite_data.apk_name = ([i for i in [i for i in config.getoption('apk').split('/')
|
||||||
if is_master(config):
|
if '.apk' in i]])[0]
|
||||||
if config.getoption('testrail_report'):
|
if is_master(config):
|
||||||
testrail_report.add_run(test_suite_data.apk_name)
|
if config.getoption('testrail_report'):
|
||||||
if config.getoption('env') == 'sauce':
|
testrail_report.add_run(test_suite_data.apk_name)
|
||||||
if not is_uploaded():
|
if config.getoption('env') == 'sauce':
|
||||||
if 'http' in config.getoption('apk'):
|
if not is_uploaded():
|
||||||
response = requests.get(config.getoption('apk'), stream=True)
|
if 'http' in config.getoption('apk'):
|
||||||
response.raise_for_status()
|
response = requests.get(config.getoption('apk'), stream=True)
|
||||||
file = BytesIO(response.content)
|
response.raise_for_status()
|
||||||
del response
|
file = BytesIO(response.content)
|
||||||
requests.post('http://saucelabs.com/rest/v1/storage/'
|
del response
|
||||||
+ sauce_username + '/' + test_suite_data.apk_name + '?overwrite=true',
|
requests.post('http://saucelabs.com/rest/v1/storage/'
|
||||||
auth=(sauce_username, sauce_access_key),
|
+ sauce_username + '/' + test_suite_data.apk_name + '?overwrite=true',
|
||||||
data=file,
|
auth=(sauce_username, sauce_access_key),
|
||||||
headers={'Content-Type': 'application/octet-stream'})
|
data=file,
|
||||||
else:
|
headers={'Content-Type': 'application/octet-stream'})
|
||||||
sauce.storage.upload_file(config.getoption('apk'))
|
else:
|
||||||
|
sauce.storage.upload_file(config.getoption('apk'))
|
||||||
|
|
||||||
|
|
||||||
def pytest_unconfigure(config):
|
def pytest_unconfigure(config):
|
||||||
|
@ -4,6 +4,7 @@ pr = pytest.mark.pr
|
|||||||
testrail_case_id = pytest.mark.testrail_case_id
|
testrail_case_id = pytest.mark.testrail_case_id
|
||||||
|
|
||||||
all = pytest.mark.all
|
all = pytest.mark.all
|
||||||
|
api = pytest.mark.api
|
||||||
chat = pytest.mark.chat
|
chat = pytest.mark.chat
|
||||||
chat_management = pytest.mark.chat_management
|
chat_management = pytest.mark.chat_management
|
||||||
message_reliability = pytest.mark.message_reliability
|
message_reliability = pytest.mark.message_reliability
|
||||||
|
38
test/appium/tests/test_api.py
Normal file
38
test/appium/tests/test_api.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import os
|
||||||
|
import pytest
|
||||||
|
import re
|
||||||
|
import time
|
||||||
|
|
||||||
|
from os import path
|
||||||
|
|
||||||
|
from support.api.third_parties_api import get_token_info
|
||||||
|
from tests import marks
|
||||||
|
|
||||||
|
|
||||||
|
def get_parameters():
|
||||||
|
directory = os.sep.join(__file__.split(os.sep)[:-4])
|
||||||
|
file_path = path.join(directory, 'src/status_im/utils/ethereum/tokens.cljs')
|
||||||
|
with open(file_path, 'r') as f:
|
||||||
|
data = f.read()
|
||||||
|
return re.findall('{:symbol\s*:(.*)\n\s*:name\s*"(.*)"\n\s*:address\s*"(.*)"\n\s*:decimals\s*(.*)}', data)
|
||||||
|
|
||||||
|
|
||||||
|
class TestAPi(object):
|
||||||
|
|
||||||
|
@marks.api
|
||||||
|
@pytest.mark.parametrize('symbol,name,address,decimals', get_parameters())
|
||||||
|
def test_tokens_verification(self, symbol, name, address, decimals):
|
||||||
|
res = get_token_info(address)
|
||||||
|
errors = list()
|
||||||
|
if str(res['decimals']) != decimals:
|
||||||
|
errors.append("decimals value %s doesn't match expected %s" % (decimals, res['decimals']))
|
||||||
|
if res['symbol'] != symbol:
|
||||||
|
errors.append("symbol '%s' doesn't match expected '%s'" % (symbol, res['symbol']))
|
||||||
|
if res['name'] != name:
|
||||||
|
errors.append("token name '%s' doesn't match expected '%s'" % (name, res['name']))
|
||||||
|
if errors:
|
||||||
|
pytest.fail('For address %s %s' % (address, ', '.join(errors)))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def teardown():
|
||||||
|
time.sleep(3)
|
Loading…
x
Reference in New Issue
Block a user