0g-chain/x/committee/keeper/keeper_test.go
Denali Marsh cae7503f7b
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 18:08:03 +02:00

120 lines
3.0 KiB
Go

package keeper_test
import (
"testing"
"time"
"github.com/stretchr/testify/suite"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/supply"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/x/committee/keeper"
"github.com/kava-labs/kava/x/committee/types"
)
type KeeperTestSuite struct {
suite.Suite
keeper keeper.Keeper
supplyKeeper supply.Keeper
app app.TestApp
ctx sdk.Context
addresses []sdk.AccAddress
}
func (suite *KeeperTestSuite) SetupTest() {
suite.app = app.NewTestApp()
suite.keeper = suite.app.GetCommitteeKeeper()
suite.supplyKeeper = suite.app.GetSupplyKeeper()
suite.ctx = suite.app.NewContext(true, abci.Header{})
_, suite.addresses = app.GeneratePrivKeyAddressPairs(10)
}
func (suite *KeeperTestSuite) TestGetSetDeleteCommittee() {
// setup test
com := types.MemberCommittee{
BaseCommittee: types.BaseCommittee{
ID: 12,
Description: "This committee is for testing.",
Members: suite.addresses,
Permissions: []types.Permission{types.GodPermission{}},
VoteThreshold: d("0.667"),
ProposalDuration: time.Hour * 24 * 7,
TallyOption: types.FirstPastThePost,
},
}
// write and read from store
suite.keeper.SetCommittee(suite.ctx, com)
readCommittee, found := suite.keeper.GetCommittee(suite.ctx, com.ID)
// check before and after match
suite.True(found)
suite.Equal(com, readCommittee)
// delete from store
suite.keeper.DeleteCommittee(suite.ctx, com.ID)
// check does not exist
_, found = suite.keeper.GetCommittee(suite.ctx, com.ID)
suite.False(found)
}
func (suite *KeeperTestSuite) TestGetSetDeleteProposal() {
// test setup
prop := types.Proposal{
ID: 12,
CommitteeID: 0,
PubProposal: gov.NewTextProposal("A Title", "A description of this proposal."),
Deadline: time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC),
}
// write and read from store
suite.keeper.SetProposal(suite.ctx, prop)
readProposal, found := suite.keeper.GetProposal(suite.ctx, prop.ID)
// check before and after match
suite.True(found)
suite.Equal(prop, readProposal)
// delete from store
suite.keeper.DeleteProposal(suite.ctx, prop.ID)
// check does not exist
_, found = suite.keeper.GetProposal(suite.ctx, prop.ID)
suite.False(found)
}
func (suite *KeeperTestSuite) TestGetSetDeleteVote() {
// test setup
vote := types.Vote{
ProposalID: 12,
Voter: suite.addresses[0],
}
// write and read from store
suite.keeper.SetVote(suite.ctx, vote)
readVote, found := suite.keeper.GetVote(suite.ctx, vote.ProposalID, vote.Voter)
// check before and after match
suite.True(found)
suite.Equal(vote, readVote)
// delete from store
suite.keeper.DeleteVote(suite.ctx, vote.ProposalID, vote.Voter)
// check does not exist
_, found = suite.keeper.GetVote(suite.ctx, vote.ProposalID, vote.Voter)
suite.False(found)
}
func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}