mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Addressed comments to import tests.
Fixed some pep8 violations
This commit is contained in:
parent
19caad3d34
commit
7d3c6ee5ce
@ -558,7 +558,6 @@ class Bigchain(object):
|
|||||||
"""Prepare a genesis block."""
|
"""Prepare a genesis block."""
|
||||||
|
|
||||||
metadata = {'message': 'Hello World from the BigchainDB'}
|
metadata = {'message': 'Hello World from the BigchainDB'}
|
||||||
# TODO: When updating the BDBC lib, change `payload` to `metadata`
|
|
||||||
transaction = Transaction.create([self.me], [self.me],
|
transaction = Transaction.create([self.me], [self.me],
|
||||||
metadata=metadata)
|
metadata=metadata)
|
||||||
|
|
||||||
|
@ -8,8 +8,9 @@ def test_asset_transfer(b, user_vk, user_sk):
|
|||||||
|
|
||||||
tx_input = b.get_owned_ids(user_vk).pop()
|
tx_input = b.get_owned_ids(user_vk).pop()
|
||||||
tx_create = b.get_transaction(tx_input.txid)
|
tx_create = b.get_transaction(tx_input.txid)
|
||||||
|
|
||||||
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [user_vk], tx_create.asset)
|
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [user_vk],
|
||||||
|
tx_create.asset)
|
||||||
tx_transfer_signed = tx_transfer.sign([user_sk])
|
tx_transfer_signed = tx_transfer.sign([user_sk])
|
||||||
|
|
||||||
assert tx_transfer_signed.validate(b) == tx_transfer_signed
|
assert tx_transfer_signed.validate(b) == tx_transfer_signed
|
||||||
@ -17,7 +18,6 @@ def test_asset_transfer(b, user_vk, user_sk):
|
|||||||
|
|
||||||
|
|
||||||
def test_validate_bad_asset_creation(b, user_vk):
|
def test_validate_bad_asset_creation(b, user_vk):
|
||||||
from bigchaindb_common.exceptions import AmountError
|
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
|
|
||||||
# `divisible` needs to be a boolean
|
# `divisible` needs to be a boolean
|
||||||
@ -73,6 +73,7 @@ def test_validate_bad_asset_creation(b, user_vk):
|
|||||||
b.validate_transaction(tx_signed)
|
b.validate_transaction(tx_signed)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_validate_transfer_asset_id_mismatch(b, user_vk, user_sk):
|
def test_validate_transfer_asset_id_mismatch(b, user_vk, user_sk):
|
||||||
from bigchaindb_common.exceptions import AssetIdMismatch
|
from bigchaindb_common.exceptions import AssetIdMismatch
|
||||||
@ -80,19 +81,18 @@ def test_validate_transfer_asset_id_mismatch(b, user_vk, user_sk):
|
|||||||
|
|
||||||
tx_create = b.get_owned_ids(user_vk).pop()
|
tx_create = b.get_owned_ids(user_vk).pop()
|
||||||
tx_create = b.get_transaction(tx_create.txid)
|
tx_create = b.get_transaction(tx_create.txid)
|
||||||
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [user_vk], tx_create.asset)
|
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [user_vk],
|
||||||
|
tx_create.asset)
|
||||||
tx_transfer.asset.data_id = 'aaa'
|
tx_transfer.asset.data_id = 'aaa'
|
||||||
tx_transfer_signed = tx_transfer.sign([user_sk])
|
tx_transfer_signed = tx_transfer.sign([user_sk])
|
||||||
with pytest.raises(AssetIdMismatch):
|
with pytest.raises(AssetIdMismatch):
|
||||||
tx_transfer_signed.validate(b)
|
tx_transfer_signed.validate(b)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('inputs')
|
|
||||||
def test_get_asset_id_create_transaction(b, user_vk):
|
def test_get_asset_id_create_transaction(b, user_vk):
|
||||||
from bigchaindb.models import Asset
|
from bigchaindb.models import Transaction, Asset
|
||||||
|
|
||||||
tx_create = b.get_owned_ids(user_vk).pop()
|
tx_create = Transaction.create([b.me], [user_vk])
|
||||||
tx_create = b.get_transaction(tx_create.txid)
|
|
||||||
asset_id = Asset.get_asset_id(tx_create)
|
asset_id = Asset.get_asset_id(tx_create)
|
||||||
|
|
||||||
assert asset_id == tx_create.asset.data_id
|
assert asset_id == tx_create.asset.data_id
|
||||||
@ -105,7 +105,8 @@ def test_get_asset_id_transfer_transaction(b, user_vk, user_sk):
|
|||||||
tx_create = b.get_owned_ids(user_vk).pop()
|
tx_create = b.get_owned_ids(user_vk).pop()
|
||||||
tx_create = b.get_transaction(tx_create.txid)
|
tx_create = b.get_transaction(tx_create.txid)
|
||||||
# create a transfer transaction
|
# create a transfer transaction
|
||||||
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [user_vk], tx_create.asset)
|
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [user_vk],
|
||||||
|
tx_create.asset)
|
||||||
tx_transfer_signed = tx_transfer.sign([user_sk])
|
tx_transfer_signed = tx_transfer.sign([user_sk])
|
||||||
# create a block
|
# create a block
|
||||||
block = b.create_block([tx_transfer_signed])
|
block = b.create_block([tx_transfer_signed])
|
||||||
@ -118,14 +119,12 @@ def test_get_asset_id_transfer_transaction(b, user_vk, user_sk):
|
|||||||
assert asset_id == tx_transfer.asset.data_id
|
assert asset_id == tx_transfer.asset.data_id
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('inputs')
|
|
||||||
def test_asset_id_mismatch(b, user_vk):
|
def test_asset_id_mismatch(b, user_vk):
|
||||||
from bigchaindb.models import Asset
|
from bigchaindb.models import Transaction, Asset
|
||||||
from bigchaindb_common.exceptions import AssetIdMismatch
|
from bigchaindb_common.exceptions import AssetIdMismatch
|
||||||
|
|
||||||
tx_input1, tx_input2 = b.get_owned_ids(user_vk)[:2]
|
tx1 = Transaction.create([b.me], [user_vk])
|
||||||
tx1 = b.get_transaction(tx_input1.txid)
|
tx2 = Transaction.create([b.me], [user_vk])
|
||||||
tx2 = b.get_transaction(tx_input2.txid)
|
|
||||||
|
|
||||||
with pytest.raises(AssetIdMismatch):
|
with pytest.raises(AssetIdMismatch):
|
||||||
Asset.get_asset_id([tx1, tx2])
|
Asset.get_asset_id([tx1, tx2])
|
||||||
@ -145,7 +144,8 @@ def test_get_txs_by_asset_id(b, user_vk, user_sk):
|
|||||||
assert txs[0].asset.data_id == asset_id
|
assert txs[0].asset.data_id == asset_id
|
||||||
|
|
||||||
# create a transfer transaction
|
# create a transfer transaction
|
||||||
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [user_vk], tx_create.asset)
|
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [user_vk],
|
||||||
|
tx_create.asset)
|
||||||
tx_transfer_signed = tx_transfer.sign([user_sk])
|
tx_transfer_signed = tx_transfer.sign([user_sk])
|
||||||
# create the block
|
# create the block
|
||||||
block = b.create_block([tx_transfer_signed])
|
block = b.create_block([tx_transfer_signed])
|
||||||
|
@ -119,8 +119,7 @@ def inputs(user_vk):
|
|||||||
prev_block_id = g.id
|
prev_block_id = g.id
|
||||||
for block in range(4):
|
for block in range(4):
|
||||||
transactions = [
|
transactions = [
|
||||||
Transaction.create(
|
Transaction.create([b.me], [user_vk]).sign([b.me_private])
|
||||||
[b.me], [user_vk], metadata={'i': i}).sign([b.me_private])
|
|
||||||
for i in range(10)
|
for i in range(10)
|
||||||
]
|
]
|
||||||
block = b.create_block(transactions)
|
block = b.create_block(transactions)
|
||||||
|
@ -521,24 +521,19 @@ class TestBigchainApi(object):
|
|||||||
assert response['assignee'] in b.nodes_except_me
|
assert response['assignee'] in b.nodes_except_me
|
||||||
|
|
||||||
|
|
||||||
# TODO: Make this test work
|
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_non_create_input_not_found(self, b, user_vk):
|
def test_non_create_input_not_found(self, b, user_vk):
|
||||||
|
from cryptoconditions import Ed25519Fulfillment
|
||||||
from bigchaindb_common.exceptions import TransactionDoesNotExist
|
from bigchaindb_common.exceptions import TransactionDoesNotExist
|
||||||
from bigchaindb_common.transaction import Fulfillment, Asset
|
from bigchaindb_common.transaction import (Fulfillment, Asset,
|
||||||
|
TransactionLink)
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
from bigchaindb import Bigchain
|
from bigchaindb import Bigchain
|
||||||
|
|
||||||
# Create a fulfillment for a non existing transaction
|
# Create a fulfillment for a non existing transaction
|
||||||
fulfillment_dict = {'fulfillment': {'bitmask': 32,
|
fulfillment = Fulfillment(Ed25519Fulfillment(public_key=user_vk),
|
||||||
'public_key': user_vk,
|
[user_vk],
|
||||||
'signature': None,
|
TransactionLink('somethingsomething', 0))
|
||||||
'type': 'fulfillment',
|
|
||||||
'type_id': 4},
|
|
||||||
'input': {'cid': 0,
|
|
||||||
'txid': 'somethingsomething'},
|
|
||||||
'owners_before': [user_vk]}
|
|
||||||
fulfillment = Fulfillment.from_dict(fulfillment_dict)
|
|
||||||
tx = Transaction.transfer([fulfillment], [user_vk], Asset())
|
tx = Transaction.transfer([fulfillment], [user_vk], Asset())
|
||||||
|
|
||||||
with pytest.raises(TransactionDoesNotExist) as excinfo:
|
with pytest.raises(TransactionDoesNotExist) as excinfo:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user