From 522c6dcbfa4de56eb295a6d8103c466e86da0490 Mon Sep 17 00:00:00 2001 From: ixje Date: Fri, 29 Sep 2023 09:47:44 +0200 Subject: [PATCH] vm: allow pushing empty strings (#284) --- neo3/vm.py | 2 -- tests/test_vm.py | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/neo3/vm.py b/neo3/vm.py index 3d8cab45..8ac42152 100644 --- a/neo3/vm.py +++ b/neo3/vm.py @@ -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" diff --git a/tests/test_vm.py b/tests/test_vm.py index 38010a14..61c59e74 100644 --- a/tests/test_vm.py +++ b/tests/test_vm.py @@ -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( @@ -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()