Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(1557): fix for big int serialization #1581

Merged
merged 3 commits into from
Dec 17, 2024
Merged

fix(1557): fix for big int serialization #1581

merged 3 commits into from
Dec 17, 2024

Conversation

leszek-vechain
Copy link
Contributor

@leszek-vechain leszek-vechain commented Dec 12, 2024

Description

  • added big int serialization
  • added tests

Fixes # (#1557 )

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • local unit tests

Checklist:

  • My code follows the coding standards of this project
  • I have performed a self-review of my code
  • I have commented on my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • New and existing integration tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have not added any vulnerable dependencies to my code

Summary by CodeRabbit

  • New Features

    • Enhanced error handling to support bigint values in the stringification process.
  • Bug Fixes

    • Improved functionality of error message creation to accommodate bigint data types.
  • Tests

    • Updated unit tests to include scenarios for handling bigint in error messages.

- changed serialization of bigint
- cleaned up tests and added new one
@leszek-vechain leszek-vechain requested a review from a team as a code owner December 12, 2024 20:24
Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Walkthrough

The changes introduce a modification to the getCircularReplacer function within the stringifyData function in the helpers.ts file, adding a conditional check for bigint values to ensure they are correctly stringified. In the corresponding unit tests, several existing test cases were removed, and a new test case was added to validate the handling of BigInt in the createErrorMessage function. The overall structure and logic of the existing functions and tests remain unchanged.

Changes

File Path Change Summary
packages/errors/src/helpers/helpers.ts Modified getCircularReplacer to handle bigint values, converting them to strings with an appended 'n'.
packages/errors/tests/helpers/helpers.unit.test.ts Updated unit tests for createErrorMessage, removing old tests and adding a new test for BigInt handling.

Poem

In the code where errors dwell,
A bigint now rings a bell.
With strings that end in 'n' so bright,
Our functions now work just right!
Hop along, let’s celebrate,
For handling types, it’s never too late! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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

🧹 Outside diff range and nitpick comments (1)
packages/errors/tests/helpers/helpers.unit.test.ts (1)

76-87: Consider adding more BigInt test cases.

While the current test case verifies basic BigInt handling, consider adding tests for:

  • Maximum safe integer boundary cases (Number.MAX_SAFE_INTEGER + 1n)
  • Negative BigInt values
  • Zero as BigInt (0n)

Example addition:

 test('Should be able to build an error message - bigint', () => {
+    const testCases = [
+        { input: 10n, expected: '10n' },
+        { input: -10n, expected: '-10n' },
+        { input: 0n, expected: '0n' },
+        { input: BigInt(Number.MAX_SAFE_INTEGER) + 1n, expected: '9007199254740992n' }
+    ];
+
+    for (const { input, expected } of testCases) {
         const errorMessage = createErrorMessage(
             'simpleMethod',
             'Error message',
             {
-                data: 10n
+                data: input
             }
         );
         expect(errorMessage).toBeDefined();
-        expect(errorMessage).toContain('10n');
+        expect(errorMessage).toContain(expected);
+    }
 });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e0e536 and ac1e175.

📒 Files selected for processing (2)
  • packages/errors/src/helpers/helpers.ts (1 hunks)
  • packages/errors/tests/helpers/helpers.unit.test.ts (1 hunks)
🔇 Additional comments (2)
packages/errors/src/helpers/helpers.ts (1)

25-27: LGTM! Proper handling of BigInt serialization.

The implementation correctly handles BigInt serialization by converting to string with 'n' suffix, matching JavaScript's standard BigInt literal notation.

packages/errors/tests/helpers/helpers.unit.test.ts (1)

Line range hint 25-27: Verify BigInt handling across the codebase.

Let's ensure consistent BigInt handling across the codebase.

✅ Verification successful

Let me analyze the results and generate additional verification scripts to get more specific information about BigInt handling.

The first scan revealed extensive BigInt usage across the codebase, particularly in core packages and network-related functionality. However, we need to verify if there are proper error handling patterns and test coverage specifically for BigInt serialization, which these additional checks will help us determine.


Let me generate one final verification script to check the specific error handling implementation in the helpers file.

