Skip to content

Commit

Permalink
test(logic): add test cases to cover new param "limit"
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Mar 11, 2024
1 parent b509653 commit 78ab886
Showing 1 changed file with 50 additions and 13 deletions.
63 changes: 50 additions & 13 deletions x/logic/keeper/grpc_query_ask_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:gocognit
package keeper_test

import (
Expand Down Expand Up @@ -33,6 +34,7 @@ func TestGRPCAsk(t *testing.T) {
program string
query string
limit int
maxResultCount int
predicateBlacklist []string
maxGas uint64
predicateCosts map[string]uint64
Expand Down Expand Up @@ -83,9 +85,22 @@ func TestGRPCAsk(t *testing.T) {
},
},
{
program: "father(bob, alice). father(bob, john).",
query: "father(bob, X).",
limit: 5,
program: "father(bob, alice). father(bob, john).",
query: "father(bob, X).",
maxResultCount: 5,
expectedAnswer: &types.Answer{
HasMore: true,
Variables: []string{"X"},
Results: []types.Result{{Substitutions: []types.Substitution{{
Variable: "X", Expression: "alice",
}}}},
},
},
{
program: "father(bob, alice). father(bob, john).",
query: "father(bob, X).",
limit: 2,
maxResultCount: 5,
expectedAnswer: &types.Answer{
Variables: []string{"X"},
Results: []types.Result{{Substitutions: []types.Substitution{{
Expand All @@ -95,6 +110,19 @@ func TestGRPCAsk(t *testing.T) {
}}}},
},
},
{
program: "father(bob, alice). father(bob, john).",
query: "father(bob, X).",
limit: 2,
maxResultCount: 1,
expectedAnswer: &types.Answer{
HasMore: true,
Variables: []string{"X"},
Results: []types.Result{{Substitutions: []types.Substitution{{
Variable: "X", Expression: "alice",
}}}},
},
},
{
query: "block_height(X).",
expectedAnswer: &types.Answer{
Expand Down Expand Up @@ -204,8 +232,8 @@ foo(a2).
foo(a3) :- throw(error(resource_error(foo))).
foo(a4).
`,
query: `foo(X).`,
limit: 1,
query: `foo(X).`,
maxResultCount: 1,
expectedAnswer: &types.Answer{
HasMore: true,
Variables: []string{"X"},
Expand All @@ -221,8 +249,9 @@ foo(a2).
foo(a3) :- throw(error(resource_error(foo))).
foo(a4).
`,
query: `foo(X).`,
limit: 2,
query: `foo(X).`,
limit: 2,
maxResultCount: 3,
expectedAnswer: &types.Answer{
HasMore: true,
Variables: []string{"X"},
Expand All @@ -239,8 +268,9 @@ foo(a2).
foo(a3) :- throw(error(resource_error(foo))).
foo(a4).
`,
query: `foo(X).`,
limit: 3,
query: `foo(X).`,
limit: 5,
maxResultCount: 3,
expectedAnswer: &types.Answer{
Variables: []string{"X"},
Results: []types.Result{
Expand All @@ -257,8 +287,9 @@ foo(a2).
foo(a3) :- throw(error(resource_error(foo))).
foo(a4).
`,
query: `foo(X).`,
limit: 5,
query: `foo(X).`,
limit: 5,
maxResultCount: 5,
expectedAnswer: &types.Answer{
Variables: []string{"X"},
Results: []types.Result{
Expand Down Expand Up @@ -295,9 +326,9 @@ foo(a4).
return fsProvider
},
)
limit := sdkmath.NewUint(uint64(lo.If(tc.limit == 0, 1).Else(tc.limit)))
maxResultCount := sdkmath.NewUint(uint64(lo.If(tc.maxResultCount == 0, 1).Else(tc.maxResultCount)))
params := types.DefaultParams()
params.Limits.MaxResultCount = &limit
params.Limits.MaxResultCount = &maxResultCount
if tc.predicateBlacklist != nil {
params.Interpreter.PredicatesFilter.Blacklist = tc.predicateBlacklist
}
Expand Down Expand Up @@ -326,9 +357,15 @@ foo(a4).

queryClient := types.NewQueryServiceClient(queryHelper)

var limit *sdkmath.Uint
if tc.limit != 0 {
v := sdkmath.NewUint(uint64(tc.limit))
limit = &v
}
query := types.QueryServiceAskRequest{
Program: tc.program,
Query: tc.query,
Limit: limit,
}

Convey("when the grpc query ask is called", func() {
Expand Down

0 comments on commit 78ab886

Please sign in to comment.