-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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: decouple x/params
from simapp
#12259
Changes from 4 commits
263fa5e
5c3e288
3ec8249
5aabf9c
ad0a1db
295b617
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package sims | ||
|
||
// Default simulation operation weights for messages and gov proposals | ||
const ( | ||
DefaultWeightMsgSend int = 100 | ||
DefaultWeightMsgMultiSend int = 10 | ||
DefaultWeightMsgSetWithdrawAddress int = 50 | ||
DefaultWeightMsgWithdrawDelegationReward int = 50 | ||
DefaultWeightMsgWithdrawValidatorCommission int = 50 | ||
DefaultWeightMsgFundCommunityPool int = 50 | ||
DefaultWeightMsgDeposit int = 100 | ||
DefaultWeightMsgVote int = 67 | ||
DefaultWeightMsgVoteWeighted int = 33 | ||
DefaultWeightMsgUnjail int = 100 | ||
DefaultWeightMsgCreateValidator int = 100 | ||
DefaultWeightMsgEditValidator int = 5 | ||
DefaultWeightMsgDelegate int = 100 | ||
DefaultWeightMsgUndelegate int = 100 | ||
DefaultWeightMsgBeginRedelegate int = 100 | ||
DefaultWeightMsgCancelUnbondingDelegation int = 100 | ||
|
||
DefaultWeightCommunitySpendProposal int = 5 | ||
DefaultWeightTextProposal int = 5 | ||
DefaultWeightParamChangeProposal int = 5 | ||
|
||
// feegrant | ||
DefaultWeightGrantAllowance int = 100 | ||
DefaultWeightRevokeAllowance int = 100 | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,28 +7,36 @@ import ( | |
|
||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/simapp" | ||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" | ||
"github.com/cosmos/cosmos-sdk/x/params" | ||
"github.com/cosmos/cosmos-sdk/x/params/keeper" | ||
"github.com/cosmos/cosmos-sdk/x/params/testutil" | ||
"github.com/cosmos/cosmos-sdk/x/params/types/proposal" | ||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
type HandlerTestSuite struct { | ||
suite.Suite | ||
|
||
app *simapp.SimApp | ||
ctx sdk.Context | ||
govHandler govv1beta1.Handler | ||
ctx sdk.Context | ||
govHandler govv1beta1.Handler | ||
stakingKeeper *stakingkeeper.Keeper | ||
} | ||
|
||
func (suite *HandlerTestSuite) SetupTest() { | ||
suite.app = simapp.Setup(suite.T(), false) | ||
suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{}) | ||
suite.govHandler = params.NewParamChangeProposalHandler(suite.app.ParamsKeeper) | ||
var paramsKeeper keeper.Keeper | ||
app, err := simtestutil.Setup( | ||
testutil.AppConfig, | ||
¶msKeeper, | ||
&suite.stakingKeeper, | ||
) | ||
suite.Require().NoError(err) | ||
|
||
suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) | ||
suite.govHandler = params.NewParamChangeProposalHandler(paramsKeeper) | ||
} | ||
|
||
func TestHandlerTestSuite(t *testing.T) { | ||
|
@@ -50,7 +58,7 @@ func (suite *HandlerTestSuite) TestProposalHandler() { | |
"all fields", | ||
testProposal(proposal.NewParamChange(stakingtypes.ModuleName, string(stakingtypes.KeyMaxValidators), "1")), | ||
func() { | ||
maxVals := suite.app.StakingKeeper.MaxValidators(suite.ctx) | ||
maxVals := suite.stakingKeeper.MaxValidators(suite.ctx) | ||
suite.Require().Equal(uint32(1), maxVals) | ||
}, | ||
false, | ||
|
@@ -61,23 +69,23 @@ func (suite *HandlerTestSuite) TestProposalHandler() { | |
func() {}, | ||
true, | ||
}, | ||
{ | ||
"omit empty fields", | ||
testProposal(proposal.ParamChange{ | ||
Subspace: govtypes.ModuleName, | ||
Key: string(govv1.ParamStoreKeyDepositParams), | ||
Value: `{"min_deposit": [{"denom": "uatom","amount": "64000000"}], "max_deposit_period": "172800000000000"}`, | ||
}), | ||
func() { | ||
depositParams := suite.app.GovKeeper.GetDepositParams(suite.ctx) | ||
defaultPeriod := govv1.DefaultPeriod | ||
suite.Require().Equal(govv1.DepositParams{ | ||
MinDeposit: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(64000000))), | ||
MaxDepositPeriod: &defaultPeriod, | ||
}, depositParams) | ||
}, | ||
false, | ||
}, | ||
// { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aaronc Shouldn't we use another There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really following. Can you explain more? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I meant is from my understanding the app.yaml of a module should be minimalistic. That means only requiring modules that are dependencies or strictly required for running the module app. Here we need to add as well the gov module which isn't a dependency of params. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense but seems like the tests were written in a tightly coupled way so they depend on gov... We'll need to do some refactoring of tests probably |
||
// "omit empty fields", | ||
// testProposal(proposal.ParamChange{ | ||
// Subspace: govtypes.ModuleName, | ||
// Key: string(govv1.ParamStoreKeyDepositParams), | ||
// Value: `{"min_deposit": [{"denom": "uatom","amount": "64000000"}], "max_deposit_period": "172800000000000"}`, | ||
// }), | ||
// func() { | ||
// depositParams := suite.app.GovKeeper.GetDepositParams(suite.ctx) | ||
// defaultPeriod := govv1.DefaultPeriod | ||
// suite.Require().Equal(govv1.DepositParams{ | ||
// MinDeposit: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(64000000))), | ||
// MaxDepositPeriod: &defaultPeriod, | ||
// }, depositParams) | ||
// }, | ||
// false, | ||
// }, | ||
} | ||
|
||
for _, tc := range testCases { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
# App Wiring | ||
|
||
The minimal app-wiring configuration for `x/params` is as follows: | ||
|
||
+++ https://github.com/cosmos/cosmos-sdk/blob/main/x/params/testutil/app.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
modules: | ||
- name: runtime | ||
config: | ||
"@type": cosmos.app.runtime.v1alpha1.Module | ||
|
||
app_name: ParamsApp | ||
|
||
begin_blockers: [staking, auth, bank, genutil, params] | ||
end_blockers: [staking, auth, bank, genutil, params] | ||
init_genesis: [auth, bank, staking, genutil, params] | ||
|
||
- name: auth | ||
config: | ||
"@type": cosmos.auth.module.v1.Module | ||
bech32_prefix: cosmos | ||
module_account_permissions: | ||
- account: fee_collector | ||
- account: bonded_tokens_pool | ||
permissions: [burner, staking] | ||
- account: not_bonded_tokens_pool | ||
permissions: [burner, staking] | ||
|
||
- name: bank | ||
config: | ||
"@type": cosmos.bank.module.v1.Module | ||
|
||
- name: params | ||
config: | ||
"@type": cosmos.params.module.v1.Module | ||
|
||
- name: tx | ||
config: | ||
"@type": cosmos.tx.module.v1.Module | ||
|
||
- name: staking | ||
config: | ||
"@type": cosmos.staking.module.v1.Module | ||
|
||
- name: genutil | ||
config: | ||
"@type": cosmos.genutil.module.v1.Module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im a bit worried about these direct dependencies. It could make versioning harder for us and users. Not sure alternative solutions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There shouldn't be a problem using an expected keeper interface instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think sometimes with expected keepers we still need to import the types. I am not sure it solve that concern then.
It seems it does here tho as the input is only a context for staking, so I will fix that.
However for gov it won't work as we import types as well.