Skip to content

Commit d4adeca

Browse files
authored
refactor: replace sort.Slice with slices.Sort for natural ordering (#5376)
Signed-off-by: slightsharp <slightsharp@outlook.com>
1 parent 83b7db0 commit d4adeca

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

internal/peer/chaincode/common_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"errors"
1515
"fmt"
1616
"os"
17-
"sort"
17+
"slices"
1818
"testing"
1919
"time"
2020

@@ -808,7 +808,7 @@ func TestProcessProposals(t *testing.T) {
808808
for _, response := range responses {
809809
statuses = append(statuses, response.Response.Status)
810810
}
811-
sort.Slice(statuses, func(i, j int) bool { return statuses[i] < statuses[j] })
811+
slices.Sort(statuses)
812812
require.EqualValues(t, []int32{200, 300, 400, 500}, statuses)
813813
})
814814
t.Run("should return an error from processing a proposal for a single peer", func(t *testing.T) {

orderer/consensus/smartbft/util.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"encoding/hex"
1414
"encoding/pem"
1515
"fmt"
16-
"sort"
16+
"slices"
1717
"time"
1818

1919
"github.com/hyperledger-labs/SmartBFT/pkg/types"
@@ -367,9 +367,7 @@ func remoteNodesFromConfigBlock(block *cb.Block, logger *flogging.FabricLogger,
367367
})
368368
}
369369

370-
sort.Slice(nodeIDs, func(i, j int) bool {
371-
return nodeIDs[i] < nodeIDs[j]
372-
})
370+
slices.Sort(nodeIDs)
373371

374372
return &nodeConfig{
375373
consenters: oc.Consenters(),

orderer/consensus/smartbft/util_network_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"path/filepath"
1313
"reflect"
1414
"slices"
15-
"sort"
1615
"sync"
1716
"sync/atomic"
1817
"testing"
@@ -562,9 +561,7 @@ func createBFTChainUsingMocks(t *testing.T, node *Node, configInfo *ConfigInfo)
562561
nodeIds = append(nodeIds, nodeId)
563562
}
564563

565-
sort.Slice(nodeIds, func(i, j int) bool {
566-
return nodeIds[i] < nodeIds[j]
567-
})
564+
slices.Sort(nodeIds)
568565

569566
return nodeIds
570567
}).Maybe()

0 commit comments

Comments
 (0)