From f0beb4abc95e3264bf7e3864838c26cbe3366b9a Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 13 Sep 2021 12:02:32 +0300 Subject: [PATCH] [#825] event/notaryPreparator: Add args checking unit test Signed-off-by: Pavel Karpy --- pkg/morph/event/notary_preparator_test.go | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/morph/event/notary_preparator_test.go b/pkg/morph/event/notary_preparator_test.go index c18d5c72..f1d6b924 100644 --- a/pkg/morph/event/notary_preparator_test.go +++ b/pkg/morph/event/notary_preparator_test.go @@ -4,6 +4,8 @@ import ( "encoding/binary" "testing" + "github.com/nspcc-dev/neo-go/pkg/vm" + "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" @@ -89,6 +91,32 @@ func TestPrepare_CorrectNR(t *testing.T) { require.NoError(t, err) require.Equal(t, test.method, event.Type().String()) require.Equal(t, test.hash.StringLE(), event.ScriptHash().StringLE()) + + // check args parsing + bw := io.NewBufBinWriter() + emit.Array(bw.BinWriter, test.args...) + + ctx := vm.NewContext(bw.Bytes()) + + opCode, param, err := ctx.Next() + require.NoError(t, err) + + for _, opGot := range event.Params() { + require.Equal(t, opCode, opGot.code) + require.Equal(t, param, opGot.param) + + opCode, param, err = ctx.Next() + require.NoError(t, err) + } + + _, _, err = ctx.Next() // PACK opcode + require.NoError(t, err) + _, _, err = ctx.Next() // packing len opcode + require.NoError(t, err) + + opCode, _, err = ctx.Next() + require.NoError(t, err) + require.Equal(t, opcode.RET, opCode) } }