diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index a7d9e4c3b..a8c1df58c 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -499,8 +499,8 @@ func (v *VM) execute(ctx *Context, op Instruction) { v.estack.PushVal(!x) case NZ: - panic("todo NZ") - // x := v.estack.Pop().BigInt() + x := v.estack.Pop().BigInt() + v.estack.PushVal(x.Cmp(big.NewInt(0)) != 0) // Object operations. case NEWARRAY: diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index 257271056..6658fadd1 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -231,6 +231,24 @@ func TestSimpleCall(t *testing.T) { assert.Equal(t, result, int(vm.estack.Pop().BigInt().Int64())) } +func TestNZtrue(t *testing.T) { + prog := makeProgram(NZ) + vm := load(prog) + vm.estack.PushVal(1) + vm.Run() + assert.Equal(t, false, vm.state.HasFlag(faultState)) + assert.Equal(t, true, vm.estack.Pop().Bool()) +} + +func TestNZfalse(t *testing.T) { + prog := makeProgram(NZ) + vm := load(prog) + vm.estack.PushVal(0) + vm.Run() + assert.Equal(t, false, vm.state.HasFlag(faultState)) + assert.Equal(t, false, vm.estack.Pop().Bool()) +} + func makeProgram(opcodes ...Instruction) []byte { prog := make([]byte, len(opcodes)+1) // RET for i := 0; i < len(opcodes); i++ {