Skip to content

Commit

Permalink
test(logic): max_result_count and max_size zero as unlimited
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Jul 29, 2024
1 parent 707d5a1 commit bc60a0b
Showing 1 changed file with 55 additions and 26 deletions.
81 changes: 55 additions & 26 deletions x/logic/keeper/grpc_query_ask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/samber/lo"

. "github.com/smartystreets/goconvey/convey"

sdkmath "cosmossdk.io/math"
Expand All @@ -36,8 +34,8 @@ func TestGRPCAsk(t *testing.T) {
program string
query string
limit int
maxResultCount int
maxSize int
maxResultCount uint64
maxSize uint64
predicateBlacklist []string
maxGas uint64
maxVariables uint64
Expand Down Expand Up @@ -127,6 +125,18 @@ func TestGRPCAsk(t *testing.T) {
maxSize: 5,
expectedError: "query: 15 > MaxSize: 5: limit exceeded",
},
{
program: "father(bob, alice). father(bob, john).",
query: "father(bob, X).",
maxSize: 0,
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 @@ -248,11 +258,11 @@ func TestGRPCAsk(t *testing.T) {
},
{
program: `
foo(a1).
foo(a2).
foo(a3) :- throw(error(resource_error(foo))).
foo(a4).
`,
foo(a1).
foo(a2).
foo(a3) :- throw(error(resource_error(foo))).
foo(a4).
`,
query: `foo(X).`,
maxResultCount: 1,
expectedAnswer: &types.Answer{
Expand All @@ -265,11 +275,11 @@ foo(a4).
},
{
program: `
foo(a1).
foo(a2).
foo(a3) :- throw(error(resource_error(foo))).
foo(a4).
`,
foo(a1).
foo(a2).
foo(a3) :- throw(error(resource_error(foo))).
foo(a4).
`,
query: `foo(X).`,
limit: 2,
maxResultCount: 3,
Expand All @@ -284,11 +294,11 @@ foo(a4).
},
{
program: `
foo(a1).
foo(a2).
foo(a3) :- throw(error(resource_error(foo))).
foo(a4).
`,
foo(a1).
foo(a2).
foo(a3) :- throw(error(resource_error(foo))).
foo(a4).
`,
query: `foo(X).`,
limit: 3,
maxResultCount: 5,
Expand All @@ -303,11 +313,11 @@ foo(a4).
},
{
program: `
foo(a1).
foo(a2).
foo(a3) :- throw(error(resource_error(foo))).
foo(a4).
`,
foo(a1).
foo(a2).
foo(a3) :- throw(error(resource_error(foo))).
foo(a4).
`,
query: `foo(X).`,
limit: 5,
maxResultCount: 5,
Expand All @@ -320,6 +330,25 @@ foo(a4).
},
},
},
{
program: `
foo(a1).
foo(a2).
foo(a3) :- throw(error(resource_error(foo))).
foo(a4).
`,
query: `foo(X).`,
limit: 5,
maxResultCount: 0,
expectedAnswer: &types.Answer{
Variables: []string{"X"},
Results: []types.Result{
{Substitutions: []types.Substitution{{Variable: "X", Expression: "a1"}}},
{Substitutions: []types.Substitution{{Variable: "X", Expression: "a2"}}},
{Error: "error(resource_error(foo))"},
},
},
},
}

for nc, tc := range cases {
Expand Down Expand Up @@ -352,8 +381,8 @@ foo(a4).
return fsProvider
},
)
maxResultCount := sdkmath.NewUint(uint64(lo.If(tc.maxResultCount == 0, 1).Else(tc.maxResultCount)))
maxSize := sdkmath.NewUint(uint64(lo.If(tc.maxSize == 0, 5000).Else(tc.maxSize)))
maxResultCount := sdkmath.NewUint(tc.maxResultCount)
maxSize := sdkmath.NewUint(tc.maxSize)
params := types.DefaultParams()
params.Limits.MaxResultCount = &maxResultCount
params.Limits.MaxSize = &maxSize
Expand Down

0 comments on commit bc60a0b

Please sign in to comment.