@@ -19,6 +19,7 @@ import {
19
19
} from '@cardano-sdk/core' ;
20
20
import { HexBlob } from '@cardano-sdk/util' ;
21
21
import { InitializeTxProps } from '@cardano-sdk/tx-construction' ;
22
+ import { babbageTx } from '../../../core/test/Serialization/testData' ;
22
23
import { buildDRepIDFromDRepKey , toOutgoingTx , waitForWalletStateSettle } from '../util' ;
23
24
import { getPassphrase , stakeKeyDerivationPath , testAsyncKeyAgent } from '../../../key-management/test/mocks' ;
24
25
import { dummyLogger as logger } from 'ts-log' ;
@@ -534,6 +535,79 @@ describe('BaseWallet methods', () => {
534
535
} ) ;
535
536
} ) ;
536
537
538
+ describe ( 'addSignatures' , ( ) => {
539
+ it ( 'adds the signatures and preserves all previous witnesses' , async ( ) => {
540
+ const mockWitnesser = {
541
+ signData : jest . fn ( ) ,
542
+ witness : jest . fn ( ) . mockResolvedValue ( {
543
+ cbor : Serialization . Transaction . fromCore ( babbageTx ) . toCbor ( ) ,
544
+ context : {
545
+ handleResolutions : [ ]
546
+ } ,
547
+ tx : {
548
+ ...babbageTx ,
549
+ witness : {
550
+ ...babbageTx . witness ,
551
+ signatures : new Map ( [
552
+ ...babbageTx . witness . signatures . entries ( ) ,
553
+ [
554
+ '0000000000000000000000000000000000000000000000000000000000000000' ,
555
+ '0000000000000000000000000000000000000000000000000000000000000000'
556
+ ]
557
+ ] )
558
+ }
559
+ }
560
+ } )
561
+ } ;
562
+
563
+ wallet . shutdown ( ) ;
564
+ wallet = createPersonalWallet (
565
+ { name : 'Test Wallet' } ,
566
+ {
567
+ addressDiscovery,
568
+ assetProvider,
569
+ bip32Account,
570
+ chainHistoryProvider,
571
+ handleProvider,
572
+ logger,
573
+ networkInfoProvider,
574
+ rewardsProvider,
575
+ stakePoolProvider,
576
+ txSubmitProvider,
577
+ utxoProvider,
578
+ witnesser : mockWitnesser
579
+ }
580
+ ) ;
581
+
582
+ await waitForWalletStateSettle ( wallet ) ;
583
+
584
+ const serializedTx = Serialization . Transaction . fromCore ( babbageTx ) . toCbor ( ) ;
585
+ const tx = await wallet . addSignatures ( { tx : serializedTx } ) ;
586
+ const updatedTx = Serialization . Transaction . fromCbor ( tx ) . toCore ( ) ;
587
+
588
+ expect ( babbageTx . witness . bootstrap ) . toEqual ( updatedTx . witness . bootstrap ) ;
589
+ expect ( babbageTx . witness . datums ) . toEqual ( updatedTx . witness . datums ) ;
590
+ expect ( babbageTx . witness . redeemers ) . toEqual ( updatedTx . witness . redeemers ) ;
591
+ expect ( babbageTx . witness . scripts ) . toEqual ( updatedTx . witness . scripts ) ;
592
+
593
+ for ( const [ key , value ] of Object . entries ( babbageTx . witness . signatures ) ) {
594
+ expect ( value ) . toEqual ( updatedTx . witness . signatures . get ( key as Crypto . Ed25519PublicKeyHex ) ) ;
595
+ }
596
+
597
+ expect ( updatedTx . witness . signatures . size ) . toEqual ( babbageTx . witness . signatures . size + 1 ) ;
598
+ expect (
599
+ updatedTx . witness . signatures . get (
600
+ '0000000000000000000000000000000000000000000000000000000000000000' as Crypto . Ed25519PublicKeyHex
601
+ )
602
+ ) . toEqual ( '0000000000000000000000000000000000000000000000000000000000000000' ) ;
603
+
604
+ // signed$ emits transaction and all its witnesses
605
+ const signedTxs = await firstValueFrom ( wallet . transactions . outgoing . signed$ ) ;
606
+
607
+ expect ( signedTxs [ 0 ] . tx ) . toEqual ( updatedTx ) ;
608
+ } ) ;
609
+ } ) ;
610
+
537
611
// eslint-disable-next-line sonarjs/cognitive-complexity
538
612
describe ( 'getNextUnusedAddress' , ( ) => {
539
613
const script : Cardano . NativeScript = {
0 commit comments