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

Consolidate MaxWasmSize constraints into a single var #826

Merged
merged 5 commits into from
Apr 29, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Complete max wasm size changes
alpe committed Apr 29, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
alpe Alexander Peters
commit fbe67beede8311f04eebc75377574c4ad9e40126
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

**Merged pull requests:**

- Consolidate MaxWasmSize constraints into a single var [\#809](https://github.com/CosmWasm/wasmd/pull/809)
- Consolidate MaxWasmSize constraints into a single var [\#826](https://github.com/CosmWasm/wasmd/pull/826)

[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.26.0...HEAD)

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -189,6 +189,8 @@ Available flags:
* `-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`)
* `-X github.com/CosmWasm/wasmd/x/wasm/types/validation.MaxWasmSize=819200` - set the max size of compiled wasm to be accepted (default `819200`)
* `-X github.com/CosmWasm/wasmd/x/wasm/types/validation.MaxLabelSize=128` - set the max length of the label on instantiation (default `128`)

Examples:

1 change: 0 additions & 1 deletion docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
@@ -219,7 +219,6 @@ Params defines the set of wasm parameters.
| ----- | ---- | ----- | ----------- |
| `code_upload_access` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | |
| `instantiate_default_permission` | [AccessType](#cosmwasm.wasm.v1.AccessType) | | |
| `max_wasm_code_size` | [uint64](#uint64) | | |



2 changes: 0 additions & 2 deletions proto/cosmwasm/wasm/v1/types.proto
Original file line number Diff line number Diff line change
@@ -49,8 +49,6 @@ message Params {
];
AccessType instantiate_default_permission = 2
[ (gogoproto.moretags) = "yaml:\"instantiate_default_permission\"" ];
uint64 max_wasm_code_size = 3
[ (gogoproto.moretags) = "yaml:\"max_wasm_code_size\"" ];
}

// CodeInfo is data for the uploaded contract WASM code
3 changes: 1 addition & 2 deletions x/wasm/keeper/genesis_test.go
Original file line number Diff line number Diff line change
@@ -463,8 +463,7 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {
"code_upload_access": {
"permission": "Everybody"
},
"instantiate_default_permission": "Everybody",
"max_wasm_code_size": 500000
"instantiate_default_permission": "Everybody"
},
"codes": [
{
1 change: 0 additions & 1 deletion x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -126,7 +126,6 @@ func TestCreateStoresInstantiatePermission(t *testing.T) {
keepers.WasmKeeper.SetParams(ctx, types.Params{
CodeUploadAccess: types.AllowEverybody,
InstantiateDefaultPermission: spec.srcPermission,
MaxWasmCodeSize: types.DefaultMaxWasmCodeSize,
})
fundAccounts(t, ctx, accKeeper, bankKeeper, myAddr, deposit)

4 changes: 0 additions & 4 deletions x/wasm/keeper/proposal_integration_test.go
Original file line number Diff line number Diff line change
@@ -29,7 +29,6 @@ func TestStoreCodeProposal(t *testing.T) {
wasmKeeper.SetParams(ctx, types.Params{
CodeUploadAccess: types.AllowNobody,
InstantiateDefaultPermission: types.AccessTypeNobody,
MaxWasmCodeSize: types.DefaultMaxWasmCodeSize,
})
wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)
@@ -67,7 +66,6 @@ func TestInstantiateProposal(t *testing.T) {
wasmKeeper.SetParams(ctx, types.Params{
CodeUploadAccess: types.AllowNobody,
InstantiateDefaultPermission: types.AccessTypeNobody,
MaxWasmCodeSize: types.DefaultMaxWasmCodeSize,
})

wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
@@ -131,7 +129,6 @@ func TestMigrateProposal(t *testing.T) {
wasmKeeper.SetParams(ctx, types.Params{
CodeUploadAccess: types.AllowNobody,
InstantiateDefaultPermission: types.AccessTypeNobody,
MaxWasmCodeSize: types.DefaultMaxWasmCodeSize,
})

wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
@@ -383,7 +380,6 @@ func TestAdminProposals(t *testing.T) {
wasmKeeper.SetParams(ctx, types.Params{
CodeUploadAccess: types.AllowNobody,
InstantiateDefaultPermission: types.AccessTypeNobody,
MaxWasmCodeSize: types.DefaultMaxWasmCodeSize,
})

codeInfoFixture := types.CodeInfoFixture(types.WithSHA256CodeHash(wasmCode))
1 change: 0 additions & 1 deletion x/wasm/simulation/params.go
Original file line number Diff line number Diff line change
@@ -38,6 +38,5 @@ func RandomParams(r *rand.Rand) types.Params {
return types.Params{
CodeUploadAccess: accessConfig,
InstantiateDefaultPermission: accessConfig.Permission,
MaxWasmCodeSize: uint64(simtypes.RandIntBetween(r, 1, 600) * 1024),
}
}
14 changes: 0 additions & 14 deletions x/wasm/types/params.go
Original file line number Diff line number Diff line change
@@ -117,9 +117,6 @@ func (p Params) ValidateBasic() error {
if err := validateAccessConfig(p.CodeUploadAccess); err != nil {
return errors.Wrap(err, "upload access")
}
if err := validateMaxWasmCodeSize(p.MaxWasmCodeSize); err != nil {
return errors.Wrap(err, "max wasm code size")
}
return nil
}

@@ -147,17 +144,6 @@ func validateAccessType(i interface{}) error {
return sdkerrors.Wrapf(ErrInvalid, "unknown type: %q", a)
}

func validateMaxWasmCodeSize(i interface{}) error {
a, ok := i.(uint64)
if !ok {
return sdkerrors.Wrapf(ErrInvalid, "type: %T", i)
}
if a == 0 {
return sdkerrors.Wrap(ErrInvalid, "must be greater 0")
}
return nil
}

func (a AccessConfig) ValidateBasic() error {
switch a.Permission {
case AccessTypeUnspecified:
20 changes: 1 addition & 19 deletions x/wasm/types/params_test.go
Original file line number Diff line number Diff line change
@@ -28,81 +28,64 @@ func TestValidateParams(t *testing.T) {
src: Params{
CodeUploadAccess: AllowNobody,
InstantiateDefaultPermission: AccessTypeNobody,
MaxWasmCodeSize: DefaultMaxWasmCodeSize,
},
},
"all good with everybody": {
src: Params{
CodeUploadAccess: AllowEverybody,
InstantiateDefaultPermission: AccessTypeEverybody,
MaxWasmCodeSize: DefaultMaxWasmCodeSize,
},
},
"all good with only address": {
src: Params{
CodeUploadAccess: AccessTypeOnlyAddress.With(anyAddress),
InstantiateDefaultPermission: AccessTypeOnlyAddress,
MaxWasmCodeSize: DefaultMaxWasmCodeSize,
},
},
"reject empty type in instantiate permission": {
src: Params{
CodeUploadAccess: AllowNobody,
MaxWasmCodeSize: DefaultMaxWasmCodeSize,
},
expErr: true,
},
"reject unknown type in instantiate": {
src: Params{
CodeUploadAccess: AllowNobody,
InstantiateDefaultPermission: 1111,
MaxWasmCodeSize: DefaultMaxWasmCodeSize,
},
expErr: true,
},
"reject invalid address in only address": {
src: Params{
CodeUploadAccess: AccessConfig{Permission: AccessTypeOnlyAddress, Address: invalidAddress},
InstantiateDefaultPermission: AccessTypeOnlyAddress,
MaxWasmCodeSize: DefaultMaxWasmCodeSize,
},
expErr: true,
},
"reject CodeUploadAccess Everybody with obsolete address": {
src: Params{
CodeUploadAccess: AccessConfig{Permission: AccessTypeEverybody, Address: anyAddress.String()},
InstantiateDefaultPermission: AccessTypeOnlyAddress,
MaxWasmCodeSize: DefaultMaxWasmCodeSize,
},
expErr: true,
},
"reject CodeUploadAccess Nobody with obsolete address": {
src: Params{
CodeUploadAccess: AccessConfig{Permission: AccessTypeNobody, Address: anyAddress.String()},
InstantiateDefaultPermission: AccessTypeOnlyAddress,
MaxWasmCodeSize: DefaultMaxWasmCodeSize,
},
expErr: true,
},
"reject empty CodeUploadAccess": {
src: Params{
InstantiateDefaultPermission: AccessTypeOnlyAddress,
MaxWasmCodeSize: DefaultMaxWasmCodeSize,
},
expErr: true,
},
"reject undefined permission in CodeUploadAccess": {
src: Params{
CodeUploadAccess: AccessConfig{Permission: AccessTypeUnspecified},
InstantiateDefaultPermission: AccessTypeOnlyAddress,
MaxWasmCodeSize: DefaultMaxWasmCodeSize,
},
expErr: true,
},
"reject empty max wasm code size": {
src: Params{
CodeUploadAccess: AllowNobody,
InstantiateDefaultPermission: AccessTypeNobody,
},
expErr: true,
},
@@ -167,8 +150,7 @@ func TestParamsUnmarshalJson(t *testing.T) {

"defaults": {
src: `{"code_upload_access": {"permission": "Everybody"},
"instantiate_default_permission": "Everybody",
"max_wasm_code_size": 1228800}`,
"instantiate_default_permission": "Everybody"}`,
exp: DefaultParams(),
},
}
Loading