diff --git a/agreement/credentialArrivalHistory.go b/agreement/credentialArrivalHistory.go index 321ec5b3a4..b79237b547 100644 --- a/agreement/credentialArrivalHistory.go +++ b/agreement/credentialArrivalHistory.go @@ -17,7 +17,7 @@ package agreement import ( - "sort" + "slices" "time" ) @@ -78,6 +78,6 @@ func (history *credentialArrivalHistory) orderStatistics(idx int) time.Duration // the linear time order statistics algorithm. sortedArrivals := make([]time.Duration, len(history.history)) copy(sortedArrivals[:], history.history[:]) - sort.Slice(sortedArrivals, func(i, j int) bool { return sortedArrivals[i] < sortedArrivals[j] }) + slices.Sort(sortedArrivals) return sortedArrivals[idx] } diff --git a/agreement/state_machine_test.go b/agreement/state_machine_test.go index 189ae432c7..7a17b2147e 100644 --- a/agreement/state_machine_test.go +++ b/agreement/state_machine_test.go @@ -20,6 +20,7 @@ import ( "bytes" "fmt" "os" + "slices" "strings" "github.com/algorand/go-algorand/logging" @@ -158,12 +159,7 @@ func (t ioTrace) CountEvent(b event) (count int) { // for each event, passes it into the given fn; if returns true, returns true. func (t ioTrace) ContainsFn(compareFn func(b event) bool) bool { - for _, ev := range t.events { - if compareFn(ev) { - return true - } - } - return false + return slices.ContainsFunc(t.events, compareFn) } func (t ioTrace) countAction() (count int) { diff --git a/data/basics/fields_test.go b/data/basics/fields_test.go index 234e4246bf..d06cbede66 100644 --- a/data/basics/fields_test.go +++ b/data/basics/fields_test.go @@ -18,6 +18,7 @@ package basics_test import ( "reflect" + "slices" "testing" "github.com/algorand/go-algorand/data/basics" @@ -35,11 +36,9 @@ func makeTypeCheckFunction(t *testing.T, exceptions []reflectionhelpers.TypePath return func(path reflectionhelpers.TypePath, stack []reflect.Type) bool { currentType := stack[len(stack)-1] - for _, exception := range exceptions { - if path.Equals(exception) { - t.Logf("Skipping exception for path: %s", path) - return true - } + if slices.ContainsFunc(exceptions, path.Equals) { + t.Logf("Skipping exception for path: %s", path) + return true } switch currentType.Kind() { diff --git a/gen/generate_test.go b/gen/generate_test.go index fcd4d38970..11d595eddc 100644 --- a/gen/generate_test.go +++ b/gen/generate_test.go @@ -22,6 +22,7 @@ import ( "io" "os" "path/filepath" + "slices" "strings" "sync" "testing" @@ -171,12 +172,7 @@ func TestGenesisJsonCreation(t *testing.T) { deterministicAddresses := []string{"FeeSink", "RewardsPool"} isNondeterministicAddress := func(name string) bool { - for _, address := range deterministicAddresses { - if name == address { - return false - } - } - return true + return !slices.Contains(deterministicAddresses, name) } for i := range as { diff --git a/ledger/simulation/simulator_test.go b/ledger/simulation/simulator_test.go index d8a13ed713..a08225153e 100644 --- a/ledger/simulation/simulator_test.go +++ b/ledger/simulation/simulator_test.go @@ -18,6 +18,7 @@ package simulation import ( "reflect" + "slices" "testing" "github.com/algorand/go-algorand/crypto" @@ -59,17 +60,10 @@ func TestNonOverridenDataLedgerMethodsUseRoundParameter(t *testing.T) { } methodIsSkipped := func(methodName string) bool { - for _, overridenMethod := range overridenMethods { - if overridenMethod == methodName { - return true - } - } - for _, excludedMethod := range excludedMethods { - if excludedMethod == methodName { - return true - } + if slices.Contains(overridenMethods, methodName) { + return true } - return false + return slices.Contains(excludedMethods, methodName) } methodExistsInEvalLedger := func(methodName string) bool { diff --git a/network/wsNetwork.go b/network/wsNetwork.go index 184616e998..11a0262abb 100644 --- a/network/wsNetwork.go +++ b/network/wsNetwork.go @@ -2392,11 +2392,9 @@ func (wn *WebsocketNetwork) addPeer(peer *wsPeer) { } // simple duplicate *pointer* check. should never trigger given the callers to addPeer // TODO: remove this after making sure it is safe to do so - for _, p := range wn.peers { - if p == peer { - wn.log.Errorf("dup peer added %#v", peer) - return - } + if slices.Contains(wn.peers, peer) { + wn.log.Errorf("dup peer added %#v", peer) + return } heap.Push(peersHeap{wn}, peer) wn.prioTracker.setPriority(peer, peer.prioAddress, peer.prioWeight) diff --git a/test/e2e-go/features/catchup/catchpointCatchup_test.go b/test/e2e-go/features/catchup/catchpointCatchup_test.go index 5e7ec6d14b..7b198ee50e 100644 --- a/test/e2e-go/features/catchup/catchpointCatchup_test.go +++ b/test/e2e-go/features/catchup/catchpointCatchup_test.go @@ -550,8 +550,8 @@ func downloadCatchpointFile(t *testing.T, a *require.Assertions, baseURL string, var chunks []ledger.CatchpointSnapshotChunkV6 for _, d := range tarData { t.Logf("tar filename: %s, size %d", d.headerName, len(d.data)) - if strings.HasPrefix(d.headerName, "balances.") { // chunk file - idxStr := strings.TrimSuffix(strings.TrimPrefix(d.headerName, "balances."), ".msgpack") + if after, ok := strings.CutPrefix(d.headerName, "balances."); ok { // chunk file + idxStr := strings.TrimSuffix(after, ".msgpack") idx, err := strconv.Atoi(idxStr) a.NoError(err) var c ledger.CatchpointSnapshotChunkV6