vm: update SUBSTR to NEO3 version

This reverts commit 9ebb793009.
This commit is contained in:
Evgenii Stratonikov 2020-04-15 16:16:49 +03:00
parent f5933c83c6
commit 2fd26287c5
2 changed files with 4 additions and 18 deletions

View file

@ -615,15 +615,9 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
panic("negative index") panic("negative index")
} }
s := v.estack.Pop().Bytes() 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 last := l + o
if last > len(s) { if last > len(s) {
last = len(s) panic("invalid offset")
} }
v.estack.PushVal(s[o:last]) v.estack.PushVal(s[o:last])

View file

@ -2267,11 +2267,7 @@ func TestSUBSTRBadOffset(t *testing.T) {
vm.estack.PushVal(7) vm.estack.PushVal(7)
vm.estack.PushVal(1) vm.estack.PushVal(1)
// checkVMFailed(t, vm) 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())
} }
func TestSUBSTRBigLen(t *testing.T) { func TestSUBSTRBigLen(t *testing.T) {
@ -2280,9 +2276,7 @@ func TestSUBSTRBigLen(t *testing.T) {
vm.estack.PushVal([]byte("abcdef")) vm.estack.PushVal([]byte("abcdef"))
vm.estack.PushVal(1) vm.estack.PushVal(1)
vm.estack.PushVal(6) vm.estack.PushVal(6)
runVM(t, vm) checkVMFailed(t, vm)
assert.Equal(t, 1, vm.estack.Len())
assert.Equal(t, []byte("bcdef"), vm.estack.Pop().Bytes())
} }
func TestSUBSTRBad387(t *testing.T) { func TestSUBSTRBad387(t *testing.T) {
@ -2293,9 +2287,7 @@ func TestSUBSTRBad387(t *testing.T) {
vm.estack.PushVal(b) vm.estack.PushVal(b)
vm.estack.PushVal(1) vm.estack.PushVal(1)
vm.estack.PushVal(6) vm.estack.PushVal(6)
runVM(t, vm) checkVMFailed(t, vm)
assert.Equal(t, 1, vm.estack.Len())
assert.Equal(t, []byte("bcdef"), vm.estack.Pop().Bytes())
} }
func TestSUBSTRBadNegativeOffset(t *testing.T) { func TestSUBSTRBadNegativeOffset(t *testing.T) {