Merge pull request #392 from nspcc-dev/fix/bug-append
VM: APPEND should push no value on stack. Fixes #391.
This commit is contained in:
commit
6855e4e07a
2 changed files with 50 additions and 5 deletions
11
pkg/vm/vm.go
11
pkg/vm/vm.go
|
@ -633,13 +633,14 @@ func (v *VM) execute(ctx *Context, op Instruction) {
|
||||||
arrElem := v.estack.Pop()
|
arrElem := v.estack.Pop()
|
||||||
|
|
||||||
switch t := arrElem.value.(type) {
|
switch t := arrElem.value.(type) {
|
||||||
case *ArrayItem, *StructItem:
|
case *ArrayItem:
|
||||||
arr := t.Value().([]StackItem)
|
arr := t.Value().([]StackItem)
|
||||||
arr = append(arr, itemElem.value)
|
arr = append(arr, itemElem.value)
|
||||||
v.estack.PushVal(arr)
|
t.value = arr
|
||||||
case *ByteArrayItem:
|
case *StructItem:
|
||||||
newVal := append(t.value, itemElem.value.Value().([]byte)...)
|
arr := t.Value().([]StackItem)
|
||||||
v.estack.PushVal(newVal)
|
arr = append(arr, itemElem.value)
|
||||||
|
t.value = arr
|
||||||
default:
|
default:
|
||||||
panic("APPEND: not of underlying type Array")
|
panic("APPEND: not of underlying type Array")
|
||||||
}
|
}
|
||||||
|
|
|
@ -444,6 +444,50 @@ func TestNEWSTRUCTWrongType(t *testing.T) {
|
||||||
assert.Equal(t, true, vm.state.HasFlag(faultState))
|
assert.Equal(t, true, vm.state.HasFlag(faultState))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAPPENDArray(t *testing.T) {
|
||||||
|
prog := makeProgram(DUP, PUSH5, APPEND)
|
||||||
|
vm := load(prog)
|
||||||
|
vm.estack.Push(&Element{value: &ArrayItem{}})
|
||||||
|
vm.Run()
|
||||||
|
assert.Equal(t, false, vm.state.HasFlag(faultState))
|
||||||
|
assert.Equal(t, 1, vm.estack.Len())
|
||||||
|
assert.Equal(t, &ArrayItem{[]StackItem{makeStackItem(5)}}, vm.estack.Pop().value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAPPENDStruct(t *testing.T) {
|
||||||
|
prog := makeProgram(DUP, PUSH5, APPEND)
|
||||||
|
vm := load(prog)
|
||||||
|
vm.estack.Push(&Element{value: &StructItem{}})
|
||||||
|
vm.Run()
|
||||||
|
assert.Equal(t, false, vm.state.HasFlag(faultState))
|
||||||
|
assert.Equal(t, 1, vm.estack.Len())
|
||||||
|
assert.Equal(t, &StructItem{[]StackItem{makeStackItem(5)}}, vm.estack.Pop().value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAPPENDBadNoArguments(t *testing.T) {
|
||||||
|
prog := makeProgram(APPEND)
|
||||||
|
vm := load(prog)
|
||||||
|
vm.Run()
|
||||||
|
assert.Equal(t, true, vm.state.HasFlag(faultState))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAPPENDBad1Argument(t *testing.T) {
|
||||||
|
prog := makeProgram(APPEND)
|
||||||
|
vm := load(prog)
|
||||||
|
vm.estack.PushVal(1)
|
||||||
|
vm.Run()
|
||||||
|
assert.Equal(t, true, vm.state.HasFlag(faultState))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAPPENDWrongType(t *testing.T) {
|
||||||
|
prog := makeProgram(APPEND)
|
||||||
|
vm := load(prog)
|
||||||
|
vm.estack.PushVal([]byte{})
|
||||||
|
vm.estack.PushVal(1)
|
||||||
|
vm.Run()
|
||||||
|
assert.Equal(t, true, vm.state.HasFlag(faultState))
|
||||||
|
}
|
||||||
|
|
||||||
func TestSIGNNoArgument(t *testing.T) {
|
func TestSIGNNoArgument(t *testing.T) {
|
||||||
prog := makeProgram(SIGN)
|
prog := makeProgram(SIGN)
|
||||||
vm := load(prog)
|
vm := load(prog)
|
||||||
|
|
Loading…
Reference in a new issue