Skip to content
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

Gov param change examples #805

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": ""
}
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good examples!

### 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(),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

// 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