Skip to content

Conversation

@Azorlogh
Copy link
Contributor

@Azorlogh Azorlogh requested a review from a team as a code owner August 25, 2025 16:07
@coderabbitai
Copy link

coderabbitai bot commented Aug 25, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (6)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
  • tools/generator/go.mod is excluded by !**/*.mod
  • tools/generator/go.sum is excluded by !**/*.sum, !**/*.sum
  • tools/provisioner/go.mod is excluded by !**/*.mod
  • tools/provisioner/go.sum is excluded by !**/*.sum, !**/*.sum

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Tests for account balance filters were updated to use big.Int values instead of float64. Schema validation now accepts big.Int and *big.Int as valid numeric types. An end-to-end test was added to verify balance filtering with large big integers.

Changes

Cohort / File(s) Summary
API v2 controller tests: balance filter types
internal/api/v2/controllers_accounts_count_test.go, internal/api/v2/controllers_accounts_list_test.go, internal/api/v2/controllers_volumes_test.go
Import math/big; replace float64 bounds in balance filters with big.NewInt(...) for Lt/Gte conditions.
Storage schema: numeric validation
internal/storage/common/schema.go
Import math/big; TypeNumeric.ValidateValue now accepts big.Int and *big.Int in type switch.
E2E accounts list: big int filtering
test/e2e/api_accounts_list_test.go
Add test validating $gte/$lte filters on balance[USD] using a large big.Int; expect one matching account.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant API as API (Accounts List)
  participant Q as Query Builder
  participant S as Storage Schema
  participant DB as Database

  C->>API: GET /accounts?filter=balance[CCY] $gte/$lte (big.Int)
  API->>Q: Build filters with big.Int bounds
  Q->>S: Validate numeric values
  Note over S: Accept int/float/big.Int
  S-->>Q: OK
  Q->>DB: Execute query with balance predicates
  DB-->>API: Matching accounts
  API-->>C: 200 OK with result set
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibbled on bits, both tiny and grand,
Swapping floats for big ints, just as planned.
Filters now stretch where balances grow,
The schema nods, “Big numbers? Let’s go!”
One hop, two hops—tests all green 🥕✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/query-filters-with-big-ints

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
internal/storage/common/schema.go (1)

217-225: No pointer numeric usages found in query builders; nil-pointer checks remain optional

  • Ran ripgrep against all Go files for patterns like query.Lt(..., &x) and literal pointer types (*big.Int, *int, etc.); no matches were found in the repo.
  • Since pointer numerics aren’t currently passed into the query builders, adding nil-pointer rejection in ValidateValue won’t break existing behavior—this remains an optional hardening step.

You may choose to implement the suggested diff to guard against typed-nil pointers in the future, but there are no immediate downstream impacts.

test/e2e/api_accounts_list_test.go (1)

120-143: Valuable e2e for big.Int range filters; tighten assertion to check the actual account.

The $and with $gte/$lte around the same bigInt exercises range handling for huge values. To make the test more robust, assert which account is returned (not just count). Example change:

 It("should properly filter big ints", func(specContext SpecContext) {
   response, err := Wait(specContext, DeferClient(testServer)).Ledger.V2.ListAccounts(
     ctx,
     operations.V2ListAccountsRequest{
       Ledger: "default",
       RequestBody: map[string]any{
         "$and": []map[string]any{
           {
             "$gte": map[string]any{
               "balance[USD]": bigInt,
             },
           },
           {
             "$lte": map[string]any{
               "balance[USD]": bigInt,
             },
           },
         },
       },
     },
   )
   Expect(err).ToNot(HaveOccurred())
   Expect(len(response.V2AccountsCursorResponse.Cursor.Data)).To(Equal(1))
+  Expect(response.V2AccountsCursorResponse.Cursor.Data[0].Address).To(Equal("foo:foo"))
 })

If $eq is supported by the query language, you could alternatively use it here; the current form is fine if you specifically want to cover both comparison paths.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5b6b3ab and c4a8f11.

📒 Files selected for processing (7)
  • internal/api/v2/common.go (1 hunks)
  • internal/api/v2/controllers_accounts_count_test.go (3 hunks)
  • internal/api/v2/controllers_accounts_list.go (1 hunks)
  • internal/api/v2/controllers_accounts_list_test.go (3 hunks)
  • internal/api/v2/controllers_volumes_test.go (2 hunks)
  • internal/storage/common/schema.go (2 hunks)
  • test/e2e/api_accounts_list_test.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/e2e/api_accounts_list_test.go (1)
