cic-internal-integration/apps/cic-eth/tests/test_server.py
2021-12-02 15:07:49 +03:00

120 lines
3.0 KiB
Python

# coding: utf-8
from __future__ import absolute_import
import logging
import time
import hexathon
import pytest
import requests
from cic_eth.runnable.daemons.server import application
from pytest_localserver.http import WSGIServer
log = logging.getLogger(__name__)
@pytest.fixture
def testserver(request):
"""Defines the testserver funcarg"""
server = WSGIServer(application=application)
server.start()
request.addfinalizer(server.stop)
return server
def test_account(testserver):
# Default Token
response = requests.get(
testserver.url + '/default_token',
)
log.debug(f"balance response {response}")
default_token = response.json()
# Create Account 1
params = {
'password': '',
'register': True
}
response = requests.post(
testserver.url + '/create_account',
params=params)
address_1 = hexathon.valid(response.json())
# Create Account 2
params = {
'password': '',
'register': True
}
response = requests.post(
testserver.url + '/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 = requests.get(
testserver.url + '/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 = requests.post(
testserver.url + '/transfer',
params=params)
transfer = response.json()
# Balance Account 1
params = {
'address': address_1,
'token_symbol': 'COFE',
'include_pending': True
}
response = requests.get(
testserver.url + '/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 = requests.get(
testserver.url + '/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'
exit(1) # Forcing it to fail to i get logs out of pytest