Repository navigation
fix(hypercore): make ReferrerState.data optional for needToCreateCode… - #1020
Conversation
… stage Hyperliquid referral API omits the `data` field when referrerState.stage is "needToCreateCode", causing swap deserialization failures.
Summary of ChangesHello, 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 resolves an issue where the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly makes the data field in ReferrerState optional to handle cases where the Hyperliquid API omits it, preventing deserialization failures. The changes are properly reflected in the related logic, and a new test case has been added to cover this scenario. My feedback focuses on improving the assertions within the tests to be more robust and readable by avoiding chained unwrap() calls, which can obscure the cause of test failures.
|
|
||
| assert_eq!(referral.cum_vlm, 0.0); | ||
| assert!(referral.referrer_state.unwrap().data.referral_states.is_none()); | ||
| assert!(referral.referrer_state.unwrap().data.unwrap().referral_states.is_none()); |
There was a problem hiding this comment.
Chained unwrap() calls can make test failures less informative by causing a panic without a clear message about what was None. Using matches! provides a more expressive and safer way to assert the structure of the data, improving test readability and robustness.
| assert!(referral.referrer_state.unwrap().data.unwrap().referral_states.is_none()); | |
| assert!(matches!(referral.referrer_state.as_ref(), Some(ReferrerState { data: Some(ReferrerData { referral_states: None }) }))); |
| let json = r#"{"referredBy":{"code":"GEMWALLET"},"cumVlm":"46615331.93","unclaimedRewards":"0.0","claimedRewards":"0.0","builderRewards":"0.0","referrerState":{"stage":"needToCreateCode"},"rewardHistory":[],"tokenToState":[]}"#; | ||
| let referral: Referral = serde_json::from_str(json).unwrap(); | ||
|
|
||
| assert!(referral.referrer_state.unwrap().data.is_none()); |
There was a problem hiding this comment.
Using unwrap() can lead to uninformative panics in tests. The matches! macro provides a safer and more descriptive way to assert the state of an Option, making the test more robust.
| assert!(referral.referrer_state.unwrap().data.is_none()); | |
| assert!(matches!(referral.referrer_state.as_ref(), Some(ReferrerState { data: None }))); |
|
|
||
| #[test] | ||
| fn referral_need_to_create_code_payload() { | ||
| let json = r#"{"referredBy":{"code":"GEMWALLET"},"cumVlm":"46615331.93","unclaimedRewards":"0.0","claimedRewards":"0.0","builderRewards":"0.0","referrerState":{"stage":"needToCreateCode"},"rewardHistory":[],"tokenToState":[]}"#; |
There was a problem hiding this comment.
move to json file, there might be one already
|
@copilot can you move let json = r to files, so it's consistent with other unit tests |
|
@gemcoder21 I've opened a new pull request, #1021, to work on those changes. Once the pull request is ready, I'll request review from you. |
…es (#1021) Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: gemcoder21 <[email protected]>
… stage
Hyperliquid referral API omits the
datafield when referrerState.stage is "needToCreateCode", causing swap deserialization failures.