mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
cae7503f7b
* Committee types (#899) * committee types * refactor to committee interface * include tokencommitee stringer method * add members to BaseCommittee * address revisions * update querier * update querier * fix compilation errors, tests, etc. * Update MsgVote with vote type (#900) * add vote to msg * update querier/rest * update example cli vote msg * remove incorrect comments * address revisions * update handler, stub keeper method * add vote type to vote struct * Committee module keeper logic for token holder governance (#902) * fix keeper/test compilation errors * fix keeper/test compilation errors pt 2 * add setters to committee interface * fix sims compilation errors * fix incentive tests compilation errors * update types, expected keepers * core keeper logic * don't allow bond denom * implement vote tallying * query proposal polling status * update module keepers in app.go * register committee interface * fix failing incentive test * commitee types tests * refactor GetProposalResult by committee types * update invariants * implement most proposal keeper tests * add nulls to custom enums * remove abstain vote type * add test for close proposal * remove outdated TODOs * update ProcessProposals * switch on committee type directly * reintroduce Abstain votes and update vote tallying * don't allow divide by 0 panics * delete unused setters on committee interface * clean up tally methods return values for querier * update enum validation to catch negative ints * reintroduce setters for sims compilation * address revisions * remove commented out test * implement ProcessProposals test * additional revisions * Committee migrations (#909) * add committee v14 legacy types * update migration imports for compile * addRegisterCodec() to committee v14 legacy types * migrate committee genesis state from v14 to v15 * set stability committee permissions properly * fix committee allowed params * migration test, kava-7 sample data * add concrete types to committees (#911) * revisions: migrate + tests * register msgs on legacy codec * Prepare Committee module for migrations (#906) * remove invariants * edits * fix abci test * fix keeper querier tests * add committee interface registration * use codec.Codec * don't allow null vote types * don't allow null tally option * minor spelling fixes * update example cli proposal * fix cli tally query * enable vote abstain from cli * include vote options in cli help text * call CloseProposal from handler * custom enum marshaling * committee: fix failing tests (#921) * fix failing tests * fix: spelling Co-authored-by: rhuairahrighairigh <ruaridh.odonnell@gmail.com> Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com> Co-authored-by: Kevin Davis <karzak@users.noreply.github.com>
165 lines
4.0 KiB
Go
165 lines
4.0 KiB
Go
package committee_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
"github.com/kava-labs/kava/x/committee"
|
|
"github.com/kava-labs/kava/x/committee/types"
|
|
)
|
|
|
|
type GenesisTestSuite struct {
|
|
suite.Suite
|
|
|
|
app app.TestApp
|
|
ctx sdk.Context
|
|
keeper committee.Keeper
|
|
addresses []sdk.AccAddress
|
|
}
|
|
|
|
func (suite *GenesisTestSuite) SetupTest() {
|
|
suite.app = app.NewTestApp()
|
|
suite.keeper = suite.app.GetCommitteeKeeper()
|
|
suite.ctx = suite.app.NewContext(true, abci.Header{})
|
|
_, suite.addresses = app.GeneratePrivKeyAddressPairs(10)
|
|
}
|
|
|
|
func (suite *GenesisTestSuite) TestInitGenesis() {
|
|
|
|
memberCom := types.MemberCommittee{
|
|
BaseCommittee: types.BaseCommittee{
|
|
ID: 1,
|
|
Description: "This member committee is for testing.",
|
|
Members: suite.addresses[:2],
|
|
Permissions: []types.Permission{types.GodPermission{}},
|
|
VoteThreshold: d("0.667"),
|
|
ProposalDuration: time.Hour * 24 * 7,
|
|
TallyOption: types.FirstPastThePost,
|
|
},
|
|
}
|
|
|
|
tokenCom := types.TokenCommittee{
|
|
BaseCommittee: types.BaseCommittee{
|
|
ID: 1,
|
|
Description: "This token committee is for testing.",
|
|
Members: suite.addresses[:2],
|
|
Permissions: []types.Permission{types.GodPermission{}},
|
|
VoteThreshold: d("0.667"),
|
|
ProposalDuration: time.Hour * 24 * 7,
|
|
TallyOption: types.FirstPastThePost,
|
|
},
|
|
Quorum: d("0.4"),
|
|
TallyDenom: "hard",
|
|
}
|
|
|
|
// Most genesis validation tests are located in the types directory. The 'invalid' test cases are
|
|
// randomly selected subset of those tests.
|
|
testCases := []struct {
|
|
name string
|
|
genState types.GenesisState
|
|
expectPass bool
|
|
}{
|
|
{
|
|
name: "normal",
|
|
genState: types.DefaultGenesisState(),
|
|
expectPass: true,
|
|
},
|
|
{
|
|
name: "member committee is correctly validated",
|
|
genState: types.NewGenesisState(
|
|
1,
|
|
[]types.Committee{memberCom},
|
|
[]types.Proposal{},
|
|
[]types.Vote{},
|
|
),
|
|
expectPass: true,
|
|
},
|
|
{
|
|
name: "token committee is correctly validated",
|
|
genState: types.NewGenesisState(
|
|
1,
|
|
[]types.Committee{tokenCom},
|
|
[]types.Proposal{},
|
|
[]types.Vote{},
|
|
),
|
|
expectPass: true,
|
|
},
|
|
{
|
|
name: "invalid: duplicate committee ID",
|
|
genState: types.NewGenesisState(
|
|
1,
|
|
[]types.Committee{memberCom, memberCom},
|
|
[]types.Proposal{},
|
|
[]types.Vote{},
|
|
),
|
|
expectPass: false,
|
|
},
|
|
{
|
|
name: "invalid: proposal doesn't have committee",
|
|
genState: types.NewGenesisState(
|
|
2,
|
|
[]types.Committee{},
|
|
[]types.Proposal{{ID: 1, CommitteeID: 57}},
|
|
[]types.Vote{},
|
|
),
|
|
expectPass: false,
|
|
},
|
|
{
|
|
name: "invalid: vote doesn't have proposal",
|
|
genState: types.NewGenesisState(
|
|
1,
|
|
[]types.Committee{},
|
|
[]types.Proposal{},
|
|
[]types.Vote{{Voter: suite.addresses[0], ProposalID: 1, VoteType: types.Yes}},
|
|
),
|
|
expectPass: false,
|
|
},
|
|
{
|
|
name: "invalid: next proposal ID isn't greater than proposal ID",
|
|
genState: types.NewGenesisState(
|
|
4,
|
|
[]types.Committee{memberCom},
|
|
[]types.Proposal{{ID: 3, CommitteeID: 1}, {ID: 4, CommitteeID: 1}},
|
|
[]types.Vote{},
|
|
),
|
|
expectPass: false,
|
|
},
|
|
}
|
|
for _, tc := range testCases {
|
|
suite.Run(tc.name, func() {
|
|
// Setup (note: suite.SetupTest is not run before every suite.Run)
|
|
suite.app = app.NewTestApp()
|
|
suite.keeper = suite.app.GetCommitteeKeeper()
|
|
suite.ctx = suite.app.NewContext(true, abci.Header{})
|
|
|
|
// Run
|
|
var exportedGenState types.GenesisState
|
|
run := func() {
|
|
committee.InitGenesis(suite.ctx, suite.keeper, tc.genState)
|
|
exportedGenState = committee.ExportGenesis(suite.ctx, suite.keeper)
|
|
}
|
|
if tc.expectPass {
|
|
suite.NotPanics(run)
|
|
} else {
|
|
suite.Panics(run)
|
|
}
|
|
|
|
// Check
|
|
if tc.expectPass {
|
|
suite.Equal(tc.genState, exportedGenState)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGenesisTestSuite(t *testing.T) {
|
|
suite.Run(t, new(GenesisTestSuite))
|
|
}
|