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 (#296)
* feat!: initial deposit for proposals * fix TestValidateInitialDeposit * fix migration tests * integrate new param into simulator * increase consensus version and migration tests * fix app state determinism tests * fix gov cli * fix grpc query tests * more fixes * restore build tags * fix genesis and proposal handler tests * Adam's comment * revert some test changes * fix TestSimulateMsgSubmitProposal * more fixes * err check * uncomment test * fixTestProposalHandler * convert uint32 to dec * revert NewDepositParams API, use decorator instead * fix proto comment * fix more tests * go mod * remove copied proto field * typo * fix tests * fix x/gov/client/testutil tests * add json tags
- Loading branch information
Showing
23 changed files
with
538 additions
and
137 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//go:build norace | ||
// +build norace | ||
|
||
package testutil | ||
|
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
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) | ||
} |
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,38 @@ | ||
package v3_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/simapp" | ||
"github.com/cosmos/cosmos-sdk/testutil" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
v3 "github.com/cosmos/cosmos-sdk/x/gov/legacy/v3" | ||
"github.com/cosmos/cosmos-sdk/x/gov/types" | ||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
) | ||
|
||
func TestGovStoreMigrationToV3ConsensusVersion(t *testing.T) { | ||
encCfg := simapp.MakeTestEncodingConfig() | ||
govKey := sdk.NewKVStoreKey("gov") | ||
transientTestKey := sdk.NewTransientStoreKey("transient_test") | ||
ctx := testutil.DefaultContext(govKey, transientTestKey) | ||
paramstore := paramtypes.NewSubspace(encCfg.Marshaler, encCfg.Amino, govKey, transientTestKey, "gov") | ||
|
||
paramstore = paramstore.WithKeyTable(types.ParamKeyTable()) | ||
|
||
// We assume that all deposit params are set besdides the MinInitialDepositRatio | ||
originalDepositParams := types.DefaultDepositParams() | ||
originalDepositParams.MinInitialDepositRatio = sdk.ZeroDec() | ||
paramstore.Set(ctx, types.ParamStoreKeyDepositParams, originalDepositParams) | ||
|
||
// Run migrations. | ||
err := v3.MigrateStore(ctx, paramstore) | ||
require.NoError(t, err) | ||
|
||
// Make sure the new param is set. | ||
var depositParams types.DepositParams | ||
paramstore.Get(ctx, types.ParamStoreKeyDepositParams, &depositParams) | ||
require.Equal(t, v3.MinInitialDepositRatio, depositParams.MinInitialDepositRatio) | ||
} |
Oops, something went wrong.