Skip to content

Commit 892c1e9

Browse files
fixup! feat!: replace updateWitness with addSignatures in observable wallet
1 parent 79a721a commit 892c1e9

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

packages/wallet/test/PersonalWallet/methods.test.ts

+74
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from '@cardano-sdk/core';
2020
import { HexBlob } from '@cardano-sdk/util';
2121
import { InitializeTxProps } from '@cardano-sdk/tx-construction';
22+
import { babbageTx } from '../../../core/test/Serialization/testData';
2223
import { buildDRepIDFromDRepKey, toOutgoingTx, waitForWalletStateSettle } from '../util';
2324
import { getPassphrase, stakeKeyDerivationPath, testAsyncKeyAgent } from '../../../key-management/test/mocks';
2425
import { dummyLogger as logger } from 'ts-log';
@@ -534,6 +535,79 @@ describe('BaseWallet methods', () => {
534535
});
535536
});
536537

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+
537611
// eslint-disable-next-line sonarjs/cognitive-complexity
538612
describe('getNextUnusedAddress', () => {
539613
const script: Cardano.NativeScript = {

0 commit comments

Comments
 (0)