feat(x/gov): implement a minimum amount per deposit (#18146)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
Aleksandr Bezobchuk
Julien Robert
parent
bd274b8c9a
commit
177e7f4595
@@ -14,7 +14,6 @@ import (
|
||||
"cosmossdk.io/x/gov/types/v1beta1"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
@@ -72,33 +71,6 @@ func (s *DepositTestSuite) TearDownSuite() {
|
||||
s.network.Cleanup()
|
||||
}
|
||||
|
||||
func (s *DepositTestSuite) TestQueryDepositsWithoutInitialDeposit() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
// submit proposal without initial deposit
|
||||
id := s.submitProposal(val, sdk.NewCoin(s.cfg.BondDenom, math.NewInt(0)), "TestQueryDepositsWithoutInitialDeposit")
|
||||
|
||||
// deposit amount
|
||||
depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens.Add(math.NewInt(50)))
|
||||
msg := v1.NewMsgDeposit(val.Address, id, sdk.NewCoins(depositAmount))
|
||||
_, err := clitestutil.SubmitTestTx(val.ClientCtx, msg, val.Address, clitestutil.TestTxConfig{})
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
// query deposit
|
||||
proposalID := strconv.FormatUint(id, 10)
|
||||
deposit := s.queryDeposit(val, proposalID, false, "")
|
||||
s.Require().NotNil(deposit)
|
||||
s.Require().Equal(depositAmount.String(), sdk.Coins(deposit.Deposit.Amount).String())
|
||||
|
||||
// query deposits
|
||||
deposits := s.queryDeposits(val, proposalID, false, "")
|
||||
s.Require().NotNil(deposits)
|
||||
s.Require().Len(deposits.Deposits, 1)
|
||||
// verify initial deposit
|
||||
s.Require().Equal(depositAmount.String(), sdk.Coins(deposits.Deposits[0].Amount).String())
|
||||
}
|
||||
|
||||
func (s *DepositTestSuite) TestQueryDepositsWithInitialDeposit() {
|
||||
val := s.network.Validators[0]
|
||||
depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens)
|
||||
|
||||
+9
-6
@@ -59,9 +59,12 @@ func (s *E2ETestSuite) SetupSuite() {
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &resp), out.String())
|
||||
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, 0))
|
||||
|
||||
// create a proposal without deposit
|
||||
// create a proposal with a small deposit
|
||||
minimumAcceptedDep := v1.DefaultMinDepositTokens.ToLegacyDec().Mul(v1.DefaultMinDepositRatio).Ceil().TruncateInt()
|
||||
out, err = govclitestutil.MsgSubmitLegacyProposal(val.ClientCtx, val.Address.String(),
|
||||
"Text Proposal 2", "Where is the title!?", v1beta1.ProposalTypeText)
|
||||
"Text Proposal 2", "Where is the title!?", v1beta1.ProposalTypeText,
|
||||
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, minimumAcceptedDep).String()))
|
||||
|
||||
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, 0))
|
||||
@@ -127,7 +130,7 @@ func (s *E2ETestSuite) TestNewCmdSubmitProposal() {
|
||||
"summary": "My awesome description",
|
||||
"metadata": "%s",
|
||||
"deposit": "%s"
|
||||
}`, authtypes.NewModuleAddress(types.ModuleName), base64.StdEncoding.EncodeToString(propMetadata), sdk.NewCoin(s.cfg.BondDenom, math.NewInt(5431)))
|
||||
}`, authtypes.NewModuleAddress(types.ModuleName), base64.StdEncoding.EncodeToString(propMetadata), sdk.NewCoin(s.cfg.BondDenom, math.NewInt(100000)))
|
||||
validPropFile := testutil.WriteToNewTempFile(s.T(), validProp)
|
||||
defer validPropFile.Close()
|
||||
|
||||
@@ -195,7 +198,7 @@ func (s *E2ETestSuite) TestNewCmdSubmitLegacyProposal() {
|
||||
"description": "Hello, World!",
|
||||
"type": "Text",
|
||||
"deposit": "%s"
|
||||
}`, sdk.NewCoin(s.cfg.BondDenom, math.NewInt(5431)))
|
||||
}`, sdk.NewCoin(s.cfg.BondDenom, math.NewInt(154310)))
|
||||
validPropFile := testutil.WriteToNewTempFile(s.T(), validProp)
|
||||
defer validPropFile.Close()
|
||||
|
||||
@@ -221,7 +224,7 @@ func (s *E2ETestSuite) TestNewCmdSubmitLegacyProposal() {
|
||||
[]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, math.NewInt(5431)).String()),
|
||||
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10000)).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, math.NewInt(10))).String()),
|
||||
@@ -246,7 +249,7 @@ func (s *E2ETestSuite) TestNewCmdSubmitLegacyProposal() {
|
||||
fmt.Sprintf("--%s='Text Proposal'", cli.FlagTitle),
|
||||
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, math.NewInt(5431)).String()),
|
||||
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, math.NewInt(100000)).String()),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
|
||||
@@ -373,14 +373,15 @@ func TestMsgSetSendEnabled(t *testing.T) {
|
||||
s := createTestSuite(t, genAccs)
|
||||
|
||||
ctx := s.App.BaseApp.NewContext(false)
|
||||
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("stake", 101))))
|
||||
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 101))))
|
||||
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("stake", 100000))))
|
||||
addr1Str := addr1.String()
|
||||
govAddr := s.BankKeeper.GetAuthority()
|
||||
goodGovProp, err := govv1.NewMsgSubmitProposal(
|
||||
[]sdk.Msg{
|
||||
types.NewMsgSetSendEnabled(govAddr, nil, nil),
|
||||
},
|
||||
sdk.Coins{{Denom: "stake", Amount: sdkmath.NewInt(5)}},
|
||||
sdk.Coins{{Denom: "stake", Amount: sdkmath.NewInt(100000)}},
|
||||
addr1Str,
|
||||
"set default send enabled to true",
|
||||
"Change send enabled",
|
||||
|
||||
Reference in New Issue
Block a user