From b6617f3eb868898902ebb23a575db35cd2590d66 Mon Sep 17 00:00:00 2001 From: javiersuweijie Date: Mon, 25 Mar 2024 15:57:46 +0800 Subject: [PATCH 1/2] feat: binding error to match expected --- x/alliance/bindings/query_plugin.go | 3 ++- x/alliance/bindings/tests/query_plugin_test.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/x/alliance/bindings/query_plugin.go b/x/alliance/bindings/query_plugin.go index c2a095ee..28f1fedb 100644 --- a/x/alliance/bindings/query_plugin.go +++ b/x/alliance/bindings/query_plugin.go @@ -2,6 +2,7 @@ package bindings import ( "encoding/json" + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -48,7 +49,7 @@ func CustomQuerier(q *QueryPlugin) func(ctx sdk.Context, request json.RawMessage validator, ) } - return nil, nil + return nil, fmt.Errorf("unknown query") } } diff --git a/x/alliance/bindings/tests/query_plugin_test.go b/x/alliance/bindings/tests/query_plugin_test.go index 8a6c9f09..444a9153 100644 --- a/x/alliance/bindings/tests/query_plugin_test.go +++ b/x/alliance/bindings/tests/query_plugin_test.go @@ -203,3 +203,21 @@ func TestDelegationRewardsQuery(t *testing.T) { }, }, response) } + +func TestCustomQuerier(t *testing.T) { + app, ctx := createTestContext(t) + genesisTime := ctx.BlockTime() + app.AllianceKeeper.InitGenesis(ctx, &types.GenesisState{ + Params: types.DefaultParams(), + Assets: []types.AllianceAsset{ + types.NewAllianceAsset(AllianceDenom, sdk.NewDec(2), sdk.ZeroDec(), sdk.NewDec(5), sdk.NewDec(0), genesisTime), + }, + }) + + querierPlugin := bindings.NewAllianceQueryPlugin(app.AllianceKeeper) + querier := bindings.CustomQuerier(querierPlugin) + + queryBytes := []byte("{\"random\": \"query\"}") + _, err := querier(ctx, queryBytes) + require.Error(t, err) +} From 084e2d77cef6909d7ba0f75a50d346e1ec2ddd70 Mon Sep 17 00:00:00 2001 From: javiersuweijie Date: Mon, 25 Mar 2024 16:48:52 +0800 Subject: [PATCH 2/2] fix: lint --- x/alliance/bindings/query_plugin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/alliance/bindings/query_plugin.go b/x/alliance/bindings/query_plugin.go index 28f1fedb..df00cc5f 100644 --- a/x/alliance/bindings/query_plugin.go +++ b/x/alliance/bindings/query_plugin.go @@ -26,7 +26,7 @@ func CustomQuerier(q *QueryPlugin) func(ctx sdk.Context, request json.RawMessage var AllianceRequest types.AllianceQuery err = json.Unmarshal(request, &AllianceRequest) if err != nil { - return + return nil, err } if AllianceRequest.Alliance != nil { return q.GetAlliance(ctx, AllianceRequest.Alliance.Denom)