-
Notifications
You must be signed in to change notification settings - Fork 0
tests: add Decimal serialization contract tests #93
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
tests: add Decimal serialization contract tests #93
Conversation
Summary of ChangesHello @zensgit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the robustness of the API by adding comprehensive contract tests to validate the serialization of Decimal fields. The primary goal is to ensure that these fields are consistently converted to JSON strings, thereby safeguarding against potential precision loss when consumed by JavaScript clients. This is a crucial step in maintaining data integrity across the system. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds contract tests to verify that Decimal fields in API responses are serialized as JSON strings rather than numbers, which prevents JavaScript floating-point precision issues. This is part of a broader effort to ensure consistent Decimal handling across the API.
Key Changes
- Added test assertions for GlobalMarketStats to verify Decimal fields serialize as strings
- Added explicit verification that the
updated_attimestamp field remains numeric
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds valuable contract tests to ensure Decimal fields are correctly serialized as strings, which is an important step to prevent precision loss in client-side applications. The new tests cover both GlobalMarketStats and AccountResponse structs. My review contains one suggestion for improving the structure of the tests to enhance clarity and maintainability.
| // updated_at is numeric unix timestamp | ||
| assert!(val.get("updated_at").and_then(|v| v.as_i64()).is_some()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test function is named global_market_stats_decimal_serializes_as_string, which implies its scope is limited to testing Decimal fields. The added assertion for updated_at (an i64) is outside this scope. While testing the entire contract is important, mixing concerns within a single test can make the test suite harder to understand and maintain. It's best practice for a test to have a single, clear purpose reflected in its name.
To improve clarity, I recommend moving this check to a separate test function, for example global_market_stats_numeric_fields_are_serialized_correctly. This would keep your tests focused and self-documenting.
Purpose
Scope
Notes