bigchaindb/tests/web/test_basic_views.py

41 lines
1.3 KiB
Python
Raw Normal View History

2016-02-24 02:38:30 +01:00
import json
2016-02-23 03:37:33 +01:00
import pytest
2016-02-24 02:38:30 +01:00
from bigchaindb import crypto
from bigchaindb import util
2016-02-23 03:37:33 +01:00
@pytest.mark.usefixtures('inputs')
2016-02-24 02:38:30 +01:00
def test_get_transaction_endpoint(b, client, user_public_key):
2016-02-23 03:37:33 +01:00
input_tx = b.get_owned_ids(user_public_key).pop()
tx = b.get_transaction(input_tx)
res = client.get('/tx/{}'.format(input_tx))
assert tx == res.json
2016-02-24 02:38:30 +01:00
def test_post_create_transaction_endpoint(b, client):
keypair = crypto.generate_key_pair()
tx = util.create_and_sign_tx(keypair[0], keypair[1], keypair[1], None, 'CREATE')
res = client.post('/tx/', data=json.dumps(tx))
assert res.json['transaction']['current_owner'] == b.me
assert res.json['transaction']['new_owner'] == keypair[1]
def test_post_transfer_transaction_endpoint(b, client):
from_keypair = crypto.generate_key_pair()
to_keypair = crypto.generate_key_pair()
tx = util.create_and_sign_tx(from_keypair[0], from_keypair[1], from_keypair[1], None, 'CREATE')
res = client.post('/tx/', data=json.dumps(tx))
tx_id = res.json['id']
transfer = util.create_and_sign_tx(from_keypair[0], from_keypair[1], to_keypair[1], tx_id)
res = client.post('/tx/', data=json.dumps(transfer))
assert res.json['transaction']['current_owner'] == from_keypair[1]
assert res.json['transaction']['new_owner'] == to_keypair[1]