mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 03:38:35 +00:00
vm: implement the NZ opcode
This commit is contained in:
parent
bcd81bcfb2
commit
fcf9c1213b
2 changed files with 20 additions and 2 deletions
|
@ -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:
|
||||
|
|
|
@ -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++ {
|
||||
|
|
Loading…
Reference in a new issue