Skip to content

Commit

Permalink
fix compactfixedblobkind
Browse files Browse the repository at this point in the history
  • Loading branch information
laalaguer committed Nov 11, 2020
1 parent 36d1e2f commit e96231d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="thor-devkit",
version="1.0.5",
version="1.0.6",
author="laalaguer",
author_email="[email protected]",
description="SDK to interact with VeChain Thor public blockchain.",
Expand Down
7 changes: 6 additions & 1 deletion tests/test_rlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,17 @@ def test_noneableFixedBlobKind_decode():

def test_compact_fixed_blobkind_encode():
kind = m_rlp.CompactFixedBlobKind(4)
# zero leading
assert kind.serialize('0x00112233').hex() == '112233'

# zero in the middle
assert kind.serialize('0x11002233').hex() == '11002233'

def test_compact_fixed_blobkind_decode():
kind = m_rlp.CompactFixedBlobKind(4)
# should prefix the zeros
assert kind.deserialize(bytes([1])) == '0x00000001'
# should prefix the zeros, and the middle zeros should not interfer.
assert kind.deserialize(bytes.fromhex('110022')) == '0x00110022'


def test_compact_fixed_blobkind_encode_with_zero():
Expand Down
11 changes: 10 additions & 1 deletion thor_devkit/rlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,16 @@ def __init__(self, byte_length):

def serialize(self, obj: str) -> bytes:
b = super().serialize(obj)
b_list = [x for x in b if x != 0]
first_non_zero_index = -1
for idx, each in enumerate(b):
if each != 0:
first_non_zero_index = idx
break

b_list = []
if first_non_zero_index != -1:
b_list = b[first_non_zero_index:]

if (len(b_list) == 0):
return bytes(0)
else:
Expand Down

0 comments on commit e96231d

Please sign in to comment.