From c596a6b273c837571914c1c088052846d0dd5eab Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 17 Dec 2019 14:01:15 +0300 Subject: [PATCH] vm: fix INVERT behaviour for converted values Tests added were failing before this change. --- pkg/vm/vm.go | 5 +++-- pkg/vm/vm_test.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 4c57ea3bc..1d36341b2 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -677,8 +677,9 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro // Bit operations. case opcode.INVERT: // inplace - a := v.estack.Peek(0).BigInt() - a.Not(a) + e := v.estack.Peek(0) + i := e.BigInt() + e.value = makeStackItem(i.Not(i)) case opcode.AND: b := v.estack.Pop().BigInt() diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index 838b1faf4..1bf8d1887 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -1759,6 +1759,20 @@ func TestINVERTgood3(t *testing.T) { assert.Equal(t, int64(-0x6A), vm.estack.Peek(0).BigInt().Int64()) } +func TestINVERTWithConversion1(t *testing.T) { + prog := makeProgram(opcode.PUSHDATA2, 0, 0, opcode.INVERT) + vm := load(prog) + runVM(t, vm) + assert.Equal(t, int64(-1), vm.estack.Peek(0).BigInt().Int64()) +} + +func TestINVERTWithConversion2(t *testing.T) { + prog := makeProgram(opcode.PUSH0, opcode.PUSH1, opcode.NUMEQUAL, opcode.INVERT) + vm := load(prog) + runVM(t, vm) + assert.Equal(t, int64(-1), vm.estack.Peek(0).BigInt().Int64()) +} + func TestCATBadNoArgs(t *testing.T) { prog := makeProgram(opcode.CAT) vm := load(prog)