Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: add initial deposit ratio requirement of 0.5 for proposal submission #2

Merged
merged 3 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ breaking changes.
This forked Cosmos SDK has the following changes and it contains state breaking changes.

- [`x/staking`](https://github.com/cosmosquad-labs/cosmos-sdk/pull/10) fix: allow delegate only spendable coins
- [`x/gov`](https://github.com/cosmosquad-labs/cosmos-sdk/pull/8) feat: add additional voting powers hook on tally
- [`x/gov`](https://github.com/cosmosquad-labs/cosmos-sdk/pull/8) feat: add additional voting powers hook on tally, add initial deposit ratio requirement of 0.5 for proposal submission
- [`x/vesting`](https://github.com/cosmosquad-labs/cosmos-sdk/pull/11) feat: periodic vesting msg

## Quick Start
Expand Down
2 changes: 2 additions & 0 deletions x/auth/legacy/v043/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ func TestMigrateVestingAccounts(t *testing.T) {

delayedAccount := types.NewPeriodicVestingAccount(baseAccount, vestedCoins, startTime, periods)

ctx = ctx.WithBlockTime(time.Unix(1601042400, 0))

app.AccountKeeper.SetAccount(ctx, delayedAccount)

// delegation of the original vesting, failed because of no spendable balances
Expand Down
1 change: 0 additions & 1 deletion x/auth/vesting/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,4 @@ func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *type
),
)
return &types.MsgCreatePeriodicVestingAccountResponse{}, nil

}
1 change: 0 additions & 1 deletion x/auth/vesting/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func (msg MsgCreateVestingAccount) GetSigners() []sdk.AccAddress {
}

// NewMsgCreatePeriodicVestingAccount returns a reference to a new MsgCreatePeriodicVestingAccount.
//nolint:interfacer
func NewMsgCreatePeriodicVestingAccount(fromAddr, toAddr sdk.AccAddress, startTime int64, periods []Period) *MsgCreatePeriodicVestingAccount {
return &MsgCreatePeriodicVestingAccount{
FromAddress: fromAddr.String(),
Expand Down
27 changes: 27 additions & 0 deletions x/feegrant/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import (
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
"github.com/cosmos/cosmos-sdk/x/feegrant"
"github.com/cosmos/cosmos-sdk/x/feegrant/client/cli"
govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
govtestutil "github.com/cosmos/cosmos-sdk/x/gov/client/testutil"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
Expand Down Expand Up @@ -51,6 +53,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.T().Skip("skipping test in unit-tests mode.")
}

s.cfg.StakingTokens = s.cfg.StakingTokens.Add(govtypes.DefaultMinDepositTokens)
s.network = network.New(s.T(), s.cfg)

_, err := s.network.WaitForHeight(1)
Expand Down Expand Up @@ -745,10 +748,22 @@ func (s *IntegrationTestSuite) TestTxWithFeeGrant() {
_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)

// Send some funds to the new account for initial deposit
_, err = banktestutil.MsgSendExec(
val.ClientCtx,
val.Address,
grantee,
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, govtypes.DefaultMinDepositTokens)), 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()),
)
s.Require().NoError(err)

// granted fee allowance for an account which is not in state and creating
// any tx with it by using --fee-account shouldn't fail
out, err := govtestutil.MsgSubmitProposal(val.ClientCtx, grantee.String(),
"Text Proposal", "No desc", govtypes.ProposalTypeText,
fmt.Sprintf("--%s=%s", govcli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, govtypes.DefaultMinDepositTokens).String()),
fmt.Sprintf("--%s=%s", flags.FlagFeeAccount, granter.String()),
)

Expand Down Expand Up @@ -875,6 +890,17 @@ func (s *IntegrationTestSuite) TestFilteredFeeAllowance() {
spendLimit.String(),
)

// Send some funds to the new account for initial deposit
_, err = banktestutil.MsgSendExec(
val.ClientCtx,
val.Address,
grantee,
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, govtypes.DefaultMinDepositTokens)), 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()),
)
s.Require().NoError(err)

