0g-chain/x/committee/keeper/committee_test.go

190 lines
4.3 KiB
Go
Raw Normal View History

package keeper_test
2020-04-27 12:57:47 +00:00
import (
"testing"
"time"
2020-04-30 14:23:41 +00:00
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
2020-04-30 14:23:41 +00:00
2020-04-28 00:28:00 +00:00
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
2020-04-27 12:57:47 +00:00
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/x/committee/types"
)
2020-04-27 12:57:47 +00:00
type TypesTestSuite struct {
suite.Suite
}
func (suite *TypesTestSuite) TestCommittee_HasPermissionsFor() {
testcases := []struct {
name string
permissions []types.Permission
pubProposal types.PubProposal
2020-04-27 12:57:47 +00:00
expectHasPermissions bool
}{
{
name: "normal (single permission)",
permissions: []types.Permission{types.SimpleParamChangePermission{
AllowedParams: types.AllowedParams{
2020-04-27 12:57:47 +00:00
{
Subspace: "cdp",
Key: "DebtThreshold",
},
}}},
2020-04-28 00:28:00 +00:00
pubProposal: paramstypes.NewParameterChangeProposal(
2020-04-27 12:57:47 +00:00
"A Title",
"A description of this proposal.",
2020-04-28 00:28:00 +00:00
[]paramstypes.ParamChange{
2020-04-27 12:57:47 +00:00
{
Subspace: "cdp",
Key: "DebtThreshold",
2020-04-27 18:19:05 +00:00
Value: `{"denom": "usdx", "amount": "1000000"}`,
2020-04-27 12:57:47 +00:00
},
},
),
expectHasPermissions: true,
},
{
name: "normal (multiple permissions)",
permissions: []types.Permission{
types.SimpleParamChangePermission{
AllowedParams: types.AllowedParams{
2020-04-27 12:57:47 +00:00
{
Subspace: "cdp",
Key: "DebtThreshold",
},
}},
types.TextPermission{},
2020-04-27 12:57:47 +00:00
},
2020-04-28 00:28:00 +00:00
pubProposal: govtypes.NewTextProposal("A Proposal Title", "A description of this proposal"),
2020-04-27 12:57:47 +00:00
expectHasPermissions: true,
},
{
name: "overruling permission",
permissions: []types.Permission{
types.SimpleParamChangePermission{
AllowedParams: types.AllowedParams{
2020-04-27 12:57:47 +00:00
{
Subspace: "cdp",
Key: "DebtThreshold",
},
}},
types.GodPermission{},
2020-04-27 12:57:47 +00:00
},
2020-04-28 00:28:00 +00:00
pubProposal: paramstypes.NewParameterChangeProposal(
2020-04-27 12:57:47 +00:00
"A Title",
"A description of this proposal.",
2020-04-28 00:28:00 +00:00
[]paramstypes.ParamChange{
2020-04-27 12:57:47 +00:00
{
Subspace: "cdp",
Key: "CollateralParams",
2020-04-27 18:19:05 +00:00
Value: `[]`,
2020-04-27 12:57:47 +00:00
},
},
),
expectHasPermissions: true,
},
{
name: "no permissions",
permissions: nil,
2020-04-28 00:28:00 +00:00
pubProposal: paramstypes.NewParameterChangeProposal(
2020-04-27 12:57:47 +00:00
"A Title",
"A description of this proposal.",
2020-04-28 00:28:00 +00:00
[]paramstypes.ParamChange{
2020-04-27 12:57:47 +00:00
{
Subspace: "cdp",
Key: "CollateralParams",
2020-04-27 18:19:05 +00:00
Value: `[]`,
2020-04-27 12:57:47 +00:00
},
},
),
expectHasPermissions: false,
},
{
name: "split permissions",
// These permissions looks like they allow the param change proposal, however a proposal must pass a single permission independently of others.
permissions: []types.Permission{
types.SimpleParamChangePermission{
AllowedParams: types.AllowedParams{
2020-04-27 12:57:47 +00:00
{
Subspace: "cdp",
Key: "DebtThreshold",
},
}},
types.SimpleParamChangePermission{
AllowedParams: types.AllowedParams{
2020-04-27 12:57:47 +00:00
{
Subspace: "cdp",
Key: "DebtParams",
},
}},
},
2020-04-28 00:28:00 +00:00
pubProposal: paramstypes.NewParameterChangeProposal(
2020-04-27 12:57:47 +00:00
"A Title",
"A description of this proposal.",
2020-04-28 00:28:00 +00:00
[]paramstypes.ParamChange{
2020-04-27 12:57:47 +00:00
{
Subspace: "cdp",
Key: "DebtThreshold",
2020-04-27 18:19:05 +00:00
Value: `{"denom": "usdx", "amount": "1000000"}`,
2020-04-27 12:57:47 +00:00
},
{
Subspace: "cdp",
Key: "DebtParams",
2020-04-27 18:19:05 +00:00
Value: `[]`,
2020-04-27 12:57:47 +00:00
},
},
),
expectHasPermissions: false,
},
{
name: "unregistered proposal",
permissions: []types.Permission{
types.SimpleParamChangePermission{
AllowedParams: types.AllowedParams{
2020-04-27 12:57:47 +00:00
{
Subspace: "cdp",
Key: "DebtThreshold",
},
}},
},
2020-04-30 15:33:10 +00:00
pubProposal: UnregisteredPubProposal{govtypes.TextProposal{Title: "A Title", Description: "A description."}},
2020-04-27 12:57:47 +00:00
expectHasPermissions: false,
},
}
for _, tc := range testcases {
suite.Run(tc.name, func() {
tApp := app.NewTestApp()
ctx := tApp.NewContext(true, abci.Header{})
tApp.InitializeFromGenesisStates()
Token holder governance (#917) * 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>
2021-06-07 16:08:03 +00:00
com := types.NewMemberCommittee(
2020-04-27 12:57:47 +00:00
12,
"a description of this committee",
nil,
tc.permissions,
d("0.5"),
24*time.Hour,
Token holder governance (#917) * 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>
2021-06-07 16:08:03 +00:00
types.FirstPastThePost,
2020-04-27 12:57:47 +00:00
)
suite.Equal(
tc.expectHasPermissions,
com.HasPermissionsFor(ctx, tApp.Codec(), tApp.GetParamsKeeper(), tc.pubProposal),
2020-04-27 12:57:47 +00:00
)
})
}
}
func TestTypesTestSuite(t *testing.T) {
suite.Run(t, new(TypesTestSuite))
}