@@ -229,6 +229,18 @@ describe('BaseWallet methods', () => {
229229 } ) ;
230230
231231 describe ( 'finalizeTx' , ( ) => {
232+ let witnessSpy : jest . SpyInstance ;
233+
234+ beforeEach ( ( ) => {
235+ witnessSpy = jest . spyOn ( witnesser , 'witness' ) ;
236+ } ) ;
237+
238+ afterEach ( ( ) => {
239+ witnessSpy . mockClear ( ) ;
240+ witnessSpy . mockReset ( ) ;
241+ witnessSpy . mockRestore ( ) ;
242+ } ) ;
243+
232244 it ( 'resolves with TransactionWitnessSet' , async ( ) => {
233245 const txInternals = await wallet . initializeTx ( props ) ;
234246 const unhydratedTxBody = Serialization . TransactionBody . fromCore ( txInternals . body ) . toCore ( ) ;
@@ -241,24 +253,50 @@ describe('BaseWallet methods', () => {
241253
242254 it ( 'passes through sender to witnesser' , async ( ) => {
243255 const sender = { url : 'https://lace.io' } ;
244- const witnessSpy = jest . spyOn ( witnesser , 'witness' ) ;
245256 const txInternals = await wallet . initializeTx ( props ) ;
246- await wallet . finalizeTx ( { signingContext : { sender } , tx : txInternals } ) ;
247257
258+ // Reset witness calls from wallet.initializeTx
259+ witnessSpy . mockClear ( ) ;
260+
261+ await wallet . finalizeTx ( { signingContext : { sender } , tx : txInternals } ) ;
262+ expect ( witnessSpy ) . toHaveBeenCalledTimes ( 1 ) ;
248263 expect ( witnessSpy ) . toBeCalledWith ( expect . anything ( ) , expect . objectContaining ( { sender } ) , void 0 ) ;
249264 } ) ;
250265
251266 it ( 'uses the original CBOR to create the serializable transaction if given' , async ( ) => {
252267 const sender = { url : 'https://lace.io' } ;
253- const witnessSpy = jest . spyOn ( witnesser , 'witness' ) ;
254268 const txInternals = await wallet . initializeTx ( props ) ;
269+
270+ // Reset witness calls from wallet.initializeTx
271+ witnessSpy . mockClear ( ) ;
272+
255273 await wallet . finalizeTx ( {
274+ auxiliaryData : geniusYieldTx . auxiliaryData ( ) ?. toCore ( ) ,
256275 bodyCbor : geniusYieldTx . body ( ) . toCbor ( ) ,
257276 signingContext : { sender } ,
258- tx : txInternals
277+ tx : txInternals ,
278+ witness : geniusYieldTx . witnessSet ( ) ?. toCore ( )
279+ } ) ;
280+
281+ expect ( witnessSpy ) . toHaveBeenCalledTimes ( 1 ) ;
282+ const tx : Serialization . Transaction = witnessSpy . mock . calls [ 0 ] [ 0 ] ;
283+ expect ( tx . body ( ) . toCbor ( ) ) . toEqual ( geniusYieldTx . body ( ) . toCbor ( ) ) ;
284+ // The transaction CBOR will not match due to reencoding witnessSet and auxiliaryData
285+ // expect(tx.toCbor()).toEqual(geniusYieldTx.toCbor());
286+ } ) ;
287+
288+ it ( 'uses the complete transaction CBOR, ignoring auxiliaryData, witness and isValid' , async ( ) => {
289+ const sender = { url : 'https://lace.io' } ;
290+ await wallet . finalizeTx ( {
291+ auxiliaryData : 'ignored auxiliary data' as Cardano . AuxiliaryData ,
292+ signingContext : { sender } ,
293+ tx : geniusYieldTx . toCbor ( ) ,
294+ witness : 'ignored witness set' as Partial < Cardano . Witness >
259295 } ) ;
260296
261- expect ( witnessSpy ) . toBeCalledWith ( geniusYieldTx , expect . objectContaining ( { sender } ) , void 0 ) ;
297+ expect ( witnessSpy ) . toHaveBeenCalledTimes ( 1 ) ;
298+ const tx : Serialization . Transaction = witnessSpy . mock . calls [ 0 ] [ 0 ] ;
299+ expect ( tx . toCbor ( ) ) . toEqual ( geniusYieldTx . toCbor ( ) ) ;
262300 } ) ;
263301 } ) ;
264302
0 commit comments