Skip to content

Commit

Permalink
vm: fix order when pushing dictionaries with ScriptBuilder (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje authored Jan 12, 2024
1 parent c238d68 commit 3c52009
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion neo3/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3c52009

Please sign in to comment.