Replaces asserts for Exceptions in simulator

This commit is contained in:
Sergi Delgado Segura
2019-11-18 16:39:23 +00:00
parent a1c0eeadbc
commit 764e513ab9
2 changed files with 39 additions and 3 deletions

View File

@@ -31,9 +31,14 @@ def parse_varint(tx):
# First of all, the offset of the hex transaction if moved to the proper position (i.e where the varint should be
# located) and the length and format of the data to be analyzed is checked.
data = tx.hex[tx.offset :]
assert len(data) > 0
size = int(data[:2], 16)
assert size <= 255
if len(data) > 0:
size = int(data[:2], 16)
else:
raise ValueError("No data to be parsed")
if size > 255:
raise ValueError("Wrong value (varint size > 255)")
# Then, the integer is encoded as a varint using the proper prefix, if needed.
if size <= 252: # No prefix