2020-04-24 22:15:51 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
2022-01-08 00:39:27 +00:00
|
|
|
"time"
|
|
|
|
|
2020-04-26 14:28:57 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2020-04-24 22:15:51 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2022-01-08 00:39:27 +00:00
|
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
2023-04-04 00:08:45 +00:00
|
|
|
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
2020-04-24 23:22:56 +00:00
|
|
|
|
2020-04-26 14:28:57 +00:00
|
|
|
"github.com/kava-labs/kava/app"
|
2020-04-24 23:22:56 +00:00
|
|
|
"github.com/kava-labs/kava/x/committee/keeper"
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/kava-labs/kava/x/committee/testutil"
|
2020-04-24 22:15:51 +00:00
|
|
|
"github.com/kava-labs/kava/x/committee/types"
|
|
|
|
)
|
|
|
|
|
2020-04-27 14:04:47 +00:00
|
|
|
// getProposalVoteMap collects up votes into a map indexed by proposalID
|
2020-04-24 22:15:51 +00:00
|
|
|
func getProposalVoteMap(k keeper.Keeper, ctx sdk.Context) map[uint64]([]types.Vote) {
|
2020-04-24 23:22:56 +00:00
|
|
|
proposalVoteMap := map[uint64]([]types.Vote){}
|
2020-04-24 22:15:51 +00:00
|
|
|
|
2020-04-24 23:22:56 +00:00
|
|
|
k.IterateProposals(ctx, func(p types.Proposal) bool {
|
2020-04-27 14:04:47 +00:00
|
|
|
proposalVoteMap[p.ID] = k.GetVotesByProposal(ctx, p.ID)
|
2020-04-24 22:15:51 +00:00
|
|
|
return false
|
|
|
|
})
|
|
|
|
return proposalVoteMap
|
|
|
|
}
|
2020-04-26 14:28:57 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func (suite *keeperTestSuite) getAccount(addr sdk.AccAddress) authtypes.AccountI {
|
|
|
|
ak := suite.App.GetAccountKeeper()
|
|
|
|
return ak.GetAccount(suite.Ctx, addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func mustNewTestMemberCommittee(addresses []sdk.AccAddress) *types.MemberCommittee {
|
|
|
|
com, err := types.NewMemberCommittee(
|
|
|
|
12,
|
|
|
|
"This committee is for testing.",
|
|
|
|
addresses,
|
|
|
|
[]types.Permission{&types.GodPermission{}},
|
|
|
|
testutil.D("0.667"),
|
|
|
|
time.Hour*24*7,
|
|
|
|
types.TALLY_OPTION_FIRST_PAST_THE_POST,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return com
|
|
|
|
}
|
|
|
|
|
|
|
|
// mustNewTestProposal returns a new test proposal.
|
|
|
|
func mustNewTestProposal() types.Proposal {
|
|
|
|
proposal, err := types.NewProposal(
|
2023-04-04 00:08:45 +00:00
|
|
|
govv1beta1.NewTextProposal("A Title", "A description of this proposal."),
|
2022-01-08 00:39:27 +00:00
|
|
|
1, 1, time.Date(2010, time.January, 1, 0, 0, 0, 0, time.UTC),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return proposal
|
2021-06-07 16:08:03 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 14:28:57 +00:00
|
|
|
// NewCommitteeGenesisState marshals a committee genesis state into json for use in initializing test apps.
|
2022-01-08 00:39:27 +00:00
|
|
|
func NewCommitteeGenesisState(cdc codec.Codec, gs *types.GenesisState) app.GenesisState {
|
|
|
|
return app.GenesisState{types.ModuleName: cdc.MustMarshalJSON(gs)}
|
2020-04-26 14:28:57 +00:00
|
|
|
}
|