Logging in networks
Signed-off-by: Serhy <sergii@status.im>
This commit is contained in:
parent
ea3735d938
commit
453c1bf824
|
@ -22,19 +22,24 @@ class NetworkApi(object):
|
||||||
self.chat_bot_url = 'http://offsite.chat:8099'
|
self.chat_bot_url = 'http://offsite.chat:8099'
|
||||||
self.api_key = environ.get('ETHERSCAN_API_KEY')
|
self.api_key = environ.get('ETHERSCAN_API_KEY')
|
||||||
|
|
||||||
|
def log(self, text: str):
|
||||||
|
|
||||||
|
tests.test_suite_data.current_test.testruns[-1].steps.append(text)
|
||||||
|
logging.info(text)
|
||||||
|
|
||||||
def get_transactions(self, address: str) -> List[dict]:
|
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)
|
method = self.network_url + 'module=account&action=txlist&address=0x%s&sort=desc&apikey=%s' % (address, self.api_key)
|
||||||
try:
|
try:
|
||||||
return requests.request('GET', url=method, headers=self.headers).json()['result']
|
return requests.request('GET', url=method, headers=self.headers).json()['result']
|
||||||
except TypeError:
|
except TypeError as e:
|
||||||
print('Check response from etherscan API. Returned values don\'t match expected')
|
self.log("Check response from etherscan API. Returned values do not match expected. %s" % e)
|
||||||
|
|
||||||
def get_token_transactions(self, address: str) -> List[dict]:
|
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)
|
method = self.network_url + 'module=account&action=tokentx&address=0x%s&sort=desc&apikey=%s' % (address, self.api_key)
|
||||||
try:
|
try:
|
||||||
return requests.request('GET', url=method, headers=self.headers).json()['result']
|
return requests.request('GET', url=method, headers=self.headers).json()['result']
|
||||||
except TypeError:
|
except TypeError as e:
|
||||||
print('Check response from etherscan API. Returned values don\'t match expected')
|
self.log("Check response from etherscan API. Returned values do not match expected. %s" % e)
|
||||||
|
|
||||||
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
|
||||||
|
@ -75,16 +80,21 @@ class NetworkApi(object):
|
||||||
transactions = self.get_token_transactions(address)
|
transactions = self.get_token_transactions(address)
|
||||||
else:
|
else:
|
||||||
transactions = self.get_transactions(address)
|
transactions = self.get_transactions(address)
|
||||||
except JSONDecodeError:
|
except JSONDecodeError as e:
|
||||||
|
self.log(str(e))
|
||||||
continue
|
continue
|
||||||
logging.info('Looking for a transaction with unique amount %s in list of transactions, address is %s' %
|
self.log('Looking for a transaction with unique amount %s in list of transactions, address is %s' %
|
||||||
(amount, address))
|
(amount, address))
|
||||||
for transaction in transactions:
|
try:
|
||||||
if float(int(transaction['value']) / 10 ** decimals) == float(amount):
|
for transaction in transactions:
|
||||||
logging.info(
|
if float(int(transaction['value']) / 10 ** decimals) == float(amount):
|
||||||
'Transaction with unique amount %s is found in list of transactions, address is %s' %
|
self.log(
|
||||||
(amount, address))
|
'Transaction with unique amount %s is found in list of transactions, address is %s' %
|
||||||
return transaction
|
(amount, address))
|
||||||
|
return transaction
|
||||||
|
except TypeError as e:
|
||||||
|
self.log("Failed iterate transactions " + str(e))
|
||||||
|
continue
|
||||||
|
|
||||||
def wait_for_confirmation_of_transaction(self, address, amount, confirmations=12, token=False):
|
def wait_for_confirmation_of_transaction(self, address, amount, confirmations=12, token=False):
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
@ -103,9 +113,9 @@ class NetworkApi(object):
|
||||||
elif initial_balance == self.get_balance(recipient_address):
|
elif initial_balance == self.get_balance(recipient_address):
|
||||||
counter += 10
|
counter += 10
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
logging.info('Waiting %s seconds for funds' % counter)
|
self.log('Waiting %s seconds for funds' % counter)
|
||||||
else:
|
else:
|
||||||
logging.info('Transaction is received')
|
self.log('Transaction is received')
|
||||||
return
|
return
|
||||||
|
|
||||||
def verify_balance_is(self, expected_balance: int, recipient_address: str, errors: list):
|
def verify_balance_is(self, expected_balance: int, recipient_address: str, errors: list):
|
||||||
|
@ -132,9 +142,9 @@ class NetworkApi(object):
|
||||||
elif self.get_balance(address) == initial_balance:
|
elif self.get_balance(address) == initial_balance:
|
||||||
counter += 10
|
counter += 10
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
logging.info('Waiting %s seconds for donation' % counter)
|
self.log('Waiting %s seconds for donation' % counter)
|
||||||
else:
|
else:
|
||||||
logging.info('Got %s for %s' % (response["amount_eth"], address))
|
self.log('Got %s for %s' % (response["amount_eth"], address))
|
||||||
return
|
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:
|
||||||
|
|
Loading…
Reference in New Issue