From a3f419f8df723fa253670f4a14f22f7bd16bc97f Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 4 Aug 2020 12:03:31 +0300 Subject: [PATCH] emit: allow to emit Null --- pkg/vm/emit/emit.go | 7 +++++-- pkg/vm/emit/emit_test.go | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/vm/emit/emit.go b/pkg/vm/emit/emit.go index 0d3fbd38a..e2de1df46 100644 --- a/pkg/vm/emit/emit.go +++ b/pkg/vm/emit/emit.go @@ -79,8 +79,11 @@ func Array(w *io.BinWriter, es ...interface{}) { case bool: Bool(w, e) default: - w.Err = errors.New("unsupported type") - return + if es[i] != nil { + w.Err = errors.New("unsupported type") + return + } + Opcode(w, opcode.PUSHNULL) } } Int(w, int64(len(es))) diff --git a/pkg/vm/emit/emit_test.go b/pkg/vm/emit/emit_test.go index 67fec612d..ddda3e684 100644 --- a/pkg/vm/emit/emit_test.go +++ b/pkg/vm/emit/emit_test.go @@ -142,7 +142,7 @@ func TestBytes(t *testing.T) { func TestEmitArray(t *testing.T) { t.Run("good", func(t *testing.T) { buf := io.NewBufBinWriter() - Array(buf.BinWriter, int64(1), "str", true, []byte{0xCA, 0xFE}) + Array(buf.BinWriter, nil, int64(1), "str", true, []byte{0xCA, 0xFE}) require.NoError(t, buf.Err) res := buf.Bytes() @@ -154,6 +154,7 @@ func TestEmitArray(t *testing.T) { assert.EqualValues(t, 3, res[6]) assert.EqualValues(t, []byte("str"), res[7:10]) assert.EqualValues(t, opcode.PUSH1, res[10]) + assert.EqualValues(t, opcode.PUSHNULL, res[11]) }) t.Run("empty", func(t *testing.T) {