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

* Adjust imports to bigchaindb_common * Adjust get_spent function signature * Adjust block serialization * Fix BigchainApi Test * Fix TestTransactionValidation tests * Fix TestBlockValidation tests * WIP: TestMultipleInputs * Adjust tests to tx-model interface changes - Fix old tests - Fix tests in TestMultipleInputs class * Remove fulfillment message tests * Fix TransactionMalleability tests * Remove Cryptoconditions tests * Remove create_transaction * Remove signing logic * Remove consensus plugin * Fix block_creation pipeline * Fix election pipeline * Replace some util functions with bdb_common ones - timestamp ==> gen_timestamp - serialize. * Implement Block model * Simplify function signatures for vote functions Change parameter interface for the following functions: - has_previous_vote - verify_vote_signature - block_election_status so that they take a block's id and voters instead of a fake block. * Integrate Block and Transaction model * Fix leftover tests and cleanup conftest * Add bigchaindb-common to install_requires * Delete transactions after block is written (#609) * delete transactions after block is written * cleanup transaction_exists * check for duplicate transactions * delete invalid tx from backlog * test duplicate transaction * Remove dead code * Test processes.py * Test invalid tx in on server * Fix tests for core.py * Fix models tests * Test commands main fn * Add final coverage to vote pipeline * Add more tests to voting pipeline * Remove consensus plugin docs and misc * Post rebase fixes * Fix rebase mess * Remove extra blank line * Improve docstring * Remove comment handled in bigchaindb/cryptoconditions#27; see https://github.com/bigchaindb/cryptoconditions/issues/27 * Fix block serialization in block creation * Add signed_ prefix to transfer_tx * Improve docs * Add library documentation page on pipelines * PR feedback for models.py * Impr. readability of get_last_voted_block * Use dict comprehension * Add docker-compose file to build and serve docs locally for development purposes * Change private_key for signing_key * Improve docstrings * Remove consensus docs * Document new consensus module * Create different transactions for the block * Cleanup variable names in block.py * Create different transactions for the block * Cleanup variable names in block.py
120 lines
4.0 KiB
Python
120 lines
4.0 KiB
Python
"""
|
|
Fixtures and setup / teardown functions
|
|
|
|
Tasks:
|
|
1. setup test database before starting the tests
|
|
2. delete test database after running the tests
|
|
"""
|
|
|
|
import pytest
|
|
import rethinkdb as r
|
|
|
|
from bigchaindb import Bigchain
|
|
from bigchaindb.db import get_conn
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def restore_config(request, node_config):
|
|
from bigchaindb import config_utils
|
|
config_utils.set_config(node_config)
|
|
|
|
|
|
@pytest.fixture(scope='module', autouse=True)
|
|
def setup_database(request, node_config):
|
|
print('Initializing test db')
|
|
db_name = node_config['database']['name']
|
|
get_conn().repl()
|
|
try:
|
|
r.db_create(db_name).run()
|
|
except r.ReqlOpFailedError as e:
|
|
if e.message == 'Database `{}` already exists.'.format(db_name):
|
|
r.db_drop(db_name).run()
|
|
r.db_create(db_name).run()
|
|
else:
|
|
raise
|
|
|
|
print('Finished initializing test db')
|
|
|
|
# setup tables
|
|
r.db(db_name).table_create('bigchain').run()
|
|
r.db(db_name).table_create('backlog').run()
|
|
r.db(db_name).table_create('votes').run()
|
|
|
|
# create the secondary indexes
|
|
# to order blocks by timestamp
|
|
r.db(db_name).table('bigchain').index_create('block_timestamp', r.row['block']['timestamp']).run()
|
|
# to order blocks by block number
|
|
r.db(db_name).table('bigchain').index_create('block_number', r.row['block']['block_number']).run()
|
|
# to order transactions by timestamp
|
|
r.db(db_name).table('backlog').index_create('transaction_timestamp', r.row['transaction']['timestamp']).run()
|
|
# to query by payload uuid
|
|
r.db(db_name).table('bigchain').index_create(
|
|
'payload_uuid',
|
|
r.row['block']['transactions']['transaction']['data']['uuid'],
|
|
multi=True,
|
|
).run()
|
|
# compound index to read transactions from the backlog per assignee
|
|
r.db(db_name).table('backlog')\
|
|
.index_create('assignee__transaction_timestamp', [r.row['assignee'], r.row['transaction']['timestamp']])\
|
|
.run()
|
|
# compound index to order votes by block id and node
|
|
r.db(db_name).table('votes').index_create('block_and_voter',
|
|
[r.row['vote']['voting_for_block'], r.row['node_pubkey']]).run()
|
|
# order transactions by id
|
|
r.db(db_name).table('bigchain').index_create('transaction_id', r.row['block']['transactions']['id'],
|
|
multi=True).run()
|
|
|
|
r.db(db_name).table('bigchain').index_wait('transaction_id').run()
|
|
|
|
def fin():
|
|
print('Deleting `{}` database'.format(db_name))
|
|
get_conn().repl()
|
|
try:
|
|
r.db_drop(db_name).run()
|
|
except r.ReqlOpFailedError as e:
|
|
if e.message != 'Database `{}` does not exist.'.format(db_name):
|
|
raise
|
|
|
|
print('Finished deleting `{}`'.format(db_name))
|
|
|
|
request.addfinalizer(fin)
|
|
|
|
|
|
@pytest.fixture(scope='function', autouse=True)
|
|
def cleanup_tables(request, node_config):
|
|
db_name = node_config['database']['name']
|
|
|
|
def fin():
|
|
get_conn().repl()
|
|
try:
|
|
r.db(db_name).table('bigchain').delete().run()
|
|
r.db(db_name).table('backlog').delete().run()
|
|
r.db(db_name).table('votes').delete().run()
|
|
except r.ReqlOpFailedError as e:
|
|
if e.message != 'Database `{}` does not exist.'.format(db_name):
|
|
raise
|
|
|
|
request.addfinalizer(fin)
|
|
|
|
|
|
@pytest.fixture
|
|
def inputs(user_vk):
|
|
from bigchaindb.models import Transaction
|
|
from bigchaindb_common.exceptions import GenesisBlockAlreadyExistsError
|
|
# 1. create the genesis block
|
|
b = Bigchain()
|
|
try:
|
|
b.create_genesis_block()
|
|
except GenesisBlockAlreadyExistsError:
|
|
pass
|
|
|
|
# 2. create block with transactions for `USER` to spend
|
|
for block in range(4):
|
|
transactions = [
|
|
Transaction.create(
|
|
[b.me], [user_vk], payload={'i': i}).sign([b.me_private])
|
|
for i in range(10)
|
|
]
|
|
block = b.create_block(transactions)
|
|
b.write_block(block, durability='hard')
|