Skip to content

Commit

Permalink
Merge pull request #336 from terra-money/feat/v0.3/update-binding-error
Browse files Browse the repository at this point in the history
feat: binding error to match expected
  • Loading branch information
javiersuweijie authored Mar 25, 2024
2 parents d576fa8 + 084e2d7 commit 528af3d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions x/alliance/bindings/query_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bindings

import (
"encoding/json"
"fmt"

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

Expand All @@ -25,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)
Expand All @@ -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")
}
}

Expand Down
18 changes: 18 additions & 0 deletions x/alliance/bindings/tests/query_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 528af3d

Please sign in to comment.