cli: ensure all outcomes are handled in TestAwaitUtilCancelTx

Close #3365.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2024-04-03 16:40:11 +03:00
parent be1b97d04e
commit b6a9c64c55
2 changed files with 17 additions and 5 deletions

View file

@ -4,12 +4,14 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"time"
"github.com/nspcc-dev/neo-go/internal/testcli"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
"github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/stretchr/testify/require"
)
@ -170,11 +172,21 @@ func TestAwaitUtilCancelTx(t *testing.T) {
// Allow both cases: either target or conflicting tx acceptance.
e.In.WriteString("one\r")
err = e.RunOrError(t, fmt.Sprintf("target transaction %s is accepted", txHash), append(args, txHash.StringLE())...)
if err == nil {
err = e.RunUnchecked(t, append(args, txHash.StringLE())...)
switch {
case err == nil:
response := e.GetNextLine(t)
require.Equal(t, "Conflicting transaction accepted", response)
resHash, _ := e.CheckAwaitableTxPersisted(t)
require.NotEqual(t, resHash, txHash)
case strings.Contains(err.Error(), fmt.Sprintf("target transaction %s is accepted", txHash)) ||
strings.Contains(err.Error(), fmt.Sprintf("failed to send conflicting transaction: Invalid transaction attribute (-507) - invalid attribute: conflicting transaction %s is already on chain", txHash)):
tx, _ := e.GetTransaction(t, txHash)
aer, err := e.Chain.GetAppExecResults(tx.Hash(), trigger.Application)
require.NoError(t, err)
require.Equal(t, 1, len(aer))
require.Equal(t, vmstate.Halt, aer[0].VMState)
default:
t.Fatal(fmt.Errorf("unexpected error: %w", err))
}
}

View file

@ -287,12 +287,12 @@ func (e *Executor) Run(t *testing.T, args ...string) {
checkExit(t, ch, 0)
}
// RunOrError runs command and checks that if there was an error, then its text matches the provided one.
func (e *Executor) RunOrError(t *testing.T, errText string, args ...string) error {
// RunUnchecked runs command and ensures that proper exit code is set (0 if no error is returned, 1 is an error is returned).
// The resulting error is returned (if so).
func (e *Executor) RunUnchecked(t *testing.T, args ...string) error {
ch := setExitFunc()
err := e.run(args...)
if err != nil {
require.True(t, strings.Contains(err.Error(), errText))
checkExit(t, ch, 1)
} else {
checkExit(t, ch, 0)