Skip to content

Commit

Permalink
Merge pull request #805 from CosmWasm/804-param_change
Browse files Browse the repository at this point in the history
Gov param change examples
  • Loading branch information
alpe authored Apr 14, 2022
2 parents ab661d5 + 45c826a commit 57ead1a
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 11 deletions.
96 changes: 94 additions & 2 deletions x/wasm/Governance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <proposal-json-file> --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)
Expand Down
46 changes: 37 additions & 9 deletions x/wasm/keeper/proposal_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 57ead1a

Please sign in to comment.