From b578fbd4c79cd95b649e0beb5c1c148ab953c188 Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Sat, 13 Feb 2016 02:07:50 +0100 Subject: [PATCH 01/13] Add missing blank line (pep8) --- bigchaindb/core.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bigchaindb/core.py b/bigchaindb/core.py index 286336a0..d6669f74 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -15,6 +15,7 @@ from bigchaindb.crypto import hash_data, PublicKey, PrivateKey, generate_key_pai class GenesisBlockAlreadyExistsError(Exception): pass + class KeypairNotFoundException(Exception): pass From 5b8a31a34171363304696edb98925857c9658fe0 Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Sat, 13 Feb 2016 02:14:15 +0100 Subject: [PATCH 02/13] Re-worked tests such that #27 is covered --- tests/conftest.py | 36 +++++++++++++-------------- tests/db/conftest.py | 7 ++++++ tests/test_core.py | 59 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 19 deletions(-) create mode 100644 tests/test_core.py diff --git a/tests/conftest.py b/tests/conftest.py index 4a6ca97e..d6692274 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,7 +9,6 @@ Tasks: import pytest import bigchaindb -import bigchaindb.config_utils config = { @@ -27,23 +26,22 @@ USER_PRIVATE_KEY = 'GmRZxQdQv7tooMijXytQkexKuFN6mJocciJarAmMwTX2' USER_PUBLIC_KEY = 'r3cEu8GNoz8rYpNJ61k7GqfR8VEvdUbtyHce8u1kaYwh' -@pytest.fixture(scope='function', autouse=True) -def restore_config(request): - bigchaindb.config_utils.dict_config(config) +@pytest.fixture +def restore_config(request, node_config): + import bigchaindb.config_utils + bigchaindb.config_utils.dict_config(node_config) -# FIXME: make this fixtures work :) -# @pytest.fixture -# def config(): -# return config -# -# -# @pytest.fixture -# def user_private_key(): -# return USER_PRIVATE_KEY -# -# -# @pytest.fixture -# def user_public_key(): -# return USER_PUBLIC_KEY -# +@pytest.fixture +def node_config(): + return config + + +@pytest.fixture +def user_private_key(): + return USER_PRIVATE_KEY + + +@pytest.fixture +def user_public_key(): + return USER_PUBLIC_KEY diff --git a/tests/db/conftest.py b/tests/db/conftest.py index 438f30e5..7dfe61df 100644 --- a/tests/db/conftest.py +++ b/tests/db/conftest.py @@ -17,6 +17,13 @@ from ..conftest import config, USER_PRIVATE_KEY, USER_PUBLIC_KEY NOOP = None + +@pytest.fixture(autouse=True) +def restore_config(request, node_config): + import bigchaindb.config_utils + bigchaindb.config_utils.dict_config(node_config) + + @pytest.fixture(scope='module', autouse=True) def setup_database(request): print('Initializing test db') diff --git a/tests/test_core.py b/tests/test_core.py new file mode 100644 index 00000000..6374b8be --- /dev/null +++ b/tests/test_core.py @@ -0,0 +1,59 @@ +import copy +import pytest + + +@pytest.fixture +def config(request): + import bigchaindb + config = { + 'database': { + 'host': 'host', + 'port': 28015, + 'name': 'bigchain', + }, + 'keypair': { + 'public': 'pubkey', + 'private': 'privkey', + }, + 'keyring': [], + 'CONFIGURED': True, + } + bigchaindb.config.update(config) + + def fin(): + bigchaindb.config = bigchaindb._config + bigchaindb._config = copy.deepcopy(bigchaindb._config) + request.addfinalizer(fin) + return bigchaindb.config + + +def test_bigchain_class_default_initialization(config): + from bigchaindb.core import Bigchain + bigchain = Bigchain() + assert bigchain.host == config['database']['host'] + assert bigchain.port == config['database']['port'] + assert bigchain.dbname == config['database']['name'] + assert bigchain.me == config['keypair']['public'] + assert bigchain.me_private == config['keypair']['private'] + assert bigchain.federation_nodes == config['keyring'] + assert bigchain._conn is None + + +def test_bigchain_class_initialization_with_parameters(config): + from bigchaindb.core import Bigchain + init_kwargs = { + 'host': 'some_node', + 'port': '12345', + 'dbname': 'atom', + 'public_key': 'white', + 'private_key': 'black', + 'keyring': ['key_one', 'key_two'], + } + bigchain = Bigchain(**init_kwargs) + assert bigchain.host == init_kwargs['host'] + assert bigchain.port == init_kwargs['port'] + assert bigchain.dbname == init_kwargs['dbname'] + assert bigchain.me == init_kwargs['public_key'] + assert bigchain.me_private == init_kwargs['private_key'] + assert bigchain.federation_nodes == init_kwargs['keyring'] + assert bigchain._conn is None From 2db5197619aa7086f2c14b677f78d78cbe75d2af Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Sat, 13 Feb 2016 02:15:44 +0100 Subject: [PATCH 03/13] Remove unused import --- tests/conftest.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index d6692274..e0d4fcd4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,8 +8,6 @@ Tasks: import pytest -import bigchaindb - config = { 'database': { From df242a35c6d18dadd1fdb0a82a7ab60b3685b035 Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Sat, 13 Feb 2016 02:35:09 +0100 Subject: [PATCH 04/13] Use pytest fixtures instead of imports --- tests/db/conftest.py | 2 - tests/db/test_bigchain_api.py | 118 +++++++++++++++++----------------- tests/db/test_voter.py | 6 +- 3 files changed, 61 insertions(+), 65 deletions(-) diff --git a/tests/db/conftest.py b/tests/db/conftest.py index 7dfe61df..0864a6bf 100644 --- a/tests/db/conftest.py +++ b/tests/db/conftest.py @@ -12,8 +12,6 @@ import rethinkdb as r from bigchaindb import Bigchain from bigchaindb.db import get_conn -from ..conftest import config, USER_PRIVATE_KEY, USER_PUBLIC_KEY - NOOP = None diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index 1c40c314..44fc5fc0 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -13,7 +13,7 @@ from bigchaindb.voter import Voter from bigchaindb.block import Block import bigchaindb.config_utils -from .conftest import USER_PUBLIC_KEY, USER_PRIVATE_KEY +from ..conftest import USER_PUBLIC_KEY def create_inputs(amount=1, b=None): @@ -86,11 +86,11 @@ class TestBigchainApi(object): tx = b.create_transaction('a', 'b', 'c', 'd') assert b.deserialize(b.serialize(tx)) == tx - def test_write_transaction(self, b): + def test_write_transaction(self, b, user_public_key, user_private_key): create_inputs() - input_tx = b.get_owned_ids(USER_PUBLIC_KEY).pop() - tx = b.create_transaction(USER_PUBLIC_KEY, 'b', input_tx, 'd') - tx_signed = b.sign_transaction(tx, USER_PRIVATE_KEY) + input_tx = b.get_owned_ids(user_public_key).pop() + tx = b.create_transaction(user_public_key, 'b', input_tx, 'd') + tx_signed = b.sign_transaction(tx, user_private_key) response = b.write_transaction(tx_signed) assert response['skipped'] == 0 @@ -100,11 +100,11 @@ class TestBigchainApi(object): assert response['replaced'] == 0 assert response['inserted'] == 1 - def test_read_transaction(self, b): + def test_read_transaction(self, b, user_public_key, user_private_key): create_inputs() - input_tx = b.get_owned_ids(USER_PUBLIC_KEY).pop() - tx = b.create_transaction(USER_PUBLIC_KEY, 'b', input_tx, 'd') - tx_signed = b.sign_transaction(tx, USER_PRIVATE_KEY) + input_tx = b.get_owned_ids(user_public_key).pop() + tx = b.create_transaction(user_public_key, 'b', input_tx, 'd') + tx_signed = b.sign_transaction(tx, user_private_key) b.write_transaction(tx_signed) # create block and write it to the bighcain before retrieving the transaction @@ -114,11 +114,11 @@ class TestBigchainApi(object): response = b.get_transaction(tx_signed["id"]) assert b.serialize(tx_signed) == b.serialize(response) - def test_assign_transaction_one_node(self, b): + def test_assign_transaction_one_node(self, b, user_public_key, user_private_key): create_inputs() - input_tx = b.get_owned_ids(USER_PUBLIC_KEY).pop() - tx = b.create_transaction(USER_PUBLIC_KEY, 'b', input_tx, 'd') - tx_signed = b.sign_transaction(tx, USER_PRIVATE_KEY) + input_tx = b.get_owned_ids(user_public_key).pop() + tx = b.create_transaction(user_public_key, 'b', input_tx, 'd') + tx_signed = b.sign_transaction(tx, user_private_key) b.write_transaction(tx_signed) # retrieve the transaction @@ -127,7 +127,7 @@ class TestBigchainApi(object): # check if the assignee is the current node assert response['assignee'] == b.me - def test_assign_transaction_multiple_nodes(self, b): + def test_assign_transaction_multiple_nodes(self, b, user_public_key, user_private_key): # create 5 federation nodes for _ in range(5): b.federation_nodes.append(b.generate_keys()[1]) @@ -135,9 +135,9 @@ class TestBigchainApi(object): # test assignee for several transactions for _ in range(20): - input_tx = b.get_owned_ids(USER_PUBLIC_KEY).pop() - tx = b.create_transaction(USER_PUBLIC_KEY, 'b', input_tx, 'd') - tx_signed = b.sign_transaction(tx, USER_PRIVATE_KEY) + input_tx = b.get_owned_ids(user_public_key).pop() + tx = b.create_transaction(user_public_key, 'b', input_tx, 'd') + tx_signed = b.sign_transaction(tx, user_private_key) b.write_transaction(tx_signed) # retrieve the transaction @@ -280,9 +280,9 @@ class TestTransactionValidation(object): assert excinfo.value.args[0] == 'input `c` does not exist in the bigchain' assert b.is_valid_transaction(tx) == False - def test_non_create_valid_input_wrong_owner(self, b): + def test_non_create_valid_input_wrong_owner(self, b, user_public_key): create_inputs() - valid_input = b.get_owned_ids(USER_PUBLIC_KEY).pop() + valid_input = b.get_owned_ids(user_public_key).pop() tx = b.create_transaction('a', 'b', valid_input, 'c') with pytest.raises(exceptions.TransactionOwnerError) as excinfo: b.validate_transaction(tx) @@ -290,11 +290,11 @@ class TestTransactionValidation(object): assert excinfo.value.args[0] == 'current_owner `a` does not own the input `{}`'.format(valid_input) assert b.is_valid_transaction(tx) == False - def test_non_create_double_spend(self, b): + def test_non_create_double_spend(self, b, user_public_key, user_private_key): create_inputs() - input_valid = b.get_owned_ids(USER_PUBLIC_KEY).pop() - tx_valid = b.create_transaction(USER_PUBLIC_KEY, 'b', input_valid, 'd') - tx_valid_signed = b.sign_transaction(tx_valid, USER_PRIVATE_KEY) + input_valid = b.get_owned_ids(user_public_key).pop() + tx_valid = b.create_transaction(user_public_key, 'b', input_valid, 'd') + tx_valid_signed = b.sign_transaction(tx_valid, user_private_key) b.write_transaction(tx_valid_signed) # create and write block to bigchain @@ -302,17 +302,17 @@ class TestTransactionValidation(object): b.write_block(block, durability='hard') # create another transaction with the same input - tx_double_spend = b.create_transaction(USER_PUBLIC_KEY, 'd', input_valid, 'd') + tx_double_spend = b.create_transaction(user_public_key, 'd', input_valid, 'd') with pytest.raises(exceptions.DoubleSpend) as excinfo: b.validate_transaction(tx_double_spend) assert excinfo.value.args[0] == 'input `{}` was already spent'.format(input_valid) assert b.is_valid_transaction(tx_double_spend) == False - def test_wrong_transaction_hash(self, b): + def test_wrong_transaction_hash(self, b, user_public_key): create_inputs() - input_valid = b.get_owned_ids(USER_PUBLIC_KEY).pop() - tx_valid = b.create_transaction(USER_PUBLIC_KEY, 'b', input_valid, 'd') + input_valid = b.get_owned_ids(user_public_key).pop() + tx_valid = b.create_transaction(user_public_key, 'b', input_valid, 'd') # change the transaction hash tx_valid.update({'id': 'abcd'}) @@ -320,10 +320,10 @@ class TestTransactionValidation(object): b.validate_transaction(tx_valid) assert b.is_valid_transaction(tx_valid) == False - def test_wrong_signature(self, b): + def test_wrong_signature(self, b, user_public_key): create_inputs() - input_valid = b.get_owned_ids(USER_PUBLIC_KEY).pop() - tx_valid = b.create_transaction(USER_PUBLIC_KEY, 'b', input_valid, 'd') + input_valid = b.get_owned_ids(user_public_key).pop() + tx_valid = b.create_transaction(user_public_key, 'b', input_valid, 'd') wrong_private_key = '4fyvJe1aw2qHZ4UNRYftXK7JU7zy9bCqoU5ps6Ne3xrY' @@ -332,18 +332,18 @@ class TestTransactionValidation(object): b.validate_transaction(tx_invalid_signed) assert b.is_valid_transaction(tx_invalid_signed) == False - def test_valid_create_transaction(self, b): - tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE') + def test_valid_create_transaction(self, b, user_public_key): + tx = b.create_transaction(b.me, user_public_key, None, 'CREATE') tx_signed = b.sign_transaction(tx, b.me_private) assert tx_signed == b.validate_transaction(tx_signed) assert tx_signed == b.is_valid_transaction(tx_signed) - def test_valid_non_create_transaction(self, b): + def test_valid_non_create_transaction(self, b, user_public_key, user_private_key): create_inputs() - input_valid = b.get_owned_ids(USER_PUBLIC_KEY).pop() - tx_valid = b.create_transaction(USER_PUBLIC_KEY, 'b', input_valid, 'd') + input_valid = b.get_owned_ids(user_public_key).pop() + tx_valid = b.create_transaction(user_public_key, 'b', input_valid, 'd') - tx_valid_signed = b.sign_transaction(tx_valid, USER_PRIVATE_KEY) + tx_valid_signed = b.sign_transaction(tx_valid, user_private_key) assert tx_valid_signed == b.validate_transaction(tx_valid_signed) assert tx_valid_signed == b.is_valid_transaction(tx_valid_signed) @@ -359,10 +359,10 @@ class TestBlockValidation(object): b.validate_block(block) @pytest.mark.skipif(reason='Separated tx validation from block creation.') - def test_invalid_transactions_in_block(self, b): + def test_invalid_transactions_in_block(self, b, user_public_key, ): # invalid transaction create_inputs() - valid_input = b.get_owned_ids(USER_PUBLIC_KEY).pop() + valid_input = b.get_owned_ids(user_public_key).pop() tx_invalid = b.create_transaction('a', 'b', valid_input, 'c') block = b.create_block([tx_invalid]) @@ -400,12 +400,12 @@ class TestBlockValidation(object): with pytest.raises(exceptions.InvalidHash): b.validate_block(block) - def test_valid_block(self, b): + def test_valid_block(self, b, user_public_key, user_private_key): create_inputs() # create valid transaction - input_valid = b.get_owned_ids(USER_PUBLIC_KEY).pop() - tx_valid = b.create_transaction(USER_PUBLIC_KEY, 'b', input_valid, 'd') - tx_valid_signed = b.sign_transaction(tx_valid, USER_PRIVATE_KEY) + input_valid = b.get_owned_ids(user_public_key).pop() + tx_valid = b.create_transaction(user_public_key, 'b', input_valid, 'd') + tx_valid_signed = b.sign_transaction(tx_valid, user_private_key) # create valid block block = b.create_block([tx_valid_signed]) @@ -491,13 +491,13 @@ class TestBigchainVoter(object): assert vote['node_pubkey'] == b.me assert PublicKey(b.me).verify(b.serialize(vote['vote']), vote['signature']) == True - def test_invalid_block_voting(self, b): + def test_invalid_block_voting(self, b, user_public_key): # create queue and voter q_new_block = mp.Queue() voter = Voter(q_new_block) # create transaction - transaction = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE') + transaction = b.create_transaction(b.me, user_public_key, None, 'CREATE') transaction_signed = b.sign_transaction(transaction, b.me_private) genesis = b.create_genesis_block() @@ -564,12 +564,12 @@ class TestBigchainVoter(object): class TestBigchainBlock(object): - def test_by_assignee(self, b): + def test_by_assignee(self, b, user_public_key): # create transactions and randomly assigne them transactions = mp.Queue() count_assigned_to_me = 0 for i in range(100): - tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE') + tx = b.create_transaction(b.me, user_public_key, None, 'CREATE') assignee = random.choice([b.me, 'aaa', 'bbb', 'ccc']) if assignee == b.me: count_assigned_to_me += 1 @@ -588,13 +588,13 @@ class TestBigchainBlock(object): # the queue minus 'stop' assert block.q_tx_to_validate.qsize() - 1 == count_assigned_to_me - def test_validate_transactions(self, b): + def test_validate_transactions(self, b, user_public_key): # create transactions and randomly invalidate some of them by changing the hash transactions = mp.Queue() count_valid = 0 for i in range(100): valid = random.choice([True, False]) - tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE') + tx = b.create_transaction(b.me, user_public_key, None, 'CREATE') tx = b.sign_transaction(tx, b.me_private) if not valid: tx['id'] = 'a' * 64 @@ -613,11 +613,11 @@ class TestBigchainBlock(object): assert block.q_tx_validated.qsize() - 1 == count_valid assert block.q_tx_delete.qsize() - 1 == 100 - def test_create_block(self, b): + def test_create_block(self, b, user_public_key): # create transactions transactions = mp.Queue() for i in range(100): - tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE') + tx = b.create_transaction(b.me, user_public_key, None, 'CREATE') tx = b.sign_transaction(tx, b.me_private) transactions.put(tx) transactions.put('stop') @@ -631,12 +631,12 @@ class TestBigchainBlock(object): # check if the number of valid transactions assert block.q_block.qsize() - 1 == 1 - def test_write_block(self, b): + def test_write_block(self, b, user_public_key): # create transactions transactions = [] blocks = mp.Queue() for i in range(100): - tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE') + tx = b.create_transaction(b.me, user_public_key, None, 'CREATE') tx = b.sign_transaction(tx, b.me_private) transactions.append(tx) @@ -661,14 +661,14 @@ class TestBigchainBlock(object): # check if the number of blocks in bigchain increased assert r.table('bigchain').count() == 2 - def test_delete_transactions(self, b): + def test_delete_transactions(self, b, user_public_key): # make sure that there are no transactions in the backlog r.table('backlog').delete().run(b.conn) # create and write transactions to the backlog transactions = mp.Queue() for i in range(100): - tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE') + tx = b.create_transaction(b.me, user_public_key, None, 'CREATE') tx = b.sign_transaction(tx, b.me_private) b.write_transaction(tx) transactions.put(tx['id']) @@ -689,13 +689,13 @@ class TestBigchainBlock(object): # check if all transactions were deleted from the backlog assert r.table('backlog').count() == 0 - def test_bootstrap(self, b): + def test_bootstrap(self, b, user_public_key): # make sure that there are no transactions in the backlog r.table('backlog').delete().run(b.conn) # create and write transactions to the backlog for i in range(100): - tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE') + tx = b.create_transaction(b.me, user_public_key, None, 'CREATE') tx = b.sign_transaction(tx, b.me_private) b.write_transaction(tx) @@ -708,7 +708,7 @@ class TestBigchainBlock(object): # we should have gotten a queue with 100 results assert initial_results.qsize() - 1 == 100 - def test_start(self, b): + def test_start(self, b, user_public_key): # start with 100 transactions in the backlog and 100 in the changefeed # make sure that there are no transactions in the backlog @@ -716,14 +716,14 @@ class TestBigchainBlock(object): # create and write transactions to the backlog for i in range(100): - tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE') + tx = b.create_transaction(b.me, user_public_key, None, 'CREATE') tx = b.sign_transaction(tx, b.me_private) b.write_transaction(tx) # create 100 more transactions to emulate the changefeed new_transactions = mp.Queue() for i in range(100): - tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE') + tx = b.create_transaction(b.me, user_public_key, None, 'CREATE') tx = b.sign_transaction(tx, b.me_private) b.write_transaction(tx) new_transactions.put(tx) diff --git a/tests/db/test_voter.py b/tests/db/test_voter.py index c5af20e9..26c2bac0 100644 --- a/tests/db/test_voter.py +++ b/tests/db/test_voter.py @@ -7,8 +7,6 @@ from bigchaindb import Bigchain from bigchaindb.voter import Voter, BlockStream from bigchaindb.crypto import PublicKey -from .conftest import USER_PUBLIC_KEY - class TestBigchainVoter(object): @@ -50,13 +48,13 @@ class TestBigchainVoter(object): assert PublicKey(b.me).verify(b.serialize(vote['vote']), vote['signature']) == True - def test_invalid_block_voting(self, b): + def test_invalid_block_voting(self, b, user_public_key): # create queue and voter q_new_block = mp.Queue() voter = Voter(q_new_block) # create transaction - transaction = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE') + transaction = b.create_transaction(b.me, user_public_key, None, 'CREATE') transaction_signed = b.sign_transaction(transaction, b.me_private) genesis = b.create_genesis_block() From f623046f236e6c4f1e492df6a11b872659d514d8 Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Sat, 13 Feb 2016 03:59:01 +0100 Subject: [PATCH 05/13] Use pytest fixtures to create the inputs --- tests/db/test_bigchain_api.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index 44fc5fc0..f4ba8cef 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -13,10 +13,9 @@ from bigchaindb.voter import Voter from bigchaindb.block import Block import bigchaindb.config_utils -from ..conftest import USER_PUBLIC_KEY -def create_inputs(amount=1, b=None): +def create_inputs(user_public_key, amount=1, b=None): # 1. create the genesis block b = b or Bigchain() try: @@ -27,7 +26,7 @@ def create_inputs(amount=1, b=None): # 2. create block with transactions for `USER` to spend transactions = [] for i in range(amount): - tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE') + tx = b.create_transaction(b.me, user_public_key, None, 'CREATE') tx_signed = b.sign_transaction(tx, b.me_private) transactions.append(tx_signed) b.write_transaction(tx_signed) @@ -37,6 +36,11 @@ def create_inputs(amount=1, b=None): return block +@pytest.fixture +def inputs(user_public_key): + return create_inputs(user_public_key) + + @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* ' 'interfere with the correctness of the tests. ') @@ -86,8 +90,8 @@ class TestBigchainApi(object): tx = b.create_transaction('a', 'b', 'c', 'd') assert b.deserialize(b.serialize(tx)) == tx + @pytest.mark.usefixtures('inputs') def test_write_transaction(self, b, user_public_key, user_private_key): - create_inputs() input_tx = b.get_owned_ids(user_public_key).pop() tx = b.create_transaction(user_public_key, 'b', input_tx, 'd') tx_signed = b.sign_transaction(tx, user_private_key) @@ -100,8 +104,8 @@ class TestBigchainApi(object): assert response['replaced'] == 0 assert response['inserted'] == 1 + @pytest.mark.usefixtures('inputs') def test_read_transaction(self, b, user_public_key, user_private_key): - create_inputs() input_tx = b.get_owned_ids(user_public_key).pop() tx = b.create_transaction(user_public_key, 'b', input_tx, 'd') tx_signed = b.sign_transaction(tx, user_private_key) @@ -114,8 +118,8 @@ class TestBigchainApi(object): response = b.get_transaction(tx_signed["id"]) assert b.serialize(tx_signed) == b.serialize(response) + @pytest.mark.usefixtures('inputs') def test_assign_transaction_one_node(self, b, user_public_key, user_private_key): - create_inputs() input_tx = b.get_owned_ids(user_public_key).pop() tx = b.create_transaction(user_public_key, 'b', input_tx, 'd') tx_signed = b.sign_transaction(tx, user_private_key) @@ -131,7 +135,7 @@ class TestBigchainApi(object): # create 5 federation nodes for _ in range(5): b.federation_nodes.append(b.generate_keys()[1]) - create_inputs(20, b=b) + create_inputs(user_public_key, amount=20, b=b) # test assignee for several transactions for _ in range(20): @@ -146,8 +150,8 @@ class TestBigchainApi(object): # check if the assignee is the federation_nodes assert response['assignee'] in b.federation_nodes + @pytest.mark.usefixtures('inputs') def test_genesis_block(self, b): - create_inputs() response = list(r.table('bigchain') .filter(r.row['block_number'] == 0) .run(b.conn))[0] @@ -280,8 +284,8 @@ class TestTransactionValidation(object): assert excinfo.value.args[0] == 'input `c` does not exist in the bigchain' assert b.is_valid_transaction(tx) == False + @pytest.mark.usefixtures('inputs') def test_non_create_valid_input_wrong_owner(self, b, user_public_key): - create_inputs() valid_input = b.get_owned_ids(user_public_key).pop() tx = b.create_transaction('a', 'b', valid_input, 'c') with pytest.raises(exceptions.TransactionOwnerError) as excinfo: @@ -290,8 +294,8 @@ class TestTransactionValidation(object): assert excinfo.value.args[0] == 'current_owner `a` does not own the input `{}`'.format(valid_input) assert b.is_valid_transaction(tx) == False + @pytest.mark.usefixtures('inputs') def test_non_create_double_spend(self, b, user_public_key, user_private_key): - create_inputs() input_valid = b.get_owned_ids(user_public_key).pop() tx_valid = b.create_transaction(user_public_key, 'b', input_valid, 'd') tx_valid_signed = b.sign_transaction(tx_valid, user_private_key) @@ -309,8 +313,8 @@ class TestTransactionValidation(object): assert excinfo.value.args[0] == 'input `{}` was already spent'.format(input_valid) assert b.is_valid_transaction(tx_double_spend) == False + @pytest.mark.usefixtures('inputs') def test_wrong_transaction_hash(self, b, user_public_key): - create_inputs() input_valid = b.get_owned_ids(user_public_key).pop() tx_valid = b.create_transaction(user_public_key, 'b', input_valid, 'd') @@ -320,8 +324,8 @@ class TestTransactionValidation(object): b.validate_transaction(tx_valid) assert b.is_valid_transaction(tx_valid) == False + @pytest.mark.usefixtures('inputs') def test_wrong_signature(self, b, user_public_key): - create_inputs() input_valid = b.get_owned_ids(user_public_key).pop() tx_valid = b.create_transaction(user_public_key, 'b', input_valid, 'd') @@ -338,8 +342,8 @@ class TestTransactionValidation(object): assert tx_signed == b.validate_transaction(tx_signed) assert tx_signed == b.is_valid_transaction(tx_signed) + @pytest.mark.usefixtures('inputs') def test_valid_non_create_transaction(self, b, user_public_key, user_private_key): - create_inputs() input_valid = b.get_owned_ids(user_public_key).pop() tx_valid = b.create_transaction(user_public_key, 'b', input_valid, 'd') @@ -359,9 +363,9 @@ class TestBlockValidation(object): b.validate_block(block) @pytest.mark.skipif(reason='Separated tx validation from block creation.') + @pytest.mark.usefixtures('inputs') def test_invalid_transactions_in_block(self, b, user_public_key, ): # invalid transaction - create_inputs() valid_input = b.get_owned_ids(user_public_key).pop() tx_invalid = b.create_transaction('a', 'b', valid_input, 'c') @@ -400,8 +404,8 @@ class TestBlockValidation(object): with pytest.raises(exceptions.InvalidHash): b.validate_block(block) + @pytest.mark.usefixtures('inputs') def test_valid_block(self, b, user_public_key, user_private_key): - create_inputs() # create valid transaction input_valid = b.get_owned_ids(user_public_key).pop() tx_valid = b.create_transaction(user_public_key, 'b', input_valid, 'd') From 2cf2201095ee538c0ee1628e8b625abc6581e6f0 Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Mon, 15 Feb 2016 11:25:47 +0100 Subject: [PATCH 06/13] Remove unused import --- tests/db/test_bigchain_api.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index f4ba8cef..ca082ba9 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -12,8 +12,6 @@ from bigchaindb.crypto import hash_data, PrivateKey, PublicKey, generate_key_pai from bigchaindb.voter import Voter from bigchaindb.block import Block -import bigchaindb.config_utils - def create_inputs(user_public_key, amount=1, b=None): # 1. create the genesis block From a68a4352b833cc3b56e2f77ae73573f03f1d294e Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Mon, 15 Feb 2016 11:25:56 +0100 Subject: [PATCH 07/13] Import locally --- tests/utils/test_config_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utils/test_config_utils.py b/tests/utils/test_config_utils.py index adbdbe37..54c425b4 100644 --- a/tests/utils/test_config_utils.py +++ b/tests/utils/test_config_utils.py @@ -3,7 +3,6 @@ import copy import pytest import bigchaindb -from bigchaindb import config_utils ORIGINAL_CONFIG = copy.deepcopy(bigchaindb.config) @@ -15,6 +14,7 @@ def clean_config(): def test_bigchain_instance_is_initialized_when_conf_provided(): + from bigchaindb import config_utils assert 'CONFIGURED' not in bigchaindb.config config_utils.dict_config({'keypair': {'public': 'a', 'private': 'b'}}) @@ -27,6 +27,7 @@ def test_bigchain_instance_is_initialized_when_conf_provided(): def test_bigchain_instance_raises_when_not_configured(monkeypatch): + from bigchaindb import config_utils assert 'CONFIGURED' not in bigchaindb.config # We need to disable ``bigchaindb.config_utils.autoconfigure`` to avoid reading @@ -35,4 +36,3 @@ def test_bigchain_instance_raises_when_not_configured(monkeypatch): with pytest.raises(bigchaindb.core.KeypairNotFoundException): bigchaindb.Bigchain() - From dbcf9c0e205bf028a220a1143f887187d406b9f6 Mon Sep 17 00:00:00 2001 From: troymc Date: Mon, 15 Feb 2016 17:22:33 +0100 Subject: [PATCH 08/13] Update CONTRIBUTING.md to say we use GitHub Flow --- CONTRIBUTING.md | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a9583e1e..abd234a0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,11 +20,10 @@ Familiarize yourself with how we do coding and documentation in the BigchainDB p * our Python Style Guide (coming soon) * [our documentation strategy](./docs/README.md) (including code documentation) -* our Documentation Style Guide (coming soon) -* the Gitflow Git workflow (also called git-flow): - * [DataSift's introduction](https://datasift.github.io/gitflow/IntroducingGitFlow.html) - * [Atlassian's tutorial](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow) - * [the original blog post](http://nvie.com/posts/a-successful-git-branching-model/) +* the GitHub Flow (workflow) + * [GitHub Guide: Understanding the GitHub Flow](https://guides.github.com/introduction/flow/) + * [Scott Chacon's blog post about GitHub Flow](http://scottchacon.com/2011/08/31/github-flow.html) + * Note that we call the main branch `develop` rather than `master` * [semantic versioning](http://semver.org/) ### Step 1 - Fork bigchaindb on GitHub @@ -34,7 +33,7 @@ In your web browser, go to [the BigchainDB repository on GitHub](https://github. ### Step 2 - Clone Your Fork (This only has to be done once.) In your local terminal, use Git to clone _your_ `bigchaindb` repository to your local computer. Also add the original GitHub bigchaindb/bigchaindb repository as a remote named `upstream` (a convention): -```bash +```shell git clone git@github.com:your-github-username/bigchaindb.git cd bigchaindb git add upstream git@github.com:BigchainDB/bigchaindb.git @@ -43,7 +42,7 @@ git add upstream git@github.com:BigchainDB/bigchaindb.git ### Step 3 - Fetch and Merge the Latest from `upstream/develop` Switch to the `develop` branch locally, fetch all `upstream` branches, and merge the just-fetched `upstream/develop` branch with the local `develop` branch: -```bash +```shell git checkout develop git fetch upstream git merge upstream/develop @@ -56,26 +55,29 @@ If your new branch is to **fix a bug** identified in a specific GitHub Issue wit If your new branch is to **add a feature** requested in a specific GitHub Issue with number `ISSNO`, then name your new branch `feat/ISSNO/short-description-here`. For example, `feat/135/blue-background-on-mondays`. Otherwise, please give your new branch a short, descriptive, all-lowercase name. -```bash +```shell git checkout -b new-branch-name ``` ### Step 5 - Make Edits, git add, git commit With your new branch checked out locally, make changes or additions to the code or documentation, git add them, and git commit them. -```bash +```shell git add new-or-changed-file git commit -m "Short description of new or changed things" ``` Remember to write tests for new code. If you don't, our code (test) coverage will go down, and we won't be able to accept your code. (We have some hard checks that run on all new pull requests and code coverage is one of them.) -Please run all existing tests to make sure you didn't break something. +Please run all existing tests to make sure you didn't break something. Do: +```shell +py.test -v +``` Remember to write or modify documentation to reflect your additions or changes. You will want to merge changes from upstream (i.e. the original repository) into your new branch from time to time, using something like: -```bash +```shell git fetch upstream git merge upstream/develop ``` @@ -83,7 +85,7 @@ git merge upstream/develop ### Step 6 - Push Your New Branch to origin Make sure you've commited all the additions or changes you want to include in your pull request. Then push your new branch to origin (i.e. _your_ remote bigchaindb repository). -```bash +```shell git push origin new-branch-name ``` @@ -91,7 +93,7 @@ git push origin new-branch-name Go to the GitHub website and to _your_ remote bigchaindb repository (i.e. something like https://github.com/your-user-name/bigchaindb). -See [GitHub's documentation on how to initiate and send a pull request](https://help.github.com/articles/using-pull-requests/). Note that the destination repository should be `BigchainDB/bigchaindb` and the destination branch will typically be `develop` (because we use the Gitflow workflow). +See [GitHub's documentation on how to initiate and send a pull request](https://help.github.com/articles/using-pull-requests/). Note that the destination repository should be `BigchainDB/bigchaindb` and the destination branch will be `develop` (usually, and if it's not, then we can change that if necessary). If this is the first time you've submitted a pull request to BigchainDB, then you must read and accept the Contributor License Agreement (CLA) before we can merge your contributions. That can be found at [https://www.bigchaindb.com/cla](https://www.bigchaindb.com/cla). @@ -104,6 +106,7 @@ Someone will then merge your branch or suggest changes. If we suggsest changes, * [BigchainDB Community links](https://www.bigchaindb.com/community) (e.g. mailing list, Slack) * [General GitHub Documentation](https://help.github.com/) * [Code of Conduct](./CODE_OF_CONDUCT.md) +* [BigchainDB Licenses](./LICENSES.md) * [Contributor License Agreement](https://www.bigchaindb.com/cla) (Note: GitHub automatically links to CONTRIBUTING.md when a contributor creates an Issue or opens a Pull Request.) \ No newline at end of file From 9dcf0840d3591ab0d85e2da0f9960465cd76cc3e Mon Sep 17 00:00:00 2001 From: troymc Date: Mon, 15 Feb 2016 17:27:01 +0100 Subject: [PATCH 09/13] Change bash atop code blocks --- CONTRIBUTING.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index abd234a0..31142c6a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,7 +33,7 @@ In your web browser, go to [the BigchainDB repository on GitHub](https://github. ### Step 2 - Clone Your Fork (This only has to be done once.) In your local terminal, use Git to clone _your_ `bigchaindb` repository to your local computer. Also add the original GitHub bigchaindb/bigchaindb repository as a remote named `upstream` (a convention): -```shell +```bash git clone git@github.com:your-github-username/bigchaindb.git cd bigchaindb git add upstream git@github.com:BigchainDB/bigchaindb.git @@ -42,7 +42,7 @@ git add upstream git@github.com:BigchainDB/bigchaindb.git ### Step 3 - Fetch and Merge the Latest from `upstream/develop` Switch to the `develop` branch locally, fetch all `upstream` branches, and merge the just-fetched `upstream/develop` branch with the local `develop` branch: -```shell +```bash git checkout develop git fetch upstream git merge upstream/develop @@ -55,14 +55,14 @@ If your new branch is to **fix a bug** identified in a specific GitHub Issue wit If your new branch is to **add a feature** requested in a specific GitHub Issue with number `ISSNO`, then name your new branch `feat/ISSNO/short-description-here`. For example, `feat/135/blue-background-on-mondays`. Otherwise, please give your new branch a short, descriptive, all-lowercase name. -```shell +```bash git checkout -b new-branch-name ``` ### Step 5 - Make Edits, git add, git commit With your new branch checked out locally, make changes or additions to the code or documentation, git add them, and git commit them. -```shell +```bash git add new-or-changed-file git commit -m "Short description of new or changed things" ``` @@ -70,14 +70,14 @@ git commit -m "Short description of new or changed things" Remember to write tests for new code. If you don't, our code (test) coverage will go down, and we won't be able to accept your code. (We have some hard checks that run on all new pull requests and code coverage is one of them.) Please run all existing tests to make sure you didn't break something. Do: -```shell +```bash py.test -v ``` Remember to write or modify documentation to reflect your additions or changes. You will want to merge changes from upstream (i.e. the original repository) into your new branch from time to time, using something like: -```shell +```bash git fetch upstream git merge upstream/develop ``` @@ -85,7 +85,7 @@ git merge upstream/develop ### Step 6 - Push Your New Branch to origin Make sure you've commited all the additions or changes you want to include in your pull request. Then push your new branch to origin (i.e. _your_ remote bigchaindb repository). -```shell +```bash git push origin new-branch-name ``` From 2e323208ff037e1fc6b39aae1640ca1d45e1b670 Mon Sep 17 00:00:00 2001 From: troymc Date: Mon, 15 Feb 2016 17:37:40 +0100 Subject: [PATCH 10/13] In CONTRIBUTING.md format code blocks as plain text --- CONTRIBUTING.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 31142c6a..a76edac2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,7 +33,7 @@ In your web browser, go to [the BigchainDB repository on GitHub](https://github. ### Step 2 - Clone Your Fork (This only has to be done once.) In your local terminal, use Git to clone _your_ `bigchaindb` repository to your local computer. Also add the original GitHub bigchaindb/bigchaindb repository as a remote named `upstream` (a convention): -```bash +```text git clone git@github.com:your-github-username/bigchaindb.git cd bigchaindb git add upstream git@github.com:BigchainDB/bigchaindb.git @@ -42,7 +42,7 @@ git add upstream git@github.com:BigchainDB/bigchaindb.git ### Step 3 - Fetch and Merge the Latest from `upstream/develop` Switch to the `develop` branch locally, fetch all `upstream` branches, and merge the just-fetched `upstream/develop` branch with the local `develop` branch: -```bash +```text git checkout develop git fetch upstream git merge upstream/develop @@ -55,14 +55,14 @@ If your new branch is to **fix a bug** identified in a specific GitHub Issue wit If your new branch is to **add a feature** requested in a specific GitHub Issue with number `ISSNO`, then name your new branch `feat/ISSNO/short-description-here`. For example, `feat/135/blue-background-on-mondays`. Otherwise, please give your new branch a short, descriptive, all-lowercase name. -```bash +```text git checkout -b new-branch-name ``` ### Step 5 - Make Edits, git add, git commit With your new branch checked out locally, make changes or additions to the code or documentation, git add them, and git commit them. -```bash +```text git add new-or-changed-file git commit -m "Short description of new or changed things" ``` @@ -70,14 +70,14 @@ git commit -m "Short description of new or changed things" Remember to write tests for new code. If you don't, our code (test) coverage will go down, and we won't be able to accept your code. (We have some hard checks that run on all new pull requests and code coverage is one of them.) Please run all existing tests to make sure you didn't break something. Do: -```bash +```text py.test -v ``` Remember to write or modify documentation to reflect your additions or changes. You will want to merge changes from upstream (i.e. the original repository) into your new branch from time to time, using something like: -```bash +```text git fetch upstream git merge upstream/develop ``` @@ -85,7 +85,7 @@ git merge upstream/develop ### Step 6 - Push Your New Branch to origin Make sure you've commited all the additions or changes you want to include in your pull request. Then push your new branch to origin (i.e. _your_ remote bigchaindb repository). -```bash +```text git push origin new-branch-name ``` From 90129b8fa580c187fe8c37f717d83d72dfe58cc0 Mon Sep 17 00:00:00 2001 From: troymc Date: Mon, 15 Feb 2016 18:52:57 +0100 Subject: [PATCH 11/13] Changed pip3 install instructions for U14.04 --- docs/source/installing.md | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/docs/source/installing.md b/docs/source/installing.md index f859ae9c..a89686a6 100644 --- a/docs/source/installing.md +++ b/docs/source/installing.md @@ -7,7 +7,7 @@ We're developing BigchainDB on Ubuntu 14.04, but it should work on any OS that r The RethinkDB documentation has instructions for how to install RethinkDB Server on a variety of operating systems. Do that (using their instructions for your OS): [Install RethinkDB Server](http://rethinkdb.com/docs/install/). RethinkDB Server doesn't require any special configuration. You can run it by opening a Terminal and entering: -```shell +```text $ rethinkdb ``` @@ -20,7 +20,7 @@ If you don't already have it, then you should [install Python 3.4+](https://www. BigchainDB has some OS-level dependencies. In particular, you need to install the OS-level dependencies for the Python **cryptography** package. Instructions for installing those dependencies on your OS can be found in the [cryptography package documentation](https://cryptography.io/en/latest/installation/). On Ubuntu 14.04, we found that the following was enough (YMMV): -```shell +```text $ sudo apt-get update $ sudo apt-get install libffi-dev g++ libssl-dev python3-dev ``` @@ -30,38 +30,34 @@ With OS-level dependencies installed, you can install BigchainDB with `pip` or f ### How to Install BigchainDB with `pip` BigchainDB is distributed as a Python package on PyPI so you can install it using `pip`. First, make sure you have a version of `pip` installed for Python 3.4+: -```shell +```text $ pip -V ``` -If it says the associated Python version is Python 3.4+, then you can do: -```shell -$ pip install bigchaindb +If it says that `pip` isn't installed, or it says `pip` is associated with a Python version less then 3.4, then you must install a `pip` version associated with Python 3.4+. See [the `pip` installation instructions](https://pip.pypa.io/en/stable/installing/). On Ubuntu 14.04, we found that this works: +```text +$ sudo apt-get install python3-setuptools +$ sudo easy_install3 pip ``` +(Note: Using `sudo apt-get python3-pip` also installs a Python 3 version of `pip` (named `pip3`) but we found it installed a very old version and there were issues with updating it.) -If it says that `pip` isn't installed, or it says `pip` is associated with a Python version less then 3.4, then you must install a `pip` version associated with Python 3.4+. See [the `pip` installation instructions](https://pip.pypa.io/en/stable/installing/). - -On Ubuntu 14.04, we found that this works: -```shell -$ sudo apt-get python3-pip -$ sudo pip3 install bigchaindb +Once you have a version of `pip` associated with Python 3.4+, then you can install BigchainDB using: +```text +pip install bigchaindb ``` - -(It might not be necessary to use `sudo` in the last command above, but we found that it _was_ necessary for Ubuntu 14.04 on an Amazon Web Services (AWS) instance.) - -In general, once you have a version of `pip` associated with Python 3.4+, then you can install BigchainDB using `pip install bigchaindb` or `pipVER install bigchaindb` where `pipVER` is replaced by whatever you must use to call a version of `pip` associated with Python 3.4+ (e.g. `pip3`). +(or maybe `pip3 install bigchaindb` or `pip3.4 bigchaindb`.) ### How to Install BigchainDB from Source BigchainDB is in its early stages and being actively developed on its [GitHub repository](https://github.com/bigchaindb/bigchaindb). Contributions are highly appreciated. Clone the public repository: -```shell +```text $ git clone git@github.com:bigchaindb/bigchaindb.git ``` Install from the source: -```shell +```text $ python setup.py install ``` @@ -72,7 +68,7 @@ Coming soon... ## Run BigchainDB After installing BigchainDB, run it with: -```shell +```text $ bigchaindb start ``` From b725b4e716cb4dc31aaa206da0faba07dd73eb19 Mon Sep 17 00:00:00 2001 From: troymc Date: Mon, 15 Feb 2016 19:40:55 +0100 Subject: [PATCH 12/13] Add sudo before pip install bigchaindb sometimes --- docs/source/installing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/installing.md b/docs/source/installing.md index a89686a6..5c8ee9eb 100644 --- a/docs/source/installing.md +++ b/docs/source/installing.md @@ -43,9 +43,9 @@ $ sudo easy_install3 pip Once you have a version of `pip` associated with Python 3.4+, then you can install BigchainDB using: ```text -pip install bigchaindb +sudo pip install bigchaindb ``` -(or maybe `pip3 install bigchaindb` or `pip3.4 bigchaindb`.) +(or maybe `sudo pip3 install bigchaindb` or `sudo pip3.4 install bigchaindb`. The `sudo` may not be necessary.) ### How to Install BigchainDB from Source From 53aff999aafe6fedb83d1c9f2ee5d94d83b36801 Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Mon, 15 Feb 2016 22:18:26 +0100 Subject: [PATCH 13/13] Make it harder for issue #27 to go unnoticed --- bigchaindb/core.py | 4 ++-- tests/conftest.py | 4 ++-- tests/db/conftest.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bigchaindb/core.py b/bigchaindb/core.py index d6669f74..76d90a58 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -7,7 +7,7 @@ import rapidjson from datetime import datetime import bigchaindb -import bigchaindb.config_utils +from bigchaindb import config_utils from bigchaindb import exceptions from bigchaindb.crypto import hash_data, PublicKey, PrivateKey, generate_key_pair @@ -46,7 +46,7 @@ class Bigchain(object): keyring (list[str]): list of base58 encoded public keys of the federation nodes. """ - bigchaindb.config_utils.autoconfigure() + config_utils.autoconfigure() self.host = host or bigchaindb.config['database']['host'] self.port = port or bigchaindb.config['database']['port'] self.dbname = dbname or bigchaindb.config['database']['name'] diff --git a/tests/conftest.py b/tests/conftest.py index e0d4fcd4..a6006ac2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -26,8 +26,8 @@ USER_PUBLIC_KEY = 'r3cEu8GNoz8rYpNJ61k7GqfR8VEvdUbtyHce8u1kaYwh' @pytest.fixture def restore_config(request, node_config): - import bigchaindb.config_utils - bigchaindb.config_utils.dict_config(node_config) + from bigchaindb import config_utils + config_utils.dict_config(node_config) @pytest.fixture diff --git a/tests/db/conftest.py b/tests/db/conftest.py index 0864a6bf..a9a85d71 100644 --- a/tests/db/conftest.py +++ b/tests/db/conftest.py @@ -18,8 +18,8 @@ NOOP = None @pytest.fixture(autouse=True) def restore_config(request, node_config): - import bigchaindb.config_utils - bigchaindb.config_utils.dict_config(node_config) + from bigchaindb import config_utils + config_utils.dict_config(node_config) @pytest.fixture(scope='module', autouse=True)