diff --git a/neo3/vm.py b/neo3/vm.py index 8ac4215..450b5e4 100644 --- a/neo3/vm.py +++ b/neo3/vm.py @@ -388,9 +388,12 @@ def emit_push(self, value) -> ScriptBuilder: elif isinstance(value, dict): for k, v in value.items(): # This restriction exists on the VM side where keys to a 'Map' may only be of 'PrimitiveType' - if not isinstance(k, (int, str, bool)): + if not isinstance( + k, (int, str, bool, bytes, serialization.ISerializable) + ): raise ValueError( - f"Unsupported key type {type(k)}. Supported types by the VM are bool, int and str" + f"Unsupported key type {type(k)}. " + f"Supported types by the VM are bool, int, str, bytes or ISerializable" ) self.emit_push(v) self.emit_push(k) diff --git a/tests/test_vm.py b/tests/test_vm.py index 61c59e7..68d8ee5 100644 --- a/tests/test_vm.py +++ b/tests/test_vm.py @@ -146,12 +146,18 @@ def test_emit_push_dict(self): expected = "007b0c016101c8010c016212be" self.assertEqual(expected, sb.to_array().hex()) + data = {b"\x01": 1, b"\x02": 2} + sb = vm.ScriptBuilder() + sb.emit_push(data) + expected = "110c0101120c010212be" + self.assertEqual(expected, sb.to_array().hex()) + # test invalid key type sb = vm.ScriptBuilder() with self.assertRaises(ValueError) as context: sb.emit_push({1.0: "abc"}) self.assertEqual( - "Unsupported key type . Supported types by the VM are bool, int and str", + "Unsupported key type . Supported types by the VM are bool, int, str, bytes or ISerializable", str(context.exception), )