// exec filtered fee allowance
cases := []struct {
name string
Expand All @@ -887,6 +913,7 @@ func (s *IntegrationTestSuite) TestFilteredFeeAllowance() {
func() (testutil.BufferWriter, error) {
return govtestutil.MsgSubmitProposal(val.ClientCtx, grantee.String(),
"Text Proposal", "No desc", govtypes.ProposalTypeText,
fmt.Sprintf("--%s=%s", govcli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, govtypes.DefaultMinDepositTokens).String()),
fmt.Sprintf("--%s=%s", flags.FlagFeeAccount, granter.String()),
)
},
Expand Down
8 changes: 4 additions & 4 deletions x/gov/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestTickExpiredDepositPeriod(t *testing.T) {

newProposalMsg, err := types.NewMsgSubmitProposal(
types.ContentFromProposalType("test", "test", types.ProposalTypeText),
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5000000)},
addrs[0],
)
require.NoError(t, err)
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) {

newProposalMsg, err := types.NewMsgSubmitProposal(
types.ContentFromProposalType("test", "test", types.ProposalTypeText),
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5000000)},
addrs[0],
)
require.NoError(t, err)
Expand All @@ -107,7 +107,7 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) {

newProposalMsg2, err := types.NewMsgSubmitProposal(
types.ContentFromProposalType("test2", "test2", types.ProposalTypeText),
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5000000)},
addrs[0],
)
require.NoError(t, err)
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestTickPassedDepositPeriod(t *testing.T) {

newProposalMsg, err := types.NewMsgSubmitProposal(
types.ContentFromProposalType("test2", "test2", types.ProposalTypeText),
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5000000)},
addrs[0],
)
require.NoError(t, err)
Expand Down
5 changes: 3 additions & 2 deletions x/gov/client/rest/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ func (s *IntegrationTestSuite) SetupSuite() {
_, err = govtestutil.MsgVote(val.ClientCtx, val.Address.String(), "1", "yes")
s.Require().NoError(err)

// create a proposal without deposit
// create a proposal with min initial deposit
_, err = govtestutil.MsgSubmitProposal(val.ClientCtx, val.Address.String(),
"Text Proposal 2", "Where is the title!?", types.ProposalTypeText)
"Text Proposal 2", "Where is the title!?", types.ProposalTypeText,
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.ToDec().Mul(types.MinInitialDepositRatio).RoundInt()).String()))
s.Require().NoError(err)
_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)
Expand Down
50 changes: 12 additions & 38 deletions x/gov/client/testutil/deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ 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"
"github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/stretchr/testify/suite"
tmcli "github.com/tendermint/tendermint/libs/cli"
)

type DepositTestSuite struct {
Expand Down Expand Up @@ -69,46 +70,19 @@ func (s *DepositTestSuite) TestQueryDepositsInitialDeposit() {
s.Require().Equal(deposits[0].Amount.String(), initialDeposit)
}

func (s *DepositTestSuite) TestQueryDepositsWithoutInitialDeposit() {
val := s.network.Validators[0]
clientCtx := val.ClientCtx

// create a proposal without deposit
_, err := MsgSubmitProposal(val.ClientCtx, val.Address.String(),
"Text Proposal 2", "Where is the title!?", types.ProposalTypeText)
s.Require().NoError(err)

// deposit amount
_, err = MsgDeposit(clientCtx, val.Address.String(), "2", sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.Add(sdk.NewInt(50))).String())
s.Require().NoError(err)

// waiting for voting period to end
time.Sleep(20 * time.Second)

// query deposit
deposit := s.queryDeposit(val, "2", false)
s.Require().Equal(deposit.Amount.String(), sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.Add(sdk.NewInt(50))).String())

// query deposits
deposits := s.queryDeposits(val, "2", false)
s.Require().Equal(len(deposits), 1)
// verify initial deposit
s.Require().Equal(deposits[0].Amount.String(), sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.Add(sdk.NewInt(50))).String())
}

func (s *DepositTestSuite) TestQueryProposalNotEnoughDeposits() {
val := s.network.Validators[0]
clientCtx := val.ClientCtx
initialDeposit := sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.Sub(sdk.NewInt(2000))).String()
initialDeposit := sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.Sub(sdk.NewInt(1))).String()

// create a proposal with deposit
_, err := MsgSubmitProposal(val.ClientCtx, val.Address.String(),
"Text Proposal 3", "Where is the title!?", types.ProposalTypeText,
"Text Proposal 2", "Where is the title!?", types.ProposalTypeText,
fmt.Sprintf("--%s=%s", cli.FlagDeposit, initialDeposit))
s.Require().NoError(err)

