From ae8153bd10f4af9121c6175059e345c34b328232 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 14 Mar 2017 15:05:02 +0100 Subject: [PATCH 01/33] new home of structural validation in tests --- .../common/schema/test_transaction_schema.py | 39 ---------- .../validation/test_transaction_structure.py | 71 +++++++++++++++++++ 2 files changed, 71 insertions(+), 39 deletions(-) create mode 100644 tests/validation/test_transaction_structure.py diff --git a/tests/common/schema/test_transaction_schema.py b/tests/common/schema/test_transaction_schema.py index dca10e70..86b192e0 100644 --- a/tests/common/schema/test_transaction_schema.py +++ b/tests/common/schema/test_transaction_schema.py @@ -19,42 +19,3 @@ def test_validate_transaction_signed_transfer(signed_transfer_tx): def test_validate_transaction_fails(): with raises(SchemaValidationError): validate_transaction_schema({}) - - -def test_validate_fails_metadata_empty_dict(create_tx): - create_tx.metadata = {'a': 1} - validate_transaction_schema(create_tx.to_dict()) - create_tx.metadata = None - validate_transaction_schema(create_tx.to_dict()) - create_tx.metadata = {} - with raises(SchemaValidationError): - validate_transaction_schema(create_tx.to_dict()) - - -def test_transfer_asset_schema(signed_transfer_tx): - tx = signed_transfer_tx.to_dict() - validate_transaction_schema(tx) - tx['asset']['data'] = {} - with raises(SchemaValidationError): - validate_transaction_schema(tx) - del tx['asset']['data'] - tx['asset']['id'] = 'b' * 63 - with raises(SchemaValidationError): - validate_transaction_schema(tx) - - -def test_create_single_input(create_tx): - tx = create_tx.to_dict() - tx['inputs'] += tx['inputs'] - with raises(SchemaValidationError): - validate_transaction_schema(tx) - tx['inputs'] = [] - with raises(SchemaValidationError): - validate_transaction_schema(tx) - - -def test_create_tx_no_fulfills(create_tx): - tx = create_tx.to_dict() - tx['inputs'][0]['fulfills'] = {'tx': 'a' * 64, 'output': 0} - with raises(SchemaValidationError): - validate_transaction_schema(tx) diff --git a/tests/validation/test_transaction_structure.py b/tests/validation/test_transaction_structure.py new file mode 100644 index 00000000..6cff9350 --- /dev/null +++ b/tests/validation/test_transaction_structure.py @@ -0,0 +1,71 @@ +""" +All tests of transaction structure. The concern here is that transaction +structural / schematic issues are caught when reading a transaction +(ie going from dict -> transaction). +""" + +import pytest + +from bigchaindb.common.exceptions import SchemaValidationError +from bigchaindb.models import Transaction + + +################################################################################ +# Helper functions + +def validate(tx): + if isinstance(tx, Transaction): + tx = tx.to_dict() + Transaction.from_dict(tx) + + +def validate_throws(tx): + with pytest.raises(SchemaValidationError): + validate(tx) + + +################################################################################ +# Metadata + +def test_validate_fails_metadata_empty_dict(create_tx): + create_tx.metadata = {'a': 1} + validate(create_tx) + create_tx.metadata = None + validate(create_tx) + create_tx.metadata = {} + validate_throws(create_tx) + + +################################################################################ +# Asset + +def test_transfer_asset_schema(signed_transfer_tx): + tx = signed_transfer_tx.to_dict() + validate_transaction_schema(tx) + tx['asset']['data'] = {} + with raises(SchemaValidationError): + validate_transaction_schema(tx) + del tx['asset']['data'] + tx['asset']['id'] = 'b' * 63 + with raises(SchemaValidationError): + validate_transaction_schema(tx) + + +################################################################################ +# Inputs + +def test_create_single_input(create_tx): + tx = create_tx.to_dict() + tx['inputs'] += tx['inputs'] + with raises(SchemaValidationError): + validate_transaction_schema(tx) + tx['inputs'] = [] + with raises(SchemaValidationError): + validate_transaction_schema(tx) + + +def test_create_tx_no_fulfills(create_tx): + tx = create_tx.to_dict() + tx['inputs'][0]['fulfills'] = {'tx': 'a' * 64, 'output': 0} + with raises(SchemaValidationError): + validate_transaction_schema(tx) From 8a5814bb08eb2cdca34a9d41f4bfd1dc2da9b932 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 14 Mar 2017 15:12:12 +0100 Subject: [PATCH 02/33] clarify schema testing module --- .../common/schema/test_transaction_schema.py | 21 -------- tests/common/schema/test_vote_schema.py | 13 ----- tests/common/{schema => }/test_schema.py | 50 ++++++++++++++++++- 3 files changed, 48 insertions(+), 36 deletions(-) delete mode 100644 tests/common/schema/test_transaction_schema.py delete mode 100644 tests/common/schema/test_vote_schema.py rename tests/common/{schema => }/test_schema.py (58%) diff --git a/tests/common/schema/test_transaction_schema.py b/tests/common/schema/test_transaction_schema.py deleted file mode 100644 index 86b192e0..00000000 --- a/tests/common/schema/test_transaction_schema.py +++ /dev/null @@ -1,21 +0,0 @@ -from pytest import raises - -from bigchaindb.common.exceptions import SchemaValidationError -from bigchaindb.common.schema import validate_transaction_schema - - -def test_validate_transaction_create(create_tx): - validate_transaction_schema(create_tx.to_dict()) - - -def test_validate_transaction_signed_create(signed_create_tx): - validate_transaction_schema(signed_create_tx.to_dict()) - - -def test_validate_transaction_signed_transfer(signed_transfer_tx): - validate_transaction_schema(signed_transfer_tx.to_dict()) - - -def test_validate_transaction_fails(): - with raises(SchemaValidationError): - validate_transaction_schema({}) diff --git a/tests/common/schema/test_vote_schema.py b/tests/common/schema/test_vote_schema.py deleted file mode 100644 index a9de9492..00000000 --- a/tests/common/schema/test_vote_schema.py +++ /dev/null @@ -1,13 +0,0 @@ -from pytest import raises - -from bigchaindb.common.exceptions import SchemaValidationError -from bigchaindb.common.schema import validate_vote_schema - - -def test_validate_vote(structurally_valid_vote): - validate_vote_schema(structurally_valid_vote) - - -def test_validate_vote_fails(): - with raises(SchemaValidationError): - validate_vote_schema({}) diff --git a/tests/common/schema/test_schema.py b/tests/common/test_schema.py similarity index 58% rename from tests/common/schema/test_schema.py rename to tests/common/test_schema.py index 02a00ee2..ef972f22 100644 --- a/tests/common/schema/test_schema.py +++ b/tests/common/test_schema.py @@ -1,6 +1,18 @@ -from bigchaindb.common.schema import ( - TX_SCHEMA, VOTE_SCHEMA, drop_schema_descriptions) +""" +This module is tests related to schema checking, but _not_ of granular schematic +properties related to validation. +""" +from pytest import raises + +from bigchaindb.common.exceptions import SchemaValidationError +from bigchaindb.common.schema import ( + TX_SCHEMA, VOTE_SCHEMA, drop_schema_descriptions, + validate_transaction_schema, validate_vote_schema) + + +################################################################################ +# Test of schema utils def _test_additionalproperties(node, path=''): """ @@ -67,3 +79,37 @@ def test_drop_descriptions(): } drop_schema_descriptions(node) assert node == expected + + +################################################################################ +# Test call transaction schema + + +def test_validate_transaction_create(create_tx): + validate_transaction_schema(create_tx.to_dict()) + + +def test_validate_transaction_signed_create(signed_create_tx): + validate_transaction_schema(signed_create_tx.to_dict()) + + +def test_validate_transaction_signed_transfer(signed_transfer_tx): + validate_transaction_schema(signed_transfer_tx.to_dict()) + + +def test_validate_transaction_fails(): + with raises(SchemaValidationError): + validate_transaction_schema({}) + + +################################################################################ +# Test call vote schema + + +def test_validate_vote(structurally_valid_vote): + validate_vote_schema(structurally_valid_vote) + + +def test_validate_vote_fails(): + with raises(SchemaValidationError): + validate_vote_schema({}) From 66830fc1d9228b9fd70c0937b6d30d89d5f533d1 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 14 Mar 2017 15:18:47 +0100 Subject: [PATCH 03/33] move version validation to transaction structure test module --- tests/common/test_transaction.py | 34 -------------- .../validation/test_transaction_structure.py | 44 +++++++++++++------ 2 files changed, 31 insertions(+), 47 deletions(-) diff --git a/tests/common/test_transaction.py b/tests/common/test_transaction.py index 45cadc3b..153c0e6c 100644 --- a/tests/common/test_transaction.py +++ b/tests/common/test_transaction.py @@ -947,37 +947,3 @@ def test_cant_add_empty_input(): with raises(TypeError): tx.add_input(None) - - -def test_validate_version(utx): - import re - import bigchaindb.version - from .utils import validate_transaction_model - from bigchaindb.common.exceptions import SchemaValidationError - - short_ver = bigchaindb.version.__short_version__ - assert utx.version == re.match(r'^(.*\d)', short_ver).group(1) - - validate_transaction_model(utx) - - # At version 1, transaction version will break step with server version. - utx.version = '1.0.0' - with raises(SchemaValidationError): - validate_transaction_model(utx) - - -def test_create_tx_no_asset_id(b, utx): - from bigchaindb.common.exceptions import SchemaValidationError - from .utils import validate_transaction_model - utx.asset['id'] = 'b' * 64 - with raises(SchemaValidationError): - validate_transaction_model(utx) - - -def test_transfer_tx_asset_schema(transfer_utx): - from bigchaindb.common.exceptions import SchemaValidationError - from .utils import validate_transaction_model - tx = transfer_utx - tx.asset['data'] = {} - with raises(SchemaValidationError): - validate_transaction_model(tx) diff --git a/tests/validation/test_transaction_structure.py b/tests/validation/test_transaction_structure.py index 6cff9350..dfdeac01 100644 --- a/tests/validation/test_transaction_structure.py +++ b/tests/validation/test_transaction_structure.py @@ -5,6 +5,7 @@ structural / schematic issues are caught when reading a transaction """ import pytest +import re from bigchaindb.common.exceptions import SchemaValidationError from bigchaindb.models import Transaction @@ -19,7 +20,7 @@ def validate(tx): Transaction.from_dict(tx) -def validate_throws(tx): +def validate_raises(tx): with pytest.raises(SchemaValidationError): validate(tx) @@ -33,7 +34,7 @@ def test_validate_fails_metadata_empty_dict(create_tx): create_tx.metadata = None validate(create_tx) create_tx.metadata = {} - validate_throws(create_tx) + validate_raises(create_tx) ################################################################################ @@ -41,14 +42,17 @@ def test_validate_fails_metadata_empty_dict(create_tx): def test_transfer_asset_schema(signed_transfer_tx): tx = signed_transfer_tx.to_dict() - validate_transaction_schema(tx) + validate(tx) tx['asset']['data'] = {} - with raises(SchemaValidationError): - validate_transaction_schema(tx) + validate_raises(tx) del tx['asset']['data'] tx['asset']['id'] = 'b' * 63 - with raises(SchemaValidationError): - validate_transaction_schema(tx) + validate_raises(tx) + + +def test_create_tx_no_asset_id(create_tx): + create_tx.asset['id'] = 'b' * 64 + validate_raises(create_tx) ################################################################################ @@ -57,15 +61,29 @@ def test_transfer_asset_schema(signed_transfer_tx): def test_create_single_input(create_tx): tx = create_tx.to_dict() tx['inputs'] += tx['inputs'] - with raises(SchemaValidationError): - validate_transaction_schema(tx) + validate_raises(tx) tx['inputs'] = [] - with raises(SchemaValidationError): - validate_transaction_schema(tx) + validate_raises(tx) def test_create_tx_no_fulfills(create_tx): tx = create_tx.to_dict() tx['inputs'][0]['fulfills'] = {'tx': 'a' * 64, 'output': 0} - with raises(SchemaValidationError): - validate_transaction_schema(tx) + validate_raises(tx) + + +################################################################################ +# Version + +def test_validate_version(create_tx): + import re + import bigchaindb.version + + short_ver = bigchaindb.version.__short_version__ + assert create_tx.version == re.match(r'^(.*\d)', short_ver).group(1) + + validate(create_tx) + + # At version 1, transaction version will break step with server version. + create_tx.version = '1.0.0' + validate_raises(create_tx) From 48a3ba96ae5b9dcd9feb4715615a0a36aebb112a Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 14 Mar 2017 16:18:08 +0100 Subject: [PATCH 04/33] move tx tests from test_models.py --- tests/{test_models.py => test_block_model.py} | 0 tests/validation/test_transaction_structure.py | 13 +++++++++++++ 2 files changed, 13 insertions(+) rename tests/{test_models.py => test_block_model.py} (100%) diff --git a/tests/test_models.py b/tests/test_block_model.py similarity index 100% rename from tests/test_models.py rename to tests/test_block_model.py diff --git a/tests/validation/test_transaction_structure.py b/tests/validation/test_transaction_structure.py index dfdeac01..461d408f 100644 --- a/tests/validation/test_transaction_structure.py +++ b/tests/validation/test_transaction_structure.py @@ -25,6 +25,14 @@ def validate_raises(tx): validate(tx) +################################################################################ +# Operation + +def test_validate_invalid_operation(create_tx): + create_tx.operation = 'something invalid' + validate_raises(create_tx) + + ################################################################################ # Metadata @@ -58,6 +66,11 @@ def test_create_tx_no_asset_id(create_tx): ################################################################################ # Inputs +def test_no_inputs(create_tx): + create_tx.inputs = [] + validate_raises(create_tx) + + def test_create_single_input(create_tx): tx = create_tx.to_dict() tx['inputs'] += tx['inputs'] From 4b060e64882ee57adcd141d12b2e862059121281 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 14 Mar 2017 18:07:25 +0100 Subject: [PATCH 05/33] move tests related to assets --- tests/assets/test_digital_assets.py | 26 ------ tests/assets/test_divisible_assets.py | 85 ------------------- .../validation/test_transaction_structure.py | 29 ++++++- 3 files changed, 25 insertions(+), 115 deletions(-) diff --git a/tests/assets/test_digital_assets.py b/tests/assets/test_digital_assets.py index c31ec3da..1e63dbec 100644 --- a/tests/assets/test_digital_assets.py +++ b/tests/assets/test_digital_assets.py @@ -1,4 +1,3 @@ -from bigchaindb.common.exceptions import ValidationError import pytest import random @@ -19,18 +18,6 @@ def test_asset_transfer(b, user_pk, user_sk): assert tx_transfer_signed.asset['id'] == tx_create.id -def test_validate_bad_asset_creation(b, user_pk): - from bigchaindb.models import Transaction - - # `data` needs to be a dictionary - tx = Transaction.create([b.me], [([user_pk], 1)]) - tx.asset['data'] = 'a' - tx_signed = tx.sign([b.me_private]) - - with pytest.raises(ValidationError): - Transaction.from_dict(tx_signed.to_dict()) - - @pytest.mark.bdb @pytest.mark.usefixtures('inputs') def test_validate_transfer_asset_id_mismatch(b, user_pk, user_sk): @@ -91,19 +78,6 @@ def test_asset_id_mismatch(b, user_pk): Transaction.get_asset_id([tx1, tx2]) -def test_create_invalid_divisible_asset(b, user_pk, user_sk): - from bigchaindb.models import Transaction - from bigchaindb.common.exceptions import ValidationError - - # Asset amount must be more than 0 - tx = Transaction.create([user_pk], [([user_pk], 1)]) - tx.outputs[0].amount = 0 - tx.sign([user_sk]) - - with pytest.raises(ValidationError): - Transaction.from_dict(tx.to_dict()) - - def test_create_valid_divisible_asset(b, user_pk, user_sk): from bigchaindb.models import Transaction diff --git a/tests/assets/test_divisible_assets.py b/tests/assets/test_divisible_assets.py index 87a29c2b..e1ea726f 100644 --- a/tests/assets/test_divisible_assets.py +++ b/tests/assets/test_divisible_assets.py @@ -635,88 +635,3 @@ def test_divide(b, user_pk, user_sk): assert len(tx_transfer_signed.outputs) == 3 for output in tx_transfer_signed.outputs: assert output.amount == 1 - - -# Check that negative inputs are caught when creating a TRANSFER transaction -@pytest.mark.skip(reason='part of tx structural tests') -@pytest.mark.bdb -@pytest.mark.usefixtures('inputs') -def test_non_positive_amounts_on_transfer(b, user_pk): - from bigchaindb.models import Transaction - from bigchaindb.common.exceptions import AmountError - - # CREATE divisible asset with 1 output with amount 3 - tx_create = Transaction.create([b.me], [([user_pk], 3)]) - tx_create_signed = tx_create.sign([b.me_private]) - # create block - block = b.create_block([tx_create_signed]) - assert block.validate(b) == block - b.write_block(block) - # vote - vote = b.vote(block.id, b.get_last_voted_block().id, True) - b.write_vote(vote) - - with pytest.raises(AmountError): - Transaction.transfer(tx_create.to_inputs(), - [([b.me], 4), ([b.me], -1)], - asset_id=tx_create.id) - - -# Check that negative inputs are caught when validating a TRANSFER transaction -@pytest.mark.skip(reason='part of tx structural tests') -@pytest.mark.bdb -@pytest.mark.usefixtures('inputs') -def test_non_positive_amounts_on_transfer_validate(b, user_pk, user_sk): - from bigchaindb.models import Transaction - from bigchaindb.common.exceptions import AmountError - - # CREATE divisible asset with 1 output with amount 3 - tx_create = Transaction.create([b.me], [([user_pk], 3)]) - tx_create_signed = tx_create.sign([b.me_private]) - # create block - block = b.create_block([tx_create_signed]) - assert block.validate(b) == block - b.write_block(block) - # vote - vote = b.vote(block.id, b.get_last_voted_block().id, True) - b.write_vote(vote) - - # create a transfer transaction with 3 outputs and check if the amount - # of each output is 1 - tx_transfer = Transaction.transfer(tx_create.to_inputs(), - [([b.me], 4), ([b.me], 1)], - asset_id=tx_create.id) - tx_transfer.outputs[1].amount = -1 - tx_transfer_signed = tx_transfer.sign([user_sk]) - - with pytest.raises(AmountError): - tx_transfer_signed.validate(b) - - -# Check that negative inputs are caught when creating a CREATE transaction -@pytest.mark.bdb -@pytest.mark.usefixtures('inputs') -def test_non_positive_amounts_on_create(b, user_pk): - from bigchaindb.models import Transaction - from bigchaindb.common.exceptions import AmountError - - # CREATE divisible asset with 1 output with amount 3 - with pytest.raises(AmountError): - Transaction.create([b.me], [([user_pk], -3)]) - - -# Check that negative inputs are caught when validating a CREATE transaction -@pytest.mark.skip(reason='part of tx structural tests') -@pytest.mark.bdb -@pytest.mark.usefixtures('inputs') -def test_non_positive_amounts_on_create_validate(b, user_pk): - from bigchaindb.models import Transaction - from bigchaindb.common.exceptions import AmountError - - # CREATE divisible asset with 1 output with amount 3 - tx_create = Transaction.create([b.me], [([user_pk], 3)]) - tx_create.outputs[0].amount = -3 - tx_create_signed = tx_create.sign([b.me_private]) - - with pytest.raises(AmountError): - tx_create_signed.validate(b) diff --git a/tests/validation/test_transaction_structure.py b/tests/validation/test_transaction_structure.py index 461d408f..cf7c43ca 100644 --- a/tests/validation/test_transaction_structure.py +++ b/tests/validation/test_transaction_structure.py @@ -5,9 +5,8 @@ structural / schematic issues are caught when reading a transaction """ import pytest -import re -from bigchaindb.common.exceptions import SchemaValidationError +from bigchaindb.common.exceptions import AmountError, SchemaValidationError from bigchaindb.models import Transaction @@ -20,11 +19,16 @@ def validate(tx): Transaction.from_dict(tx) -def validate_raises(tx): - with pytest.raises(SchemaValidationError): +def validate_raises(tx, exc=SchemaValidationError): + with pytest.raises(exc): validate(tx) +# We should test that validation works when we expect it to +def test_validation_passes(create_tx): + validate(create_tx) + + ################################################################################ # Operation @@ -63,6 +67,11 @@ def test_create_tx_no_asset_id(create_tx): validate_raises(create_tx) +def test_create_tx_asset_type(create_tx): + create_tx.asset['data'] = 'a' + validate_raises(create_tx) + + ################################################################################ # Inputs @@ -85,6 +94,18 @@ def test_create_tx_no_fulfills(create_tx): validate_raises(tx) +################################################################################ +# Outputs + + +def test_bad_amounts(create_tx, signed_transfer_tx): + for tx in [create_tx, signed_transfer_tx]: + tx.outputs[0].amount = 0 + validate_raises(tx, AmountError) + tx.outputs[0].amount = -1 + validate_raises(tx, AmountError) + + ################################################################################ # Version From 47c6a722ad4a2834a5d41c9e8e84f8abea31541d Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 14 Mar 2017 18:35:53 +0100 Subject: [PATCH 06/33] move tests to validate transaction ID --- tests/common/test_transaction.py | 27 ++++--------------- .../validation/test_transaction_structure.py | 24 ++++++++++++++++- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/tests/common/test_transaction.py b/tests/common/test_transaction.py index 153c0e6c..ec288de5 100644 --- a/tests/common/test_transaction.py +++ b/tests/common/test_transaction.py @@ -1,3 +1,8 @@ +""" +These are tests of the API of the Transaction class and associated classes. +Tests for transaction validation are separate. +""" + from pytest import raises @@ -341,28 +346,6 @@ def test_transaction_deserialization(user_input, user_output, data): validate_transaction_model(tx) -def test_tx_serialization_with_incorrect_hash(utx): - from bigchaindb.common.transaction import Transaction - from bigchaindb.common.exceptions import InvalidHash - - utx_dict = utx.to_dict() - utx_dict['id'] = 'a' * 64 - with raises(InvalidHash): - Transaction.from_dict(utx_dict) - utx_dict.pop('id') - - -def test_tx_serialization_hash_function(tx): - import sha3 - import json - tx_dict = tx.to_dict() - tx_dict['inputs'][0]['fulfillment'] = None - del tx_dict['id'] - payload = json.dumps(tx_dict, skipkeys=False, sort_keys=True, - separators=(',', ':')) - assert sha3.sha3_256(payload.encode()).hexdigest() == tx.id - - def test_invalid_input_initialization(user_input, user_pub): from bigchaindb.common.transaction import Input diff --git a/tests/validation/test_transaction_structure.py b/tests/validation/test_transaction_structure.py index cf7c43ca..6b64a559 100644 --- a/tests/validation/test_transaction_structure.py +++ b/tests/validation/test_transaction_structure.py @@ -6,7 +6,8 @@ structural / schematic issues are caught when reading a transaction import pytest -from bigchaindb.common.exceptions import AmountError, SchemaValidationError +from bigchaindb.common.exceptions import (AmountError, InvalidHash, + SchemaValidationError) from bigchaindb.models import Transaction @@ -29,6 +30,27 @@ def test_validation_passes(create_tx): validate(create_tx) +################################################################################ +# ID + + +def test_tx_serialization_hash_function(create_tx): + import sha3 + import json + tx = create_tx.to_dict() + tx['inputs'][0]['fulfillment'] = None + del tx['id'] + payload = json.dumps(tx, skipkeys=False, sort_keys=True, + separators=(',', ':')) + assert sha3.sha3_256(payload.encode()).hexdigest() == create_tx.id + + +def test_tx_serialization_with_incorrect_hash(create_tx): + tx = create_tx.to_dict() + tx['id'] = 'a' * 64 + validate_raises(tx, InvalidHash) + + ################################################################################ # Operation From 28e06399ae27fc824190af7dd22026199f18aa94 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 14 Mar 2017 18:40:04 +0100 Subject: [PATCH 07/33] fix breakage from other branch --- tests/common/test_schema.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/common/test_schema.py b/tests/common/test_schema.py index ef972f22..1db17170 100644 --- a/tests/common/test_schema.py +++ b/tests/common/test_schema.py @@ -7,7 +7,7 @@ from pytest import raises from bigchaindb.common.exceptions import SchemaValidationError from bigchaindb.common.schema import ( - TX_SCHEMA, VOTE_SCHEMA, drop_schema_descriptions, + TX_SCHEMA_COMMON, VOTE_SCHEMA, drop_schema_descriptions, validate_transaction_schema, validate_vote_schema) @@ -31,7 +31,7 @@ def _test_additionalproperties(node, path=''): def test_transaction_schema_additionalproperties(): - _test_additionalproperties(TX_SCHEMA) + _test_additionalproperties(TX_SCHEMA_COMMON) def test_vote_schema_additionalproperties(): From 56b81f9d8d684d782ea1b387a36d9e04ec79b1a9 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 14 Mar 2017 21:45:36 +0100 Subject: [PATCH 08/33] change amount type to string in schema file --- bigchaindb/common/schema/transaction.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bigchaindb/common/schema/transaction.yaml b/bigchaindb/common/schema/transaction.yaml index 86e5947b..ff52a366 100644 --- a/bigchaindb/common/schema/transaction.yaml +++ b/bigchaindb/common/schema/transaction.yaml @@ -132,7 +132,7 @@ definitions: - public_keys properties: amount: - type: integer + type: string description: | Integral amount of the asset represented by this output. In the case of a non divisible asset, this will always be 1. @@ -158,10 +158,6 @@ definitions: "$ref": "#/definitions/public_keys" description: | List of public keys associated with the conditions on an output. - amount: - type: integer - description: | - Integral amount of the asset represented by this condition. input: type: "object" description: From f23bfa52d161556d64560566fc157d46430c9e6f Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Wed, 15 Mar 2017 10:00:00 +0100 Subject: [PATCH 09/33] Output.from_dict accepts string --- bigchaindb/common/transaction.py | 8 ++++++-- tests/common/test_transaction.py | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bigchaindb/common/transaction.py b/bigchaindb/common/transaction.py index 23b8f169..00126cd9 100644 --- a/bigchaindb/common/transaction.py +++ b/bigchaindb/common/transaction.py @@ -264,7 +264,7 @@ class Output(object): output = { 'public_keys': self.public_keys, 'condition': condition, - 'amount': self.amount + 'amount': str(self.amount), } return output @@ -381,7 +381,11 @@ class Output(object): except KeyError: # NOTE: Hashlock condition case fulfillment = data['condition']['uri'] - return cls(fulfillment, data['public_keys'], data['amount']) + try: + amount = int(data['amount']) + except ValueError: + raise AmountError('Invalid amount: %s' % amount) + return cls(fulfillment, data['public_keys'], amount) class Transaction(object): diff --git a/tests/common/test_transaction.py b/tests/common/test_transaction.py index ec288de5..5a9ad766 100644 --- a/tests/common/test_transaction.py +++ b/tests/common/test_transaction.py @@ -83,7 +83,7 @@ def test_output_serialization(user_Ed25519, user_pub): 'details': user_Ed25519.to_dict(), }, 'public_keys': [user_pub], - 'amount': 1, + 'amount': '1', } cond = Output(user_Ed25519, [user_pub], 1) @@ -101,7 +101,7 @@ def test_output_deserialization(user_Ed25519, user_pub): 'details': user_Ed25519.to_dict() }, 'public_keys': [user_pub], - 'amount': 1, + 'amount': '1', } cond = Output.from_dict(cond) @@ -120,7 +120,7 @@ def test_output_hashlock_serialization(): 'uri': hashlock, }, 'public_keys': None, - 'amount': 1, + 'amount': '1', } cond = Output(hashlock, amount=1) @@ -140,7 +140,7 @@ def test_output_hashlock_deserialization(): 'uri': hashlock }, 'public_keys': None, - 'amount': 1, + 'amount': '1', } cond = Output.from_dict(cond) From 69bafc80c0598c7b7b51509547bcd4290540fdb4 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Wed, 15 Mar 2017 10:17:41 +0100 Subject: [PATCH 10/33] put limits on amount size --- bigchaindb/common/schema/transaction.yaml | 1 + bigchaindb/common/transaction.py | 2 ++ tests/validation/test_transaction_structure.py | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/bigchaindb/common/schema/transaction.yaml b/bigchaindb/common/schema/transaction.yaml index ff52a366..f63b652e 100644 --- a/bigchaindb/common/schema/transaction.yaml +++ b/bigchaindb/common/schema/transaction.yaml @@ -133,6 +133,7 @@ definitions: properties: amount: type: string + pattern: "^[0-9]{1,20}$" description: | Integral amount of the asset represented by this output. In the case of a non divisible asset, this will always be 1. diff --git a/bigchaindb/common/transaction.py b/bigchaindb/common/transaction.py index 00126cd9..746844e4 100644 --- a/bigchaindb/common/transaction.py +++ b/bigchaindb/common/transaction.py @@ -229,6 +229,8 @@ class Output(object): raise TypeError('`amount` must be an int') if amount < 1: raise AmountError('`amount` must be greater than 0') + if amount > 9 * 10 ** 18: + raise AmountError('`amount` must be <= 9000000000000000000') self.fulfillment = fulfillment self.amount = amount diff --git a/tests/validation/test_transaction_structure.py b/tests/validation/test_transaction_structure.py index 6b64a559..f6678b32 100644 --- a/tests/validation/test_transaction_structure.py +++ b/tests/validation/test_transaction_structure.py @@ -14,6 +14,7 @@ from bigchaindb.models import Transaction ################################################################################ # Helper functions + def validate(tx): if isinstance(tx, Transaction): tx = tx.to_dict() @@ -120,7 +121,7 @@ def test_create_tx_no_fulfills(create_tx): # Outputs -def test_bad_amounts(create_tx, signed_transfer_tx): +def test_low_amounts(create_tx, signed_transfer_tx): for tx in [create_tx, signed_transfer_tx]: tx.outputs[0].amount = 0 validate_raises(tx, AmountError) @@ -128,6 +129,19 @@ def test_bad_amounts(create_tx, signed_transfer_tx): validate_raises(tx, AmountError) +def test_high_amounts(create_tx): + # Should raise a SchemaValidationError - don't want to allow ridiculously + # large numbers to get converted to int + create_tx.outputs[0].amount = 10 ** 21 + validate_raises(create_tx) + # Should raise AmountError + create_tx.outputs[0].amount = 9 * 10 ** 18 + 1 + validate_raises(create_tx, AmountError) + # Should pass + create_tx.outputs[0].amount -= 1 + validate(create_tx) + + ################################################################################ # Version From 48a766400dcf630949ca42f1d833cbbde6cc28c1 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Wed, 15 Mar 2017 11:03:00 +0100 Subject: [PATCH 11/33] try to bump codecov into correct calculation --- tests/validation/test_transaction_structure.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/validation/test_transaction_structure.py b/tests/validation/test_transaction_structure.py index 6b64a559..63063f7f 100644 --- a/tests/validation/test_transaction_structure.py +++ b/tests/validation/test_transaction_structure.py @@ -119,7 +119,6 @@ def test_create_tx_no_fulfills(create_tx): ################################################################################ # Outputs - def test_bad_amounts(create_tx, signed_transfer_tx): for tx in [create_tx, signed_transfer_tx]: tx.outputs[0].amount = 0 From a869f6d1dd5778f11f1ca48483be29bafbc25214 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Wed, 15 Mar 2017 11:08:19 +0100 Subject: [PATCH 12/33] fix wrong exception after schema change --- tests/validation/test_transaction_structure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/validation/test_transaction_structure.py b/tests/validation/test_transaction_structure.py index f6678b32..9edfd367 100644 --- a/tests/validation/test_transaction_structure.py +++ b/tests/validation/test_transaction_structure.py @@ -126,7 +126,7 @@ def test_low_amounts(create_tx, signed_transfer_tx): tx.outputs[0].amount = 0 validate_raises(tx, AmountError) tx.outputs[0].amount = -1 - validate_raises(tx, AmountError) + validate_raises(tx) def test_high_amounts(create_tx): From 25650597b1c88ab622fc1189d4f98f3b3a9d4828 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Wed, 15 Mar 2017 11:27:35 +0100 Subject: [PATCH 13/33] test invalid string amount case --- bigchaindb/common/transaction.py | 2 +- tests/common/test_transaction.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bigchaindb/common/transaction.py b/bigchaindb/common/transaction.py index 746844e4..81b5614f 100644 --- a/bigchaindb/common/transaction.py +++ b/bigchaindb/common/transaction.py @@ -386,7 +386,7 @@ class Output(object): try: amount = int(data['amount']) except ValueError: - raise AmountError('Invalid amount: %s' % amount) + raise AmountError('Invalid amount: %s' % data['amount']) return cls(fulfillment, data['public_keys'], amount) diff --git a/tests/common/test_transaction.py b/tests/common/test_transaction.py index 5a9ad766..565a5bf8 100644 --- a/tests/common/test_transaction.py +++ b/tests/common/test_transaction.py @@ -930,3 +930,13 @@ def test_cant_add_empty_input(): with raises(TypeError): tx.add_input(None) + + +def test_output_from_dict_invalid_amount(user_output): + from bigchaindb.common.transaction import Output + from bigchaindb.common.exceptions import AmountError + + out = user_output.to_dict() + out['amount'] = 'a' + with raises(AmountError): + Output.from_dict(out) From d08d932627a5ec0b1915bf1508225b2244ca36ad Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Wed, 15 Mar 2017 13:37:56 +0100 Subject: [PATCH 14/33] make max output amount a constant --- bigchaindb/common/transaction.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bigchaindb/common/transaction.py b/bigchaindb/common/transaction.py index 81b5614f..8d415246 100644 --- a/bigchaindb/common/transaction.py +++ b/bigchaindb/common/transaction.py @@ -209,6 +209,8 @@ class Output(object): owners before a Transaction was confirmed. """ + MAX_AMOUNT = 9 * 10 ** 18 + def __init__(self, fulfillment, public_keys=None, amount=1): """Create an instance of a :class:`~.Output`. @@ -229,8 +231,8 @@ class Output(object): raise TypeError('`amount` must be an int') if amount < 1: raise AmountError('`amount` must be greater than 0') - if amount > 9 * 10 ** 18: - raise AmountError('`amount` must be <= 9000000000000000000') + if amount > self.MAX_AMOUNT: + raise AmountError('`amount` must be <= %s' % self.MAX_AMOUNT) self.fulfillment = fulfillment self.amount = amount From 860e7cda02614833a3fc7e7ed178fb2059de136d Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Wed, 15 Mar 2017 14:32:54 +0100 Subject: [PATCH 15/33] test that transaction with no hash raises schema validation error --- tests/validation/test_transaction_structure.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/validation/test_transaction_structure.py b/tests/validation/test_transaction_structure.py index 63063f7f..df79f594 100644 --- a/tests/validation/test_transaction_structure.py +++ b/tests/validation/test_transaction_structure.py @@ -51,6 +51,12 @@ def test_tx_serialization_with_incorrect_hash(create_tx): validate_raises(tx, InvalidHash) +def test_tx_serialization_with_no_hash(create_tx): + tx = create_tx.to_dict() + del tx['id'] + validate_raises(tx) + + ################################################################################ # Operation From bbf5c49f9aa9ff8983989467a98388c3f30973e4 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Wed, 15 Mar 2017 17:19:46 +0100 Subject: [PATCH 16/33] test that transfer tx cannot have no inputs --- tests/validation/test_transaction_structure.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/validation/test_transaction_structure.py b/tests/validation/test_transaction_structure.py index df79f594..7f813afc 100644 --- a/tests/validation/test_transaction_structure.py +++ b/tests/validation/test_transaction_structure.py @@ -122,6 +122,11 @@ def test_create_tx_no_fulfills(create_tx): validate_raises(tx) +def test_transfer_has_inputs(signed_transfer_tx): + signed_transfer_tx.inputs = [] + validate_raises(signed_transfer_tx) + + ################################################################################ # Outputs From 03ca4b1fd3beddd7b810ed0078e2ca0628db1a2b Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Fri, 17 Mar 2017 15:34:17 +0100 Subject: [PATCH 17/33] make stepping pipeline queue items mutable --- tests/pipelines/stepping.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pipelines/stepping.py b/tests/pipelines/stepping.py index 030863c6..1a9d3a69 100644 --- a/tests/pipelines/stepping.py +++ b/tests/pipelines/stepping.py @@ -106,7 +106,7 @@ class MultipipesStepper: for item in items: if type(item) != tuple: item = (item,) - queue.append(item) + queue.append(list(item)) def step(self, name, **kwargs): """ Advance pipeline stage. Throws Empty if no data to consume. """ From d8b84891b65cfce024c4f2f6fa98ffb9f8d1f04b Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 21 Mar 2017 16:23:56 +0100 Subject: [PATCH 18/33] federation tests --- tests/integration/test_federation.py | 215 +++++++++++++++++++++++++++ tests/pipelines/stepping.py | 2 + 2 files changed, 217 insertions(+) create mode 100644 tests/integration/test_federation.py diff --git a/tests/integration/test_federation.py b/tests/integration/test_federation.py new file mode 100644 index 00000000..c18c65de --- /dev/null +++ b/tests/integration/test_federation.py @@ -0,0 +1,215 @@ +from copy import deepcopy +import pytest +import random + +import bigchaindb +from bigchaindb.core import Bigchain +from contextlib import contextmanager +from bigchaindb.common.crypto import generate_key_pair +from tests.pipelines.stepping import create_stepper + + +################################################################################ +# Test setup code + + +@contextmanager +def federation(n): + """ + Return a list of Bigchain objects and pipeline steppers to represent + a BigchainDB federation + """ + keys = [generate_key_pair() for _ in range(n)] + config_orig = bigchaindb.config + + @contextmanager + def make_nodes(i): + nonlocal keys + if i == 0: + yield [] + else: + config = deepcopy(config_orig) + keys = [keys[-1]] + keys[:-1] + config['keypair']['private'] = keys[0][0] + config['keypair']['public'] = keys[0][1] + config['keyring'] = list(list(zip(*keys[1:]))[1]) + bigchaindb.config = config + stepper = create_stepper() + with stepper.start(): + node = (Bigchain(), stepper) + with make_nodes(i-1) as rest: + yield [node] + rest + + with make_nodes(n) as steppers: + bigchaindb.config = config_orig + yield zip(*steppers) + + +@pytest.fixture +def federation_3(): + with federation(3) as f: + yield f + + +def process_tx(steps): + steps.block_changefeed(timeout=1) + if steps.block_filter_tx(): + steps.block_validate_tx() + steps.block_create(timeout=True) + steps.block_write() + steps.block_delete_tx() + + +def input_single_create(b): + from bigchaindb.common.transaction import Transaction + metadata = {'r': random.random()} + tx = Transaction.create([b.me], [([b.me], 1)], metadata).sign([b.me_private]) + b.write_transaction(tx) + return tx + + +def process_vote(steps, result=None): + steps.vote_changefeed() + steps.vote_validate_block() + steps.vote_ungroup() + steps.vote_validate_tx() + if result is not None: + steps.queues['vote_vote'][0][0] = result + vote = steps.vote_vote() + steps.vote_write_vote() + return vote + + +################################################################################ +# Tests here on down + + +@pytest.mark.bdb +@pytest.mark.genesis +def test_elect_valid(federation_3): + [bx, (s0, s1, s2)] = federation_3 + tx = input_single_create(bx[0]) + process_tx(s0) + process_tx(s1) + process_tx(s2) + process_vote(s2, False) + for i in range(3): + assert bx[i].get_transaction(tx.id, True)[1] == 'undecided' + process_vote(s0, True) + for i in range(3): + assert bx[i].get_transaction(tx.id, True)[1] == 'undecided' + process_vote(s1, True) + for i in range(3): + assert bx[i].get_transaction(tx.id, True)[1] == 'valid' + + +@pytest.mark.bdb +@pytest.mark.genesis +def test_elect_invalid(federation_3): + [bx, (s0, s1, s2)] = federation_3 + tx = input_single_create(bx[0]) + process_tx(s0) + process_tx(s1) + process_tx(s2) + process_vote(s1, True) + for i in range(3): + assert bx[i].get_transaction(tx.id, True)[1] == 'undecided' + process_vote(s2, False) + for i in range(3): + assert bx[i].get_transaction(tx.id, True)[1] == 'undecided' + process_vote(s0, False) + for i in range(3): + assert bx[i].get_transaction(tx.id, True)[1] is None + + +@pytest.mark.bdb +@pytest.mark.genesis +def test_elect_disagree_prev_block(federation_3): + [bx, (s0, s1, s2)] = federation_3 + tx = input_single_create(bx[0]) + process_tx(s0) + process_tx(s1) + process_tx(s2) + process_vote(s0, True) + for i in range(3): + assert bx[i].get_transaction(tx.id, True)[1] == 'undecided' + s1.vote.last_voted_id = '5' * 64 + process_vote(s1, True) + for i in range(3): + assert bx[i].get_transaction(tx.id, True)[1] == 'undecided' + s2.vote.last_voted_id = '6' * 64 + process_vote(s2, True) + for i in range(3): + assert bx[i].get_transaction(tx.id, True)[1] is None + + +@pytest.mark.skip() # TODO: wait for #1309 +@pytest.mark.bdb +@pytest.mark.genesis +def test_elect_dupe_vote(federation_3): + from bigchaindb.exceptions import CriticalDuplicateVote + [bx, (s0, s1, s2)] = federation_3 + tx = input_single_create(bx[0]) + process_tx(s0) + process_tx(s1) + process_tx(s2) + vote = process_vote(s0, True) + # Drop the unique index and write the vote again + bx[0].connection.db.votes.drop_index('block_and_voter') + s0.queues['vote_write_vote'].append([vote]) + s0.vote_write_vote() + for i in range(3): + with pytest.raises(CriticalDuplicateVote): + bx[i].get_transaction(tx.id, True)[1] + + +@pytest.mark.bdb +@pytest.mark.genesis +def test_elect_sybill(federation_3): + [bx, (s0, s1, s2)] = federation_3 + tx = input_single_create(bx[0]) + process_tx(s0) + process_tx(s1) + process_tx(s2) + # What we need is some votes from unknown nodes! + for s in [s0, s1, s2]: + s.vote.bigchain.me_private = generate_key_pair()[0] + process_vote(s0, True) + process_vote(s1, True) + process_vote(s2, True) + for i in range(3): + assert bx[i].get_transaction(tx.id, True)[1] == 'undecided' + + +@pytest.mark.skip() +@pytest.mark.bdb +@pytest.mark.genesis +def test_elect_dos(federation_3): + """ + https://github.com/bigchaindb/bigchaindb/issues/1314 + Test that a node cannot block another node's opportunity to vote + on a block by writing an incorrectly signed vote + """ + raise NotImplementedError() + + +@pytest.mark.skip('Revisit when we have block election status cache') +@pytest.mark.bdb +@pytest.mark.genesis +def test_elect_bad_block_voters_list(federation_3): + """ + See https://github.com/bigchaindb/bigchaindb/issues/1224 + """ + [bx, (s0, s1, s2)] = federation_3 + b = s0.block.bigchain + # First remove other nodes from node 0 so that it self assigns the tx + b.nodes_except_me = [] + tx = input_single_create(b) + # Now create a block voters list which will not match other keyrings + b.nodes_except_me = [bx[1].me] + process_tx(s0) + process_vote(s0) + process_vote(s1) + process_vote(s2) + for i in range(3): + assert bx[i].get_transaction(tx.id, True)[1] == 'invalid' diff --git a/tests/pipelines/stepping.py b/tests/pipelines/stepping.py index 1a9d3a69..36f68a6a 100644 --- a/tests/pipelines/stepping.py +++ b/tests/pipelines/stepping.py @@ -163,6 +163,8 @@ def _update_stepper(stepper, prefix, pipeline): n1 = (nodes + [None])[i+1] f = stepper.add_input if i == 0 else stepper.add_stage f(prefix, n0, n1) + # Expose pipeline state + setattr(stepper, prefix, nodes[-1].target.__self__) def create_stepper(): From de445bb977a583c79f7c5a723e0ab6c86a82ae58 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Wed, 12 Apr 2017 11:58:43 +0200 Subject: [PATCH 19/33] simplifications and clarifications for review of federation tests --- tests/integration/test_federation.py | 36 +++++++++++----------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/tests/integration/test_federation.py b/tests/integration/test_federation.py index c18c65de..00c59685 100644 --- a/tests/integration/test_federation.py +++ b/tests/integration/test_federation.py @@ -24,15 +24,26 @@ def federation(n): @contextmanager def make_nodes(i): + """ + make_nodes is a recursive context manager. Essentially it is doing: + + with f(a[0]) as b0: + with f(a[1]) as b1: + with f(a[2]) as b2: + yield [b0, b1, b2] + + with an arbitrary depth. It is also temporarily patching global + configuration to simulate nodes with separate identities. + """ nonlocal keys if i == 0: yield [] else: config = deepcopy(config_orig) - keys = [keys[-1]] + keys[:-1] + keys = [keys[-1]] + keys[:-1] # Rotate keys + config['keyring'] = [pub for _, pub in keys[1:]] config['keypair']['private'] = keys[0][0] config['keypair']['public'] = keys[0][1] - config['keyring'] = list(list(zip(*keys[1:]))[1]) bigchaindb.config = config stepper = create_stepper() with stepper.start(): @@ -143,26 +154,6 @@ def test_elect_disagree_prev_block(federation_3): assert bx[i].get_transaction(tx.id, True)[1] is None -@pytest.mark.skip() # TODO: wait for #1309 -@pytest.mark.bdb -@pytest.mark.genesis -def test_elect_dupe_vote(federation_3): - from bigchaindb.exceptions import CriticalDuplicateVote - [bx, (s0, s1, s2)] = federation_3 - tx = input_single_create(bx[0]) - process_tx(s0) - process_tx(s1) - process_tx(s2) - vote = process_vote(s0, True) - # Drop the unique index and write the vote again - bx[0].connection.db.votes.drop_index('block_and_voter') - s0.queues['vote_write_vote'].append([vote]) - s0.vote_write_vote() - for i in range(3): - with pytest.raises(CriticalDuplicateVote): - bx[i].get_transaction(tx.id, True)[1] - - @pytest.mark.bdb @pytest.mark.genesis def test_elect_sybill(federation_3): @@ -172,6 +163,7 @@ def test_elect_sybill(federation_3): process_tx(s1) process_tx(s2) # What we need is some votes from unknown nodes! + # Incorrectly signed votes are ineligible. for s in [s0, s1, s2]: s.vote.bigchain.me_private = generate_key_pair()[0] process_vote(s0, True) From 3bf1f9fa176caae457486f46acdee64e353f4e80 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Wed, 12 Apr 2017 12:16:42 +0200 Subject: [PATCH 20/33] add additional test of negative amount to fix codecov --- tests/common/test_transaction.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/common/test_transaction.py b/tests/common/test_transaction.py index cdb270cf..4b72164c 100644 --- a/tests/common/test_transaction.py +++ b/tests/common/test_transaction.py @@ -237,6 +237,7 @@ def test_generate_output_single_owner_with_output(user_pub): def test_generate_output_invalid_parameters(user_pub, user2_pub, user3_pub): from bigchaindb.common.transaction import Output + from bigchaindb.common.exceptions import AmountError with raises(ValueError): Output.generate([], 1) @@ -246,6 +247,8 @@ def test_generate_output_invalid_parameters(user_pub, user2_pub, user3_pub): Output.generate([[user_pub, [user2_pub, [user3_pub]]]], 1) with raises(ValueError): Output.generate([[user_pub]], 1) + with raises(AmountError): + Output.generate([[user_pub]], -1) def test_invalid_transaction_initialization(asset_definition): From 6f8f2e2f93dc4f8a3ec7ca3173ad6dcd77fa376d Mon Sep 17 00:00:00 2001 From: Leo Arias Date: Thu, 20 Apr 2017 03:25:30 +0000 Subject: [PATCH 21/33] Add the packaging metadata to build the bigchaindb snap --- snap/snapcraft.yaml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 snap/snapcraft.yaml diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 00000000..aa3a9bca --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,23 @@ +name: bigchaindb +version: master +summary: a scalable blockchain database +description: | + With high throughput, sub-second latency and powerful functionality to + automate business processes, BigchainDB looks, acts and feels like a database + with added blockchain characteristics. + +# grade must be 'stable' to release into candidate/stable channels +grade: devel +# strict confinement requires https://github.com/snapcore/snapd/pull/2749 +confinement: devmode + +apps: + bigchaindb: + command: bigchaindb + plugs: [network, network-bind] + +parts: + bigchaindb: + source: . + plugin: python + build-packages: [g++, libffi-dev] From 3a3f73aeb271d2ed3c8f08489a5e839376ef67eb Mon Sep 17 00:00:00 2001 From: Leo Arias Date: Sat, 22 Apr 2017 19:19:46 +0000 Subject: [PATCH 22/33] Add the snap README --- snap/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 snap/README.md diff --git a/snap/README.md b/snap/README.md new file mode 100644 index 00000000..14bfdbce --- /dev/null +++ b/snap/README.md @@ -0,0 +1,12 @@ +This is the packaging metadata for the BigchainDB snap. + +Snaps and the snap store allows for the secure installation of apps that work +in most Linux distributions. For more information, go to https://snapcraft.io/ + +To build and install this snap in Ubuntu 16.04: + + $ sudo apt install git snapcraft + $ git clone https://github.com/bigchaindb/bigchaindb + $ cd bigchaindb + $ snapcraft + $ sudo snap install *.snap --dangerous --devmode From 96feb1860466e3288d94e54e644b95752a8bf8c5 Mon Sep 17 00:00:00 2001 From: Troy McConaghy Date: Mon, 24 Apr 2017 15:56:36 +0200 Subject: [PATCH 23/33] Changed from Alpha to Beta in setup.py I changed the classifier `'Development Status :: 3 - Alpha'` to `'Development Status :: 4 - Beta'` as per the list of classifiers here: https://pypi.python.org/pypi?%3Aaction=list_classifiers This is in preparation for the version 1.0 release but I think it's probably fine to have it in master now. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 45d6f04f..179b561f 100644 --- a/setup.py +++ b/setup.py @@ -101,7 +101,7 @@ setup( zip_safe=False, classifiers=[ - 'Development Status :: 3 - Alpha', + 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'Topic :: Database', 'Topic :: Database :: Database Engines/Servers', From 920d4aa181b7354554b8b91b4458876d5ddd740b Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Fri, 21 Apr 2017 18:13:20 +0200 Subject: [PATCH 24/33] Add log analytics oms deployment scripts --- k8s/log_analytics_oms.json | 49 +++++++++++++++++++++++++++ k8s/log_analytics_oms.parameters.json | 15 ++++++++ k8s/oms-daemonset.yaml | 30 ++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 k8s/log_analytics_oms.json create mode 100644 k8s/log_analytics_oms.parameters.json create mode 100644 k8s/oms-daemonset.yaml diff --git a/k8s/log_analytics_oms.json b/k8s/log_analytics_oms.json new file mode 100644 index 00000000..caca7fab --- /dev/null +++ b/k8s/log_analytics_oms.json @@ -0,0 +1,49 @@ +{ + "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "sku": { + "type": "String" + }, + "workspaceName": { + "type": "String" + }, + "solutionType": { + "type": "String" + }, + }, + "resources": [ + { + "apiVersion": "2015-03-20", + "type": "Microsoft.OperationalInsights/workspaces", + "name": "[parameters('workspaceName')]", + "location": "[resourceGroup().location]", + "properties": { + "sku": { + "name": "[parameters('sku')]" + } + }, + "resources": [ + { + "apiVersion": "2015-11-01-preview", + "location": "[resourceGroup().location]", + "name": "[Concat(parameters('solutionType'), '(', parameters('workspaceName'), ')')]", + "type": "Microsoft.OperationsManagement/solutions", + "id": "[Concat(resourceGroup().id, '/providers/Microsoft.OperationsManagement/solutions/', parameters('solutionType'), '(', parameters('workspaceName'), ')')]", + "dependsOn": [ + "[concat('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'))]" + ], + "properties": { + "workspaceResourceId": "[resourceId('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'))]" + }, + "plan": { + "publisher": "Microsoft", + "product": "[Concat('OMSGallery/', parameters('solutionType'))]", + "name": "[Concat(parameters('solutionType'), '(', parameters('workspaceName'), ')')]", + "promotionCode": "" + } + } + ] + } + ] +} diff --git a/k8s/log_analytics_oms.parameters.json b/k8s/log_analytics_oms.parameters.json new file mode 100644 index 00000000..c5d215e4 --- /dev/null +++ b/k8s/log_analytics_oms.parameters.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "sku": { + "value": "Free" + }, + "workspaceName": { + "value": "rg-abc-logs" + }, + "solutionType": { + "value": "Containers" + }, + } +} diff --git a/k8s/oms-daemonset.yaml b/k8s/oms-daemonset.yaml new file mode 100644 index 00000000..99cf14fe --- /dev/null +++ b/k8s/oms-daemonset.yaml @@ -0,0 +1,30 @@ +apiVersion: extensions/v1beta1 +kind: DaemonSet +metadata: + name: omsagent +spec: + template: + metadata: + labels: + app: omsagent + spec: + containers: + - env: + - name: WSID + value: + - name: KEY + value: + image: microsoft/oms + name: omsagent + ports: + - containerPort: 25225 + protocol: TCP + securityContext: + privileged: true + volumeMounts: + - mountPath: /var/run/docker.sock + name: docker-sock + volumes: + - name: docker-sock + hostPath: + path: /var/run/docker.sock From e954668eaa3cb2d52cad5ab3ef6cb598c9e1ff61 Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Fri, 21 Apr 2017 18:19:24 +0200 Subject: [PATCH 25/33] Add docs --- .../cloud-deployment-templates/index.rst | 1 + .../log-analytics.rst | 238 ++++++++++++++++++ 2 files changed, 239 insertions(+) create mode 100644 docs/server/source/cloud-deployment-templates/log-analytics.rst diff --git a/docs/server/source/cloud-deployment-templates/index.rst b/docs/server/source/cloud-deployment-templates/index.rst index d5b60a0e..41eec0ed 100644 --- a/docs/server/source/cloud-deployment-templates/index.rst +++ b/docs/server/source/cloud-deployment-templates/index.rst @@ -18,3 +18,4 @@ If you find the cloud deployment templates for nodes helpful, then you may also add-node-on-kubernetes upgrade-on-kubernetes first-node + log-analytics diff --git a/docs/server/source/cloud-deployment-templates/log-analytics.rst b/docs/server/source/cloud-deployment-templates/log-analytics.rst new file mode 100644 index 00000000..05587689 --- /dev/null +++ b/docs/server/source/cloud-deployment-templates/log-analytics.rst @@ -0,0 +1,238 @@ +Log Analytics on Azure +====================== + +This section documents how to create and configure a Log Analytics workspace on +Azure, for a Kubernetes-based deployment. + +The documented approach is based on an integration of Microsoft's Operations +Management Suite (OMS) with a Kubernetes-based Azure Container Service cluster. + +The :ref:`oms-k8s-references` contains links to more detailed documentation on +Azure, and Kubernetes. + +There are three main steps involved: + +1. Create a workspace (``LogAnalyticsOMS``). +2. Create a ``ContainersOMS`` solution under the workspace. +3. Deploy the OMS agent(s). + +Steps 1 and 2 rely on `Azure Resource Manager templates`_ and can be done with +one template so we'll cover them together. Step 3 relies on a +`Kubernetes DaemonSet`_ and will be covered separately. + +Minimum Requirements +-------------------- +This document assumes that you have already deployed a Kubernetes cluster, and +that you have the Kubernetes command line ``kubectl`` installed. + +Creating a workspace and adding a containers solution +----------------------------------------------------- + +.. code-block:: bash + + $ az group deployment create --debug \ + --resource-group rg \ + --name "Microsoft.LogAnalyticsOMS" \ + --template-file log_analytics_oms.json \ + --parameters @log_analytics_oms.parameters.json + +An example of a simple tenplate file (``--template-file``): + +.. code-block:: json + + { + "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "sku": { + "type": "String" + }, + "workspaceName": { + "type": "String" + }, + "solutionType": { + "type": "String" + }, + }, + "resources": [ + { + "apiVersion": "2015-03-20", + "type": "Microsoft.OperationalInsights/workspaces", + "name": "[parameters('workspaceName')]", + "location": "[resourceGroup().location]", + "properties": { + "sku": { + "name": "[parameters('sku')]" + } + }, + "resources": [ + { + "apiVersion": "2015-11-01-preview", + "location": "[resourceGroup().location]", + "name": "[Concat(parameters('solutionType'), '(', parameters('workspaceName'), ')')]", + "type": "Microsoft.OperationsManagement/solutions", + "id": "[Concat(resourceGroup().id, '/providers/Microsoft.OperationsManagement/solutions/', parameters('solutionType'), '(', parameters('workspaceName'), ')')]", + "dependsOn": [ + "[concat('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'))]" + ], + "properties": { + "workspaceResourceId": "[resourceId('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'))]" + }, + "plan": { + "publisher": "Microsoft", + "product": "[Concat('OMSGallery/', parameters('solutionType'))]", + "name": "[Concat(parameters('solutionType'), '(', parameters('workspaceName'), ')')]", + "promotionCode": "" + } + } + ] + } + ] + } + +An example of the associated parameter file (``--parameters``): + +.. code-block:: json + + { + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "sku": { + "value": "Free" + }, + "workspaceName": { + "value": "rg-abc-logs" + }, + "solutionType": { + "value": "Containers" + }, + } + } + +Deploying the OMS agent(s) +-------------------------- +In order to deploy an OMS agent two important pieces of information are needed: + +* workspace id +* workspace key + +Obtaining the workspace id: + +.. code-block:: bash + + $ az resource show + --resource-group rg + --resource-type Microsoft.OperationalInsights/workspaces + --name rg-abc-logs \ + | grep customerId + "customerId": "12345678-1234-1234-1234-123456789012", + +Obtaining the workspace key: + + +.. code-block:: yaml + + # oms-daemonset.yaml + apiVersion: extensions/v1beta1 + kind: DaemonSet + metadata: + name: omsagent + spec: + template: + metadata: + labels: + app: omsagent + spec: + containers: + - env: + - name: WSID + value: + - name: KEY + value: + image: microsoft/oms + name: omsagent + ports: + - containerPort: 25225 + protocol: TCP + securityContext: + privileged: true + volumeMounts: + - mountPath: /var/run/docker.sock + name: docker-sock + volumes: + - name: docker-sock + hostPath: + path: /var/run/docker.sock + + +.. code-block:: bash + + $ kubectl create -f oms-daemonset.yaml + + +Some useful management tasks +---------------------------- +List workspaces: + +.. code-block:: bash + + $ az resource list \ + --resource-group rg \ + --resource-type Microsoft.OperationalInsights/workspaces + +List solutions: + +.. code-block:: bash + + $ az resource list \ + --resource-group rg \ + --resource-type Microsoft.OperationsManagement/solutions + +Deleting the containers solution: + +.. code-block:: bash + + $ az group deployment delete --debug \ + --resource-group rg \ + --name Microsoft.ContainersOMS + +.. code-block:: bash + + $ az resource delete \ + --resource-group rg \ + --resource-type Microsoft.OperationsManagement/solutions \ + --name "Containers(rglogs)" + +Deleting the workspace: + +.. code-block:: bash + + $ az group deployment delete --debug \ + --resource-group rg \ + --name Microsoft.LogAnalyticsOMS + +.. code-block:: bash + + $ az resource delete \ + --resource-group rg \ + --resource-type Microsoft.OperationalInsights/workspaces \ + --name rglogs + + +.. _oms-k8s-references: + +References +---------- + +* `Monitor an Azure Container Service cluster with Microsoft Operations Management Suite (OMS) `_ +* `Manage Log Analytics using Azure Resource Manager templates `_ +* `azure commands for deployments `_ + (``az group deployment``) +* `Understand the structure and syntax of Azure Resource Manager templates `_ +* `Kubernetes DaemonSet`_ + + + +.. _Azure Resource Manager templates: https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-authoring-templates +.. _Kubernetes DaemonSet: https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/ From 43ac369e4529bd8f0a20d282bd1080760735a8bf Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Mon, 24 Apr 2017 16:25:58 +0200 Subject: [PATCH 26/33] Move oms related files under dedicated dir --- k8s/{ => logging-and-monitoring}/log_analytics_oms.json | 0 .../log_analytics_oms.parameters.json | 0 k8s/{ => logging-and-monitoring}/oms-daemonset.yaml | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename k8s/{ => logging-and-monitoring}/log_analytics_oms.json (100%) rename k8s/{ => logging-and-monitoring}/log_analytics_oms.parameters.json (100%) rename k8s/{ => logging-and-monitoring}/oms-daemonset.yaml (100%) diff --git a/k8s/log_analytics_oms.json b/k8s/logging-and-monitoring/log_analytics_oms.json similarity index 100% rename from k8s/log_analytics_oms.json rename to k8s/logging-and-monitoring/log_analytics_oms.json diff --git a/k8s/log_analytics_oms.parameters.json b/k8s/logging-and-monitoring/log_analytics_oms.parameters.json similarity index 100% rename from k8s/log_analytics_oms.parameters.json rename to k8s/logging-and-monitoring/log_analytics_oms.parameters.json diff --git a/k8s/oms-daemonset.yaml b/k8s/logging-and-monitoring/oms-daemonset.yaml similarity index 100% rename from k8s/oms-daemonset.yaml rename to k8s/logging-and-monitoring/oms-daemonset.yaml From 22f0e25c9aa81376cb4f06f0365f9c85a802637a Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Mon, 24 Apr 2017 16:30:20 +0200 Subject: [PATCH 27/33] Correct JSON --- k8s/logging-and-monitoring/log_analytics_oms.json | 2 +- k8s/logging-and-monitoring/log_analytics_oms.parameters.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/k8s/logging-and-monitoring/log_analytics_oms.json b/k8s/logging-and-monitoring/log_analytics_oms.json index caca7fab..44b9d05a 100644 --- a/k8s/logging-and-monitoring/log_analytics_oms.json +++ b/k8s/logging-and-monitoring/log_analytics_oms.json @@ -10,7 +10,7 @@ }, "solutionType": { "type": "String" - }, + } }, "resources": [ { diff --git a/k8s/logging-and-monitoring/log_analytics_oms.parameters.json b/k8s/logging-and-monitoring/log_analytics_oms.parameters.json index c5d215e4..895cbb15 100644 --- a/k8s/logging-and-monitoring/log_analytics_oms.parameters.json +++ b/k8s/logging-and-monitoring/log_analytics_oms.parameters.json @@ -10,6 +10,6 @@ }, "solutionType": { "value": "Containers" - }, + } } } From 7659290518e42449cf4bdd7e887f835847993956 Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Mon, 24 Apr 2017 16:31:47 +0200 Subject: [PATCH 28/33] Add missing backslash (\) --- docs/server/source/cloud-deployment-templates/log-analytics.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/server/source/cloud-deployment-templates/log-analytics.rst b/docs/server/source/cloud-deployment-templates/log-analytics.rst index 05587689..4705c6f7 100644 --- a/docs/server/source/cloud-deployment-templates/log-analytics.rst +++ b/docs/server/source/cloud-deployment-templates/log-analytics.rst @@ -121,7 +121,7 @@ Obtaining the workspace id: .. code-block:: bash - $ az resource show + $ az resource show \ --resource-group rg --resource-type Microsoft.OperationalInsights/workspaces --name rg-abc-logs \ From 8900276b1d959179a9dfd41c4a4825d1fa21a27c Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Mon, 24 Apr 2017 17:22:12 +0200 Subject: [PATCH 29/33] Mount k8s dir for docker-compose --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 322cbcf6..c7f3c584 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -37,6 +37,7 @@ services: - ./bigchaindb:/usr/src/app/bigchaindb - ./tests:/usr/src/app/tests - ./docs:/usr/src/app/docs + - ./k8s:/usr/src/app/k8s - ./setup.py:/usr/src/app/setup.py - ./setup.cfg:/usr/src/app/setup.cfg - ./pytest.ini:/usr/src/app/pytest.ini @@ -58,6 +59,7 @@ services: - ./bigchaindb:/usr/src/app/bigchaindb - ./tests:/usr/src/app/tests - ./docs:/usr/src/app/docs + - ./k8s:/usr/src/app/k8s - ./setup.py:/usr/src/app/setup.py - ./setup.cfg:/usr/src/app/setup.cfg - ./pytest.ini:/usr/src/app/pytest.ini From 8f750456d89bd63f691b1d1122f59104ddd30abf Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Mon, 24 Apr 2017 17:22:49 +0200 Subject: [PATCH 30/33] Address remaining details --- .../log-analytics.rst | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/docs/server/source/cloud-deployment-templates/log-analytics.rst b/docs/server/source/cloud-deployment-templates/log-analytics.rst index 4705c6f7..fbef70d2 100644 --- a/docs/server/source/cloud-deployment-templates/log-analytics.rst +++ b/docs/server/source/cloud-deployment-templates/log-analytics.rst @@ -27,11 +27,21 @@ that you have the Kubernetes command line ``kubectl`` installed. Creating a workspace and adding a containers solution ----------------------------------------------------- +For the sake of this document and example, we'll assume an existing resource +group named: + +* ``resource_group`` + +and the workspace we'll create will be named: + +* ``work_space`` + +If you feel creative you may replace these names by more interesting ones. .. code-block:: bash $ az group deployment create --debug \ - --resource-group rg \ + --resource-group resource_group \ --name "Microsoft.LogAnalyticsOMS" \ --template-file log_analytics_oms.json \ --parameters @log_analytics_oms.parameters.json @@ -102,7 +112,7 @@ An example of the associated parameter file (``--parameters``): "value": "Free" }, "workspaceName": { - "value": "rg-abc-logs" + "value": "work_space" }, "solutionType": { "value": "Containers" @@ -122,14 +132,21 @@ Obtaining the workspace id: .. code-block:: bash $ az resource show \ - --resource-group rg + --resource-group resource_group --resource-type Microsoft.OperationalInsights/workspaces - --name rg-abc-logs \ + --name work_space \ | grep customerId "customerId": "12345678-1234-1234-1234-123456789012", Obtaining the workspace key: +Until we figure out a way to this via the command line please see instructions +under `Obtain your workspace ID and key +`_. + +Once you have the workspace id and key you can include them in the following +YAML file (:download:`oms-daemonset.yaml +<../../../../k8s/logging-and-monitoring/oms-daemonset.yaml>`): .. code-block:: yaml @@ -165,6 +182,7 @@ Obtaining the workspace key: hostPath: path: /var/run/docker.sock +To deploy the agent simply run the following command: .. code-block:: bash @@ -178,7 +196,7 @@ List workspaces: .. code-block:: bash $ az resource list \ - --resource-group rg \ + --resource-group resource_group \ --resource-type Microsoft.OperationalInsights/workspaces List solutions: @@ -186,7 +204,7 @@ List solutions: .. code-block:: bash $ az resource list \ - --resource-group rg \ + --resource-group resource_group \ --resource-type Microsoft.OperationsManagement/solutions Deleting the containers solution: @@ -194,30 +212,30 @@ Deleting the containers solution: .. code-block:: bash $ az group deployment delete --debug \ - --resource-group rg \ + --resource-group resource_group \ --name Microsoft.ContainersOMS .. code-block:: bash $ az resource delete \ - --resource-group rg \ + --resource-group resource_group \ --resource-type Microsoft.OperationsManagement/solutions \ - --name "Containers(rglogs)" + --name "Containers(work_space)" Deleting the workspace: .. code-block:: bash $ az group deployment delete --debug \ - --resource-group rg \ + --resource-group resource_group \ --name Microsoft.LogAnalyticsOMS .. code-block:: bash $ az resource delete \ - --resource-group rg \ + --resource-group resource_group \ --resource-type Microsoft.OperationalInsights/workspaces \ - --name rglogs + --name work_space .. _oms-k8s-references: From ae9d6f1e6e71a74a3f1a81a82d675d9f93b9e8f8 Mon Sep 17 00:00:00 2001 From: Troy McConaghy Date: Wed, 26 Apr 2017 10:11:45 +0200 Subject: [PATCH 31/33] Updated Drivers & Clients docs page, including Ruby driver --- docs/server/source/drivers-clients/index.rst | 30 +++++++++----------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/docs/server/source/drivers-clients/index.rst b/docs/server/source/drivers-clients/index.rst index 127d6309..0bfde7ad 100644 --- a/docs/server/source/drivers-clients/index.rst +++ b/docs/server/source/drivers-clients/index.rst @@ -1,29 +1,27 @@ Drivers & Clients ================= -Currently, the only language-native driver is written in the Python language. +Libraries and Tools Maintained by the BigchainDB Team +----------------------------------------------------- -We also provide the Transaction CLI to be able to script the building of -transactions. You may be able to wrap this tool inside the language of -your choice, and then use the HTTP API directly to post transactions. - -If you use a language other than Python, you may want to look at the current -community projects listed below. - - -.. toctree:: - :maxdepth: 1 - - The Python Driver - Transaction CLI +* `The Python Driver `_ +* `The Transaction CLI `_ is + a command-line interface for building BigchainDB transactions. + You may be able to call it from inside the language of + your choice, and then use :ref:`the HTTP API ` + to post transactions. Community-Driven Libraries and Tools ------------------------------------ -Please note that some of these projects may be work in progress, but may -nevertheless be very useful. + +.. note:: + + Some of these projects are a work in progress, + but may still be useful. * `Javascript transaction builder `_ * `Haskell transaction builder `_ * `Go driver `_ * `Java driver `_ +* `Ruby driver `_ From 20270cdb9bc5e53cd75741591be61cb17f8aa589 Mon Sep 17 00:00:00 2001 From: Krish Date: Wed, 26 Apr 2017 18:34:22 +0200 Subject: [PATCH 32/33] Config settings for MongoDB Backup Agent (#1442) --- .../container/mongodb_backup_agent_entrypoint.bash | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/k8s/mongodb-backup-agent/container/mongodb_backup_agent_entrypoint.bash b/k8s/mongodb-backup-agent/container/mongodb_backup_agent_entrypoint.bash index 3eb20633..ef3895ea 100755 --- a/k8s/mongodb-backup-agent/container/mongodb_backup_agent_entrypoint.bash +++ b/k8s/mongodb-backup-agent/container/mongodb_backup_agent_entrypoint.bash @@ -12,9 +12,10 @@ if [[ -z "${mms_api_key}" ]]; then fi sed -i '/mmsApiKey/d' $MONGODB_BACKUP_CONF_FILE +sed -i '/mothership/d' $MONGODB_BACKUP_CONF_FILE echo "mmsApiKey="${mms_api_key} >> $MONGODB_BACKUP_CONF_FILE +echo "mothership=api-backup.eu-west-1.mongodb.com" >> $MONGODB_BACKUP_CONF_FILE echo "INFO: starting mdb backup..." -exec mongodb-mms-backup-agent \ - -c $MONGODB_BACKUP_CONF_FILE +exec mongodb-mms-backup-agent -c $MONGODB_BACKUP_CONF_FILE From 43f9f678675c339d6b2cf744bda164c7ff200a9a Mon Sep 17 00:00:00 2001 From: Krish Date: Fri, 28 Apr 2017 10:14:14 +0200 Subject: [PATCH 33/33] Publish port 80 publicly in nginx-3scale. (#1446) Upgrade docker image tag to `1.1` as the corresponding config changes for displaying error message are built in the `1.1` container image. --- k8s/nginx-3scale/nginx-3scale-dep.yaml | 6 +++++- k8s/nginx-3scale/nginx-3scale-svc.yaml | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/k8s/nginx-3scale/nginx-3scale-dep.yaml b/k8s/nginx-3scale/nginx-3scale-dep.yaml index 8b1fa673..964cbf8b 100644 --- a/k8s/nginx-3scale/nginx-3scale-dep.yaml +++ b/k8s/nginx-3scale/nginx-3scale-dep.yaml @@ -19,7 +19,7 @@ spec: terminationGracePeriodSeconds: 10 containers: - name: nginx-3scale - image: bigchaindb/nginx_3scale:1.0 + image: bigchaindb/nginx_3scale:1.1 # TODO(Krish): Change later to IfNotPresent imagePullPolicy: Always env: @@ -68,6 +68,10 @@ spec: hostPort: 443 name: public-bdb-port protocol: TCP + - containerPort: 80 + hostPort: 80 + name: https-msg-port + protocol: TCP - containerPort: 8888 hostPort: 8888 name: health-check diff --git a/k8s/nginx-3scale/nginx-3scale-svc.yaml b/k8s/nginx-3scale/nginx-3scale-svc.yaml index db212222..9150c24d 100644 --- a/k8s/nginx-3scale/nginx-3scale-svc.yaml +++ b/k8s/nginx-3scale/nginx-3scale-svc.yaml @@ -14,6 +14,10 @@ spec: selector: app: ngx-instance-0-dep ports: + - port: 80 + targetPort: 80 + name: ngx-public-bdb-port-http + protocol: TCP - port: 443 targetPort: 443 name: ngx-public-bdb-port