From 781def735d1199b24b99f98e4a896121f646c4b3 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 20 May 2020 16:37:00 +0300 Subject: [PATCH] vm: use Null item as a default value for Array/Struct elements --- pkg/vm/vm.go | 4 ++-- pkg/vm/vm_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index b860cec42..f05a8259a 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -993,7 +993,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro if n > MaxArraySize { panic("too long array") } - typ := BooleanT + typ := AnyT if op == opcode.NEWARRAYT { typ = StackItemType(parameter[0]) } @@ -1018,7 +1018,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro if n > MaxArraySize { panic("too long struct") } - items := makeArrayOfType(int(n), BooleanT) + items := makeArrayOfType(int(n), AnyT) v.estack.PushVal(&StructItem{items}) } diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index da504ae45..b00069f14 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -1188,7 +1188,7 @@ func TestNEWARRAYArray(t *testing.T) { prog := makeProgram(opcode.NEWARRAY) t.Run("ByteArray", getTestFuncForVM(prog, NewArrayItem([]StackItem{}), []byte{})) t.Run("BadSize", getTestFuncForVM(prog, nil, MaxArraySize+1)) - t.Run("Integer", getTestFuncForVM(prog, []StackItem{NewBoolItem(false)}, 1)) + t.Run("Integer", getTestFuncForVM(prog, []StackItem{NullItem{}}, 1)) arr := []StackItem{makeStackItem(42)} t.Run("Array", getTestFuncForVM(prog, arr, arr)) @@ -1206,7 +1206,7 @@ func testNEWARRAYIssue437(t *testing.T, i1, i2 opcode.Opcode, appended bool) { vm := load(prog) vm.Run() - arr := makeArrayOfType(4, BooleanT) + arr := makeArrayOfType(4, AnyT) arr[2] = makeStackItem(3) arr[3] = makeStackItem(4) if appended { @@ -1247,7 +1247,7 @@ func TestNEWSTRUCT(t *testing.T) { prog := makeProgram(opcode.NEWSTRUCT) t.Run("ByteArray", getTestFuncForVM(prog, NewStructItem([]StackItem{}), []byte{})) t.Run("BadSize", getTestFuncForVM(prog, nil, MaxArraySize+1)) - t.Run("Integer", getTestFuncForVM(prog, NewStructItem([]StackItem{NewBoolItem(false)}), 1)) + t.Run("Integer", getTestFuncForVM(prog, NewStructItem([]StackItem{NullItem{}}), 1)) arr := []StackItem{makeStackItem(42)} t.Run("Array", getTestFuncForVM(prog, NewStructItem(arr), NewArrayItem(arr)))