2021-04-23 11:49:49 -07:00
|
|
|
package testutil
|
2020-05-10 07:25:27 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-09-18 07:26:46 -07:00
|
|
|
"strings"
|
2020-05-10 07:25:27 -07:00
|
|
|
|
2020-12-10 04:56:55 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/testutil"
|
|
|
|
|
2020-08-26 02:39:38 -07:00
|
|
|
"github.com/gogo/protobuf/proto"
|
2020-07-21 06:54:07 -07:00
|
|
|
"github.com/stretchr/testify/suite"
|
2020-05-11 01:22:36 -07:00
|
|
|
|
2020-09-18 09:56:27 -07:00
|
|
|
tmcli "github.com/tendermint/tendermint/libs/cli"
|
|
|
|
|
2020-07-21 06:54:07 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2020-08-17 05:47:31 -07:00
|
|
|
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
2020-07-21 06:54:07 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/testutil/network"
|
2020-05-10 07:25:27 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-07-21 06:54:07 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
2021-12-13 10:48:44 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
2020-05-10 07:25:27 -07:00
|
|
|
)
|
|
|
|
|
2020-07-21 06:54:07 -07:00
|
|
|
type IntegrationTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
cfg network.Config
|
|
|
|
network *network.Network
|
|
|
|
}
|
|
|
|
|
2021-04-23 11:49:49 -07:00
|
|
|
func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite {
|
|
|
|
return &IntegrationTestSuite{cfg: cfg}
|
|
|
|
}
|
|
|
|
|
2020-07-21 06:54:07 -07:00
|
|
|
func (s *IntegrationTestSuite) SetupSuite() {
|
|
|
|
s.T().Log("setting up integration test suite")
|
|
|
|
|
2021-06-29 03:41:55 -07:00
|
|
|
var err error
|
|
|
|
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
|
|
|
|
s.Require().NoError(err)
|
2020-07-21 06:54:07 -07:00
|
|
|
|
2021-06-29 03:41:55 -07:00
|
|
|
_, err = s.network.WaitForHeight(1)
|
2020-07-21 06:54:07 -07:00
|
|
|
s.Require().NoError(err)
|
2020-09-18 07:26:46 -07:00
|
|
|
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
|
|
|
|
// create a proposal with deposit
|
2021-04-23 11:49:49 -07:00
|
|
|
_, err = MsgSubmitProposal(val.ClientCtx, val.Address.String(),
|
2021-12-13 10:48:44 -08:00
|
|
|
"Text Proposal 1", "Where is the title!?", v1beta1.ProposalTypeText,
|
|
|
|
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, v1beta1.DefaultMinDepositTokens).String()))
|
2020-09-18 07:26:46 -07:00
|
|
|
s.Require().NoError(err)
|
|
|
|
_, err = s.network.WaitForHeight(1)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// vote for proposal
|
2021-04-23 11:49:49 -07:00
|
|
|
_, err = MsgVote(val.ClientCtx, val.Address.String(), "1", "yes")
|
2020-09-18 07:26:46 -07:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// create a proposal without deposit
|
2021-04-23 11:49:49 -07:00
|
|
|
_, err = MsgSubmitProposal(val.ClientCtx, val.Address.String(),
|
2021-12-13 10:48:44 -08:00
|
|
|
"Text Proposal 2", "Where is the title!?", v1beta1.ProposalTypeText)
|
2020-09-18 07:26:46 -07:00
|
|
|
s.Require().NoError(err)
|
|
|
|
_, err = s.network.WaitForHeight(1)
|
|
|
|
s.Require().NoError(err)
|
2020-10-29 06:52:21 -07:00
|
|
|
|
|
|
|
// create a proposal3 with deposit
|
2021-04-23 11:49:49 -07:00
|
|
|
_, err = MsgSubmitProposal(val.ClientCtx, val.Address.String(),
|
2021-12-13 10:48:44 -08:00
|
|
|
"Text Proposal 3", "Where is the title!?", v1beta1.ProposalTypeText,
|
|
|
|
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, v1beta1.DefaultMinDepositTokens).String()))
|
2020-10-29 06:52:21 -07:00
|
|
|
s.Require().NoError(err)
|
|
|
|
_, err = s.network.WaitForHeight(1)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// vote for proposal3 as val
|
2021-04-23 11:49:49 -07:00
|
|
|
_, err = MsgVote(val.ClientCtx, val.Address.String(), "3", "yes=0.6,no=0.3,abstain=0.05,no_with_veto=0.05")
|
2020-10-29 06:52:21 -07:00
|
|
|
s.Require().NoError(err)
|
2020-07-21 06:54:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *IntegrationTestSuite) TearDownSuite() {
|
|
|
|
s.T().Log("tearing down integration test suite")
|
|
|
|
s.network.Cleanup()
|
|
|
|
}
|
|
|
|
|
2020-09-18 07:26:46 -07:00
|
|
|
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":"172800000000000"},"tally_params":{"quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000"},"deposit_params":{"min_deposit":[{"denom":"stake","amount":"10000000"}],"max_deposit_period":"172800000000000"}}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"text output",
|
|
|
|
[]string{},
|
|
|
|
`
|
|
|
|
deposit_params:
|
|
|
|
max_deposit_period: "172800000000000"
|
|
|
|
min_deposit:
|
|
|
|
- amount: "10000000"
|
|
|
|
denom: stake
|
|
|
|
tally_params:
|
|
|
|
quorum: "0.334000000000000000"
|
|
|
|
threshold: "0.500000000000000000"
|
|
|
|
veto_threshold: "0.334000000000000000"
|
|
|
|
voting_params:
|
|
|
|
voting_period: "172800000000000"
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2021-12-13 10:48:44 -08:00
|
|
|
expectedOutput v1beta1.TallyResult
|
2020-09-18 07:26:46 -07:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"without proposal id",
|
|
|
|
[]string{
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
},
|
|
|
|
true,
|
2021-12-13 10:48:44 -08:00
|
|
|
v1beta1.TallyResult{},
|
2020-09-18 07:26:46 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"json output",
|
|
|
|
[]string{
|
|
|
|
"2",
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
},
|
|
|
|
false,
|
2021-12-13 10:48:44 -08:00
|
|
|
v1beta1.NewTallyResult(sdk.NewInt(0), sdk.NewInt(0), sdk.NewInt(0), sdk.NewInt(0)),
|
2020-09-18 07:26:46 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"json output",
|
|
|
|
[]string{
|
|
|
|
"1",
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
},
|
|
|
|
false,
|
2021-12-13 10:48:44 -08:00
|
|
|
v1beta1.NewTallyResult(s.cfg.BondedTokens, sdk.NewInt(0), sdk.NewInt(0), sdk.NewInt(0)),
|
2020-09-18 07:26:46 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2021-12-13 10:48:44 -08:00
|
|
|
var tally v1beta1.TallyResult
|
2021-06-11 04:49:39 -07:00
|
|
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &tally), out.String())
|
2020-09-18 07:26:46 -07:00
|
|
|
s.Require().Equal(tally, tc.expectedOutput)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-21 06:54:07 -07:00
|
|
|
func (s *IntegrationTestSuite) TestNewCmdSubmitProposal() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
invalidProp := `{
|
|
|
|
"title": "",
|
|
|
|
"description": "Where is the title!?",
|
|
|
|
"type": "Text",
|
|
|
|
"deposit": "-324foocoin"
|
|
|
|
}`
|
2020-12-10 04:56:55 -08:00
|
|
|
invalidPropFile := testutil.WriteToNewTempFile(s.T(), invalidProp)
|
2020-07-21 06:54:07 -07:00
|
|
|
validProp := fmt.Sprintf(`{
|
|
|
|
"title": "Text Proposal",
|
|
|
|
"description": "Hello, World!",
|
|
|
|
"type": "Text",
|
|
|
|
"deposit": "%s"
|
|
|
|
}`, sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(5431)))
|
2020-12-10 04:56:55 -08:00
|
|
|
validPropFile := testutil.WriteToNewTempFile(s.T(), validProp)
|
2020-07-21 06:54:07 -07:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
expectErr bool
|
|
|
|
expectedCode uint32
|
2021-04-23 11:49:49 -07:00
|
|
|
respType proto.Message
|
2020-07-21 06:54:07 -07:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"invalid proposal (file)",
|
|
|
|
[]string{
|
|
|
|
fmt.Sprintf("--%s=%s", cli.FlagProposal, invalidPropFile.Name()),
|
|
|
|
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()),
|
|
|
|
},
|
2021-04-23 11:49:49 -07:00
|
|
|
true, 0, nil,
|
2020-07-21 06:54:07 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid proposal",
|
|
|
|
[]string{
|
|
|
|
fmt.Sprintf("--%s='Where is the title!?'", cli.FlagDescription),
|
2021-12-13 10:48:44 -08:00
|
|
|
fmt.Sprintf("--%s=%s", cli.FlagProposalType, v1beta1.ProposalTypeText),
|
2020-07-21 06:54:07 -07:00
|
|
|
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()),
|
|
|
|
},
|
2021-04-23 11:49:49 -07:00
|
|
|
true, 0, nil,
|
2020-07-21 06:54:07 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"valid transaction (file)",
|
|
|
|
[]string{
|
|
|
|
fmt.Sprintf("--%s=%s", cli.FlagProposal, validPropFile.Name()),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
2020-07-29 15:33:42 -07:00
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
2020-07-21 06:54:07 -07:00
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
|
|
|
},
|
2021-04-23 11:49:49 -07:00
|
|
|
false, 0, &sdk.TxResponse{},
|
2020-07-21 06:54:07 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"valid transaction",
|
|
|
|
[]string{
|
|
|
|
fmt.Sprintf("--%s='Text Proposal'", cli.FlagTitle),
|
|
|
|
fmt.Sprintf("--%s='Where is the title!?'", cli.FlagDescription),
|
2021-12-13 10:48:44 -08:00
|
|
|
fmt.Sprintf("--%s=%s", cli.FlagProposalType, v1beta1.ProposalTypeText),
|
2020-07-21 06:54:07 -07:00
|
|
|
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),
|
2020-07-29 15:33:42 -07:00
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
2020-07-21 06:54:07 -07:00
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
|
|
|
},
|
2021-04-23 11:49:49 -07:00
|
|
|
false, 0, &sdk.TxResponse{},
|
2020-07-21 06:54:07 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
tc := tc
|
|
|
|
|
|
|
|
s.Run(tc.name, func() {
|
|
|
|
cmd := cli.NewCmdSubmitProposal()
|
2020-08-17 05:47:31 -07:00
|
|
|
clientCtx := val.ClientCtx
|
2020-07-21 06:54:07 -07:00
|
|
|
|
2020-08-17 05:47:31 -07:00
|
|
|
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
2020-07-21 06:54:07 -07:00
|
|
|
if tc.expectErr {
|
|
|
|
s.Require().Error(err)
|
|
|
|
} else {
|
|
|
|
s.Require().NoError(err)
|
2021-06-11 04:49:39 -07:00
|
|
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())
|
2020-07-21 06:54:07 -07:00
|
|
|
txResp := tc.respType.(*sdk.TxResponse)
|
|
|
|
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-18 07:26:46 -07:00
|
|
|
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)
|
2021-12-13 10:48:44 -08:00
|
|
|
var proposal v1beta1.Proposal
|
2021-06-11 04:49:39 -07:00
|
|
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &proposal), out.String())
|
2020-09-18 07:26:46 -07:00
|
|
|
s.Require().Equal(title, proposal.GetTitle())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *IntegrationTestSuite) TestCmdGetProposals() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
expectErr bool
|
|
|
|
}{
|
|
|
|
{
|
2020-09-18 09:56:27 -07:00
|
|
|
"get proposals as json response",
|
2020-09-18 07:26:46 -07:00
|
|
|
[]string{
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2021-03-08 06:38:24 -08:00
|
|
|
{
|
|
|
|
"get proposals with invalid status",
|
|
|
|
[]string{
|
|
|
|
"--status=unknown",
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
2020-09-18 07:26:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2021-12-13 10:48:44 -08:00
|
|
|
var proposals v1beta1.QueryProposalsResponse
|
2020-09-18 07:26:46 -07:00
|
|
|
|
2021-06-11 04:49:39 -07:00
|
|
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &proposals), out.String())
|
2020-10-29 06:52:21 -07:00
|
|
|
s.Require().Len(proposals.Proposals, 3)
|
2020-09-18 07:26:46 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
var deposits v1beta1.QueryDepositsResponse
|
2021-06-11 04:49:39 -07:00
|
|
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &deposits), out.String())
|
2020-09-18 07:26:46 -07:00
|
|
|
s.Require().Len(deposits.Deposits, 1)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *IntegrationTestSuite) TestCmdQueryDeposit() {
|
|
|
|
val := s.network.Validators[0]
|
2021-12-13 10:48:44 -08:00
|
|
|
depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1beta1.DefaultMinDepositTokens)
|
2020-09-18 07:26:46 -07:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
var deposit v1beta1.Deposit
|
2021-06-11 04:49:39 -07:00
|
|
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &deposit), out.String())
|
2020-09-18 07:26:46 -07:00
|
|
|
s.Require().Equal(depositAmount.String(), deposit.Amount.String())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *IntegrationTestSuite) TestNewCmdDeposit() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
expectErr bool
|
|
|
|
expectedCode uint32
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"without proposal id",
|
|
|
|
[]string{
|
2021-04-23 11:49:49 -07:00
|
|
|
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)).String(), // 10stake
|
2020-09-18 07:26:46 -07:00
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
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.BroadcastBlock),
|
|
|
|
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",
|
2021-04-23 11:49:49 -07:00
|
|
|
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)).String(), // 10stake
|
2020-09-18 07:26:46 -07:00
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
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",
|
2021-04-23 11:49:49 -07:00
|
|
|
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)).String(), // 10stake
|
2020-09-18 07:26:46 -07:00
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
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)
|
|
|
|
|
2021-06-11 04:49:39 -07:00
|
|
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &resp), out.String())
|
2020-09-18 07:26:46 -07:00
|
|
|
s.Require().Equal(tc.expectedCode, resp.Code, out.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)
|
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
var votes v1beta1.QueryVotesResponse
|
2021-06-11 04:49:39 -07:00
|
|
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &votes), out.String())
|
2020-10-29 06:52:21 -07:00
|
|
|
s.Require().Len(votes.Votes, 1)
|
2020-09-18 07:26:46 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *IntegrationTestSuite) TestCmdQueryVote() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
|
|
|
|
testCases := []struct {
|
2020-10-30 06:14:39 -07:00
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
expectErr bool
|
2021-12-13 10:48:44 -08:00
|
|
|
expVoteOptions v1beta1.WeightedVoteOptions
|
2020-09-18 07:26:46 -07:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"get vote of non existing proposal",
|
|
|
|
[]string{
|
|
|
|
"10",
|
|
|
|
val.Address.String(),
|
|
|
|
},
|
|
|
|
true,
|
2021-12-13 10:48:44 -08:00
|
|
|
v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes),
|
2020-09-18 07:26:46 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"get vote by wrong voter",
|
|
|
|
[]string{
|
|
|
|
"1",
|
|
|
|
"wrong address",
|
|
|
|
},
|
|
|
|
true,
|
2021-12-13 10:48:44 -08:00
|
|
|
v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes),
|
2020-09-18 07:26:46 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"vote for valid proposal",
|
|
|
|
[]string{
|
|
|
|
"1",
|
|
|
|
val.Address.String(),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
},
|
|
|
|
false,
|
2021-12-13 10:48:44 -08:00
|
|
|
v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes),
|
2020-10-29 05:24:55 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"split vote for valid proposal",
|
|
|
|
[]string{
|
2020-10-29 06:52:21 -07:00
|
|
|
"3",
|
|
|
|
val.Address.String(),
|
2020-10-29 05:24:55 -07:00
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
},
|
|
|
|
false,
|
2021-12-13 10:48:44 -08:00
|
|
|
v1beta1.WeightedVoteOptions{
|
|
|
|
v1beta1.WeightedVoteOption{Option: v1beta1.OptionYes, Weight: sdk.NewDecWithPrec(60, 2)},
|
|
|
|
v1beta1.WeightedVoteOption{Option: v1beta1.OptionNo, Weight: sdk.NewDecWithPrec(30, 2)},
|
|
|
|
v1beta1.WeightedVoteOption{Option: v1beta1.OptionAbstain, Weight: sdk.NewDecWithPrec(5, 2)},
|
|
|
|
v1beta1.WeightedVoteOption{Option: v1beta1.OptionNoWithVeto, Weight: sdk.NewDecWithPrec(5, 2)},
|
2020-10-29 05:24:55 -07:00
|
|
|
},
|
2020-09-18 07:26:46 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
var vote v1beta1.Vote
|
2021-06-11 04:49:39 -07:00
|
|
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &vote), out.String())
|
2020-10-30 06:14:39 -07:00
|
|
|
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().True(option.Weight.Equal(vote.Options[i].Weight))
|
2020-10-29 05:24:55 -07:00
|
|
|
}
|
2020-09-18 07:26:46 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *IntegrationTestSuite) TestNewCmdVote() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
|
2020-11-03 03:48:53 -08:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
expectErr bool
|
|
|
|
expectedCode uint32
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"invalid vote",
|
|
|
|
[]string{},
|
|
|
|
true, 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"vote for invalid proposal",
|
|
|
|
[]string{
|
|
|
|
"10",
|
2021-04-23 11:49:49 -07:00
|
|
|
"yes",
|
2020-11-03 03:48:53 -08:00
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
|
|
|
},
|
|
|
|
false, 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"valid vote",
|
|
|
|
[]string{
|
|
|
|
"1",
|
2021-04-23 11:49:49 -07:00
|
|
|
"yes",
|
2020-11-03 03:48:53 -08:00
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
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)
|
2021-06-11 04:49:39 -07:00
|
|
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
|
2020-11-03 03:48:53 -08:00
|
|
|
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *IntegrationTestSuite) TestNewCmdWeightedVote() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
|
2020-09-18 07:26:46 -07:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
expectErr bool
|
|
|
|
expectedCode uint32
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"invalid vote",
|
|
|
|
[]string{},
|
|
|
|
true, 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"vote for invalid proposal",
|
|
|
|
[]string{
|
|
|
|
"10",
|
2021-04-23 11:49:49 -07:00
|
|
|
"yes",
|
2020-09-18 07:26:46 -07:00
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
|
|
|
},
|
|
|
|
false, 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"valid vote",
|
|
|
|
[]string{
|
|
|
|
"1",
|
2021-04-23 11:49:49 -07:00
|
|
|
"yes",
|
2020-09-18 07:26:46 -07:00
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
|
|
|
},
|
|
|
|
false, 0,
|
|
|
|
},
|
2020-10-29 05:24:55 -07:00
|
|
|
{
|
|
|
|
"invalid valid split vote string",
|
|
|
|
[]string{
|
|
|
|
"1",
|
2021-04-23 11:49:49 -07:00
|
|
|
"yes/0.6,no/0.3,abstain/0.05,no_with_veto/0.05",
|
2020-10-29 05:24:55 -07:00
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
|
|
|
},
|
|
|
|
true, 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"valid split vote",
|
|
|
|
[]string{
|
|
|
|
"1",
|
2021-04-23 11:49:49 -07:00
|
|
|
"yes=0.6,no=0.3,abstain=0.05,no_with_veto=0.05",
|
2020-10-29 05:24:55 -07:00
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
|
|
|
},
|
|
|
|
false, 0,
|
|
|
|
},
|
2020-09-18 07:26:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
tc := tc
|
|
|
|
s.Run(tc.name, func() {
|
2020-11-03 03:48:53 -08:00
|
|
|
cmd := cli.NewCmdWeightedVote()
|
2020-09-18 07:26:46 -07:00
|
|
|
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)
|
2021-06-11 04:49:39 -07:00
|
|
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
|
2020-09-18 07:26:46 -07:00
|
|
|
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|