Merge pull request #3395 from nspcc-dev/fix-awaitabletxtest

cli: ensure all outcomes are handled in TestAwaitUtilCancelTx
This commit is contained in:
Roman Khimov 2024-04-03 17:55:35 +03:00 committed by GitHub
commit 0280ceefe6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 5 deletions

View file

@ -4,12 +4,14 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"testing" "testing"
"time" "time"
"github.com/nspcc-dev/neo-go/internal/testcli" "github.com/nspcc-dev/neo-go/internal/testcli"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/nspcc-dev/neo-go/pkg/util" "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/nspcc-dev/neo-go/pkg/wallet"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -170,11 +172,21 @@ func TestAwaitUtilCancelTx(t *testing.T) {
// Allow both cases: either target or conflicting tx acceptance. // Allow both cases: either target or conflicting tx acceptance.
e.In.WriteString("one\r") e.In.WriteString("one\r")
err = e.RunOrError(t, fmt.Sprintf("target transaction %s is accepted", txHash), append(args, txHash.StringLE())...) err = e.RunUnchecked(t, append(args, txHash.StringLE())...)
if err == nil { switch {
case err == nil:
response := e.GetNextLine(t) response := e.GetNextLine(t)
require.Equal(t, "Conflicting transaction accepted", response) require.Equal(t, "Conflicting transaction accepted", response)
resHash, _ := e.CheckAwaitableTxPersisted(t) resHash, _ := e.CheckAwaitableTxPersisted(t)
require.NotEqual(t, resHash, txHash) 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) checkExit(t, ch, 0)
} }
// RunOrError runs command and checks that if there was an error, then its text matches the provided one. // RunUnchecked runs command and ensures that proper exit code is set (0 if no error is returned, 1 is an error is returned).
func (e *Executor) RunOrError(t *testing.T, errText string, args ...string) error { // The resulting error is returned (if so).
func (e *Executor) RunUnchecked(t *testing.T, args ...string) error {
ch := setExitFunc() ch := setExitFunc()
err := e.run(args...) err := e.run(args...)
if err != nil { if err != nil {
require.True(t, strings.Contains(err.Error(), errText))
checkExit(t, ch, 1) checkExit(t, ch, 1)
} else { } else {
checkExit(t, ch, 0) checkExit(t, ch, 0)