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

* Planning release * Clean up after move * Add exceptions.py * Add crypto.py * Adjust setup to package structure * Fix tests * Add test coverage * Comply to flake8 * Add test coverage * Transfer-tx fulfillments validation * Remove condition and fulfillment ids * Fix signing logic Specifically for transfer-tx with multiple inputs and outputs. * Compliance to legacy BDB models * Adjust fulfillment validation interface * Add serialization validation for txids * Use __eq__ to compare objects * Heavy refactor to comply with current implementation * Add Transaction.create * Correct fulfillment validation logic * Add Transaction.create for hashlock conditions * Add hashlock condition serialization * Transaction.transfer add single input and outputs * Small adjustments to transfer-tx interface * Create transfer-tx interface * Increase test coverage * Adjust fulfillment (de)serialization * Catch CC Error for Fulfillment * Allow custom thresholds * PR feedback * Fix tests * Rename Data to Metadata * Add Asset exceptions * Add basic Asset model * More renaming of payload => data * Add Asset into work-flow-functions * Add Asset amount to condition * add fulfillment exception * initial integration of asset * Make transaction.py compy to 79 chars * Make util.py comply to 79 chars * Make exceptions.py comply to 80 chars * Renaming inp to input_ * fix pep8 issues * Correct raised error * Remove resolved TODOs * prevent adding None as fulfillment / condition to Transaction * Small modifications to support new cryptoconditions * Improve documentation (#42) * Add doc strings for Fulfillment cls * Add doc strings for TransactionLink cls * Add doc strings for Condition cls * Add doc strings for Data cls * Add doc strings for Transaction cls * Add doc strings for Asset cls * Extract common implementation * Tx model: Add test for empty inputs * WIP: Implement sign tx * Add tests for: - Conditions; and - Fulfillments Mostly on the (de)serialization part. * Finalize serialization logic for tx class * Add Tests for tx serialization logic * Add fulfillment validation * Add ThresholdCondition support * WIP transfer * Clean up after move * Adjust setup to package structure * Fix tests * Add test coverage * Add test coverage * Transfer-tx fulfillments validation * Remove condition and fulfillment ids * Fix signing logic Specifically for transfer-tx with multiple inputs and outputs. * Fix test case * Compliance to legacy BDB models * Adjust fulfillment validation interface * Add serialization validation for txids * Use __eq__ to compare objects * Heavy refactor to comply with current implementation * Add Transaction.create * Add validation tests * Add Transaction.create for hashlock conditions * Add hashlock condition serialization * Transaction.transfer add single input and outputs * Small adjustments to transfer-tx interface * Create transfer-tx interface * Increase test coverage * Adjust fulfillment (de)serialization * Catch CC Error for Fulfillment * Allow custom thresholds * Rename Data to Metadata * Add basic Asset model * Add Asset into work-flow-functions * Add Asset amount to condition * initial integration of asset * Make tests comply to 79 chars per line * Fixed tests * fix pep8 issues * Correct raised error * Add test for asset initialization * Remove resolved TODOs * prevent adding None as fulfillment / condition to Transaction * Small modifications to support new cryptoconditions * Extract common tests * Copy conftest from bigchaindb-common - by @timdaub * Replace bigchaindb_common pkg by bigchaindb.common
123 lines
4.1 KiB
Python
123 lines
4.1 KiB
Python
import json
|
|
|
|
import pytest
|
|
from bigchaindb.common import crypto
|
|
|
|
|
|
TX_ENDPOINT = '/api/v1/transactions/'
|
|
|
|
|
|
@pytest.mark.usefixtures('inputs')
|
|
def test_get_transaction_endpoint(b, client, user_vk):
|
|
input_tx = b.get_owned_ids(user_vk).pop()
|
|
tx = b.get_transaction(input_tx.txid)
|
|
res = client.get(TX_ENDPOINT + tx.id)
|
|
assert tx.to_dict() == res.json
|
|
assert res.status_code == 200
|
|
|
|
|
|
@pytest.mark.usefixtures('inputs')
|
|
def test_get_transaction_returns_404_if_not_found(client):
|
|
res = client.get(TX_ENDPOINT + '123')
|
|
assert res.status_code == 404
|
|
|
|
res = client.get(TX_ENDPOINT + '123/')
|
|
assert res.status_code == 404
|
|
|
|
|
|
def test_api_endpoint_shows_basic_info(client):
|
|
from bigchaindb import version
|
|
res = client.get('/')
|
|
assert res.json['software'] == 'BigchainDB'
|
|
assert res.json['version'] == version.__version__
|
|
|
|
|
|
def test_post_create_transaction_endpoint(b, client):
|
|
from bigchaindb.models import Transaction
|
|
user_priv, user_pub = crypto.generate_key_pair()
|
|
|
|
tx = Transaction.create([user_pub], [user_pub])
|
|
tx = tx.sign([user_priv])
|
|
|
|
res = client.post(TX_ENDPOINT, data=json.dumps(tx.to_dict()))
|
|
assert res.json['transaction']['fulfillments'][0]['owners_before'][0] == user_pub
|
|
assert res.json['transaction']['conditions'][0]['owners_after'][0] == user_pub
|
|
|
|
|
|
def test_post_create_transaction_with_invalid_id(b, client):
|
|
from bigchaindb.models import Transaction
|
|
user_priv, user_pub = crypto.generate_key_pair()
|
|
|
|
tx = Transaction.create([user_pub], [user_pub])
|
|
tx = tx.sign([user_priv]).to_dict()
|
|
tx['id'] = 'invalid id'
|
|
|
|
res = client.post(TX_ENDPOINT, data=json.dumps(tx))
|
|
assert res.status_code == 400
|
|
|
|
|
|
def test_post_create_transaction_with_invalid_signature(b, client):
|
|
from bigchaindb.models import Transaction
|
|
user_priv, user_pub = crypto.generate_key_pair()
|
|
|
|
tx = Transaction.create([user_pub], [user_pub])
|
|
tx = tx.sign([user_priv]).to_dict()
|
|
tx['transaction']['fulfillments'][0]['fulfillment'] = 'invalid signature'
|
|
|
|
res = client.post(TX_ENDPOINT, data=json.dumps(tx))
|
|
assert res.status_code == 400
|
|
|
|
|
|
@pytest.mark.usefixtures('inputs')
|
|
def test_post_transfer_transaction_endpoint(b, client, user_vk, user_sk):
|
|
sk, vk = crypto.generate_key_pair()
|
|
from bigchaindb.models import Transaction
|
|
|
|
user_priv, user_pub = crypto.generate_key_pair()
|
|
|
|
input_valid = b.get_owned_ids(user_vk).pop()
|
|
create_tx = b.get_transaction(input_valid.txid)
|
|
transfer_tx = Transaction.transfer(create_tx.to_inputs(), [user_pub], create_tx.asset)
|
|
transfer_tx = transfer_tx.sign([user_sk])
|
|
|
|
res = client.post(TX_ENDPOINT, data=json.dumps(transfer_tx.to_dict()))
|
|
|
|
assert res.json['transaction']['fulfillments'][0]['owners_before'][0] == user_vk
|
|
assert res.json['transaction']['conditions'][0]['owners_after'][0] == user_pub
|
|
|
|
|
|
@pytest.mark.usefixtures('inputs')
|
|
def test_post_invalid_transfer_transaction_returns_400(b, client, user_vk, user_sk):
|
|
from bigchaindb.models import Transaction
|
|
|
|
user_priv, user_pub = crypto.generate_key_pair()
|
|
|
|
input_valid = b.get_owned_ids(user_vk).pop()
|
|
create_tx = b.get_transaction(input_valid.txid)
|
|
transfer_tx = Transaction.transfer(create_tx.to_inputs(), [user_pub], create_tx.asset)
|
|
|
|
res = client.post(TX_ENDPOINT, data=json.dumps(transfer_tx.to_dict()))
|
|
assert res.status_code == 400
|
|
|
|
|
|
@pytest.mark.usefixtures('inputs')
|
|
def test_get_transaction_status_endpoint(b, client, user_vk):
|
|
input_tx = b.get_owned_ids(user_vk).pop()
|
|
tx, status = b.get_transaction(input_tx.txid, include_status=True)
|
|
res = client.get(TX_ENDPOINT + input_tx.txid + "/status")
|
|
assert status == res.json['status']
|
|
assert res.status_code == 200
|
|
|
|
res = client.get(TX_ENDPOINT + input_tx.txid + "/status/")
|
|
assert status == res.json['status']
|
|
assert res.status_code == 200
|
|
|
|
|
|
@pytest.mark.usefixtures('inputs')
|
|
def test_get_transaction_status_returns_404_if_not_found(client):
|
|
res = client.get(TX_ENDPOINT + '123' + "/status")
|
|
assert res.status_code == 404
|
|
|
|
res = client.get(TX_ENDPOINT + '123' + "/status/")
|
|
assert res.status_code == 404
|