2020-03-10 22:29:16 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-03-10 23:16:22 +00:00
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/committee/types"
|
2020-03-10 22:29:16 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-03-10 23:16:22 +00:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2020-03-10 22:29:16 +00:00
|
|
|
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
|
|
"github.com/kava-labs/kava/x/committee/keeper"
|
|
|
|
)
|
|
|
|
|
|
|
|
type KeeperTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
keeper keeper.Keeper
|
|
|
|
app app.TestApp
|
|
|
|
ctx sdk.Context
|
2020-03-10 23:16:22 +00:00
|
|
|
|
|
|
|
addresses []sdk.AccAddress
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) SetupTest() {
|
|
|
|
|
2020-03-10 23:16:22 +00:00
|
|
|
suite.app = app.NewTestApp()
|
2020-03-10 22:29:16 +00:00
|
|
|
suite.keeper = suite.app.GetCommitteeKeeper()
|
2020-03-10 23:16:22 +00:00
|
|
|
suite.ctx = suite.app.NewContext(true, abci.Header{})
|
|
|
|
_, suite.addresses = app.GeneratePrivKeyAddressPairs(2)
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2020-03-10 23:28:25 +00:00
|
|
|
func (suite *KeeperTestSuite) TestGetSetDeleteCommittee() {
|
2020-03-10 23:16:22 +00:00
|
|
|
// test setup
|
|
|
|
com := types.Committee{
|
|
|
|
ID: 12,
|
|
|
|
// TODO other fields
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2020-03-10 23:28:25 +00:00
|
|
|
|
|
|
|
// 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)
|
2020-03-10 23:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestGetSetProposal() {
|
|
|
|
// test setup
|
|
|
|
prop := types.Proposal{
|
|
|
|
ID: 12,
|
|
|
|
// TODO other fields
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2020-03-10 23:28:25 +00:00
|
|
|
|
|
|
|
// 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)
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2020-03-10 23:16:22 +00:00
|
|
|
func (suite *KeeperTestSuite) TestGetSetVote() {
|
|
|
|
// test setup
|
|
|
|
vote := types.Vote{
|
|
|
|
ProposalID: 12,
|
|
|
|
Voter: suite.addresses[0],
|
|
|
|
// TODO other fields
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2020-03-10 23:28:25 +00:00
|
|
|
|
|
|
|
// 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)
|
2020-03-10 23:16:22 +00:00
|
|
|
}
|
2020-03-10 22:29:16 +00:00
|
|
|
|
|
|
|
func TestKeeperTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(KeeperTestSuite))
|
2020-03-10 23:16:22 +00:00
|
|
|
}
|