mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Merge remote-tracking branch 'origin/master' into feat/980/initialise-replica-set-mongo
This commit is contained in:
commit
1dd6c748b9
@ -17,7 +17,7 @@ config = {
|
|||||||
'database': {
|
'database': {
|
||||||
'backend': os.environ.get('BIGCHAINDB_DATABASE_BACKEND', 'rethinkdb'),
|
'backend': os.environ.get('BIGCHAINDB_DATABASE_BACKEND', 'rethinkdb'),
|
||||||
'host': os.environ.get('BIGCHAINDB_DATABASE_HOST', 'localhost'),
|
'host': os.environ.get('BIGCHAINDB_DATABASE_HOST', 'localhost'),
|
||||||
'port': 28015,
|
'port': int(os.environ.get('BIGCHAINDB_DATABASE_PORT', 28015)),
|
||||||
'name': 'bigchain',
|
'name': 'bigchain',
|
||||||
},
|
},
|
||||||
'keypair': {
|
'keypair': {
|
||||||
|
@ -3,6 +3,7 @@ import random
|
|||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_asset_transfer(b, user_pk, user_sk):
|
def test_asset_transfer(b, user_pk, user_sk):
|
||||||
from bigchaindb.common.transaction import AssetLink
|
from bigchaindb.common.transaction import AssetLink
|
||||||
@ -31,6 +32,7 @@ def test_validate_bad_asset_creation(b, user_pk):
|
|||||||
b.validate_transaction(tx_signed)
|
b.validate_transaction(tx_signed)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_validate_transfer_asset_id_mismatch(b, user_pk, user_sk):
|
def test_validate_transfer_asset_id_mismatch(b, user_pk, user_sk):
|
||||||
from bigchaindb.common.exceptions import AssetIdMismatch
|
from bigchaindb.common.exceptions import AssetIdMismatch
|
||||||
@ -56,6 +58,7 @@ def test_get_asset_id_create_transaction(b, user_pk):
|
|||||||
assert asset_id == tx_create.id
|
assert asset_id == tx_create.id
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_get_asset_id_transfer_transaction(b, user_pk, user_sk):
|
def test_get_asset_id_transfer_transaction(b, user_pk, user_sk):
|
||||||
from bigchaindb.common.transaction import AssetLink
|
from bigchaindb.common.transaction import AssetLink
|
||||||
@ -91,6 +94,7 @@ def test_asset_id_mismatch(b, user_pk):
|
|||||||
Asset.get_asset_id([tx1, tx2])
|
Asset.get_asset_id([tx1, tx2])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_get_transactions_by_asset_id(b, user_pk, user_sk):
|
def test_get_transactions_by_asset_id(b, user_pk, user_sk):
|
||||||
from bigchaindb.common.transaction import AssetLink
|
from bigchaindb.common.transaction import AssetLink
|
||||||
@ -126,6 +130,7 @@ def test_get_transactions_by_asset_id(b, user_pk, user_sk):
|
|||||||
assert asset_id == txs[1].asset.id
|
assert asset_id == txs[1].asset.id
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_get_transactions_by_asset_id_with_invalid_block(b, user_pk, user_sk):
|
def test_get_transactions_by_asset_id_with_invalid_block(b, user_pk, user_sk):
|
||||||
from bigchaindb.common.transaction import AssetLink
|
from bigchaindb.common.transaction import AssetLink
|
||||||
@ -156,6 +161,7 @@ def test_get_transactions_by_asset_id_with_invalid_block(b, user_pk, user_sk):
|
|||||||
assert len(txs) == 1
|
assert len(txs) == 1
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_get_asset_by_id(b, user_pk, user_sk):
|
def test_get_asset_by_id(b, user_pk, user_sk):
|
||||||
from bigchaindb.common.transaction import AssetLink
|
from bigchaindb.common.transaction import AssetLink
|
||||||
|
@ -126,6 +126,7 @@ def test_single_in_multiple_own_single_out_single_own_create(b, user_pk,
|
|||||||
# else there will be no genesis block and b.get_last_voted_block will
|
# else there will be no genesis block and b.get_last_voted_block will
|
||||||
# fail.
|
# fail.
|
||||||
# Is there a better way of doing this?
|
# Is there a better way of doing this?
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_single_in_single_own_single_out_single_own_transfer(b, user_pk,
|
def test_single_in_single_own_single_out_single_own_transfer(b, user_pk,
|
||||||
user_sk):
|
user_sk):
|
||||||
@ -160,6 +161,7 @@ def test_single_in_single_own_single_out_single_own_transfer(b, user_pk,
|
|||||||
# Single owners_before
|
# Single owners_before
|
||||||
# Multiple output
|
# Multiple output
|
||||||
# Single owners_after
|
# Single owners_after
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_single_in_single_own_multiple_out_single_own_transfer(b, user_pk,
|
def test_single_in_single_own_multiple_out_single_own_transfer(b, user_pk,
|
||||||
user_sk):
|
user_sk):
|
||||||
@ -196,6 +198,7 @@ def test_single_in_single_own_multiple_out_single_own_transfer(b, user_pk,
|
|||||||
# Single owners_before
|
# Single owners_before
|
||||||
# Single output
|
# Single output
|
||||||
# Multiple owners_after
|
# Multiple owners_after
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_single_in_single_own_single_out_multiple_own_transfer(b, user_pk,
|
def test_single_in_single_own_single_out_multiple_own_transfer(b, user_pk,
|
||||||
user_sk):
|
user_sk):
|
||||||
@ -237,6 +240,7 @@ def test_single_in_single_own_single_out_multiple_own_transfer(b, user_pk,
|
|||||||
# Multiple outputs
|
# Multiple outputs
|
||||||
# Mix: one output with a single owners_after, one output with multiple
|
# Mix: one output with a single owners_after, one output with multiple
|
||||||
# owners_after
|
# owners_after
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_single_in_single_own_multiple_out_mix_own_transfer(b, user_pk,
|
def test_single_in_single_own_multiple_out_mix_own_transfer(b, user_pk,
|
||||||
user_sk):
|
user_sk):
|
||||||
@ -278,6 +282,7 @@ def test_single_in_single_own_multiple_out_mix_own_transfer(b, user_pk,
|
|||||||
# Multiple owners_before
|
# Multiple owners_before
|
||||||
# Single output
|
# Single output
|
||||||
# Single owners_after
|
# Single owners_after
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_single_in_multiple_own_single_out_single_own_transfer(b, user_pk,
|
def test_single_in_multiple_own_single_out_single_own_transfer(b, user_pk,
|
||||||
user_sk):
|
user_sk):
|
||||||
@ -317,6 +322,7 @@ def test_single_in_multiple_own_single_out_single_own_transfer(b, user_pk,
|
|||||||
# Single owners_before per input
|
# Single owners_before per input
|
||||||
# Single output
|
# Single output
|
||||||
# Single owners_after
|
# Single owners_after
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_multiple_in_single_own_single_out_single_own_transfer(b, user_pk,
|
def test_multiple_in_single_own_single_out_single_own_transfer(b, user_pk,
|
||||||
user_sk):
|
user_sk):
|
||||||
@ -352,6 +358,7 @@ def test_multiple_in_single_own_single_out_single_own_transfer(b, user_pk,
|
|||||||
# Multiple owners_before per input
|
# Multiple owners_before per input
|
||||||
# Single output
|
# Single output
|
||||||
# Single owners_after
|
# Single owners_after
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_multiple_in_multiple_own_single_out_single_own_transfer(b, user_pk,
|
def test_multiple_in_multiple_own_single_out_single_own_transfer(b, user_pk,
|
||||||
user_sk):
|
user_sk):
|
||||||
@ -397,6 +404,7 @@ def test_multiple_in_multiple_own_single_out_single_own_transfer(b, user_pk,
|
|||||||
# owners_before
|
# owners_before
|
||||||
# Single output
|
# Single output
|
||||||
# Single owners_after
|
# Single owners_after
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_muiltiple_in_mix_own_multiple_out_single_own_transfer(b, user_pk,
|
def test_muiltiple_in_mix_own_multiple_out_single_own_transfer(b, user_pk,
|
||||||
user_sk):
|
user_sk):
|
||||||
@ -442,6 +450,7 @@ def test_muiltiple_in_mix_own_multiple_out_single_own_transfer(b, user_pk,
|
|||||||
# Multiple outputs
|
# Multiple outputs
|
||||||
# Mix: one output with a single owners_after, one output with multiple
|
# Mix: one output with a single owners_after, one output with multiple
|
||||||
# owners_after
|
# owners_after
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_muiltiple_in_mix_own_multiple_out_mix_own_transfer(b, user_pk,
|
def test_muiltiple_in_mix_own_multiple_out_mix_own_transfer(b, user_pk,
|
||||||
user_sk):
|
user_sk):
|
||||||
@ -493,6 +502,7 @@ def test_muiltiple_in_mix_own_multiple_out_mix_own_transfer(b, user_pk,
|
|||||||
# Single owners_before
|
# Single owners_before
|
||||||
# Single output
|
# Single output
|
||||||
# Single owners_after
|
# Single owners_after
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_multiple_in_different_transactions(b, user_pk, user_sk):
|
def test_multiple_in_different_transactions(b, user_pk, user_sk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
@ -554,6 +564,7 @@ def test_multiple_in_different_transactions(b, user_pk, user_sk):
|
|||||||
# In a TRANSFER transaction of a divisible asset the amount being spent in the
|
# In a TRANSFER transaction of a divisible asset the amount being spent in the
|
||||||
# inputs needs to match the amount being sent in the outputs.
|
# inputs needs to match the amount being sent in the outputs.
|
||||||
# In other words `amount_in_inputs - amount_in_outputs == 0`
|
# In other words `amount_in_inputs - amount_in_outputs == 0`
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_amount_error_transfer(b, user_pk, user_sk):
|
def test_amount_error_transfer(b, user_pk, user_sk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
@ -590,6 +601,7 @@ def test_amount_error_transfer(b, user_pk, user_sk):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason='Figure out how to handle this case')
|
@pytest.mark.skip(reason='Figure out how to handle this case')
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_threshold_same_public_key(b, user_pk, user_sk):
|
def test_threshold_same_public_key(b, user_pk, user_sk):
|
||||||
# If we try to fulfill a threshold condition where each subcondition has
|
# If we try to fulfill a threshold condition where each subcondition has
|
||||||
@ -623,6 +635,7 @@ def test_threshold_same_public_key(b, user_pk, user_sk):
|
|||||||
assert tx_transfer_signed.validate(b) == tx_transfer_signed
|
assert tx_transfer_signed.validate(b) == tx_transfer_signed
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_sum_amount(b, user_pk, user_sk):
|
def test_sum_amount(b, user_pk, user_sk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
@ -655,6 +668,7 @@ def test_sum_amount(b, user_pk, user_sk):
|
|||||||
assert tx_transfer_signed.conditions[0].amount == 3
|
assert tx_transfer_signed.conditions[0].amount == 3
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_divide(b, user_pk, user_sk):
|
def test_divide(b, user_pk, user_sk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
@ -687,6 +701,7 @@ def test_divide(b, user_pk, user_sk):
|
|||||||
|
|
||||||
|
|
||||||
# Check that negative inputs are caught when creating a TRANSFER transaction
|
# Check that negative inputs are caught when creating a TRANSFER transaction
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_non_positive_amounts_on_transfer(b, user_pk):
|
def test_non_positive_amounts_on_transfer(b, user_pk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
@ -713,6 +728,7 @@ def test_non_positive_amounts_on_transfer(b, user_pk):
|
|||||||
|
|
||||||
|
|
||||||
# Check that negative inputs are caught when validating a TRANSFER transaction
|
# Check that negative inputs are caught when validating a TRANSFER transaction
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_non_positive_amounts_on_transfer_validate(b, user_pk, user_sk):
|
def test_non_positive_amounts_on_transfer_validate(b, user_pk, user_sk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
@ -745,6 +761,7 @@ def test_non_positive_amounts_on_transfer_validate(b, user_pk, user_sk):
|
|||||||
|
|
||||||
|
|
||||||
# Check that negative inputs are caught when creating a CREATE transaction
|
# Check that negative inputs are caught when creating a CREATE transaction
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_non_positive_amounts_on_create(b, user_pk):
|
def test_non_positive_amounts_on_create(b, user_pk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
@ -759,6 +776,7 @@ def test_non_positive_amounts_on_create(b, user_pk):
|
|||||||
|
|
||||||
|
|
||||||
# Check that negative inputs are caught when validating a CREATE transaction
|
# Check that negative inputs are caught when validating a CREATE transaction
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_non_positive_amounts_on_create_validate(b, user_pk):
|
def test_non_positive_amounts_on_create_validate(b, user_pk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.bdb
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_init_creates_db_tables_and_indexes():
|
def test_init_creates_db_tables_and_indexes():
|
||||||
import bigchaindb
|
import bigchaindb
|
||||||
from bigchaindb import backend
|
from bigchaindb import backend
|
||||||
@ -30,7 +31,6 @@ def test_init_creates_db_tables_and_indexes():
|
|||||||
assert sorted(indexes) == ['_id_', 'block_and_voter']
|
assert sorted(indexes) == ['_id_', 'block_and_voter']
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_init_database_fails_if_db_exists():
|
def test_init_database_fails_if_db_exists():
|
||||||
import bigchaindb
|
import bigchaindb
|
||||||
from bigchaindb import backend
|
from bigchaindb import backend
|
||||||
@ -47,7 +47,6 @@ def test_init_database_fails_if_db_exists():
|
|||||||
init_database()
|
init_database()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_create_tables():
|
def test_create_tables():
|
||||||
import bigchaindb
|
import bigchaindb
|
||||||
from bigchaindb import backend
|
from bigchaindb import backend
|
||||||
@ -65,7 +64,6 @@ def test_create_tables():
|
|||||||
assert sorted(collection_names) == ['backlog', 'bigchain', 'votes']
|
assert sorted(collection_names) == ['backlog', 'bigchain', 'votes']
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_create_secondary_indexes():
|
def test_create_secondary_indexes():
|
||||||
import bigchaindb
|
import bigchaindb
|
||||||
from bigchaindb import backend
|
from bigchaindb import backend
|
||||||
@ -94,7 +92,6 @@ def test_create_secondary_indexes():
|
|||||||
assert sorted(indexes) == ['_id_', 'block_and_voter']
|
assert sorted(indexes) == ['_id_', 'block_and_voter']
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_drop():
|
def test_drop():
|
||||||
import bigchaindb
|
import bigchaindb
|
||||||
from bigchaindb import backend
|
from bigchaindb import backend
|
||||||
|
@ -6,7 +6,7 @@ from bigchaindb import backend
|
|||||||
from bigchaindb.backend.rethinkdb import schema
|
from bigchaindb.backend.rethinkdb import schema
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_init_creates_db_tables_and_indexes():
|
def test_init_creates_db_tables_and_indexes():
|
||||||
from bigchaindb.backend.schema import init_database
|
from bigchaindb.backend.schema import init_database
|
||||||
conn = backend.connect()
|
conn = backend.connect()
|
||||||
@ -28,7 +28,7 @@ def test_init_creates_db_tables_and_indexes():
|
|||||||
'assignee__transaction_timestamp')) is True
|
'assignee__transaction_timestamp')) is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_init_database_fails_if_db_exists():
|
def test_init_database_fails_if_db_exists():
|
||||||
from bigchaindb.backend.schema import init_database
|
from bigchaindb.backend.schema import init_database
|
||||||
from bigchaindb.common import exceptions
|
from bigchaindb.common import exceptions
|
||||||
@ -43,14 +43,13 @@ def test_init_database_fails_if_db_exists():
|
|||||||
init_database()
|
init_database()
|
||||||
|
|
||||||
|
|
||||||
def test_create_database():
|
def test_create_database(not_yet_created_db):
|
||||||
conn = backend.connect()
|
conn = backend.connect()
|
||||||
dbname = bigchaindb.config['database']['name']
|
schema.create_database(conn, not_yet_created_db)
|
||||||
schema.create_database(conn, dbname)
|
assert conn.run(r.db_list().contains(not_yet_created_db)) is True
|
||||||
assert conn.run(r.db_list().contains(dbname)) is True
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_create_tables():
|
def test_create_tables():
|
||||||
conn = backend.connect()
|
conn = backend.connect()
|
||||||
dbname = bigchaindb.config['database']['name']
|
dbname = bigchaindb.config['database']['name']
|
||||||
@ -67,7 +66,7 @@ def test_create_tables():
|
|||||||
assert len(conn.run(r.db(dbname).table_list())) == 3
|
assert len(conn.run(r.db(dbname).table_list())) == 3
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_create_secondary_indexes():
|
def test_create_secondary_indexes():
|
||||||
conn = backend.connect()
|
conn = backend.connect()
|
||||||
dbname = bigchaindb.config['database']['name']
|
dbname = bigchaindb.config['database']['name']
|
||||||
@ -96,29 +95,17 @@ def test_create_secondary_indexes():
|
|||||||
'block_and_voter')) is True
|
'block_and_voter')) is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
def test_drop(dummy_db):
|
||||||
def test_drop():
|
|
||||||
conn = backend.connect()
|
conn = backend.connect()
|
||||||
dbname = bigchaindb.config['database']['name']
|
assert conn.run(r.db_list().contains(dummy_db)) is True
|
||||||
|
schema.drop_database(conn, dummy_db)
|
||||||
# The db is set up by fixtures
|
assert conn.run(r.db_list().contains(dummy_db)) is False
|
||||||
assert conn.run(r.db_list().contains(dbname)) is True
|
|
||||||
|
|
||||||
schema.drop_database(conn, dbname)
|
|
||||||
assert conn.run(r.db_list().contains(dbname)) is False
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
def test_drop_non_existent_db_raises_an_error(dummy_db):
|
||||||
def test_drop_non_existent_db_raises_an_error():
|
|
||||||
from bigchaindb.common import exceptions
|
from bigchaindb.common import exceptions
|
||||||
|
|
||||||
conn = backend.connect()
|
conn = backend.connect()
|
||||||
dbname = bigchaindb.config['database']['name']
|
assert conn.run(r.db_list().contains(dummy_db)) is True
|
||||||
|
schema.drop_database(conn, dummy_db)
|
||||||
# The db is set up by fixtures
|
|
||||||
assert conn.run(r.db_list().contains(dbname)) is True
|
|
||||||
|
|
||||||
schema.drop_database(conn, dbname)
|
|
||||||
|
|
||||||
with pytest.raises(exceptions.DatabaseDoesNotExist):
|
with pytest.raises(exceptions.DatabaseDoesNotExist):
|
||||||
schema.drop_database(conn, dbname)
|
schema.drop_database(conn, dummy_db)
|
||||||
|
@ -101,7 +101,7 @@ def test_bigchain_run_start_assume_yes_create_default_config(monkeypatch, mock_p
|
|||||||
# TODO Please beware, that if debugging, the "-s" switch for pytest will
|
# TODO Please beware, that if debugging, the "-s" switch for pytest will
|
||||||
# interfere with capsys.
|
# interfere with capsys.
|
||||||
# See related issue: https://github.com/pytest-dev/pytest/issues/128
|
# See related issue: https://github.com/pytest-dev/pytest/issues/128
|
||||||
@pytest.mark.usefixtures('restore_config')
|
@pytest.mark.usefixtures('ignore_local_config_file')
|
||||||
def test_bigchain_show_config(capsys):
|
def test_bigchain_show_config(capsys):
|
||||||
from bigchaindb import config
|
from bigchaindb import config
|
||||||
from bigchaindb.commands.bigchain import run_show_config
|
from bigchaindb.commands.bigchain import run_show_config
|
||||||
@ -229,7 +229,7 @@ def test_run_configure_when_config_does_exist(monkeypatch,
|
|||||||
|
|
||||||
@patch('bigchaindb.common.crypto.generate_key_pair',
|
@patch('bigchaindb.common.crypto.generate_key_pair',
|
||||||
return_value=('private_key', 'public_key'))
|
return_value=('private_key', 'public_key'))
|
||||||
@pytest.mark.usefixtures('restore_config')
|
@pytest.mark.usefixtures('ignore_local_config_file')
|
||||||
def test_allow_temp_keypair_generates_one_on_the_fly(mock_gen_keypair,
|
def test_allow_temp_keypair_generates_one_on_the_fly(mock_gen_keypair,
|
||||||
mock_processes_start,
|
mock_processes_start,
|
||||||
mock_db_init_with_existing_db):
|
mock_db_init_with_existing_db):
|
||||||
@ -247,7 +247,7 @@ def test_allow_temp_keypair_generates_one_on_the_fly(mock_gen_keypair,
|
|||||||
|
|
||||||
@patch('bigchaindb.common.crypto.generate_key_pair',
|
@patch('bigchaindb.common.crypto.generate_key_pair',
|
||||||
return_value=('private_key', 'public_key'))
|
return_value=('private_key', 'public_key'))
|
||||||
@pytest.mark.usefixtures('restore_config')
|
@pytest.mark.usefixtures('ignore_local_config_file')
|
||||||
def test_allow_temp_keypair_doesnt_override_if_keypair_found(mock_gen_keypair,
|
def test_allow_temp_keypair_doesnt_override_if_keypair_found(mock_gen_keypair,
|
||||||
mock_processes_start,
|
mock_processes_start,
|
||||||
mock_db_init_with_existing_db):
|
mock_db_init_with_existing_db):
|
||||||
|
@ -14,19 +14,9 @@ import pytest
|
|||||||
|
|
||||||
from bigchaindb.common import crypto
|
from bigchaindb.common import crypto
|
||||||
|
|
||||||
|
TEST_DB_NAME = 'bigchain_test'
|
||||||
|
|
||||||
USER2_SK, USER2_PK = crypto.generate_key_pair()
|
USER2_SK, USER2_PK = crypto.generate_key_pair()
|
||||||
DB_NAME = 'bigchain_test_{}'.format(os.getpid())
|
|
||||||
|
|
||||||
CONFIG = {
|
|
||||||
'database': {
|
|
||||||
'name': DB_NAME,
|
|
||||||
},
|
|
||||||
'keypair': {
|
|
||||||
'private': '31Lb1ZGKTyHnmVK3LUMrAUrPNfd4sE2YyBt3UA4A25aA',
|
|
||||||
'public': '4XYfCbabAWVUCbjTmRTFEu2sc3dFEdkse4r6X498B1s8',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Test user. inputs will be created for this user. Cryptography Keys
|
# Test user. inputs will be created for this user. Cryptography Keys
|
||||||
USER_PRIVATE_KEY = '8eJ8q9ZQpReWyQT5aFCiwtZ5wDZC4eDnCen88p3tQ6ie'
|
USER_PRIVATE_KEY = '8eJ8q9ZQpReWyQT5aFCiwtZ5wDZC4eDnCen88p3tQ6ie'
|
||||||
@ -56,6 +46,118 @@ def pytest_ignore_collect(path, config):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_configure(config):
|
||||||
|
config.addinivalue_line(
|
||||||
|
'markers',
|
||||||
|
'bdb(): Mark the test as needing BigchainDB, i.e. a database with '
|
||||||
|
'the three tables: "backlog", "bigchain", "votes". BigchainDB will '
|
||||||
|
'be configured such that the database and tables are available for an '
|
||||||
|
'entire test session. For distributed tests, the database name will '
|
||||||
|
'be suffixed with the process identifier, e.g.: "bigchain_test_gw0", '
|
||||||
|
'to ensure that each process session has its own separate database.'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def _bdb_marker(request):
|
||||||
|
if request.keywords.get('bdb', None):
|
||||||
|
request.getfixturevalue('_bdb')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def _restore_config(_configure_bigchaindb):
|
||||||
|
from bigchaindb import config, config_utils
|
||||||
|
config_before_test = copy.deepcopy(config)
|
||||||
|
yield
|
||||||
|
config_utils.set_config(config_before_test)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def _restore_dbs(request):
|
||||||
|
from bigchaindb.backend import connect, schema
|
||||||
|
from bigchaindb.common.exceptions import DatabaseDoesNotExist
|
||||||
|
from .utils import list_dbs
|
||||||
|
conn = connect()
|
||||||
|
dbs_before_test = list_dbs(conn)
|
||||||
|
yield
|
||||||
|
dbs_after_test = list_dbs(conn)
|
||||||
|
dbs_to_delete = (
|
||||||
|
db for db in set(dbs_after_test) - set(dbs_before_test)
|
||||||
|
if TEST_DB_NAME not in db
|
||||||
|
)
|
||||||
|
print(dbs_to_delete)
|
||||||
|
for db in dbs_to_delete:
|
||||||
|
try:
|
||||||
|
schema.drop_database(conn, db)
|
||||||
|
except DatabaseDoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='session')
|
||||||
|
def _configure_bigchaindb(request):
|
||||||
|
from bigchaindb import config_utils
|
||||||
|
test_db_name = TEST_DB_NAME
|
||||||
|
# Put a suffix like _gw0, _gw1 etc on xdist processes
|
||||||
|
xdist_suffix = getattr(request.config, 'slaveinput', {}).get('slaveid')
|
||||||
|
if xdist_suffix:
|
||||||
|
test_db_name = '{}_{}'.format(TEST_DB_NAME, xdist_suffix)
|
||||||
|
config = {
|
||||||
|
'database': {
|
||||||
|
'name': test_db_name,
|
||||||
|
'backend': request.config.getoption('--database-backend'),
|
||||||
|
},
|
||||||
|
'keypair': {
|
||||||
|
'private': '31Lb1ZGKTyHnmVK3LUMrAUrPNfd4sE2YyBt3UA4A25aA',
|
||||||
|
'public': '4XYfCbabAWVUCbjTmRTFEu2sc3dFEdkse4r6X498B1s8',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# FIXME
|
||||||
|
if config['database']['backend'] == 'mongodb':
|
||||||
|
# not a great way to do this
|
||||||
|
config['database']['port'] = 27017
|
||||||
|
config_utils.set_config(config)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='session')
|
||||||
|
def _setup_database(_configure_bigchaindb):
|
||||||
|
from bigchaindb import config
|
||||||
|
from bigchaindb.backend import connect, schema
|
||||||
|
from bigchaindb.common.exceptions import DatabaseDoesNotExist
|
||||||
|
print('Initializing test db')
|
||||||
|
dbname = config['database']['name']
|
||||||
|
conn = connect()
|
||||||
|
|
||||||
|
try:
|
||||||
|
schema.drop_database(conn, dbname)
|
||||||
|
except DatabaseDoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
|
schema.init_database(conn)
|
||||||
|
print('Finishing init database')
|
||||||
|
|
||||||
|
yield
|
||||||
|
|
||||||
|
print('Deleting `{}` database'.format(dbname))
|
||||||
|
conn = connect()
|
||||||
|
try:
|
||||||
|
schema.drop_database(conn, dbname)
|
||||||
|
except DatabaseDoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
|
print('Finished deleting `{}`'.format(dbname))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def _bdb(_setup_database, _configure_bigchaindb):
|
||||||
|
yield
|
||||||
|
from bigchaindb import config
|
||||||
|
from bigchaindb.backend import connect
|
||||||
|
from .utils import flush_db
|
||||||
|
dbname = config['database']['name']
|
||||||
|
conn = connect()
|
||||||
|
flush_db(conn, dbname)
|
||||||
|
|
||||||
|
|
||||||
# We need this function to avoid loading an existing
|
# We need this function to avoid loading an existing
|
||||||
# conf file located in the home of the user running
|
# conf file located in the home of the user running
|
||||||
# the tests. If it's too aggressive we can change it
|
# the tests. If it's too aggressive we can change it
|
||||||
@ -69,22 +171,6 @@ def ignore_local_config_file(monkeypatch):
|
|||||||
mock_file_config)
|
mock_file_config)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def restore_config(ignore_local_config_file, node_config):
|
|
||||||
from bigchaindb import config_utils
|
|
||||||
config_utils.set_config(node_config)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='module')
|
|
||||||
def node_config(request):
|
|
||||||
config = copy.deepcopy(CONFIG)
|
|
||||||
config['database']['backend'] = request.config.getoption('--database-backend')
|
|
||||||
if config['database']['backend'] == 'mongodb':
|
|
||||||
# not a great way to do this
|
|
||||||
config['database']['port'] = 27017
|
|
||||||
return config
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def user_sk():
|
def user_sk():
|
||||||
return USER_PRIVATE_KEY
|
return USER_PRIVATE_KEY
|
||||||
@ -106,7 +192,7 @@ def user2_pk():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def b(restore_config):
|
def b():
|
||||||
from bigchaindb import Bigchain
|
from bigchaindb import Bigchain
|
||||||
return Bigchain()
|
return Bigchain()
|
||||||
|
|
||||||
@ -149,35 +235,7 @@ def structurally_valid_vote():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def setup_database(restore_config, node_config):
|
def inputs(user_pk):
|
||||||
from bigchaindb.backend import connect, schema
|
|
||||||
from bigchaindb.common.exceptions import DatabaseDoesNotExist
|
|
||||||
print('Initializing test db')
|
|
||||||
db_name = node_config['database']['name']
|
|
||||||
conn = connect()
|
|
||||||
|
|
||||||
try:
|
|
||||||
schema.drop_database(conn, db_name)
|
|
||||||
except DatabaseDoesNotExist:
|
|
||||||
pass
|
|
||||||
|
|
||||||
schema.init_database(conn)
|
|
||||||
print('Finishing init database')
|
|
||||||
|
|
||||||
yield
|
|
||||||
|
|
||||||
print('Deleting `{}` database'.format(db_name))
|
|
||||||
conn = connect()
|
|
||||||
try:
|
|
||||||
schema.drop_database(conn, db_name)
|
|
||||||
except DatabaseDoesNotExist:
|
|
||||||
pass
|
|
||||||
|
|
||||||
print('Finished deleting `{}`'.format(db_name))
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def inputs(user_pk, setup_database):
|
|
||||||
from bigchaindb import Bigchain
|
from bigchaindb import Bigchain
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
from bigchaindb.common.exceptions import GenesisBlockAlreadyExistsError
|
from bigchaindb.common.exceptions import GenesisBlockAlreadyExistsError
|
||||||
@ -207,7 +265,7 @@ def inputs(user_pk, setup_database):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def inputs_shared(user_pk, user2_pk, setup_database):
|
def inputs_shared(user_pk, user2_pk):
|
||||||
from bigchaindb import Bigchain
|
from bigchaindb import Bigchain
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
from bigchaindb.common.exceptions import GenesisBlockAlreadyExistsError
|
from bigchaindb.common.exceptions import GenesisBlockAlreadyExistsError
|
||||||
@ -234,3 +292,45 @@ def inputs_shared(user_pk, user2_pk, setup_database):
|
|||||||
vote = b.vote(block.id, prev_block_id, True)
|
vote = b.vote(block.id, prev_block_id, True)
|
||||||
prev_block_id = block.id
|
prev_block_id = block.id
|
||||||
b.write_vote(vote)
|
b.write_vote(vote)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def dummy_db(request):
|
||||||
|
from bigchaindb.backend import connect, schema
|
||||||
|
from bigchaindb.common.exceptions import (DatabaseDoesNotExist,
|
||||||
|
DatabaseAlreadyExists)
|
||||||
|
conn = connect()
|
||||||
|
dbname = request.fixturename
|
||||||
|
xdist_suffix = getattr(request.config, 'slaveinput', {}).get('slaveid')
|
||||||
|
if xdist_suffix:
|
||||||
|
dbname = '{}_{}'.format(dbname, xdist_suffix)
|
||||||
|
try:
|
||||||
|
schema.create_database(conn, dbname)
|
||||||
|
except DatabaseAlreadyExists:
|
||||||
|
schema.drop_database(conn, dbname)
|
||||||
|
schema.create_database(conn, dbname)
|
||||||
|
yield dbname
|
||||||
|
try:
|
||||||
|
schema.drop_database(conn, dbname)
|
||||||
|
except DatabaseDoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def not_yet_created_db(request):
|
||||||
|
from bigchaindb.backend import connect, schema
|
||||||
|
from bigchaindb.common.exceptions import DatabaseDoesNotExist
|
||||||
|
conn = connect()
|
||||||
|
dbname = request.fixturename
|
||||||
|
xdist_suffix = getattr(request.config, 'slaveinput', {}).get('slaveid')
|
||||||
|
if xdist_suffix:
|
||||||
|
dbname = '{}_{}'.format(dbname, xdist_suffix)
|
||||||
|
try:
|
||||||
|
schema.drop_database(conn, dbname)
|
||||||
|
except DatabaseDoesNotExist:
|
||||||
|
pass
|
||||||
|
yield dbname
|
||||||
|
try:
|
||||||
|
schema.drop_database(conn, dbname)
|
||||||
|
except DatabaseDoesNotExist:
|
||||||
|
pass
|
||||||
|
@ -3,6 +3,8 @@ from time import sleep
|
|||||||
import pytest
|
import pytest
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.bdb
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(reason='Some tests throw a ResourceWarning that might result in some weird '
|
@pytest.mark.skipif(reason='Some tests throw a ResourceWarning that might result in some weird '
|
||||||
'exceptions while running the tests. The problem seems to *not* '
|
'exceptions while running the tests. The problem seems to *not* '
|
||||||
@ -29,7 +31,6 @@ def dummy_block():
|
|||||||
return block
|
return block
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
class TestBigchainApi(object):
|
class TestBigchainApi(object):
|
||||||
def test_get_last_voted_block_cyclic_blockchain(self, b, monkeypatch):
|
def test_get_last_voted_block_cyclic_blockchain(self, b, monkeypatch):
|
||||||
from bigchaindb.common.crypto import PrivateKey
|
from bigchaindb.common.crypto import PrivateKey
|
||||||
@ -591,7 +592,7 @@ class TestTransactionValidation(object):
|
|||||||
|
|
||||||
assert excinfo.value.args[0] == 'Only `CREATE` transactions can have null inputs'
|
assert excinfo.value.args[0] == 'Only `CREATE` transactions can have null inputs'
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_non_create_input_not_found(self, b, user_pk, signed_transfer_tx):
|
def test_non_create_input_not_found(self, b, user_pk, signed_transfer_tx):
|
||||||
from bigchaindb.common.exceptions import TransactionDoesNotExist
|
from bigchaindb.common.exceptions import TransactionDoesNotExist
|
||||||
from bigchaindb.common.transaction import TransactionLink
|
from bigchaindb.common.transaction import TransactionLink
|
||||||
@ -745,7 +746,7 @@ class TestBlockValidation(object):
|
|||||||
|
|
||||||
assert excinfo.value.args[0] == 'owner_before `a` does not own the input `{}`'.format(valid_input)
|
assert excinfo.value.args[0] == 'owner_before `a` does not own the input `{}`'.format(valid_input)
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_invalid_signature(self, b):
|
def test_invalid_signature(self, b):
|
||||||
from bigchaindb.common.exceptions import InvalidSignature
|
from bigchaindb.common.exceptions import InvalidSignature
|
||||||
from bigchaindb.common import crypto
|
from bigchaindb.common import crypto
|
||||||
@ -760,7 +761,7 @@ class TestBlockValidation(object):
|
|||||||
with pytest.raises(InvalidSignature):
|
with pytest.raises(InvalidSignature):
|
||||||
b.validate_block(block)
|
b.validate_block(block)
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_invalid_node_pubkey(self, b):
|
def test_invalid_node_pubkey(self, b):
|
||||||
from bigchaindb.common.exceptions import OperationError
|
from bigchaindb.common.exceptions import OperationError
|
||||||
from bigchaindb.common import crypto
|
from bigchaindb.common import crypto
|
||||||
@ -894,7 +895,6 @@ class TestMultipleInputs(object):
|
|||||||
assert len(tx.fulfillments) == 1
|
assert len(tx.fulfillments) == 1
|
||||||
assert len(tx.conditions) == 1
|
assert len(tx.conditions) == 1
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_get_owned_ids_single_tx_single_output(self, b, user_sk, user_pk):
|
def test_get_owned_ids_single_tx_single_output(self, b, user_sk, user_pk):
|
||||||
from bigchaindb.common import crypto
|
from bigchaindb.common import crypto
|
||||||
from bigchaindb.common.transaction import AssetLink, TransactionLink
|
from bigchaindb.common.transaction import AssetLink, TransactionLink
|
||||||
@ -923,7 +923,6 @@ class TestMultipleInputs(object):
|
|||||||
assert owned_inputs_user1 == []
|
assert owned_inputs_user1 == []
|
||||||
assert owned_inputs_user2 == [TransactionLink(tx.id, 0)]
|
assert owned_inputs_user2 == [TransactionLink(tx.id, 0)]
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_get_owned_ids_single_tx_single_output_invalid_block(self, b,
|
def test_get_owned_ids_single_tx_single_output_invalid_block(self, b,
|
||||||
user_sk,
|
user_sk,
|
||||||
user_pk):
|
user_pk):
|
||||||
@ -967,7 +966,6 @@ class TestMultipleInputs(object):
|
|||||||
assert owned_inputs_user1 == [TransactionLink(tx.id, 0)]
|
assert owned_inputs_user1 == [TransactionLink(tx.id, 0)]
|
||||||
assert owned_inputs_user2 == []
|
assert owned_inputs_user2 == []
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_get_owned_ids_single_tx_multiple_outputs(self, b, user_sk,
|
def test_get_owned_ids_single_tx_multiple_outputs(self, b, user_sk,
|
||||||
user_pk):
|
user_pk):
|
||||||
from bigchaindb.common import crypto
|
from bigchaindb.common import crypto
|
||||||
@ -1009,7 +1007,6 @@ class TestMultipleInputs(object):
|
|||||||
assert owned_inputs_user2 == [TransactionLink(tx_transfer.id, 0),
|
assert owned_inputs_user2 == [TransactionLink(tx_transfer.id, 0),
|
||||||
TransactionLink(tx_transfer.id, 1)]
|
TransactionLink(tx_transfer.id, 1)]
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_get_owned_ids_multiple_owners(self, b, user_sk, user_pk):
|
def test_get_owned_ids_multiple_owners(self, b, user_sk, user_pk):
|
||||||
from bigchaindb.common import crypto
|
from bigchaindb.common import crypto
|
||||||
from bigchaindb.common.transaction import AssetLink, TransactionLink
|
from bigchaindb.common.transaction import AssetLink, TransactionLink
|
||||||
@ -1041,7 +1038,6 @@ class TestMultipleInputs(object):
|
|||||||
assert owned_inputs_user1 == owned_inputs_user2
|
assert owned_inputs_user1 == owned_inputs_user2
|
||||||
assert owned_inputs_user1 == []
|
assert owned_inputs_user1 == []
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_get_spent_single_tx_single_output(self, b, user_sk, user_pk):
|
def test_get_spent_single_tx_single_output(self, b, user_sk, user_pk):
|
||||||
from bigchaindb.common import crypto
|
from bigchaindb.common import crypto
|
||||||
from bigchaindb.common.transaction import AssetLink
|
from bigchaindb.common.transaction import AssetLink
|
||||||
@ -1072,7 +1068,6 @@ class TestMultipleInputs(object):
|
|||||||
spent_inputs_user1 = b.get_spent(input_txid, input_cid)
|
spent_inputs_user1 = b.get_spent(input_txid, input_cid)
|
||||||
assert spent_inputs_user1 == tx
|
assert spent_inputs_user1 == tx
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_get_spent_single_tx_single_output_invalid_block(self, b, user_sk, user_pk):
|
def test_get_spent_single_tx_single_output_invalid_block(self, b, user_sk, user_pk):
|
||||||
from bigchaindb.common import crypto
|
from bigchaindb.common import crypto
|
||||||
from bigchaindb.common.transaction import AssetLink
|
from bigchaindb.common.transaction import AssetLink
|
||||||
@ -1117,7 +1112,6 @@ class TestMultipleInputs(object):
|
|||||||
# Now there should be no spents (the block is invalid)
|
# Now there should be no spents (the block is invalid)
|
||||||
assert spent_inputs_user1 is None
|
assert spent_inputs_user1 is None
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_get_spent_single_tx_multiple_outputs(self, b, user_sk, user_pk):
|
def test_get_spent_single_tx_multiple_outputs(self, b, user_sk, user_pk):
|
||||||
from bigchaindb.common import crypto
|
from bigchaindb.common import crypto
|
||||||
from bigchaindb.common.transaction import Asset, AssetLink
|
from bigchaindb.common.transaction import Asset, AssetLink
|
||||||
@ -1160,7 +1154,6 @@ class TestMultipleInputs(object):
|
|||||||
# spendable by BigchainDB
|
# spendable by BigchainDB
|
||||||
assert b.get_spent(tx_create.to_inputs()[2].tx_input.txid, 2) is None
|
assert b.get_spent(tx_create.to_inputs()[2].tx_input.txid, 2) is None
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
|
||||||
def test_get_spent_multiple_owners(self, b, user_sk, user_pk):
|
def test_get_spent_multiple_owners(self, b, user_sk, user_pk):
|
||||||
from bigchaindb.common import crypto
|
from bigchaindb.common import crypto
|
||||||
from bigchaindb.common.transaction import AssetLink
|
from bigchaindb.common.transaction import AssetLink
|
||||||
|
@ -3,7 +3,7 @@ from bigchaindb.pipelines import block, election, vote, stale
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def processes(b, setup_database):
|
def processes(b):
|
||||||
b.create_genesis_block()
|
b.create_genesis_block()
|
||||||
block_maker = block.start()
|
block_maker = block.start()
|
||||||
voter = vote.start()
|
voter = vote.start()
|
||||||
|
@ -2,8 +2,9 @@ import time
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
pytestmark = [pytest.mark.bdb, pytest.mark.usefixtures('processes')]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('processes')
|
|
||||||
def test_fast_double_create(b, user_pk):
|
def test_fast_double_create(b, user_pk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
from bigchaindb.backend.query import count_blocks
|
from bigchaindb.backend.query import count_blocks
|
||||||
@ -25,7 +26,6 @@ def test_fast_double_create(b, user_pk):
|
|||||||
assert count_blocks(b.connection) == 2
|
assert count_blocks(b.connection) == 2
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('processes')
|
|
||||||
def test_double_create(b, user_pk):
|
def test_double_create(b, user_pk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
from bigchaindb.backend.query import count_blocks
|
from bigchaindb.backend.query import count_blocks
|
||||||
|
@ -27,7 +27,7 @@ def test_filter_by_assignee(b, signed_create_tx):
|
|||||||
assert block_maker.filter_tx(tx) is None
|
assert block_maker.filter_tx(tx) is None
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_validate_transaction(b, create_tx):
|
def test_validate_transaction(b, create_tx):
|
||||||
from bigchaindb.pipelines.block import BlockPipeline
|
from bigchaindb.pipelines.block import BlockPipeline
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ def test_create_block(b, user_pk):
|
|||||||
assert len(block_doc.transactions) == 100
|
assert len(block_doc.transactions) == 100
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_write_block(b, user_pk):
|
def test_write_block(b, user_pk):
|
||||||
from bigchaindb.models import Block, Transaction
|
from bigchaindb.models import Block, Transaction
|
||||||
from bigchaindb.pipelines.block import BlockPipeline
|
from bigchaindb.pipelines.block import BlockPipeline
|
||||||
@ -79,7 +79,7 @@ def test_write_block(b, user_pk):
|
|||||||
assert expected == block_doc
|
assert expected == block_doc
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_duplicate_transaction(b, user_pk):
|
def test_duplicate_transaction(b, user_pk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
from bigchaindb.pipelines import block
|
from bigchaindb.pipelines import block
|
||||||
@ -112,7 +112,7 @@ def test_duplicate_transaction(b, user_pk):
|
|||||||
assert status != b.TX_IN_BACKLOG
|
assert status != b.TX_IN_BACKLOG
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_delete_tx(b, user_pk):
|
def test_delete_tx(b, user_pk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
from bigchaindb.pipelines.block import BlockPipeline
|
from bigchaindb.pipelines.block import BlockPipeline
|
||||||
@ -142,7 +142,7 @@ def test_delete_tx(b, user_pk):
|
|||||||
|
|
||||||
|
|
||||||
@patch('bigchaindb.pipelines.block.create_pipeline')
|
@patch('bigchaindb.pipelines.block.create_pipeline')
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_start(create_pipeline):
|
def test_start(create_pipeline):
|
||||||
from bigchaindb.pipelines import block
|
from bigchaindb.pipelines import block
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ def test_start(create_pipeline):
|
|||||||
assert pipeline == create_pipeline.return_value
|
assert pipeline == create_pipeline.return_value
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_full_pipeline(b, user_pk):
|
def test_full_pipeline(b, user_pk):
|
||||||
from bigchaindb.models import Block, Transaction
|
from bigchaindb.models import Block, Transaction
|
||||||
from bigchaindb.pipelines.block import create_pipeline
|
from bigchaindb.pipelines.block import create_pipeline
|
||||||
|
@ -10,7 +10,7 @@ from bigchaindb import Bigchain
|
|||||||
from bigchaindb.pipelines import election
|
from bigchaindb.pipelines import election
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_check_for_quorum_invalid(b, user_pk):
|
def test_check_for_quorum_invalid(b, user_pk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ def test_check_for_quorum_invalid(b, user_pk):
|
|||||||
assert e.check_for_quorum(votes[-1]) == test_block
|
assert e.check_for_quorum(votes[-1]) == test_block
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_check_for_quorum_invalid_prev_node(b, user_pk):
|
def test_check_for_quorum_invalid_prev_node(b, user_pk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
e = election.Election()
|
e = election.Election()
|
||||||
@ -79,7 +79,7 @@ def test_check_for_quorum_invalid_prev_node(b, user_pk):
|
|||||||
assert e.check_for_quorum(votes[-1]) == test_block
|
assert e.check_for_quorum(votes[-1]) == test_block
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_check_for_quorum_valid(b, user_pk):
|
def test_check_for_quorum_valid(b, user_pk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ def test_check_for_quorum_valid(b, user_pk):
|
|||||||
assert e.check_for_quorum(votes[-1]) is None
|
assert e.check_for_quorum(votes[-1]) is None
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_check_requeue_transaction(b, user_pk):
|
def test_check_requeue_transaction(b, user_pk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ def test_start(mock_start):
|
|||||||
mock_start.assert_called_with()
|
mock_start.assert_called_with()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_full_pipeline(b, user_pk):
|
def test_full_pipeline(b, user_pk):
|
||||||
import random
|
import random
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
|
@ -9,7 +9,7 @@ from bigchaindb import config_utils
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_get_stale(b, user_pk):
|
def test_get_stale(b, user_pk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
tx = Transaction.create([b.me], [([user_pk], 1)])
|
tx = Transaction.create([b.me], [([user_pk], 1)])
|
||||||
@ -26,7 +26,7 @@ def test_get_stale(b, user_pk):
|
|||||||
assert tx.to_dict() == _tx
|
assert tx.to_dict() == _tx
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_reassign_transactions(b, user_pk):
|
def test_reassign_transactions(b, user_pk):
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
@ -66,22 +66,15 @@ def test_reassign_transactions(b, user_pk):
|
|||||||
assert tx['assignee'] != 'lol'
|
assert tx['assignee'] != 'lol'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_full_pipeline(monkeypatch, user_pk):
|
def test_full_pipeline(monkeypatch, user_pk):
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
'database': {
|
|
||||||
'name': 'bigchain_test_{}'.format(os.getpid())
|
|
||||||
},
|
|
||||||
'keypair': {
|
|
||||||
'private': '31Lb1ZGKTyHnmVK3LUMrAUrPNfd4sE2YyBt3UA4A25aA',
|
|
||||||
'public': '4XYfCbabAWVUCbjTmRTFEu2sc3dFEdkse4r6X498B1s8'
|
|
||||||
},
|
|
||||||
'keyring': ['aaa', 'bbb'],
|
'keyring': ['aaa', 'bbb'],
|
||||||
'backlog_reassign_delay': 0.01
|
'backlog_reassign_delay': 0.01
|
||||||
}
|
}
|
||||||
config_utils.set_config(CONFIG)
|
config_utils.update_config(CONFIG)
|
||||||
b = Bigchain()
|
b = Bigchain()
|
||||||
|
|
||||||
original_txs = {}
|
original_txs = {}
|
||||||
|
@ -62,7 +62,7 @@ def test_vote_creation_invalid(b):
|
|||||||
vote['signature']) is True
|
vote['signature']) is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_vote_ungroup_returns_a_set_of_results(b):
|
def test_vote_ungroup_returns_a_set_of_results(b):
|
||||||
from bigchaindb.pipelines import vote
|
from bigchaindb.pipelines import vote
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ def test_vote_ungroup_returns_a_set_of_results(b):
|
|||||||
assert len(txs) == 10
|
assert len(txs) == 10
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_vote_validate_block(b):
|
def test_vote_validate_block(b):
|
||||||
from bigchaindb.pipelines import vote
|
from bigchaindb.pipelines import vote
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ def test_vote_validate_block(b):
|
|||||||
assert tx1 == tx2
|
assert tx1 == tx2
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_validate_block_with_invalid_id(b):
|
def test_validate_block_with_invalid_id(b):
|
||||||
from bigchaindb.pipelines import vote
|
from bigchaindb.pipelines import vote
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ def test_validate_block_with_invalid_id(b):
|
|||||||
assert invalid_dummy_tx == [vote_obj.invalid_dummy_tx]
|
assert invalid_dummy_tx == [vote_obj.invalid_dummy_tx]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_validate_block_with_invalid_signature(b):
|
def test_validate_block_with_invalid_signature(b):
|
||||||
from bigchaindb.pipelines import vote
|
from bigchaindb.pipelines import vote
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ def test_validate_block_with_invalid_signature(b):
|
|||||||
assert invalid_dummy_tx == [vote_obj.invalid_dummy_tx]
|
assert invalid_dummy_tx == [vote_obj.invalid_dummy_tx]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_vote_validate_transaction(b):
|
def test_vote_validate_transaction(b):
|
||||||
from bigchaindb.pipelines import vote
|
from bigchaindb.pipelines import vote
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
@ -146,7 +146,7 @@ def test_vote_validate_transaction(b):
|
|||||||
assert validation == (False, 456, 10)
|
assert validation == (False, 456, 10)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_vote_accumulates_transactions(b):
|
def test_vote_accumulates_transactions(b):
|
||||||
from bigchaindb.pipelines import vote
|
from bigchaindb.pipelines import vote
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ def test_vote_accumulates_transactions(b):
|
|||||||
assert validation == (False, 456, 10)
|
assert validation == (False, 456, 10)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_valid_block_voting_sequential(b, monkeypatch):
|
def test_valid_block_voting_sequential(b, monkeypatch):
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
from bigchaindb.common import crypto, util
|
from bigchaindb.common import crypto, util
|
||||||
@ -195,7 +195,7 @@ def test_valid_block_voting_sequential(b, monkeypatch):
|
|||||||
vote_doc['signature']) is True
|
vote_doc['signature']) is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_valid_block_voting_multiprocessing(b, monkeypatch):
|
def test_valid_block_voting_multiprocessing(b, monkeypatch):
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
from bigchaindb.common import crypto, util
|
from bigchaindb.common import crypto, util
|
||||||
@ -231,7 +231,7 @@ def test_valid_block_voting_multiprocessing(b, monkeypatch):
|
|||||||
vote_doc['signature']) is True
|
vote_doc['signature']) is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_valid_block_voting_with_create_transaction(b, monkeypatch):
|
def test_valid_block_voting_with_create_transaction(b, monkeypatch):
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
from bigchaindb.common import crypto, util
|
from bigchaindb.common import crypto, util
|
||||||
@ -274,7 +274,7 @@ def test_valid_block_voting_with_create_transaction(b, monkeypatch):
|
|||||||
vote_doc['signature']) is True
|
vote_doc['signature']) is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_valid_block_voting_with_transfer_transactions(monkeypatch, b):
|
def test_valid_block_voting_with_transfer_transactions(monkeypatch, b):
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
from bigchaindb.common import crypto, util
|
from bigchaindb.common import crypto, util
|
||||||
@ -346,7 +346,7 @@ def test_valid_block_voting_with_transfer_transactions(monkeypatch, b):
|
|||||||
vote2_doc['signature']) is True
|
vote2_doc['signature']) is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_unsigned_tx_in_block_voting(monkeypatch, b, user_pk):
|
def test_unsigned_tx_in_block_voting(monkeypatch, b, user_pk):
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
from bigchaindb.common import crypto, util
|
from bigchaindb.common import crypto, util
|
||||||
@ -385,7 +385,7 @@ def test_unsigned_tx_in_block_voting(monkeypatch, b, user_pk):
|
|||||||
vote_doc['signature']) is True
|
vote_doc['signature']) is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_pk):
|
def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_pk):
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
from bigchaindb.common import crypto, util
|
from bigchaindb.common import crypto, util
|
||||||
@ -426,7 +426,7 @@ def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_pk):
|
|||||||
vote_doc['signature']) is True
|
vote_doc['signature']) is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_pk):
|
def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_pk):
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
from bigchaindb.common import crypto, util
|
from bigchaindb.common import crypto, util
|
||||||
@ -467,7 +467,7 @@ def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_pk):
|
|||||||
vote_doc['signature']) is True
|
vote_doc['signature']) is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_invalid_block_voting(monkeypatch, b, user_pk):
|
def test_invalid_block_voting(monkeypatch, b, user_pk):
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
from bigchaindb.common import crypto, util
|
from bigchaindb.common import crypto, util
|
||||||
@ -504,7 +504,7 @@ def test_invalid_block_voting(monkeypatch, b, user_pk):
|
|||||||
vote_doc['signature']) is True
|
vote_doc['signature']) is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_voter_considers_unvoted_blocks_when_single_node(monkeypatch, b):
|
def test_voter_considers_unvoted_blocks_when_single_node(monkeypatch, b):
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
from bigchaindb.pipelines import vote
|
from bigchaindb.pipelines import vote
|
||||||
@ -553,7 +553,7 @@ def test_voter_considers_unvoted_blocks_when_single_node(monkeypatch, b):
|
|||||||
assert all(vote['node_pubkey'] == b.me for vote in votes)
|
assert all(vote['node_pubkey'] == b.me for vote in votes)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_voter_chains_blocks_with_the_previous_ones(monkeypatch, b):
|
def test_voter_chains_blocks_with_the_previous_ones(monkeypatch, b):
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
from bigchaindb.pipelines import vote
|
from bigchaindb.pipelines import vote
|
||||||
@ -595,7 +595,7 @@ def test_voter_chains_blocks_with_the_previous_ones(monkeypatch, b):
|
|||||||
{block['id'] for block in blocks})
|
{block['id'] for block in blocks})
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_voter_checks_for_previous_vote(monkeypatch, b):
|
def test_voter_checks_for_previous_vote(monkeypatch, b):
|
||||||
from bigchaindb.backend import query
|
from bigchaindb.backend import query
|
||||||
from bigchaindb.pipelines import vote
|
from bigchaindb.pipelines import vote
|
||||||
@ -637,7 +637,7 @@ def test_voter_checks_for_previous_vote(monkeypatch, b):
|
|||||||
|
|
||||||
|
|
||||||
@patch.object(Pipeline, 'start')
|
@patch.object(Pipeline, 'start')
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_start(mock_start, b):
|
def test_start(mock_start, b):
|
||||||
# TODO: `block.start` is just a wrapper around `vote.create_pipeline`,
|
# TODO: `block.start` is just a wrapper around `vote.create_pipeline`,
|
||||||
# that is tested by `test_full_pipeline`.
|
# that is tested by `test_full_pipeline`.
|
||||||
|
@ -9,19 +9,6 @@ import bigchaindb
|
|||||||
ORIGINAL_CONFIG = copy.deepcopy(bigchaindb._config)
|
ORIGINAL_CONFIG = copy.deepcopy(bigchaindb._config)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def ignore_local_config_file(monkeypatch):
|
|
||||||
"""
|
|
||||||
This fixture's purpose is to override the one under
|
|
||||||
:module:`tests/conftest.py` so that the original behaviour of
|
|
||||||
:func:`bigchaindb.config_utils.file_config` is restored, so that it can be
|
|
||||||
tested.
|
|
||||||
|
|
||||||
"""
|
|
||||||
from bigchaindb.config_utils import file_config
|
|
||||||
monkeypatch.setattr('bigchaindb.config_utils.file_config', file_config)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function', autouse=True)
|
@pytest.fixture(scope='function', autouse=True)
|
||||||
def clean_config(monkeypatch):
|
def clean_config(monkeypatch):
|
||||||
monkeypatch.setattr('bigchaindb.config', copy.deepcopy(ORIGINAL_CONFIG))
|
monkeypatch.setattr('bigchaindb.config', copy.deepcopy(ORIGINAL_CONFIG))
|
||||||
|
@ -91,9 +91,10 @@ def test_has_previous_vote(monkeypatch):
|
|||||||
bigchain.has_previous_vote(block)
|
bigchain.has_previous_vote(block)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('count,exists', ((1, True), (0, False)))
|
@pytest.mark.parametrize('exists', (True, False))
|
||||||
def test_transaction_exists(monkeypatch, count, exists):
|
def test_transaction_exists(monkeypatch, exists):
|
||||||
from bigchaindb.core import Bigchain
|
from bigchaindb.core import Bigchain
|
||||||
monkeypatch.setattr(RqlQuery, 'run', lambda x, y: count)
|
monkeypatch.setattr(
|
||||||
|
'bigchaindb.backend.query.has_transaction', lambda x, y: exists)
|
||||||
bigchain = Bigchain(public_key='pubkey', private_key='privkey')
|
bigchain = Bigchain(public_key='pubkey', private_key='privkey')
|
||||||
assert bigchain.transaction_exists('txid') is exists
|
assert bigchain.transaction_exists('txid') is exists
|
||||||
|
43
tests/utils.py
Normal file
43
tests/utils.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
from functools import singledispatch
|
||||||
|
|
||||||
|
import rethinkdb as r
|
||||||
|
|
||||||
|
from bigchaindb.backend.mongodb.connection import MongoDBConnection
|
||||||
|
from bigchaindb.backend.rethinkdb.connection import RethinkDBConnection
|
||||||
|
|
||||||
|
|
||||||
|
@singledispatch
|
||||||
|
def list_dbs(connection):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
@list_dbs.register(RethinkDBConnection)
|
||||||
|
def list_rethink_dbs(connection):
|
||||||
|
return connection.run(r.db_list())
|
||||||
|
|
||||||
|
|
||||||
|
@list_dbs.register(MongoDBConnection)
|
||||||
|
def list_mongo_dbs(connection):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
@singledispatch
|
||||||
|
def flush_db(connection, dbname):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
@flush_db.register(RethinkDBConnection)
|
||||||
|
def flush_rethink_db(connection, dbname):
|
||||||
|
try:
|
||||||
|
connection.run(r.db(dbname).table('bigchain').delete())
|
||||||
|
connection.run(r.db(dbname).table('backlog').delete())
|
||||||
|
connection.run(r.db(dbname).table('votes').delete())
|
||||||
|
except r.ReqlOpFailedError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@flush_db.register(MongoDBConnection)
|
||||||
|
def flush_mongo_db(connection, dbname):
|
||||||
|
connection.conn[dbname].bigchain.delete_many({})
|
||||||
|
connection.conn[dbname].backlog.delete_many({})
|
||||||
|
connection.conn[dbname].votes.delete_many({})
|
@ -2,7 +2,7 @@ import pytest
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def app(request, restore_config):
|
def app(request):
|
||||||
from bigchaindb.web import server
|
from bigchaindb.web import server
|
||||||
app = server.create_app(debug=True)
|
app = server.create_app(debug=True)
|
||||||
return app
|
return app
|
||||||
|
@ -8,6 +8,7 @@ from bigchaindb.common import crypto
|
|||||||
TX_ENDPOINT = '/api/v1/transactions/'
|
TX_ENDPOINT = '/api/v1/transactions/'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_get_transaction_endpoint(b, client, user_pk):
|
def test_get_transaction_endpoint(b, client, user_pk):
|
||||||
input_tx = b.get_owned_ids(user_pk).pop()
|
input_tx = b.get_owned_ids(user_pk).pop()
|
||||||
@ -17,6 +18,7 @@ def test_get_transaction_endpoint(b, client, user_pk):
|
|||||||
assert res.status_code == 200
|
assert res.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_get_transaction_returns_404_if_not_found(client):
|
def test_get_transaction_returns_404_if_not_found(client):
|
||||||
res = client.get(TX_ENDPOINT + '123')
|
res = client.get(TX_ENDPOINT + '123')
|
||||||
@ -26,7 +28,7 @@ def test_get_transaction_returns_404_if_not_found(client):
|
|||||||
assert res.status_code == 404
|
assert res.status_code == 404
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('setup_database')
|
@pytest.mark.bdb
|
||||||
def test_post_create_transaction_endpoint(b, client):
|
def test_post_create_transaction_endpoint(b, client):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
user_priv, user_pub = crypto.generate_key_pair()
|
user_priv, user_pub = crypto.generate_key_pair()
|
||||||
@ -120,6 +122,7 @@ def test_post_invalid_transaction(client, exc, msg, monkeypatch):
|
|||||||
'Invalid transaction ({}): {}'.format(exc, msg))
|
'Invalid transaction ({}): {}'.format(exc, msg))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_post_transfer_transaction_endpoint(b, client, user_pk, user_sk):
|
def test_post_transfer_transaction_endpoint(b, client, user_pk, user_sk):
|
||||||
sk, pk = crypto.generate_key_pair()
|
sk, pk = crypto.generate_key_pair()
|
||||||
@ -141,6 +144,7 @@ def test_post_transfer_transaction_endpoint(b, client, user_pk, user_sk):
|
|||||||
assert res.json['conditions'][0]['owners_after'][0] == user_pub
|
assert res.json['conditions'][0]['owners_after'][0] == user_pub
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_post_invalid_transfer_transaction_returns_400(b, client, user_pk, user_sk):
|
def test_post_invalid_transfer_transaction_returns_400(b, client, user_pk, user_sk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
@ -158,6 +162,7 @@ def test_post_invalid_transfer_transaction_returns_400(b, client, user_pk, user_
|
|||||||
assert res.status_code == 400
|
assert res.status_code == 400
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_get_transaction_status_endpoint(b, client, user_pk):
|
def test_get_transaction_status_endpoint(b, client, user_pk):
|
||||||
input_tx = b.get_owned_ids(user_pk).pop()
|
input_tx = b.get_owned_ids(user_pk).pop()
|
||||||
@ -171,6 +176,7 @@ def test_get_transaction_status_endpoint(b, client, user_pk):
|
|||||||
assert res.status_code == 200
|
assert res.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_get_transaction_status_returns_404_if_not_found(client):
|
def test_get_transaction_status_returns_404_if_not_found(client):
|
||||||
res = client.get(TX_ENDPOINT + '123' + "/status")
|
res = client.get(TX_ENDPOINT + '123' + "/status")
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
pytestmark = [pytest.mark.bdb, pytest.mark.usefixtures('inputs')]
|
||||||
|
|
||||||
UNSPENTS_ENDPOINT = '/api/v1/unspents/'
|
UNSPENTS_ENDPOINT = '/api/v1/unspents/'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('inputs')
|
|
||||||
def test_get_unspents_endpoint(b, client, user_pk):
|
def test_get_unspents_endpoint(b, client, user_pk):
|
||||||
expected = [u.to_uri('..') for u in b.get_owned_ids(user_pk)]
|
expected = [u.to_uri('..') for u in b.get_owned_ids(user_pk)]
|
||||||
res = client.get(UNSPENTS_ENDPOINT + '?public_key={}'.format(user_pk))
|
res = client.get(UNSPENTS_ENDPOINT + '?public_key={}'.format(user_pk))
|
||||||
@ -12,13 +12,11 @@ def test_get_unspents_endpoint(b, client, user_pk):
|
|||||||
assert res.status_code == 200
|
assert res.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('inputs')
|
|
||||||
def test_get_unspents_endpoint_without_public_key(client):
|
def test_get_unspents_endpoint_without_public_key(client):
|
||||||
res = client.get(UNSPENTS_ENDPOINT)
|
res = client.get(UNSPENTS_ENDPOINT)
|
||||||
assert res.status_code == 400
|
assert res.status_code == 400
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('inputs')
|
|
||||||
def test_get_unspents_endpoint_with_unused_public_key(client):
|
def test_get_unspents_endpoint_with_unused_public_key(client):
|
||||||
expected = []
|
expected = []
|
||||||
res = client.get(UNSPENTS_ENDPOINT + '?public_key=abc')
|
res = client.get(UNSPENTS_ENDPOINT + '?public_key=abc')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user