vm: implement PUSHNULL opcode

This commit is contained in:
Evgenii Stratonikov 2020-03-23 11:58:41 +03:00
parent e50b529631
commit 3db030bbb6
3 changed files with 13 additions and 0 deletions

View file

@ -89,6 +89,7 @@ const (
PUSHDATA2 Opcode = 0x4D
PUSHDATA4 Opcode = 0x4E
PUSHM1 Opcode = 0x4F
PUSHNULL Opcode = 0x50
PUSH1 Opcode = 0x51
PUSHT Opcode = PUSH1
PUSH2 Opcode = 0x52

View file

@ -560,6 +560,9 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
case opcode.PUSHDATA1, opcode.PUSHDATA2, opcode.PUSHDATA4:
v.estack.PushVal(parameter)
case opcode.PUSHNULL:
v.estack.PushVal(NullItem{})
// Stack operations.
case opcode.TOALTSTACK:
v.astack.Push(v.estack.Pop())

View file

@ -197,6 +197,15 @@ func TestStackLimitPUSH1Bad(t *testing.T) {
checkVMFailed(t, v)
}
func TestPUSHNULL(t *testing.T) {
prog := makeProgram(opcode.PUSHNULL, opcode.PUSHNULL, opcode.EQUAL)
v := load(prog)
require.NoError(t, v.Step())
require.Equal(t, 1, v.estack.Len())
runVM(t, v)
require.True(t, v.estack.Pop().Bool())
}
// appendBigStruct returns a program which:
// 1. pushes size Structs on stack
// 2. packs them into a new struct