2021-03-29 15:27:53 +02:00
|
|
|
# standard imports
|
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
|
|
|
|
# external imports
|
2021-10-07 17:12:35 +02:00
|
|
|
import pytest
|
2021-03-29 15:27:53 +02:00
|
|
|
from chainlib.eth.address import to_checksum_address
|
2021-10-07 17:12:35 +02:00
|
|
|
from hexathon import add_0x
|
2021-03-29 15:27:53 +02:00
|
|
|
|
|
|
|
# local imports
|
|
|
|
from cic_eth.api.api_task import Api
|
|
|
|
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
2021-10-07 17:12:35 +02:00
|
|
|
|
2021-03-29 15:27:53 +02:00
|
|
|
def test_balance_simple_api(
|
|
|
|
default_chain_spec,
|
|
|
|
init_database,
|
|
|
|
cic_registry,
|
|
|
|
foo_token,
|
2021-10-07 17:12:35 +02:00
|
|
|
register_lookups,
|
2021-03-29 15:27:53 +02:00
|
|
|
register_tokens,
|
|
|
|
api,
|
|
|
|
celery_session_worker,
|
|
|
|
):
|
|
|
|
|
|
|
|
chain_str = str(default_chain_spec)
|
|
|
|
|
2021-10-07 17:12:35 +02:00
|
|
|
a = add_0x(to_checksum_address(os.urandom(20).hex()))
|
2021-03-29 15:27:53 +02:00
|
|
|
t = api.balance(a, 'FOO', include_pending=False)
|
|
|
|
r = t.get_leaf()
|
|
|
|
assert t.successful()
|
|
|
|
logg.debug(r)
|
|
|
|
|
|
|
|
assert r[0].get('balance_network') != None
|
|
|
|
|
|
|
|
|
|
|
|
def test_balance_complex_api(
|
|
|
|
default_chain_spec,
|
|
|
|
init_database,
|
|
|
|
cic_registry,
|
|
|
|
foo_token,
|
2021-10-07 17:12:35 +02:00
|
|
|
register_lookups,
|
2021-03-29 15:27:53 +02:00
|
|
|
register_tokens,
|
|
|
|
api,
|
|
|
|
celery_session_worker,
|
|
|
|
):
|
|
|
|
|
|
|
|
chain_str = str(default_chain_spec)
|
|
|
|
|
2021-10-07 17:12:35 +02:00
|
|
|
a = add_0x(to_checksum_address(os.urandom(20).hex()))
|
2021-03-29 15:27:53 +02:00
|
|
|
t = api.balance(a, 'FOO', include_pending=True)
|
|
|
|
r = t.get_leaf()
|
|
|
|
assert t.successful()
|
|
|
|
logg.debug(r)
|
|
|
|
|
|
|
|
assert r[0].get('balance_incoming') != None
|
|
|
|
assert r[0].get('balance_outgoing') != None
|
|
|
|
assert r[0].get('balance_network') != None
|
|
|
|
|