jamcodec 0.1.1__tar.gz → 0.1.2__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.
Files changed (37) hide show
  1. {jamcodec-0.1.1 → jamcodec-0.1.2}/PKG-INFO +5 -4
  2. {jamcodec-0.1.1 → jamcodec-0.1.2}/README.md +2 -2
  3. {jamcodec-0.1.1 → jamcodec-0.1.2}/jamcodec/types.py +7 -7
  4. {jamcodec-0.1.1 → jamcodec-0.1.2}/jamcodec.egg-info/PKG-INFO +5 -4
  5. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_compact.py +17 -17
  6. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_map.py +21 -3
  7. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_scale_types.py +4 -4
  8. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_scalebytes.py +2 -2
  9. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_tuple.py +3 -3
  10. {jamcodec-0.1.1 → jamcodec-0.1.2}/LICENSE +0 -0
  11. {jamcodec-0.1.1 → jamcodec-0.1.2}/jamcodec/__init__.py +0 -0
  12. {jamcodec-0.1.1 → jamcodec-0.1.2}/jamcodec/base.py +0 -0
  13. {jamcodec-0.1.1 → jamcodec-0.1.2}/jamcodec/constants.py +0 -0
  14. {jamcodec-0.1.1 → jamcodec-0.1.2}/jamcodec/exceptions.py +0 -0
  15. {jamcodec-0.1.1 → jamcodec-0.1.2}/jamcodec/mixins.py +0 -0
  16. {jamcodec-0.1.1 → jamcodec-0.1.2}/jamcodec.egg-info/SOURCES.txt +0 -0
  17. {jamcodec-0.1.1 → jamcodec-0.1.2}/jamcodec.egg-info/dependency_links.txt +0 -0
  18. {jamcodec-0.1.1 → jamcodec-0.1.2}/jamcodec.egg-info/requires.txt +0 -0
  19. {jamcodec-0.1.1 → jamcodec-0.1.2}/jamcodec.egg-info/top_level.txt +0 -0
  20. {jamcodec-0.1.1 → jamcodec-0.1.2}/pyproject.toml +0 -0
  21. {jamcodec-0.1.1 → jamcodec-0.1.2}/requirements.txt +0 -0
  22. {jamcodec-0.1.1 → jamcodec-0.1.2}/setup.cfg +0 -0
  23. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_array.py +0 -0
  24. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_bitarray.py +0 -0
  25. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_bitvec.py +0 -0
  26. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_boolean.py +0 -0
  27. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_bytes.py +0 -0
  28. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_enum.py +0 -0
  29. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_float.py +0 -0
  30. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_hashmap.py +0 -0
  31. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_integer.py +0 -0
  32. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_mixins.py +0 -0
  33. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_option.py +0 -0
  34. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_string.py +0 -0
  35. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_struct.py +0 -0
  36. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_varint.py +0 -0
  37. {jamcodec-0.1.1 → jamcodec-0.1.2}/test/test_vec.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: jamcodec
3
- Version: 0.1.1
3
+ Version: 0.1.2
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, Compact, Tuple, Enum
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=Compact(U8)),
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, Compact, Tuple, Enum
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=Compact(U8)),
36
+ Complex=Struct(data=String(), version=VarInt64),
37
37
  None_=None
38
38
  ).new()
39
39
  value = {'Bool': True}
@@ -508,7 +508,7 @@ class Option(JamCodecTypeDef):
508
508
  return None, self.some.example_value()
509
509
 
510
510
 
511
- class Compact(JamCodecTypeDef):
511
+ class CompactDef(JamCodecTypeDef):
512
512
  def __init__(self, type_: JamCodecTypeDef = None):
513
513
  self.type = type_
514
514
  self.compact_length = 0
@@ -595,7 +595,6 @@ class Vec(JamCodecTypeDef):
595
595
  self.type_def = type_def
596
596
 
597
597
  def encode(self, value: list) -> JamBytes:
598
-
599
598
  if self.type_def is U8:
600
599
  return Bytes.encode(value)
601
600
 
@@ -959,8 +958,11 @@ class Map(JamCodecTypeDef):
959
958
  def encode(self, value: Union[typing.Mapping, list]) -> JamBytes:
960
959
 
961
960
  if isinstance(value, Mapping):
962
- # Sort Map by keys
963
- value = sorted(value.items(), key=lambda x: x[0])
961
+ # Convert to list
962
+ value = value.items()
963
+
964
+ # Sort Map by keys
965
+ value = sorted(value, key=lambda x: x[0])
964
966
 
965
967
  # Encode length of Vec
966
968
  data = VarInt64.encode(len(value))
@@ -1137,9 +1139,6 @@ class HashDef(JamCodecTypeDef):
1137
1139
 
1138
1140
  class VarInt64Def(JamCodecTypeDef):
1139
1141
 
1140
- def encode(self, value: any, external_call=True) -> JamBytes:
1141
- return self.encode(value)
1142
-
1143
1142
  def encode(self, value: int) -> JamBytes:
1144
1143
  if value < 0:
1145
1144
  raise ScaleEncodeException("Cannot encode negative value")
@@ -1235,3 +1234,4 @@ Hash = H256
1235
1234
  HashMap = Map
1236
1235
  BTreeMap = Map
1237
1236
  VarInt64 = VarInt64Def()
1237
+ Compact = CompactDef()
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: jamcodec
3
- Version: 0.1.1
3
+ Version: 0.1.2
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, Compact, Tuple, Enum
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=Compact(U8)),
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 Compact, U32, U128
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 = Compact(U32).new()
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 = Compact(U32).new()
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 = Compact(U32).new()
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 = Compact(U32).new()
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 = Compact(U32).new()
47
+ obj = CompactDef(U32).new()
48
48
  obj.decode(JamBytes("0x18"))
49
49
 
50
- obj = Compact(U32).new()
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 = Compact(U32).new()
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 = Compact(U32).new()
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 = Compact(U32).new()
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 = Compact(U32).new()
75
+ obj = CompactDef(U32).new()
76
76
  data = obj.encode(value)
77
77
 
78
- obj = Compact(U32).new()
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 = Compact(U32).new()
86
+ obj = CompactDef(U32).new()
87
87
  data = obj.encode(value)
88
88
 
89
- obj = Compact(U32).new()
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 = Compact(Balance).new()
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 = Compact(Balance).new()
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 = Compact().new()
114
+ compact = CompactDef().new()
115
115
  compact.decode(data)
116
116
  self.assertEqual(compact.value, 1000000)
117
117
 
@@ -24,14 +24,13 @@ from jamcodec.types import U32, Map, H256, Bytes
24
24
 
25
25
  class TestMap(unittest.TestCase):
26
26
 
27
- def test_map_encode(self):
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 Compact, U32, U16, Tuple
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(Compact(U32), Compact(U32)).new()
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(Compact(U32), Compact(U32)).new()
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(Compact(U32), Compact(U32)).new()
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 Compact, U32, Array, U8, String
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 = Compact(U32).new()
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, Compact, U32, U8
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(Compact(U32), Compact(U32)).new()
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(Compact(U32), Compact(U32)).new()
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