forked from TrueCloudLab/neoneo-go
vm: allow HASKEY on byte-arrays
Current neo-vm master has them https://github.com/neo-project/neo-vm/blob/master/src/neo-vm/ExecutionEngine.cs#L1157
Were silently added in
029466fa9d
.
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
39866b8512
commit
32f4404954
2 changed files with 9 additions and 2 deletions
|
@ -1461,12 +1461,12 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
res = index < len(c.Array())
|
||||
case *stackitem.Map:
|
||||
res = t.Has(key.Item())
|
||||
case *stackitem.Buffer:
|
||||
case *stackitem.Buffer, *stackitem.ByteArray:
|
||||
index := toInt(key.BigInt())
|
||||
if index < 0 {
|
||||
panic("negative index")
|
||||
}
|
||||
res = index < t.Len()
|
||||
res = index < len(t.Value().([]byte))
|
||||
default:
|
||||
panic("wrong collection type")
|
||||
}
|
||||
|
|
|
@ -1435,6 +1435,13 @@ func TestHASKEY(t *testing.T) {
|
|||
t.Run("False", getTestFuncForVM(prog, false, stackitem.NewBuffer([]byte{5, 5, 5}), 3))
|
||||
t.Run("Negative", getTestFuncForVM(prog, nil, stackitem.NewBuffer([]byte{5, 5, 5}), -1))
|
||||
})
|
||||
|
||||
t.Run("ByteArray", func(t *testing.T) {
|
||||
t.Run("True", getTestFuncForVM(prog, true, stackitem.NewByteArray([]byte{5, 5, 5}), 2))
|
||||
t.Run("too big", getTestFuncForVM(prog, nil, stackitem.NewByteArray([]byte{5, 5, 5}), maxu64Plus(2)))
|
||||
t.Run("False", getTestFuncForVM(prog, false, stackitem.NewByteArray([]byte{5, 5, 5}), 3))
|
||||
t.Run("Negative", getTestFuncForVM(prog, nil, stackitem.NewByteArray([]byte{5, 5, 5}), -1))
|
||||
})
|
||||
}
|
||||
|
||||
func TestHASKEYMap(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue