neotest: add API to check notification event

This commit is contained in:
Anna Shaleva 2021-11-16 17:40:01 +03:00
parent 4df5d370c5
commit 4057e635af

View file

@ -2,6 +2,7 @@ package neotest
import ( import (
"encoding/json" "encoding/json"
"fmt"
"strings" "strings"
"testing" "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) "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. // 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 { func (e *Executor) NewDeployTx(t *testing.T, bc blockchainer.Blockchainer, c *Contract, data interface{}) *transaction.Transaction {
rawManifest, err := json.Marshal(c.Manifest) rawManifest, err := json.Marshal(c.Manifest)