cic-internal-integration/apps/cic-eth/tests/server/test_account_controller.py

160 lines
4.4 KiB
Python

# coding: utf-8
from __future__ import absolute_import
import logging
import time
import hexathon
import pytest
from cic_eth.server.app import create_app
log = logging.getLogger(__name__)
@pytest.fixture
def client():
log.debug("Here")
app = create_app({'TESTING': True})
with app.app.test_client() as client:
# with app.app_context():
# init_db()
yield client
def test_account(client):
# Default Token
query_string = []
response = client.open(
'/token',
method='GET',
query_string=query_string)
default_token = response.get_json()
# Create Account 1
query_string = [('password', ''),
('register', True)]
response = client.open(
'/create_account',
method='POST',
query_string=query_string)
address_1 = hexathon.valid(response.get_json())
# Create Account 2
query_string = [('password', ''),
('register', True)]
response = client.open(
'/create_account',
method='POST',
query_string=query_string)
address_2 = hexathon.valid(response.get_json())
time.sleep(30) # Required to allow balance to show
# Balance Account 1
query_string = [('address', address_1),
('token_symbol', 'COFE'),
('include_pending', True)]
response = client.open(
'/balance',
method='GET',
query_string=query_string)
balance = response.get_json()
assert (balance[0] == {
"address": default_token.get('address').lower(),
"balance_available": 30000000000,
"balance_incoming": 0,
"balance_network": 30000000000,
"balance_outgoing": 0,
"converters": []
})
# Transfer
query_string = [('from_address', address_1),
('to_address', address_2),
('value', 100),
('token_symbol', 'COFE')]
response = client.open(
'/transfer',
method='POST',
query_string=query_string)
transfer = response.get_json()
# Balance Account 1
query_string = [('address', address_1),
('token_symbol', 'COFE'),
('include_pending', True)]
response = client.open(
'/balance',
method='GET',
query_string=query_string)
balance_after_transfer = response.get_json()
assert (balance_after_transfer[0] == {
"address": default_token.get('address').lower(),
"balance_available": 29900000000,
"balance_incoming": 0,
"balance_network": 30000000000,
"balance_outgoing": 100000000,
"converters": []
})
# Transactions Account 1
query_string = [('address', address_1),
('limit', 10)]
response = client.open(
'/transactions',
method='GET',
query_string=query_string)
transactions = response.get_json()
log.debug(transactions)
exit(1)
# def test_list_transactions(client):
# """Test case for list_transactions
# """
# query_string = [('address', "test_address"),
# ('limit', 10)]
# response = client.open(
# '/transactions',
# method='GET',
# query_string=query_string)
# self.assert200(response,
# 'Response body is : ' + response.data.decode('utf-8'))
# def test_transfer(client):
# """Test case for transfer
# """
# query_string = [('from_address', "test_address"),
# ('to_address', "test_address"),
# ('value', 56),
# ('token_symbol', 'token_symbol_example')]
# response = client.open(
# '/transfer',
# method='POST',
# query_string=query_string)
# self.assert200(response,
# 'Response body is : ' + response.data.decode('utf-8'))
# def test_transfer_from(client):
# """Test case for transfer_from
# """
# query_string = [('from_address', "test_address"),
# ('to_address', "test_address"),
# ('value', 56),
# ('token_symbol', 'token_symbol_example'),
# ('spender_address', "test_address")]
# response = client.open(
# '/transfer_from',
# method='POST',
# query_string=query_string)
# self.assert200(response,
# 'Response body is : ' + response.data.decode('utf-8'))