vm: convert SIZE argument to bytearray
This commit is contained in:
parent
9780889239
commit
9eca5ee317
2 changed files with 28 additions and 4 deletions
|
@ -759,10 +759,7 @@ func (v *VM) execute(ctx *Context, op Instruction) {
|
|||
|
||||
case SIZE:
|
||||
elem := v.estack.Pop()
|
||||
arr, ok := elem.value.Value().([]uint8)
|
||||
if !ok {
|
||||
panic("SIZE: item not of type []uint8")
|
||||
}
|
||||
arr := elem.Bytes()
|
||||
v.estack.PushVal(len(arr))
|
||||
|
||||
case JMP, JMPIF, JMPIFNOT:
|
||||
|
|
|
@ -549,6 +549,33 @@ func TestPICKITEMByteArray(t *testing.T) {
|
|||
assert.Equal(t, makeStackItem(2), vm.estack.Pop().value)
|
||||
}
|
||||
|
||||
func TestSIZENoArgument(t *testing.T) {
|
||||
prog := makeProgram(SIZE)
|
||||
vm := load(prog)
|
||||
vm.Run()
|
||||
assert.Equal(t, true, vm.state.HasFlag(faultState))
|
||||
}
|
||||
|
||||
func TestSIZEByteArray(t *testing.T) {
|
||||
prog := makeProgram(SIZE)
|
||||
vm := load(prog)
|
||||
vm.estack.PushVal([]byte{0, 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 TestSIZEBool(t *testing.T) {
|
||||
prog := makeProgram(SIZE)
|
||||
vm := load(prog)
|
||||
vm.estack.PushVal(false)
|
||||
vm.Run()
|
||||
assert.Equal(t, false, vm.state.HasFlag(faultState))
|
||||
assert.Equal(t, 1, vm.estack.Len())
|
||||
assert.Equal(t, makeStackItem(1), vm.estack.Pop().value)
|
||||
}
|
||||
|
||||
func TestSIGNNoArgument(t *testing.T) {
|
||||
prog := makeProgram(SIGN)
|
||||
vm := load(prog)
|
||||
|
|
Loading…
Reference in a new issue