// query proposal
args := []string{"3", fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
args := []string{"2", fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
cmd := cli.GetCmdQueryProposal()
_, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
s.Require().NoError(err)
Expand All @@ -119,7 +93,7 @@ func (s *DepositTestSuite) TestQueryProposalNotEnoughDeposits() {
// query proposal
_, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
s.Require().Error(err)
s.Require().Contains(err.Error(), "proposal 3 doesn't exist")
s.Require().Contains(err.Error(), "proposal 2 doesn't exist")
}

func (s *DepositTestSuite) TestRejectedProposalDeposits() {
Expand All @@ -129,13 +103,13 @@ func (s *DepositTestSuite) TestRejectedProposalDeposits() {

// create a proposal with deposit
_, err := MsgSubmitProposal(clientCtx, val.Address.String(),
"Text Proposal 4", "Where is the title!?", types.ProposalTypeText,
"Text Proposal 3", "Where is the title!?", types.ProposalTypeText,
fmt.Sprintf("--%s=%s", cli.FlagDeposit, initialDeposit))
s.Require().NoError(err)

// query deposits
var deposits types.QueryDepositsResponse
args := []string{"4", fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
args := []string{"3", fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
cmd := cli.GetCmdQueryDeposits()
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
s.Require().NoError(err)
Expand All @@ -145,18 +119,18 @@ func (s *DepositTestSuite) TestRejectedProposalDeposits() {
s.Require().Equal(deposits.Deposits[0].Amount.String(), sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens).String())

// vote
_, err = MsgVote(clientCtx, val.Address.String(), "4", "no")
_, err = MsgVote(clientCtx, val.Address.String(), "3", "no")
s.Require().NoError(err)

time.Sleep(20 * time.Second)

args = []string{"4", fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
args = []string{"3", fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
cmd = cli.GetCmdQueryProposal()
_, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
s.Require().NoError(err)

// query deposits
depositsRes := s.queryDeposits(val, "4", false)
depositsRes := s.queryDeposits(val, "3", false)
s.Require().Equal(len(depositsRes), 1)
// verify initial deposit
s.Require().Equal(depositsRes[0].Amount.String(), initialDeposit.String())
Expand Down
9 changes: 5 additions & 4 deletions x/gov/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ func (s *IntegrationTestSuite) SetupSuite() {
_, err = MsgVote(val.ClientCtx, val.Address.String(), "1", "yes")
s.Require().NoError(err)

// create a proposal without deposit
// create a proposal with min initial deposit
_, err = MsgSubmitProposal(val.ClientCtx, val.Address.String(),
"Text Proposal 2", "Where is the title!?", types.ProposalTypeText)
"Text Proposal 2", "Where is the title!?", types.ProposalTypeText,
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.ToDec().Mul(types.MinInitialDepositRatio).RoundInt()).String()))
s.Require().NoError(err)
_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)
Expand Down Expand Up @@ -287,7 +288,7 @@ func (s *IntegrationTestSuite) TestNewCmdSubmitProposal() {
"description": "Hello, World!",
"type": "Text",
"deposit": "%s"
}`, sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(5431)))
}`, sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(5000000)))
validPropFile := testutil.WriteToNewTempFile(s.T(), validProp)
testCases := []struct {
name string
Expand Down Expand Up @@ -335,7 +336,7 @@ func (s *IntegrationTestSuite) TestNewCmdSubmitProposal() {
fmt.Sprintf("--%s='Text Proposal'", cli.FlagTitle),
fmt.Sprintf("--%s='Where is the title!?'", cli.FlagDescription),
fmt.Sprintf("--%s=%s", cli.FlagProposalType, types.ProposalTypeText),
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(5431)).String()),
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(5000000)).String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
Expand Down
14 changes: 13 additions & 1 deletion x/gov/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/gov/types"
)

Expand All @@ -26,14 +27,25 @@ var _ types.MsgServer = msgServer{}

func (k msgServer) SubmitProposal(goCtx context.Context, msg *types.MsgSubmitProposal) (*types.MsgSubmitProposalResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// checking minimum initial deposit requirement for submitting proposals, ref. https://github.com/cosmos/cosmos-sdk/pull/12771
initialDeposit := msg.GetInitialDeposit()
initialDepositRequired := k.GetDepositParams(ctx).MinDeposit
crypin marked this conversation as resolved.
Show resolved Hide resolved
for i := range initialDepositRequired {
initialDepositRequired[i].Amount = initialDepositRequired[i].Amount.ToDec().Mul(types.MinInitialDepositRatio).RoundInt()
crypin marked this conversation as resolved.
Show resolved Hide resolved
}
if !initialDeposit.IsAllGTE(initialDepositRequired) {
return nil, sdkerrors.Wrapf(types.ErrMinDepositTooSmall, "was (%s), need (%s)", initialDeposit, initialDepositRequired)
}

proposal, err := k.Keeper.SubmitProposal(ctx, msg.GetContent())
if err != nil {
return nil, err
}

defer telemetry.IncrCounter(1, types.ModuleName, "proposal")

votingStarted, err := k.Keeper.AddDeposit(ctx, proposal.ProposalId, msg.GetProposer(), msg.GetInitialDeposit())
votingStarted, err := k.Keeper.AddDeposit(ctx, proposal.ProposalId, msg.GetProposer(), initialDeposit)
if err != nil {
return nil, err
}
Expand Down
Loading