From a06fbae0eea3e9878859e81c3856023a41d27985 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 18 Nov 2021 12:14:53 +0300 Subject: [PATCH] neotest: extend Executor with InvokeScript* helpers It is useful for tests and allows to omit code duplication. --- pkg/neotest/basic.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pkg/neotest/basic.go b/pkg/neotest/basic.go index 422c967be..d1ed1c6e1 100644 --- a/pkg/neotest/basic.go +++ b/pkg/neotest/basic.go @@ -135,6 +135,31 @@ func (e *Executor) DeployContract(t *testing.T, c *Contract, data interface{}) u return tx.Hash() } +// InvokeScript adds transaction with the specified script to the chain and +// returns its hash. It does no faults check. +func (e *Executor) InvokeScript(t *testing.T, script []byte, signers []Signer) util.Uint256 { + tx := transaction.New(script, 0) + tx.Nonce = Nonce() + tx.ValidUntilBlock = e.Chain.BlockHeight() + 1 + e.SignTx(t, tx, -1, signers...) + e.AddNewBlock(t, tx) + return tx.Hash() +} + +// InvokeScriptCheckHALT adds transaction with the specified script to the chain +// and checks it's HALTed with the specified items on stack. +func (e *Executor) InvokeScriptCheckHALT(t *testing.T, script []byte, signers []Signer, stack ...stackitem.Item) { + hash := e.InvokeScript(t, script, signers) + e.CheckHalt(t, hash, stack...) +} + +// InvokeScriptCheckFAULT adds transaction with the specified script to the +// chain and checks it's FAULTed with the specified error. +func (e *Executor) InvokeScriptCheckFAULT(t *testing.T, script []byte, signers []Signer, errMessage string) { + hash := e.InvokeScript(t, script, signers) + e.CheckFault(t, hash, errMessage) +} + // CheckHalt checks that transaction persisted with HALT state. func (e *Executor) CheckHalt(t *testing.T, h util.Uint256, stack ...stackitem.Item) *state.AppExecResult { aer, err := e.Chain.GetAppExecResults(h, trigger.Application)