From dccbc3c1fe47835b59ded6f0e43e1bce8433da89 Mon Sep 17 00:00:00 2001 From: Rodolphe Marques Date: Wed, 9 Nov 2016 14:25:42 +0100 Subject: [PATCH] pep8 fixes --- bigchaindb/common/transaction.py | 11 +---------- bigchaindb/core.py | 4 ++-- bigchaindb/db/backends/rethinkdb.py | 3 ++- bigchaindb/pipelines/vote.py | 3 ++- tests/common/test_transaction.py | 9 ++++----- tests/db/test_bigchain_api.py | 19 ++++++++++--------- 6 files changed, 21 insertions(+), 28 deletions(-) diff --git a/bigchaindb/common/transaction.py b/bigchaindb/common/transaction.py index f87d9a3c..8a8fcded 100644 --- a/bigchaindb/common/transaction.py +++ b/bigchaindb/common/transaction.py @@ -3,8 +3,7 @@ from functools import reduce from uuid import uuid4 from cryptoconditions import (Fulfillment as CCFulfillment, - ThresholdSha256Fulfillment, Ed25519Fulfillment, - PreimageSha256Fulfillment) + ThresholdSha256Fulfillment, Ed25519Fulfillment) from cryptoconditions.exceptions import ParsingError from bigchaindb.common.crypto import SigningKey, hash_data @@ -800,7 +799,6 @@ class Transaction(object): pub_keys, amount = owner_after conds.append(Condition.generate(pub_keys, amount)) - metadata = Metadata(metadata) inputs = deepcopy(inputs) return cls(cls.TRANSFER, asset, inputs, conds, metadata) @@ -914,12 +912,6 @@ class Transaction(object): key_pairs = {gen_public_key(SigningKey(private_key)): SigningKey(private_key) for private_key in private_keys} - # TODO: What does the conditions of this transaction have to do with the - # fulfillments, and why does this enforce for the number of fulfillments - # and conditions to be the same? - # TODO: Need to check how this was done before common but I from what I remember we - # included the condition that we were fulfilling in the message to be signed. - # zippedIO = enumerate(zip(self.fulfillments, self.conditions)) for index, fulfillment in enumerate(self.fulfillments): # NOTE: We clone the current transaction but only add the condition # and fulfillment we're currently working on plus all @@ -1082,7 +1074,6 @@ class Transaction(object): """ input_condition_uris_count = len(input_condition_uris) fulfillments_count = len(self.fulfillments) - conditions_count = len(self.conditions) def gen_tx(fulfillment, condition, input_condition_uri=None): """Splits multiple IO Transactions into partial single IO diff --git a/bigchaindb/core.py b/bigchaindb/core.py index 430b95d7..3c4f5347 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -182,7 +182,8 @@ class Bigchain(object): try: return self.validate_transaction(transaction) - except (ValueError, exceptions.OperationError, exceptions.TransactionDoesNotExist, + except (ValueError, exceptions.OperationError, + exceptions.TransactionDoesNotExist, exceptions.TransactionOwnerError, exceptions.DoubleSpend, exceptions.InvalidHash, exceptions.InvalidSignature, exceptions.FulfillmentNotInValidBlock, exceptions.AmountError): @@ -358,7 +359,6 @@ class Bigchain(object): if cursor: return Asset.from_dict(cursor[0]['transaction']['asset']) - def get_spent(self, txid, cid): """Check if a `txid` was already used as an input. diff --git a/bigchaindb/db/backends/rethinkdb.py b/bigchaindb/db/backends/rethinkdb.py index 8f28eca9..944d5e7c 100644 --- a/bigchaindb/db/backends/rethinkdb.py +++ b/bigchaindb/db/backends/rethinkdb.py @@ -178,7 +178,8 @@ class RethinkDBBackend: r.table('bigchain', read_mode=self.read_mode) .get_all(asset_id, index='asset_id') .concat_map(lambda block: block['block']['transactions']) - .filter(lambda transaction: transaction['transaction']['asset']['id'] == asset_id)) + .filter(lambda transaction: + transaction['transaction']['asset']['id'] == asset_id)) def get_asset_by_id(self, asset_id): """Returns the asset associated with an asset_id diff --git a/bigchaindb/pipelines/vote.py b/bigchaindb/pipelines/vote.py index 3d30de35..b89e0786 100644 --- a/bigchaindb/pipelines/vote.py +++ b/bigchaindb/pipelines/vote.py @@ -43,7 +43,8 @@ class Vote: [([self.bigchain.me], 1)]) def validate_block(self, block): - if not self.bigchain.has_previous_vote(block['id'], block['block']['voters']): + if not self.bigchain.has_previous_vote(block['id'], + block['block']['voters']): try: block = Block.from_dict(block) except (exceptions.InvalidHash, exceptions.InvalidSignature): diff --git a/tests/common/test_transaction.py b/tests/common/test_transaction.py index 50e26c21..438c796c 100644 --- a/tests/common/test_transaction.py +++ b/tests/common/test_transaction.py @@ -596,7 +596,7 @@ def test_validate_multiple_fulfillments(user_ffill, user_cond, user_priv): from copy import deepcopy from bigchaindb.common.crypto import SigningKey - from bigchaindb.common.transaction import Transaction, Asset, Condition + from bigchaindb.common.transaction import Transaction, Asset # TODO: Why is there a fulfillment in the conditions list tx = Transaction(Transaction.CREATE, Asset(divisible=True), @@ -920,9 +920,9 @@ def test_create_create_transaction_with_invalid_parameters(user_pub): with raises(TypeError): Transaction.create([], 'not a list') with raises(ValueError): - Transaction.create([],[user_pub]) + Transaction.create([], [user_pub]) with raises(ValueError): - Transaction.create([user_pub],[]) + Transaction.create([user_pub], []) with raises(ValueError): Transaction.create([user_pub], [user_pub]) with raises(ValueError): @@ -998,7 +998,7 @@ def test_create_transfer_transaction_multiple_io(user_pub, user_priv, asset = Asset(divisible=True) tx = Transaction.create([user_pub], [([user_pub], 1), ([user2_pub], 1)], - asset=asset, metadata={'message': 'hello'}) + asset=asset, metadata={'message': 'hello'}) tx = tx.sign([user_priv]) expected = { @@ -1032,7 +1032,6 @@ def test_create_transfer_transaction_multiple_io(user_pub, user_priv, }, 'version': 1 } - tx_inputs = tx.to_inputs() transfer_tx = Transaction.transfer(tx.to_inputs(), [([user2_pub], 1), ([user2_pub], 1)], diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index a7b4413d..31844d29 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -582,7 +582,7 @@ class TestBigchainApi(object): TransactionLink('somethingsomething', 0)) tx = Transaction.transfer([fulfillment], [([user_vk], 1)], Asset()) - with pytest.raises(TransactionDoesNotExist) as excinfo: + with pytest.raises(TransactionDoesNotExist): tx.validate(Bigchain()) @@ -666,7 +666,8 @@ class TestTransactionValidation(object): input_tx = b.get_owned_ids(user_vk).pop() input_tx = b.get_transaction(input_tx.txid) inputs = input_tx.to_inputs() - transfer_tx = Transaction.transfer(inputs, [([user_vk], 1)], input_tx.asset) + transfer_tx = Transaction.transfer(inputs, [([user_vk], 1)], + input_tx.asset) transfer_tx = transfer_tx.sign([user_sk]) assert transfer_tx == b.validate_transaction(transfer_tx) @@ -690,7 +691,8 @@ class TestTransactionValidation(object): inputs = input_tx.to_inputs() # create a transaction that's valid but not in a voted valid block - transfer_tx = Transaction.transfer(inputs, [([user_vk], 1)], input_tx.asset) + transfer_tx = Transaction.transfer(inputs, [([user_vk], 1)], + input_tx.asset) transfer_tx = transfer_tx.sign([user_sk]) assert transfer_tx == b.validate_transaction(transfer_tx) @@ -965,7 +967,6 @@ class TestMultipleInputs(object): def test_get_owned_ids_single_tx_multiple_outputs(self, b, user_sk, user_vk): - import random from bigchaindb.common import crypto from bigchaindb.common.transaction import TransactionLink, Asset from bigchaindb.models import Transaction @@ -992,8 +993,8 @@ class TestMultipleInputs(object): # transfer divisible asset divided in two outputs tx_transfer = Transaction.transfer(tx_create.to_inputs(), - [([user2_vk], 1), ([user2_vk], 1)], - asset=tx_create.asset) + [([user2_vk], 1), ([user2_vk], 1)], + asset=tx_create.asset) tx_transfer_signed = tx_transfer.sign([user_sk]) block = b.create_block([tx_transfer_signed]) b.write_block(block, durability='hard') @@ -1012,7 +1013,7 @@ class TestMultipleInputs(object): user2_sk, user2_vk = crypto.generate_key_pair() user3_sk, user3_vk = crypto.generate_key_pair() - tx = Transaction.create([b.me], [([user_vk, user2_vk],1)]) + tx = Transaction.create([b.me], [([user_vk, user2_vk], 1)]) tx = tx.sign([b.me_private]) block = b.create_block([tx]) b.write_block(block, durability='hard') @@ -1105,7 +1106,6 @@ class TestMultipleInputs(object): assert spent_inputs_user1 is None def test_get_spent_single_tx_multiple_outputs(self, b, user_sk, user_vk): - import random from bigchaindb.common import crypto from bigchaindb.models import Transaction from bigchaindb.common.transaction import Asset @@ -1158,7 +1158,8 @@ class TestMultipleInputs(object): transactions = [] for i in range(3): payload = {'somedata': random.randint(0, 255)} - tx = Transaction.create([b.me], [([user_vk, user2_vk], 1)], payload) + tx = Transaction.create([b.me], [([user_vk, user2_vk], 1)], + payload) tx = tx.sign([b.me_private]) transactions.append(tx) block = b.create_block(transactions)