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

86 lines
1.8 KiB
Go
Raw Normal View History

package keeper_test
import (
"testing"
2020-03-10 23:16:22 +00:00
"github.com/kava-labs/kava/x/committee/types"
"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"
"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
}
func (suite *KeeperTestSuite) SetupTest() {
2020-03-10 23:16:22 +00:00
suite.app = app.NewTestApp()
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)
}
func (suite *KeeperTestSuite) TestGetSetCommittee() {
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)
}
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: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)
}
func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
2020-03-10 23:16:22 +00:00
}