Skip to content

fix(bitcoin): repair bitcoin-wallet-snap integration tests - #371

Merged
Battambang merged 2 commits into
mainfrom
fix/bitcoin-snap-integration-tests
Sep 25, 2026
Merged

Battambang merged 2 commits into
mainfrom
fix/bitcoin-snap-integration-tests

Conversation

@Battambang

@Battambang Battambang commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Explanation

The bitcoin-wallet-snap integration suite could not run at all from a fresh checkout — it failed before executing a single test. Three separate defects were stacked on top of each other:

  1. Wrong Jest config path. integration-test/run-integration.sh invoked jest --config jest.integration.config.js, but the file on disk is jest.integration.config.mjs. Jest aborted with Can't find a root directory while resolving a config file path and never discovered the test files.

  2. No transform configured. With the path corrected, the @metamask/snaps-jest preset fell back to babel-jest, which resolves @babel/preset-env — a package this repo does not depend on. Every test file failed to compile. This is why an explicit transform is required rather than optional.

  3. Stale keyring response assertions. keyring-request.test.ts still asserted the legacy v1 keyring envelope, { pending: false, result: <payload> }. Keyring requests now return the payload directly, so 11 toRespondWith assertions failed on shape and 2 response destructures double-unwrapped result.result.

The fixes are correspondingly narrow: correct the config filename, add transform: { '^.+\\.(t|j)sx?$': 'ts-jest' } to the config, and update the assertions to the current response shape.

Nothing here changes Snap behavior — it is test-harness only, which is why it does not need to touch another package.

References

  • Branch: fix/bitcoin-snap-integration-tests (based on main)
  • Run with: yarn workspace @metamask/bitcoin-wallet-snap run test:integration
  • Result: 4 suites passed, 53 tests passed, 7 skipped

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Repair the bitcoin-wallet-snap integration test suite, which could not
run at all from a fresh checkout.

- Point `run-integration.sh` at `jest.integration.config.mjs`. The
  script referenced `jest.integration.config.js`, which does not exist,
  so Jest failed to resolve a root directory before any test could run.
- Add a `ts-jest` transform to `jest.integration.config.mjs`. Without an
  explicit transform, the `@metamask/snaps-jest` preset falls back to
  `babel-jest`, which requires `@babel/preset-env` (not installed), so
  every test file failed to compile.
- Update `keyring-request.test.ts` to match the current keyring request
  response shape. Responses are no longer wrapped in the legacy
  `{ pending, result }` envelope, so 11 `toRespondWith` assertions were
  changed to expect the raw payload and 2 response destructures were
  unwrapped.

Verified with `yarn workspace @metamask/bitcoin-wallet-snap run
test:integration`: 4 suites passed, 53 tests passed, 7 skipped.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Correct the SignPsbt response assertion type.

Review effort: Lite
Findings: None

What changed in this PR

Repairs the Bitcoin wallet Snap integration-test harness and updates keyring assertions.

Changes:

  • Corrects the Jest config path.
  • Adds ts-jest transformation.
  • Updates assertions for direct keyring responses.
  • A SignPsbt assertion still uses the inaccurate FillPsbtResponse type.
File Summary
packages/​bitcoin-wallet-snap/​jest.integration.config.mjs Adds TypeScript transformation.
packages/​bitcoin-wallet-snap/​integration-test/​run-integration.sh Uses the correct Jest config path.
packages/​bitcoin-wallet-snap/​integration-test/​keyring-request.test.ts Updates response assertions and unwrapping.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

The `broadcasts a PSBT successfully` test issues `AccountCapability.SignPsbt`
but asserted its response as `FillPsbtResponse`, which only declares `psbt`.
The handler returns `SignPsbtResponse` (`psbt`, `txid`, optional
`canBeMalleable`), so the assertion named a type from a different capability.

Because this is a type assertion, TypeScript never verified it: the cast
compiles regardless, and the tests pass either way. Swapping it to
`SignPsbtResponse` restores the type accuracy that the assertion was meant to
provide.

Verified with `yarn workspace @metamask/bitcoin-wallet-snap run
test:integration` (4 suites passed, 53 tests passed, 7 skipped) and
`tsc --noEmit`.
@Battambang

Battambang commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Copilot review overview

🔵 Needs a closer look

Correct the SignPsbt response assertion type.

Fixed in commit fda2a4d

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The reviewed test-harness fixes address the stated integration failures with no unresolved issues.

Review effort: Lite
Findings: None

@sonarqubecloud

Copy link
Copy Markdown

@Battambang
Battambang added this pull request to the merge queue Sep 25, 2026
Merged via the queue into main with commit 73a62c8 Sep 25, 2026
56 checks passed
@Battambang
Battambang deleted the fix/bitcoin-snap-integration-tests branch September 25, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants