Skip to content

Commit 6d0f574

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): test signPsbtWithMusig2Participant
Replace signAndVerifyPsbt test with signPsbtWithMusig2Participant test to verify that this function works with a mock Musig2Participant. Issue: BTC-2806 Co-authored-by: llm-git <llm-git@ttll.de>
1 parent c666d1f commit 6d0f574

File tree

1 file changed

+16
-11
lines changed
  • modules/abstract-utxo/test/unit/transaction/fixedScript

1 file changed

+16
-11
lines changed

modules/abstract-utxo/test/unit/transaction/fixedScript/signPsbt.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,27 @@ import assert from 'node:assert/strict';
22

33
import * as utxolib from '@bitgo/utxo-lib';
44

5-
import { signAndVerifyPsbt } from '../../../../src/transaction/fixedScript/signPsbt';
5+
import { Musig2Participant, signPsbtWithMusig2Participant } from '../../../../src/transaction/fixedScript/signPsbt';
66

7-
function describeSignAndVerifyPsbt(acidTest: utxolib.testutil.AcidTest) {
7+
function describeSignPsbtWithMusig2Participant(acidTest: utxolib.testutil.AcidTest) {
88
describe(`${acidTest.name}`, function () {
9-
it('should sign unsigned psbt to halfsigned', function () {
9+
it('should sign unsigned psbt to halfsigned', async function () {
1010
// Create unsigned PSBT
1111
const psbt = acidTest.createPsbt();
1212

13-
// Set musig2 nonces for taproot inputs before signing
14-
const sessionId = Buffer.alloc(32);
15-
psbt.setAllInputsMusig2NonceHD(acidTest.rootWalletKeys.user, { sessionId });
16-
psbt.setAllInputsMusig2NonceHD(acidTest.rootWalletKeys.bitgo, { deterministic: true });
13+
// Create mock Musig2Participant that sets BitGo nonces
14+
const mockCoin: Musig2Participant = {
15+
async getMusig2Nonces(psbt: utxolib.bitgo.UtxoPsbt, walletId: string): Promise<utxolib.bitgo.UtxoPsbt> {
16+
psbt.setAllInputsMusig2NonceHD(acidTest.rootWalletKeys.bitgo, { deterministic: true });
17+
return psbt;
18+
},
19+
};
1720

18-
// Sign with user key
19-
const result = signAndVerifyPsbt(psbt, acidTest.rootWalletKeys.user, {
21+
// Sign with user key through signPsbtWithMusig2Participant
22+
const result = await signPsbtWithMusig2Participant(mockCoin, psbt, acidTest.rootWalletKeys.user, {
2023
isLastSignature: false,
24+
signingStep: undefined,
25+
walletId: 'test-wallet-id',
2126
});
2227

2328
// Result should be a PSBT (not finalized)
@@ -40,13 +45,13 @@ function describeSignAndVerifyPsbt(acidTest: utxolib.testutil.AcidTest) {
4045
});
4146
}
4247

43-
describe('signAndVerifyPsbt', function () {
48+
describe('signPsbtWithMusig2Participant', function () {
4449
// Create test suite with includeP2trMusig2ScriptPath set to false
4550
// p2trMusig2 script path inputs are signed by user and backup keys,
4651
// which is not the typical signing pattern and makes testing more complex
4752
utxolib.testutil.AcidTest.suite({ includeP2trMusig2ScriptPath: false })
4853
.filter((test) => test.signStage === 'unsigned')
4954
.forEach((test) => {
50-
describeSignAndVerifyPsbt(test);
55+
describeSignPsbtWithMusig2Participant(test);
5156
});
5257
});

0 commit comments

Comments
 (0)