Skip to content

Commit 528af3d

Browse files
Merge pull request #336 from terra-money/feat/v0.3/update-binding-error
feat: binding error to match expected
2 parents d576fa8 + 084e2d7 commit 528af3d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

x/alliance/bindings/query_plugin.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package bindings
22

33
import (
44
"encoding/json"
5+
"fmt"
56

67
sdk "github.com/cosmos/cosmos-sdk/types"
78

@@ -25,7 +26,7 @@ func CustomQuerier(q *QueryPlugin) func(ctx sdk.Context, request json.RawMessage
2526
var AllianceRequest types.AllianceQuery
2627
err = json.Unmarshal(request, &AllianceRequest)
2728
if err != nil {
28-
return
29+
return nil, err
2930
}
3031
if AllianceRequest.Alliance != nil {
3132
return q.GetAlliance(ctx, AllianceRequest.Alliance.Denom)
@@ -48,7 +49,7 @@ func CustomQuerier(q *QueryPlugin) func(ctx sdk.Context, request json.RawMessage
4849
validator,
4950
)
5051
}
51-
return nil, nil
52+
return nil, fmt.Errorf("unknown query")
5253
}
5354
}
5455

x/alliance/bindings/tests/query_plugin_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,21 @@ func TestDelegationRewardsQuery(t *testing.T) {
203203
},
204204
}, response)
205205
}
206+
207+
func TestCustomQuerier(t *testing.T) {
208+
app, ctx := createTestContext(t)
209+
genesisTime := ctx.BlockTime()
210+
app.AllianceKeeper.InitGenesis(ctx, &types.GenesisState{
211+
Params: types.DefaultParams(),
212+
Assets: []types.AllianceAsset{
213+
types.NewAllianceAsset(AllianceDenom, sdk.NewDec(2), sdk.ZeroDec(), sdk.NewDec(5), sdk.NewDec(0), genesisTime),
214+
},
215+
})
216+
217+
querierPlugin := bindings.NewAllianceQueryPlugin(app.AllianceKeeper)
218+
querier := bindings.CustomQuerier(querierPlugin)
219+
220+
queryBytes := []byte("{\"random\": \"query\"}")
221+
_, err := querier(ctx, queryBytes)
222+
require.Error(t, err)
223+
}

0 commit comments

Comments
 (0)