mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00

There was a problem related to the import of the module `bigchaindb.web.views`. The module, when imported, inizialises a new `Bigchain` instance, and this is wrong for testing and because it's a bad practice. I spent more or less 2h finding out the problem.
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
import json
|
|
|
|
import pytest
|
|
from bigchaindb import crypto
|
|
from bigchaindb import util
|
|
|
|
|
|
TX_ENDPOINT = '/api/v1/transactions/'
|
|
|
|
|
|
@pytest.mark.usefixtures('inputs')
|
|
def test_get_transaction_endpoint(b, client, user_public_key):
|
|
input_tx = b.get_owned_ids(user_public_key).pop()
|
|
tx = b.get_transaction(input_tx)
|
|
res = client.get(TX_ENDPOINT + input_tx)
|
|
assert tx == res.json
|
|
|
|
|
|
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_ENDPOINT, 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_ENDPOINT, 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_ENDPOINT, data=json.dumps(transfer))
|
|
|
|
assert res.json['transaction']['current_owner'] == from_keypair[1]
|
|
assert res.json['transaction']['new_owner'] == to_keypair[1]
|
|
|