This will help us verify if the error handling implementation properly handles BigInt serialization, which is crucial for the final assessment.


BigInt handling is properly implemented across the codebase

The error handling implementation in packages/errors/src/helpers/helpers.ts already includes proper BigInt serialization by converting BigInt values to strings with an 'n' suffix during JSON stringification. This is the correct approach for handling BigInt values in error messages and logging.

Key findings:

  • The stringifyData function includes specific handling for BigInt values
  • BigInt test coverage exists in the codebase
  • The error handling implementation properly handles BigInt serialization
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for BigInt usage in the codebase
echo "Searching for BigInt usage patterns..."
rg -l "bigint|BigInt" --type ts

# Search for potential JSON.stringify usage that might need BigInt handling
echo -e "\nChecking for JSON.stringify usage that might need BigInt handling..."
rg "JSON\.stringify" --type ts -C 2

# Look for potential test files that might need BigInt test coverage
echo -e "\nIdentifying test files that might need BigInt test coverage..."
fd ".*\.test\.ts$" | xargs rg "test\(" -l

Length of output: 29796


Script:

#!/bin/bash
# Check for BigInt-related error handling patterns
echo "Checking for BigInt error handling patterns..."
rg "BigInt.*error|error.*BigInt" --type ts -C 2

# Look for JSON.stringify with BigInt handling
echo -e "\nChecking for BigInt-aware JSON.stringify usage..."
rg "JSON\.stringify.*BigInt|BigInt.*JSON\.stringify" --type ts -C 2

# Check for specific BigInt test cases
echo -e "\nLooking for BigInt-specific test cases..."
rg "test.*BigInt|describe.*BigInt" --type ts -C 2

# Check for BigInt type definitions and interfaces
echo -e "\nChecking for BigInt type definitions..."
ast-grep --pattern 'type $_ = bigint'

Length of output: 2721


Script:

#!/bin/bash
# Check the error handling implementation in helpers.ts
echo "Checking error handling implementation in helpers.ts..."
rg -C 10 "stringify" packages/errors/src/helpers/helpers.ts

# Check for any BigInt-related error handling in the errors package
echo -e "\nChecking for BigInt handling in errors package..."
rg "bigint|BigInt" packages/errors/src/ -C 5

Length of output: 3534

Copy link

github-actions bot commented Dec 12, 2024

Test Coverage

Summary

Lines Statements Branches Functions
Coverage: 99%
99% (4371/4415) 97.55% (1399/1434) 99.01% (906/915)
Title Tests Skipped Failures Errors Time
core 836 0 💤 0 ❌ 0 🔥 2m 19s ⏱️
network 729 0 💤 0 ❌ 0 🔥 4m 45s ⏱️
errors 40 0 💤 0 ❌ 0 🔥 17.116s ⏱️
logging 3 0 💤 0 ❌ 0 🔥 17.962s ⏱️
hardhat-plugin 19 0 💤 0 ❌ 0 🔥 1m 1s ⏱️
aws-kms-adapter 23 0 💤 0 ❌ 0 🔥 1m 14s ⏱️
ethers-adapter 5 0 💤 0 ❌ 0 🔥 1m 12s ⏱️
rpc-proxy 37 0 💤 0 ❌ 0 🔥 1m 1s ⏱️

@victhorbi victhorbi linked an issue Dec 13, 2024 that may be closed by this pull request
@claytonneal claytonneal merged commit db1aa68 into main Dec 17, 2024
17 checks passed
@claytonneal claytonneal deleted the fix_1557 branch December 17, 2024 13:36
@victhorbi victhorbi mentioned this pull request Jan 9, 2025
2 tasks
@fabiorigam fabiorigam restored the fix_1557 branch January 9, 2025 16:35
fabiorigam added a commit that referenced this pull request Jan 10, 2025
fabiorigam added a commit that referenced this pull request Jan 10, 2025
* chore: add #1652

* chore: #1581

* chore: #1608

* fix: change branches for gh actions

* fix: prepare for release

* chore: remove comments

* fix: fix issue
@victhorbi victhorbi mentioned this pull request Jan 10, 2025
16 tasks
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.

🐛 [BUG] - BigInt serialization
3 participants