cosmos-sdk/x/gov/keeper/keeper_test.go

93 lines
2.6 KiB
Go
Raw Normal View History

package keeper_test
import (
"testing"
"github.com/stretchr/testify/require"
x/gov: gRPC query Service (#6491) * WIP: adding gRPC for gov * removed passing new store * fixed error * added register query service in module * order of imports changed * order of imports changed * Fix proto file * added get all proposals grpc * added more tests * added doc in tests * added grpc for votes * Added grpc for Deposits * updated protos * added grpc for proposal, vote, deposit, tally * WIP: adding params grpc * added params in gRPC * updated error messages * fixed error check * added more tests * updated tests * added yaml types * review changes and lint issues * updated tests * code cleanup * removed cosmos.gov prefixes * added more checks * added more test checks * added filtered pagination * removed test check * added tests for filtered pagination * Fix Proposals * lint * fixed error in tests * lint issues * Add nil check for params * Added unpacker * removed casttypes * review changes * use suite in grpc query tests * migrated tests to use suite * fix non-determinism * tests migrated to table driven tests * fixed doc typo * revert change * Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/5921-grpc-x-gov * review changes * review changes * review changes * review change * review changes * docs updated * review change * review changes * review changes * review changes * Update x/gov/keeper/keeper_test.go Co-authored-by: sahith-narahari <sahithnarahari@gmail.com> Co-authored-by: Anil Kumar Kammari <anil@vitwit.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-07-16 02:16:23 -07:00
"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
x/gov: gRPC query Service (#6491) * WIP: adding gRPC for gov * removed passing new store * fixed error * added register query service in module * order of imports changed * order of imports changed * Fix proto file * added get all proposals grpc * added more tests * added doc in tests * added grpc for votes * Added grpc for Deposits * updated protos * added grpc for proposal, vote, deposit, tally * WIP: adding params grpc * added params in gRPC * updated error messages * fixed error check * added more tests * updated tests * added yaml types * review changes and lint issues * updated tests * code cleanup * removed cosmos.gov prefixes * added more checks * added more test checks * added filtered pagination * removed test check * added tests for filtered pagination * Fix Proposals * lint * fixed error in tests * lint issues * Add nil check for params * Added unpacker * removed casttypes * review changes * use suite in grpc query tests * migrated tests to use suite * fix non-determinism * tests migrated to table driven tests * fixed doc typo * revert change * Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/5921-grpc-x-gov * review changes * review changes * review changes * review change * review changes * docs updated * review change * review changes * review changes * review changes * Update x/gov/keeper/keeper_test.go Co-authored-by: sahith-narahari <sahithnarahari@gmail.com> Co-authored-by: Anil Kumar Kammari <anil@vitwit.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-07-16 02:16:23 -07:00
"github.com/cosmos/cosmos-sdk/baseapp"
2020-03-02 07:04:49 -08:00
"github.com/cosmos/cosmos-sdk/simapp"
x/gov: gRPC query Service (#6491) * WIP: adding gRPC for gov * removed passing new store * fixed error * added register query service in module * order of imports changed * order of imports changed * Fix proto file * added get all proposals grpc * added more tests * added doc in tests * added grpc for votes * Added grpc for Deposits * updated protos * added grpc for proposal, vote, deposit, tally * WIP: adding params grpc * added params in gRPC * updated error messages * fixed error check * added more tests * updated tests * added yaml types * review changes and lint issues * updated tests * code cleanup * removed cosmos.gov prefixes * added more checks * added more test checks * added filtered pagination * removed test check * added tests for filtered pagination * Fix Proposals * lint * fixed error in tests * lint issues * Add nil check for params * Added unpacker * removed casttypes * review changes * use suite in grpc query tests * migrated tests to use suite * fix non-determinism * tests migrated to table driven tests * fixed doc typo * revert change * Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/5921-grpc-x-gov * review changes * review changes * review changes * review change * review changes * docs updated * review change * review changes * review changes * review changes * Update x/gov/keeper/keeper_test.go Co-authored-by: sahith-narahari <sahithnarahari@gmail.com> Co-authored-by: Anil Kumar Kammari <anil@vitwit.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-07-16 02:16:23 -07:00
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/types"
)
x/gov: gRPC query Service (#6491) * WIP: adding gRPC for gov * removed passing new store * fixed error * added register query service in module * order of imports changed * order of imports changed * Fix proto file * added get all proposals grpc * added more tests * added doc in tests * added grpc for votes * Added grpc for Deposits * updated protos * added grpc for proposal, vote, deposit, tally * WIP: adding params grpc * added params in gRPC * updated error messages * fixed error check * added more tests * updated tests * added yaml types * review changes and lint issues * updated tests * code cleanup * removed cosmos.gov prefixes * added more checks * added more test checks * added filtered pagination * removed test check * added tests for filtered pagination * Fix Proposals * lint * fixed error in tests * lint issues * Add nil check for params * Added unpacker * removed casttypes * review changes * use suite in grpc query tests * migrated tests to use suite * fix non-determinism * tests migrated to table driven tests * fixed doc typo * revert change * Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/5921-grpc-x-gov * review changes * review changes * review changes * review change * review changes * docs updated * review change * review changes * review changes * review changes * Update x/gov/keeper/keeper_test.go Co-authored-by: sahith-narahari <sahithnarahari@gmail.com> Co-authored-by: Anil Kumar Kammari <anil@vitwit.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-07-16 02:16:23 -07:00
type KeeperTestSuite struct {
suite.Suite
app *simapp.SimApp
ctx sdk.Context
queryClient types.QueryClient
addrs []sdk.AccAddress
}
func (suite *KeeperTestSuite) SetupTest() {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
x/gov: gRPC query Service (#6491) * WIP: adding gRPC for gov * removed passing new store * fixed error * added register query service in module * order of imports changed * order of imports changed * Fix proto file * added get all proposals grpc * added more tests * added doc in tests * added grpc for votes * Added grpc for Deposits * updated protos * added grpc for proposal, vote, deposit, tally * WIP: adding params grpc * added params in gRPC * updated error messages * fixed error check * added more tests * updated tests * added yaml types * review changes and lint issues * updated tests * code cleanup * removed cosmos.gov prefixes * added more checks * added more test checks * added filtered pagination * removed test check * added tests for filtered pagination * Fix Proposals * lint * fixed error in tests * lint issues * Add nil check for params * Added unpacker * removed casttypes * review changes * use suite in grpc query tests * migrated tests to use suite * fix non-determinism * tests migrated to table driven tests * fixed doc typo * revert change * Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/5921-grpc-x-gov * review changes * review changes * review changes * review change * review changes * docs updated * review change * review changes * review changes * review changes * Update x/gov/keeper/keeper_test.go Co-authored-by: sahith-narahari <sahithnarahari@gmail.com> Co-authored-by: Anil Kumar Kammari <anil@vitwit.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-07-16 02:16:23 -07:00
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
types.RegisterQueryServer(queryHelper, app.GovKeeper)
queryClient := types.NewQueryClient(queryHelper)
suite.app = app
suite.ctx = ctx
suite.queryClient = queryClient
suite.addrs = simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(30000000))
}
func TestIncrementProposalNumber(t *testing.T) {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
tp := TestProposal
_, err := app.GovKeeper.SubmitProposal(ctx, tp)
require.NoError(t, err)
_, err = app.GovKeeper.SubmitProposal(ctx, tp)
require.NoError(t, err)
_, err = app.GovKeeper.SubmitProposal(ctx, tp)
require.NoError(t, err)
_, err = app.GovKeeper.SubmitProposal(ctx, tp)
require.NoError(t, err)
_, err = app.GovKeeper.SubmitProposal(ctx, tp)
require.NoError(t, err)
proposal6, err := app.GovKeeper.SubmitProposal(ctx, tp)
require.NoError(t, err)
require.Equal(t, uint64(6), proposal6.ProposalId)
}
func TestProposalQueues(t *testing.T) {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
// create test proposals
tp := TestProposal
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
require.NoError(t, err)
inactiveIterator := app.GovKeeper.InactiveProposalQueueIterator(ctx, proposal.DepositEndTime)
require.True(t, inactiveIterator.Valid())
proposalID := types.GetProposalIDFromBytes(inactiveIterator.Value())
require.Equal(t, proposalID, proposal.ProposalId)
inactiveIterator.Close()
app.GovKeeper.ActivateVotingPeriod(ctx, proposal)
proposal, ok := app.GovKeeper.GetProposal(ctx, proposal.ProposalId)
require.True(t, ok)
activeIterator := app.GovKeeper.ActiveProposalQueueIterator(ctx, proposal.VotingEndTime)
require.True(t, activeIterator.Valid())
2020-03-02 13:46:28 -08:00
proposalID, _ = types.SplitActiveProposalQueueKey(activeIterator.Key())
require.Equal(t, proposalID, proposal.ProposalId)
activeIterator.Close()
}
x/gov: gRPC query Service (#6491) * WIP: adding gRPC for gov * removed passing new store * fixed error * added register query service in module * order of imports changed * order of imports changed * Fix proto file * added get all proposals grpc * added more tests * added doc in tests * added grpc for votes * Added grpc for Deposits * updated protos * added grpc for proposal, vote, deposit, tally * WIP: adding params grpc * added params in gRPC * updated error messages * fixed error check * added more tests * updated tests * added yaml types * review changes and lint issues * updated tests * code cleanup * removed cosmos.gov prefixes * added more checks * added more test checks * added filtered pagination * removed test check * added tests for filtered pagination * Fix Proposals * lint * fixed error in tests * lint issues * Add nil check for params * Added unpacker * removed casttypes * review changes * use suite in grpc query tests * migrated tests to use suite * fix non-determinism * tests migrated to table driven tests * fixed doc typo * revert change * Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/5921-grpc-x-gov * review changes * review changes * review changes * review change * review changes * docs updated * review change * review changes * review changes * review changes * Update x/gov/keeper/keeper_test.go Co-authored-by: sahith-narahari <sahithnarahari@gmail.com> Co-authored-by: Anil Kumar Kammari <anil@vitwit.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-07-16 02:16:23 -07:00
func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}