Skip to content

Commit

Permalink
refactor(gov): CLI tests using Tendermint Mock (#13717)
Browse files Browse the repository at this point in the history
## Description

Closes: #13480 



---

### 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...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] 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)
  • Loading branch information
likhita-809 authored Nov 3, 2022
1 parent 9a246fa commit ad0e41d
Show file tree
Hide file tree
Showing 7 changed files with 951 additions and 14 deletions.
6 changes: 3 additions & 3 deletions tests/e2e/gov/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"time"

"cosmossdk.io/simapp"

"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/x/gov/client/testutil"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"

"github.com/stretchr/testify/require"
Expand All @@ -19,7 +19,7 @@ import (
func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
cfg.NumValidators = 1
suite.Run(t, testutil.NewIntegrationTestSuite(cfg))
suite.Run(t, NewIntegrationTestSuite(cfg))
}

func TestDepositTestSuite(t *testing.T) {
Expand All @@ -33,5 +33,5 @@ func TestDepositTestSuite(t *testing.T) {
bz, err := cfg.Codec.MarshalJSON(genesisState)
require.NoError(t, err)
cfg.GenesisState["gov"] = bz
suite.Run(t, testutil.NewDepositTestSuite(cfg))
suite.Run(t, NewDepositTestSuite(cfg))
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testutil
package gov

import (
"fmt"
Expand All @@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
govclitestutil "github.com/cosmos/cosmos-sdk/x/gov/client/testutil"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)
Expand Down Expand Up @@ -72,7 +73,7 @@ func (s *DepositTestSuite) submitProposal(val *network.Validator, initialDeposit
exactArgs = append(exactArgs, fmt.Sprintf("--%s=%s", cli.FlagDeposit, initialDeposit.String()))
}

_, err := MsgSubmitLegacyProposal(
_, err := govclitestutil.MsgSubmitLegacyProposal(
val.ClientCtx,
val.Address.String(),
fmt.Sprintf("Text Proposal %d", id),
Expand All @@ -96,7 +97,7 @@ func (s *DepositTestSuite) TestQueryDepositsWithoutInitialDeposit() {

// deposit amount
depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens.Add(sdk.NewInt(50))).String()
_, err := MsgDeposit(clientCtx, val.Address.String(), proposalID, depositAmount)
_, err := govclitestutil.MsgDeposit(clientCtx, val.Address.String(), proposalID, depositAmount)
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())

Expand Down
2 changes: 1 addition & 1 deletion x/gov/client/testutil/grpc.go → tests/e2e/gov/grpc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testutil
package gov

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion x/gov/client/testutil/query.go → tests/e2e/gov/query.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testutil
package gov

import (
"fmt"
Expand Down
13 changes: 7 additions & 6 deletions x/gov/client/testutil/tx.go → tests/e2e/gov/tx.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testutil
package gov

import (
"encoding/base64"
Expand All @@ -15,6 +15,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
govclitestutil "github.com/cosmos/cosmos-sdk/x/gov/client/testutil"
"github.com/cosmos/cosmos-sdk/x/gov/types"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
Expand Down Expand Up @@ -42,32 +43,32 @@ func (s *IntegrationTestSuite) SetupSuite() {
val := s.network.Validators[0]

// create a proposal with deposit
_, err = MsgSubmitLegacyProposal(val.ClientCtx, val.Address.String(),
_, err = govclitestutil.MsgSubmitLegacyProposal(val.ClientCtx, val.Address.String(),
"Text Proposal 1", "Where is the title!?", v1beta1.ProposalTypeText,
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens).String()))
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())

// vote for proposal
_, err = MsgVote(val.ClientCtx, val.Address.String(), "1", "yes")
_, err = govclitestutil.MsgVote(val.ClientCtx, val.Address.String(), "1", "yes")
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())

// create a proposal without deposit
_, err = MsgSubmitLegacyProposal(val.ClientCtx, val.Address.String(),
_, err = govclitestutil.MsgSubmitLegacyProposal(val.ClientCtx, val.Address.String(),
"Text Proposal 2", "Where is the title!?", v1beta1.ProposalTypeText)
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())

// create a proposal3 with deposit
_, err = MsgSubmitLegacyProposal(val.ClientCtx, val.Address.String(),
_, err = govclitestutil.MsgSubmitLegacyProposal(val.ClientCtx, val.Address.String(),
"Text Proposal 3", "Where is the title!?", v1beta1.ProposalTypeText,
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens).String()))
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())

// vote for proposal3 as val
_, err = MsgVote(val.ClientCtx, val.Address.String(), "3", "yes=0.6,no=0.3,abstain=0.05,no_with_veto=0.05")
_, err = govclitestutil.MsgVote(val.ClientCtx, val.Address.String(), "3", "yes=0.6,no=0.3,abstain=0.05,no_with_veto=0.05")
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
}
Expand Down
Loading

0 comments on commit ad0e41d

Please sign in to comment.