From 3836a835144a574f44cd382e07a8740e173c12df Mon Sep 17 00:00:00 2001 From: Frederic HENG Date: Fri, 25 Sep 2026 11:42:39 +0200 Subject: [PATCH 1/2] fix(bitcoin): repair bitcoin-wallet-snap integration tests 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. --- .../integration-test/keyring-request.test.ts | 101 ++++++------------ .../integration-test/run-integration.sh | 2 +- .../jest.integration.config.mjs | 3 + 3 files changed, 37 insertions(+), 69 deletions(-) diff --git a/packages/bitcoin-wallet-snap/integration-test/keyring-request.test.ts b/packages/bitcoin-wallet-snap/integration-test/keyring-request.test.ts index b698dbe56..c91bd31cc 100644 --- a/packages/bitcoin-wallet-snap/integration-test/keyring-request.test.ts +++ b/packages/bitcoin-wallet-snap/integration-test/keyring-request.test.ts @@ -132,24 +132,20 @@ describe('KeyringRequestHandler', () => { } as KeyringRequest, }); - expect(response).toRespondWith({ - pending: false, - result: [ - { - address: 'bcrt1qs2fj7czz0amfm74j73yujx6dn6223md56gkkuy', - derivationIndex: 0, - outpoint: expect.any(String), - scriptPubkey: - 'OP_0 OP_PUSHBYTES_20 82932f60427f769dfab2f449c91b4d9e94a8edb4', - scriptPubkeyHex: '001482932f60427f769dfab2f449c91b4d9e94a8edb4', - value: '1000000000', - }, - ], - }); + expect(response).toRespondWith([ + { + address: 'bcrt1qs2fj7czz0amfm74j73yujx6dn6223md56gkkuy', + derivationIndex: 0, + outpoint: expect.any(String), + scriptPubkey: + 'OP_0 OP_PUSHBYTES_20 82932f60427f769dfab2f449c91b4d9e94a8edb4', + scriptPubkeyHex: '001482932f60427f769dfab2f449c91b4d9e94a8edb4', + value: '1000000000', + }, + ]); - const utxos = ( - response.response as { result: { result: { outpoint: string }[] } } - ).result.result; + const utxos = (response.response as { result: { outpoint: string }[] }) + .result; response = await snap.onKeyringRequest({ origin: ORIGIN, @@ -169,10 +165,7 @@ describe('KeyringRequestHandler', () => { } as KeyringRequest, }); - expect(response).toRespondWith({ - pending: false, - result: utxos[0], - }); + expect(response).toRespondWith(utxos[0]); }); it('publicDescriptor', async () => { @@ -190,11 +183,9 @@ describe('KeyringRequestHandler', () => { } as KeyringRequest, }); - expect(response).toRespondWith({ - pending: false, - result: - "wpkh([27f9035f/84'/1'/0']tpubDCkv2fHDfPg5ok9EPv6CDozH72rvY2jgEPm79szMeBwCBwUf2T6n5nLrWFfhuuD48SgzrELezoiyDM9KbZaVen4wuuGwrqQANDhzB7E8yDh/0/*)#sx899xk6", - }); + expect(response).toRespondWith( + "wpkh([27f9035f/84'/1'/0']tpubDCkv2fHDfPg5ok9EPv6CDozH72rvY2jgEPm79szMeBwCBwUf2T6n5nLrWFfhuuD48SgzrELezoiyDM9KbZaVen4wuuGwrqQANDhzB7E8yDh/0/*)#sx899xk6", + ); }); }); @@ -236,11 +227,8 @@ describe('KeyringRequestHandler', () => { const result = await response; expect(result).toRespondWith({ - pending: false, - result: { - psbt: SIGNED_PSBT, - txid: null, - }, + psbt: SIGNED_PSBT, + txid: null, }); }); @@ -275,11 +263,8 @@ describe('KeyringRequestHandler', () => { const result = await response; expect(result).toRespondWith({ - pending: false, - result: { - psbt: expect.any(String), // non deterministic - txid: null, - }, + psbt: expect.any(String), // non deterministic + txid: null, }); }); @@ -314,12 +299,9 @@ describe('KeyringRequestHandler', () => { const result = await response; expect(result).toRespondWith({ - pending: false, - result: { - psbt: expect.any(String), // non deterministic - txid: expect.any(String), - canBeMalleable: false, - }, + psbt: expect.any(String), // non deterministic + txid: expect.any(String), + canBeMalleable: false, }); // Regression for issue #597: after broadcasting a partial-spend tx @@ -466,10 +448,7 @@ describe('KeyringRequestHandler', () => { }); expect(response).toRespondWith({ - pending: false, - result: { - psbt: expect.any(String), // non deterministic - }, + psbt: expect.any(String), // non deterministic }); }); @@ -526,10 +505,7 @@ describe('KeyringRequestHandler', () => { }); expect(response).toRespondWith({ - pending: false, - result: { - fee: '632', - }, + fee: '632', }); }); @@ -596,9 +572,7 @@ describe('KeyringRequestHandler', () => { const signResult = await signResponse; - const { result } = ( - signResult.response as { result: { result: FillPsbtResponse } } - ).result; + const { result } = signResult.response as { result: FillPsbtResponse }; const response = await snap.onKeyringRequest({ origin: ORIGIN, @@ -619,11 +593,8 @@ describe('KeyringRequestHandler', () => { }); expect(response).toRespondWith({ - pending: false, - result: { - txid: expect.any(String), - canBeMalleable: false, - }, + txid: expect.any(String), + canBeMalleable: false, }); }); @@ -687,11 +658,8 @@ describe('KeyringRequestHandler', () => { const result = await response; expect(result).toRespondWith({ - pending: false, - result: { - txid: expect.any(String), - canBeMalleable: false, - }, + txid: expect.any(String), + canBeMalleable: false, }); }); @@ -749,11 +717,8 @@ describe('KeyringRequestHandler', () => { const result = await response; expect(result).toRespondWith({ - pending: false, - result: { - signature: - 'AkcwRAIgZxodJQ60t9Rr/hABEHZ1zPUJ4m5hdM5QLpysH8fDSzgCIENOEuZtYf9/Nn/ZW15PcImkknol403dmZrgoOQ+6K+TASECwDKypXm/ElmVTxTLJ7nao6X5mB/iGbU2Q2qtot0QRL4=', - }, + signature: + 'AkcwRAIgZxodJQ60t9Rr/hABEHZ1zPUJ4m5hdM5QLpysH8fDSzgCIENOEuZtYf9/Nn/ZW15PcImkknol403dmZrgoOQ+6K+TASECwDKypXm/ElmVTxTLJ7nao6X5mB/iGbU2Q2qtot0QRL4=', }); }); }); diff --git a/packages/bitcoin-wallet-snap/integration-test/run-integration.sh b/packages/bitcoin-wallet-snap/integration-test/run-integration.sh index 1fcd07f35..629bd26dd 100755 --- a/packages/bitcoin-wallet-snap/integration-test/run-integration.sh +++ b/packages/bitcoin-wallet-snap/integration-test/run-integration.sh @@ -30,7 +30,7 @@ docker exec esplora bash /init-esplora.sh echo "Running integration tests..." set +e -jest --config jest.integration.config.js +jest --config jest.integration.config.mjs TEST_EXIT_CODE=$? set -e exit $TEST_EXIT_CODE diff --git a/packages/bitcoin-wallet-snap/jest.integration.config.mjs b/packages/bitcoin-wallet-snap/jest.integration.config.mjs index c36c839e2..e42012c10 100644 --- a/packages/bitcoin-wallet-snap/jest.integration.config.mjs +++ b/packages/bitcoin-wallet-snap/jest.integration.config.mjs @@ -4,6 +4,9 @@ */ const config = { preset: '@metamask/snaps-jest', + transform: { + '^.+\\.(t|j)sx?$': 'ts-jest', + }, testMatch: ['**/integration-test/**/*.test.ts'], }; From fda2a4d607f9e6bc6c1b99c8ef22b8c109de081f Mon Sep 17 00:00:00 2001 From: Frederic HENG Date: Fri, 25 Sep 2026 12:01:22 +0200 Subject: [PATCH 2/2] fix(bitcoin): correct SignPsbt response type in integration test 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`. --- .../integration-test/keyring-request.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/bitcoin-wallet-snap/integration-test/keyring-request.test.ts b/packages/bitcoin-wallet-snap/integration-test/keyring-request.test.ts index c91bd31cc..cd6401884 100644 --- a/packages/bitcoin-wallet-snap/integration-test/keyring-request.test.ts +++ b/packages/bitcoin-wallet-snap/integration-test/keyring-request.test.ts @@ -5,7 +5,7 @@ import { assertIsConfirmationDialog, installSnap } from '@metamask/snaps-jest'; import { AccountCapability } from '../src/entities'; import { Caip19Asset } from '../src/handlers/caip'; -import type { FillPsbtResponse } from '../src/handlers/KeyringRequestHandler'; +import type { SignPsbtResponse } from '../src/handlers/KeyringRequestHandler'; import { BlockchainTestUtils } from './blockchain-utils'; import { MNEMONIC, ORIGIN } from './constants'; @@ -572,7 +572,7 @@ describe('KeyringRequestHandler', () => { const signResult = await signResponse; - const { result } = signResult.response as { result: FillPsbtResponse }; + const { result } = signResult.response as { result: SignPsbtResponse }; const response = await snap.onKeyringRequest({ origin: ORIGIN,