refactor(gov): CLI tests using Tendermint Mock (#13717)
## 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)
This commit is contained in:
@@ -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"
|
||||
@@ -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) {
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
package gov
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
tmcli "github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"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"
|
||||
)
|
||||
|
||||
type DepositTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
cfg network.Config
|
||||
network *network.Network
|
||||
deposits sdk.Coins
|
||||
proposalIDs []string
|
||||
}
|
||||
|
||||
func NewDepositTestSuite(cfg network.Config) *DepositTestSuite {
|
||||
return &DepositTestSuite{cfg: cfg}
|
||||
}
|
||||
|
||||
func (s *DepositTestSuite) SetupSuite() {
|
||||
s.T().Log("setting up test suite")
|
||||
|
||||
var err error
|
||||
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
val := s.network.Validators[0]
|
||||
|
||||
deposits := sdk.Coins{
|
||||
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(0)),
|
||||
sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens),
|
||||
sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens.Sub(sdk.NewInt(50))),
|
||||
}
|
||||
s.deposits = deposits
|
||||
|
||||
// create 2 proposals for testing
|
||||
for i := 0; i < len(deposits); i++ {
|
||||
id := i + 1
|
||||
deposit := deposits[i]
|
||||
|
||||
s.submitProposal(val, deposit, id)
|
||||
s.proposalIDs = append(s.proposalIDs, fmt.Sprintf("%d", id))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DepositTestSuite) SetupNewSuite() {
|
||||
s.T().Log("setting up new test suite")
|
||||
|
||||
var err error
|
||||
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
}
|
||||
|
||||
func (s *DepositTestSuite) submitProposal(val *network.Validator, initialDeposit sdk.Coin, id int) {
|
||||
var exactArgs []string
|
||||
|
||||
if !initialDeposit.IsZero() {
|
||||
exactArgs = append(exactArgs, fmt.Sprintf("--%s=%s", cli.FlagDeposit, initialDeposit.String()))
|
||||
}
|
||||
|
||||
_, err := govclitestutil.MsgSubmitLegacyProposal(
|
||||
val.ClientCtx,
|
||||
val.Address.String(),
|
||||
fmt.Sprintf("Text Proposal %d", id),
|
||||
"Where is the title!?",
|
||||
v1beta1.ProposalTypeText,
|
||||
exactArgs...,
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
}
|
||||
|
||||
func (s *DepositTestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down test suite")
|
||||
s.network.Cleanup()
|
||||
}
|
||||
|
||||
func (s *DepositTestSuite) TestQueryDepositsWithoutInitialDeposit() {
|
||||
val := s.network.Validators[0]
|
||||
clientCtx := val.ClientCtx
|
||||
proposalID := s.proposalIDs[0]
|
||||
|
||||
// deposit amount
|
||||
depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens.Add(sdk.NewInt(50))).String()
|
||||
_, err := govclitestutil.MsgDeposit(clientCtx, val.Address.String(), proposalID, depositAmount)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
// query deposit
|
||||
deposit := s.queryDeposit(val, proposalID, false, "")
|
||||
s.Require().NotNil(deposit)
|
||||
s.Require().Equal(sdk.Coins(deposit.Amount).String(), depositAmount)
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
// query deposits
|
||||
deposits := s.queryDeposits(val, proposalID, false, "")
|
||||
s.Require().NotNil(deposits)
|
||||
s.Require().Len(deposits.Deposits, 1)
|
||||
// verify initial deposit
|
||||
s.Require().Equal(sdk.Coins(deposits.Deposits[0].Amount).String(), depositAmount)
|
||||
}
|
||||
|
||||
func (s *DepositTestSuite) TestQueryDepositsWithInitialDeposit() {
|
||||
val := s.network.Validators[0]
|
||||
proposalID := s.proposalIDs[1]
|
||||
|
||||
// query deposit
|
||||
deposit := s.queryDeposit(val, proposalID, false, "")
|
||||
s.Require().NotNil(deposit)
|
||||
s.Require().Equal(sdk.Coins(deposit.Amount).String(), s.deposits[1].String())
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
// query deposits
|
||||
deposits := s.queryDeposits(val, proposalID, false, "")
|
||||
s.Require().NotNil(deposits)
|
||||
s.Require().Len(deposits.Deposits, 1)
|
||||
// verify initial deposit
|
||||
s.Require().Equal(sdk.Coins(deposits.Deposits[0].Amount).String(), s.deposits[1].String())
|
||||
}
|
||||
|
||||
func (s *DepositTestSuite) TestQueryProposalAfterVotingPeriod() {
|
||||
val := s.network.Validators[0]
|
||||
clientCtx := val.ClientCtx
|
||||
proposalID := s.proposalIDs[2]
|
||||
|
||||
// query proposal
|
||||
args := []string{proposalID, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
|
||||
cmd := cli.GetCmdQueryProposal()
|
||||
_, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
|
||||
s.Require().NoError(err)
|
||||
|
||||
// waiting for deposit and voting period to end
|
||||
time.Sleep(20 * time.Second)
|
||||
|
||||
// query proposal
|
||||
_, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
|
||||
s.Require().Error(err)
|
||||
s.Require().Contains(err.Error(), fmt.Sprintf("proposal %s doesn't exist", proposalID))
|
||||
|
||||
// query deposits
|
||||
deposits := s.queryDeposits(val, proposalID, true, "proposal 3 doesn't exist")
|
||||
s.Require().Nil(deposits)
|
||||
}
|
||||
|
||||
func (s *DepositTestSuite) queryDeposits(val *network.Validator, proposalID string, exceptErr bool, message string) *v1.QueryDepositsResponse {
|
||||
args := []string{proposalID, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
|
||||
var depositsRes *v1.QueryDepositsResponse
|
||||
cmd := cli.GetCmdQueryDeposits()
|
||||
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
||||
|
||||
if exceptErr {
|
||||
s.Require().Error(err)
|
||||
s.Require().Contains(err.Error(), message)
|
||||
return nil
|
||||
}
|
||||
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(val.ClientCtx.LegacyAmino.UnmarshalJSON(out.Bytes(), &depositsRes))
|
||||
return depositsRes
|
||||
}
|
||||
|
||||
func (s *DepositTestSuite) queryDeposit(val *network.Validator, proposalID string, exceptErr bool, message string) *v1.Deposit {
|
||||
args := []string{proposalID, val.Address.String(), fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
|
||||
var depositRes *v1.Deposit
|
||||
cmd := cli.GetCmdQueryDeposit()
|
||||
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
||||
if exceptErr {
|
||||
s.Require().Error(err)
|
||||
s.Require().Contains(err.Error(), message)
|
||||
return nil
|
||||
}
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(val.ClientCtx.LegacyAmino.UnmarshalJSON(out.Bytes(), &depositRes))
|
||||
|
||||
return depositRes
|
||||
}
|
||||
@@ -0,0 +1,414 @@
|
||||
package gov
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
|
||||
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
)
|
||||
|
||||
func (s *IntegrationTestSuite) TestGetProposalGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expErr bool
|
||||
}{
|
||||
{
|
||||
"empty proposal",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.APIAddress, ""),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"get non existing proposal",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.APIAddress, "10"),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"get proposal with id",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.APIAddress, "1"),
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
s.Require().NoError(err)
|
||||
|
||||
var proposal v1.QueryProposalResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &proposal)
|
||||
|
||||
if tc.expErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(proposal.Proposal)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestGetProposalsGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
headers map[string]string
|
||||
wantNumProposals int
|
||||
expErr bool
|
||||
}{
|
||||
{
|
||||
"get proposals with height 1",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals", val.APIAddress),
|
||||
map[string]string{
|
||||
grpctypes.GRPCBlockHeightHeader: "1",
|
||||
},
|
||||
0,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals", val.APIAddress),
|
||||
map[string]string{},
|
||||
3,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"valid request with filter by status",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals?proposal_status=1", val.APIAddress),
|
||||
map[string]string{},
|
||||
1,
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
|
||||
s.Require().NoError(err)
|
||||
|
||||
var proposals v1.QueryProposalsResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &proposals)
|
||||
|
||||
if tc.expErr {
|
||||
s.Require().Empty(proposals.Proposals)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().Len(proposals.Proposals, tc.wantNumProposals)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestGetProposalVoteGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
voterAddressBech32 := val.Address.String()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expErr bool
|
||||
expVoteOptions v1.WeightedVoteOptions
|
||||
}{
|
||||
{
|
||||
"empty proposal",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes/%s", val.APIAddress, "", voterAddressBech32),
|
||||
true,
|
||||
v1.NewNonSplitVoteOption(v1.OptionYes),
|
||||
},
|
||||
{
|
||||
"get non existing proposal",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes/%s", val.APIAddress, "10", voterAddressBech32),
|
||||
true,
|
||||
v1.NewNonSplitVoteOption(v1.OptionYes),
|
||||
},
|
||||
{
|
||||
"get proposal with wrong voter address",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes/%s", val.APIAddress, "1", "wrongVoterAddress"),
|
||||
true,
|
||||
v1.NewNonSplitVoteOption(v1.OptionYes),
|
||||
},
|
||||
{
|
||||
"get proposal with id",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes/%s", val.APIAddress, "1", voterAddressBech32),
|
||||
false,
|
||||
v1.NewNonSplitVoteOption(v1.OptionYes),
|
||||
},
|
||||
{
|
||||
"get proposal with id for split vote",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes/%s", val.APIAddress, "3", voterAddressBech32),
|
||||
false,
|
||||
v1.WeightedVoteOptions{
|
||||
&v1.WeightedVoteOption{Option: v1.OptionYes, Weight: sdk.NewDecWithPrec(60, 2).String()},
|
||||
&v1.WeightedVoteOption{Option: v1.OptionNo, Weight: sdk.NewDecWithPrec(30, 2).String()},
|
||||
&v1.WeightedVoteOption{Option: v1.OptionAbstain, Weight: sdk.NewDecWithPrec(5, 2).String()},
|
||||
&v1.WeightedVoteOption{Option: v1.OptionNoWithVeto, Weight: sdk.NewDecWithPrec(5, 2).String()},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
s.Require().NoError(err)
|
||||
|
||||
var vote v1.QueryVoteResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &vote)
|
||||
|
||||
if tc.expErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotEmpty(vote.Vote)
|
||||
s.Require().Equal(len(vote.Vote.Options), len(tc.expVoteOptions))
|
||||
for i, option := range tc.expVoteOptions {
|
||||
s.Require().Equal(option.Option, vote.Vote.Options[i].Option)
|
||||
s.Require().Equal(option.Weight, vote.Vote.Options[i].Weight)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestGetProposalVotesGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expErr bool
|
||||
}{
|
||||
{
|
||||
"votes with empty proposal id",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes", val.APIAddress, ""),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"get votes with valid id",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes", val.APIAddress, "1"),
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
s.Require().NoError(err)
|
||||
|
||||
var votes v1.QueryVotesResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &votes)
|
||||
|
||||
if tc.expErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().Len(votes.Votes, 1)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestGetProposalDepositGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expErr bool
|
||||
}{
|
||||
{
|
||||
"get deposit with empty proposal id",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.APIAddress, "", val.Address.String()),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"get deposit of non existing proposal",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.APIAddress, "10", val.Address.String()),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"get deposit with wrong depositer address",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.APIAddress, "1", "wrongDepositerAddress"),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"get deposit valid request",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.APIAddress, "1", val.Address.String()),
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
s.Require().NoError(err)
|
||||
|
||||
var deposit v1.QueryDepositResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &deposit)
|
||||
|
||||
if tc.expErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotEmpty(deposit.Deposit)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestGetProposalDepositsGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expErr bool
|
||||
}{
|
||||
{
|
||||
"get deposits with empty proposal id",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits", val.APIAddress, ""),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits", val.APIAddress, "1"),
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
s.Require().NoError(err)
|
||||
|
||||
var deposits v1.QueryDepositsResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &deposits)
|
||||
|
||||
if tc.expErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().Len(deposits.Deposits, 1)
|
||||
s.Require().NotEmpty(deposits.Deposits[0])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestGetTallyGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expErr bool
|
||||
}{
|
||||
{
|
||||
"get tally with no proposal id",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/tally", val.APIAddress, ""),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"get tally with non existing proposal",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/tally", val.APIAddress, "10"),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"get tally valid request",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/tally", val.APIAddress, "1"),
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
s.Require().NoError(err)
|
||||
|
||||
var tally v1.QueryTallyResultResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &tally)
|
||||
|
||||
if tc.expErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotEmpty(tally.Tally)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestGetParamsGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
params := v1.DefaultParams()
|
||||
dp := v1.NewDepositParams(params.MinDeposit, params.MaxDepositPeriod) //nolint:staticcheck // we use deprecated gov commands here, but we don't want to remove them
|
||||
vp := v1.NewVotingParams(params.VotingPeriod) //nolint:staticcheck // we use deprecated gov commands here, but we don't want to remove them
|
||||
tp := v1.NewTallyParams(params.Quorum, params.Threshold, params.VetoThreshold) //nolint:staticcheck // we use deprecated gov commands here, but we don't want to remove them
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expErr bool
|
||||
respType proto.Message
|
||||
expectResp proto.Message
|
||||
}{
|
||||
{
|
||||
"request params with empty params type",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/params/%s", val.APIAddress, ""),
|
||||
true, nil, nil,
|
||||
},
|
||||
{
|
||||
"get deposit params",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/params/%s", val.APIAddress, v1.ParamDeposit),
|
||||
false,
|
||||
&v1.QueryParamsResponse{},
|
||||
&v1.QueryParamsResponse{DepositParams: &dp, Params: ¶ms},
|
||||
},
|
||||
{
|
||||
"get vote params",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/params/%s", val.APIAddress, v1.ParamVoting),
|
||||
false,
|
||||
&v1.QueryParamsResponse{},
|
||||
&v1.QueryParamsResponse{VotingParams: &vp, Params: ¶ms},
|
||||
},
|
||||
{
|
||||
"get tally params",
|
||||
fmt.Sprintf("%s/cosmos/gov/v1/params/%s", val.APIAddress, v1.ParamTallying),
|
||||
false,
|
||||
&v1.QueryParamsResponse{},
|
||||
&v1.QueryParamsResponse{TallyParams: &tp, Params: ¶ms},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType)
|
||||
|
||||
if tc.expErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(tc.expectResp.String(), tc.respType.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,546 @@
|
||||
package gov
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
tmcli "github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
||||
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||
)
|
||||
|
||||
func (s *IntegrationTestSuite) TestCmdParams() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectedOutput string
|
||||
}{
|
||||
{
|
||||
"json output",
|
||||
[]string{fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
|
||||
`{"voting_params":{"voting_period":"172800s"},"deposit_params":{"min_deposit":[{"denom":"stake","amount":"10000000"}],"max_deposit_period":"172800s"},"tally_params":{"quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000"},"params":{"min_deposit":[{"denom":"stake","amount":"10000000"}],"max_deposit_period":"172800s","voting_period":"172800s","quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000","min_initial_deposit_ratio":"0.000000000000000000"}}`,
|
||||
},
|
||||
{
|
||||
"text output",
|
||||
[]string{},
|
||||
`
|
||||
deposit_params:
|
||||
max_deposit_period: 172800s
|
||||
min_deposit:
|
||||
- amount: "10000000"
|
||||
denom: stake
|
||||
params:
|
||||
max_deposit_period: 172800s
|
||||
min_deposit:
|
||||
- amount: "10000000"
|
||||
denom: stake
|
||||
min_initial_deposit_ratio: "0.000000000000000000"
|
||||
quorum: "0.334000000000000000"
|
||||
threshold: "0.500000000000000000"
|
||||
veto_threshold: "0.334000000000000000"
|
||||
voting_period: 172800s
|
||||
tally_params:
|
||||
quorum: "0.334000000000000000"
|
||||
threshold: "0.500000000000000000"
|
||||
veto_threshold: "0.334000000000000000"
|
||||
voting_params:
|
||||
voting_period: 172800s
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.GetCmdQueryParams()
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(strings.TrimSpace(tc.expectedOutput), strings.TrimSpace(out.String()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestCmdParam() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectedOutput string
|
||||
}{
|
||||
{
|
||||
"voting params",
|
||||
[]string{
|
||||
"voting",
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
`{"voting_period":"172800000000000"}`,
|
||||
},
|
||||
{
|
||||
"tally params",
|
||||
[]string{
|
||||
"tallying",
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
`{"quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000"}`,
|
||||
},
|
||||
{
|
||||
"deposit params",
|
||||
[]string{
|
||||
"deposit",
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
`{"min_deposit":[{"denom":"stake","amount":"10000000"}],"max_deposit_period":"172800000000000"}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.GetCmdQueryParam()
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(strings.TrimSpace(tc.expectedOutput), strings.TrimSpace(out.String()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestCmdProposer() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
expectedOutput string
|
||||
}{
|
||||
{
|
||||
"without proposal id",
|
||||
[]string{
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
true,
|
||||
``,
|
||||
},
|
||||
{
|
||||
"json output",
|
||||
[]string{
|
||||
"1",
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
false,
|
||||
fmt.Sprintf("{\"proposal_id\":\"%s\",\"proposer\":\"%s\"}", "1", val.Address.String()),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.GetCmdQueryProposer()
|
||||
clientCtx := val.ClientCtx
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(strings.TrimSpace(tc.expectedOutput), strings.TrimSpace(out.String()))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestCmdTally() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
expectedOutput v1.TallyResult
|
||||
}{
|
||||
{
|
||||
"without proposal id",
|
||||
[]string{
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
true,
|
||||
v1.TallyResult{},
|
||||
},
|
||||
{
|
||||
"json output",
|
||||
[]string{
|
||||
"2",
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
false,
|
||||
v1.NewTallyResult(sdk.NewInt(0), sdk.NewInt(0), sdk.NewInt(0), sdk.NewInt(0)),
|
||||
},
|
||||
{
|
||||
"json output",
|
||||
[]string{
|
||||
"1",
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
false,
|
||||
v1.NewTallyResult(s.cfg.BondedTokens, sdk.NewInt(0), sdk.NewInt(0), sdk.NewInt(0)),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.GetCmdQueryTally()
|
||||
clientCtx := val.ClientCtx
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
var tally v1.TallyResult
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &tally), out.String())
|
||||
s.Require().Equal(tally, tc.expectedOutput)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestCmdGetProposal() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
title := "Text Proposal 1"
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
"get non existing proposal",
|
||||
[]string{
|
||||
"10",
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"get proposal with json response",
|
||||
[]string{
|
||||
"1",
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.GetCmdQueryProposal()
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
var proposal v1.Proposal
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &proposal), out.String())
|
||||
s.Require().Equal(title, proposal.Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content).GetTitle())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestCmdGetProposals() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
"get proposals as json response",
|
||||
[]string{
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"get proposals with invalid status",
|
||||
[]string{
|
||||
"--status=unknown",
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.GetCmdQueryProposals()
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
var proposals v1.QueryProposalsResponse
|
||||
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &proposals), out.String())
|
||||
s.Require().Len(proposals.Proposals, 3)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestCmdQueryDeposits() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
"get deposits of non existing proposal",
|
||||
[]string{
|
||||
"10",
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"get deposits(valid req)",
|
||||
[]string{
|
||||
"1",
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.GetCmdQueryDeposits()
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
|
||||
var deposits v1.QueryDepositsResponse
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &deposits), out.String())
|
||||
s.Require().Len(deposits.Deposits, 1)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestCmdQueryDeposit() {
|
||||
val := s.network.Validators[0]
|
||||
depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
"get deposit with no depositer",
|
||||
[]string{
|
||||
"1",
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"get deposit with wrong deposit address",
|
||||
[]string{
|
||||
"1",
|
||||
"wrong address",
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"get deposit (valid req)",
|
||||
[]string{
|
||||
"1",
|
||||
val.Address.String(),
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.GetCmdQueryDeposit()
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
|
||||
var deposit v1.Deposit
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &deposit), out.String())
|
||||
s.Require().Equal(depositAmount.String(), sdk.Coins(deposit.Amount).String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestCmdQueryVotes() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
"get votes with no proposal id",
|
||||
[]string{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"get votes of non existed proposal",
|
||||
[]string{
|
||||
"10",
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"vote for invalid proposal",
|
||||
[]string{
|
||||
"1",
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.GetCmdQueryVotes()
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
|
||||
var votes v1.QueryVotesResponse
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &votes), out.String())
|
||||
s.Require().Len(votes.Votes, 1)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestCmdQueryVote() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
expVoteOptions v1.WeightedVoteOptions
|
||||
}{
|
||||
{
|
||||
"get vote of non existing proposal",
|
||||
[]string{
|
||||
"10",
|
||||
val.Address.String(),
|
||||
},
|
||||
true,
|
||||
v1.NewNonSplitVoteOption(v1.OptionYes),
|
||||
},
|
||||
{
|
||||
"get vote by wrong voter",
|
||||
[]string{
|
||||
"1",
|
||||
"wrong address",
|
||||
},
|
||||
true,
|
||||
v1.NewNonSplitVoteOption(v1.OptionYes),
|
||||
},
|
||||
{
|
||||
"vote for valid proposal",
|
||||
[]string{
|
||||
"1",
|
||||
val.Address.String(),
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
false,
|
||||
v1.NewNonSplitVoteOption(v1.OptionYes),
|
||||
},
|
||||
{
|
||||
"split vote for valid proposal",
|
||||
[]string{
|
||||
"3",
|
||||
val.Address.String(),
|
||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||
},
|
||||
false,
|
||||
v1.WeightedVoteOptions{
|
||||
&v1.WeightedVoteOption{Option: v1.OptionYes, Weight: sdk.NewDecWithPrec(60, 2).String()},
|
||||
&v1.WeightedVoteOption{Option: v1.OptionNo, Weight: sdk.NewDecWithPrec(30, 2).String()},
|
||||
&v1.WeightedVoteOption{Option: v1.OptionAbstain, Weight: sdk.NewDecWithPrec(5, 2).String()},
|
||||
&v1.WeightedVoteOption{Option: v1.OptionNoWithVeto, Weight: sdk.NewDecWithPrec(5, 2).String()},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.GetCmdQueryVote()
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
|
||||
var vote v1.Vote
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &vote), out.String())
|
||||
s.Require().Equal(len(vote.Options), len(tc.expVoteOptions))
|
||||
for i, option := range tc.expVoteOptions {
|
||||
s.Require().Equal(option.Option, vote.Options[i].Option)
|
||||
s.Require().Equal(option.Weight, vote.Options[i].Weight)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,508 @@
|
||||
package gov
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
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"
|
||||
)
|
||||
|
||||
type IntegrationTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
cfg network.Config
|
||||
network *network.Network
|
||||
}
|
||||
|
||||
func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite {
|
||||
return &IntegrationTestSuite{cfg: cfg}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) SetupSuite() {
|
||||
s.T().Log("setting up integration test suite")
|
||||
|
||||
var err error
|
||||
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
val := s.network.Validators[0]
|
||||
|
||||
// create a proposal with deposit
|
||||
_, 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 = 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 = 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 = 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 = 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())
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down integration test suite")
|
||||
s.network.Cleanup()
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestNewCmdSubmitProposal() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
// Create a legacy proposal JSON, make sure it doesn't pass this new CLI
|
||||
// command.
|
||||
invalidProp := `{
|
||||
"title": "",
|
||||
"description": "Where is the title!?",
|
||||
"type": "Text",
|
||||
"deposit": "-324foocoin"
|
||||
}`
|
||||
invalidPropFile := testutil.WriteToNewTempFile(s.T(), invalidProp)
|
||||
defer invalidPropFile.Close()
|
||||
|
||||
// Create a valid new proposal JSON.
|
||||
propMetadata := []byte{42}
|
||||
validProp := fmt.Sprintf(`
|
||||
{
|
||||
"messages": [
|
||||
{
|
||||
"@type": "/cosmos.gov.v1.MsgExecLegacyContent",
|
||||
"authority": "%s",
|
||||
"content": {
|
||||
"@type": "/cosmos.gov.v1beta1.TextProposal",
|
||||
"title": "My awesome title",
|
||||
"description": "My awesome description"
|
||||
}
|
||||
}
|
||||
],
|
||||
"metadata": "%s",
|
||||
"deposit": "%s"
|
||||
}`, authtypes.NewModuleAddress(types.ModuleName), base64.StdEncoding.EncodeToString(propMetadata), sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(5431)))
|
||||
validPropFile := testutil.WriteToNewTempFile(s.T(), validProp)
|
||||
defer validPropFile.Close()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
expectedCode uint32
|
||||
respType proto.Message
|
||||
}{
|
||||
{
|
||||
"invalid proposal",
|
||||
[]string{
|
||||
invalidPropFile.Name(),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
true, 0, nil,
|
||||
},
|
||||
{
|
||||
"valid proposal",
|
||||
[]string{
|
||||
validPropFile.Name(),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
false, 0, &sdk.TxResponse{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewCmdSubmitProposal()
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())
|
||||
txResp := tc.respType.(*sdk.TxResponse)
|
||||
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestNewCmdSubmitLegacyProposal() {
|
||||
val := s.network.Validators[0]
|
||||
invalidProp := `{
|
||||
"title": "",
|
||||
"description": "Where is the title!?",
|
||||
"type": "Text",
|
||||
"deposit": "-324foocoin"
|
||||
}`
|
||||
invalidPropFile := testutil.WriteToNewTempFile(s.T(), invalidProp)
|
||||
defer invalidPropFile.Close()
|
||||
validProp := fmt.Sprintf(`{
|
||||
"title": "Text Proposal",
|
||||
"description": "Hello, World!",
|
||||
"type": "Text",
|
||||
"deposit": "%s"
|
||||
}`, sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(5431)))
|
||||
validPropFile := testutil.WriteToNewTempFile(s.T(), validProp)
|
||||
defer validPropFile.Close()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
expectedCode uint32
|
||||
respType proto.Message
|
||||
}{
|
||||
{
|
||||
"invalid proposal (file)",
|
||||
[]string{
|
||||
fmt.Sprintf("--%s=%s", cli.FlagProposal, invalidPropFile.Name()), //nolint:staticcheck // we are intentionally using a deprecated flag here.
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
true, 0, nil,
|
||||
},
|
||||
{
|
||||
"invalid proposal",
|
||||
[]string{
|
||||
fmt.Sprintf("--%s='Where is the title!?'", cli.FlagDescription), //nolint:staticcheck // we are intentionally using a deprecated flag here.
|
||||
fmt.Sprintf("--%s=%s", cli.FlagProposalType, v1beta1.ProposalTypeText), //nolint:staticcheck // we are intentionally using a deprecated flag here.
|
||||
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(5431)).String()),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
true, 0, nil,
|
||||
},
|
||||
{
|
||||
"valid transaction (file)",
|
||||
//nolint:staticcheck // we are intentionally using a deprecated flag here.
|
||||
[]string{
|
||||
fmt.Sprintf("--%s=%s", cli.FlagProposal, validPropFile.Name()),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
false, 0, &sdk.TxResponse{},
|
||||
},
|
||||
{
|
||||
"valid transaction",
|
||||
[]string{
|
||||
fmt.Sprintf("--%s='Text Proposal'", cli.FlagTitle), //nolint:staticcheck // we are intentionally using a deprecated flag here.
|
||||
fmt.Sprintf("--%s='Where is the title!?'", cli.FlagDescription), //nolint:staticcheck // we are intentionally using a deprecated flag here.
|
||||
fmt.Sprintf("--%s=%s", cli.FlagProposalType, v1beta1.ProposalTypeText), //nolint:staticcheck // we are intentionally using a deprecated flag here.
|
||||
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(5431)).String()),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
false, 0, &sdk.TxResponse{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewCmdSubmitLegacyProposal()
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())
|
||||
txResp := tc.respType.(*sdk.TxResponse)
|
||||
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestNewCmdDeposit() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
expectedCode uint32
|
||||
}{
|
||||
{
|
||||
"without proposal id",
|
||||
[]string{
|
||||
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)).String(), // 10stake
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
true, 0,
|
||||
},
|
||||
{
|
||||
"without deposit amount",
|
||||
[]string{
|
||||
"1",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
true, 0,
|
||||
},
|
||||
{
|
||||
"deposit on non existing proposal",
|
||||
[]string{
|
||||
"10",
|
||||
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)).String(), // 10stake
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
false, 2,
|
||||
},
|
||||
{
|
||||
"deposit on non existing proposal",
|
||||
[]string{
|
||||
"1",
|
||||
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)).String(), // 10stake
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
false, 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
var resp sdk.TxResponse
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewCmdDeposit()
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &resp), out.String())
|
||||
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, tc.expectedCode))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestNewCmdVote() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
expectedCode uint32
|
||||
}{
|
||||
{
|
||||
"invalid vote",
|
||||
[]string{},
|
||||
true, 0,
|
||||
},
|
||||
{
|
||||
"vote for invalid proposal",
|
||||
[]string{
|
||||
"10",
|
||||
"yes",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--metadata=%s", "AQ=="),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
false, 3,
|
||||
},
|
||||
{
|
||||
"valid vote",
|
||||
[]string{
|
||||
"1",
|
||||
"yes",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
false, 0,
|
||||
},
|
||||
{
|
||||
"valid vote with metadata",
|
||||
[]string{
|
||||
"1",
|
||||
"yes",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--metadata=%s", "AQ=="),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
false, 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewCmdVote()
|
||||
clientCtx := val.ClientCtx
|
||||
var txResp sdk.TxResponse
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
|
||||
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestNewCmdWeightedVote() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
expectedCode uint32
|
||||
}{
|
||||
{
|
||||
"invalid vote",
|
||||
[]string{},
|
||||
true, 0,
|
||||
},
|
||||
{
|
||||
"vote for invalid proposal",
|
||||
[]string{
|
||||
"10",
|
||||
"yes",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
false, 3,
|
||||
},
|
||||
{
|
||||
"valid vote",
|
||||
[]string{
|
||||
"1",
|
||||
"yes",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
false, 0,
|
||||
},
|
||||
{
|
||||
"valid vote with metadata",
|
||||
[]string{
|
||||
"1",
|
||||
"yes",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--metadata=%s", "AQ=="),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
false, 0,
|
||||
},
|
||||
{
|
||||
"invalid valid split vote string",
|
||||
[]string{
|
||||
"1",
|
||||
"yes/0.6,no/0.3,abstain/0.05,no_with_veto/0.05",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
true, 0,
|
||||
},
|
||||
{
|
||||
"valid split vote",
|
||||
[]string{
|
||||
"1",
|
||||
"yes=0.6,no=0.3,abstain=0.05,no_with_veto=0.05",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
},
|
||||
false, 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewCmdWeightedVote()
|
||||
clientCtx := val.ClientCtx
|
||||
var txResp sdk.TxResponse
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
|
||||
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user