pkg/client/models/operations/v2listaccounts.go (1)
  • V2ListAccountsRequest (11-30)
🔇 Additional comments (12)
internal/storage/common/schema.go (2)

5-6: Import of math/big is appropriate for big.Int acceptance.

No issues. This aligns with the extended numeric validation.


5-6: Unable to locate dependency management files to verify go-libs version

I wasn’t able to find a go.mod, go.work, Gopkg.toml/lock, glide.yaml/lock, or vendor/modules.txt in the repo—so I can’t confirm that you’ve pinned github.com/formancehq/go-libs/v3 to the version containing PR 505 (which adds the required big.Int support). Please ensure:

  • Your module’s go.mod (or equivalent) at the project root includes
    require github.com/formancehq/go-libs/v3 <version-with-PR-505>
  • No conflicting replace directive overrides that version
  • If you manage dependencies elsewhere (e.g. in a parent module), point me to the file/location where go-libs is declared

File under review: internal/storage/common/schema.go (imports “math/big” and relies on go-libs big.Int support)

internal/api/v2/common.go (1)

90-91: Whitespace-only change.

No behavioral impact. Fine to keep.

internal/api/v2/controllers_accounts_count_test.go (3)

5-5: Import math/big to exercise big.Int filters is correct.

Matches the updated schema validation and query expectations.


11-14: Import adjustments look fine.

No functional changes; keeps tests readable and organized.


76-77: Switch to big.NewInt(100) in expected Builder aligns with body payload.

This validates big.Int flow end-to-end for Lt on balance[USD/2].

internal/api/v2/controllers_volumes_test.go (1)

38-38: Formatting-only blank line.

No action needed.

internal/api/v2/controllers_accounts_list.go (1)

4-5: Import reorder only.

No behavioral impact; goimports-compatible.

internal/api/v2/controllers_accounts_list_test.go (4)

5-5: Good move: use big.Int to avoid float precision pitfalls in filters.

Switching tests to math/big ensures deterministic comparisons for balances.


11-15: Imports look correct and necessary.

pointer, common, storagecommon, and ledgerstore are all used below; aliasing storagecommon keeps call sites readable.


42-42: Whitespace-only change.

No action needed.


151-151: Confirm big.Int usage and parser parity for JSON numbers vs. strings
All existing balance-filter tests now use big.NewInt (no float64/json.Number left in query.Lt|Lte|Gt|Gte|Eq for balance[...]) and TypeNumeric.ValidateValue accepts both big.Int and *big.Int per schema logic.

• File/internal/api/v2/controllers_accounts_list_test.go:151

  • The change to query.Lt("balance[USD/2]", big.NewInt(100)) is correct to avoid float rounding.

• Depedency check

  • Please manually verify that your go-libs/v3 module is upgraded to the version including PR 505 (which ensures JSON numbers and string‐encoded big ints are handled identically).

• Optional test enhancement

  • Consider adding a sibling test using a string literal filter, e.g.:
    Builder: query.Lt("balance[USD/2]", "100"),
    and assert that the parser still produces a big.Int of value 100.

Builder: query.Gte("balance[EUR]", big.NewInt(100)),
Expand: make([]string, 0),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Mismatch: body uses 50 but expected Builder uses big.NewInt(100).

Test will fail as the parsed query compares against 50 while expectation asserts 100. Align the expected Builder to 50.

Apply this diff:

-					Builder: query.Gte("balance[EUR]", big.NewInt(100)),
+					Builder: query.Gte("balance[EUR]", big.NewInt(50)),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Builder: query.Gte("balance[EUR]", big.NewInt(100)),
Expand: make([]string, 0),
@@ internal/api/v2/controllers_volumes_test.go
Builder: query.Gte("balance[EUR]", big.NewInt(50)),
Expand: make([]string, 0),
🤖 Prompt for AI Agents
In internal/api/v2/controllers_volumes_test.go around lines 128 to 129, the test
expectation uses Builder: query.Gte("balance[EUR]", big.NewInt(100)) while the
test body parses a query with value 50; update the expected Builder value to
big.NewInt(50) so the parsed query and the expectation match, and run tests to
verify the failure is resolved.

@codecov
Copy link

