mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
new home of structural validation in tests
This commit is contained in:
parent
277251b50b
commit
ae8153bd10
@ -19,42 +19,3 @@ def test_validate_transaction_signed_transfer(signed_transfer_tx):
|
|||||||
def test_validate_transaction_fails():
|
def test_validate_transaction_fails():
|
||||||
with raises(SchemaValidationError):
|
with raises(SchemaValidationError):
|
||||||
validate_transaction_schema({})
|
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)
|
|
||||||
|
71
tests/validation/test_transaction_structure.py
Normal file
71
tests/validation/test_transaction_structure.py
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user