File tree Expand file tree Collapse file tree
token-erc-1155/chaincode-go/chaincode Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1113,9 +1113,9 @@ func sortedKeysToID(m map[ToID]uint64) []ToID {
11131113 // Sort the slice first according to ID if equal then sort by recipient ("To" field)
11141114 sort .Slice (keys , func (i , j int ) bool {
11151115 if keys [i ].ID != keys [j ].ID {
1116- return keys [i ].To < keys [j ].To
1116+ return keys [i ].ID < keys [j ].ID
11171117 }
1118- return keys [i ].ID < keys [j ].ID
1118+ return keys [i ].To < keys [j ].To
11191119 })
11201120 return keys
11211121}
Original file line number Diff line number Diff line change 1+ package chaincode
2+
3+ import (
4+ "reflect"
5+ "testing"
6+ )
7+
8+ func TestSortedKeysToID (t * testing.T ) {
9+ testMap := map [ToID ]uint64 {
10+ {To : "Alice" , ID : 2 }: 100 ,
11+ {To : "Bob" , ID : 1 }: 200 ,
12+ {To : "Charlie" , ID : 2 }: 300 ,
13+ {To : "Alice" , ID : 1 }: 400 ,
14+ {To : "Bob" , ID : 2 }: 500 ,
15+ {To : "Charlie" , ID : 1 }: 600 ,
16+ }
17+
18+ expectedResult := []ToID {
19+ {To : "Alice" , ID : 1 },
20+ {To : "Bob" , ID : 1 },
21+ {To : "Charlie" , ID : 1 },
22+ {To : "Alice" , ID : 2 },
23+ {To : "Bob" , ID : 2 },
24+ {To : "Charlie" , ID : 2 },
25+ }
26+
27+ result := sortedKeysToID (testMap )
28+
29+ if ! reflect .DeepEqual (result , expectedResult ) {
30+ t .Fatalf ("sortedKeysToID failed.\n Expected: %v\n Got: %v" , expectedResult , result )
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments