11import * as utxolib from "@bitgo/utxo-lib" ;
22import * as assert from "node:assert" ;
3- import { getPsbtFixtures } from "./psbtFixtures" ;
3+ import { getPsbtFixtures , PsbtStage } from "./psbtFixtures" ;
44import { Descriptor , Psbt } from "../js" ;
55
66import { getDescriptorForScriptType } from "./descriptorUtil" ;
7- import { toUtxoPsbt , toWrappedPsbt , updateInputWithDescriptor } from "./psbt.util" ;
7+ import { assertEqualPsbt , toUtxoPsbt , toWrappedPsbt , updateInputWithDescriptor } from "./psbt.util" ;
88
99const rootWalletKeys = new utxolib . bitgo . RootWalletKeys ( utxolib . testutil . getKeyTriple ( "wasm" ) ) ;
1010
@@ -14,15 +14,26 @@ function assertEqualBuffer(a: Buffer | Uint8Array, b: Buffer | Uint8Array, messa
1414
1515const fixtures = getPsbtFixtures ( rootWalletKeys ) ;
1616
17+ function getWasmDescriptor (
18+ scriptType : utxolib . bitgo . outputScripts . ScriptType2Of3 ,
19+ scope : "internal" | "external" ,
20+ ) {
21+ return Descriptor . fromString (
22+ getDescriptorForScriptType ( rootWalletKeys , scriptType , scope ) ,
23+ "derivable" ,
24+ ) ;
25+ }
26+
1727function describeUpdateInputWithDescriptor (
1828 psbt : utxolib . bitgo . UtxoPsbt ,
1929 scriptType : utxolib . bitgo . outputScripts . ScriptType2Of3 ,
2030) {
21- const fullSignedFixture = fixtures . find (
22- ( f ) => f . scriptType === scriptType && f . stage === "fullsigned" ,
23- ) ;
24- if ( ! fullSignedFixture ) {
25- throw new Error ( "Could not find fullsigned fixture" ) ;
31+ function getFixtureAtStage ( stage : PsbtStage ) {
32+ const f = fixtures . find ( ( f ) => f . scriptType === scriptType && f . stage === stage ) ;
33+ if ( ! f ) {
34+ throw new Error ( `Could not find fixture for scriptType ${ scriptType } and stage ${ stage } ` ) ;
35+ }
36+ return f ;
2637 }
2738
2839 const descriptorStr = getDescriptorForScriptType ( rootWalletKeys , scriptType , "internal" ) ;
@@ -33,7 +44,9 @@ function describeUpdateInputWithDescriptor(
3344 it ( "should update the input with the descriptor" , function ( ) {
3445 const wrappedPsbt = toWrappedPsbt ( psbt ) ;
3546 wrappedPsbt . updateInputWithDescriptor ( 0 , descriptor . atDerivationIndex ( index ) ) ;
47+ wrappedPsbt . updateOutputWithDescriptor ( 0 , descriptor . atDerivationIndex ( index ) ) ;
3648 const updatedPsbt = toUtxoPsbt ( wrappedPsbt ) ;
49+ assertEqualPsbt ( updatedPsbt , getFixtureAtStage ( "unsigned" ) . psbt ) ;
3750 updatedPsbt . signAllInputsHD ( rootWalletKeys . triple [ 0 ] ) ;
3851 updatedPsbt . signAllInputsHD ( rootWalletKeys . triple [ 2 ] ) ;
3952 const wrappedSignedPsbt = toWrappedPsbt ( updatedPsbt ) ;
@@ -43,7 +56,11 @@ function describeUpdateInputWithDescriptor(
4356 assertEqualBuffer ( updatedPsbt . toBuffer ( ) , wrappedSignedPsbt . serialize ( ) ) ;
4457
4558 assertEqualBuffer (
46- fullSignedFixture . psbt . clone ( ) . finalizeAllInputs ( ) . extractTransaction ( ) . toBuffer ( ) ,
59+ getFixtureAtStage ( "fullsigned" )
60+ . psbt . clone ( )
61+ . finalizeAllInputs ( )
62+ . extractTransaction ( )
63+ . toBuffer ( ) ,
4764 updatedPsbt . extractTransaction ( ) . toBuffer ( ) ,
4865 ) ;
4966 } ) ;
@@ -58,7 +75,11 @@ function describeUpdateInputWithDescriptor(
5875 cloned . finalizeAllInputs ( ) ;
5976
6077 assertEqualBuffer (
61- fullSignedFixture . psbt . clone ( ) . finalizeAllInputs ( ) . extractTransaction ( ) . toBuffer ( ) ,
78+ getFixtureAtStage ( "fullsigned" )
79+ . psbt . clone ( )
80+ . finalizeAllInputs ( )
81+ . extractTransaction ( )
82+ . toBuffer ( ) ,
6283 cloned . extractTransaction ( ) . toBuffer ( ) ,
6384 ) ;
6485 } ) ;
0 commit comments