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

refactor: refactor test cases for Params #69

Merged
merged 12 commits into from
Aug 18, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* [\#75](https://github.com/Finschia/wasmd/pull/75) test: add the test case for InactiveContract
* [\#74](https://github.com/Finschia/wasmd/pull/74) add event checking to TestInstantiateContract2
* [\#78](https://github.com/Finschia/wasmd/pull/78) add the check for TestMigrateContract
* [\#69](https://github.com/Finschia/wasmd/pull/69) refactor: refactor test cases for Params

### Bug Fixes
* [\#62](https://github.com/Finschia/wasmd/pull/62) fill ContractHistory querier result's Updated field
Expand Down
45 changes: 31 additions & 14 deletions x/wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,22 +866,39 @@ func TestQueryParams(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, paramsResponse)

defaultParams := types.DefaultParams()

require.Equal(t, paramsResponse.Params.CodeUploadAccess, defaultParams.CodeUploadAccess)
require.Equal(t, paramsResponse.Params.InstantiateDefaultPermission, defaultParams.InstantiateDefaultPermission)

keeper.SetParams(ctx, types.Params{
CodeUploadAccess: types.AllowNobody,
InstantiateDefaultPermission: types.AccessTypeNobody,
})
specs := map[string]struct {
setParams types.Params
expParams types.Params
expErr error
}{
"allowEverybody(DefaultParams)": {
setParams: types.DefaultParams(),
expParams: types.DefaultParams(),
},
"allowNobody": {
setParams: types.Params{
CodeUploadAccess: types.AllowNobody,
InstantiateDefaultPermission: types.AccessTypeNobody,
},
expParams: types.Params{
CodeUploadAccess: types.AllowNobody,
InstantiateDefaultPermission: types.AccessTypeNobody,
},
},
}
for msg, spec := range specs {
t.Run(msg, func(t *testing.T) {
xCtx, _ := ctx.CacheContext()
keeper.SetParams(xCtx, spec.setParams)

paramsResponse, err = q.Params(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{})
require.NoError(t, err)
require.NotNil(t, paramsResponse)
paramsResponse, err = q.Params(sdk.WrapSDKContext(xCtx), &types.QueryParamsRequest{})

require.Equal(t, paramsResponse.Params.CodeUploadAccess, types.AllowNobody)
require.Equal(t, paramsResponse.Params.InstantiateDefaultPermission, types.AccessTypeNobody)
require.NoError(t, err)
require.NotNil(t, paramsResponse)
require.Equal(t, spec.expParams.CodeUploadAccess, paramsResponse.Params.CodeUploadAccess)
require.Equal(t, spec.expParams.InstantiateDefaultPermission, paramsResponse.Params.InstantiateDefaultPermission)
})
}
}

func TestQueryCodeInfo(t *testing.T) {
Expand Down