Skip to content

Commit

Permalink
Modify list parameters handling in tx build
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoDashboard committed Apr 8, 2023
1 parent 84b931d commit b733fdd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 7 additions & 5 deletions neo3/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,13 @@ def emit_push(self, value) -> ScriptBuilder:
self.emit_raw(value)
return self
elif isinstance(value, Sequence):
self.emit(OpCode.NEWARRAY0)
for v in value:
self.emit(OpCode.DUP)
self.emit_push(v)
self.emit(OpCode.APPEND)
for item in reversed(value):
if isinstance(item, Sequence):
self.emit_push(item)
continue
self.emit_push(item)
self.emit_push(len(value))
self.emit(OpCode.PACK)
return self
elif isinstance(value, dict):
for k, v in value.items():
Expand Down
8 changes: 8 additions & 0 deletions tests/test_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ def test_emit_push_dict(self):
str(context.exception),
)

def test_emit_push_list(self):
data = ["a", 123, "b", 456]

sb = vm.ScriptBuilder()
sb.emit_push(data)
expected = "01c8010c0162007b0c016114c0"
self.assertEqual(expected, sb.to_array().hex())

def test_emit_push_unsupported(self):
class Unsupported:
pass
Expand Down

0 comments on commit b733fdd

Please sign in to comment.