...
 
Commits (2)
......@@ -29,9 +29,9 @@ test-watch:
@ptw
smoke:
@docker run ${DOCKER_OPTS} --rm -e PYTHONPATH=/app -v ${PWD}:/app -w /app ${IMAGE_NAME} python -u smoke.py
@docker run ${DOCKER_OPTS} --rm -e PYTHONPATH=/app -v ${PWD}:/app -w /app ${IMAGE_NAME} python smoke.py
health:
@docker run ${DOCKER_OPTS} --rm -e PYTHONPATH=/app -v ${PWD}:/app -w /app ${IMAGE_NAME} python -u health.py
@docker run ${DOCKER_OPTS} --rm -e PYTHONPATH=/app -v ${PWD}:/app -w /app ${IMAGE_NAME} python health.py
.PHONY: build lint format test test-watch health smoke
import time
import logging
from common import Transaction, Coin, Asset, HttpClient
......@@ -40,9 +41,7 @@ class MockBinance(HttpClient):
block = self.get_block_height()
if block - start_block >= count:
return
raise Exception(
"failed waiting for mock binance transactions ({})", format(count)
)
raise Exception(f"failed waiting for mock binance transactions ({count})")
def accounts(self):
return self.fetch("/accounts")
......@@ -93,7 +92,7 @@ class Account:
if coin.asset.is_equal(c.asset):
self.balances[i].amount -= coin.amount
if self.balances[i].amount < 0:
print("Balance:", self.address, self.balances[i])
logging.info(f"Balance: {self.address} {self.balances[i]}")
self.balances[i].amount = 0
# raise Exception("insufficient funds")
......@@ -178,9 +177,7 @@ class Binance:
Makes a transfer on the binance chain. Returns gas used
"""
if txn.chain != Binance.chain:
raise Exception(
"Cannot transfer. {} is not {}".format(Binance.chain, txn.chain)
)
raise Exception(f"Cannot transfer. {Binance.chain} is not {txn.chain}")
from_acct = self.get_account(txn.fromAddress)
to_acct = self.get_account(txn.toAddress)
......
......@@ -4,7 +4,7 @@ class PoolError(Exception):
def __init__(self, pool, msg=None):
if msg is None:
# Set some default useful error message
msg = "An error occured with pool [{}]".format(pool)
msg = f"An error occured with pool [{pool}]"
super().__init__(msg)
self.msg = msg
self.pool = pool
......@@ -14,9 +14,7 @@ class MidgardPoolError(PoolError):
"""Pool midgard error"""
def __init__(self, pool, field, expected, obtained):
msg = "Midgard Pool [{}] || {} ==> {} != {}".format(
pool, field, expected, obtained
)
msg = f"Midgard Pool [{pool}] || {field} ==> {expected} != {obtained}"
super().__init__(pool, msg=msg)
self.msg = msg
self.field = field
......
import argparse
import sys
import os
import logging
from thorchain import ThorchainClient
from midgard import MidgardClient
from exceptions import MidgardPoolError
# Init logging
logging.basicConfig(
format="%(asctime)s | %(levelname)-8s | %(message)s",
level=os.environ.get("LOGLEVEL", "INFO"),
)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
......@@ -21,7 +30,7 @@ def main():
try:
health.run()
except Exception as e:
print(e)
logging.error(e)
sys.exit(1)
......@@ -49,7 +58,7 @@ class Health:
"""Check errors and exit accordingly.
"""
for error in self.errors:
print(error)
logging.error(error)
if len(self.errors):
raise Exception("Health checks failed")
......@@ -90,7 +99,7 @@ class Health:
self.errors.append(
MidgardPoolError(
asset,
"Balance {}".format(asset),
f"Balance {asset}",
tpool["balance_asset"],
mpool["assetDepth"],
)
......
......@@ -13,4 +13,4 @@ class MidgardClient(HttpClient):
:returns: Pool data
"""
return self.fetch("/v1/pools/{}".format(asset))
return self.fetch(f"/v1/pools/{asset}")
import argparse
import logging
import os
from chains import Binance, MockBinance
from thorchain import ThorchainState, ThorchainClient
from common import Transaction, Coin, Asset
# Init logging
logging.basicConfig(
format="%(asctime)s | %(levelname)-8s | %(message)s",
level=os.environ.get("LOGLEVEL", "INFO"),
)
# A list of smoke test transaction, [inbound txn, expected # of outbound txns]
txns = [
# Seeding funds to various accounts
......@@ -383,8 +391,7 @@ class Smoker:
for i, unit in enumerate(self.txns):
# get transaction and expected number of outbound transactions
txn, out = unit
print("{} {}".format(i, txn))
logging.info(f"{i} {txn}")
if txn.memo == "SEED":
self.binance.seed(txn.toAddress, txn.coins)
self.mock_binance.seed(txn.toAddress, txn.coins)
......@@ -414,15 +421,13 @@ class Smoker:
spool = self.thorchain.get_pool(Asset(rpool["asset"]))
if int(spool.rune_balance) != int(rpool["balance_rune"]):
raise Exception(
"bad pool rune balance: {} {} != {}".format(
rpool["asset"], spool.rune_balance, rpool["balance_rune"]
)
f"bad pool rune balance: {rpool['asset']} "
f"{spool.rune_balance} != {rpool['balance_rune']}"
)
if int(spool.asset_balance) != int(rpool["balance_asset"]):
raise Exception(
"bad pool asset balance: {} {} != {}".format(
rpool["asset"], spool.asset_balance, rpool["balance_asset"]
)
f"bad pool asset balance: {rpool['asset']} "
f"{spool.asset_balance} != {rpool['balance_asset']}"
)
# compare simulation binance vs mock binance
......@@ -439,9 +444,8 @@ class Smoker:
Coin(bal["denom"], int(bal["amount"]))
):
raise Exception(
"bad binance balance: {} {} != {}".format(
bal["denom"], bal["amount"], coin
)
f"bad binance balance: {bal['denom']} "
f"{bal['amount']} != {coin}"
)
......
import unittest
import logging
import json
import pprint
from pprint import pformat
from deepdiff import DeepDiff
from chains import Binance
......@@ -36,11 +37,9 @@ class TestSmoke(unittest.TestCase):
thorchain = ThorchainState() # init local thorchain
for i, unit in enumerate(txns):
(
txn,
out,
) = unit # get transaction and expected number of outbound transactions
print("{} {}".format(i, txn))
# get transaction and expected number of outbound transactions
txn, out = unit
logging.info(f"{i} {txn}")
if txn.memo == "SEED":
bnb.seed(txn.toAddress, txn.coins)
continue
......@@ -59,13 +58,13 @@ class TestSmoke(unittest.TestCase):
snap, expected, ignore_order=True
) # empty dict if are equal
if len(diff) > 0:
print("Transaction:", i, txn)
print(">>>>>> Expected")
pprint.pprint(expected)
print(">>>>>> Obtained")
pprint.pprint(snap)
print(">>>>>> DIFF")
pprint.pprint(diff)
logging.info(f"Transaction: {i} {txn}")
logging.info(">>>>>> Expected")
logging.info(pformat(expected))
logging.info(">>>>>> Obtained")
logging.info(pformat(snap))
logging.info(">>>>>> DIFF")
logging.info(pformat(diff))
raise Exception("did not match!")
......
import time
import logging
from copy import deepcopy
from common import (
......@@ -32,7 +33,7 @@ class ThorchainClient(HttpClient):
block = self.get_block_height()
if block - start_block >= count:
return
raise Exception("failed waiting for thorchain blocks ({})", format(count))
raise Exception(f"failed waiting for thorchain blocks ({count})")
def get_vault_address(self):
data = self.fetch("/thorchain/pool_addresses")
......@@ -113,7 +114,7 @@ class ThorchainState:
elif tx.memo.startswith("SWAP:"):
return self.handle_swap(tx)
else:
print("handler not recognized")
logging.warning("handler not recognized")
return self.refund(tx)
def handle_add(self, txn):
......@@ -348,7 +349,7 @@ class Pool:
self.rune_balance -= rune_amt
self.asset_balance -= asset_amt
if self.asset_balance < 0 or self.rune_balance < 0:
print("Overdrawn pool", self)
logging.error(f"Overdrawn pool: {self}")
raise Exception("insufficient funds")
def add(self, rune_amt, asset_amt):
......@@ -455,7 +456,7 @@ class Pool:
)
units_after = staker_units - units_to_claim
if units_after < 0:
print("Overdrawn staker units", self)
logging.error(f"Overdrawn staker units: {self}")
raise Exception("Overdrawn staker units")
return units_to_claim, withdraw_rune, withdraw_asset
......@@ -491,7 +492,7 @@ class Staker:
"""
self.units -= units
if self.units < 0:
print("Overdrawn staker", self)
logging.error(f"Overdrawn staker: {self}")
raise Exception("insufficient staker units")
def is_zero(self):
......