Merge pull request #1 from hyperledger/main

Fulfilling the requirements of issue #1378
This commit is contained in:
Vishal More 2026-05-27 10:54:31 +05:30 committed by GitHub
commit 7a88afe922
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 3 deletions

View file

@ -35,7 +35,7 @@ context CLUSTER_RUNTIME kind # or k3s for Rancher
context CONTAINER_CLI docker # or nerdctl for containerd
context CONTAINER_NAMESPACE "" # or "--namespace k8s.io" for containerd / nerdctl
context FABRIC_CONTAINER_REGISTRY hyperledger
context FABRIC_CONTAINER_REGISTRY ghcr.io/hyperledger
context FABRIC_PEER_IMAGE ${FABRIC_CONTAINER_REGISTRY}/fabric-peer:${FABRIC_VERSION}
context COUCHDB_VERSION 3.4.2
context NETWORK_NAME test-network

View file

@ -1113,9 +1113,9 @@ func sortedKeysToID(m map[ToID]uint64) []ToID {
// Sort the slice first according to ID if equal then sort by recipient ("To" field)
sort.Slice(keys, func(i, j int) bool {
if keys[i].ID != keys[j].ID {
return keys[i].To < keys[j].To
return keys[i].ID < keys[j].ID
}
return keys[i].ID < keys[j].ID
return keys[i].To < keys[j].To
})
return keys
}

View file

@ -0,0 +1,32 @@
package chaincode
import (
"reflect"
"testing"
)
func TestSortedKeysToID(t *testing.T) {
testMap := map[ToID]uint64{
{To: "Alice", ID: 2}: 100,
{To: "Bob", ID: 1}: 200,
{To: "Charlie", ID: 2}: 300,
{To: "Alice", ID: 1}: 400,
{To: "Bob", ID: 2}: 500,
{To: "Charlie", ID: 1}: 600,
}
expectedResult := []ToID{
{To: "Alice", ID: 1},
{To: "Bob", ID: 1},
{To: "Charlie", ID: 1},
{To: "Alice", ID: 2},
{To: "Bob", ID: 2},
{To: "Charlie", ID: 2},
}
result := sortedKeysToID(testMap)
if !reflect.DeepEqual(result, expectedResult) {
t.Fatalf("sortedKeysToID failed.\nExpected: %v\nGot: %v", expectedResult, result)
}
}