From a41ef62814a9c2ae9880e670dc818f414d5cb95e Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Mon, 14 Aug 2023 14:36:24 +0900 Subject: [PATCH 01/10] test: test: add test cases to Params --- x/wasm/keeper/querier_test.go | 58 +++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index 2b07612325..740acca99e 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -798,31 +798,51 @@ func TestQueryPinnedCodes(t *testing.T) { } func TestQueryParams(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) - keeper := keepers.WasmKeeper - - q := Querier(keeper) + specs := map[string]struct { + srcPermission types.AccessType + expInstConf types.AccessConfig + }{ + "default": { + srcPermission: types.DefaultParams().InstantiateDefaultPermission, + expInstConf: types.AllowEverybody, + }, + "everybody": { + srcPermission: types.AccessTypeEverybody, + expInstConf: types.AllowEverybody, + }, + "nobody": { + srcPermission: types.AccessTypeNobody, + expInstConf: types.AllowNobody, + }, + } + for msg, spec := range specs { + t.Run(msg, func(t *testing.T) { + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) + keeper := keepers.WasmKeeper - paramsResponse, err := q.Params(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{}) - require.NoError(t, err) - require.NotNil(t, paramsResponse) + q := Querier(keeper) - defaultParams := types.DefaultParams() + paramsResponse, err := q.Params(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{}) + require.NoError(t, err) + require.NotNil(t, paramsResponse) - require.Equal(t, paramsResponse.Params.CodeUploadAccess, defaultParams.CodeUploadAccess) - require.Equal(t, paramsResponse.Params.InstantiateDefaultPermission, defaultParams.InstantiateDefaultPermission) + defaultParams := types.DefaultParams() - keeper.SetParams(ctx, types.Params{ - CodeUploadAccess: types.AllowNobody, - InstantiateDefaultPermission: types.AccessTypeNobody, - }) + require.Equal(t, paramsResponse.Params.CodeUploadAccess, defaultParams.CodeUploadAccess) + require.Equal(t, paramsResponse.Params.InstantiateDefaultPermission, defaultParams.InstantiateDefaultPermission) - paramsResponse, err = q.Params(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{}) - require.NoError(t, err) - require.NotNil(t, paramsResponse) + keeper.SetParams(ctx, types.Params{ + CodeUploadAccess: spec.expInstConf, + InstantiateDefaultPermission: spec.srcPermission, + }) - require.Equal(t, paramsResponse.Params.CodeUploadAccess, types.AllowNobody) - require.Equal(t, paramsResponse.Params.InstantiateDefaultPermission, types.AccessTypeNobody) + paramsResponse, err = q.Params(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{}) + require.NoError(t, err) + require.NotNil(t, paramsResponse) + require.Equal(t, spec.expInstConf, paramsResponse.Params.CodeUploadAccess) + require.Equal(t, spec.srcPermission, paramsResponse.Params.InstantiateDefaultPermission) + }) + } } func TestQueryCodeInfo(t *testing.T) { From 04d3403186daa5b7f77d062453ce35c6acb51fad Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Mon, 14 Aug 2023 14:39:19 +0900 Subject: [PATCH 02/10] chore: add this pr to CHANGE.log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40fc07c446..917cd8197a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * [\#63](https://github.com/Finschia/wasmd/pull/63) add event checking to TestStoreCode * [\#65](https://github.com/Finschia/wasmd/pull/65) add test cases for empty request in each function * [\#66](https://github.com/Finschia/wasmd/pull/66) add test cases for invalid pagination key in some functions +* [\#66](https://github.com/Finschia/wasmd/pull/69) add test cases to Params ### Bug Fixes * [\#52](https://github.com/Finschia/wasmd/pull/52) fix cli_test error of wasmplus and add cli_test ci From 5db073e44427f9033f509c43ab4a41f1f738a3fc Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Fri, 18 Aug 2023 11:40:15 +0900 Subject: [PATCH 03/10] fix: rename variable and so on --- x/wasm/keeper/querier_test.go | 68 ++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index 9cfffdeff3..79d645fde9 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -857,49 +857,53 @@ func TestQueryPinnedCodes(t *testing.T) { } func TestQueryParams(t *testing.T) { + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) + keeper := keepers.WasmKeeper + + q := Querier(keeper) + + paramsResponse, err := q.Params(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{}) + 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) + specs := map[string]struct { - srcPermission types.AccessType - expInstConf types.AccessConfig + setParams types.Params + srcQuery *types.QueryParamsRequest + expParams types.Params + expErr error }{ - "default": { - srcPermission: types.DefaultParams().InstantiateDefaultPermission, - expInstConf: types.AllowEverybody, - }, - "everybody": { - srcPermission: types.AccessTypeEverybody, - expInstConf: types.AllowEverybody, + "with empty request": { + setParams: types.DefaultParams(), + srcQuery: nil, + expParams: types.DefaultParams(), }, - "nobody": { - srcPermission: types.AccessTypeNobody, - expInstConf: types.AllowNobody, + "allowNobody": { + setParams: types.Params{ + CodeUploadAccess: types.AllowNobody, + InstantiateDefaultPermission: types.AccessTypeNobody, + }, + srcQuery: &types.QueryParamsRequest{}, + expParams: types.Params{ + CodeUploadAccess: types.AllowNobody, + InstantiateDefaultPermission: types.AccessTypeNobody, + }, }, } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) - keeper := keepers.WasmKeeper + keeper.SetParams(ctx, spec.setParams) - q := Querier(keeper) - - paramsResponse, err := q.Params(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{}) - 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: spec.expInstConf, - InstantiateDefaultPermission: spec.srcPermission, - }) + paramsResponse, err = q.Params(sdk.WrapSDKContext(ctx), spec.srcQuery) - paramsResponse, err = q.Params(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{}) require.NoError(t, err) require.NotNil(t, paramsResponse) - require.Equal(t, spec.expInstConf, paramsResponse.Params.CodeUploadAccess) - require.Equal(t, spec.srcPermission, paramsResponse.Params.InstantiateDefaultPermission) + require.Equal(t, spec.expParams.CodeUploadAccess, paramsResponse.Params.CodeUploadAccess) + require.Equal(t, spec.expParams.InstantiateDefaultPermission, paramsResponse.Params.InstantiateDefaultPermission) }) } } From 4bf3a3c51d269dded1a687debeb71697366c5f7a Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Fri, 18 Aug 2023 13:57:45 +0900 Subject: [PATCH 04/10] fix: delete unnecessary test case and the spec field --- x/wasm/keeper/querier_test.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index 79d645fde9..8ae7945d14 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -873,21 +873,14 @@ func TestQueryParams(t *testing.T) { specs := map[string]struct { setParams types.Params - srcQuery *types.QueryParamsRequest expParams types.Params expErr error }{ - "with empty request": { - setParams: types.DefaultParams(), - srcQuery: nil, - expParams: types.DefaultParams(), - }, "allowNobody": { setParams: types.Params{ CodeUploadAccess: types.AllowNobody, InstantiateDefaultPermission: types.AccessTypeNobody, }, - srcQuery: &types.QueryParamsRequest{}, expParams: types.Params{ CodeUploadAccess: types.AllowNobody, InstantiateDefaultPermission: types.AccessTypeNobody, @@ -896,9 +889,10 @@ func TestQueryParams(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { + xCtx, _ := ctx.CacheContext() keeper.SetParams(ctx, spec.setParams) - paramsResponse, err = q.Params(sdk.WrapSDKContext(ctx), spec.srcQuery) + paramsResponse, err = q.Params(sdk.WrapSDKContext(xCtx), &types.QueryParamsRequest{}) require.NoError(t, err) require.NotNil(t, paramsResponse) From 456cd844493a7f358c871f3ba2ad2ac98c0628f7 Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Fri, 18 Aug 2023 13:59:43 +0900 Subject: [PATCH 05/10] fix: Changed to refer to xCtx --- x/wasm/keeper/querier_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index 8ae7945d14..e28cb6efc0 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -890,7 +890,7 @@ func TestQueryParams(t *testing.T) { for msg, spec := range specs { t.Run(msg, func(t *testing.T) { xCtx, _ := ctx.CacheContext() - keeper.SetParams(ctx, spec.setParams) + keeper.SetParams(xCtx, spec.setParams) paramsResponse, err = q.Params(sdk.WrapSDKContext(xCtx), &types.QueryParamsRequest{}) From 02ea0c452a2581ed9bb3130fb1fc2d0af66ccf68 Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Fri, 18 Aug 2023 14:20:59 +0900 Subject: [PATCH 06/10] fix: add test case default params --- x/wasm/keeper/querier_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index e28cb6efc0..b3a70a9b7c 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -876,6 +876,10 @@ func TestQueryParams(t *testing.T) { expParams types.Params expErr error }{ + "allowEverybody(DefaultParams)": { + setParams: types.DefaultParams(), + expParams: types.DefaultParams(), + }, "allowNobody": { setParams: types.Params{ CodeUploadAccess: types.AllowNobody, From 010378b28fa89cf331f14d601d386fe8d2f3fee8 Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Fri, 18 Aug 2023 14:22:38 +0900 Subject: [PATCH 07/10] fix: rename pr title --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1936270795..28b7fc203a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ * [\#73](https://github.com/Finschia/wasmd/pull/73) test: add the check for expPaginationTotal * [\#72](https://github.com/Finschia/wasmd/pull/72) add pagination next key test in ContractHistory * [\#75](https://github.com/Finschia/wasmd/pull/75) test: add the test case for InactiveContract -* [\#69](https://github.com/Finschia/wasmd/pull/69) add test cases to Params +* [\#69](https://github.com/Finschia/wasmd/pull/69) refactor: add test cases to Params ### Bug Fixes * [\#62](https://github.com/Finschia/wasmd/pull/62) fill ContractHistory querier result's Updated field From f04767af5af9043f0fe89c05c4d4134e604ed3c6 Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Fri, 18 Aug 2023 16:08:27 +0900 Subject: [PATCH 08/10] fix: delete unnecessary test --- x/wasm/keeper/querier_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index b3a70a9b7c..dfde052e20 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -866,11 +866,6 @@ 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) - specs := map[string]struct { setParams types.Params expParams types.Params From 004a223ddc1f5a05b309dfe85bc64af846d2fe4c Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Fri, 18 Aug 2023 16:38:47 +0900 Subject: [PATCH 09/10] fix: fix change.log --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28b7fc203a..aef7f15fd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ * [\#73](https://github.com/Finschia/wasmd/pull/73) test: add the check for expPaginationTotal * [\#72](https://github.com/Finschia/wasmd/pull/72) add pagination next key test in ContractHistory * [\#75](https://github.com/Finschia/wasmd/pull/75) test: add the test case for InactiveContract -* [\#69](https://github.com/Finschia/wasmd/pull/69) refactor: add test cases to Params +* [\#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 From db4ef8e64984d5d683c46f5d471a56bf62aadc37 Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Fri, 18 Aug 2023 17:02:56 +0900 Subject: [PATCH 10/10] fix: delete unnecessary test --- x/wasm/keeper/querier_test.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index dfde052e20..a022a73ac1 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -862,10 +862,6 @@ func TestQueryParams(t *testing.T) { q := Querier(keeper) - paramsResponse, err := q.Params(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{}) - require.NoError(t, err) - require.NotNil(t, paramsResponse) - specs := map[string]struct { setParams types.Params expParams types.Params @@ -891,7 +887,7 @@ func TestQueryParams(t *testing.T) { xCtx, _ := ctx.CacheContext() keeper.SetParams(xCtx, spec.setParams) - paramsResponse, err = q.Params(sdk.WrapSDKContext(xCtx), &types.QueryParamsRequest{}) + paramsResponse, err := q.Params(sdk.WrapSDKContext(xCtx), &types.QueryParamsRequest{}) require.NoError(t, err) require.NotNil(t, paramsResponse)