jamcodec 0.1.1__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {jamcodec-0.1.1 → jamcodec-0.1.3}/PKG-INFO +5 -4
- {jamcodec-0.1.1 → jamcodec-0.1.3}/README.md +2 -2
- {jamcodec-0.1.1 → jamcodec-0.1.3}/jamcodec/types.py +27 -11
- {jamcodec-0.1.1 → jamcodec-0.1.3}/jamcodec.egg-info/PKG-INFO +5 -4
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_compact.py +17 -17
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_enum.py +9 -1
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_map.py +21 -3
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_scale_types.py +4 -4
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_scalebytes.py +2 -2
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_tuple.py +3 -3
- {jamcodec-0.1.1 → jamcodec-0.1.3}/LICENSE +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/jamcodec/__init__.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/jamcodec/base.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/jamcodec/constants.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/jamcodec/exceptions.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/jamcodec/mixins.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/jamcodec.egg-info/SOURCES.txt +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/jamcodec.egg-info/dependency_links.txt +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/jamcodec.egg-info/requires.txt +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/jamcodec.egg-info/top_level.txt +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/pyproject.toml +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/requirements.txt +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/setup.cfg +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_array.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_bitarray.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_bitvec.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_boolean.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_bytes.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_float.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_hashmap.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_integer.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_mixins.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_option.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_string.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_struct.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_varint.py +0 -0
- {jamcodec-0.1.1 → jamcodec-0.1.3}/test/test_vec.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: jamcodec
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: Python JAM Codec Library
|
|
5
5
|
Author-email: JAMdot Technologies <dev@jamdot.tech>
|
|
6
6
|
Project-URL: Homepage, https://github.com/JAMdotTech/py-jam-codec
|
|
@@ -21,6 +21,7 @@ Requires-Dist: mkdocs-material; extra == "dev"
|
|
|
21
21
|
Requires-Dist: mkdocs-autorefs; extra == "dev"
|
|
22
22
|
Requires-Dist: mkdocstrings; extra == "dev"
|
|
23
23
|
Requires-Dist: mkdocstrings[python]; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
24
25
|
|
|
25
26
|
# Python JAM Codec
|
|
26
27
|
|
|
@@ -42,7 +43,7 @@ pip install jamcodec
|
|
|
42
43
|
## Code examples
|
|
43
44
|
|
|
44
45
|
```python
|
|
45
|
-
from jamcodec.types import JamBytes, Bool, String, U32, U8, U16, Struct, Vec,
|
|
46
|
+
from jamcodec.types import JamBytes, Bool, String, U32, U8, U16, Struct, Vec, VarInt64, Tuple, Enum
|
|
46
47
|
|
|
47
48
|
# encode a Vec<u16>
|
|
48
49
|
obj = Vec(U16).new()
|
|
@@ -57,7 +58,7 @@ value = scale_obj.decode(JamBytes("0x020105"))
|
|
|
57
58
|
scale_obj = Enum(
|
|
58
59
|
Bool=Bool(),
|
|
59
60
|
Number=U32,
|
|
60
|
-
Complex=Struct(data=String(), version=
|
|
61
|
+
Complex=Struct(data=String(), version=VarInt64),
|
|
61
62
|
None_=None
|
|
62
63
|
).new()
|
|
63
64
|
value = {'Bool': True}
|
|
@@ -18,7 +18,7 @@ pip install jamcodec
|
|
|
18
18
|
## Code examples
|
|
19
19
|
|
|
20
20
|
```python
|
|
21
|
-
from jamcodec.types import JamBytes, Bool, String, U32, U8, U16, Struct, Vec,
|
|
21
|
+
from jamcodec.types import JamBytes, Bool, String, U32, U8, U16, Struct, Vec, VarInt64, Tuple, Enum
|
|
22
22
|
|
|
23
23
|
# encode a Vec<u16>
|
|
24
24
|
obj = Vec(U16).new()
|
|
@@ -33,7 +33,7 @@ value = scale_obj.decode(JamBytes("0x020105"))
|
|
|
33
33
|
scale_obj = Enum(
|
|
34
34
|
Bool=Bool(),
|
|
35
35
|
Number=U32,
|
|
36
|
-
Complex=Struct(data=String(), version=
|
|
36
|
+
Complex=Struct(data=String(), version=VarInt64),
|
|
37
37
|
None_=None
|
|
38
38
|
).new()
|
|
39
39
|
value = {'Bool': True}
|
|
@@ -371,8 +371,11 @@ class Enum(JamCodecTypeDef):
|
|
|
371
371
|
|
|
372
372
|
for idx, (variant_name, variant_obj) in enumerate(self.variants.items()):
|
|
373
373
|
|
|
374
|
-
if
|
|
374
|
+
if type(variant_obj) is dict:
|
|
375
|
+
idx = variant_obj.get('id', idx)
|
|
376
|
+
variant_obj = variant_obj.get('type', variant_obj)
|
|
375
377
|
|
|
378
|
+
if enum_key == variant_name:
|
|
376
379
|
data = JamBytes(bytearray([idx]))
|
|
377
380
|
|
|
378
381
|
if variant_obj is not None:
|
|
@@ -387,9 +390,19 @@ class Enum(JamCodecTypeDef):
|
|
|
387
390
|
|
|
388
391
|
index = int.from_bytes(data.get_next_bytes(1), byteorder='little')
|
|
389
392
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
+
enum_key = None
|
|
394
|
+
enum_variant = None
|
|
395
|
+
|
|
396
|
+
for idx, (variant_key, variant_obj) in enumerate(self.variants.items()):
|
|
397
|
+
if type(variant_obj) is dict:
|
|
398
|
+
idx = variant_obj.get('id', idx)
|
|
399
|
+
variant_obj = variant_obj.get('type', variant_obj)
|
|
400
|
+
if index == idx:
|
|
401
|
+
enum_key = variant_key
|
|
402
|
+
enum_variant = variant_obj
|
|
403
|
+
break
|
|
404
|
+
|
|
405
|
+
if enum_key is None:
|
|
393
406
|
raise ScaleDecodeException(f"Index '{index}' not present in Enum type mapping")
|
|
394
407
|
|
|
395
408
|
if enum_variant is None:
|
|
@@ -434,6 +447,9 @@ class Enum(JamCodecTypeDef):
|
|
|
434
447
|
|
|
435
448
|
for idx, (variant_name, variant_obj) in enumerate(self.variants.items()):
|
|
436
449
|
|
|
450
|
+
if type(variant_obj) is dict:
|
|
451
|
+
variant_obj = variant_obj.get('type', variant_obj)
|
|
452
|
+
|
|
437
453
|
if enum_key == variant_name:
|
|
438
454
|
|
|
439
455
|
if variant_obj is not None:
|
|
@@ -508,7 +524,7 @@ class Option(JamCodecTypeDef):
|
|
|
508
524
|
return None, self.some.example_value()
|
|
509
525
|
|
|
510
526
|
|
|
511
|
-
class
|
|
527
|
+
class CompactDef(JamCodecTypeDef):
|
|
512
528
|
def __init__(self, type_: JamCodecTypeDef = None):
|
|
513
529
|
self.type = type_
|
|
514
530
|
self.compact_length = 0
|
|
@@ -595,7 +611,6 @@ class Vec(JamCodecTypeDef):
|
|
|
595
611
|
self.type_def = type_def
|
|
596
612
|
|
|
597
613
|
def encode(self, value: list) -> JamBytes:
|
|
598
|
-
|
|
599
614
|
if self.type_def is U8:
|
|
600
615
|
return Bytes.encode(value)
|
|
601
616
|
|
|
@@ -959,8 +974,11 @@ class Map(JamCodecTypeDef):
|
|
|
959
974
|
def encode(self, value: Union[typing.Mapping, list]) -> JamBytes:
|
|
960
975
|
|
|
961
976
|
if isinstance(value, Mapping):
|
|
962
|
-
#
|
|
963
|
-
value =
|
|
977
|
+
# Convert to list
|
|
978
|
+
value = value.items()
|
|
979
|
+
|
|
980
|
+
# Sort Map by keys
|
|
981
|
+
value = sorted(value, key=lambda x: x[0])
|
|
964
982
|
|
|
965
983
|
# Encode length of Vec
|
|
966
984
|
data = VarInt64.encode(len(value))
|
|
@@ -1137,9 +1155,6 @@ class HashDef(JamCodecTypeDef):
|
|
|
1137
1155
|
|
|
1138
1156
|
class VarInt64Def(JamCodecTypeDef):
|
|
1139
1157
|
|
|
1140
|
-
def encode(self, value: any, external_call=True) -> JamBytes:
|
|
1141
|
-
return self.encode(value)
|
|
1142
|
-
|
|
1143
1158
|
def encode(self, value: int) -> JamBytes:
|
|
1144
1159
|
if value < 0:
|
|
1145
1160
|
raise ScaleEncodeException("Cannot encode negative value")
|
|
@@ -1235,3 +1250,4 @@ Hash = H256
|
|
|
1235
1250
|
HashMap = Map
|
|
1236
1251
|
BTreeMap = Map
|
|
1237
1252
|
VarInt64 = VarInt64Def()
|
|
1253
|
+
Compact = CompactDef()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: jamcodec
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: Python JAM Codec Library
|
|
5
5
|
Author-email: JAMdot Technologies <dev@jamdot.tech>
|
|
6
6
|
Project-URL: Homepage, https://github.com/JAMdotTech/py-jam-codec
|
|
@@ -21,6 +21,7 @@ Requires-Dist: mkdocs-material; extra == "dev"
|
|
|
21
21
|
Requires-Dist: mkdocs-autorefs; extra == "dev"
|
|
22
22
|
Requires-Dist: mkdocstrings; extra == "dev"
|
|
23
23
|
Requires-Dist: mkdocstrings[python]; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
24
25
|
|
|
25
26
|
# Python JAM Codec
|
|
26
27
|
|
|
@@ -42,7 +43,7 @@ pip install jamcodec
|
|
|
42
43
|
## Code examples
|
|
43
44
|
|
|
44
45
|
```python
|
|
45
|
-
from jamcodec.types import JamBytes, Bool, String, U32, U8, U16, Struct, Vec,
|
|
46
|
+
from jamcodec.types import JamBytes, Bool, String, U32, U8, U16, Struct, Vec, VarInt64, Tuple, Enum
|
|
46
47
|
|
|
47
48
|
# encode a Vec<u16>
|
|
48
49
|
obj = Vec(U16).new()
|
|
@@ -57,7 +58,7 @@ value = scale_obj.decode(JamBytes("0x020105"))
|
|
|
57
58
|
scale_obj = Enum(
|
|
58
59
|
Bool=Bool(),
|
|
59
60
|
Number=U32,
|
|
60
|
-
Complex=Struct(data=String(), version=
|
|
61
|
+
Complex=Struct(data=String(), version=VarInt64),
|
|
61
62
|
None_=None
|
|
62
63
|
).new()
|
|
63
64
|
value = {'Bool': True}
|
|
@@ -19,52 +19,52 @@ import unittest
|
|
|
19
19
|
|
|
20
20
|
from jamcodec.base import JamBytes
|
|
21
21
|
from jamcodec.exceptions import ScaleDecodeException, RemainingScaleBytesNotEmptyException
|
|
22
|
-
from jamcodec.types import
|
|
22
|
+
from jamcodec.types import CompactDef, U32, U128
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
class TestCompact(unittest.TestCase):
|
|
26
26
|
|
|
27
27
|
def test_compact_u32(self):
|
|
28
|
-
obj =
|
|
28
|
+
obj = CompactDef(U32).new()
|
|
29
29
|
obj.decode(JamBytes("0x02093d00"))
|
|
30
30
|
self.assertEqual(obj.value, 1000000)
|
|
31
31
|
|
|
32
32
|
def test_compact_u32_1byte(self):
|
|
33
|
-
obj =
|
|
33
|
+
obj = CompactDef(U32).new()
|
|
34
34
|
obj.decode(JamBytes("0x18"))
|
|
35
35
|
self.assertEqual(obj.value, 6)
|
|
36
36
|
|
|
37
37
|
def test_compact_u32_remaining_bytes(self):
|
|
38
|
-
obj =
|
|
38
|
+
obj = CompactDef(U32).new()
|
|
39
39
|
with self.assertRaises(ScaleDecodeException):
|
|
40
40
|
obj.decode(JamBytes("0x02093d0001"), check_remaining=True)
|
|
41
41
|
|
|
42
42
|
def test_compact_u32_invalid(self):
|
|
43
|
-
obj =
|
|
43
|
+
obj = CompactDef(U32).new()
|
|
44
44
|
self.assertRaises(RemainingScaleBytesNotEmptyException, obj.decode, JamBytes("0x"))
|
|
45
45
|
|
|
46
46
|
def test_compact_u32_1byte_encode(self):
|
|
47
|
-
obj =
|
|
47
|
+
obj = CompactDef(U32).new()
|
|
48
48
|
obj.decode(JamBytes("0x18"))
|
|
49
49
|
|
|
50
|
-
obj =
|
|
50
|
+
obj = CompactDef(U32).new()
|
|
51
51
|
obj.encode(6)
|
|
52
52
|
self.assertEqual(str(obj.data), "0x18")
|
|
53
53
|
|
|
54
54
|
def test_compact_u32_2bytes_encode(self):
|
|
55
|
-
obj =
|
|
55
|
+
obj = CompactDef(U32).new()
|
|
56
56
|
obj.encode(6000)
|
|
57
57
|
self.assertEqual(str(obj.data), "0xc15d")
|
|
58
58
|
|
|
59
59
|
def test_compact_u32_4bytes_encode(self):
|
|
60
60
|
|
|
61
|
-
obj =
|
|
61
|
+
obj = CompactDef(U32).new()
|
|
62
62
|
obj.encode(1000000)
|
|
63
63
|
self.assertEqual(str(obj.data), "0x02093d00")
|
|
64
64
|
|
|
65
65
|
def test_compact_u32_larger_than_4bytes_encode(self):
|
|
66
66
|
|
|
67
|
-
obj =
|
|
67
|
+
obj = CompactDef(U32).new()
|
|
68
68
|
obj.encode(150000000000000)
|
|
69
69
|
self.assertEqual(str(obj.data), "0x0b0060b7986c88")
|
|
70
70
|
|
|
@@ -72,10 +72,10 @@ class TestCompact(unittest.TestCase):
|
|
|
72
72
|
|
|
73
73
|
value = 2000001
|
|
74
74
|
|
|
75
|
-
obj =
|
|
75
|
+
obj = CompactDef(U32).new()
|
|
76
76
|
data = obj.encode(value)
|
|
77
77
|
|
|
78
|
-
obj =
|
|
78
|
+
obj = CompactDef(U32).new()
|
|
79
79
|
|
|
80
80
|
self.assertEqual(obj.decode(data), value)
|
|
81
81
|
|
|
@@ -83,10 +83,10 @@ class TestCompact(unittest.TestCase):
|
|
|
83
83
|
|
|
84
84
|
value = 2**30
|
|
85
85
|
|
|
86
|
-
obj =
|
|
86
|
+
obj = CompactDef(U32).new()
|
|
87
87
|
data = obj.encode(value)
|
|
88
88
|
|
|
89
|
-
obj =
|
|
89
|
+
obj = CompactDef(U32).new()
|
|
90
90
|
|
|
91
91
|
self.assertEqual(obj.decode(data), value)
|
|
92
92
|
|
|
@@ -96,7 +96,7 @@ class TestCompact(unittest.TestCase):
|
|
|
96
96
|
|
|
97
97
|
Balance = U128
|
|
98
98
|
|
|
99
|
-
obj =
|
|
99
|
+
obj = CompactDef(Balance).new()
|
|
100
100
|
data = obj.encode(value)
|
|
101
101
|
|
|
102
102
|
self.assertEqual(str(scale_data), str(data))
|
|
@@ -105,13 +105,13 @@ class TestCompact(unittest.TestCase):
|
|
|
105
105
|
|
|
106
106
|
def test_balance(self):
|
|
107
107
|
Balance = U128
|
|
108
|
-
obj =
|
|
108
|
+
obj = CompactDef(Balance).new()
|
|
109
109
|
obj.decode(JamBytes("0x130080cd103d71bc22"))
|
|
110
110
|
self.assertEqual(obj.value, 2503000000000000000)
|
|
111
111
|
|
|
112
112
|
def test_compact_no_type(self):
|
|
113
113
|
data = JamBytes("0x02093d00")
|
|
114
|
-
compact =
|
|
114
|
+
compact = CompactDef().new()
|
|
115
115
|
compact.decode(data)
|
|
116
116
|
self.assertEqual(compact.value, 1000000)
|
|
117
117
|
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import unittest
|
|
19
19
|
|
|
20
|
-
from jamcodec.types import Enum, Bool, U32
|
|
20
|
+
from jamcodec.types import Enum, Bool, U32, String
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
class TestEnum(unittest.TestCase):
|
|
@@ -60,6 +60,14 @@ class TestEnum(unittest.TestCase):
|
|
|
60
60
|
scale_obj.deserialize('None')
|
|
61
61
|
self.assertEqual(('None', None), scale_obj.value_object)
|
|
62
62
|
|
|
63
|
+
def test_enum_explicit_id(self):
|
|
64
|
+
scale_obj = Enum(Bool=Bool(), Number=U32, Error={'id': 255, 'type': String}).new()
|
|
65
|
+
jam_bytes = scale_obj.encode({'Error': 'test'})
|
|
66
|
+
self.assertEqual('0xff0474657374', jam_bytes.to_hex())
|
|
67
|
+
|
|
68
|
+
value = scale_obj.decode(jam_bytes)
|
|
69
|
+
self.assertEqual({'Error': 'test'}, value)
|
|
70
|
+
|
|
63
71
|
|
|
64
72
|
if __name__ == '__main__':
|
|
65
73
|
unittest.main()
|
|
@@ -24,14 +24,13 @@ from jamcodec.types import U32, Map, H256, Bytes
|
|
|
24
24
|
|
|
25
25
|
class TestMap(unittest.TestCase):
|
|
26
26
|
|
|
27
|
-
def
|
|
27
|
+
def test_map_dict_encode(self):
|
|
28
28
|
|
|
29
29
|
obj = Map(H256, Bytes).new()
|
|
30
30
|
|
|
31
31
|
value = {
|
|
32
32
|
"0xbb30a42c1e62f0afda5f0a4e8a562f7a13a24cea00ee81917b86b89e801314aa": b'\x01\x02',
|
|
33
|
-
"0x03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314": b'test'
|
|
34
|
-
|
|
33
|
+
"0x03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314": b'test'
|
|
35
34
|
}
|
|
36
35
|
# Should be encoded sorted by key
|
|
37
36
|
data = obj.encode(value)
|
|
@@ -40,6 +39,23 @@ class TestMap(unittest.TestCase):
|
|
|
40
39
|
data
|
|
41
40
|
)
|
|
42
41
|
|
|
42
|
+
def test_map_encode_list(self):
|
|
43
|
+
obj = Map(H256, Bytes).new()
|
|
44
|
+
|
|
45
|
+
value = [
|
|
46
|
+
("0xbb30a42c1e62f0afda5f0a4e8a562f7a13a24cea00ee81917b86b89e801314aa", b'\x01\x02'),
|
|
47
|
+
("0x03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314", b'test')
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
# Should be encoded sorted by key
|
|
51
|
+
data = obj.encode(value)
|
|
52
|
+
self.assertEqual(
|
|
53
|
+
JamBytes(
|
|
54
|
+
"0x0203170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c1113140474657374bb30a42c1e62f0afda5f0a4e8a562f7a13a24cea00ee81917b86b89e801314aa020102"
|
|
55
|
+
),
|
|
56
|
+
data
|
|
57
|
+
)
|
|
58
|
+
|
|
43
59
|
def test_map_decode(self):
|
|
44
60
|
obj = Map(U32, Bytes).new()
|
|
45
61
|
|
|
@@ -49,6 +65,8 @@ class TestMap(unittest.TestCase):
|
|
|
49
65
|
self.assertEqual({2: b'test'}, obj.to_serializable_obj())
|
|
50
66
|
|
|
51
67
|
|
|
68
|
+
|
|
69
|
+
|
|
52
70
|
def test_mapping_type(self):
|
|
53
71
|
|
|
54
72
|
class StorageMap(Mapping):
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import unittest
|
|
18
18
|
|
|
19
19
|
from jamcodec.base import JamBytes
|
|
20
|
-
from jamcodec.types import
|
|
20
|
+
from jamcodec.types import CompactDef, U32, U16, Tuple
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
class TestScaleTypes(unittest.TestCase):
|
|
@@ -29,19 +29,19 @@ class TestScaleTypes(unittest.TestCase):
|
|
|
29
29
|
self.assertEqual(obj.value, 64302)
|
|
30
30
|
|
|
31
31
|
def test_value_equals_value_serialized_and_value_object(self):
|
|
32
|
-
obj = Tuple(
|
|
32
|
+
obj = Tuple(CompactDef(U32), CompactDef(U32)).new()
|
|
33
33
|
obj.decode(JamBytes("0x0c00"))
|
|
34
34
|
self.assertEqual(obj.value, obj.value_serialized)
|
|
35
35
|
self.assertEqual(obj.value, obj.value_object)
|
|
36
36
|
|
|
37
37
|
def test_value_object(self):
|
|
38
|
-
obj = Tuple(
|
|
38
|
+
obj = Tuple(CompactDef(U32), CompactDef(U32)).new()
|
|
39
39
|
obj.decode(JamBytes("0x0c00"))
|
|
40
40
|
self.assertEqual(obj.value_object[0].value_object, 3)
|
|
41
41
|
self.assertEqual(obj.value_object[1].value_object, 0)
|
|
42
42
|
|
|
43
43
|
def test_value_object_shorthand(self):
|
|
44
|
-
obj = Tuple(
|
|
44
|
+
obj = Tuple(CompactDef(U32), CompactDef(U32)).new()
|
|
45
45
|
obj.decode(JamBytes("0x0c00"))
|
|
46
46
|
self.assertEqual(obj[0], 3)
|
|
47
47
|
self.assertEqual(obj[1], 0)
|
|
@@ -21,7 +21,7 @@ import unittest
|
|
|
21
21
|
|
|
22
22
|
from jamcodec.base import JamBytes
|
|
23
23
|
from jamcodec.exceptions import RemainingScaleBytesNotEmptyException
|
|
24
|
-
from jamcodec.types import
|
|
24
|
+
from jamcodec.types import CompactDef, U32, Array, U8, String
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
class TestScaleBytes(unittest.TestCase):
|
|
@@ -31,7 +31,7 @@ class TestScaleBytes(unittest.TestCase):
|
|
|
31
31
|
self.assertRaises(ValueError, JamBytes, 'test')
|
|
32
32
|
|
|
33
33
|
def test_bytes_data_format(self):
|
|
34
|
-
obj =
|
|
34
|
+
obj = CompactDef(U32).new()
|
|
35
35
|
obj.decode(JamBytes(b"\x02\x09\x3d\x00"))
|
|
36
36
|
self.assertEqual(obj.value, 1000000)
|
|
37
37
|
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
import unittest
|
|
19
19
|
|
|
20
20
|
from jamcodec.base import JamBytes
|
|
21
|
-
from jamcodec.types import Tuple,
|
|
21
|
+
from jamcodec.types import Tuple, CompactDef, U32, U8
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
class TestTuple(unittest.TestCase):
|
|
25
25
|
|
|
26
26
|
def test_tuple_decode(self):
|
|
27
|
-
obj = Tuple(
|
|
27
|
+
obj = Tuple(CompactDef(U32), CompactDef(U32)).new()
|
|
28
28
|
obj.decode(JamBytes("0x0c00"))
|
|
29
29
|
self.assertEqual(obj.value, (3, 0))
|
|
30
30
|
|
|
@@ -38,7 +38,7 @@ class TestTuple(unittest.TestCase):
|
|
|
38
38
|
self.assertEqual(value, scale_obj.value)
|
|
39
39
|
|
|
40
40
|
def test_tuple_deserialize(self):
|
|
41
|
-
obj = Tuple(
|
|
41
|
+
obj = Tuple(CompactDef(U32), CompactDef(U32)).new()
|
|
42
42
|
obj.deserialize((3, 2))
|
|
43
43
|
self.assertEqual(obj.value, (3, 2))
|
|
44
44
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|