From 7a15e649baa85c48fb142ef163af915363fbb692 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 14 Sep 2021 23:38:14 +0300 Subject: [PATCH] [#825] event/notaryPreparator: Add unit test for incorrect Main TX script Signed-off-by: Pavel Karpy --- pkg/morph/event/notary_preparator_test.go | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pkg/morph/event/notary_preparator_test.go b/pkg/morph/event/notary_preparator_test.go index 959434f34..7ed3dc92a 100644 --- a/pkg/morph/event/notary_preparator_test.go +++ b/pkg/morph/event/notary_preparator_test.go @@ -60,6 +60,45 @@ func (b blockCounter) BlockCount() (res uint32, err error) { return b.epoch, b.err } +func TestPrepare_IncorrectScript(t *testing.T) { + preparator := notaryPreparator( + PreparatorPrm{ + alphaKeysSource(), + blockCounter{100, nil}, + }, + ) + + t.Run("not contract call", func(t *testing.T) { + bw := io.NewBufBinWriter() + + emit.Int(bw.BinWriter, 4) + emit.String(bw.BinWriter, "test") + emit.Bytes(bw.BinWriter, scriptHash.BytesBE()) + emit.Syscall(bw.BinWriter, interopnames.SystemCallbackInvoke) + + nr := correctNR(bw.Bytes()) + + _, err := preparator.Prepare(nr) + + require.EqualError(t, err, errNotContractCall.Error()) + }) + + t.Run("incorrect ", func(t *testing.T) { + bw := io.NewBufBinWriter() + + emit.Int(bw.BinWriter, -1) + emit.String(bw.BinWriter, "test") + emit.Bytes(bw.BinWriter, scriptHash.BytesBE()) + emit.Syscall(bw.BinWriter, interopnames.SystemContractCall) + + nr := correctNR(bw.Bytes()) + + _, err := preparator.Prepare(nr) + + require.EqualError(t, err, errIncorrectCallFlag.Error()) + }) +} + func TestPrepare_IncorrectNR(t *testing.T) { type ( mTX struct {