mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Merge common lib (#739)
* 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
This commit is contained in:
parent
35788088f2
commit
64cafc62ad
@ -8,7 +8,7 @@ import logging
|
||||
import rethinkdb as r
|
||||
|
||||
from os.path import expanduser
|
||||
from bigchaindb_common.transaction import Transaction
|
||||
from bigchaindb.common.transaction import Transaction
|
||||
|
||||
from bigchaindb import Bigchain
|
||||
from bigchaindb.util import ProcessGroup
|
||||
|
@ -13,8 +13,8 @@ import builtins
|
||||
|
||||
import logstats
|
||||
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb_common.exceptions import (StartupError,
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.common.exceptions import (StartupError,
|
||||
DatabaseAlreadyExists,
|
||||
KeypairNotFoundException)
|
||||
import rethinkdb as r
|
||||
|
@ -3,7 +3,7 @@ for ``argparse.ArgumentParser``.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
from bigchaindb_common.exceptions import StartupError
|
||||
from bigchaindb.common.exceptions import StartupError
|
||||
import multiprocessing as mp
|
||||
import subprocess
|
||||
|
||||
@ -25,7 +25,7 @@ def start_rethinkdb():
|
||||
starting the db
|
||||
|
||||
Raises:
|
||||
``bigchaindb_common.exceptions.StartupError`` if RethinkDB cannot
|
||||
``bigchaindb.common.exceptions.StartupError`` if RethinkDB cannot
|
||||
be started.
|
||||
"""
|
||||
|
||||
|
18
bigchaindb/common/crypto.py
Normal file
18
bigchaindb/common/crypto.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Separate all crypto code so that we can easily test several implementations
|
||||
|
||||
import sha3
|
||||
from cryptoconditions import crypto
|
||||
|
||||
|
||||
def hash_data(data):
|
||||
"""Hash the provided data using SHA3-256"""
|
||||
return sha3.sha3_256(data.encode()).hexdigest()
|
||||
|
||||
|
||||
def generate_key_pair():
|
||||
# TODO FOR CC: Adjust interface so that this function becomes unnecessary
|
||||
private_key, public_key = crypto.ed25519_generate_key_pair()
|
||||
return private_key.decode(), public_key.decode()
|
||||
|
||||
SigningKey = crypto.Ed25519SigningKey
|
||||
VerifyingKey = crypto.Ed25519VerifyingKey
|
82
bigchaindb/common/exceptions.py
Normal file
82
bigchaindb/common/exceptions.py
Normal file
@ -0,0 +1,82 @@
|
||||
"""Custom exceptions used in the `bigchaindb` package.
|
||||
"""
|
||||
|
||||
|
||||
class ConfigurationError(Exception):
|
||||
"""Raised when there is a problem with server configuration"""
|
||||
|
||||
|
||||
class OperationError(Exception):
|
||||
"""Raised when an operation cannot go through"""
|
||||
|
||||
|
||||
class TransactionDoesNotExist(Exception):
|
||||
"""Raised if the transaction is not in the database"""
|
||||
|
||||
|
||||
class TransactionOwnerError(Exception):
|
||||
"""Raised if a user tries to transfer a transaction they don't own"""
|
||||
|
||||
|
||||
class DoubleSpend(Exception):
|
||||
"""Raised if a double spend is found"""
|
||||
|
||||
|
||||
class InvalidHash(Exception):
|
||||
"""Raised if there was an error checking the hash for a particular
|
||||
operation"""
|
||||
|
||||
|
||||
class InvalidSignature(Exception):
|
||||
"""Raised if there was an error checking the signature for a particular
|
||||
operation"""
|
||||
|
||||
|
||||
class DatabaseAlreadyExists(Exception):
|
||||
"""Raised when trying to create the database but the db is already there"""
|
||||
|
||||
|
||||
class DatabaseDoesNotExist(Exception):
|
||||
"""Raised when trying to delete the database but the db is not there"""
|
||||
|
||||
|
||||
class KeypairNotFoundException(Exception):
|
||||
"""Raised if operation cannot proceed because the keypair was not given"""
|
||||
|
||||
|
||||
class KeypairMismatchException(Exception):
|
||||
"""Raised if the private key(s) provided for signing don't match any of the
|
||||
current owner(s)"""
|
||||
|
||||
|
||||
class StartupError(Exception):
|
||||
"""Raised when there is an error starting up the system"""
|
||||
|
||||
|
||||
class ImproperVoteError(Exception):
|
||||
"""Raised if a vote is not constructed correctly, or signed incorrectly"""
|
||||
|
||||
|
||||
class MultipleVotesError(Exception):
|
||||
"""Raised if a voter has voted more than once"""
|
||||
|
||||
|
||||
class GenesisBlockAlreadyExistsError(Exception):
|
||||
"""Raised when trying to create the already existing genesis block"""
|
||||
|
||||
|
||||
class CyclicBlockchainError(Exception):
|
||||
"""Raised when there is a cycle in the blockchain"""
|
||||
|
||||
|
||||
class FulfillmentNotInValidBlock(Exception):
|
||||
"""Raised when a transaction depends on an invalid or undecided
|
||||
fulfillment"""
|
||||
|
||||
|
||||
class AssetIdMismatch(Exception):
|
||||
"""Raised when multiple transaction inputs related to different assets"""
|
||||
|
||||
|
||||
class AmountError(Exception):
|
||||
"""Raised when the amount of a non-divisible asset is different then 1"""
|
1246
bigchaindb/common/transaction.py
Normal file
1246
bigchaindb/common/transaction.py
Normal file
File diff suppressed because it is too large
Load Diff
48
bigchaindb/common/util.py
Normal file
48
bigchaindb/common/util.py
Normal file
@ -0,0 +1,48 @@
|
||||
import time
|
||||
|
||||
import rapidjson
|
||||
|
||||
|
||||
def gen_timestamp():
|
||||
"""The Unix time, rounded to the nearest second.
|
||||
See https://en.wikipedia.org/wiki/Unix_time
|
||||
|
||||
Returns:
|
||||
str: the Unix time
|
||||
"""
|
||||
return str(round(time.time()))
|
||||
|
||||
|
||||
def serialize(data):
|
||||
"""Serialize a dict into a JSON formatted string.
|
||||
|
||||
This function enforces rules like the separator and order of keys.
|
||||
This ensures that all dicts are serialized in the same way.
|
||||
|
||||
This is specially important for hashing data. We need to make sure that
|
||||
everyone serializes their data in the same way so that we do not have
|
||||
hash mismatches for the same structure due to serialization
|
||||
differences.
|
||||
|
||||
Args:
|
||||
data (dict): dict to serialize
|
||||
|
||||
Returns:
|
||||
str: JSON formatted string
|
||||
|
||||
"""
|
||||
return rapidjson.dumps(data, skipkeys=False, ensure_ascii=False,
|
||||
sort_keys=True)
|
||||
|
||||
|
||||
def deserialize(data):
|
||||
"""Deserialize a JSON formatted string into a dict.
|
||||
|
||||
Args:
|
||||
data (str): JSON formatted string.
|
||||
|
||||
Returns:
|
||||
dict: dict resulting from the serialization of a JSON formatted
|
||||
string.
|
||||
"""
|
||||
return rapidjson.loads(data)
|
@ -17,7 +17,7 @@ import json
|
||||
import logging
|
||||
import collections
|
||||
|
||||
from bigchaindb_common import exceptions
|
||||
from bigchaindb.common import exceptions
|
||||
|
||||
import bigchaindb
|
||||
|
||||
|
@ -4,9 +4,9 @@ import collections
|
||||
from time import time
|
||||
|
||||
from itertools import compress
|
||||
from bigchaindb_common import crypto, exceptions
|
||||
from bigchaindb_common.util import gen_timestamp, serialize
|
||||
from bigchaindb_common.transaction import TransactionLink, Metadata
|
||||
from bigchaindb.common import crypto, exceptions
|
||||
from bigchaindb.common.util import gen_timestamp, serialize
|
||||
from bigchaindb.common.transaction import TransactionLink, Metadata
|
||||
|
||||
import rethinkdb as r
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
import time
|
||||
import logging
|
||||
|
||||
from bigchaindb_common import exceptions
|
||||
from bigchaindb.common import exceptions
|
||||
import rethinkdb as r
|
||||
|
||||
import bigchaindb
|
||||
|
@ -1,11 +1,11 @@
|
||||
from bigchaindb_common.crypto import hash_data, VerifyingKey, SigningKey
|
||||
from bigchaindb_common.exceptions import (InvalidHash, InvalidSignature,
|
||||
from bigchaindb.common.crypto import hash_data, VerifyingKey, SigningKey
|
||||
from bigchaindb.common.exceptions import (InvalidHash, InvalidSignature,
|
||||
OperationError, DoubleSpend,
|
||||
TransactionDoesNotExist,
|
||||
FulfillmentNotInValidBlock,
|
||||
AssetIdMismatch)
|
||||
from bigchaindb_common.transaction import Transaction, Asset
|
||||
from bigchaindb_common.util import gen_timestamp, serialize
|
||||
from bigchaindb.common.transaction import Transaction, Asset
|
||||
from bigchaindb.common.util import gen_timestamp, serialize
|
||||
|
||||
|
||||
class Asset(Asset):
|
||||
|
@ -8,7 +8,7 @@ function.
|
||||
from collections import Counter
|
||||
|
||||
from multipipes import Pipeline, Node
|
||||
from bigchaindb_common import exceptions
|
||||
from bigchaindb.common import exceptions
|
||||
|
||||
from bigchaindb.consensus import BaseConsensusRules
|
||||
from bigchaindb.models import Transaction, Block
|
||||
|
@ -3,8 +3,8 @@ import threading
|
||||
import queue
|
||||
import multiprocessing as mp
|
||||
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb_common.util import serialize
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.common.util import serialize
|
||||
|
||||
|
||||
class ProcessGroup(object):
|
||||
|
@ -6,7 +6,7 @@ For more information please refer to the documentation on ReadTheDocs:
|
||||
from flask import current_app, request, Blueprint
|
||||
from flask_restful import Resource, Api
|
||||
|
||||
from bigchaindb_common.exceptions import InvalidHash, InvalidSignature
|
||||
from bigchaindb.common.exceptions import InvalidHash, InvalidSignature
|
||||
|
||||
import bigchaindb
|
||||
from bigchaindb.models import Transaction
|
||||
|
@ -1,5 +1,5 @@
|
||||
"""A Python 3 script to write a file with a specified number
|
||||
of keypairs, using bigchaindb_common.crypto.generate_key_pair()
|
||||
of keypairs, using bigchaindb.common.crypto.generate_key_pair()
|
||||
The written file is always named keypairs.py and it should be
|
||||
interpreted as a Python 2 script.
|
||||
|
||||
@ -16,7 +16,7 @@ Using the list in other Python scripts:
|
||||
|
||||
import argparse
|
||||
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
|
||||
|
||||
# Parse the command-line arguments
|
||||
|
1
setup.py
1
setup.py
@ -103,7 +103,6 @@ setup(
|
||||
'requests~=2.9',
|
||||
'gunicorn~=19.0',
|
||||
'multipipes~=0.1.0',
|
||||
'bigchaindb-common==0.0.6',
|
||||
],
|
||||
setup_requires=['pytest-runner'],
|
||||
tests_require=tests_require,
|
||||
|
@ -76,7 +76,7 @@ def test_validate_bad_asset_creation(b, user_vk):
|
||||
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_validate_transfer_asset_id_mismatch(b, user_vk, user_sk):
|
||||
from bigchaindb_common.exceptions import AssetIdMismatch
|
||||
from bigchaindb.common.exceptions import AssetIdMismatch
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
tx_create = b.get_owned_ids(user_vk).pop()
|
||||
@ -121,7 +121,7 @@ def test_get_asset_id_transfer_transaction(b, user_vk, user_sk):
|
||||
|
||||
def test_asset_id_mismatch(b, user_vk):
|
||||
from bigchaindb.models import Transaction, Asset
|
||||
from bigchaindb_common.exceptions import AssetIdMismatch
|
||||
from bigchaindb.common.exceptions import AssetIdMismatch
|
||||
|
||||
tx1 = Transaction.create([b.me], [user_vk])
|
||||
tx2 = Transaction.create([b.me], [user_vk])
|
||||
|
162
tests/common/conftest.py
Normal file
162
tests/common/conftest.py
Normal file
@ -0,0 +1,162 @@
|
||||
import pytest
|
||||
|
||||
|
||||
USER_PRIVATE_KEY = '8eJ8q9ZQpReWyQT5aFCiwtZ5wDZC4eDnCen88p3tQ6ie'
|
||||
USER_PUBLIC_KEY = 'JEAkEJqLbbgDRAtMm8YAjGp759Aq2qTn9eaEHUj2XePE'
|
||||
|
||||
USER2_PRIVATE_KEY = 'F86PQPiqMTwM2Qi2Sda3U4Vdh3AgadMdX3KNVsu5wNJr'
|
||||
USER2_PUBLIC_KEY = 'GDxwMFbwdATkQELZbMfW8bd9hbNYMZLyVXA3nur2aNbE'
|
||||
|
||||
USER3_PRIVATE_KEY = '4rNQFzWQbVwuTiDVxwuFMvLG5zd8AhrQKCtVovBvcYsB'
|
||||
USER3_PUBLIC_KEY = 'Gbrg7JtxdjedQRmr81ZZbh1BozS7fBW88ZyxNDy7WLNC'
|
||||
|
||||
|
||||
CC_FULFILLMENT_URI = 'cf:0:'
|
||||
CC_CONDITION_URI = 'cc:0:3:47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU:0'
|
||||
|
||||
DATA = {
|
||||
'msg': 'Hello BigchainDB!'
|
||||
}
|
||||
DATA_ID = '872fa6e6f46246cd44afdb2ee9cfae0e72885fb0910e2bcf9a5a2a4eadb417b8'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user_priv():
|
||||
return USER_PRIVATE_KEY
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user_pub():
|
||||
return USER_PUBLIC_KEY
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user2_priv():
|
||||
return USER2_PRIVATE_KEY
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user2_pub():
|
||||
return USER2_PUBLIC_KEY
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user3_priv():
|
||||
return USER3_PRIVATE_KEY
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user3_pub():
|
||||
return USER3_PUBLIC_KEY
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ffill_uri():
|
||||
return CC_FULFILLMENT_URI
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cond_uri():
|
||||
return CC_CONDITION_URI
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user_Ed25519(user_pub):
|
||||
from cryptoconditions import Ed25519Fulfillment
|
||||
return Ed25519Fulfillment(public_key=user_pub)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user_user2_threshold(user_pub, user2_pub):
|
||||
from cryptoconditions import (ThresholdSha256Fulfillment,
|
||||
Ed25519Fulfillment)
|
||||
user_pub_keys = [user_pub, user2_pub]
|
||||
threshold = ThresholdSha256Fulfillment(threshold=len(user_pub_keys))
|
||||
for user_pub in user_pub_keys:
|
||||
threshold.add_subfulfillment(Ed25519Fulfillment(public_key=user_pub))
|
||||
return threshold
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user2_Ed25519(user2_pub):
|
||||
from cryptoconditions import Ed25519Fulfillment
|
||||
return Ed25519Fulfillment(public_key=user2_pub)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user_ffill(user_Ed25519, user_pub):
|
||||
from bigchaindb.common.transaction import Fulfillment
|
||||
return Fulfillment(user_Ed25519, [user_pub])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user2_ffill(user2_Ed25519, user2_pub):
|
||||
from bigchaindb.common.transaction import Fulfillment
|
||||
return Fulfillment(user2_Ed25519, [user2_pub])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user_user2_threshold_cond(user_user2_threshold, user_pub, user2_pub):
|
||||
from bigchaindb.common.transaction import Condition
|
||||
return Condition(user_user2_threshold, [user_pub, user2_pub])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user_user2_threshold_ffill(user_user2_threshold, user_pub, user2_pub):
|
||||
from bigchaindb.common.transaction import Fulfillment
|
||||
return Fulfillment(user_user2_threshold, [user_pub, user2_pub])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user_cond(user_Ed25519, user_pub):
|
||||
from bigchaindb.common.transaction import Condition
|
||||
return Condition(user_Ed25519, [user_pub])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user2_cond(user2_Ed25519, user2_pub):
|
||||
from bigchaindb.common.transaction import Condition
|
||||
return Condition(user2_Ed25519, [user2_pub])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def data():
|
||||
return DATA
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def data_id():
|
||||
return DATA_ID
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def metadata(data, data_id):
|
||||
from bigchaindb.common.transaction import Metadata
|
||||
return Metadata(data, data_id)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def utx(user_ffill, user_cond):
|
||||
from bigchaindb.common.transaction import Transaction, Asset
|
||||
return Transaction(Transaction.CREATE, Asset(), [user_ffill], [user_cond])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tx(utx, user_priv):
|
||||
return utx.sign([user_priv])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def transfer_utx(user_cond, user2_cond, utx):
|
||||
from bigchaindb.common.transaction import (Fulfillment, TransactionLink,
|
||||
Transaction, Asset)
|
||||
user_cond = user_cond.to_dict()
|
||||
ffill = Fulfillment(utx.conditions[0].fulfillment,
|
||||
user_cond['owners_after'],
|
||||
TransactionLink(utx.id, 0))
|
||||
return Transaction('TRANSFER', Asset(), [ffill], [user2_cond])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def transfer_tx(transfer_utx, user_priv):
|
||||
return transfer_utx.sign([user_priv])
|
80
tests/common/test_asset.py
Normal file
80
tests/common/test_asset.py
Normal file
@ -0,0 +1,80 @@
|
||||
from pytest import raises
|
||||
|
||||
|
||||
def test_asset_default_values():
|
||||
from bigchaindb.common.transaction import Asset
|
||||
|
||||
asset = Asset()
|
||||
assert asset.data is None
|
||||
assert asset.data_id
|
||||
assert asset.divisible is False
|
||||
assert asset.updatable is False
|
||||
assert asset.refillable is False
|
||||
|
||||
|
||||
def test_asset_creation_with_data(data):
|
||||
from bigchaindb.common.transaction import Asset
|
||||
|
||||
asset = Asset(data)
|
||||
assert asset.data == data
|
||||
|
||||
|
||||
def test_asset_invalid_asset_initialization():
|
||||
from bigchaindb.common.transaction import Asset
|
||||
|
||||
with raises(TypeError):
|
||||
Asset(data='some wrong type')
|
||||
with raises(TypeError):
|
||||
Asset(divisible=1)
|
||||
with raises(TypeError):
|
||||
Asset(refillable=1)
|
||||
with raises(TypeError):
|
||||
Asset(updatable=1)
|
||||
|
||||
|
||||
def test_invalid_asset_comparison(data, data_id):
|
||||
from bigchaindb.common.transaction import Asset
|
||||
|
||||
assert Asset(data, data_id) != 'invalid comparison'
|
||||
|
||||
|
||||
def test_asset_serialization(data, data_id):
|
||||
from bigchaindb.common.transaction import Asset
|
||||
|
||||
expected = {
|
||||
'id': data_id,
|
||||
'divisible': False,
|
||||
'updatable': False,
|
||||
'refillable': False,
|
||||
'data': data,
|
||||
}
|
||||
asset = Asset(data, data_id)
|
||||
assert asset.to_dict() == expected
|
||||
|
||||
|
||||
def test_asset_deserialization(data, data_id):
|
||||
from bigchaindb.common.transaction import Asset
|
||||
|
||||
asset_dict = {
|
||||
'id': data_id,
|
||||
'divisible': False,
|
||||
'updatable': False,
|
||||
'refillable': False,
|
||||
'data': data,
|
||||
}
|
||||
asset = Asset.from_dict(asset_dict)
|
||||
expected = Asset(data, data_id)
|
||||
assert asset == expected
|
||||
|
||||
|
||||
def test_validate_asset():
|
||||
from bigchaindb.common.transaction import Asset
|
||||
|
||||
with raises(TypeError):
|
||||
Asset(divisible=1)
|
||||
with raises(TypeError):
|
||||
Asset(refillable=1)
|
||||
with raises(TypeError):
|
||||
Asset(updatable=1)
|
||||
with raises(TypeError):
|
||||
Asset(data='we need more lemon pledge')
|
1106
tests/common/test_transaction.py
Normal file
1106
tests/common/test_transaction.py
Normal file
File diff suppressed because it is too large
Load Diff
@ -11,7 +11,7 @@ import rethinkdb as r
|
||||
|
||||
from bigchaindb import Bigchain
|
||||
from bigchaindb.db import get_conn
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
|
||||
USER2_SK, USER2_VK = crypto.generate_key_pair()
|
||||
|
||||
@ -107,7 +107,7 @@ def cleanup_tables(request, node_config):
|
||||
@pytest.fixture
|
||||
def inputs(user_vk):
|
||||
from bigchaindb.models import Transaction
|
||||
from bigchaindb_common.exceptions import GenesisBlockAlreadyExistsError
|
||||
from bigchaindb.common.exceptions import GenesisBlockAlreadyExistsError
|
||||
# 1. create the genesis block
|
||||
b = Bigchain()
|
||||
try:
|
||||
@ -144,7 +144,7 @@ def user2_vk():
|
||||
@pytest.fixture
|
||||
def inputs_shared(user_vk, user2_vk):
|
||||
from bigchaindb.models import Transaction
|
||||
from bigchaindb_common.exceptions import GenesisBlockAlreadyExistsError
|
||||
from bigchaindb.common.exceptions import GenesisBlockAlreadyExistsError
|
||||
# 1. create the genesis block
|
||||
b = Bigchain()
|
||||
try:
|
||||
|
@ -30,9 +30,9 @@ def dummy_block():
|
||||
|
||||
class TestBigchainApi(object):
|
||||
def test_get_last_voted_block_cyclic_blockchain(self, b, monkeypatch):
|
||||
from bigchaindb_common.crypto import SigningKey
|
||||
from bigchaindb_common.exceptions import CyclicBlockchainError
|
||||
from bigchaindb_common.util import serialize
|
||||
from bigchaindb.common.crypto import SigningKey
|
||||
from bigchaindb.common.exceptions import CyclicBlockchainError
|
||||
from bigchaindb.common.util import serialize
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
b.create_genesis_block()
|
||||
@ -55,7 +55,7 @@ class TestBigchainApi(object):
|
||||
|
||||
def test_try_voting_while_constructing_cyclic_blockchain(self, b,
|
||||
monkeypatch):
|
||||
from bigchaindb_common.exceptions import CyclicBlockchainError
|
||||
from bigchaindb.common.exceptions import CyclicBlockchainError
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
b.create_genesis_block()
|
||||
@ -94,7 +94,7 @@ class TestBigchainApi(object):
|
||||
assert not matches
|
||||
|
||||
def test_get_spent_with_double_spend(self, b, monkeypatch):
|
||||
from bigchaindb_common.exceptions import DoubleSpend
|
||||
from bigchaindb.common.exceptions import DoubleSpend
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
b.create_genesis_block()
|
||||
@ -128,7 +128,7 @@ class TestBigchainApi(object):
|
||||
b.get_spent(tx.id, 0)
|
||||
|
||||
def test_get_block_status_for_tx_with_double_spend(self, b, monkeypatch):
|
||||
from bigchaindb_common.exceptions import DoubleSpend
|
||||
from bigchaindb.common.exceptions import DoubleSpend
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
b.create_genesis_block()
|
||||
@ -277,7 +277,7 @@ class TestBigchainApi(object):
|
||||
|
||||
def test_create_genesis_block_fails_if_table_not_empty(self, b):
|
||||
import rethinkdb as r
|
||||
from bigchaindb_common.exceptions import GenesisBlockAlreadyExistsError
|
||||
from bigchaindb.common.exceptions import GenesisBlockAlreadyExistsError
|
||||
from bigchaindb.util import is_genesis_block
|
||||
from bigchaindb.db.utils import get_conn
|
||||
|
||||
@ -333,7 +333,7 @@ class TestBigchainApi(object):
|
||||
assert prev_block_id == last_block['id']
|
||||
|
||||
def test_create_empty_block(self, b):
|
||||
from bigchaindb_common.exceptions import OperationError
|
||||
from bigchaindb.common.exceptions import OperationError
|
||||
|
||||
with pytest.raises(OperationError) as excinfo:
|
||||
b.create_block([])
|
||||
@ -433,7 +433,7 @@ class TestBigchainApi(object):
|
||||
|
||||
def test_more_votes_than_voters(self, b):
|
||||
import rethinkdb as r
|
||||
from bigchaindb_common.exceptions import MultipleVotesError
|
||||
from bigchaindb.common.exceptions import MultipleVotesError
|
||||
from bigchaindb.db.utils import get_conn
|
||||
|
||||
b.create_genesis_block()
|
||||
@ -453,7 +453,7 @@ class TestBigchainApi(object):
|
||||
|
||||
def test_multiple_votes_single_node(self, b):
|
||||
import rethinkdb as r
|
||||
from bigchaindb_common.exceptions import MultipleVotesError
|
||||
from bigchaindb.common.exceptions import MultipleVotesError
|
||||
from bigchaindb.db.utils import get_conn
|
||||
|
||||
genesis = b.create_genesis_block()
|
||||
@ -475,7 +475,7 @@ class TestBigchainApi(object):
|
||||
|
||||
def test_improper_vote_error(selfs, b):
|
||||
import rethinkdb as r
|
||||
from bigchaindb_common.exceptions import ImproperVoteError
|
||||
from bigchaindb.common.exceptions import ImproperVoteError
|
||||
from bigchaindb.db.utils import get_conn
|
||||
|
||||
b.create_genesis_block()
|
||||
@ -512,7 +512,7 @@ class TestBigchainApi(object):
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_assign_transaction_multiple_nodes(self, b, user_vk, user_sk):
|
||||
import rethinkdb as r
|
||||
from bigchaindb_common.crypto import generate_key_pair
|
||||
from bigchaindb.common.crypto import generate_key_pair
|
||||
from bigchaindb.models import Transaction
|
||||
from bigchaindb.db.utils import get_conn
|
||||
|
||||
@ -539,8 +539,8 @@ class TestBigchainApi(object):
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_non_create_input_not_found(self, b, user_vk):
|
||||
from cryptoconditions import Ed25519Fulfillment
|
||||
from bigchaindb_common.exceptions import TransactionDoesNotExist
|
||||
from bigchaindb_common.transaction import (Fulfillment, Asset,
|
||||
from bigchaindb.common.exceptions import TransactionDoesNotExist
|
||||
from bigchaindb.common.transaction import (Fulfillment, Asset,
|
||||
TransactionLink)
|
||||
from bigchaindb.models import Transaction
|
||||
from bigchaindb import Bigchain
|
||||
@ -557,7 +557,7 @@ class TestBigchainApi(object):
|
||||
|
||||
class TestTransactionValidation(object):
|
||||
def test_create_operation_with_inputs(self, b, user_vk, create_tx):
|
||||
from bigchaindb_common.transaction import TransactionLink
|
||||
from bigchaindb.common.transaction import TransactionLink
|
||||
|
||||
# Manipulate fulfillment so that it has a `tx_input` defined even
|
||||
# though it shouldn't have one
|
||||
@ -575,8 +575,8 @@ class TestTransactionValidation(object):
|
||||
assert excinfo.value.args[0] == 'Only `CREATE` transactions can have null inputs'
|
||||
|
||||
def test_non_create_input_not_found(self, b, user_vk, signed_transfer_tx):
|
||||
from bigchaindb_common.exceptions import TransactionDoesNotExist
|
||||
from bigchaindb_common.transaction import TransactionLink
|
||||
from bigchaindb.common.exceptions import TransactionDoesNotExist
|
||||
from bigchaindb.common.transaction import TransactionLink
|
||||
|
||||
signed_transfer_tx.fulfillments[0].tx_input = TransactionLink('c', 0)
|
||||
with pytest.raises(TransactionDoesNotExist):
|
||||
@ -584,8 +584,8 @@ class TestTransactionValidation(object):
|
||||
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_non_create_valid_input_wrong_owner(self, b, user_vk):
|
||||
from bigchaindb_common.crypto import generate_key_pair
|
||||
from bigchaindb_common.exceptions import InvalidSignature
|
||||
from bigchaindb.common.crypto import generate_key_pair
|
||||
from bigchaindb.common.exceptions import InvalidSignature
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
input_tx = b.get_owned_ids(user_vk).pop()
|
||||
@ -602,7 +602,7 @@ class TestTransactionValidation(object):
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_non_create_double_spend(self, b, signed_create_tx,
|
||||
signed_transfer_tx):
|
||||
from bigchaindb_common.exceptions import DoubleSpend
|
||||
from bigchaindb.common.exceptions import DoubleSpend
|
||||
|
||||
block1 = b.create_block([signed_create_tx])
|
||||
b.write_block(block1)
|
||||
@ -652,7 +652,7 @@ class TestTransactionValidation(object):
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_fulfillment_not_in_valid_block(self, b, user_vk, user_sk):
|
||||
from bigchaindb.models import Transaction
|
||||
from bigchaindb_common.exceptions import FulfillmentNotInValidBlock
|
||||
from bigchaindb.common.exceptions import FulfillmentNotInValidBlock
|
||||
|
||||
input_tx = b.get_owned_ids(user_vk).pop()
|
||||
input_tx = b.get_transaction(input_tx.txid)
|
||||
@ -681,9 +681,9 @@ class TestBlockValidation(object):
|
||||
@pytest.mark.skipif(reason='Separated tx validation from block creation.')
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_invalid_transactions_in_block(self, b, user_vk):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb_common.exceptions import TransactionOwnerError
|
||||
from bigchaindb_common.util import gen_timestamp
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.common.exceptions import TransactionOwnerError
|
||||
from bigchaindb.common.util import gen_timestamp
|
||||
|
||||
from bigchaindb import util
|
||||
|
||||
@ -722,8 +722,8 @@ class TestBlockValidation(object):
|
||||
assert excinfo.value.args[0] == 'owner_before `a` does not own the input `{}`'.format(valid_input)
|
||||
|
||||
def test_invalid_signature(self, b):
|
||||
from bigchaindb_common.exceptions import InvalidSignature
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common.exceptions import InvalidSignature
|
||||
from bigchaindb.common import crypto
|
||||
|
||||
# create a valid block
|
||||
block = dummy_block()
|
||||
@ -736,8 +736,8 @@ class TestBlockValidation(object):
|
||||
b.validate_block(block)
|
||||
|
||||
def test_invalid_node_pubkey(self, b):
|
||||
from bigchaindb_common.exceptions import OperationError
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common.exceptions import OperationError
|
||||
from bigchaindb.common import crypto
|
||||
|
||||
# blocks can only be created by a federation node
|
||||
# create a valid block
|
||||
@ -761,7 +761,7 @@ class TestBlockValidation(object):
|
||||
class TestMultipleInputs(object):
|
||||
def test_transfer_single_owner_single_input(self, b, inputs, user_vk,
|
||||
user_sk):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.models import Transaction
|
||||
user2_sk, user2_vk = crypto.generate_key_pair()
|
||||
|
||||
@ -781,7 +781,7 @@ class TestMultipleInputs(object):
|
||||
'multiple assets'))
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_transfer_single_owners_multiple_inputs(self, b, user_sk, user_vk):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
user2_sk, user2_vk = crypto.generate_key_pair()
|
||||
@ -804,7 +804,7 @@ class TestMultipleInputs(object):
|
||||
def test_transfer_single_owners_single_input_from_multiple_outputs(self, b,
|
||||
user_sk,
|
||||
user_vk):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
user2_sk, user2_vk = crypto.generate_key_pair()
|
||||
@ -843,7 +843,7 @@ class TestMultipleInputs(object):
|
||||
user_sk,
|
||||
user_vk,
|
||||
inputs):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
user2_sk, user2_vk = crypto.generate_key_pair()
|
||||
@ -866,7 +866,7 @@ class TestMultipleInputs(object):
|
||||
def test_single_owner_before_multiple_owners_after_multiple_inputs(self, b,
|
||||
user_sk,
|
||||
user_vk):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
user2_sk, user2_vk = crypto.generate_key_pair()
|
||||
@ -897,7 +897,7 @@ class TestMultipleInputs(object):
|
||||
def test_multiple_owners_before_single_owner_after_single_input(self, b,
|
||||
user_sk,
|
||||
user_vk):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
user2_sk, user2_vk = crypto.generate_key_pair()
|
||||
@ -930,7 +930,7 @@ class TestMultipleInputs(object):
|
||||
@pytest.mark.usefixtures('inputs_shared')
|
||||
def test_multiple_owners_before_single_owner_after_multiple_inputs(self, b,
|
||||
user_sk, user_vk, user2_vk, user2_sk):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
# create a new users
|
||||
@ -951,7 +951,7 @@ class TestMultipleInputs(object):
|
||||
def test_multiple_owners_before_multiple_owners_after_single_input(self, b,
|
||||
user_sk,
|
||||
user_vk):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
user2_sk, user2_vk = crypto.generate_key_pair()
|
||||
@ -985,7 +985,7 @@ class TestMultipleInputs(object):
|
||||
def test_multiple_owners_before_multiple_owners_after_multiple_inputs(self, b,
|
||||
user_sk, user_vk,
|
||||
user2_sk, user2_vk):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
# create a new users
|
||||
@ -1004,8 +1004,8 @@ class TestMultipleInputs(object):
|
||||
assert len(tx.conditions) == len(inputs)
|
||||
|
||||
def test_get_owned_ids_single_tx_single_output(self, b, user_sk, user_vk):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb_common.transaction import TransactionLink
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.common.transaction import TransactionLink
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
user2_sk, user2_vk = crypto.generate_key_pair()
|
||||
@ -1033,8 +1033,8 @@ class TestMultipleInputs(object):
|
||||
def test_get_owned_ids_single_tx_single_output_invalid_block(self, b,
|
||||
user_sk,
|
||||
user_vk):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb_common.transaction import TransactionLink
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.common.transaction import TransactionLink
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
genesis = b.create_genesis_block()
|
||||
@ -1078,8 +1078,8 @@ class TestMultipleInputs(object):
|
||||
def test_get_owned_ids_single_tx_multiple_outputs(self, b, user_sk,
|
||||
user_vk):
|
||||
import random
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb_common.transaction import TransactionLink
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.common.transaction import TransactionLink
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
user2_sk, user2_vk = crypto.generate_key_pair()
|
||||
@ -1115,8 +1115,8 @@ class TestMultipleInputs(object):
|
||||
TransactionLink(tx.id, 1)]
|
||||
|
||||
def test_get_owned_ids_multiple_owners(self, b, user_sk, user_vk):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb_common.transaction import TransactionLink
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.common.transaction import TransactionLink
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
user2_sk, user2_vk = crypto.generate_key_pair()
|
||||
@ -1145,7 +1145,7 @@ class TestMultipleInputs(object):
|
||||
assert owned_inputs_user1 == []
|
||||
|
||||
def test_get_spent_single_tx_single_output(self, b, user_sk, user_vk):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
user2_sk, user2_vk = crypto.generate_key_pair()
|
||||
@ -1173,7 +1173,7 @@ class TestMultipleInputs(object):
|
||||
assert spent_inputs_user1 == tx
|
||||
|
||||
def test_get_spent_single_tx_single_output_invalid_block(self, b, user_sk, user_vk):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
genesis = b.create_genesis_block()
|
||||
@ -1219,7 +1219,7 @@ class TestMultipleInputs(object):
|
||||
'multiple assets'))
|
||||
def test_get_spent_single_tx_multiple_outputs(self, b, user_sk, user_vk):
|
||||
import random
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
# create a new users
|
||||
@ -1259,7 +1259,7 @@ class TestMultipleInputs(object):
|
||||
|
||||
def test_get_spent_multiple_owners(self, b, user_sk, user_vk):
|
||||
import random
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
user2_sk, user2_vk = crypto.generate_key_pair()
|
||||
|
@ -1,6 +1,6 @@
|
||||
import builtins
|
||||
|
||||
from bigchaindb_common import exceptions
|
||||
from bigchaindb.common import exceptions
|
||||
import pytest
|
||||
import rethinkdb as r
|
||||
|
||||
|
@ -2,7 +2,7 @@ import json
|
||||
from time import sleep
|
||||
|
||||
import cryptoconditions as cc
|
||||
from bigchaindb_common.util import gen_timestamp
|
||||
from bigchaindb.common.util import gen_timestamp
|
||||
|
||||
from bigchaindb import Bigchain, util, crypto, exceptions
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import time
|
||||
from unittest.mock import patch
|
||||
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
import rethinkdb as r
|
||||
from multipipes import Pipe, Pipeline
|
||||
|
||||
|
@ -19,8 +19,8 @@ def dummy_block(b):
|
||||
|
||||
|
||||
def test_vote_creation_valid(b):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb_common.util import serialize
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.common.util import serialize
|
||||
|
||||
# create valid block
|
||||
block = dummy_block(b)
|
||||
@ -38,8 +38,8 @@ def test_vote_creation_valid(b):
|
||||
|
||||
|
||||
def test_vote_creation_invalid(b):
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb_common.util import serialize
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.common.util import serialize
|
||||
|
||||
# create valid block
|
||||
block = dummy_block(b)
|
||||
@ -154,7 +154,7 @@ def test_vote_accumulates_transactions(b):
|
||||
|
||||
|
||||
def test_valid_block_voting_sequential(b, monkeypatch):
|
||||
from bigchaindb_common import crypto, util
|
||||
from bigchaindb.common import crypto, util
|
||||
from bigchaindb.pipelines import vote
|
||||
|
||||
monkeypatch.setattr('time.time', lambda: 1)
|
||||
@ -182,7 +182,7 @@ def test_valid_block_voting_sequential(b, monkeypatch):
|
||||
|
||||
|
||||
def test_valid_block_voting_multiprocessing(b, monkeypatch):
|
||||
from bigchaindb_common import crypto, util
|
||||
from bigchaindb.common import crypto, util
|
||||
from bigchaindb.pipelines import vote
|
||||
|
||||
inpipe = Pipe()
|
||||
@ -216,7 +216,7 @@ def test_valid_block_voting_multiprocessing(b, monkeypatch):
|
||||
|
||||
|
||||
def test_valid_block_voting_with_create_transaction(b, monkeypatch):
|
||||
from bigchaindb_common import crypto, util
|
||||
from bigchaindb.common import crypto, util
|
||||
from bigchaindb.models import Transaction
|
||||
from bigchaindb.pipelines import vote
|
||||
|
||||
@ -257,7 +257,7 @@ def test_valid_block_voting_with_create_transaction(b, monkeypatch):
|
||||
|
||||
|
||||
def test_valid_block_voting_with_transfer_transactions(monkeypatch, b):
|
||||
from bigchaindb_common import crypto, util
|
||||
from bigchaindb.common import crypto, util
|
||||
from bigchaindb.models import Transaction
|
||||
from bigchaindb.pipelines import vote
|
||||
|
||||
@ -325,7 +325,7 @@ def test_valid_block_voting_with_transfer_transactions(monkeypatch, b):
|
||||
|
||||
|
||||
def test_unsigned_tx_in_block_voting(monkeypatch, b, user_vk):
|
||||
from bigchaindb_common import crypto, util
|
||||
from bigchaindb.common import crypto, util
|
||||
from bigchaindb.models import Transaction
|
||||
from bigchaindb.pipelines import vote
|
||||
|
||||
@ -362,7 +362,7 @@ def test_unsigned_tx_in_block_voting(monkeypatch, b, user_vk):
|
||||
|
||||
|
||||
def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_vk):
|
||||
from bigchaindb_common import crypto, util
|
||||
from bigchaindb.common import crypto, util
|
||||
from bigchaindb.models import Transaction
|
||||
from bigchaindb.pipelines import vote
|
||||
|
||||
@ -401,7 +401,7 @@ def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_vk):
|
||||
|
||||
|
||||
def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_vk):
|
||||
from bigchaindb_common import crypto, util
|
||||
from bigchaindb.common import crypto, util
|
||||
from bigchaindb.models import Transaction
|
||||
from bigchaindb.pipelines import vote
|
||||
|
||||
@ -440,7 +440,7 @@ def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_vk):
|
||||
|
||||
|
||||
def test_invalid_block_voting(monkeypatch, b, user_vk):
|
||||
from bigchaindb_common import crypto, util
|
||||
from bigchaindb.common import crypto, util
|
||||
from bigchaindb.pipelines import vote
|
||||
|
||||
inpipe = Pipe()
|
||||
|
@ -22,7 +22,7 @@ def mock_write_config(monkeypatch):
|
||||
@pytest.fixture
|
||||
def mock_db_init_with_existing_db(monkeypatch):
|
||||
from bigchaindb import db
|
||||
from bigchaindb_common.exceptions import DatabaseAlreadyExists
|
||||
from bigchaindb.common.exceptions import DatabaseAlreadyExists
|
||||
|
||||
def mockreturn():
|
||||
raise DatabaseAlreadyExists
|
||||
@ -48,7 +48,7 @@ def mock_rethink_db_drop(monkeypatch):
|
||||
|
||||
@pytest.fixture
|
||||
def mock_generate_key_pair(monkeypatch):
|
||||
monkeypatch.setattr('bigchaindb_common.crypto.generate_key_pair', lambda: ('privkey', 'pubkey'))
|
||||
monkeypatch.setattr('bigchaindb.common.crypto.generate_key_pair', lambda: ('privkey', 'pubkey'))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -283,14 +283,14 @@ def test_start_rethinkdb_returns_a_process_when_successful(mock_popen):
|
||||
|
||||
@patch('subprocess.Popen')
|
||||
def test_start_rethinkdb_exits_when_cannot_start(mock_popen):
|
||||
from bigchaindb_common import exceptions
|
||||
from bigchaindb.common import exceptions
|
||||
from bigchaindb.commands import utils
|
||||
mock_popen.return_value = Mock(stdout=['Nopety nope'])
|
||||
with pytest.raises(exceptions.StartupError):
|
||||
utils.start_rethinkdb()
|
||||
|
||||
|
||||
@patch('bigchaindb_common.crypto.generate_key_pair',
|
||||
@patch('bigchaindb.common.crypto.generate_key_pair',
|
||||
return_value=('private_key', 'public_key'))
|
||||
def test_allow_temp_keypair_generates_one_on_the_fly(mock_gen_keypair,
|
||||
mock_processes_start,
|
||||
@ -307,7 +307,7 @@ def test_allow_temp_keypair_generates_one_on_the_fly(mock_gen_keypair,
|
||||
assert bigchaindb.config['keypair']['public'] == 'public_key'
|
||||
|
||||
|
||||
@patch('bigchaindb_common.crypto.generate_key_pair',
|
||||
@patch('bigchaindb.common.crypto.generate_key_pair',
|
||||
return_value=('private_key', 'public_key'))
|
||||
def test_allow_temp_keypair_doesnt_override_if_keypair_found(mock_gen_keypair,
|
||||
mock_processes_start,
|
||||
|
@ -42,7 +42,7 @@ def test_bigchain_instance_is_initialized_when_conf_provided():
|
||||
|
||||
def test_bigchain_instance_raises_when_not_configured(monkeypatch):
|
||||
from bigchaindb import config_utils
|
||||
from bigchaindb_common import exceptions
|
||||
from bigchaindb.common import exceptions
|
||||
assert 'CONFIGURED' not in bigchaindb.config
|
||||
|
||||
# We need to disable ``bigchaindb.config_utils.autoconfigure`` to avoid reading
|
||||
@ -204,7 +204,7 @@ def test_file_config():
|
||||
|
||||
def test_invalid_file_config():
|
||||
from bigchaindb.config_utils import file_config
|
||||
from bigchaindb_common import exceptions
|
||||
from bigchaindb.common import exceptions
|
||||
with patch('builtins.open', mock_open(read_data='{_INVALID_JSON_}')):
|
||||
with pytest.raises(exceptions.ConfigurationError):
|
||||
file_config()
|
||||
|
@ -37,8 +37,8 @@ class TestBlockModel(object):
|
||||
'not a list or None')
|
||||
|
||||
def test_block_serialization(self, b):
|
||||
from bigchaindb_common.crypto import hash_data
|
||||
from bigchaindb_common.util import gen_timestamp, serialize
|
||||
from bigchaindb.common.crypto import hash_data
|
||||
from bigchaindb.common.util import gen_timestamp, serialize
|
||||
from bigchaindb.models import Block, Transaction
|
||||
|
||||
transactions = [Transaction.create([b.me], [b.me])]
|
||||
@ -61,7 +61,7 @@ class TestBlockModel(object):
|
||||
assert block.to_dict() == expected
|
||||
|
||||
def test_block_invalid_serializaton(self):
|
||||
from bigchaindb_common.exceptions import OperationError
|
||||
from bigchaindb.common.exceptions import OperationError
|
||||
from bigchaindb.models import Block
|
||||
|
||||
block = Block([])
|
||||
@ -69,8 +69,8 @@ class TestBlockModel(object):
|
||||
block.to_dict()
|
||||
|
||||
def test_block_deserialization(self, b):
|
||||
from bigchaindb_common.crypto import hash_data
|
||||
from bigchaindb_common.util import gen_timestamp, serialize
|
||||
from bigchaindb.common.crypto import hash_data
|
||||
from bigchaindb.common.util import gen_timestamp, serialize
|
||||
from bigchaindb.models import Block, Transaction
|
||||
|
||||
transactions = [Transaction.create([b.me], [b.me])]
|
||||
@ -94,7 +94,7 @@ class TestBlockModel(object):
|
||||
assert expected == Block.from_dict(block_body)
|
||||
|
||||
def test_block_invalid_id_deserialization(self, b):
|
||||
from bigchaindb_common.exceptions import InvalidHash
|
||||
from bigchaindb.common.exceptions import InvalidHash
|
||||
from bigchaindb.models import Block
|
||||
|
||||
block = {
|
||||
@ -108,9 +108,9 @@ class TestBlockModel(object):
|
||||
Block.from_dict(block)
|
||||
|
||||
def test_block_invalid_signature_deserialization(self, b):
|
||||
from bigchaindb_common.crypto import hash_data
|
||||
from bigchaindb_common.exceptions import InvalidSignature
|
||||
from bigchaindb_common.util import gen_timestamp, serialize
|
||||
from bigchaindb.common.crypto import hash_data
|
||||
from bigchaindb.common.exceptions import InvalidSignature
|
||||
from bigchaindb.common.util import gen_timestamp, serialize
|
||||
from bigchaindb.models import Block, Transaction
|
||||
|
||||
transactions = [Transaction.create([b.me], [b.me])]
|
||||
@ -142,8 +142,8 @@ class TestBlockModel(object):
|
||||
assert Block(transactions) == Block(transactions)
|
||||
|
||||
def test_sign_block(self, b):
|
||||
from bigchaindb_common.crypto import SigningKey, VerifyingKey
|
||||
from bigchaindb_common.util import gen_timestamp, serialize
|
||||
from bigchaindb.common.crypto import SigningKey, VerifyingKey
|
||||
from bigchaindb.common.util import gen_timestamp, serialize
|
||||
from bigchaindb.models import Block, Transaction
|
||||
|
||||
transactions = [Transaction.create([b.me], [b.me])]
|
||||
|
@ -1,7 +1,7 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from bigchaindb_common import crypto
|
||||
from bigchaindb.common import crypto
|
||||
|
||||
|
||||
TX_ENDPOINT = '/api/v1/transactions/'
|
||||
|
Loading…
x
Reference in New Issue
Block a user