2020-02-14 07:30:51 -08:00
|
|
|
package gov_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"log"
|
|
|
|
"sort"
|
2022-01-21 03:14:00 -08:00
|
|
|
"testing"
|
2020-02-14 07:30:51 -08:00
|
|
|
|
2020-09-25 01:41:16 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
2020-11-09 08:01:43 -08:00
|
|
|
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
2020-02-14 07:30:51 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2022-01-21 03:14:00 -08:00
|
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
2022-03-11 07:58:01 -08:00
|
|
|
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
2021-12-13 10:48:44 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
2020-06-12 07:54:37 -07:00
|
|
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
2022-01-21 03:14:00 -08:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-02-14 07:30:51 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-03-24 04:26:25 -07:00
|
|
|
valTokens = sdk.TokensFromConsensusPower(42, sdk.DefaultPowerReduction)
|
2021-12-13 10:48:44 -08:00
|
|
|
TestProposal = v1beta1.NewTextProposal("Test", "description")
|
2020-06-12 07:54:37 -07:00
|
|
|
TestDescription = stakingtypes.NewDescription("T", "E", "S", "T", "Z")
|
|
|
|
TestCommissionRates = stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
2020-02-14 07:30:51 -08:00
|
|
|
)
|
|
|
|
|
2022-01-21 03:14:00 -08:00
|
|
|
// mkTestLegacyContent creates a MsgExecLegacyContent for testing purposes.
|
2022-03-11 07:58:01 -08:00
|
|
|
func mkTestLegacyContent(t *testing.T) *v1.MsgExecLegacyContent {
|
|
|
|
msgContent, err := v1.NewLegacyContent(TestProposal, authtypes.NewModuleAddress(types.ModuleName).String())
|
2022-01-21 03:14:00 -08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return msgContent
|
|
|
|
}
|
|
|
|
|
2020-02-14 07:30:51 -08:00
|
|
|
// SortAddresses - Sorts Addresses
|
|
|
|
func SortAddresses(addrs []sdk.AccAddress) {
|
|
|
|
byteAddrs := make([][]byte, len(addrs))
|
|
|
|
|
|
|
|
for i, addr := range addrs {
|
|
|
|
byteAddrs[i] = addr.Bytes()
|
|
|
|
}
|
|
|
|
|
|
|
|
SortByteArrays(byteAddrs)
|
|
|
|
|
|
|
|
for i, byteAddr := range byteAddrs {
|
|
|
|
addrs[i] = byteAddr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// implement `Interface` in sort package.
|
|
|
|
type sortByteArrays [][]byte
|
|
|
|
|
|
|
|
func (b sortByteArrays) Len() int {
|
|
|
|
return len(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b sortByteArrays) Less(i, j int) bool {
|
|
|
|
// bytes package already implements Comparable for []byte.
|
|
|
|
switch bytes.Compare(b[i], b[j]) {
|
|
|
|
case -1:
|
|
|
|
return true
|
|
|
|
case 0, 1:
|
|
|
|
return false
|
|
|
|
default:
|
|
|
|
log.Panic("not fail-able with `bytes.Comparable` bounded [-1, 1].")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b sortByteArrays) Swap(i, j int) {
|
|
|
|
b[j], b[i] = b[i], b[j]
|
|
|
|
}
|
|
|
|
|
|
|
|
// SortByteArrays - sorts the provided byte array
|
|
|
|
func SortByteArrays(src [][]byte) [][]byte {
|
|
|
|
sorted := sortByteArrays(src)
|
|
|
|
sort.Sort(sorted)
|
|
|
|
return sorted
|
|
|
|
}
|
|
|
|
|
|
|
|
const contextKeyBadProposal = "contextKeyBadProposal"
|
|
|
|
|
|
|
|
var (
|
2020-11-09 08:01:43 -08:00
|
|
|
pubkeys = []cryptotypes.PubKey{
|
2020-02-14 07:30:51 -08:00
|
|
|
ed25519.GenPrivKey().PubKey(),
|
|
|
|
ed25519.GenPrivKey().PubKey(),
|
|
|
|
ed25519.GenPrivKey().PubKey(),
|
|
|
|
}
|
|
|
|
)
|