cli: unify canceltx command output

Always return "Target transaction accepted" error if the target transation was
either accepted by the moment of command run or during the command
handling. Exit with code 1 in both cases. Adjust TestAwaitUtilCancelTx
correspondingly, allow both cases in test. Simplify the test along the
way, remove useless code.

Close #3365.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2024-04-01 20:51:33 +03:00
parent 309016561d
commit e0e7fdf810
3 changed files with 30 additions and 28 deletions

View file

@ -1,9 +1,9 @@
package util_test
import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"time"
@ -168,24 +168,13 @@ func TestAwaitUtilCancelTx(t *testing.T) {
_, ok := e.Chain.GetMemPool().TryGetValue(txHash)
require.True(t, ok)
// Allow both cases: either target or conflicting tx acceptance.
e.In.WriteString("one\r")
e.Run(t, append(args, txHash.StringLE())...)
response := e.GetNextLine(t)
if strings.Contains(response, "Conflicting transaction accepted") {
err = e.RunOrError(t, fmt.Sprintf("target transaction %s is accepted", txHash), append(args, txHash.StringLE())...)
if err == nil {
response := e.GetNextLine(t)
require.Equal(t, "Conflicting transaction accepted", response)
resHash, _ := e.CheckAwaitableTxPersisted(t)
require.Eventually(t, func() bool {
_, aerErr := e.Chain.GetAppExecResults(resHash.Hash(), trigger.Application)
return aerErr == nil
}, time.Second*2, time.Millisecond*50)
} else if strings.Contains(response, "Target transaction accepted") {
require.Eventually(t, func() bool {
_, _, err := e.Chain.GetTransaction(txHash)
require.NoError(t, err, "original transaction should be on chain")
_, aerErr := e.Chain.GetAppExecResults(txHash, trigger.Application)
return aerErr == nil
}, time.Second*2, time.Millisecond*50)
} else {
t.Fatalf("unexpected response: %s", response)
require.NotEqual(t, resHash, txHash)
}
}