mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
parent
46bb1d6d12
commit
4d61c5e8ca
@ -153,7 +153,9 @@ definitions:
|
||||
"$ref": "#/definitions/condition_details"
|
||||
uri:
|
||||
type: string
|
||||
pattern: "^ni:///sha-256;([a-zA-Z0-9_-]{0,86})?(.+)$"
|
||||
pattern: "^ni:///sha-256;([a-zA-Z0-9_-]{0,86})[?]\
|
||||
(fpt=(ed25519|threshold)-sha-256(&)?|cost=[0-9]+(&)?|\
|
||||
subtypes=ed25519-sha-256(&)?){2,3}$"
|
||||
public_keys:
|
||||
"$ref": "#/definitions/public_keys"
|
||||
description: |
|
||||
|
@ -1,3 +1,7 @@
|
||||
"""Transaction related models to parse and construct transaction
|
||||
payloads.
|
||||
|
||||
"""
|
||||
from copy import deepcopy
|
||||
from functools import reduce
|
||||
|
||||
|
2
setup.py
2
setup.py
@ -47,6 +47,8 @@ tests_require = [
|
||||
'pep8',
|
||||
'flake8',
|
||||
'flake8-quotes==0.8.1',
|
||||
'hypothesis',
|
||||
'hypothesis-regex',
|
||||
'pylint',
|
||||
'pytest>=3.0.0',
|
||||
'pytest-catchlog>=1.2.2',
|
||||
|
@ -175,3 +175,30 @@ def transfer_utx(user_output, user2_output, utx):
|
||||
@pytest.fixture
|
||||
def transfer_tx(transfer_utx, user_priv):
|
||||
return transfer_utx.sign([user_priv])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dummy_transaction():
|
||||
return {
|
||||
'asset': {'data': None},
|
||||
'id': 64 * 'a',
|
||||
'inputs': [{
|
||||
'fulfillment': 'dummy',
|
||||
'fulfills': None,
|
||||
'owners_before': [58 * 'a'],
|
||||
}],
|
||||
'metadata': None,
|
||||
'operation': 'CREATE',
|
||||
'outputs': [{
|
||||
'amount': '1',
|
||||
'condition': {
|
||||
'details': {
|
||||
'public_key': 58 * 'b',
|
||||
'type': 'ed25519-sha-256'
|
||||
},
|
||||
'uri': 'dummy',
|
||||
},
|
||||
'public_keys': [58 * 'b']
|
||||
}],
|
||||
'version': '1.0'
|
||||
}
|
||||
|
@ -3,14 +3,21 @@ This module is tests related to schema checking, but _not_ of granular schematic
|
||||
properties related to validation.
|
||||
"""
|
||||
|
||||
from pytest import raises
|
||||
from unittest.mock import patch
|
||||
|
||||
from hypothesis import given
|
||||
from hypothesis_regex import regex
|
||||
from pytest import raises
|
||||
|
||||
from bigchaindb.common.exceptions import SchemaValidationError
|
||||
from bigchaindb.common.schema import (
|
||||
TX_SCHEMA_COMMON, VOTE_SCHEMA, drop_schema_descriptions,
|
||||
validate_transaction_schema, validate_vote_schema)
|
||||
|
||||
SUPPORTED_CRYPTOCONDITION_TYPES = ('threshold-sha-256', 'ed25519-sha-256')
|
||||
UNSUPPORTED_CRYPTOCONDITION_TYPES = (
|
||||
'preimage-sha-256', 'prefix-sha-256', 'rsa-sha-256')
|
||||
|
||||
|
||||
################################################################################
|
||||
# Test of schema utils
|
||||
@ -109,6 +116,63 @@ def test_validate_failure_inconsistent():
|
||||
validate_transaction_schema({})
|
||||
|
||||
|
||||
@given(condition_uri=regex(
|
||||
r'^ni:\/\/\/sha-256;([a-zA-Z0-9_-]{{0,86}})\?fpt=({})'
|
||||
r'&cost=[0-9]+(?![\n])$'.format('|'.join(
|
||||
t for t in SUPPORTED_CRYPTOCONDITION_TYPES))))
|
||||
def test_condition_uri_with_supported_fpt(dummy_transaction, condition_uri):
|
||||
dummy_transaction['outputs'][0]['condition']['uri'] = condition_uri
|
||||
validate_transaction_schema(dummy_transaction)
|
||||
|
||||
|
||||
@given(condition_uri=regex(r'^ni:\/\/\/sha-256;([a-zA-Z0-9_-]{{0,86}})\?fpt='
|
||||
r'({})&cost=[0-9]+(?![\n])$'.format(
|
||||
'|'.join(UNSUPPORTED_CRYPTOCONDITION_TYPES))))
|
||||
def test_condition_uri_with_unsupported_fpt(dummy_transaction, condition_uri):
|
||||
dummy_transaction['outputs'][0]['condition']['uri'] = condition_uri
|
||||
with raises(SchemaValidationError):
|
||||
validate_transaction_schema(dummy_transaction)
|
||||
|
||||
|
||||
@given(condition_uri=regex(
|
||||
r'^ni:\/\/\/sha-256;([a-zA-Z0-9_-]{{0,86}})\?fpt=(?!{})'
|
||||
r'&cost=[0-9]+(?![\n])$'.format('$|'.join(
|
||||
t for t in SUPPORTED_CRYPTOCONDITION_TYPES))))
|
||||
def test_condition_uri_with_unknown_fpt(dummy_transaction, condition_uri):
|
||||
dummy_transaction['outputs'][0]['condition']['uri'] = condition_uri
|
||||
with raises(SchemaValidationError):
|
||||
validate_transaction_schema(dummy_transaction)
|
||||
|
||||
|
||||
@given(condition_uri=regex(
|
||||
r'^ni:\/\/\/sha-256;([a-zA-Z0-9_-]{0,86})\?fpt=threshold-sha-256'
|
||||
r'&cost=[0-9]+&subtypes=ed25519-sha-256(?![\n])$'))
|
||||
def test_condition_uri_with_supported_subtype(dummy_transaction,
|
||||
condition_uri):
|
||||
dummy_transaction['outputs'][0]['condition']['uri'] = condition_uri
|
||||
validate_transaction_schema(dummy_transaction)
|
||||
|
||||
|
||||
@given(condition_uri=regex(
|
||||
r'^ni:\/\/\/sha-256;([a-zA-Z0-9_-]{0,86})\?fpt=threshold-sha-256&cost='
|
||||
r'[0-9]+&subtypes=(preimage-sha-256|prefix-sha-256|rsa-sha-256)(?![\n])$'))
|
||||
def test_condition_uri_with_unsupported_subtype(dummy_transaction,
|
||||
condition_uri):
|
||||
dummy_transaction['outputs'][0]['condition']['uri'] = condition_uri
|
||||
with raises(SchemaValidationError):
|
||||
validate_transaction_schema(dummy_transaction)
|
||||
|
||||
|
||||
@given(condition_uri=regex(
|
||||
r'^ni:\/\/\/sha-256;([a-zA-Z0-9_-]{{0,86}})\?fpt=threshold-sha-256'
|
||||
r'&cost=[0-9]+&subtypes=(?!{})(?![\n])$'.format('$|'.join(
|
||||
t for t in SUPPORTED_CRYPTOCONDITION_TYPES))))
|
||||
def test_condition_uri_with_unknown_subtype(dummy_transaction, condition_uri):
|
||||
dummy_transaction['outputs'][0]['condition']['uri'] = condition_uri
|
||||
with raises(SchemaValidationError):
|
||||
validate_transaction_schema(dummy_transaction)
|
||||
|
||||
|
||||
################################################################################
|
||||
# Test call vote schema
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user