2018-08-16 12:31:32 +02:00
|
|
|
# Copyright BigchainDB GmbH and BigchainDB contributors
|
|
|
|
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
|
|
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
|
|
|
|
2017-06-14 18:42:07 +02:00
|
|
|
from unittest.mock import patch
|
2016-10-10 09:41:49 +02:00
|
|
|
|
2016-02-10 19:55:33 +01:00
|
|
|
import pytest
|
2017-06-14 18:42:07 +02:00
|
|
|
from base58 import b58decode
|
2016-02-10 19:55:33 +01:00
|
|
|
|
2016-12-18 08:32:10 +01:00
|
|
|
pytestmark = pytest.mark.bdb
|
|
|
|
|
2016-02-10 19:55:33 +01:00
|
|
|
|
|
|
|
class TestBigchainApi(object):
|
2016-12-20 05:00:21 +01:00
|
|
|
|
2018-08-13 09:54:45 +02:00
|
|
|
def test_get_spent_with_double_spend_detected(self, b, alice):
|
2017-03-03 13:48:52 +01:00
|
|
|
from bigchaindb.models import Transaction
|
2018-08-13 09:54:45 +02:00
|
|
|
from bigchaindb.common.exceptions import DoubleSpend
|
|
|
|
from bigchaindb.exceptions import CriticalDoubleSpend
|
2017-03-03 13:48:52 +01:00
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
tx = Transaction.create([alice.public_key], [([alice.public_key], 1)])
|
|
|
|
tx = tx.sign([alice.private_key])
|
2017-03-03 13:48:52 +01:00
|
|
|
|
2018-08-13 09:54:45 +02:00
|
|
|
b.store_bulk_transactions([tx])
|
2017-03-03 13:48:52 +01:00
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
transfer_tx = Transaction.transfer(tx.to_inputs(), [([alice.public_key], 1)],
|
2017-03-03 13:48:52 +01:00
|
|
|
asset_id=tx.id)
|
2018-06-08 15:50:50 +02:00
|
|
|
transfer_tx = transfer_tx.sign([alice.private_key])
|
|
|
|
transfer_tx2 = Transaction.transfer(tx.to_inputs(), [([alice.public_key], 2)],
|
2017-03-03 13:48:52 +01:00
|
|
|
asset_id=tx.id)
|
2018-06-08 15:50:50 +02:00
|
|
|
transfer_tx2 = transfer_tx2.sign([alice.private_key])
|
2017-03-03 13:48:52 +01:00
|
|
|
|
2018-08-13 09:54:45 +02:00
|
|
|
with pytest.raises(DoubleSpend):
|
|
|
|
b.validate_transaction(transfer_tx2, [transfer_tx])
|
|
|
|
|
|
|
|
b.store_bulk_transactions([transfer_tx])
|
|
|
|
|
|
|
|
with pytest.raises(DoubleSpend):
|
|
|
|
b.validate_transaction(transfer_tx2)
|
|
|
|
|
|
|
|
b.store_bulk_transactions([transfer_tx2])
|
2017-03-03 13:48:52 +01:00
|
|
|
|
|
|
|
with pytest.raises(CriticalDoubleSpend):
|
2016-09-29 10:29:41 +02:00
|
|
|
b.get_spent(tx.id, 0)
|
2016-04-08 10:56:45 +02:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
def test_double_inclusion(self, b, alice):
|
2016-09-29 10:29:41 +02:00
|
|
|
from bigchaindb.models import Transaction
|
2018-08-13 09:54:45 +02:00
|
|
|
from bigchaindb.backend.exceptions import OperationError
|
2016-04-07 15:41:06 +02:00
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
tx = Transaction.create([alice.public_key], [([alice.public_key], 1)])
|
|
|
|
tx = tx.sign([alice.private_key])
|
2016-09-29 10:29:41 +02:00
|
|
|
|
2018-08-13 09:54:45 +02:00
|
|
|
b.store_bulk_transactions([tx])
|
2016-09-29 10:29:41 +02:00
|
|
|
|
2018-08-13 09:54:45 +02:00
|
|
|
with pytest.raises(OperationError):
|
|
|
|
b.store_bulk_transactions([tx])
|
2016-04-07 15:41:06 +02:00
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
def test_text_search(self, b, alice):
|
2017-05-24 11:38:15 +02:00
|
|
|
from bigchaindb.models import Transaction
|
|
|
|
|
|
|
|
# define the assets
|
|
|
|
asset1 = {'msg': 'BigchainDB 1'}
|
|
|
|
asset2 = {'msg': 'BigchainDB 2'}
|
|
|
|
asset3 = {'msg': 'BigchainDB 3'}
|
|
|
|
|
|
|
|
# create the transactions
|
2018-06-08 15:50:50 +02:00
|
|
|
tx1 = Transaction.create([alice.public_key], [([alice.public_key], 1)],
|
|
|
|
asset=asset1).sign([alice.private_key])
|
|
|
|
tx2 = Transaction.create([alice.public_key], [([alice.public_key], 1)],
|
|
|
|
asset=asset2).sign([alice.private_key])
|
|
|
|
tx3 = Transaction.create([alice.public_key], [([alice.public_key], 1)],
|
|
|
|
asset=asset3).sign([alice.private_key])
|
2017-05-24 11:38:15 +02:00
|
|
|
|
2018-08-13 09:54:45 +02:00
|
|
|
# write the transactions to the DB
|
|
|
|
b.store_bulk_transactions([tx1, tx2, tx3])
|
2017-05-24 11:38:15 +02:00
|
|
|
|
|
|
|
# get the assets through text search
|
2018-08-22 09:56:44 +02:00
|
|
|
assets = list(b.text_search('bigchaindb'))
|
|
|
|
assert len(assets) == 3
|
2017-05-24 11:38:15 +02:00
|
|
|
|
2016-08-24 13:34:08 +02:00
|
|
|
@pytest.mark.usefixtures('inputs')
|
2016-11-10 17:20:27 +01:00
|
|
|
def test_non_create_input_not_found(self, b, user_pk):
|
2017-06-14 18:42:07 +02:00
|
|
|
from cryptoconditions import Ed25519Sha256
|
2017-03-08 13:01:52 +01:00
|
|
|
from bigchaindb.common.exceptions import InputDoesNotExist
|
2016-12-22 13:45:02 +01:00
|
|
|
from bigchaindb.common.transaction import Input, TransactionLink
|
2016-10-07 15:46:21 +02:00
|
|
|
from bigchaindb.models import Transaction
|
2016-08-24 13:34:08 +02:00
|
|
|
|
2016-12-13 13:41:46 +01:00
|
|
|
# Create an input for a non existing transaction
|
2017-06-14 18:42:07 +02:00
|
|
|
input = Input(Ed25519Sha256(public_key=b58decode(user_pk)),
|
2016-12-13 13:41:46 +01:00
|
|
|
[user_pk],
|
|
|
|
TransactionLink('somethingsomething', 0))
|
2016-12-22 13:45:02 +01:00
|
|
|
tx = Transaction.transfer([input], [([user_pk], 1)],
|
2016-12-22 10:19:21 +01:00
|
|
|
asset_id='mock_asset_link')
|
2017-03-08 13:01:52 +01:00
|
|
|
with pytest.raises(InputDoesNotExist):
|
2018-08-13 09:54:45 +02:00
|
|
|
tx.validate(b)
|
2016-08-24 13:34:08 +02:00
|
|
|
|
2018-08-13 09:54:45 +02:00
|
|
|
def test_write_transaction(self, b, user_sk, user_pk, alice, create_tx):
|
2016-11-14 10:03:59 +01:00
|
|
|
from bigchaindb.models import Transaction
|
|
|
|
|
2018-08-13 09:54:45 +02:00
|
|
|
asset1 = {'msg': 'BigchainDB 1'}
|
|
|
|
|
|
|
|
tx = Transaction.create([alice.public_key], [([alice.public_key], 1)],
|
|
|
|
asset=asset1).sign([alice.private_key])
|
|
|
|
b.store_bulk_transactions([tx])
|
|
|
|
|
|
|
|
tx_from_db = b.get_transaction(tx.id)
|
|
|
|
|
|
|
|
before = tx.to_dict()
|
|
|
|
after = tx_from_db.to_dict()
|
2016-11-14 10:03:59 +01:00
|
|
|
|
2018-08-13 09:54:45 +02:00
|
|
|
assert before['asset']['data'] == after['asset']['data']
|
|
|
|
before.pop('asset', None)
|
|
|
|
after.pop('asset', None)
|
|
|
|
assert before == after
|
2016-11-14 10:03:59 +01:00
|
|
|
|
2016-08-24 13:34:08 +02:00
|
|
|
|
2016-09-29 10:29:41 +02:00
|
|
|
class TestTransactionValidation(object):
|
2018-08-22 09:56:44 +02:00
|
|
|
|
|
|
|
def test_non_create_input_not_found(self, b, signed_transfer_tx):
|
2017-03-08 13:01:52 +01:00
|
|
|
from bigchaindb.common.exceptions import InputDoesNotExist
|
2016-10-24 17:01:43 +02:00
|
|
|
from bigchaindb.common.transaction import TransactionLink
|
2016-02-10 19:55:33 +01:00
|
|
|
|
2016-12-13 13:41:46 +01:00
|
|
|
signed_transfer_tx.inputs[0].fulfills = TransactionLink('c', 0)
|
2017-03-08 13:01:52 +01:00
|
|
|
with pytest.raises(InputDoesNotExist):
|
2016-09-29 10:29:41 +02:00
|
|
|
b.validate_transaction(signed_transfer_tx)
|
2016-02-10 19:55:33 +01:00
|
|
|
|
2016-02-13 03:59:01 +01:00
|
|
|
@pytest.mark.usefixtures('inputs')
|
2016-11-10 17:20:27 +01:00
|
|
|
def test_non_create_valid_input_wrong_owner(self, b, user_pk):
|
2016-10-24 17:01:43 +02:00
|
|
|
from bigchaindb.common.crypto import generate_key_pair
|
|
|
|
from bigchaindb.common.exceptions import InvalidSignature
|
2016-09-29 10:29:41 +02:00
|
|
|
from bigchaindb.models import Transaction
|
2016-02-10 19:55:33 +01:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
input_tx = b.fastquery.get_outputs_by_public_key(user_pk).pop()
|
2016-10-12 10:29:25 +02:00
|
|
|
input_transaction = b.get_transaction(input_tx.txid)
|
2016-11-10 17:20:27 +01:00
|
|
|
sk, pk = generate_key_pair()
|
2016-11-17 11:41:23 +01:00
|
|
|
tx = Transaction.create([pk], [([user_pk], 1)])
|
2016-09-29 10:29:41 +02:00
|
|
|
tx.operation = 'TRANSFER'
|
2016-12-22 10:19:21 +01:00
|
|
|
tx.asset = {'id': input_transaction.id}
|
2016-12-13 13:41:46 +01:00
|
|
|
tx.inputs[0].fulfills = input_tx
|
2016-04-14 16:13:57 +02:00
|
|
|
|
2016-09-29 10:29:41 +02:00
|
|
|
with pytest.raises(InvalidSignature):
|
|
|
|
b.validate_transaction(tx)
|
2016-04-14 16:13:57 +02:00
|
|
|
|
2016-10-10 09:41:49 +02:00
|
|
|
@pytest.mark.usefixtures('inputs')
|
2016-09-29 10:29:41 +02:00
|
|
|
def test_non_create_double_spend(self, b, signed_create_tx,
|
2017-11-25 01:04:50 +01:00
|
|
|
signed_transfer_tx, double_spend_tx):
|
2016-10-24 17:01:43 +02:00
|
|
|
from bigchaindb.common.exceptions import DoubleSpend
|
2016-02-10 19:55:33 +01:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
b.store_bulk_transactions([signed_create_tx, signed_transfer_tx])
|
2016-10-10 09:41:49 +02:00
|
|
|
|
2016-09-29 10:29:41 +02:00
|
|
|
with pytest.raises(DoubleSpend):
|
2017-11-25 01:04:50 +01:00
|
|
|
b.validate_transaction(double_spend_tx)
|
2016-02-10 19:55:33 +01:00
|
|
|
|
|
|
|
|
2016-03-22 19:30:53 +01:00
|
|
|
class TestMultipleInputs(object):
|
2018-08-22 09:56:44 +02:00
|
|
|
|
2016-11-10 17:20:27 +01:00
|
|
|
def test_transfer_single_owner_single_input(self, b, inputs, user_pk,
|
2016-09-29 10:29:41 +02:00
|
|
|
user_sk):
|
2016-10-24 17:01:43 +02:00
|
|
|
from bigchaindb.common import crypto
|
2016-09-29 10:29:41 +02:00
|
|
|
from bigchaindb.models import Transaction
|
2018-08-22 09:56:44 +02:00
|
|
|
|
2016-11-10 17:20:27 +01:00
|
|
|
user2_sk, user2_pk = crypto.generate_key_pair()
|
2016-04-13 17:44:25 +02:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
tx_link = b.fastquery.get_outputs_by_public_key(user_pk).pop()
|
2016-09-29 10:29:41 +02:00
|
|
|
input_tx = b.get_transaction(tx_link.txid)
|
|
|
|
inputs = input_tx.to_inputs()
|
2016-12-20 17:28:15 +01:00
|
|
|
tx = Transaction.transfer(inputs, [([user2_pk], 1)],
|
2016-12-22 10:19:21 +01:00
|
|
|
asset_id=input_tx.id)
|
2016-09-29 10:29:41 +02:00
|
|
|
tx = tx.sign([user_sk])
|
2016-04-13 17:44:25 +02:00
|
|
|
|
|
|
|
# validate transaction
|
2017-03-03 11:36:50 +01:00
|
|
|
tx.validate(b)
|
2016-12-13 13:41:46 +01:00
|
|
|
assert len(tx.inputs) == 1
|
|
|
|
assert len(tx.outputs) == 1
|
2016-04-13 17:44:25 +02:00
|
|
|
|
2016-09-29 10:29:41 +02:00
|
|
|
def test_single_owner_before_multiple_owners_after_single_input(self, b,
|
|
|
|
user_sk,
|
2016-11-10 17:20:27 +01:00
|
|
|
user_pk,
|
2016-09-29 10:29:41 +02:00
|
|
|
inputs):
|
2016-10-24 17:01:43 +02:00
|
|
|
from bigchaindb.common import crypto
|
2016-09-29 10:29:41 +02:00
|
|
|
from bigchaindb.models import Transaction
|
2016-04-13 17:44:25 +02:00
|
|
|
|
2016-11-10 17:20:27 +01:00
|
|
|
user2_sk, user2_pk = crypto.generate_key_pair()
|
|
|
|
user3_sk, user3_pk = crypto.generate_key_pair()
|
2018-08-22 09:56:44 +02:00
|
|
|
tx_link = b.fastquery.get_outputs_by_public_key(user_pk).pop()
|
2016-04-13 17:44:25 +02:00
|
|
|
|
2016-10-07 15:46:21 +02:00
|
|
|
input_tx = b.get_transaction(tx_link.txid)
|
2016-11-09 13:32:18 +01:00
|
|
|
tx = Transaction.transfer(input_tx.to_inputs(),
|
2016-12-20 17:28:15 +01:00
|
|
|
[([user2_pk, user3_pk], 1)],
|
2016-12-22 10:19:21 +01:00
|
|
|
asset_id=input_tx.id)
|
2016-09-29 10:29:41 +02:00
|
|
|
tx = tx.sign([user_sk])
|
2016-04-13 17:44:25 +02:00
|
|
|
|
2017-03-03 11:36:50 +01:00
|
|
|
tx.validate(b)
|
2016-12-13 13:41:46 +01:00
|
|
|
assert len(tx.inputs) == 1
|
|
|
|
assert len(tx.outputs) == 1
|
2016-04-13 17:44:25 +02:00
|
|
|
|
2016-10-10 09:41:49 +02:00
|
|
|
@pytest.mark.usefixtures('inputs')
|
2016-09-29 10:29:41 +02:00
|
|
|
def test_multiple_owners_before_single_owner_after_single_input(self, b,
|
|
|
|
user_sk,
|
2018-06-08 15:50:50 +02:00
|
|
|
user_pk,
|
|
|
|
alice):
|
2016-10-24 17:01:43 +02:00
|
|
|
from bigchaindb.common import crypto
|
2016-09-29 10:29:41 +02:00
|
|
|
from bigchaindb.models import Transaction
|
2016-04-13 17:44:25 +02:00
|
|
|
|
2016-11-10 17:20:27 +01:00
|
|
|
user2_sk, user2_pk = crypto.generate_key_pair()
|
|
|
|
user3_sk, user3_pk = crypto.generate_key_pair()
|
2016-04-13 17:44:25 +02:00
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
tx = Transaction.create([alice.public_key], [([user_pk, user2_pk], 1)])
|
|
|
|
tx = tx.sign([alice.private_key])
|
2018-08-22 09:56:44 +02:00
|
|
|
b.store_bulk_transactions([tx])
|
2016-10-10 09:41:49 +02:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
owned_input = b.fastquery.get_outputs_by_public_key(user_pk).pop()
|
2016-09-29 10:29:41 +02:00
|
|
|
input_tx = b.get_transaction(owned_input.txid)
|
|
|
|
inputs = input_tx.to_inputs()
|
2016-04-14 12:22:26 +02:00
|
|
|
|
2016-11-17 11:41:23 +01:00
|
|
|
transfer_tx = Transaction.transfer(inputs, [([user3_pk], 1)],
|
2016-12-22 10:19:21 +01:00
|
|
|
asset_id=input_tx.id)
|
2016-09-29 10:29:41 +02:00
|
|
|
transfer_tx = transfer_tx.sign([user_sk, user2_sk])
|
2016-04-14 12:22:26 +02:00
|
|
|
|
|
|
|
# validate transaction
|
2017-03-03 11:36:50 +01:00
|
|
|
transfer_tx.validate(b)
|
2016-12-13 13:41:46 +01:00
|
|
|
assert len(transfer_tx.inputs) == 1
|
|
|
|
assert len(transfer_tx.outputs) == 1
|
2016-09-29 10:29:41 +02:00
|
|
|
|
2016-10-10 09:41:49 +02:00
|
|
|
@pytest.mark.usefixtures('inputs')
|
2016-09-29 10:29:41 +02:00
|
|
|
def test_multiple_owners_before_multiple_owners_after_single_input(self, b,
|
|
|
|
user_sk,
|
2018-06-08 15:50:50 +02:00
|
|
|
user_pk,
|
|
|
|
alice):
|
2016-10-24 17:01:43 +02:00
|
|
|
from bigchaindb.common import crypto
|
2016-09-29 10:29:41 +02:00
|
|
|
from bigchaindb.models import Transaction
|
2016-04-13 17:44:25 +02:00
|
|
|
|
2016-11-10 17:20:27 +01:00
|
|
|
user2_sk, user2_pk = crypto.generate_key_pair()
|
|
|
|
user3_sk, user3_pk = crypto.generate_key_pair()
|
|
|
|
user4_sk, user4_pk = crypto.generate_key_pair()
|
2016-04-12 12:18:36 +02:00
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
tx = Transaction.create([alice.public_key], [([user_pk, user2_pk], 1)])
|
|
|
|
tx = tx.sign([alice.private_key])
|
2018-08-22 09:56:44 +02:00
|
|
|
b.store_bulk_transactions([tx])
|
2016-10-10 09:41:49 +02:00
|
|
|
|
|
|
|
# get input
|
2018-08-22 09:56:44 +02:00
|
|
|
tx_link = b.fastquery.get_outputs_by_public_key(user_pk).pop()
|
2016-10-07 15:46:21 +02:00
|
|
|
tx_input = b.get_transaction(tx_link.txid)
|
2016-04-14 12:22:26 +02:00
|
|
|
|
2016-11-09 13:32:18 +01:00
|
|
|
tx = Transaction.transfer(tx_input.to_inputs(),
|
2016-12-20 17:28:15 +01:00
|
|
|
[([user3_pk, user4_pk], 1)],
|
2016-12-22 10:19:21 +01:00
|
|
|
asset_id=tx_input.id)
|
2016-09-29 10:29:41 +02:00
|
|
|
tx = tx.sign([user_sk, user2_sk])
|
2016-04-14 12:22:26 +02:00
|
|
|
|
2017-03-03 11:36:50 +01:00
|
|
|
tx.validate(b)
|
2016-12-13 13:41:46 +01:00
|
|
|
assert len(tx.inputs) == 1
|
|
|
|
assert len(tx.outputs) == 1
|
2016-09-29 10:29:41 +02:00
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
def test_get_owned_ids_single_tx_single_output(self, b, user_sk, user_pk, alice):
|
2016-10-24 17:01:43 +02:00
|
|
|
from bigchaindb.common import crypto
|
2016-12-22 10:19:21 +01:00
|
|
|
from bigchaindb.common.transaction import TransactionLink
|
2016-09-29 10:29:41 +02:00
|
|
|
from bigchaindb.models import Transaction
|
|
|
|
|
2016-11-10 17:20:27 +01:00
|
|
|
user2_sk, user2_pk = crypto.generate_key_pair()
|
2016-04-14 12:22:26 +02:00
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
tx = Transaction.create([alice.public_key], [([user_pk], 1)])
|
|
|
|
tx = tx.sign([alice.private_key])
|
2018-08-22 09:56:44 +02:00
|
|
|
b.store_bulk_transactions([tx])
|
2016-05-19 16:27:04 +02:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk)
|
|
|
|
owned_inputs_user2 = b.fastquery.get_outputs_by_public_key(user2_pk)
|
2016-09-29 10:29:41 +02:00
|
|
|
assert owned_inputs_user1 == [TransactionLink(tx.id, 0)]
|
2016-05-19 16:27:04 +02:00
|
|
|
assert owned_inputs_user2 == []
|
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
tx_transfer = Transaction.transfer(tx.to_inputs(), [([user2_pk], 1)],
|
|
|
|
asset_id=tx.id)
|
|
|
|
tx_transfer = tx_transfer.sign([user_sk])
|
|
|
|
b.store_bulk_transactions([tx_transfer])
|
2016-05-19 16:27:04 +02:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk)
|
|
|
|
owned_inputs_user2 = b.fastquery.get_outputs_by_public_key(user2_pk)
|
2016-05-19 16:27:04 +02:00
|
|
|
|
2016-09-29 10:29:41 +02:00
|
|
|
assert owned_inputs_user1 == [TransactionLink(tx.id, 0)]
|
2018-08-22 09:56:44 +02:00
|
|
|
assert owned_inputs_user2 == [TransactionLink(tx_transfer.id, 0)]
|
2016-05-19 16:27:04 +02:00
|
|
|
|
2016-09-29 10:29:41 +02:00
|
|
|
def test_get_owned_ids_single_tx_multiple_outputs(self, b, user_sk,
|
2018-06-08 15:50:50 +02:00
|
|
|
user_pk, alice):
|
2016-10-24 17:01:43 +02:00
|
|
|
from bigchaindb.common import crypto
|
2016-12-22 10:19:21 +01:00
|
|
|
from bigchaindb.common.transaction import TransactionLink
|
2016-09-29 10:29:41 +02:00
|
|
|
from bigchaindb.models import Transaction
|
|
|
|
|
2016-11-10 17:20:27 +01:00
|
|
|
user2_sk, user2_pk = crypto.generate_key_pair()
|
2016-04-14 12:22:26 +02:00
|
|
|
|
2016-11-09 13:32:18 +01:00
|
|
|
# create divisible asset
|
2018-06-08 15:50:50 +02:00
|
|
|
tx_create = Transaction.create([alice.public_key], [([user_pk], 1), ([user_pk], 1)])
|
|
|
|
tx_create_signed = tx_create.sign([alice.private_key])
|
2018-08-22 09:56:44 +02:00
|
|
|
b.store_bulk_transactions([tx_create_signed])
|
2016-04-14 12:22:26 +02:00
|
|
|
|
|
|
|
# get input
|
2018-08-22 09:56:44 +02:00
|
|
|
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk)
|
|
|
|
owned_inputs_user2 = b.fastquery.get_outputs_by_public_key(user2_pk)
|
2016-04-14 12:22:26 +02:00
|
|
|
|
2016-11-09 13:32:18 +01:00
|
|
|
expected_owned_inputs_user1 = [TransactionLink(tx_create.id, 0),
|
|
|
|
TransactionLink(tx_create.id, 1)]
|
2016-04-14 12:22:26 +02:00
|
|
|
assert owned_inputs_user1 == expected_owned_inputs_user1
|
|
|
|
assert owned_inputs_user2 == []
|
|
|
|
|
2016-11-09 13:32:18 +01:00
|
|
|
# transfer divisible asset divided in two outputs
|
|
|
|
tx_transfer = Transaction.transfer(tx_create.to_inputs(),
|
2016-11-17 11:41:23 +01:00
|
|
|
[([user2_pk], 1), ([user2_pk], 1)],
|
2016-12-22 10:19:21 +01:00
|
|
|
asset_id=tx_create.id)
|
2016-11-09 13:32:18 +01:00
|
|
|
tx_transfer_signed = tx_transfer.sign([user_sk])
|
2018-08-22 09:56:44 +02:00
|
|
|
b.store_bulk_transactions([tx_transfer_signed])
|
2016-04-14 12:22:26 +02:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk)
|
|
|
|
owned_inputs_user2 = b.fastquery.get_outputs_by_public_key(user2_pk)
|
|
|
|
assert owned_inputs_user1 == expected_owned_inputs_user1
|
2016-11-09 13:32:18 +01:00
|
|
|
assert owned_inputs_user2 == [TransactionLink(tx_transfer.id, 0),
|
|
|
|
TransactionLink(tx_transfer.id, 1)]
|
2016-04-14 12:22:26 +02:00
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
def test_get_owned_ids_multiple_owners(self, b, user_sk, user_pk, alice):
|
2016-10-24 17:01:43 +02:00
|
|
|
from bigchaindb.common import crypto
|
2016-12-22 10:19:21 +01:00
|
|
|
from bigchaindb.common.transaction import TransactionLink
|
2016-09-29 10:29:41 +02:00
|
|
|
from bigchaindb.models import Transaction
|
|
|
|
|
2016-11-10 17:20:27 +01:00
|
|
|
user2_sk, user2_pk = crypto.generate_key_pair()
|
|
|
|
user3_sk, user3_pk = crypto.generate_key_pair()
|
2016-04-14 12:22:26 +02:00
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
tx = Transaction.create([alice.public_key], [([user_pk, user2_pk], 1)])
|
|
|
|
tx = tx.sign([alice.private_key])
|
2016-04-14 12:22:26 +02:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
b.store_bulk_transactions([tx])
|
|
|
|
|
|
|
|
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk)
|
|
|
|
owned_inputs_user2 = b.fastquery.get_outputs_by_public_key(user_pk)
|
2016-09-29 10:29:41 +02:00
|
|
|
expected_owned_inputs_user1 = [TransactionLink(tx.id, 0)]
|
|
|
|
|
2016-04-14 12:22:26 +02:00
|
|
|
assert owned_inputs_user1 == owned_inputs_user2
|
|
|
|
assert owned_inputs_user1 == expected_owned_inputs_user1
|
|
|
|
|
2016-12-20 17:28:15 +01:00
|
|
|
tx = Transaction.transfer(tx.to_inputs(), [([user3_pk], 1)],
|
2016-12-22 10:19:21 +01:00
|
|
|
asset_id=tx.id)
|
2016-09-29 10:29:41 +02:00
|
|
|
tx = tx.sign([user_sk, user2_sk])
|
2018-08-22 09:56:44 +02:00
|
|
|
b.store_bulk_transactions([tx])
|
|
|
|
|
|
|
|
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk)
|
|
|
|
owned_inputs_user2 = b.fastquery.get_outputs_by_public_key(user2_pk)
|
|
|
|
spent_user1 = b.get_spent(tx.id, 0)
|
2016-04-14 12:22:26 +02:00
|
|
|
|
|
|
|
assert owned_inputs_user1 == owned_inputs_user2
|
2018-08-22 09:56:44 +02:00
|
|
|
assert not spent_user1
|
2016-04-14 12:22:26 +02:00
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
def test_get_spent_single_tx_single_output(self, b, user_sk, user_pk, alice):
|
2016-10-24 17:01:43 +02:00
|
|
|
from bigchaindb.common import crypto
|
2016-09-29 10:29:41 +02:00
|
|
|
from bigchaindb.models import Transaction
|
|
|
|
|
2016-11-10 17:20:27 +01:00
|
|
|
user2_sk, user2_pk = crypto.generate_key_pair()
|
2016-04-14 14:21:07 +02:00
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
tx = Transaction.create([alice.public_key], [([user_pk], 1)])
|
|
|
|
tx = tx.sign([alice.private_key])
|
2018-08-22 09:56:44 +02:00
|
|
|
b.store_bulk_transactions([tx])
|
2016-04-14 14:21:07 +02:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk).pop()
|
2016-04-14 14:21:07 +02:00
|
|
|
|
|
|
|
# check spents
|
2016-09-29 10:29:41 +02:00
|
|
|
input_txid = owned_inputs_user1.txid
|
2018-08-22 09:56:44 +02:00
|
|
|
spent_inputs_user1 = b.get_spent(input_txid, 0)
|
2016-04-14 14:21:07 +02:00
|
|
|
assert spent_inputs_user1 is None
|
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
# create a transaction and send it
|
2016-12-20 17:28:15 +01:00
|
|
|
tx = Transaction.transfer(tx.to_inputs(), [([user2_pk], 1)],
|
2016-12-22 10:19:21 +01:00
|
|
|
asset_id=tx.id)
|
2016-09-29 10:29:41 +02:00
|
|
|
tx = tx.sign([user_sk])
|
2018-08-22 09:56:44 +02:00
|
|
|
b.store_bulk_transactions([tx])
|
2016-04-14 14:21:07 +02:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
spent_inputs_user1 = b.get_spent(input_txid, 0)
|
2016-09-29 10:29:41 +02:00
|
|
|
assert spent_inputs_user1 == tx
|
2016-03-22 19:30:53 +01:00
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
def test_get_spent_single_tx_multiple_outputs(self, b, user_sk, user_pk, alice):
|
2016-10-24 17:01:43 +02:00
|
|
|
from bigchaindb.common import crypto
|
2016-09-29 10:29:41 +02:00
|
|
|
from bigchaindb.models import Transaction
|
|
|
|
|
2016-04-14 14:21:07 +02:00
|
|
|
# create a new users
|
2016-11-10 17:20:27 +01:00
|
|
|
user2_sk, user2_pk = crypto.generate_key_pair()
|
2016-04-14 14:21:07 +02:00
|
|
|
|
2016-11-09 13:32:18 +01:00
|
|
|
# create a divisible asset with 3 outputs
|
2018-06-08 15:50:50 +02:00
|
|
|
tx_create = Transaction.create([alice.public_key],
|
2016-11-17 11:41:23 +01:00
|
|
|
[([user_pk], 1),
|
|
|
|
([user_pk], 1),
|
2016-12-22 10:19:21 +01:00
|
|
|
([user_pk], 1)])
|
2018-06-08 15:50:50 +02:00
|
|
|
tx_create_signed = tx_create.sign([alice.private_key])
|
2018-08-22 09:56:44 +02:00
|
|
|
b.store_bulk_transactions([tx_create_signed])
|
2016-04-14 14:21:07 +02:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk)
|
2016-04-14 14:21:07 +02:00
|
|
|
|
|
|
|
# check spents
|
2016-09-29 10:29:41 +02:00
|
|
|
for input_tx in owned_inputs_user1:
|
2016-12-15 12:05:02 +01:00
|
|
|
assert b.get_spent(input_tx.txid, input_tx.output) is None
|
2016-04-14 14:21:07 +02:00
|
|
|
|
2016-11-09 13:32:18 +01:00
|
|
|
# transfer the first 2 inputs
|
|
|
|
tx_transfer = Transaction.transfer(tx_create.to_inputs()[:2],
|
2016-11-17 11:41:23 +01:00
|
|
|
[([user2_pk], 1), ([user2_pk], 1)],
|
2016-12-22 10:19:21 +01:00
|
|
|
asset_id=tx_create.id)
|
2016-11-09 13:32:18 +01:00
|
|
|
tx_transfer_signed = tx_transfer.sign([user_sk])
|
2018-08-22 09:56:44 +02:00
|
|
|
b.store_bulk_transactions([tx_transfer_signed])
|
2016-04-14 14:21:07 +02:00
|
|
|
|
|
|
|
# check that used inputs are marked as spent
|
2016-11-09 13:32:18 +01:00
|
|
|
for ffill in tx_create.to_inputs()[:2]:
|
2016-12-15 12:05:02 +01:00
|
|
|
spent_tx = b.get_spent(ffill.fulfills.txid, ffill.fulfills.output)
|
2016-11-09 13:32:18 +01:00
|
|
|
assert spent_tx == tx_transfer_signed
|
2016-04-14 14:21:07 +02:00
|
|
|
|
2016-09-29 10:29:41 +02:00
|
|
|
# check if remaining transaction that was unspent is also perceived
|
|
|
|
# spendable by BigchainDB
|
2016-12-13 13:41:46 +01:00
|
|
|
assert b.get_spent(tx_create.to_inputs()[2].fulfills.txid, 2) is None
|
2016-04-12 12:18:36 +02:00
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
def test_get_spent_multiple_owners(self, b, user_sk, user_pk, alice):
|
2016-10-24 17:01:43 +02:00
|
|
|
from bigchaindb.common import crypto
|
2016-09-29 10:29:41 +02:00
|
|
|
from bigchaindb.models import Transaction
|
|
|
|
|
2016-11-10 17:20:27 +01:00
|
|
|
user2_sk, user2_pk = crypto.generate_key_pair()
|
|
|
|
user3_sk, user3_pk = crypto.generate_key_pair()
|
2016-04-14 14:21:07 +02:00
|
|
|
|
|
|
|
transactions = []
|
2016-09-29 10:29:41 +02:00
|
|
|
for i in range(3):
|
2017-01-17 11:48:58 +01:00
|
|
|
payload = {'somedata': i}
|
2018-06-08 15:50:50 +02:00
|
|
|
tx = Transaction.create([alice.public_key], [([user_pk, user2_pk], 1)],
|
2016-11-09 14:25:42 +01:00
|
|
|
payload)
|
2018-06-08 15:50:50 +02:00
|
|
|
tx = tx.sign([alice.private_key])
|
2016-09-29 10:29:41 +02:00
|
|
|
transactions.append(tx)
|
2016-04-14 14:21:07 +02:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
b.store_bulk_transactions(transactions)
|
2016-04-14 14:21:07 +02:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk)
|
2016-04-14 14:21:07 +02:00
|
|
|
# check spents
|
2016-09-29 10:29:41 +02:00
|
|
|
for input_tx in owned_inputs_user1:
|
2016-12-15 12:05:02 +01:00
|
|
|
assert b.get_spent(input_tx.txid, input_tx.output) is None
|
2016-04-14 14:21:07 +02:00
|
|
|
|
|
|
|
# create a transaction
|
2016-11-09 13:32:18 +01:00
|
|
|
tx = Transaction.transfer(transactions[0].to_inputs(),
|
2016-12-20 17:28:15 +01:00
|
|
|
[([user3_pk], 1)],
|
2016-12-22 10:19:21 +01:00
|
|
|
asset_id=transactions[0].id)
|
2016-09-29 10:29:41 +02:00
|
|
|
tx = tx.sign([user_sk, user2_sk])
|
2018-08-22 09:56:44 +02:00
|
|
|
b.store_bulk_transactions([tx])
|
2016-04-14 14:21:07 +02:00
|
|
|
|
|
|
|
# check that used inputs are marked as spent
|
2016-09-29 10:29:41 +02:00
|
|
|
assert b.get_spent(transactions[0].id, 0) == tx
|
2016-04-14 14:21:07 +02:00
|
|
|
# check that the other remain marked as unspent
|
2016-09-29 10:29:41 +02:00
|
|
|
for unspent in transactions[1:]:
|
|
|
|
assert b.get_spent(unspent.id, 0) is None
|
2017-01-19 13:02:58 +01:00
|
|
|
|
|
|
|
|
2017-01-19 15:49:30 +01:00
|
|
|
def test_get_outputs_filtered_only_unspent():
|
2017-01-24 12:11:21 +01:00
|
|
|
from bigchaindb.common.transaction import TransactionLink
|
Refactor tendermint directory to project root (#2401)
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Fixed flake8 complaint about too many blank lines
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Updating from master changed BigchainDB.process_post_response to a private method, so I had to align with that.
* Fixed a couple stale references to bigchaindb.Bigchain in docstrings
* Missed a reference to `Bigchain` in a patch call...
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
2018-07-25 16:59:25 +02:00
|
|
|
from bigchaindb.lib import BigchainDB
|
2018-06-29 15:48:58 +02:00
|
|
|
|
Refactor tendermint directory to project root (#2401)
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Fixed flake8 complaint about too many blank lines
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Updating from master changed BigchainDB.process_post_response to a private method, so I had to align with that.
* Fixed a couple stale references to bigchaindb.Bigchain in docstrings
* Missed a reference to `Bigchain` in a patch call...
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
2018-07-25 16:59:25 +02:00
|
|
|
go = 'bigchaindb.fastquery.FastQuery.get_outputs_by_public_key'
|
2018-06-29 15:48:58 +02:00
|
|
|
with patch(go) as get_outputs:
|
2017-01-24 12:11:21 +01:00
|
|
|
get_outputs.return_value = [TransactionLink('a', 1),
|
|
|
|
TransactionLink('b', 2)]
|
Refactor tendermint directory to project root (#2401)
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Fixed flake8 complaint about too many blank lines
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Updating from master changed BigchainDB.process_post_response to a private method, so I had to align with that.
* Fixed a couple stale references to bigchaindb.Bigchain in docstrings
* Missed a reference to `Bigchain` in a patch call...
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
2018-07-25 16:59:25 +02:00
|
|
|
fs = 'bigchaindb.fastquery.FastQuery.filter_spent_outputs'
|
2018-06-29 15:48:58 +02:00
|
|
|
with patch(fs) as filter_spent:
|
2017-04-19 15:47:58 +02:00
|
|
|
filter_spent.return_value = [TransactionLink('b', 2)]
|
2018-06-29 15:48:58 +02:00
|
|
|
out = BigchainDB().get_outputs_filtered('abc', spent=False)
|
2017-01-19 15:49:30 +01:00
|
|
|
get_outputs.assert_called_once_with('abc')
|
2017-01-24 12:11:21 +01:00
|
|
|
assert out == [TransactionLink('b', 2)]
|
2017-01-19 15:49:30 +01:00
|
|
|
|
|
|
|
|
2017-06-15 14:08:38 +02:00
|
|
|
def test_get_outputs_filtered_only_spent():
|
2017-01-24 12:11:21 +01:00
|
|
|
from bigchaindb.common.transaction import TransactionLink
|
Refactor tendermint directory to project root (#2401)
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Fixed flake8 complaint about too many blank lines
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Updating from master changed BigchainDB.process_post_response to a private method, so I had to align with that.
* Fixed a couple stale references to bigchaindb.Bigchain in docstrings
* Missed a reference to `Bigchain` in a patch call...
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
2018-07-25 16:59:25 +02:00
|
|
|
from bigchaindb.lib import BigchainDB
|
|
|
|
go = 'bigchaindb.fastquery.FastQuery.get_outputs_by_public_key'
|
2018-06-29 15:48:58 +02:00
|
|
|
with patch(go) as get_outputs:
|
2017-01-24 12:11:21 +01:00
|
|
|
get_outputs.return_value = [TransactionLink('a', 1),
|
|
|
|
TransactionLink('b', 2)]
|
Refactor tendermint directory to project root (#2401)
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Fixed flake8 complaint about too many blank lines
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Updating from master changed BigchainDB.process_post_response to a private method, so I had to align with that.
* Fixed a couple stale references to bigchaindb.Bigchain in docstrings
* Missed a reference to `Bigchain` in a patch call...
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
2018-07-25 16:59:25 +02:00
|
|
|
fs = 'bigchaindb.fastquery.FastQuery.filter_unspent_outputs'
|
2018-06-29 15:48:58 +02:00
|
|
|
with patch(fs) as filter_spent:
|
2017-06-15 14:08:38 +02:00
|
|
|
filter_spent.return_value = [TransactionLink('b', 2)]
|
2018-06-29 15:48:58 +02:00
|
|
|
out = BigchainDB().get_outputs_filtered('abc', spent=True)
|
2017-06-15 14:08:38 +02:00
|
|
|
get_outputs.assert_called_once_with('abc')
|
|
|
|
assert out == [TransactionLink('b', 2)]
|
|
|
|
|
|
|
|
|
Refactor tendermint directory to project root (#2401)
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Fixed flake8 complaint about too many blank lines
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Updating from master changed BigchainDB.process_post_response to a private method, so I had to align with that.
* Fixed a couple stale references to bigchaindb.Bigchain in docstrings
* Missed a reference to `Bigchain` in a patch call...
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
2018-07-25 16:59:25 +02:00
|
|
|
@patch('bigchaindb.fastquery.FastQuery.filter_unspent_outputs')
|
|
|
|
@patch('bigchaindb.fastquery.FastQuery.filter_spent_outputs')
|
2017-06-15 14:08:38 +02:00
|
|
|
def test_get_outputs_filtered(filter_spent, filter_unspent):
|
|
|
|
from bigchaindb.common.transaction import TransactionLink
|
Refactor tendermint directory to project root (#2401)
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Fixed flake8 complaint about too many blank lines
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Updating from master changed BigchainDB.process_post_response to a private method, so I had to align with that.
* Fixed a couple stale references to bigchaindb.Bigchain in docstrings
* Missed a reference to `Bigchain` in a patch call...
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
2018-07-25 16:59:25 +02:00
|
|
|
from bigchaindb.lib import BigchainDB
|
2018-06-29 15:48:58 +02:00
|
|
|
|
Refactor tendermint directory to project root (#2401)
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Fixed flake8 complaint about too many blank lines
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Updating from master changed BigchainDB.process_post_response to a private method, so I had to align with that.
* Fixed a couple stale references to bigchaindb.Bigchain in docstrings
* Missed a reference to `Bigchain` in a patch call...
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
2018-07-25 16:59:25 +02:00
|
|
|
go = 'bigchaindb.fastquery.FastQuery.get_outputs_by_public_key'
|
2018-06-29 15:48:58 +02:00
|
|
|
with patch(go) as get_outputs:
|
2017-06-15 14:08:38 +02:00
|
|
|
get_outputs.return_value = [TransactionLink('a', 1),
|
|
|
|
TransactionLink('b', 2)]
|
2018-06-29 15:48:58 +02:00
|
|
|
out = BigchainDB().get_outputs_filtered('abc')
|
2017-01-19 15:49:30 +01:00
|
|
|
get_outputs.assert_called_once_with('abc')
|
2017-04-19 15:47:58 +02:00
|
|
|
filter_spent.assert_not_called()
|
2017-06-15 14:08:38 +02:00
|
|
|
filter_unspent.assert_not_called()
|
2017-01-19 15:49:30 +01:00
|
|
|
assert out == get_outputs.return_value
|
2017-01-26 13:39:06 +01:00
|
|
|
|
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
def test_cant_spend_same_input_twice_in_tx(b, alice):
|
2017-11-30 15:04:14 +01:00
|
|
|
"""Recreate duplicated fulfillments bug
|
2017-01-26 13:39:06 +01:00
|
|
|
https://github.com/bigchaindb/bigchaindb/issues/1099
|
|
|
|
"""
|
|
|
|
from bigchaindb.models import Transaction
|
|
|
|
from bigchaindb.common.exceptions import DoubleSpend
|
|
|
|
|
|
|
|
# create a divisible asset
|
2018-06-08 15:50:50 +02:00
|
|
|
tx_create = Transaction.create([alice.public_key], [([alice.public_key], 100)])
|
|
|
|
tx_create_signed = tx_create.sign([alice.private_key])
|
2017-01-26 13:39:06 +01:00
|
|
|
assert b.validate_transaction(tx_create_signed) == tx_create_signed
|
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
b.store_bulk_transactions([tx_create_signed])
|
2017-01-26 13:39:06 +01:00
|
|
|
|
|
|
|
# Create a transfer transaction with duplicated fulfillments
|
|
|
|
dup_inputs = tx_create.to_inputs() + tx_create.to_inputs()
|
2018-06-08 15:50:50 +02:00
|
|
|
tx_transfer = Transaction.transfer(dup_inputs, [([alice.public_key], 200)],
|
2017-01-26 13:39:06 +01:00
|
|
|
asset_id=tx_create.id)
|
2018-06-08 15:50:50 +02:00
|
|
|
tx_transfer_signed = tx_transfer.sign([alice.private_key])
|
2017-01-26 13:39:06 +01:00
|
|
|
with pytest.raises(DoubleSpend):
|
|
|
|
tx_transfer_signed.validate(b)
|
2017-01-30 16:11:44 +01:00
|
|
|
|
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
def test_transaction_unicode(b, alice):
|
2018-08-22 09:56:44 +02:00
|
|
|
import copy
|
2017-01-31 15:43:46 +01:00
|
|
|
from bigchaindb.common.utils import serialize
|
2017-01-30 16:11:44 +01:00
|
|
|
from bigchaindb.models import Transaction
|
2017-01-31 15:43:46 +01:00
|
|
|
|
|
|
|
# http://www.fileformat.info/info/unicode/char/1f37a/index.htm
|
|
|
|
beer_python = {'beer': '\N{BEER MUG}'}
|
|
|
|
beer_json = '{"beer":"\N{BEER MUG}"}'
|
|
|
|
|
2018-06-08 15:50:50 +02:00
|
|
|
tx = (Transaction.create([alice.public_key], [([alice.public_key], 100)], beer_python)
|
|
|
|
).sign([alice.private_key])
|
2017-02-22 13:26:23 +01:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
tx_1 = copy.deepcopy(tx)
|
|
|
|
b.store_bulk_transactions([tx])
|
2017-02-22 13:26:23 +01:00
|
|
|
|
2018-08-22 09:56:44 +02:00
|
|
|
assert beer_json in serialize(tx_1.to_dict())
|