mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
pep8 fixes
This commit is contained in:
parent
7313cd9441
commit
dccbc3c1fe
@ -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
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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)],
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user