2018-08-16 12:31:32 +02:00
|
|
|
# Copyright BigchainDB GmbH and BigchainDB contributors
|
|
|
|
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
|
|
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
|
|
|
|
2016-02-13 02:14:15 +01:00
|
|
|
import pytest
|
|
|
|
|
2018-07-18 10:52:33 +02:00
|
|
|
|
2016-02-13 02:14:15 +01:00
|
|
|
@pytest.fixture
|
2016-03-03 01:40:40 +01:00
|
|
|
def config(request, monkeypatch):
|
2017-06-13 12:04:34 +02:00
|
|
|
backend = request.config.getoption('--database-backend')
|
|
|
|
if backend == 'mongodb-ssl':
|
|
|
|
backend = 'mongodb'
|
|
|
|
|
2016-02-13 02:14:15 +01:00
|
|
|
config = {
|
|
|
|
'database': {
|
2017-06-13 12:04:34 +02:00
|
|
|
'backend': backend,
|
2016-02-13 02:14:15 +01:00
|
|
|
'host': 'host',
|
|
|
|
'port': 28015,
|
|
|
|
'name': 'bigchain',
|
2017-01-20 14:05:28 +01:00
|
|
|
'replicaset': 'bigchain-rs',
|
2017-02-23 17:20:21 +01:00
|
|
|
'connection_timeout': 5000,
|
|
|
|
'max_tries': 3
|
2016-02-13 02:14:15 +01:00
|
|
|
},
|
2018-08-08 12:17:44 +02:00
|
|
|
'tendermint': {
|
|
|
|
'host': 'localhost',
|
|
|
|
'port': 26657,
|
|
|
|
},
|
2016-02-13 02:14:15 +01:00
|
|
|
'CONFIGURED': True,
|
|
|
|
}
|
|
|
|
|
2016-03-03 01:40:40 +01:00
|
|
|
monkeypatch.setattr('bigchaindb.config', config)
|
|
|
|
|
|
|
|
return config
|
2016-02-13 02:14:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_bigchain_class_default_initialization(config):
|
Refactor tendermint directory to project root (#2401)
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Fixed flake8 complaint about too many blank lines
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Updating from master changed BigchainDB.process_post_response to a private method, so I had to align with that.
* Fixed a couple stale references to bigchaindb.Bigchain in docstrings
* Missed a reference to `Bigchain` in a patch call...
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
2018-07-25 16:59:25 +02:00
|
|
|
from bigchaindb import BigchainDB
|
2016-03-14 21:27:17 +01:00
|
|
|
from bigchaindb.consensus import BaseConsensusRules
|
2016-12-07 11:50:47 +01:00
|
|
|
from bigchaindb.backend.connection import Connection
|
2018-07-10 17:34:51 +02:00
|
|
|
bigchain = BigchainDB()
|
2016-12-07 11:50:47 +01:00
|
|
|
assert isinstance(bigchain.connection, Connection)
|
|
|
|
assert bigchain.connection.host == config['database']['host']
|
|
|
|
assert bigchain.connection.port == config['database']['port']
|
|
|
|
assert bigchain.connection.dbname == config['database']['name']
|
2016-03-14 21:27:17 +01:00
|
|
|
assert bigchain.consensus == BaseConsensusRules
|
2016-02-13 02:14:15 +01:00
|
|
|
|
|
|
|
|
2018-08-08 12:17:44 +02:00
|
|
|
def test_bigchain_class_initialization_with_parameters():
|
Refactor tendermint directory to project root (#2401)
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Problem: core.py contains an unused class, `Bigchain`
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
* Fixed flake8 complaint about too many blank lines
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI...
Sorry in advance!
* Updating from master changed BigchainDB.process_post_response to a private method, so I had to align with that.
* Fixed a couple stale references to bigchaindb.Bigchain in docstrings
* Missed a reference to `Bigchain` in a patch call...
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
* Problem: BigchainDB class should be part of project root
Solution: Removed the /tendermint directory and moved its contents to project root
* Problem: Flake8 complained that imports were not at the top of the file
Solution: Had to play around with the order of imports to avoid cyclic dependencies, but its working and style compliant now
* Problem: Stale reference to /tendermint directory in the index
Solution: Removed the references to /tendermint
* Problem: Flake8 complaining of unused import in __init__.py
Solution: The import is there so I can import App directly from bigchaindb, rather than from bigchaindb.core (which I think improves code readability. I added a # noqa to silence Flake8.
* Problem: Stale references to `bigchaindb.tendermint.BigchainDB` in the rst files cause Sphinx to fail
Solution: Updated the autodoc files to use `bigchaindb.BigchainDB` instead
* Problem: Stale reference to the `tendermint` directory in an @patch in a disabled test
Solution: Updated the @patch for completeness
2018-07-25 16:59:25 +02:00
|
|
|
from bigchaindb import BigchainDB
|
2016-12-07 11:50:47 +01:00
|
|
|
from bigchaindb.backend import connect
|
2016-03-14 21:27:17 +01:00
|
|
|
from bigchaindb.consensus import BaseConsensusRules
|
2016-12-07 11:50:47 +01:00
|
|
|
init_db_kwargs = {
|
2018-06-08 15:50:50 +02:00
|
|
|
'backend': 'localmongodb',
|
2016-12-07 11:50:47 +01:00
|
|
|
'host': 'this_is_the_db_host',
|
|
|
|
'port': 12345,
|
|
|
|
'name': 'this_is_the_db_name',
|
|
|
|
}
|
|
|
|
connection = connect(**init_db_kwargs)
|
2018-08-08 12:17:44 +02:00
|
|
|
bigchain = BigchainDB(connection=connection)
|
2016-12-06 14:23:17 +01:00
|
|
|
assert bigchain.connection == connection
|
2016-12-07 11:50:47 +01:00
|
|
|
assert bigchain.connection.host == init_db_kwargs['host']
|
|
|
|
assert bigchain.connection.port == init_db_kwargs['port']
|
|
|
|
assert bigchain.connection.dbname == init_db_kwargs['name']
|
2016-03-14 21:27:17 +01:00
|
|
|
assert bigchain.consensus == BaseConsensusRules
|
2016-06-28 14:19:22 +02:00
|
|
|
|
|
|
|
|
2017-03-16 14:01:43 +01:00
|
|
|
def test_get_spent_issue_1271(b, alice, bob, carol):
|
|
|
|
from bigchaindb.models import Transaction
|
|
|
|
|
|
|
|
tx_1 = Transaction.create(
|
|
|
|
[carol.public_key],
|
|
|
|
[([carol.public_key], 8)],
|
|
|
|
).sign([carol.private_key])
|
2018-07-18 10:52:33 +02:00
|
|
|
assert b.validate_transaction(tx_1)
|
|
|
|
b.store_bulk_transactions([tx_1])
|
2017-03-16 14:01:43 +01:00
|
|
|
|
|
|
|
tx_2 = Transaction.transfer(
|
|
|
|
tx_1.to_inputs(),
|
|
|
|
[([bob.public_key], 2),
|
|
|
|
([alice.public_key], 2),
|
|
|
|
([carol.public_key], 4)],
|
|
|
|
asset_id=tx_1.id,
|
|
|
|
).sign([carol.private_key])
|
2018-07-18 10:52:33 +02:00
|
|
|
assert b.validate_transaction(tx_2)
|
|
|
|
b.store_bulk_transactions([tx_2])
|
2017-03-16 14:01:43 +01:00
|
|
|
|
|
|
|
tx_3 = Transaction.transfer(
|
|
|
|
tx_2.to_inputs()[2:3],
|
|
|
|
[([alice.public_key], 1),
|
|
|
|
([carol.public_key], 3)],
|
|
|
|
asset_id=tx_1.id,
|
|
|
|
).sign([carol.private_key])
|
2018-07-18 10:52:33 +02:00
|
|
|
assert b.validate_transaction(tx_3)
|
|
|
|
b.store_bulk_transactions([tx_3])
|
2017-03-16 14:01:43 +01:00
|
|
|
|
|
|
|
tx_4 = Transaction.transfer(
|
|
|
|
tx_2.to_inputs()[1:2] + tx_3.to_inputs()[0:1],
|
|
|
|
[([bob.public_key], 3)],
|
|
|
|
asset_id=tx_1.id,
|
|
|
|
).sign([alice.private_key])
|
2018-07-18 10:52:33 +02:00
|
|
|
assert b.validate_transaction(tx_4)
|
|
|
|
b.store_bulk_transactions([tx_4])
|
2017-03-16 14:01:43 +01:00
|
|
|
|
|
|
|
tx_5 = Transaction.transfer(
|
|
|
|
tx_2.to_inputs()[0:1],
|
|
|
|
[([alice.public_key], 2)],
|
|
|
|
asset_id=tx_1.id,
|
|
|
|
).sign([bob.private_key])
|
2018-07-18 10:52:33 +02:00
|
|
|
assert b.validate_transaction(tx_5)
|
|
|
|
b.store_bulk_transactions([tx_5])
|
|
|
|
|
2017-03-16 14:01:43 +01:00
|
|
|
assert b.get_spent(tx_2.id, 0) == tx_5
|
|
|
|
assert not b.get_spent(tx_5.id, 0)
|
|
|
|
assert b.get_outputs_filtered(alice.public_key)
|
2017-06-15 14:08:38 +02:00
|
|
|
assert b.get_outputs_filtered(alice.public_key, spent=False)
|