codecov bot commented Sep 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.67%. Comparing base (913fa3b) to head (bafae8d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1042      +/-   ##
==========================================
- Coverage   80.75%   80.67%   -0.08%     
==========================================
  Files         186      186              
  Lines       10309    10309              
==========================================
- Hits         8325     8317       -8     
- Misses       1563     1569       +6     
- Partials      421      423       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Azorlogh Azorlogh force-pushed the fix/query-filters-with-big-ints branch from be1ba1d to f690471 Compare September 8, 2025 17:09
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/storage/common/schema.go (1)

217-224: Validation accepts nil numeric pointers — reject nils to avoid invalid queries slipping through

Currently, *int/*float/*big.Int values pass validation even when nil. That can admit malformed filters and defer failures downstream. Explicitly reject nil pointers.

-func (t TypeNumeric) ValidateValue(value any) error {
-	switch value.(type) {
-	case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float64, float32, big.Int,
-		*int, *int8, *int16, *int32, *int64, *uint, *uint8, *uint16, *uint32, *uint64, *float64, *float32, *big.Int:
-		return nil
-	default:
-		return fmt.Errorf("expected numeric value, got %T", value)
-	}
-}
+func (t TypeNumeric) ValidateValue(value any) error {
+	switch v := value.(type) {
+	case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float64, float32, big.Int:
+		return nil
+	case *int, *int8, *int16, *int32, *int64,
+		*uint, *uint8, *uint16, *uint32, *uint64,
+		*float64, *float32, *big.Int:
+		if v == nil {
+			return fmt.Errorf("expected non-nil numeric pointer, got %T(nil)", value)
+		}
+		return nil
+	default:
+		return fmt.Errorf("expected numeric value, got %T", value)
+	}
+}

Consider adding a small unit test set asserting nil pointers are rejected for completeness.

♻️ Duplicate comments (1)
internal/api/v2/controllers_volumes_test.go (1)

127-128: Aligned expected bound with request body (50) — resolved

The expected Builder now matches the body’s 50 value. This addresses the earlier mismatch noted in prior review.

🧹 Nitpick comments (2)
test/e2e/api_accounts_list_test.go (2)

120-143: Strengthen the big-int filter assertion

Since the filter should return exactly the “foo:foo” account, assert the address for extra confidence.

 			Expect(err).ToNot(HaveOccurred())
-			Expect(len(response.V2AccountsCursorResponse.Cursor.Data)).To(Equal(1))
+			Expect(len(response.V2AccountsCursorResponse.Cursor.Data)).To(Equal(1))
+			Expect(response.V2AccountsCursorResponse.Cursor.Data[0].Address).To(Equal("foo:foo"))

61-62: Check SetString conversion success to avoid silent test flakiness

Guard against accidental invalid literals by asserting the ok flag from SetString.

-			bigInt, _       = big.NewInt(0).SetString("98EWM95ct8tBYWroCxXYN9vCgN7NTcR6nUsvCx1mEdLZ999999999999999999999999999999999999999999", 10)
+			var ok bool
+			bigInt, ok      = big.NewInt(0).SetString("98EWM95ct8tBYWroCxXYN9vCgN7NTcR6nUsvCx1mEdLZ999999999999999999999999999999999999999999", 10)
+			Expect(ok).To(BeTrue())

Also applies to: 120-143

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1bdb1d3 and f690471.

⛔ Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (5)
  • internal/api/v2/controllers_accounts_count_test.go (2 hunks)
  • internal/api/v2/controllers_accounts_list_test.go (3 hunks)
  • internal/api/v2/controllers_volumes_test.go (1 hunks)
  • internal/storage/common/schema.go (2 hunks)
  • test/e2e/api_accounts_list_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Tests
  • GitHub Check: Dirty
🔇 Additional comments (2)
internal/api/v2/controllers_accounts_count_test.go (1)

12-12: Switch to big.Int in balance filter expectation — looks correct

Using big.NewInt(100) aligns the test with the new numeric handling in query filters. No issues spotted.

Also applies to: 73-75

internal/api/v2/controllers_accounts_list_test.go (1)

13-13: big.Int adoption in balance filter expectation — good update

The expectation now matches big-int aware parsing. All good.

Also applies to: 149-151

@Azorlogh Azorlogh added this pull request to the merge queue Sep 9, 2025
Merged via the queue into main with commit 26c3d79 Sep 9, 2025
8 of 9 checks passed
@Azorlogh Azorlogh deleted the fix/query-filters-with-big-ints branch September 9, 2025 08:51
@gfyrag gfyrag restored the fix/query-filters-with-big-ints branch September 11, 2025 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants