From 2fd26287c56b93e0fd6531e8833f9068c5540793 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 15 Apr 2020 16:16:49 +0300 Subject: [PATCH] vm: update SUBSTR to NEO3 version This reverts commit 9ebb7930091647e8f331b15c26cf1535a991d160. --- pkg/vm/vm.go | 8 +------- pkg/vm/vm_test.go | 14 +++----------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 4b56d1f8f..ba11b3e80 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -615,15 +615,9 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro panic("negative index") } s := v.estack.Pop().Bytes() - if o > len(s) { - // panic("invalid offset") - // FIXME revert when NEO 3.0 https://github.com/nspcc-dev/neo-go/issues/477 - v.estack.PushVal("") - break - } last := l + o if last > len(s) { - last = len(s) + panic("invalid offset") } v.estack.PushVal(s[o:last]) diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index e1572e22e..7b911d5d8 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -2267,11 +2267,7 @@ func TestSUBSTRBadOffset(t *testing.T) { vm.estack.PushVal(7) vm.estack.PushVal(1) - // checkVMFailed(t, vm) - // FIXME revert when NEO 3.0 https://github.com/nspcc-dev/neo-go/issues/477 - runVM(t, vm) - assert.Equal(t, 1, vm.estack.Len()) - assert.Equal(t, []byte{}, vm.estack.Peek(0).Bytes()) + checkVMFailed(t, vm) } func TestSUBSTRBigLen(t *testing.T) { @@ -2280,9 +2276,7 @@ func TestSUBSTRBigLen(t *testing.T) { vm.estack.PushVal([]byte("abcdef")) vm.estack.PushVal(1) vm.estack.PushVal(6) - runVM(t, vm) - assert.Equal(t, 1, vm.estack.Len()) - assert.Equal(t, []byte("bcdef"), vm.estack.Pop().Bytes()) + checkVMFailed(t, vm) } func TestSUBSTRBad387(t *testing.T) { @@ -2293,9 +2287,7 @@ func TestSUBSTRBad387(t *testing.T) { vm.estack.PushVal(b) vm.estack.PushVal(1) vm.estack.PushVal(6) - runVM(t, vm) - assert.Equal(t, 1, vm.estack.Len()) - assert.Equal(t, []byte("bcdef"), vm.estack.Pop().Bytes()) + checkVMFailed(t, vm) } func TestSUBSTRBadNegativeOffset(t *testing.T) {