Skip to content

Commit

Permalink
vm: allow pushing empty strings (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje authored Sep 29, 2023
1 parent 4ac098c commit 522c6dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 0 additions & 2 deletions neo3/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,6 @@ def emit_push(self, value) -> ScriptBuilder:
raise ValueError("Input number exceeds maximum data size of 32 bytes")
elif isinstance(value, (bytes, bytearray)):
len_value = len(value)
if len_value == 0:
raise ValueError("Cannot push zero sized data")
if len_value > 0xFFFFFFFF:
raise ValueError(
f"Value is too long {len_value}. Maximum allowed length is 0xFFFF_FFFF"
Expand Down
10 changes: 5 additions & 5 deletions tests/test_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def test_emit_push_strings(self):
expected = "0c0cd0bfd180d0b8d0b2d0b5d182"
self.assertEqual(expected, sb.to_array().hex())

sb = vm.ScriptBuilder()
sb.emit_push("")
expected = "0c00"
self.assertEqual(expected, sb.to_array().hex())

def test_emit_push_uint(self):
sb = vm.ScriptBuilder()
sb.emit_push(
Expand Down Expand Up @@ -126,11 +131,6 @@ def test_emit_push_bytes(self):
expected_header = bytes.fromhex("0e01000100")
self.assertEqual(expected_header + data, sb.to_array())

sb = vm.ScriptBuilder()
with self.assertRaises(ValueError) as context:
sb.emit_push(b"")
self.assertEqual("Cannot push zero sized data", str(context.exception))

# too slow
# data = b'\x01' * (0xFFFFFFFF + 1)
# sb = vm.ScriptBuilder()
Expand Down

0 comments on commit 522c6dc

Please sign in to comment.