forked from TrueCloudLab/neoneo-go
vm: make PICKITEM accept bytearrays
This commit is contained in:
parent
1881adabb9
commit
bafdb916a0
2 changed files with 37 additions and 1 deletions
|
@ -691,7 +691,12 @@ func (v *VM) execute(ctx *Context, op Instruction) {
|
||||||
item := arr[index]
|
item := arr[index]
|
||||||
v.estack.PushVal(item)
|
v.estack.PushVal(item)
|
||||||
default:
|
default:
|
||||||
panic("PICKITEM: unknown type")
|
arr := obj.Bytes()
|
||||||
|
if index < 0 || index >= len(arr) {
|
||||||
|
panic("PICKITEM: invalid index")
|
||||||
|
}
|
||||||
|
item := arr[index]
|
||||||
|
v.estack.PushVal(int(item))
|
||||||
}
|
}
|
||||||
|
|
||||||
case SETITEM:
|
case SETITEM:
|
||||||
|
|
|
@ -514,6 +514,37 @@ func TestAPPENDWrongType(t *testing.T) {
|
||||||
assert.Equal(t, true, vm.state.HasFlag(faultState))
|
assert.Equal(t, true, vm.state.HasFlag(faultState))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPICKITEMBadIndex(t *testing.T) {
|
||||||
|
prog := makeProgram(PICKITEM)
|
||||||
|
vm := load(prog)
|
||||||
|
vm.estack.PushVal([]StackItem{})
|
||||||
|
vm.estack.PushVal(0)
|
||||||
|
vm.Run()
|
||||||
|
assert.Equal(t, true, vm.state.HasFlag(faultState))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPICKITEMArray(t *testing.T) {
|
||||||
|
prog := makeProgram(PICKITEM)
|
||||||
|
vm := load(prog)
|
||||||
|
vm.estack.PushVal([]StackItem{makeStackItem(1), makeStackItem(2)})
|
||||||
|
vm.estack.PushVal(1)
|
||||||
|
vm.Run()
|
||||||
|
assert.Equal(t, false, vm.state.HasFlag(faultState))
|
||||||
|
assert.Equal(t, 1, vm.estack.Len())
|
||||||
|
assert.Equal(t, makeStackItem(2), vm.estack.Pop().value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPICKITEMByteArray(t *testing.T) {
|
||||||
|
prog := makeProgram(PICKITEM)
|
||||||
|
vm := load(prog)
|
||||||
|
vm.estack.PushVal([]byte{1, 2})
|
||||||
|
vm.estack.PushVal(1)
|
||||||
|
vm.Run()
|
||||||
|
assert.Equal(t, false, vm.state.HasFlag(faultState))
|
||||||
|
assert.Equal(t, 1, vm.estack.Len())
|
||||||
|
assert.Equal(t, makeStackItem(2), vm.estack.Pop().value)
|
||||||
|
}
|
||||||
|
|
||||||
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