Merge branch 'develop' into statsd

This commit is contained in:
ryan 2016-02-16 10:07:35 +01:00
commit 6ee330213c
9 changed files with 198 additions and 138 deletions

View File

@ -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
```text
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
```text
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
```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"
```
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:
```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
```
@ -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
```text
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.)

View File

@ -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
from bigchaindb.monitor import Monitor
@ -17,6 +17,7 @@ c = Monitor()
class GenesisBlockAlreadyExistsError(Exception):
pass
class KeypairNotFoundException(Exception):
pass
@ -47,7 +48,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']

View File

@ -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
sudo 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 `sudo pip3 install bigchaindb` or `sudo pip3.4 install bigchaindb`. The `sudo` may not be necessary.)
### 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
```

View File

@ -8,9 +8,6 @@ Tasks:
import pytest
import bigchaindb
import bigchaindb.config_utils
config = {
'database': {
@ -27,23 +24,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):
from bigchaindb import config_utils
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

View File

@ -12,11 +12,16 @@ 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
@pytest.fixture(autouse=True)
def restore_config(request, node_config):
from bigchaindb import config_utils
config_utils.dict_config(node_config)
@pytest.fixture(scope='module', autouse=True)
def setup_database(request):
print('Initializing test db')

View File

@ -12,11 +12,8 @@ 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
from .conftest import USER_PUBLIC_KEY, USER_PRIVATE_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 +24,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 +34,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,11 +88,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):
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)
@pytest.mark.usefixtures('inputs')
def test_write_transaction(self, b, user_public_key, 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 +102,11 @@ class TestBigchainApi(object):
assert response['replaced'] == 0
assert response['inserted'] == 1
def test_read_transaction(self, b):
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)
@pytest.mark.usefixtures('inputs')
def test_read_transaction(self, b, user_public_key, 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 +116,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):
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)
@pytest.mark.usefixtures('inputs')
def test_assign_transaction_one_node(self, b, user_public_key, 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,17 +129,17 @@ 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])
create_inputs(20, b=b)
create_inputs(user_public_key, amount=20, b=b)
# 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
@ -146,8 +148,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,9 +282,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):
create_inputs()
valid_input = b.get_owned_ids(USER_PUBLIC_KEY).pop()
@pytest.mark.usefixtures('inputs')
def test_non_create_valid_input_wrong_owner(self, b, user_public_key):
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 +292,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):
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)
@pytest.mark.usefixtures('inputs')
def test_non_create_double_spend(self, b, user_public_key, 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 +304,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):
create_inputs()
input_valid = b.get_owned_ids(USER_PUBLIC_KEY).pop()
tx_valid = b.create_transaction(USER_PUBLIC_KEY, 'b', input_valid, 'd')
@pytest.mark.usefixtures('inputs')
def test_wrong_transaction_hash(self, b, user_public_key):
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 +322,10 @@ class TestTransactionValidation(object):
b.validate_transaction(tx_valid)
assert b.is_valid_transaction(tx_valid) == False
def test_wrong_signature(self, b):
create_inputs()
input_valid = b.get_owned_ids(USER_PUBLIC_KEY).pop()
tx_valid = b.create_transaction(USER_PUBLIC_KEY, 'b', input_valid, 'd')
@pytest.mark.usefixtures('inputs')
def test_wrong_signature(self, b, user_public_key):
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 +334,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):
create_inputs()
input_valid = b.get_owned_ids(USER_PUBLIC_KEY).pop()
tx_valid = b.create_transaction(USER_PUBLIC_KEY, 'b', input_valid, 'd')
@pytest.mark.usefixtures('inputs')
def test_valid_non_create_transaction(self, b, user_public_key, 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)
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 +361,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):
@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()
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 +402,12 @@ class TestBlockValidation(object):
with pytest.raises(exceptions.InvalidHash):
b.validate_block(block)
def test_valid_block(self, b):
create_inputs()
@pytest.mark.usefixtures('inputs')
def test_valid_block(self, b, user_public_key, user_private_key):
# 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 +493,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 +566,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 +590,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 +615,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 +633,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 +663,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 +691,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 +710,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 +718,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)

View File

@ -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()

59
tests/test_core.py Normal file
View File

@ -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

View File

@ -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()