Added test for verification tokens data using api.ethplorer.io

Signed-off-by: yevh-berdnyk <ie.berdnyk@gmail.com>
This commit is contained in:
yevh-berdnyk 2018-06-07 17:13:37 +02:00
parent 00cd7c8578
commit 69610e41ad
No known key found for this signature in database
GPG Key ID: E9B425FDFC4DEA9C
6 changed files with 82 additions and 34 deletions

View File

@ -7,18 +7,20 @@ from tests import info
class NetworkApi:
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:
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']
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'])
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):
try:
return int(requests.request('GET', method).json()["result"])
@ -66,7 +68,7 @@ class NetworkApi:
return
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):
initial_balance = self.get_balance(address)
@ -84,11 +86,7 @@ class NetworkApi:
info('Got %s for %s' % (response["amount_eth"], address))
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:
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
return [i.split(maxsplit=5)[-1].strip('*') for i in text.splitlines()]

View 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()

View File

@ -5,7 +5,7 @@ import subprocess
import asyncio
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 appium import webdriver
from abc import ABCMeta, abstractmethod
@ -202,11 +202,10 @@ class SauceMultipleDeviceTestCase(AbstractTestCase):
cls.loop.close()
environments = {'local': LocalMultipleDeviceTestCase,
'sauce': SauceMultipleDeviceTestCase}
environment = LocalMultipleDeviceTestCase if pytest.config.getoption('env') == 'local' else SauceMultipleDeviceTestCase
class MultipleDeviceTestCase(environments[pytest.config.getoption('env')]):
class MultipleDeviceTestCase(environment):
def setup_method(self, method):
super(MultipleDeviceTestCase, self).setup_method(method)

View File

@ -32,7 +32,7 @@ def pytest_addoption(parser):
parser.addoption('--env',
action='store',
default='sauce',
help='Specify environment: local/sauce')
help='Specify environment: local/sauce/api')
parser.addoption('--log',
action='store',
default=False,
@ -90,25 +90,26 @@ def pytest_configure(config):
if config.getoption('log'):
import logging
logging.basicConfig(level=logging.INFO)
test_suite_data.apk_name = ([i for i in [i for i in config.getoption('apk').split('/')
if '.apk' in i]])[0]
if is_master(config):
if config.getoption('testrail_report'):
testrail_report.add_run(test_suite_data.apk_name)
if config.getoption('env') == 'sauce':
if not is_uploaded():
if 'http' in config.getoption('apk'):
response = requests.get(config.getoption('apk'), stream=True)
response.raise_for_status()
file = BytesIO(response.content)
del response
requests.post('http://saucelabs.com/rest/v1/storage/'
+ sauce_username + '/' + test_suite_data.apk_name + '?overwrite=true',
auth=(sauce_username, sauce_access_key),
data=file,
headers={'Content-Type': 'application/octet-stream'})
else:
sauce.storage.upload_file(config.getoption('apk'))
if config.getoption('env') != 'api':
test_suite_data.apk_name = ([i for i in [i for i in config.getoption('apk').split('/')
if '.apk' in i]])[0]
if is_master(config):
if config.getoption('testrail_report'):
testrail_report.add_run(test_suite_data.apk_name)
if config.getoption('env') == 'sauce':
if not is_uploaded():
if 'http' in config.getoption('apk'):
response = requests.get(config.getoption('apk'), stream=True)
response.raise_for_status()
file = BytesIO(response.content)
del response
requests.post('http://saucelabs.com/rest/v1/storage/'
+ sauce_username + '/' + test_suite_data.apk_name + '?overwrite=true',
auth=(sauce_username, sauce_access_key),
data=file,
headers={'Content-Type': 'application/octet-stream'})
else:
sauce.storage.upload_file(config.getoption('apk'))
def pytest_unconfigure(config):

View File

@ -4,6 +4,7 @@ pr = pytest.mark.pr
testrail_case_id = pytest.mark.testrail_case_id
all = pytest.mark.all
api = pytest.mark.api
chat = pytest.mark.chat
chat_management = pytest.mark.chat_management
message_reliability = pytest.mark.message_reliability

View 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)