Skip to content

test(integration): generate private key, add response predicates#425

Merged
dimast-x merged 2 commits intomainfrom
fix/sk-revoke-integration
Nov 11, 2025
Merged

test(integration): generate private key, add response predicates#425
dimast-x merged 2 commits intomainfrom
fix/sk-revoke-integration

Conversation

@nksazonov
Copy link
Contributor

@nksazonov nksazonov commented Nov 10, 2025

This is a continuation of #419

Summary by CodeRabbit

  • Tests

    • Improved session key validation and revocation tests using centralized predicate-based RPC checks and updated key generation, leading to more reliable coverage of transfer and revoke scenarios.
  • Chores

    • Streamlined test utilities and imports to simplify session key handling and assertions in integration tests.

@nksazonov nksazonov requested a review from a team as a code owner November 10, 2025 21:41
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 10, 2025

Note

Other AI code review bot(s) detected

CodeRabbit 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.

Walkthrough

New 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

Cohort / File(s) Summary
Predicate Factory Addition
integration/common/ws.ts
New exported predicate factory getRevokeSessionKeyPredicate added to validate RPCMethod.RevokeSessionKey responses using the existing genericPredicate pattern.
Test Suite Refactoring
integration/tests/session_key.test.ts
Imports updated to include new predicates (getRevokeSessionKeyPredicate, getTransferPredicate) and generatePrivateKey from viem/accounts. Private key generation replaced with generatePrivateKey. Inline RPC response parsing replaced with predicate-based validation; manual request/response ID extraction removed in favor of centralized predicate checks.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Predicate addition is small and follows existing pattern.
  • Test file changes cover multiple places and replace inline parsing with predicates — requires spot-checking each replaced assertion.
  • Verify getRevokeSessionKeyPredicate matches method name exactly and integrates with existing genericPredicate.
  • Confirm generatePrivateKey usage yields equivalent test behavior (key formats) where used.

Poem

🐰 I hopped through code with nimble feet,

A revoke-predicate now complete.
Keys from viem, so crisp and spry,
Tests now listen, not pry—
Hooray, clean hops across the sky! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately summarizes the main changes: introducing private key generation and adding response predicates for session key operations in integration tests.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/sk-revoke-integration

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 Transfer and RevokeSessionKey RPC methods. It also standardizes private key generation by adopting a utility from the viem/accounts library, enhancing consistency and reliability across the test suite.

Highlights

  • Refactored Response Predicates: Introduced a new getRevokeSessionKeyPredicate function and refactored existing test cases to utilize this and getTransferPredicate for cleaner and more consistent handling of WebSocket RPC responses.
  • Standardized Private Key Generation: Replaced the custom generateRandomPrivateKey helper function with the generatePrivateKey utility from the viem/accounts library, ensuring a standardized and robust approach to private key generation in tests.
  • Improved Test Assertions: Enhanced the specificity of error assertions in session_key.test.ts by updating rejects.toThrow() to check for specific error messages like 'invalid signature'.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 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
Copy link

codecov bot commented Nov 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

🧹 Nitpick comments (3)
integration/tests/session_key.test.ts (3)

28-28: Remove unused import.

The get import 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

📥 Commits

Reviewing files that changed from the base of the PR and between e03419b and 6498f56.

📒 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 genericPredicate for RPC validation.

integration/tests/session_key.test.ts (2)

625-625: LGTM!

Switching from custom private key generation to viem's generatePrivateKey aligns 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

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

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6498f56 and 4c8109f.

📒 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 generatePrivateKey improves 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

@nksazonov nksazonov changed the title fix(integration): generate private key, add response predicates test(integration): generate private key, add response predicates Nov 11, 2025
@dimast-x dimast-x merged commit 55b495c into main Nov 11, 2025
13 checks passed
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.

2 participants