@@ -32,18 +32,19 @@ function getTxParamsFromExplanation(explanation: TransactionExplanation): {
3232
3333function describeParseTransactionWith (
3434 acidTest : utxolib . testutil . AcidTest ,
35- explanation : TransactionExplanation ,
3635 {
3736 label = 'default' ,
3837 txParams,
3938 expectedExplicitExternalSpendAmount,
4039 expectedImplicitExternalSpendAmount,
4140 } : {
4241 label ?: string ;
43- txParams : {
44- recipients : ITransactionRecipient [ ] ;
45- changeAddress ?: string ;
46- } ;
42+ txParams :
43+ | {
44+ recipients : ITransactionRecipient [ ] ;
45+ changeAddress ?: string ;
46+ }
47+ | 'inferFromExplanation' ;
4748 expectedExplicitExternalSpendAmount : bigint ;
4849 expectedImplicitExternalSpendAmount : bigint ;
4950 }
@@ -58,6 +59,18 @@ function describeParseTransactionWith(
5859 const coinName = getChainFromNetwork ( acidTest . network ) ;
5960 coin = getUtxoCoin ( coinName ) ;
6061
62+ // Create PSBT and explanation
63+ const psbt = acidTest . createPsbt ( ) ;
64+ const explanation = explainPsbt ( psbt , { pubs : acidTest . rootWalletKeys } , acidTest . network , {
65+ strict : true ,
66+ } ) ;
67+
68+ // Determine txParams
69+ const resolvedTxParams =
70+ txParams === 'inferFromExplanation' || txParams === undefined
71+ ? getTxParamsFromExplanation ( explanation )
72+ : txParams ;
73+
6174 // Create mock wallet
6275 mockWallet = sinon . createStubInstance ( Wallet ) ;
6376 mockWallet . id . returns ( 'test-wallet-id' ) ;
@@ -81,9 +94,9 @@ function describeParseTransactionWith(
8194
8295 refParsedTransaction = await parseTransaction ( coin , {
8396 wallet : mockWallet as unknown as UtxoWallet ,
84- txParams,
97+ txParams : resolvedTxParams ,
8598 txPrebuild : {
86- txHex : acidTest . createPsbt ( ) . toHex ( ) ,
99+ txHex : psbt . toHex ( ) ,
87100 } ,
88101 verification,
89102 } ) ;
@@ -132,21 +145,16 @@ function describeParseTransactionWith(
132145
133146describe ( 'parsePsbt' , function ( ) {
134147 utxolib . testutil . AcidTest . suite ( ) . forEach ( ( test ) => {
135- const psbt = test . createPsbt ( ) ;
136- const explanation : TransactionExplanation = explainPsbt ( psbt , { pubs : test . rootWalletKeys } , test . network , {
137- strict : true ,
138- } ) ;
139-
140148 // Default case: infer recipients from explanation
141- describeParseTransactionWith ( test , explanation , {
142- txParams : getTxParamsFromExplanation ( explanation ) ,
149+ describeParseTransactionWith ( test , {
150+ txParams : 'inferFromExplanation' ,
143151 expectedExplicitExternalSpendAmount : 2700n ,
144152 expectedImplicitExternalSpendAmount : 0n ,
145153 } ) ;
146154
147155 if ( test . network === utxolib . networks . bitcoin ) {
148156 // extended test suite for bitcoin
149- describeParseTransactionWith ( test , explanation , {
157+ describeParseTransactionWith ( test , {
150158 label : 'empty recipients' ,
151159 txParams : {
152160 recipients : [ ] ,
0 commit comments