mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Handle transaction schema validation errors
in POST /transactions
This commit is contained in:
parent
602dfbea06
commit
9dacc12b3c
@ -6,7 +6,11 @@ For more information please refer to the documentation on ReadTheDocs:
|
||||
from flask import current_app, request, Blueprint
|
||||
from flask_restful import Resource, Api
|
||||
|
||||
from bigchaindb.common.exceptions import ValidationError, InvalidSignature
|
||||
from bigchaindb.common.exceptions import (
|
||||
ValidationError,
|
||||
InvalidSignature,
|
||||
SchemaValidationError,
|
||||
)
|
||||
|
||||
import bigchaindb
|
||||
from bigchaindb.models import Transaction
|
||||
@ -98,6 +102,12 @@ class TransactionListApi(Resource):
|
||||
|
||||
try:
|
||||
tx_obj = Transaction.from_dict(tx)
|
||||
except SchemaValidationError as e:
|
||||
return make_error(
|
||||
400,
|
||||
message='Invalid transaction schema: {}'.format(
|
||||
e.__cause__.message)
|
||||
)
|
||||
except (ValidationError, InvalidSignature):
|
||||
return make_error(400, 'Invalid transaction')
|
||||
|
||||
|
@ -66,6 +66,18 @@ def test_post_create_transaction_with_invalid_structure(client):
|
||||
assert res.status_code == 400
|
||||
|
||||
|
||||
def test_post_create_transaction_with_invalid_schema(client):
|
||||
from bigchaindb.models import Transaction
|
||||
user_priv, user_pub = crypto.generate_key_pair()
|
||||
tx = Transaction.create(
|
||||
[user_pub], [([user_pub], 1)]).sign([user_priv]).to_dict()
|
||||
del tx['version']
|
||||
res = client.post(TX_ENDPOINT, data=json.dumps(tx))
|
||||
assert res.status_code == 400
|
||||
assert res.json['message'] == (
|
||||
"Invalid transaction schema: 'version' is a required property")
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_post_transfer_transaction_endpoint(b, client, user_pk, user_sk):
|
||||
sk, pk = crypto.generate_key_pair()
|
||||
|
Loading…
x
Reference in New Issue
Block a user