From 4057e635af6e772c15f38bdbb20db32f1d46eb06 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 16 Nov 2021 17:40:01 +0300 Subject: [PATCH] neotest: add API to check notification event --- pkg/neotest/basic.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/neotest/basic.go b/pkg/neotest/basic.go index a572fab53..854a907e2 100644 --- a/pkg/neotest/basic.go +++ b/pkg/neotest/basic.go @@ -2,6 +2,7 @@ package neotest import ( "encoding/json" + "fmt" "strings" "testing" @@ -144,6 +145,19 @@ func (e *Executor) CheckFault(t *testing.T, h util.Uint256, s string) { "expected: %s, got: %s", s, aer[0].FaultException) } +// CheckTxNotificationEvent checks that specified event was emitted at the specified position +// during transaction script execution. Negative index corresponds to backwards enumeration. +func (e *Executor) CheckTxNotificationEvent(t *testing.T, h util.Uint256, index int, expected state.NotificationEvent) { + aer, err := e.Chain.GetAppExecResults(h, trigger.Application) + require.NoError(t, err) + l := len(aer[0].Events) + if index < 0 { + index = l + index + } + require.True(t, 0 <= index && index < l, fmt.Errorf("notification index is out of range: want %d, len is %d", index, l)) + require.Equal(t, expected, aer[0].Events[index]) +} + // NewDeployTx returns new deployment tx for contract signed by committee. func (e *Executor) NewDeployTx(t *testing.T, bc blockchainer.Blockchainer, c *Contract, data interface{}) *transaction.Transaction { rawManifest, err := json.Marshal(c.Manifest)