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
This commit is contained in:
Zachary Bowen 2018-07-25 16:59:25 +02:00 committed by Troy McConaghy
parent d0a24ef584
commit 2386ca9d71
33 changed files with 262 additions and 297 deletions

View File

@ -4,7 +4,7 @@ A high-level description of the files and subdirectories of BigchainDB.
## Files ## Files
### [`tendermint/lib.py`](./tendermint/lib.py) ### [`lib.py`](lib.py)
The `BigchainDB` class is defined here. Most node-level operations and database interactions are found in this file. This is the place to start if you are interested in implementing a server API, since many of these class methods concern BigchainDB interacting with the outside world. The `BigchainDB` class is defined here. Most node-level operations and database interactions are found in this file. This is the place to start if you are interested in implementing a server API, since many of these class methods concern BigchainDB interacting with the outside world.

View File

@ -2,6 +2,9 @@ import copy
import logging import logging
from bigchaindb.log import DEFAULT_LOGGING_CONFIG as log_config from bigchaindb.log import DEFAULT_LOGGING_CONFIG as log_config
from bigchaindb.lib import BigchainDB # noqa
from bigchaindb.version import __version__ # noqa
from bigchaindb.core import App # noqa
# from functools import reduce # from functools import reduce
# PORT_NUMBER = reduce(lambda x, y: x * y, map(ord, 'BigchainDB')) % 2**16 # PORT_NUMBER = reduce(lambda x, y: x * y, map(ord, 'BigchainDB')) % 2**16
@ -84,5 +87,3 @@ config = {
# the user wants to reconfigure the node. Check ``bigchaindb.config_utils`` # the user wants to reconfigure the node. Check ``bigchaindb.config_utils``
# for more info. # for more info.
_config = copy.deepcopy(config) _config = copy.deepcopy(config)
from bigchaindb.tendermint import BigchainDB # noqa
from bigchaindb.version import __version__ # noqa

View File

@ -21,7 +21,7 @@ from bigchaindb.commands import utils
from bigchaindb.commands.utils import (configure_bigchaindb, from bigchaindb.commands.utils import (configure_bigchaindb,
input_on_stderr) input_on_stderr)
from bigchaindb.log import setup_logging from bigchaindb.log import setup_logging
from bigchaindb.tendermint.utils import public_key_from_base64 from bigchaindb.tendermint_utils import public_key_from_base64
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -97,7 +97,7 @@ def run_configure(args):
def run_upsert_validator(args): def run_upsert_validator(args):
"""Store validators which should be synced with Tendermint""" """Store validators which should be synced with Tendermint"""
b = bigchaindb.tendermint.BigchainDB() b = bigchaindb.BigchainDB()
public_key = public_key_from_base64(args.public_key) public_key = public_key_from_base64(args.public_key)
validator = {'pub_key': {'type': 'ed25519', validator = {'pub_key': {'type': 'ed25519',
'data': public_key}, 'data': public_key},
@ -113,7 +113,7 @@ def run_upsert_validator(args):
def _run_init(): def _run_init():
bdb = bigchaindb.tendermint.BigchainDB() bdb = bigchaindb.BigchainDB()
schema.init_database(connection=bdb.connection) schema.init_database(connection=bdb.connection)
@ -170,7 +170,7 @@ def run_start(args):
setup_logging() setup_logging()
logger.info('BigchainDB Version %s', bigchaindb.__version__) logger.info('BigchainDB Version %s', bigchaindb.__version__)
run_recover(bigchaindb.tendermint.lib.BigchainDB()) run_recover(bigchaindb.lib.BigchainDB())
try: try:
if not args.skip_initialize_database: if not args.skip_initialize_database:
@ -180,7 +180,7 @@ def run_start(args):
pass pass
logger.info('Starting BigchainDB main process.') logger.info('Starting BigchainDB main process.')
from bigchaindb.tendermint.commands import start from bigchaindb.start import start
start() start()

View File

@ -0,0 +1,178 @@
"""This module contains all the goodness to integrate BigchainDB
with Tendermint."""
import logging
from abci.application import BaseApplication
from abci.types_pb2 import (
ResponseInitChain,
ResponseInfo,
ResponseCheckTx,
ResponseBeginBlock,
ResponseDeliverTx,
ResponseEndBlock,
ResponseCommit,
Validator,
PubKey
)
from bigchaindb import BigchainDB
from bigchaindb.tendermint_utils import (decode_transaction,
calculate_hash)
from bigchaindb.lib import Block, PreCommitState
from bigchaindb.backend.query import PRE_COMMIT_ID
CodeTypeOk = 0
CodeTypeError = 1
logger = logging.getLogger(__name__)
class App(BaseApplication):
"""Bridge between BigchainDB and Tendermint.
The role of this class is to expose the BigchainDB
transactional logic to the Tendermint Consensus
State Machine."""
def __init__(self, bigchaindb=None):
self.bigchaindb = bigchaindb or BigchainDB()
self.block_txn_ids = []
self.block_txn_hash = ''
self.block_transactions = []
self.validators = None
self.new_height = None
def init_chain(self, validators):
"""Initialize chain with block of height 0"""
block = Block(app_hash='', height=0, transactions=[])
self.bigchaindb.store_block(block._asdict())
return ResponseInitChain()
def info(self, request):
"""Return height of the latest committed block."""
r = ResponseInfo()
block = self.bigchaindb.get_latest_block()
if block:
r.last_block_height = block['height']
r.last_block_app_hash = block['app_hash'].encode('utf-8')
else:
r.last_block_height = 0
r.last_block_app_hash = b''
return r
def check_tx(self, raw_transaction):
"""Validate the transaction before entry into
the mempool.
Args:
raw_tx: a raw string (in bytes) transaction."""
logger.benchmark('CHECK_TX_INIT')
logger.debug('check_tx: %s', raw_transaction)
transaction = decode_transaction(raw_transaction)
if self.bigchaindb.is_valid_transaction(transaction):
logger.debug('check_tx: VALID')
logger.benchmark('CHECK_TX_END, tx_id:%s', transaction['id'])
return ResponseCheckTx(code=CodeTypeOk)
else:
logger.debug('check_tx: INVALID')
logger.benchmark('CHECK_TX_END, tx_id:%s', transaction['id'])
return ResponseCheckTx(code=CodeTypeError)
def begin_block(self, req_begin_block):
"""Initialize list of transaction.
Args:
req_begin_block: block object which contains block header
and block hash.
"""
logger.benchmark('BEGIN BLOCK, height:%s, num_txs:%s',
req_begin_block.header.height,
req_begin_block.header.num_txs)
self.block_txn_ids = []
self.block_transactions = []
return ResponseBeginBlock()
def deliver_tx(self, raw_transaction):
"""Validate the transaction before mutating the state.
Args:
raw_tx: a raw string (in bytes) transaction."""
logger.debug('deliver_tx: %s', raw_transaction)
transaction = self.bigchaindb.is_valid_transaction(
decode_transaction(raw_transaction), self.block_transactions)
if not transaction:
logger.debug('deliver_tx: INVALID')
return ResponseDeliverTx(code=CodeTypeError)
else:
logger.debug('storing tx')
self.block_txn_ids.append(transaction.id)
self.block_transactions.append(transaction)
return ResponseDeliverTx(code=CodeTypeOk)
def end_block(self, request_end_block):
"""Calculate block hash using transaction ids and previous block
hash to be stored in the next block.
Args:
height (int): new height of the chain."""
height = request_end_block.height
self.new_height = height
block_txn_hash = calculate_hash(self.block_txn_ids)
block = self.bigchaindb.get_latest_block()
if self.block_txn_ids:
self.block_txn_hash = calculate_hash([block['app_hash'], block_txn_hash])
else:
self.block_txn_hash = block['app_hash']
validator_updates = self.bigchaindb.get_validator_update()
validator_updates = [encode_validator(v) for v in validator_updates]
# set sync status to true
self.bigchaindb.delete_validator_update()
# Store pre-commit state to recover in case there is a crash
# during `commit`
pre_commit_state = PreCommitState(commit_id=PRE_COMMIT_ID,
height=self.new_height,
transactions=self.block_txn_ids)
logger.debug('Updating PreCommitState: %s', self.new_height)
self.bigchaindb.store_pre_commit_state(pre_commit_state._asdict())
return ResponseEndBlock(validator_updates=validator_updates)
def commit(self):
"""Store the new height and along with block hash."""
data = self.block_txn_hash.encode('utf-8')
# register a new block only when new transactions are received
if self.block_txn_ids:
self.bigchaindb.store_bulk_transactions(self.block_transactions)
block = Block(app_hash=self.block_txn_hash,
height=self.new_height,
transactions=self.block_txn_ids)
# NOTE: storing the block should be the last operation during commit
# this effects crash recovery. Refer BEP#8 for details
self.bigchaindb.store_block(block._asdict())
logger.debug('Commit-ing new block with hash: apphash=%s ,'
'height=%s, txn ids=%s', data, self.new_height,
self.block_txn_ids)
logger.benchmark('COMMIT_BLOCK, height:%s', self.new_height)
return ResponseCommit(data=data)
def encode_validator(v):
ed25519_public_key = v['pub_key']['data']
# NOTE: tendermint expects public to be encoded in go-amino format
pub_key = PubKey(type='ed25519',
data=bytes.fromhex(ed25519_public_key))
return Validator(pub_key=pub_key,
address=b'',
power=v['power'])

View File

@ -8,7 +8,7 @@ import aiohttp
from bigchaindb import config from bigchaindb import config
from bigchaindb.common.utils import gen_timestamp from bigchaindb.common.utils import gen_timestamp
from bigchaindb.events import EventTypes, Event from bigchaindb.events import EventTypes, Event
from bigchaindb.tendermint.utils import decode_transaction_base64 from bigchaindb.tendermint_utils import decode_transaction_base64
HOST = config['tendermint']['host'] HOST = config['tendermint']['host']

View File

@ -16,13 +16,12 @@ except ImportError:
import requests import requests
import bigchaindb import bigchaindb
from bigchaindb import backend, config_utils from bigchaindb import backend, config_utils, fastquery
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.common.exceptions import (SchemaValidationError, from bigchaindb.common.exceptions import (SchemaValidationError,
ValidationError, ValidationError,
DoubleSpend) DoubleSpend)
from bigchaindb.tendermint.utils import encode_transaction, merkleroot from bigchaindb.tendermint_utils import encode_transaction, merkleroot
from bigchaindb.tendermint import fastquery
from bigchaindb import exceptions as core_exceptions from bigchaindb import exceptions as core_exceptions
from bigchaindb.consensus import BaseConsensusRules from bigchaindb.consensus import BaseConsensusRules

View File

@ -14,7 +14,7 @@ class Transaction(Transaction):
"""Validate transaction spend """Validate transaction spend
Args: Args:
bigchain (BigchainDB): an instantiated bigchaindb.tendermint.BigchainDB object. bigchain (BigchainDB): an instantiated bigchaindb.BigchainDB object.
Returns: Returns:
The transaction (Transaction) if the transaction is valid else it The transaction (Transaction) if the transaction is valid else it
@ -108,7 +108,7 @@ class Transaction(Transaction):
asset from the asset table and reconstructs the transaction. asset from the asset table and reconstructs the transaction.
Args: Args:
bigchain (:class:`~bigchaindb.tendermint.BigchainDB`): An instance bigchain (:class:`~bigchaindb.BigchainDB`): An instance
of BigchainDB used to perform database queries. of BigchainDB used to perform database queries.
tx_dict_list (:list:`dict` or :obj:`dict`): The transaction dict or tx_dict_list (:list:`dict` or :obj:`dict`): The transaction dict or
list of transaction dict as returned from the database. list of transaction dict as returned from the database.

View File

@ -3,10 +3,10 @@ import logging
import setproctitle import setproctitle
import bigchaindb import bigchaindb
from bigchaindb.tendermint.lib import BigchainDB from bigchaindb.lib import BigchainDB
from bigchaindb.tendermint.core import App from bigchaindb.core import App
from bigchaindb.web import server, websocket_server from bigchaindb.web import server, websocket_server
from bigchaindb.tendermint import event_stream from bigchaindb import event_stream
from bigchaindb.events import Exchange, EventTypes from bigchaindb.events import Exchange, EventTypes
from bigchaindb.utils import Process from bigchaindb.utils import Process

View File

@ -1,7 +0,0 @@
"""Code necessary for integrating with Tendermint."""
# Order is important!
# If we import core first, core will try to load BigchainDB from
# __init__ itself, causing a loop.
from bigchaindb.tendermint.lib import BigchainDB # noqa
from bigchaindb.tendermint.core import App # noqa

View File

@ -1,178 +0,0 @@
"""This module contains all the goodness to integrate BigchainDB
with Tendermint."""
import logging
from abci.application import BaseApplication
from abci.types_pb2 import (
ResponseInitChain,
ResponseInfo,
ResponseCheckTx,
ResponseBeginBlock,
ResponseDeliverTx,
ResponseEndBlock,
ResponseCommit,
Validator,
PubKey
)
from bigchaindb.tendermint import BigchainDB
from bigchaindb.tendermint.utils import (decode_transaction,
calculate_hash)
from bigchaindb.tendermint.lib import Block, PreCommitState
from bigchaindb.backend.query import PRE_COMMIT_ID
CodeTypeOk = 0
CodeTypeError = 1
logger = logging.getLogger(__name__)
class App(BaseApplication):
"""Bridge between BigchainDB and Tendermint.
The role of this class is to expose the BigchainDB
transactional logic to the Tendermint Consensus
State Machine."""
def __init__(self, bigchaindb=None):
self.bigchaindb = bigchaindb or BigchainDB()
self.block_txn_ids = []
self.block_txn_hash = ''
self.block_transactions = []
self.validators = None
self.new_height = None
def init_chain(self, validators):
"""Initialize chain with block of height 0"""
block = Block(app_hash='', height=0, transactions=[])
self.bigchaindb.store_block(block._asdict())
return ResponseInitChain()
def info(self, request):
"""Return height of the latest committed block."""
r = ResponseInfo()
block = self.bigchaindb.get_latest_block()
if block:
r.last_block_height = block['height']
r.last_block_app_hash = block['app_hash'].encode('utf-8')
else:
r.last_block_height = 0
r.last_block_app_hash = b''
return r
def check_tx(self, raw_transaction):
"""Validate the transaction before entry into
the mempool.
Args:
raw_tx: a raw string (in bytes) transaction."""
logger.benchmark('CHECK_TX_INIT')
logger.debug('check_tx: %s', raw_transaction)
transaction = decode_transaction(raw_transaction)
if self.bigchaindb.is_valid_transaction(transaction):
logger.debug('check_tx: VALID')
logger.benchmark('CHECK_TX_END, tx_id:%s', transaction['id'])
return ResponseCheckTx(code=CodeTypeOk)
else:
logger.debug('check_tx: INVALID')
logger.benchmark('CHECK_TX_END, tx_id:%s', transaction['id'])
return ResponseCheckTx(code=CodeTypeError)
def begin_block(self, req_begin_block):
"""Initialize list of transaction.
Args:
req_begin_block: block object which contains block header
and block hash.
"""
logger.benchmark('BEGIN BLOCK, height:%s, num_txs:%s',
req_begin_block.header.height,
req_begin_block.header.num_txs)
self.block_txn_ids = []
self.block_transactions = []
return ResponseBeginBlock()
def deliver_tx(self, raw_transaction):
"""Validate the transaction before mutating the state.
Args:
raw_tx: a raw string (in bytes) transaction."""
logger.debug('deliver_tx: %s', raw_transaction)
transaction = self.bigchaindb.is_valid_transaction(
decode_transaction(raw_transaction), self.block_transactions)
if not transaction:
logger.debug('deliver_tx: INVALID')
return ResponseDeliverTx(code=CodeTypeError)
else:
logger.debug('storing tx')
self.block_txn_ids.append(transaction.id)
self.block_transactions.append(transaction)
return ResponseDeliverTx(code=CodeTypeOk)
def end_block(self, request_end_block):
"""Calculate block hash using transaction ids and previous block
hash to be stored in the next block.
Args:
height (int): new height of the chain."""
height = request_end_block.height
self.new_height = height
block_txn_hash = calculate_hash(self.block_txn_ids)
block = self.bigchaindb.get_latest_block()
if self.block_txn_ids:
self.block_txn_hash = calculate_hash([block['app_hash'], block_txn_hash])
else:
self.block_txn_hash = block['app_hash']
validator_updates = self.bigchaindb.get_validator_update()
validator_updates = [encode_validator(v) for v in validator_updates]
# set sync status to true
self.bigchaindb.delete_validator_update()
# Store pre-commit state to recover in case there is a crash
# during `commit`
pre_commit_state = PreCommitState(commit_id=PRE_COMMIT_ID,
height=self.new_height,
transactions=self.block_txn_ids)
logger.debug('Updating PreCommitState: %s', self.new_height)
self.bigchaindb.store_pre_commit_state(pre_commit_state._asdict())
return ResponseEndBlock(validator_updates=validator_updates)
def commit(self):
"""Store the new height and along with block hash."""
data = self.block_txn_hash.encode('utf-8')
# register a new block only when new transactions are received
if self.block_txn_ids:
self.bigchaindb.store_bulk_transactions(self.block_transactions)
block = Block(app_hash=self.block_txn_hash,
height=self.new_height,
transactions=self.block_txn_ids)
# NOTE: storing the block should be the last operation during commit
# this effects crash recovery. Refer BEP#8 for details
self.bigchaindb.store_block(block._asdict())
logger.debug('Commit-ing new block with hash: apphash=%s ,'
'height=%s, txn ids=%s', data, self.new_height,
self.block_txn_ids)
logger.benchmark('COMMIT_BLOCK, height:%s', self.new_height)
return ResponseCommit(data=data)
def encode_validator(v):
ed25519_public_key = v['pub_key']['data']
# NOTE: tendermint expects public to be encoded in go-amino format
pub_key = PubKey(type='ed25519',
data=bytes.fromhex(ed25519_public_key))
return Validator(pub_key=pub_key,
address=b'',
power=v['power'])

View File

@ -11,7 +11,7 @@ from flask_cors import CORS
import gunicorn.app.base import gunicorn.app.base
from bigchaindb import utils from bigchaindb import utils
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
from bigchaindb.web.routes import add_routes from bigchaindb.web.routes import add_routes
from bigchaindb.web.strip_content_type_middleware import StripContentTypeMiddleware from bigchaindb.web.strip_content_type_middleware import StripContentTypeMiddleware

View File

@ -5,8 +5,7 @@ import os
import os.path import os.path
from bigchaindb.common.transaction import Transaction, Input, TransactionLink from bigchaindb.common.transaction import Transaction, Input, TransactionLink
from bigchaindb.tendermint import BigchainDB from bigchaindb import lib
from bigchaindb.tendermint import lib
from bigchaindb.web import server from bigchaindb.web import server

View File

@ -10,7 +10,6 @@ Appendices
the-bigchaindb-class the-bigchaindb-class
backend backend
commands commands
tendermint-integration
aws-setup aws-setup
generate-key-pair-for-ssh generate-key-pair-for-ssh
firewall-notes firewall-notes

View File

@ -1,26 +0,0 @@
######################
Tendermint Integration
######################
.. automodule:: bigchaindb.tendermint
:special-members: __init__
.. automodule:: bigchaindb.tendermint.lib
:special-members: __init__
:noindex:
.. automodule:: bigchaindb.tendermint.core
:special-members: __init__
.. automodule:: bigchaindb.tendermint.event_stream
:special-members: __init__
.. automodule:: bigchaindb.tendermint.fastquery
:special-members: __init__
.. automodule:: bigchaindb.tendermint.commands
:special-members: __init__
.. automodule:: bigchaindb.tendermint.utils
:special-members: __init__

View File

@ -2,4 +2,4 @@
The BigchainDB Class The BigchainDB Class
#################### ####################
.. autoclass:: bigchaindb.tendermint.BigchainDB .. autoclass:: bigchaindb.BigchainDB

View File

@ -229,7 +229,7 @@ def test_get_spending_transactions(user_pk, user_sk):
def test_store_block(): def test_store_block():
from bigchaindb.backend import connect, query from bigchaindb.backend import connect, query
from bigchaindb.tendermint.lib import Block from bigchaindb.lib import Block
conn = connect() conn = connect()
block = Block(app_hash='random_utxo', block = Block(app_hash='random_utxo',
@ -242,7 +242,7 @@ def test_store_block():
def test_get_block(): def test_get_block():
from bigchaindb.backend import connect, query from bigchaindb.backend import connect, query
from bigchaindb.tendermint.lib import Block from bigchaindb.lib import Block
conn = connect() conn = connect()
block = Block(app_hash='random_utxo', block = Block(app_hash='random_utxo',
@ -345,7 +345,7 @@ def test_get_unspent_outputs(db_context, utxoset):
def test_store_pre_commit_state(db_context): def test_store_pre_commit_state(db_context):
from bigchaindb.backend import query from bigchaindb.backend import query
from bigchaindb.tendermint.lib import PreCommitState from bigchaindb.lib import PreCommitState
state = PreCommitState(commit_id='test', state = PreCommitState(commit_id='test',
height=3, height=3,
@ -359,7 +359,7 @@ def test_store_pre_commit_state(db_context):
def test_get_pre_commit_state(db_context): def test_get_pre_commit_state(db_context):
from bigchaindb.backend import query from bigchaindb.backend import query
from bigchaindb.tendermint.lib import PreCommitState from bigchaindb.lib import PreCommitState
state = PreCommitState(commit_id='test2', state = PreCommitState(commit_id='test2',
height=3, height=3,

View File

@ -90,7 +90,7 @@ def test_bigchain_run_init_when_db_exists(mocker, capsys):
def test__run_init(mocker): def test__run_init(mocker):
from bigchaindb.commands.bigchaindb import _run_init from bigchaindb.commands.bigchaindb import _run_init
bigchain_mock = mocker.patch( bigchain_mock = mocker.patch(
'bigchaindb.commands.bigchaindb.bigchaindb.tendermint.BigchainDB') 'bigchaindb.commands.bigchaindb.bigchaindb.BigchainDB')
init_db_mock = mocker.patch( init_db_mock = mocker.patch(
'bigchaindb.commands.bigchaindb.schema.init_database', 'bigchaindb.commands.bigchaindb.schema.init_database',
autospec=True, autospec=True,
@ -274,7 +274,7 @@ def test_calling_main(start_mock, base_parser_mock, parse_args_mock,
@patch('bigchaindb.config_utils.autoconfigure') @patch('bigchaindb.config_utils.autoconfigure')
@patch('bigchaindb.commands.bigchaindb.run_recover') @patch('bigchaindb.commands.bigchaindb.run_recover')
@patch('bigchaindb.tendermint.commands.start') @patch('bigchaindb.start.start')
def test_recover_db_on_start(mock_autoconfigure, def test_recover_db_on_start(mock_autoconfigure,
mock_run_recover, mock_run_recover,
mock_start, mock_start,
@ -293,7 +293,7 @@ def test_recover_db_on_start(mock_autoconfigure,
def test_run_recover(b, alice, bob): def test_run_recover(b, alice, bob):
from bigchaindb.commands.bigchaindb import run_recover from bigchaindb.commands.bigchaindb import run_recover
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.tendermint.lib import Block, PreCommitState from bigchaindb.lib import Block, PreCommitState
from bigchaindb.backend.query import PRE_COMMIT_ID from bigchaindb.backend.query import PRE_COMMIT_ID
from bigchaindb.backend import query from bigchaindb.backend import query

View File

@ -17,7 +17,7 @@ from pymongo import MongoClient
from bigchaindb.common import crypto from bigchaindb.common import crypto
from bigchaindb.log import setup_logging from bigchaindb.log import setup_logging
from bigchaindb.tendermint.lib import Block from bigchaindb.lib import Block
TEST_DB_NAME = 'bigchain_test' TEST_DB_NAME = 'bigchain_test'
@ -269,13 +269,13 @@ def merlin_pubkey(merlin):
@pytest.fixture @pytest.fixture
def b(): def b():
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
return BigchainDB() return BigchainDB()
@pytest.fixture @pytest.fixture
def tb(): def tb():
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
return BigchainDB() return BigchainDB()
@ -514,7 +514,7 @@ def event_loop(request):
@pytest.fixture(scope='session') @pytest.fixture(scope='session')
def abci_server(): def abci_server():
from abci import ABCIServer from abci import ABCIServer
from bigchaindb.tendermint.core import App from bigchaindb.core import App
from bigchaindb.utils import Process from bigchaindb.utils import Process
app = ABCIServer(app=App()) app = ABCIServer(app=App())

View File

@ -280,7 +280,7 @@ class TestBigchainApi(object):
@pytest.mark.usefixtures('inputs') @pytest.mark.usefixtures('inputs')
def test_write_transaction(self, b, user_pk, user_sk): def test_write_transaction(self, b, user_pk, user_sk):
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
input_tx = b.get_owned_ids(user_pk).pop() input_tx = b.get_owned_ids(user_pk).pop()
@ -439,7 +439,7 @@ class TestBigchainApi(object):
from bigchaindb.common.exceptions import InputDoesNotExist from bigchaindb.common.exceptions import InputDoesNotExist
from bigchaindb.common.transaction import Input, TransactionLink from bigchaindb.common.transaction import Input, TransactionLink
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
# Create an input for a non existing transaction # Create an input for a non existing transaction
input = Input(Ed25519Sha256(public_key=b58decode(user_pk)), input = Input(Ed25519Sha256(public_key=b58decode(user_pk)),
@ -970,8 +970,8 @@ class TestMultipleInputs(object):
def test_get_owned_ids_calls_get_outputs_filtered(): def test_get_owned_ids_calls_get_outputs_filtered():
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
with patch('bigchaindb.tendermint.BigchainDB.get_outputs_filtered') as gof: with patch('bigchaindb.BigchainDB.get_outputs_filtered') as gof:
b = BigchainDB() b = BigchainDB()
res = b.get_owned_ids('abc') res = b.get_owned_ids('abc')
gof.assert_called_once_with('abc', spent=False) gof.assert_called_once_with('abc', spent=False)
@ -981,13 +981,13 @@ def test_get_owned_ids_calls_get_outputs_filtered():
@pytest.mark.tendermint @pytest.mark.tendermint
def test_get_outputs_filtered_only_unspent(): def test_get_outputs_filtered_only_unspent():
from bigchaindb.common.transaction import TransactionLink from bigchaindb.common.transaction import TransactionLink
from bigchaindb.tendermint.lib import BigchainDB from bigchaindb.lib import BigchainDB
go = 'bigchaindb.tendermint.fastquery.FastQuery.get_outputs_by_public_key' go = 'bigchaindb.fastquery.FastQuery.get_outputs_by_public_key'
with patch(go) as get_outputs: with patch(go) as get_outputs:
get_outputs.return_value = [TransactionLink('a', 1), get_outputs.return_value = [TransactionLink('a', 1),
TransactionLink('b', 2)] TransactionLink('b', 2)]
fs = 'bigchaindb.tendermint.fastquery.FastQuery.filter_spent_outputs' fs = 'bigchaindb.fastquery.FastQuery.filter_spent_outputs'
with patch(fs) as filter_spent: with patch(fs) as filter_spent:
filter_spent.return_value = [TransactionLink('b', 2)] filter_spent.return_value = [TransactionLink('b', 2)]
out = BigchainDB().get_outputs_filtered('abc', spent=False) out = BigchainDB().get_outputs_filtered('abc', spent=False)
@ -998,12 +998,12 @@ def test_get_outputs_filtered_only_unspent():
@pytest.mark.tendermint @pytest.mark.tendermint
def test_get_outputs_filtered_only_spent(): def test_get_outputs_filtered_only_spent():
from bigchaindb.common.transaction import TransactionLink from bigchaindb.common.transaction import TransactionLink
from bigchaindb.tendermint.lib import BigchainDB from bigchaindb.lib import BigchainDB
go = 'bigchaindb.tendermint.fastquery.FastQuery.get_outputs_by_public_key' go = 'bigchaindb.fastquery.FastQuery.get_outputs_by_public_key'
with patch(go) as get_outputs: with patch(go) as get_outputs:
get_outputs.return_value = [TransactionLink('a', 1), get_outputs.return_value = [TransactionLink('a', 1),
TransactionLink('b', 2)] TransactionLink('b', 2)]
fs = 'bigchaindb.tendermint.fastquery.FastQuery.filter_unspent_outputs' fs = 'bigchaindb.fastquery.FastQuery.filter_unspent_outputs'
with patch(fs) as filter_spent: with patch(fs) as filter_spent:
filter_spent.return_value = [TransactionLink('b', 2)] filter_spent.return_value = [TransactionLink('b', 2)]
out = BigchainDB().get_outputs_filtered('abc', spent=True) out = BigchainDB().get_outputs_filtered('abc', spent=True)
@ -1012,13 +1012,13 @@ def test_get_outputs_filtered_only_spent():
@pytest.mark.tendermint @pytest.mark.tendermint
@patch('bigchaindb.tendermint.fastquery.FastQuery.filter_unspent_outputs') @patch('bigchaindb.fastquery.FastQuery.filter_unspent_outputs')
@patch('bigchaindb.tendermint.fastquery.FastQuery.filter_spent_outputs') @patch('bigchaindb.fastquery.FastQuery.filter_spent_outputs')
def test_get_outputs_filtered(filter_spent, filter_unspent): def test_get_outputs_filtered(filter_spent, filter_unspent):
from bigchaindb.common.transaction import TransactionLink from bigchaindb.common.transaction import TransactionLink
from bigchaindb.tendermint.lib import BigchainDB from bigchaindb.lib import BigchainDB
go = 'bigchaindb.tendermint.fastquery.FastQuery.get_outputs_by_public_key' go = 'bigchaindb.fastquery.FastQuery.get_outputs_by_public_key'
with patch(go) as get_outputs: with patch(go) as get_outputs:
get_outputs.return_value = [TransactionLink('a', 1), get_outputs.return_value = [TransactionLink('a', 1),
TransactionLink('b', 2)] TransactionLink('b', 2)]

View File

@ -3,7 +3,7 @@ import pytest
@pytest.fixture @pytest.fixture
def b(): def b():
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
return BigchainDB() return BigchainDB()

View File

@ -6,7 +6,7 @@ from abci.types_pb2 import (
RequestEndBlock RequestEndBlock
) )
from bigchaindb.tendermint.core import CodeTypeOk, CodeTypeError from bigchaindb.core import CodeTypeOk, CodeTypeError
pytestmark = [pytest.mark.tendermint, pytest.mark.bdb] pytestmark = [pytest.mark.tendermint, pytest.mark.bdb]
@ -17,7 +17,7 @@ def encode_tx_to_bytes(transaction):
def test_check_tx__signed_create_is_ok(b): def test_check_tx__signed_create_is_ok(b):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
@ -34,7 +34,7 @@ def test_check_tx__signed_create_is_ok(b):
def test_check_tx__unsigned_create_is_error(b): def test_check_tx__unsigned_create_is_error(b):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
@ -51,7 +51,7 @@ def test_check_tx__unsigned_create_is_error(b):
@pytest.mark.bdb @pytest.mark.bdb
def test_deliver_tx__valid_create_updates_db(b): def test_deliver_tx__valid_create_updates_db(b):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
@ -84,7 +84,7 @@ def test_deliver_tx__valid_create_updates_db(b):
def test_deliver_tx__double_spend_fails(b): def test_deliver_tx__double_spend_fails(b):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
@ -113,7 +113,7 @@ def test_deliver_tx__double_spend_fails(b):
def test_deliver_transfer_tx__double_spend_fails(b): def test_deliver_transfer_tx__double_spend_fails(b):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
@ -157,9 +157,9 @@ def test_deliver_transfer_tx__double_spend_fails(b):
def test_end_block_return_validator_updates(b): def test_end_block_return_validator_updates(b):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.backend import query from bigchaindb.backend import query
from bigchaindb.tendermint.core import encode_validator from bigchaindb.core import encode_validator
from bigchaindb.backend.query import VALIDATOR_UPDATE_ID from bigchaindb.backend.query import VALIDATOR_UPDATE_ID
app = App(b) app = App(b)
@ -183,7 +183,7 @@ def test_end_block_return_validator_updates(b):
def test_store_pre_commit_state_in_end_block(b, alice): def test_store_pre_commit_state_in_end_block(b, alice):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.backend import query from bigchaindb.backend import query
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.backend.query import PRE_COMMIT_ID from bigchaindb.backend.query import PRE_COMMIT_ID

View File

@ -8,7 +8,7 @@ import pytest
@pytest.mark.tendermint @pytest.mark.tendermint
def test_process_event_new_block(): def test_process_event_new_block():
from bigchaindb.tendermint.event_stream import process_event from bigchaindb.event_stream import process_event
event = '{"jsonrpc": "2.0", "id": "test_stream_id#event", "result": {'\ event = '{"jsonrpc": "2.0", "id": "test_stream_id#event", "result": {'\
'"query": "tm.event=\'NewBlock\'", "data": { "type": "CF18EA939D3240",'\ '"query": "tm.event=\'NewBlock\'", "data": { "type": "CF18EA939D3240",'\
@ -46,7 +46,7 @@ def test_process_event_new_block():
@pytest.mark.tendermint @pytest.mark.tendermint
def test_process_event_empty_block(): def test_process_event_empty_block():
from bigchaindb.tendermint.event_stream import process_event from bigchaindb.event_stream import process_event
event = '{"jsonrpc": "2.0", "id": "bigchaindb_stream_1524555674#event",'\ event = '{"jsonrpc": "2.0", "id": "bigchaindb_stream_1524555674#event",'\
'"result": {"query": "tm.event=\'NewBlock\'", "data": {"type": '\ '"result": {"query": "tm.event=\'NewBlock\'", "data": {"type": '\
@ -67,7 +67,7 @@ def test_process_event_empty_block():
@pytest.mark.tendermint @pytest.mark.tendermint
def test_process_unknown_event(): def test_process_unknown_event():
from bigchaindb.tendermint.event_stream import process_event from bigchaindb.event_stream import process_event
event = '{"jsonrpc": "2.0", "id": "test_stream_id#event",'\ event = '{"jsonrpc": "2.0", "id": "test_stream_id#event",'\
' "result": { "query": "tm.event=\'UnknownEvent\'" }}' ' "result": { "query": "tm.event=\'UnknownEvent\'" }}'
@ -80,7 +80,7 @@ def test_process_unknown_event():
@pytest.mark.asyncio @pytest.mark.asyncio
@pytest.mark.abci @pytest.mark.abci
async def test_subscribe_events(tendermint_ws_url, b): async def test_subscribe_events(tendermint_ws_url, b):
from bigchaindb.tendermint.event_stream import subscribe_events from bigchaindb.event_stream import subscribe_events
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
from bigchaindb.models import Transaction from bigchaindb.models import Transaction

View File

@ -12,8 +12,8 @@ from io import BytesIO
@pytest.mark.tendermint @pytest.mark.tendermint
@pytest.mark.bdb @pytest.mark.bdb
def test_app(tb): def test_app(tb):
from bigchaindb.tendermint import App from bigchaindb import App
from bigchaindb.tendermint.utils import calculate_hash from bigchaindb.tendermint_utils import calculate_hash
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
@ -103,7 +103,7 @@ def test_upsert_validator(b, alice):
from bigchaindb.backend.query import VALIDATOR_UPDATE_ID from bigchaindb.backend.query import VALIDATOR_UPDATE_ID
from bigchaindb.backend import query, connect from bigchaindb.backend import query, connect
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.tendermint.utils import public_key_to_base64 from bigchaindb.tendermint_utils import public_key_to_base64
import time import time
conn = connect() conn = connect()

View File

@ -47,7 +47,7 @@ def test_asset_is_separated_from_transaciton(b):
@pytest.mark.bdb @pytest.mark.bdb
def test_get_latest_block(tb): def test_get_latest_block(tb):
from bigchaindb.tendermint.lib import Block from bigchaindb.lib import Block
b = tb b = tb
for i in range(10): for i in range(10):
@ -63,7 +63,7 @@ def test_get_latest_block(tb):
@pytest.mark.bdb @pytest.mark.bdb
@patch('bigchaindb.backend.query.get_block', return_value=None) @patch('bigchaindb.backend.query.get_block', return_value=None)
@patch('bigchaindb.tendermint.lib.BigchainDB.get_latest_block', return_value={'height': 10}) @patch('bigchaindb.BigchainDB.get_latest_block', return_value={'height': 10})
def test_get_empty_block(_0, _1, tb): def test_get_empty_block(_0, _1, tb):
assert tb.get_block(5) == {'height': 5, 'transactions': []} assert tb.get_block(5) == {'height': 5, 'transactions': []}
@ -86,7 +86,7 @@ def test_validation_error(b):
def test_write_and_post_transaction(mock_post, b): def test_write_and_post_transaction(mock_post, b):
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.common.crypto import generate_key_pair from bigchaindb.common.crypto import generate_key_pair
from bigchaindb.tendermint.utils import encode_transaction from bigchaindb.tendermint_utils import encode_transaction
alice = generate_key_pair() alice = generate_key_pair()
tx = Transaction.create([alice.public_key], tx = Transaction.create([alice.public_key],

View File

@ -12,7 +12,7 @@ pytestmark = pytest.mark.tendermint
def test_encode_decode_transaction(b): def test_encode_decode_transaction(b):
from bigchaindb.tendermint.utils import (encode_transaction, from bigchaindb.tendermint_utils import (encode_transaction,
decode_transaction) decode_transaction)
asset = { asset = {
@ -30,7 +30,7 @@ def test_encode_decode_transaction(b):
def test_calculate_hash_no_key(b): def test_calculate_hash_no_key(b):
from bigchaindb.tendermint.utils import calculate_hash from bigchaindb.tendermint_utils import calculate_hash
# pass an empty list # pass an empty list
assert calculate_hash([]) == '' assert calculate_hash([]) == ''
@ -38,7 +38,7 @@ def test_calculate_hash_no_key(b):
# TODO test for the case of an empty list of hashes, and possibly other cases. # TODO test for the case of an empty list of hashes, and possibly other cases.
def test_merkleroot(): def test_merkleroot():
from bigchaindb.tendermint.utils import merkleroot from bigchaindb.tendermint_utils import merkleroot
hashes = [sha3_256(i.encode()).digest() for i in 'abc'] hashes = [sha3_256(i.encode()).digest() for i in 'abc']
assert merkleroot(hashes) == ( assert merkleroot(hashes) == (
'78c7c394d3158c218916b7ae0ebdea502e0f4e85c08e3b371e3dfd824d389fa3') '78c7c394d3158c218916b7ae0ebdea502e0f4e85c08e3b371e3dfd824d389fa3')
@ -54,14 +54,14 @@ SAMPLE_PUBLIC_KEY = {
def test_convert_base64_public_key_to_address(): def test_convert_base64_public_key_to_address():
from bigchaindb.tendermint.utils import public_key64_to_address from bigchaindb.tendermint_utils import public_key64_to_address
address = public_key64_to_address(SAMPLE_PUBLIC_KEY['pub_key']['value']) address = public_key64_to_address(SAMPLE_PUBLIC_KEY['pub_key']['value'])
assert address == SAMPLE_PUBLIC_KEY['address'] assert address == SAMPLE_PUBLIC_KEY['address']
def test_public_key_encoding_decoding(): def test_public_key_encoding_decoding():
from bigchaindb.tendermint.utils import (public_key_from_base64, from bigchaindb.tendermint_utils import (public_key_from_base64,
public_key_to_base64) public_key_to_base64)
public_key = public_key_from_base64(SAMPLE_PUBLIC_KEY['pub_key']['value']) public_key = public_key_from_base64(SAMPLE_PUBLIC_KEY['pub_key']['value'])

View File

@ -35,7 +35,7 @@ def test_bigchain_instance_raises_when_not_configured(request, monkeypatch):
import bigchaindb import bigchaindb
from bigchaindb import config_utils from bigchaindb import config_utils
from bigchaindb.common import exceptions from bigchaindb.common import exceptions
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
assert 'CONFIGURED' not in bigchaindb.config assert 'CONFIGURED' not in bigchaindb.config
# We need to disable ``bigchaindb.config_utils.autoconfigure`` to avoid reading # We need to disable ``bigchaindb.config_utils.autoconfigure`` to avoid reading

View File

@ -31,7 +31,7 @@ def config(request, monkeypatch):
@pytest.mark.skipif(reason='will be fixed in another PR') @pytest.mark.skipif(reason='will be fixed in another PR')
def test_bigchain_class_default_initialization(config): def test_bigchain_class_default_initialization(config):
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
from bigchaindb.consensus import BaseConsensusRules from bigchaindb.consensus import BaseConsensusRules
from bigchaindb.backend.connection import Connection from bigchaindb.backend.connection import Connection
bigchain = BigchainDB() bigchain = BigchainDB()
@ -44,7 +44,7 @@ def test_bigchain_class_default_initialization(config):
@pytest.mark.skipif(reason='will be fixed in another PR') @pytest.mark.skipif(reason='will be fixed in another PR')
def test_bigchain_class_initialization_with_parameters(config): def test_bigchain_class_initialization_with_parameters(config):
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
from bigchaindb.backend import connect from bigchaindb.backend import connect
from bigchaindb.consensus import BaseConsensusRules from bigchaindb.consensus import BaseConsensusRules
init_db_kwargs = { init_db_kwargs = {
@ -65,7 +65,7 @@ def test_bigchain_class_initialization_with_parameters(config):
@pytest.mark.skipif(reason='will be fixed in another PR') @pytest.mark.skipif(reason='will be fixed in another PR')
def test_get_blocks_status_containing_tx(monkeypatch): def test_get_blocks_status_containing_tx(monkeypatch):
from bigchaindb.backend import query as backend_query from bigchaindb.backend import query as backend_query
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
blocks = [ blocks = [
{'id': 1}, {'id': 2} {'id': 1}, {'id': 2}
] ]

View File

@ -4,7 +4,7 @@ import pytest
@pytest.fixture @pytest.fixture
def app(request): def app(request):
from bigchaindb.web import server from bigchaindb.web import server
from bigchaindb.tendermint.lib import BigchainDB from bigchaindb.lib import BigchainDB
if request.config.getoption('--database-backend') == 'localmongodb': if request.config.getoption('--database-backend') == 'localmongodb':
app = server.create_app(debug=True, bigchaindb_factory=BigchainDB) app = server.create_app(debug=True, bigchaindb_factory=BigchainDB)

View File

@ -1,7 +1,7 @@
import pytest import pytest
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.tendermint.lib import Block from bigchaindb.lib import Block
BLOCKS_ENDPOINT = '/api/v1/blocks/' BLOCKS_ENDPOINT = '/api/v1/blocks/'

View File

@ -11,7 +11,7 @@ def test_get_outputs_endpoint(client, user_pk):
m = MagicMock() m = MagicMock()
m.txid = 'a' m.txid = 'a'
m.output = 0 m.output = 0
with patch('bigchaindb.tendermint.lib.BigchainDB.get_outputs_filtered') as gof: with patch('bigchaindb.BigchainDB.get_outputs_filtered') as gof:
gof.return_value = [m, m] gof.return_value = [m, m]
res = client.get(OUTPUTS_ENDPOINT + '?public_key={}'.format(user_pk)) res = client.get(OUTPUTS_ENDPOINT + '?public_key={}'.format(user_pk))
assert res.json == [ assert res.json == [
@ -27,7 +27,7 @@ def test_get_outputs_endpoint_unspent(client, user_pk):
m = MagicMock() m = MagicMock()
m.txid = 'a' m.txid = 'a'
m.output = 0 m.output = 0
with patch('bigchaindb.tendermint.lib.BigchainDB.get_outputs_filtered') as gof: with patch('bigchaindb.BigchainDB.get_outputs_filtered') as gof:
gof.return_value = [m] gof.return_value = [m]
params = '?spent=False&public_key={}'.format(user_pk) params = '?spent=False&public_key={}'.format(user_pk)
res = client.get(OUTPUTS_ENDPOINT + params) res = client.get(OUTPUTS_ENDPOINT + params)
@ -41,7 +41,7 @@ def test_get_outputs_endpoint_spent(client, user_pk):
m = MagicMock() m = MagicMock()
m.txid = 'a' m.txid = 'a'
m.output = 0 m.output = 0
with patch('bigchaindb.tendermint.lib.BigchainDB.get_outputs_filtered') as gof: with patch('bigchaindb.BigchainDB.get_outputs_filtered') as gof:
gof.return_value = [m] gof.return_value = [m]
params = '?spent=true&public_key={}'.format(user_pk) params = '?spent=true&public_key={}'.format(user_pk)
res = client.get(OUTPUTS_ENDPOINT + params) res = client.get(OUTPUTS_ENDPOINT + params)

View File

@ -372,7 +372,7 @@ def test_transactions_get_list_good(client):
asset_id = '1' * 64 asset_id = '1' * 64
with patch('bigchaindb.tendermint.BigchainDB.get_transactions_filtered', get_txs_patched): with patch('bigchaindb.BigchainDB.get_transactions_filtered', get_txs_patched):
url = TX_ENDPOINT + '?asset_id=' + asset_id url = TX_ENDPOINT + '?asset_id=' + asset_id
assert client.get(url).json == [ assert client.get(url).json == [
['asset_id', asset_id], ['asset_id', asset_id],
@ -389,7 +389,7 @@ def test_transactions_get_list_good(client):
def test_transactions_get_list_bad(client): def test_transactions_get_list_bad(client):
def should_not_be_called(): def should_not_be_called():
assert False assert False
with patch('bigchaindb.tendermint.BigchainDB.get_transactions_filtered', with patch('bigchaindb.BigchainDB.get_transactions_filtered',
lambda *_, **__: should_not_be_called()): lambda *_, **__: should_not_be_called()):
# Test asset id validated # Test asset id validated
url = TX_ENDPOINT + '?asset_id=' + '1' * 63 url = TX_ENDPOINT + '?asset_id=' + '1' * 63
@ -404,7 +404,7 @@ def test_transactions_get_list_bad(client):
@pytest.mark.tendermint @pytest.mark.tendermint
def test_return_only_valid_transaction(client): def test_return_only_valid_transaction(client):
from bigchaindb.tendermint import BigchainDB from bigchaindb import BigchainDB
def get_transaction_patched(status): def get_transaction_patched(status):
def inner(self, tx_id, include_status): def inner(self, tx_id, include_status):
@ -415,12 +415,12 @@ def test_return_only_valid_transaction(client):
# UNDECIDED or VALID block, as well as transactions from the backlog. # UNDECIDED or VALID block, as well as transactions from the backlog.
# As the endpoint uses `get_transaction`, we don't have to test # As the endpoint uses `get_transaction`, we don't have to test
# against invalid transactions here. # against invalid transactions here.
with patch('bigchaindb.tendermint.BigchainDB.get_transaction', with patch('bigchaindb.BigchainDB.get_transaction',
get_transaction_patched(BigchainDB.TX_UNDECIDED)): get_transaction_patched(BigchainDB.TX_UNDECIDED)):
url = '{}{}'.format(TX_ENDPOINT, '123') url = '{}{}'.format(TX_ENDPOINT, '123')
assert client.get(url).status_code == 404 assert client.get(url).status_code == 404
with patch('bigchaindb.tendermint.BigchainDB.get_transaction', with patch('bigchaindb.BigchainDB.get_transaction',
get_transaction_patched(BigchainDB.TX_IN_BACKLOG)): get_transaction_patched(BigchainDB.TX_IN_BACKLOG)):
url = '{}{}'.format(TX_ENDPOINT, '123') url = '{}{}'.format(TX_ENDPOINT, '123')
assert client.get(url).status_code == 404 assert client.get(url).status_code == 404