From 3c520096c79d2bd224a30a055818ae1c266ec086 Mon Sep 17 00:00:00 2001 From: ixje Date: Fri, 12 Jan 2024 10:10:23 +0100 Subject: [PATCH] vm: fix order when pushing dictionaries with `ScriptBuilder` (#300) --- neo3/vm.py | 2 +- tests/test_vm.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/neo3/vm.py b/neo3/vm.py index f3ef2f2..adc1742 100644 --- a/neo3/vm.py +++ b/neo3/vm.py @@ -402,7 +402,7 @@ def emit_push(self, value) -> ScriptBuilder: self.emit(OpCode.PACK) return self elif isinstance(value, dict): - for k, v in value.items(): + for k, v in reversed(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, bytes, serialization.ISerializable) diff --git a/tests/test_vm.py b/tests/test_vm.py index dcee90a..e042c41 100644 --- a/tests/test_vm.py +++ b/tests/test_vm.py @@ -143,13 +143,13 @@ def test_emit_push_dict(self): sb = vm.ScriptBuilder() sb.emit_push(data) - expected = "007b0c016101c8010c016212be" + expected = "01c8010c0162007b0c016112be" self.assertEqual(expected, sb.to_array().hex()) data = {b"\x01": 1, b"\x02": 2} sb = vm.ScriptBuilder() sb.emit_push(data) - expected = "110c0101120c010212be" + expected = "120c0102110c010112be" self.assertEqual(expected, sb.to_array().hex()) # test invalid key type