test(integration): generate private key, add response predicates#425
test(integration): generate private key, add response predicates#425
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughNew predicate factory for session key revocation is added alongside existing RPC method predicates. Test suite refactored to use centralized predicate-based validation instead of inline RPC response parsing. Private key generation switched from a custom implementation to the viem library utility. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Test as Test Suite
participant WS as TestWebSocket
participant Pred as Predicate (getRevokeSessionKeyPredicate / getTransferPredicate)
participant GP as genericPredicate
Note over Test,WS: Test initiates action (e.g., transfer, revoke)
Test->>WS: send RPC request
WS->>Pred: forward received message to predicate
Pred->>GP: call genericPredicate with method matcher
GP-->>Pred: boolean match result
Pred-->>WS: predicate result (true/false)
WS-->>Test: assertion outcome based on predicate
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
Summary of ChangesHello @nksazonov, 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 refactors the integration tests for session key functionality by introducing reusable predicate functions for WebSocket responses, streamlining the test logic for 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.
Code Review
This pull request refactors the session key integration tests to improve readability and maintainability. It replaces a custom private key generation function with a standard one from viem and introduces predicate helper functions to simplify waiting for WebSocket responses. These changes are well-executed and enhance the test suite's quality. I've noted one minor issue regarding an unused import.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
integration/tests/session_key.test.ts (3)
28-28: Remove unused import.The
getimport from 'http' doesn't appear to be used anywhere in the test file.Apply this diff:
-import { generatePrivateKey } from 'viem/accounts'; -import { get } from 'http'; +import { generatePrivateKey } from 'viem/accounts';
645-652: Apply predicate-based validation consistently.This test still uses inline RPC response parsing, while all other similar tests in this file were refactored to use
getRevokeSessionKeyPredicate(). Update for consistency.Apply this diff:
const revokeResponse = await aliceAppWS.sendAndWaitForResponse( revokeMsg, - (data: string) => { - const parsed = parseAnyRPCResponse(data); - return parsed.method === RPCMethod.RevokeSessionKey; - }, + getRevokeSessionKeyPredicate(), 5000 );
670-670: Verify error expectation consistency.Line 670 checks for a specific error pattern
/invalid signature/i, while similar test assertions at lines 817, 848, and 906 use generic.rejects.toThrow(). Confirm whether the different error expectations are intentional based on the expected server behavior, or if they should be unified for consistency.Also applies to: 817-817
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
integration/common/ws.ts(1 hunks)integration/tests/session_key.test.ts(17 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: dimast-x
Repo: erc7824/nitrolite PR: 419
File: clearnode/rpc_router_private.go:827-834
Timestamp: 2025-11-07T14:03:35.354Z
Learning: For the `revoke_session_key` RPC endpoint in clearnode/rpc_router_private.go: The design intentionally allows non-deterministic behavior when multiple session key signatures are present. Client-side code must ensure correct signatures are provided. The server keeps the RPC protocol flexible rather than implementing deterministic signature selection logic.
📚 Learning: 2025-11-07T14:03:35.354Z
Learnt from: dimast-x
Repo: erc7824/nitrolite PR: 419
File: clearnode/rpc_router_private.go:827-834
Timestamp: 2025-11-07T14:03:35.354Z
Learning: For the `revoke_session_key` RPC endpoint in clearnode/rpc_router_private.go: The design intentionally allows non-deterministic behavior when multiple session key signatures are present. Client-side code must ensure correct signatures are provided. The server keeps the RPC protocol flexible rather than implementing deterministic signature selection logic.
Applied to files:
integration/tests/session_key.test.ts
🧬 Code graph analysis (1)
integration/tests/session_key.test.ts (2)
integration/common/ws.ts (2)
getTransferPredicate(248-252)getRevokeSessionKeyPredicate(242-246)sdk/src/rpc/parse/parse.ts (1)
parseAnyRPCResponse(12-40)
⏰ 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). (3)
- GitHub Check: Build and Publish (Clearnode)
- GitHub Check: Test (Integration) / Test Integration
- GitHub Check: Analyze (go)
🔇 Additional comments (3)
integration/common/ws.ts (1)
242-246: LGTM!The new predicate factory follows the established pattern and correctly delegates to
genericPredicatefor RPC validation.integration/tests/session_key.test.ts (2)
625-625: LGTM!Switching from custom private key generation to viem's
generatePrivateKeyaligns with best practices of using well-established cryptographic libraries.Also applies to: 711-711, 736-736, 760-761
682-682: LGTM!Refactoring to use predicate-based validation improves maintainability and consistency across tests.
Also applies to: 700-700, 726-726, 750-750, 773-773, 800-800, 829-829, 873-873
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
integration/tests/session_key.test.ts (2)
646-648: Consider caching predicate instances for minor efficiency gain.The predicate factories are called repeatedly throughout the tests. While the performance impact is negligible for these test scenarios, you could create the predicates once at the test suite level and reuse them.
Example refactor at the test suite level:
+ const revokeSessionKeyPredicate = getRevokeSessionKeyPredicate(); + const transferPredicate = getTransferPredicate();Then use them directly:
- await aliceAppWS.sendAndWaitForResponse( - revokeMsg, - getRevokeSessionKeyPredicate(), - 5000 - ); + await aliceAppWS.sendAndWaitForResponse( + revokeMsg, + revokeSessionKeyPredicate, + 5000 + );Also applies to: 662-664, 677-679, 694-696, 719-721, 743-745, 766-768, 781-783, 793-795, 807-809, 822-824, 865-867
779-783: Consider verifying the initial transfer succeeds.While the test's focus is on revocation behavior, verifying that the initial transfer succeeds would make the test more robust and provide clearer diagnostics if something goes wrong.
- await aliceAppWS.sendAndWaitForResponse( + const transferResponse = await aliceAppWS.sendAndWaitForResponse( transferMsg, getTransferPredicate(), 5000 ); + const parsedTransfer = parseAnyRPCResponse(transferResponse); + expect(parsedTransfer.method).toBe(RPCMethod.Transfer);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
integration/tests/session_key.test.ts(19 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: dimast-x
Repo: erc7824/nitrolite PR: 419
File: clearnode/rpc_router_private.go:827-834
Timestamp: 2025-11-07T14:03:35.354Z
Learning: For the `revoke_session_key` RPC endpoint in clearnode/rpc_router_private.go: The design intentionally allows non-deterministic behavior when multiple session key signatures are present. Client-side code must ensure correct signatures are provided. The server keeps the RPC protocol flexible rather than implementing deterministic signature selection logic.
📚 Learning: 2025-11-07T14:03:35.354Z
Learnt from: dimast-x
Repo: erc7824/nitrolite PR: 419
File: clearnode/rpc_router_private.go:827-834
Timestamp: 2025-11-07T14:03:35.354Z
Learning: For the `revoke_session_key` RPC endpoint in clearnode/rpc_router_private.go: The design intentionally allows non-deterministic behavior when multiple session key signatures are present. Client-side code must ensure correct signatures are provided. The server keeps the RPC protocol flexible rather than implementing deterministic signature selection logic.
Applied to files:
integration/tests/session_key.test.ts
🧬 Code graph analysis (1)
integration/tests/session_key.test.ts (2)
integration/common/ws.ts (2)
getRevokeSessionKeyPredicate(242-246)getTransferPredicate(248-252)sdk/src/rpc/parse/parse.ts (1)
parseAnyRPCResponse(12-40)
⏰ 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). (3)
- GitHub Check: Build and Publish (Clearnode)
- GitHub Check: Test (Integration) / Test Integration
- GitHub Check: Analyze (go)
🔇 Additional comments (2)
integration/tests/session_key.test.ts (2)
5-5: LGTM - Good refactoring to centralized predicates and standard library.The addition of centralized predicate factories and viem's
generatePrivateKeyimproves code maintainability and leverages well-established cryptographic utilities.Also applies to: 27-27
624-624: LGTM - Using viem's key generation is more secure.Switching from custom private key generation to viem's
generatePrivateKey()is a good security practice, as it leverages a well-audited cryptographic library.Also applies to: 704-704, 729-729, 753-754
This is a continuation of #419
Summary by CodeRabbit
Tests
Chores