Skip to content

Add unit tests for RemoteSigningService#141

Draft
Dexploarer wants to merge 1 commit intodevelopfrom
tests-remote-signing-service-4635356540678650487
Draft

Add unit tests for RemoteSigningService#141
Dexploarer wants to merge 1 commit intodevelopfrom
tests-remote-signing-service-4635356540678650487

Conversation

@Dexploarer
Copy link
Owner

Added comprehensive unit tests for RemoteSigningService in src/services/remote-signing-service.test.ts.
This service handles critical security operations (transaction signing), policy enforcement, and approval workflows.
The tests cover:

  • Successful auto-signing when policy allows.
  • Rejection when policy denies (e.g. wrong chain, blacklisted contract).
  • Human confirmation flow (requiring approval, approving, rejecting, expiring).
  • Audit logging of all significant events.
  • Error handling from the signer backend.

The tests use vitest mocks and fake timers to ensure determinism and isolation.


PR created automatically by Jules for task 4635356540678650487 started by @Dexploarer

- Create `src/services/remote-signing-service.test.ts`
- Cover happy paths, policy rejection, human confirmation, audit logging, and error handling
- Mock `SignerBackend` and `SandboxAuditLog`
- Use `vitest` framework features (fake timers, mocks)
@google-labs-jules
Copy link

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tests-remote-signing-service-4635356540678650487

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.

@github-actions github-actions bot added the tests label Feb 25, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @Dexploarer, 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 significantly enhances the stability and trustworthiness of the RemoteSigningService by introducing a comprehensive suite of unit tests. These tests validate critical security operations, policy adherence, and user interaction flows, ensuring the service behaves as expected under various conditions and correctly handles potential errors, thereby improving the overall security posture and reliability of transaction signing.

Highlights

  • Comprehensive Unit Tests Added: New unit tests have been introduced for the RemoteSigningService to ensure its reliability and correctness across various scenarios.
  • Policy Enforcement Validation: Tests cover successful auto-signing when policies permit, as well as correct rejection when policies deny a signing request (e.g., wrong chain, blacklisted contract).
  • Human Confirmation Workflow Tested: The human confirmation flow, including requiring approval, approving, rejecting, and expiring requests, is thoroughly tested.
  • Audit Logging Verification: The tests confirm that all significant events within the RemoteSigningService are properly recorded in the audit log.
  • Signer Backend Error Handling: Error handling from the underlying signer backend is validated to ensure robust behavior in case of failures.

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

Changelog
  • src/services/remote-signing-service.test.ts
    • Added a new test file to cover the RemoteSigningService.
Activity
  • PR created automatically by Jules for task 4635356540678650487, initiated by @Dexploarer.
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.

Comment on lines +179 to +196
vi.useFakeTimers();
policy.requireHumanConfirmation = true;
service.updatePolicy(policy);

const request = makeRequest();
await service.submitSigningRequest(request);

// Advance time past expiration (1000ms set in beforeEach)
vi.advanceTimersByTime(1500);

const result = await service.approveRequest(request.requestId);

expect(result.success).toBe(false);
expect(result.error).toContain("Approval expired");
expect(service.getPendingApprovals()).toHaveLength(0);

vi.useRealTimers();
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of vi.useFakeTimers() in the 'should fail if approval expired' test is not paired with a vi.useRealTimers() in a finally block or afterEach hook. If an error occurs before vi.useRealTimers() is called, subsequent tests may run with fake timers, leading to unpredictable behavior and flaky tests.

Recommended solution:
Wrap the test body in a try/finally block to ensure vi.useRealTimers() is always called, or use an afterEach hook to reset timers after each test that uses fake timers:

it("should fail if approval expired", async () => {
  vi.useFakeTimers();
  try {
    // ...test body...
  } finally {
    vi.useRealTimers();
  }
});

Comment on lines +237 to +240
it("should return false if request not found", () => {
const removed = service.rejectRequest("non-existent");
expect(removed).toBe(false);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test 'should return false if request not found' for rejectRequest does not assert that the audit log is not called when a non-existent request is rejected. This is important to ensure that no misleading audit entries are created for failed rejections.

Recommended solution:
Add an assertion to verify that mockAuditLog.record is not called in this scenario:

expect(mockAuditLog.record).not.toHaveBeenCalled();

Copy link

@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 introduces a comprehensive set of unit tests for the RemoteSigningService, covering critical paths like auto-signing, policy enforcement, human confirmation workflows, and error handling. The tests are well-structured and use mocks effectively. I have a couple of suggestions to enhance test determinism and clean up the test setup.

Comment on lines +14 to +24
function makeRequest(overrides: Partial<SigningRequest> = {}): SigningRequest {
return {
requestId: `req-${Date.now()}-${Math.random()}`,
chainId: 1,
to: "0x1234567890abcdef1234567890abcdef12345678",
value: "1000000000000000", // 0.001 ETH
data: "0x",
createdAt: Date.now(),
...overrides,
};
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve test determinism and make debugging easier, it's best to avoid Math.random() for generating test data like requestId. Using a simple counter is a more robust approach.

Note: You'll need to reset requestCounter = 0; inside your beforeEach block to ensure test isolation.

let requestCounter = 0;
function makeRequest(overrides: Partial<SigningRequest> = {}): SigningRequest {
  requestCounter++;
  return {
    requestId: `req-test-${requestCounter}`,
    chainId: 1,
    to: "0x1234567890abcdef1234567890abcdef12345678",
    value: "1000000000000000", // 0.001 ETH
    data: "0x",
    createdAt: Date.now(),
    ...overrides,
  };
}

Comment on lines +33 to +39
mockSigner = {
getAddress: vi.fn().mockResolvedValue("0xsigner"),
signMessage: vi.fn().mockResolvedValue("0xsignature"),
signTransaction: vi.fn().mockImplementation(async (tx: UnsignedTransaction) => {
return "0xsignedtx";
}),
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The signMessage method on the mock signer is defined but is not used in any of the tests for RemoteSigningService, as the service under test does not expose this functionality. This line can be removed to simplify the test setup and avoid confusion.

    mockSigner = {
      getAddress: vi.fn().mockResolvedValue("0xsigner"),
      signTransaction: vi.fn().mockImplementation(async (tx: UnsignedTransaction) => {
        return "0xsignedtx";
      }),
    };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant