Skip to content

Commit

Permalink
Merge pull request #337 from terra-money/feat/v0.4/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 361dd3d + c2a02bb commit 3d5b45d
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 @@ -208,3 +208,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, math.LegacyNewDec(2), math.LegacyZeroDec(), math.LegacyNewDec(5), math.LegacyNewDec(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 3d5b45d

Please sign in to comment.