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() {
refactor(test)!: refactor `simapp.Setup` function (#9938) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description ref: #8961 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> Following up on [#9697](https://github.com/cosmos/cosmos-sdk/pull/9697#pullrequestreview-727295733), this PR is the first step for the #8961. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-08-16 17:52:06 -07:00
app := simapp.Setup(suite.T(), 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) {
refactor(test)!: refactor `simapp.Setup` function (#9938) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description ref: #8961 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> Following up on [#9697](https://github.com/cosmos/cosmos-sdk/pull/9697#pullrequestreview-727295733), this PR is the first step for the #8961. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-08-16 17:52:06 -07:00
app := simapp.Setup(t, 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) {
refactor(test)!: refactor `simapp.Setup` function (#9938) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description ref: #8961 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> Following up on [#9697](https://github.com/cosmos/cosmos-sdk/pull/9697#pullrequestreview-727295733), this PR is the first step for the #8961. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-08-16 17:52:06 -07:00
app := simapp.Setup(t, 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))
}