@@ -3,13 +3,15 @@ package types
33import (
44 "fmt"
55 "math"
6+ "sort"
67 "strconv"
78 "testing"
89
910 sdk "github.com/cosmos/cosmos-sdk/types"
1011 "github.com/stretchr/testify/require"
1112 "github.com/tendermint/tendermint/crypto/secp256k1"
1213 tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
14+ "gotest.tools/v3/assert"
1315)
1416
1517func TestToMap (t * testing.T ) {
@@ -376,3 +378,29 @@ func TestClaimMapToSlice(t *testing.T) {
376378 })
377379 require .Equal (t , []Claim {claim , claim }, claimSlice )
378380}
381+
382+ func TestExchangeRateBallotSort (t * testing.T ) {
383+ v1 := VoteForTally {ExchangeRate : sdk .MustNewDecFromStr ("0.2" ), Voter : sdk.ValAddress {0 , 1 }}
384+ v1Cpy := VoteForTally {ExchangeRate : sdk .MustNewDecFromStr ("0.2" ), Voter : sdk.ValAddress {0 , 1 }}
385+ v2 := VoteForTally {ExchangeRate : sdk .MustNewDecFromStr ("0.1" ), Voter : sdk.ValAddress {0 , 1 , 1 }}
386+ v3 := VoteForTally {ExchangeRate : sdk .MustNewDecFromStr ("0.1" ), Voter : sdk.ValAddress {0 , 1 }}
387+ v4 := VoteForTally {ExchangeRate : sdk .MustNewDecFromStr ("0.5" ), Voter : sdk.ValAddress {1 }}
388+
389+ tcs := []struct {
390+ got ExchangeRateBallot
391+ expected ExchangeRateBallot
392+ }{
393+ {got : ExchangeRateBallot {v1 , v2 , v3 , v4 },
394+ expected : ExchangeRateBallot {v3 , v2 , v1 , v4 }},
395+ {got : ExchangeRateBallot {v1 },
396+ expected : ExchangeRateBallot {v1 }},
397+ {got : ExchangeRateBallot {v1 , v1Cpy },
398+ expected : ExchangeRateBallot {v1 , v1Cpy }},
399+ }
400+ for i , tc := range tcs {
401+ t .Run (fmt .Sprint (i ), func (t * testing.T ) {
402+ sort .Sort (tc .got )
403+ assert .DeepEqual (t , tc .expected , tc .got )
404+ })
405+ }
406+ }
0 commit comments