From d80e14dcbb662fc7edc44edc7dd2a87f5d095583 Mon Sep 17 00:00:00 2001
From: Ekaterina Pavlova <ekt@morphbits.io>
Date: Wed, 20 Mar 2024 14:16:04 +0300
Subject: [PATCH] cli: fix TestAwaitUtilCancelTx failing

Occasionally the block is being accepted right after main transaction
submission. Added two branches into this TestAwaitUtilCancelTx. One
branch handles the case of original transaction acceptance, the
other branch handles the conflicting transaction acceptance.

Close #3365

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
---
 cli/util/util_test.go | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/cli/util/util_test.go b/cli/util/util_test.go
index 64364bc25..4787576fa 100644
--- a/cli/util/util_test.go
+++ b/cli/util/util_test.go
@@ -3,6 +3,7 @@ package util_test
 import (
 	"os"
 	"path/filepath"
+	"strings"
 	"testing"
 	"time"
 
@@ -169,11 +170,22 @@ func TestAwaitUtilCancelTx(t *testing.T) {
 
 	e.In.WriteString("one\r")
 	e.Run(t, append(args, txHash.StringLE())...)
-	e.CheckNextLine(t, "Conflicting transaction accepted")
-	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)
+	response := e.GetNextLine(t)
+	if strings.Contains(response, "Conflicting transaction accepted") {
+		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)
+	}
 }