diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 006511f31..666e2f30b 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -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") } diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index af82328f9..1d0e107d2 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -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) {