forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: initial deposit requirement for proposals (backport cosmos#296) (
cosmos#297) * feat!: initial deposit requirement for proposals (backport cosmos#296) * Update x/gov/legacy/v3/store_test.go Co-authored-by: Adam Tucker <[email protected]> * Update x/gov/simulation/genesis.go Co-authored-by: Adam Tucker <[email protected]> Co-authored-by: Adam Tucker <[email protected]>
- Loading branch information
1 parent
2a59296
commit 643737b
Showing
22 changed files
with
518 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package keeper | ||
|
||
import sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
func (k Keeper) ValidateInitialDeposit(ctx sdk.Context, initialDeposit sdk.Coins) error { | ||
return k.validateInitialDeposit(ctx, initialDeposit) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/simapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/gov/keeper" | ||
"github.com/cosmos/cosmos-sdk/x/gov/types" | ||
"github.com/stretchr/testify/require" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
) | ||
|
||
func TestSubmitProposal_InitialDeposit(t *testing.T) { | ||
const meetsDepositValue = baseDepositTestAmount * baseDepositTestPercent / 100 | ||
var baseDepositRatioDec = sdk.NewDec(baseDepositTestPercent).Quo(sdk.NewDec(100)) | ||
|
||
testcases := map[string]struct { | ||
minDeposit sdk.Coins | ||
minInitialDepositRatio sdk.Dec | ||
initialDeposit sdk.Coins | ||
accountBalance sdk.Coins | ||
|
||
expectError bool | ||
}{ | ||
"meets initial deposit, enough balance - success": { | ||
minDeposit: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(baseDepositTestAmount))), | ||
minInitialDepositRatio: baseDepositRatioDec, | ||
initialDeposit: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(meetsDepositValue))), | ||
accountBalance: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(meetsDepositValue))), | ||
}, | ||
"does not meet initial deposit, enough balance - error": { | ||
minDeposit: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(baseDepositTestAmount))), | ||
minInitialDepositRatio: baseDepositRatioDec, | ||
initialDeposit: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(meetsDepositValue-1))), | ||
accountBalance: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(meetsDepositValue))), | ||
|
||
expectError: true, | ||
}, | ||
"meets initial deposit, not enough balance - error": { | ||
minDeposit: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(baseDepositTestAmount))), | ||
minInitialDepositRatio: baseDepositRatioDec, | ||
initialDeposit: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(meetsDepositValue))), | ||
accountBalance: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(meetsDepositValue-1))), | ||
|
||
expectError: true, | ||
}, | ||
"does not meet initial deposit and not enough balance - error": { | ||
minDeposit: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(baseDepositTestAmount))), | ||
minInitialDepositRatio: baseDepositRatioDec, | ||
initialDeposit: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(meetsDepositValue-1))), | ||
accountBalance: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(meetsDepositValue-1))), | ||
|
||
expectError: true, | ||
}, | ||
} | ||
|
||
for name, tc := range testcases { | ||
t.Run(name, func(t *testing.T) { | ||
// Setup | ||
app := simapp.Setup(false) | ||
ctx := app.BaseApp.NewContext(false, tmproto.Header{}) | ||
govKeeper := app.GovKeeper | ||
msgServer := keeper.NewMsgServerImpl(govKeeper) | ||
|
||
params := types.DefaultDepositParams() | ||
params.MinDeposit = tc.minDeposit | ||
params.MinInitialDepositRatio = tc.minInitialDepositRatio | ||
govKeeper.SetDepositParams(ctx, params) | ||
|
||
address := simapp.AddTestAddrs(app, ctx, 1, sdk.NewInt(0))[0] | ||
simapp.FundAccount(app.BankKeeper, ctx, address, tc.accountBalance) | ||
|
||
msg, err := types.NewMsgSubmitProposal(TestProposal, tc.initialDeposit, address) | ||
require.NoError(t, err) | ||
|
||
// System under test | ||
_, err = msgServer.SubmitProposal(sdk.WrapSDKContext(ctx), msg) | ||
|
||
// Assertions | ||
if tc.expectError { | ||
require.Error(t, err) | ||
return | ||
} | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package v3 | ||
|
||
var MinInitialDepositRatio = minInitialDepositRatio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package v3 | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/gov/types" | ||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
) | ||
|
||
var minInitialDepositRatio = sdk.NewDec(25).Quo(sdk.NewDec(100)) | ||
|
||
// MigrateStore performs in-place store migrations for consensus version 3 | ||
// in the gov module. | ||
// Please note that this is the first version that switches from using | ||
// SDK versioning (v043 etc) for package names to consensus versioning | ||
// of the gov module. | ||
// The migration includes: | ||
// | ||
// - Setting the minimum deposit param in the paramstore. | ||
func MigrateStore(ctx sdk.Context, paramstore paramtypes.Subspace) error { | ||
migrateParamsStore(ctx, paramstore) | ||
return nil | ||
} | ||
|
||
func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) { | ||
var depositParams types.DepositParams | ||
paramstore.Get(ctx, types.ParamStoreKeyDepositParams, &depositParams) | ||
depositParams.MinInitialDepositRatio = minInitialDepositRatio | ||
paramstore.Set(ctx, types.ParamStoreKeyDepositParams, depositParams) | ||
} |
Oops, something went wrong.