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

* Planning release * Clean up after move * Add exceptions.py * Add crypto.py * Adjust setup to package structure * Fix tests * Add test coverage * Comply to flake8 * Add test coverage * Transfer-tx fulfillments validation * Remove condition and fulfillment ids * Fix signing logic Specifically for transfer-tx with multiple inputs and outputs. * Compliance to legacy BDB models * Adjust fulfillment validation interface * Add serialization validation for txids * Use __eq__ to compare objects * Heavy refactor to comply with current implementation * Add Transaction.create * Correct fulfillment validation logic * Add Transaction.create for hashlock conditions * Add hashlock condition serialization * Transaction.transfer add single input and outputs * Small adjustments to transfer-tx interface * Create transfer-tx interface * Increase test coverage * Adjust fulfillment (de)serialization * Catch CC Error for Fulfillment * Allow custom thresholds * PR feedback * Fix tests * Rename Data to Metadata * Add Asset exceptions * Add basic Asset model * More renaming of payload => data * Add Asset into work-flow-functions * Add Asset amount to condition * add fulfillment exception * initial integration of asset * Make transaction.py compy to 79 chars * Make util.py comply to 79 chars * Make exceptions.py comply to 80 chars * Renaming inp to input_ * fix pep8 issues * Correct raised error * Remove resolved TODOs * prevent adding None as fulfillment / condition to Transaction * Small modifications to support new cryptoconditions * Improve documentation (#42) * Add doc strings for Fulfillment cls * Add doc strings for TransactionLink cls * Add doc strings for Condition cls * Add doc strings for Data cls * Add doc strings for Transaction cls * Add doc strings for Asset cls * Extract common implementation * Tx model: Add test for empty inputs * WIP: Implement sign tx * Add tests for: - Conditions; and - Fulfillments Mostly on the (de)serialization part. * Finalize serialization logic for tx class * Add Tests for tx serialization logic * Add fulfillment validation * Add ThresholdCondition support * WIP transfer * Clean up after move * Adjust setup to package structure * Fix tests * Add test coverage * Add test coverage * Transfer-tx fulfillments validation * Remove condition and fulfillment ids * Fix signing logic Specifically for transfer-tx with multiple inputs and outputs. * Fix test case * Compliance to legacy BDB models * Adjust fulfillment validation interface * Add serialization validation for txids * Use __eq__ to compare objects * Heavy refactor to comply with current implementation * Add Transaction.create * Add validation tests * Add Transaction.create for hashlock conditions * Add hashlock condition serialization * Transaction.transfer add single input and outputs * Small adjustments to transfer-tx interface * Create transfer-tx interface * Increase test coverage * Adjust fulfillment (de)serialization * Catch CC Error for Fulfillment * Allow custom thresholds * Rename Data to Metadata * Add basic Asset model * Add Asset into work-flow-functions * Add Asset amount to condition * initial integration of asset * Make tests comply to 79 chars per line * Fixed tests * fix pep8 issues * Correct raised error * Add test for asset initialization * Remove resolved TODOs * prevent adding None as fulfillment / condition to Transaction * Small modifications to support new cryptoconditions * Extract common tests * Copy conftest from bigchaindb-common - by @timdaub * Replace bigchaindb_common pkg by bigchaindb.common
207 lines
6.6 KiB
Python
207 lines
6.6 KiB
Python
import builtins
|
|
|
|
from bigchaindb.common import exceptions
|
|
import pytest
|
|
import rethinkdb as r
|
|
|
|
import bigchaindb
|
|
from bigchaindb.db import utils
|
|
from .conftest import setup_database as _setup_database
|
|
|
|
|
|
# Since we are testing database initialization and database drop,
|
|
# we need to use the `setup_database` fixture on a function level
|
|
@pytest.fixture(scope='function', autouse=True)
|
|
def setup_database(request, node_config):
|
|
_setup_database(request, node_config)
|
|
|
|
|
|
def test_init_creates_db_tables_and_indexes():
|
|
conn = utils.get_conn()
|
|
dbname = bigchaindb.config['database']['name']
|
|
|
|
# The db is set up by fixtures so we need to remove it
|
|
r.db_drop(dbname).run(conn)
|
|
|
|
utils.init()
|
|
|
|
assert r.db_list().contains(dbname).run(conn) is True
|
|
|
|
assert r.db(dbname).table_list().contains('backlog', 'bigchain').run(conn) is True
|
|
|
|
assert r.db(dbname).table('bigchain').index_list().contains(
|
|
'block_timestamp').run(conn) is True
|
|
|
|
assert r.db(dbname).table('backlog').index_list().contains(
|
|
'transaction_timestamp',
|
|
'assignee__transaction_timestamp').run(conn) is True
|
|
|
|
|
|
def test_create_database():
|
|
conn = utils.get_conn()
|
|
dbname = utils.get_database_name()
|
|
|
|
# The db is set up by fixtures so we need to remove it
|
|
# and recreate it just with one table
|
|
r.db_drop(dbname).run(conn)
|
|
utils.create_database(conn, dbname)
|
|
assert r.db_list().contains(dbname).run(conn) is True
|
|
|
|
|
|
def test_create_bigchain_table():
|
|
conn = utils.get_conn()
|
|
dbname = utils.get_database_name()
|
|
|
|
# The db is set up by fixtures so we need to remove it
|
|
# and recreate it just with one table
|
|
r.db_drop(dbname).run(conn)
|
|
utils.create_database(conn, dbname)
|
|
utils.create_table(conn, dbname, 'bigchain')
|
|
|
|
assert r.db(dbname).table_list().contains('bigchain').run(conn) is True
|
|
assert r.db(dbname).table_list().contains('backlog').run(conn) is False
|
|
assert r.db(dbname).table_list().contains('votes').run(conn) is False
|
|
|
|
|
|
def test_create_bigchain_secondary_index():
|
|
conn = utils.get_conn()
|
|
dbname = utils.get_database_name()
|
|
|
|
# The db is set up by fixtures so we need to remove it
|
|
# and recreate it just with one table
|
|
r.db_drop(dbname).run(conn)
|
|
utils.create_database(conn, dbname)
|
|
utils.create_table(conn, dbname, 'bigchain')
|
|
utils.create_bigchain_secondary_index(conn, dbname)
|
|
|
|
assert r.db(dbname).table('bigchain').index_list().contains(
|
|
'block_timestamp').run(conn) is True
|
|
assert r.db(dbname).table('bigchain').index_list().contains(
|
|
'transaction_id').run(conn) is True
|
|
assert r.db(dbname).table('bigchain').index_list().contains(
|
|
'metadata_id').run(conn) is True
|
|
|
|
|
|
def test_create_backlog_table():
|
|
conn = utils.get_conn()
|
|
dbname = utils.get_database_name()
|
|
|
|
# The db is set up by fixtures so we need to remove it
|
|
# and recreate it just with one table
|
|
r.db_drop(dbname).run(conn)
|
|
utils.create_database(conn, dbname)
|
|
utils.create_table(conn, dbname, 'backlog')
|
|
|
|
assert r.db(dbname).table_list().contains('backlog').run(conn) is True
|
|
assert r.db(dbname).table_list().contains('bigchain').run(conn) is False
|
|
assert r.db(dbname).table_list().contains('votes').run(conn) is False
|
|
|
|
|
|
def test_create_backlog_secondary_index():
|
|
conn = utils.get_conn()
|
|
dbname = utils.get_database_name()
|
|
|
|
# The db is set up by fixtures so we need to remove it
|
|
# and recreate it just with one table
|
|
r.db_drop(dbname).run(conn)
|
|
utils.create_database(conn, dbname)
|
|
utils.create_table(conn, dbname, 'backlog')
|
|
utils.create_backlog_secondary_index(conn, dbname)
|
|
|
|
assert r.db(dbname).table('backlog').index_list().contains(
|
|
'transaction_timestamp').run(conn) is True
|
|
assert r.db(dbname).table('backlog').index_list().contains(
|
|
'assignee__transaction_timestamp').run(conn) is True
|
|
|
|
|
|
def test_create_votes_table():
|
|
conn = utils.get_conn()
|
|
dbname = utils.get_database_name()
|
|
|
|
# The db is set up by fixtures so we need to remove it
|
|
# and recreate it just with one table
|
|
r.db_drop(dbname).run(conn)
|
|
utils.create_database(conn, dbname)
|
|
utils.create_table(conn, dbname, 'votes')
|
|
|
|
assert r.db(dbname).table_list().contains('votes').run(conn) is True
|
|
assert r.db(dbname).table_list().contains('bigchain').run(conn) is False
|
|
assert r.db(dbname).table_list().contains('backlog').run(conn) is False
|
|
|
|
|
|
def test_create_votes_secondary_index():
|
|
conn = utils.get_conn()
|
|
dbname = utils.get_database_name()
|
|
|
|
# The db is set up by fixtures so we need to remove it
|
|
# and recreate it just with one table
|
|
r.db_drop(dbname).run(conn)
|
|
utils.create_database(conn, dbname)
|
|
utils.create_table(conn, dbname, 'votes')
|
|
utils.create_votes_secondary_index(conn, dbname)
|
|
|
|
assert r.db(dbname).table('votes').index_list().contains(
|
|
'block_and_voter').run(conn) is True
|
|
|
|
|
|
def test_init_fails_if_db_exists():
|
|
conn = utils.get_conn()
|
|
dbname = bigchaindb.config['database']['name']
|
|
|
|
# The db is set up by fixtures
|
|
assert r.db_list().contains(dbname).run(conn) is True
|
|
|
|
with pytest.raises(exceptions.DatabaseAlreadyExists):
|
|
utils.init()
|
|
|
|
|
|
def test_drop_interactively_drops_the_database_when_user_says_yes(monkeypatch):
|
|
conn = utils.get_conn()
|
|
dbname = bigchaindb.config['database']['name']
|
|
|
|
# The db is set up by fixtures
|
|
assert r.db_list().contains(dbname).run(conn) is True
|
|
|
|
monkeypatch.setattr(builtins, 'input', lambda x: 'y')
|
|
utils.drop()
|
|
|
|
assert r.db_list().contains(dbname).run(conn) is False
|
|
|
|
|
|
def test_drop_programmatically_drops_the_database_when_assume_yes_is_true(monkeypatch):
|
|
conn = utils.get_conn()
|
|
dbname = bigchaindb.config['database']['name']
|
|
|
|
# The db is set up by fixtures
|
|
assert r.db_list().contains(dbname).run(conn) is True
|
|
|
|
utils.drop(assume_yes=True)
|
|
|
|
assert r.db_list().contains(dbname).run(conn) is False
|
|
|
|
|
|
def test_drop_interactively_does_not_drop_the_database_when_user_says_no(monkeypatch):
|
|
conn = utils.get_conn()
|
|
dbname = bigchaindb.config['database']['name']
|
|
|
|
# The db is set up by fixtures
|
|
print(r.db_list().contains(dbname).run(conn))
|
|
assert r.db_list().contains(dbname).run(conn) is True
|
|
|
|
monkeypatch.setattr(builtins, 'input', lambda x: 'n')
|
|
utils.drop()
|
|
|
|
assert r.db_list().contains(dbname).run(conn) is True
|
|
|
|
def test_drop_non_existent_db_raises_an_error():
|
|
conn = utils.get_conn()
|
|
dbname = bigchaindb.config['database']['name']
|
|
|
|
# The db is set up by fixtures
|
|
assert r.db_list().contains(dbname).run(conn) is True
|
|
utils.drop(assume_yes=True)
|
|
|
|
with pytest.raises(exceptions.DatabaseDoesNotExist):
|
|
utils.drop(assume_yes=True)
|
|
|