Skip to content

Commit

Permalink
fix: Add a test to manage the parameter MaxWasmCodeSize with gov (#51)
Browse files Browse the repository at this point in the history
* refactoring: use var defined in types as expected default value of wasm parameters

* add test for change the parameter MaxWasmCodeSize

* Add documentation
  • Loading branch information
loloicci authored Dec 4, 2020
1 parent c553ff6 commit f7be553
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 7 additions & 0 deletions x/wasm/Governance.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ For details see the proposal type [implementation](https://github.com/CosmWasm/w
A wasm message but no proposal type:
* `ExecuteContract` - execute a command on a wasm contract

And you can use `Parameter Change Proposal` to change wasm parameters.
These parameters are as following.

* `UploadAccess` - who can upload wasm codes
* `DefaultInstantiatePermission` - who can instantiate contracts from a code in default
* `MaxWasmCodeSize` - max size of wasm code to be uploaded

### Unit tests
[Proposal type validations](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/internal/types/proposal_test.go)

Expand Down
23 changes: 20 additions & 3 deletions x/wasm/internal/keeper/proposal_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,15 @@ func TestUpdateParamsProposal(t *testing.T) {
cdc = keepers.WasmKeeper.cdc
myAddress sdk.AccAddress = make([]byte, sdk.AddrLen)
oneAddressAccessConfig = types.OnlyAddress.With(myAddress)
newMaxWasmCodeSize = uint64(42)
defaultParams = types.DefaultParams()
)

specs := map[string]struct {
src params.ParamChange
expUploadConfig types.AccessConfig
expInstantiateType types.AccessType
expMaxWasmCodeSize uint64
}{
"update upload permission param": {
src: params.ParamChange{
Expand All @@ -328,7 +331,8 @@ func TestUpdateParamsProposal(t *testing.T) {
Value: string(cdc.MustMarshalJSON(&types.AllowNobody)),
},
expUploadConfig: types.AllowNobody,
expInstantiateType: types.Everybody,
expInstantiateType: defaultParams.DefaultInstantiatePermission,
expMaxWasmCodeSize: defaultParams.MaxWasmCodeSize,
},
"update upload permission param with address": {
src: params.ParamChange{
Expand All @@ -337,16 +341,28 @@ func TestUpdateParamsProposal(t *testing.T) {
Value: string(cdc.MustMarshalJSON(&oneAddressAccessConfig)),
},
expUploadConfig: oneAddressAccessConfig,
expInstantiateType: types.Everybody,
expInstantiateType: defaultParams.DefaultInstantiatePermission,
expMaxWasmCodeSize: defaultParams.MaxWasmCodeSize,
},
"update instantiate param": {
src: params.ParamChange{
Subspace: types.DefaultParamspace,
Key: string(types.ParamStoreKeyInstantiateAccess),
Value: string(cdc.MustMarshalJSON(types.Nobody)),
},
expUploadConfig: types.AllowEverybody,
expUploadConfig: defaultParams.UploadAccess,
expInstantiateType: types.Nobody,
expMaxWasmCodeSize: defaultParams.MaxWasmCodeSize,
},
"update max wasm code size": {
src: params.ParamChange{
Subspace: types.DefaultParamspace,
Key: string(types.ParamStoreKeyMaxWasmCodeSize),
Value: string(cdc.MustMarshalJSON(newMaxWasmCodeSize)),
},
expUploadConfig: defaultParams.UploadAccess,
expInstantiateType: defaultParams.DefaultInstantiatePermission,
expMaxWasmCodeSize: newMaxWasmCodeSize,
},
}
for msg, spec := range specs {
Expand All @@ -372,6 +388,7 @@ func TestUpdateParamsProposal(t *testing.T) {
assert.True(t, spec.expUploadConfig.Equals(wasmKeeper.getUploadAccessConfig(ctx)),
"got %#v not %#v", wasmKeeper.getUploadAccessConfig(ctx), spec.expUploadConfig)
assert.Equal(t, spec.expInstantiateType, wasmKeeper.getInstantiateAccessConfig(ctx))
assert.Equal(t, spec.expMaxWasmCodeSize, wasmKeeper.GetMaxWasmCodeSize(ctx))
})
}
}

0 comments on commit f7be553

Please sign in to comment.