diff --git a/cli/util/util_test.go b/cli/util/util_test.go index 3a32302cd..b1980ae40 100644 --- a/cli/util/util_test.go +++ b/cli/util/util_test.go @@ -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)) } } diff --git a/internal/testcli/executor.go b/internal/testcli/executor.go index d29a8d026..2fec7f8b1 100644 --- a/internal/testcli/executor.go +++ b/internal/testcli/executor.go @@ -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)