Skip to content

Commit

Permalink
Use slices.ContainsFunc instead of separate contains func. (#4786)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim authored Sep 28, 2023
1 parent cfcd64d commit a2ba6dd
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions e2e/testsuite/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testsuite
import (
"context"
"fmt"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -80,24 +81,15 @@ func (s *E2ETestSuite) retryNtimes(f func() (sdk.TxResponse, error), attempts in
if err != nil {
return sdk.TxResponse{}, err
}
if !containsMessage(resp.RawLog, retryMessages) {
// If the response's raw log doesn't contain any of the allowed prefixes we return, else, we retry.
if !slices.ContainsFunc(retryMessages, func(s string) bool { return strings.Contains(resp.RawLog, s) }) {
return resp, err
}
s.T().Logf("retrying tx due to non deterministic failure: %+v", resp)
}
return resp, err
}

// containsMessages returns true if the string s contains any of the messages in the slice.
func containsMessage(s string, messages []string) bool {
for _, message := range messages {
if strings.Contains(s, message) {
return true
}
}
return false
}

// AssertTxFailure verifies that an sdk.TxResponse has failed.
func (s *E2ETestSuite) AssertTxFailure(resp sdk.TxResponse, expectedError *errorsmod.Error) {
errorMsg := fmt.Sprintf("%+v", resp)
Expand Down

0 comments on commit a2ba6dd

Please sign in to comment.