160 lines
4.8 KiB
Python
160 lines
4.8 KiB
Python
# coding: utf-8
|
|
from __future__ import absolute_import
|
|
|
|
import logging
|
|
import time
|
|
|
|
import hexathon
|
|
from cic_eth.runnable.daemons.server import app
|
|
from fastapi.testclient import TestClient
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
def test_default_token():
|
|
# Default Token
|
|
response = client.get('/default_token')
|
|
log.debug(f"balance response {response}")
|
|
default_token = response.json()
|
|
assert default_token == {
|
|
'address': '3FF776B6f888980DEf9d4220858803f9dC5e341e',
|
|
'decimals': 6,
|
|
'name': 'Giftable Token',
|
|
'symbol': 'GFT',
|
|
}
|
|
|
|
|
|
def test_token():
|
|
# Default Token
|
|
response = client.get('/token?token_symbol=GFT')
|
|
log.debug(f"token response {response}")
|
|
token = response.json()
|
|
assert token == {
|
|
'address': '3ff776b6f888980def9d4220858803f9dc5e341e',
|
|
'converters': [],
|
|
'decimals': 6,
|
|
'name': 'Giftable Token',
|
|
'proofs': ['3af82fa124235f84e78145f008054b11fe477e2b043ac5e4979c3afa737fd328'],
|
|
'proofs_with_signers': [{'proof': '3af82fa124235f84e78145f008054b11fe477e2b043ac5e4979c3afa737fd328',
|
|
'signers': ['Eb3907eCad74a0013c259D5874AE7f22DcBcC95C']}],
|
|
'symbol': 'GFT',
|
|
}
|
|
|
|
|
|
def test_tokens():
|
|
# Default Token
|
|
response = client.get('/tokens', params={'token_symbols': ['GFT', 'COFE']})
|
|
|
|
log.debug(f"tokens response {response}")
|
|
tokens = response.json()
|
|
assert tokens == [
|
|
{'address': '3ff776b6f888980def9d4220858803f9dc5e341e',
|
|
'converters': [],
|
|
'decimals': 6,
|
|
'name': 'Giftable Token',
|
|
'proofs': ['3af82fa124235f84e78145f008054b11fe477e2b043ac5e4979c3afa737fd328'],
|
|
'proofs_with_signers': [{'proof': '3af82fa124235f84e78145f008054b11fe477e2b043ac5e4979c3afa737fd328',
|
|
'signers': ['Eb3907eCad74a0013c259D5874AE7f22DcBcC95C']}],
|
|
'symbol': 'GFT'},
|
|
{'address': '9c9506cf6c50f5b0371be72920fc6060d1a88a6a',
|
|
'converters': [],
|
|
'decimals': 6,
|
|
'name': 'Coffee',
|
|
'proofs': ['5b1549818725ca07c19fc47fda5d8d85bbebb1283855d5ab99785dcb7d9051d3'],
|
|
'proofs_with_signers': [{'proof': '5b1549818725ca07c19fc47fda5d8d85bbebb1283855d5ab99785dcb7d9051d3',
|
|
'signers': ['Eb3907eCad74a0013c259D5874AE7f22DcBcC95C',
|
|
'Eb3907eCad74a0013c259D5874AE7f22DcBcC95C']}],
|
|
'symbol': 'COFE'},
|
|
]
|
|
|
|
|
|
def test_account():
|
|
# Default Token
|
|
response = client.get('/default_token')
|
|
log.debug(f"balance response {response}")
|
|
default_token = response.json()
|
|
|
|
# Create Account 1
|
|
params = {
|
|
'password': '',
|
|
'register': True
|
|
}
|
|
response = client.post(
|
|
'/create_account',
|
|
params=params)
|
|
address_1 = hexathon.valid(response.json())
|
|
|
|
# Create Account 2
|
|
params = {
|
|
'password': '',
|
|
'register': True
|
|
}
|
|
response = client.post('/create_account',
|
|
params=params)
|
|
address_2 = hexathon.valid(response.json())
|
|
time.sleep(30) # Required to allow balance to show
|
|
|
|
# Balance Account 1
|
|
params = {
|
|
'address': address_1,
|
|
'token_symbol': 'COFE',
|
|
'include_pending': True
|
|
}
|
|
response = client.get('/balance',
|
|
params=params)
|
|
balance = response.json()
|
|
|
|
assert (balance[0] == {
|
|
"address": default_token.get('address').lower(),
|
|
"balance_available": 30000,
|
|
"balance_incoming": 0,
|
|
"balance_network": 30000,
|
|
"balance_outgoing": 0,
|
|
"converters": []
|
|
})
|
|
|
|
# Transfer
|
|
params = {
|
|
'from_address': address_1,
|
|
'to_address': address_2,
|
|
'value': 100,
|
|
'token_symbol': 'COFE'
|
|
}
|
|
response = client.post('/transfer',
|
|
params=params)
|
|
transfer = response.json()
|
|
|
|
# Balance Account 1
|
|
params = {
|
|
'address': address_1,
|
|
'token_symbol': 'COFE',
|
|
'include_pending': True
|
|
}
|
|
response = client.get('/balance',
|
|
params=params)
|
|
balance_after_transfer = response.json()
|
|
assert (balance_after_transfer[0] == {
|
|
"address": default_token.get('address').lower(),
|
|
"balance_available": 29900,
|
|
"balance_incoming": 0,
|
|
"balance_network": 30000,
|
|
"balance_outgoing": 100,
|
|
"converters": []
|
|
})
|
|
|
|
# Transactions Account 1
|
|
params = {
|
|
'address': address_1,
|
|
'limit': 10
|
|
}
|
|
response = client.get('/transactions',
|
|
params=params)
|
|
transactions = response.json()
|
|
# TODO: What are the other 2 transactions
|
|
assert len(transactions) == 3
|
|
# Check the transaction is correct
|
|
# TODO wtf is READSEND (Ready to send? Or already sent)
|
|
assert transactions[0].status == 'READYSEND'
|