From 45c826a86b680ba972c36495b46d51cc6b466878 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Wed, 13 Apr 2022 11:08:05 +0200 Subject: [PATCH] Revisit gov params doc and tests --- x/wasm/Governance.md | 96 +++++++++++++++++++++- x/wasm/keeper/proposal_integration_test.go | 46 +++++++++-- 2 files changed, 131 insertions(+), 11 deletions(-) diff --git a/x/wasm/Governance.md b/x/wasm/Governance.md index f26c0c5a5a..7d7a32abee 100644 --- a/x/wasm/Governance.md +++ b/x/wasm/Governance.md @@ -57,18 +57,110 @@ See [params.go](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/types/param }, "instantiate_default_permission": "Everybody" } - }, + }, ``` The values can be updated via gov proposal implemented in the `params` module. +### Update Params Via [ParamChangeProposal](https://github.com/cosmos/cosmos-sdk/blob/v0.45.3/proto/cosmos/params/v1beta1/params.proto#L10) +Example to submit a parameter change gov proposal: +```sh +wasmd tx gov submit-proposal param-change --from validator --chain-id=testing -b block +``` +#### Content examples +* Disable wasm code uploads +```json +{ + "title": "Foo", + "description": "Bar", + "changes": [ + { + "subspace": "wasm", + "key": "uploadAccess", + "value": { + "permission": "Nobody" + } + } + ], + "deposit": "" +} +``` +* Allow wasm code uploads for everybody +```json +{ + "title": "Foo", + "description": "Bar", + "changes": [ + { + "subspace": "wasm", + "key": "uploadAccess", + "value": { + "permission": "Everybody" + } + } + ], + "deposit": "" +} +``` + +* Restrict code uploads to a single address +```json +{ + "title": "Foo", + "description": "Bar", + "changes": [ + { + "subspace": "wasm", + "key": "uploadAccess", + "value": { + "permission": "OnlyAddress", + "address": "cosmos1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq0fr2sh" + } + } + ], + "deposit": "" +} +``` +* Set chain **default** instantiation settings to nobody +```json +{ + "title": "Foo", + "description": "Bar", + "changes": [ + { + "subspace": "wasm", + "key": "instantiateAccess", + "value": "Nobody" + } + ], + "deposit": "" +} +``` +* Set chain **default** instantiation settings to everybody +```json +{ + "title": "Foo", + "description": "Bar", + "changes": [ + { + "subspace": "wasm", + "key": "instantiateAccess", + "value": "Everybody" + } + ], + "deposit": "" +} +``` + ### Enable gov proposals at **compile time**. -As gov proposals bypass the existing authorzation policy they are diabled and require to be enabled at compile time. +As gov proposals bypass the existing authorization policy they are disabled and require to be enabled at compile time. ``` -X github.com/CosmWasm/wasmd/app.ProposalsEnabled=true - enable all x/wasm governance proposals (default false) -X github.com/CosmWasm/wasmd/app.EnableSpecificProposals=MigrateContract,UpdateAdmin,ClearAdmin - enable a subset of the x/wasm governance proposal types (overrides ProposalsEnabled) ``` +The `ParamChangeProposal` is always enabled. + ### Tests * [params validation unit tests](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/types/params_test.go) * [genesis validation tests](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/types/genesis_test.go) diff --git a/x/wasm/keeper/proposal_integration_test.go b/x/wasm/keeper/proposal_integration_test.go index a943003e55..f01dc6ba6f 100644 --- a/x/wasm/keeper/proposal_integration_test.go +++ b/x/wasm/keeper/proposal_integration_test.go @@ -8,6 +8,8 @@ import ( "io/ioutil" "testing" + "github.com/cosmos/cosmos-sdk/x/params/client/utils" + wasmvm "github.com/CosmWasm/wasmvm" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" @@ -410,13 +412,11 @@ func TestUpdateParamsProposal(t *testing.T) { govKeeper, wasmKeeper := keepers.GovKeeper, keepers.WasmKeeper var ( - cdc = keepers.WasmKeeper.cdc + legacyAmino = keepers.EncodingConfig.Amino myAddress sdk.AccAddress = make([]byte, types.ContractAddrLen) oneAddressAccessConfig = types.AccessTypeOnlyAddress.With(myAddress) ) - nobodyJson, err := json.Marshal(types.AccessTypeNobody) - require.NoError(t, err) specs := map[string]struct { src proposal.ParamChange expUploadConfig types.AccessConfig @@ -426,16 +426,25 @@ func TestUpdateParamsProposal(t *testing.T) { src: proposal.ParamChange{ Subspace: types.ModuleName, Key: string(types.ParamStoreKeyUploadAccess), - Value: string(cdc.MustMarshalJSON(&types.AllowNobody)), + Value: string(legacyAmino.MustMarshalJSON(&types.AllowNobody)), }, expUploadConfig: types.AllowNobody, expInstantiateType: types.AccessTypeEverybody, }, + "update upload permission with same as current value": { + src: proposal.ParamChange{ + Subspace: types.ModuleName, + Key: string(types.ParamStoreKeyUploadAccess), + Value: string(legacyAmino.MustMarshalJSON(&types.AllowEverybody)), + }, + expUploadConfig: types.AllowEverybody, + expInstantiateType: types.AccessTypeEverybody, + }, "update upload permission param with address": { src: proposal.ParamChange{ Subspace: types.ModuleName, Key: string(types.ParamStoreKeyUploadAccess), - Value: string(cdc.MustMarshalJSON(&oneAddressAccessConfig)), + Value: string(legacyAmino.MustMarshalJSON(&oneAddressAccessConfig)), }, expUploadConfig: oneAddressAccessConfig, expInstantiateType: types.AccessTypeEverybody, @@ -444,22 +453,40 @@ func TestUpdateParamsProposal(t *testing.T) { src: proposal.ParamChange{ Subspace: types.ModuleName, Key: string(types.ParamStoreKeyInstantiateAccess), - Value: string(nobodyJson), + Value: string(legacyAmino.MustMarshalJSON(types.AccessTypeNobody)), }, expUploadConfig: types.AllowEverybody, expInstantiateType: types.AccessTypeNobody, }, + "update instantiate param as default": { + src: proposal.ParamChange{ + Subspace: types.ModuleName, + Key: string(types.ParamStoreKeyInstantiateAccess), + Value: string(legacyAmino.MustMarshalJSON(types.AccessTypeEverybody)), + }, + expUploadConfig: types.AllowEverybody, + expInstantiateType: types.AccessTypeEverybody, + }, } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { wasmKeeper.SetParams(ctx, types.DefaultParams()) - proposal := proposal.ParameterChangeProposal{ + // encode + decode as CLI to play nice with amino + bz := legacyAmino.MustMarshalJSON(&utils.ParamChangeProposalJSON{ Title: "Foo", Description: "Bar", - Changes: []proposal.ParamChange{spec.src}, - } + Changes: []utils.ParamChangeJSON{{Subspace: spec.src.Subspace, Key: spec.src.Key, Value: json.RawMessage(spec.src.Value)}}, + }) + t.Log(string(bz)) + var jsonProposal utils.ParamChangeProposalJSON + require.NoError(t, legacyAmino.UnmarshalJSON(bz, &jsonProposal)) + proposal := proposal.ParameterChangeProposal{ + Title: jsonProposal.Title, + Description: jsonProposal.Description, + Changes: jsonProposal.Changes.ToParamChanges(), + } // when stored storedProposal, err := govKeeper.SubmitProposal(ctx, &proposal) require.NoError(t, err) @@ -564,6 +591,7 @@ func TestPinCodesProposal(t *testing.T) { }) } } + func TestUnpinCodesProposal(t *testing.T) { ctx, keepers := CreateTestInput(t, false, "staking") govKeeper, wasmKeeper := keepers.GovKeeper, keepers.WasmKeeper