forked from bigchaindb/cryptoconditions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_type_registry.py
97 lines (72 loc) · 3.63 KB
/
test_type_registry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import pytest
def test_find_type_by_id():
from cryptoconditions.type_registry import (TypeRegistry,
MAX_SAFE_INTEGER_JS)
from cryptoconditions.exceptions import UnsupportedTypeError
from cryptoconditions.types.preimage import PreimageSha256
# test type_id > MAX_SAFE_INTEGER_JS
with pytest.raises(UnsupportedTypeError):
TypeRegistry.find_by_type_id(MAX_SAFE_INTEGER_JS + 1)
# test type_id not in registered_types
# we currently only support types from 0..4
with pytest.raises(UnsupportedTypeError):
TypeRegistry.find_by_type_id(MAX_SAFE_INTEGER_JS)
# test type_id returns correct registered_type
# type_id 0 is for preimage-sha-256
registered_type = TypeRegistry.find_by_type_id(0)
assert registered_type['name'] == PreimageSha256.TYPE_NAME
def test_find_by_name():
from cryptoconditions.type_registry import TypeRegistry
from cryptoconditions.exceptions import UnsupportedTypeError
from cryptoconditions.types.preimage import PreimageSha256
# test type name not in registered_types
with pytest.raises(UnsupportedTypeError):
TypeRegistry.find_by_name('magic')
# test type name returns the correct registered_type
registered_type = TypeRegistry.find_by_name('preimage-sha-256')
assert registered_type['name'] == PreimageSha256.TYPE_NAME
def test_find_by_asn1_type():
from cryptoconditions.type_registry import TypeRegistry
from cryptoconditions.exceptions import UnsupportedTypeError
from cryptoconditions.types.preimage import PreimageSha256
# test asn1 type not in registered_types
with pytest.raises(UnsupportedTypeError):
TypeRegistry.find_by_asn1_type('magic')
# test asn1 type returns the correct registered_type
registered_type = TypeRegistry.find_by_asn1_type('preimageSha256')
assert registered_type['asn1'] == PreimageSha256.TYPE_ASN1
def test_find_by_asn1_condition_type():
from cryptoconditions.type_registry import TypeRegistry
from cryptoconditions.exceptions import UnsupportedTypeError
from cryptoconditions.types.preimage import PreimageSha256
# test asn1 condition_type not in registered_types
with pytest.raises(UnsupportedTypeError):
TypeRegistry.find_by_asn1_condition_type('magic')
# test asn1 condition_type returns the correct registered_type
registered_type = TypeRegistry.find_by_asn1_condition_type(
'preimageSha256Condition')
assert registered_type['asn1_condition'] == \
PreimageSha256.TYPE_ASN1_CONDITION
def test_find_by_asn1_fulfillment_type():
from cryptoconditions.type_registry import TypeRegistry
from cryptoconditions.exceptions import UnsupportedTypeError
from cryptoconditions.types.preimage import PreimageSha256
# test asn1 fulfillment_type not in registered_types
with pytest.raises(UnsupportedTypeError):
TypeRegistry.find_by_asn1_fulfillment_type('magic')
# test asn1 fulfillment_type returns the correct registered_type
registered_type = TypeRegistry.find_by_asn1_fulfillment_type(
'preimageSha256Fulfillment')
assert registered_type['asn1_fulfillment'] == \
PreimageSha256.TYPE_ASN1_FULFILLMENT
def test_register_type():
from cryptoconditions.type_registry import TypeRegistry
class NewType:
TYPE_ID = 1000
TYPE_NAME = 'newType'
TYPE_ASN1 = 'asn1NewType'
TYPE_ASN1_CONDITION = 'asn1NewTypeCondition'
TYPE_ASN1_FULFILLMENT = 'asn1NewTypeFulfillment'
TypeRegistry.register_type(NewType)
registered_type = TypeRegistry.find_by_type_id(1000)
assert registered_type['class'] == NewType