mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
move tests related to assets
This commit is contained in:
parent
48a3ba96ae
commit
4b060e6488
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user