Skip to content

Commit

Permalink
feat: Remove bailout behavior from missing sig func (#2006)
Browse files Browse the repository at this point in the history
* remove bailout behavior from missing sig func

* format

* add type dec

* fix test

* Update packages/transactions/src/signatures.ts

* adapt tests

* style

* fix test in signers
  • Loading branch information
cryptopapi997 authored Jan 10, 2024
1 parent b5bbd3a commit 6b33c7e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/signers/src/__tests__/sign-transaction-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ describe('signTransactionWithSigners', () => {

// Then we expect an error letting us know the transaction is not fully signed.
// This is because sending signers are ignored by signTransactionWithSigners.
await expect(promise).rejects.toThrow('Transaction is missing signature for address `2222`');
await expect(promise).rejects.toThrow('Transaction is missing signatures for addresses: 2222');
});

it('can be cancelled using an AbortSignal', async () => {
Expand Down
29 changes: 24 additions & 5 deletions packages/transactions/src/__tests__/signatures-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ describe('signTransaction', () => {
expect.assertions(1);
const signedTransactionPromise = signTransaction([mockKeyPairA], MOCK_TRANSACTION);
await expect(signedTransactionPromise).rejects.toThrow(
`Transaction is missing signature for address \`${mockPublicKeyAddressB}\``,
`Transaction is missing signatures for addresses: ${mockPublicKeyAddressB}`,
);
});
it('returns a transaction object having multiple signatures', async () => {
Expand Down Expand Up @@ -368,7 +368,26 @@ describe('assertTransactionIsFullySigned', () => {
};

expect(() => assertTransactionIsFullySigned(transaction)).toThrow(
'Transaction is missing signature for address `A`',
'Transaction is missing signatures for addresses: A',
);
});

it('throws all missing signers if the transaction has no signature for multiple signers', () => {
const transaction: SignedTransaction = {
feePayer: mockPublicKeyAddressA,
instructions: [
{
accounts: [{ address: mockPublicKeyAddressB, role: AccountRole.READONLY_SIGNER }],
programAddress: '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>,
},
],
lifetimeConstraint: mockBlockhashConstraint,
signatures: {},
version: 0,
};

expect(() => assertTransactionIsFullySigned(transaction)).toThrow(
'Transaction is missing signatures for addresses: A, B',
);
});

Expand All @@ -394,7 +413,7 @@ describe('assertTransactionIsFullySigned', () => {
};

expect(() => assertTransactionIsFullySigned(transaction)).toThrow(
'Transaction is missing signature for address `B`',
'Transaction is missing signatures for addresses: B',
);
});

Expand All @@ -420,7 +439,7 @@ describe('assertTransactionIsFullySigned', () => {
};

expect(() => assertTransactionIsFullySigned(transaction)).toThrow(
'Transaction is missing signature for address `B`',
'Transaction is missing signatures for addresses: B',
);
});

Expand Down Expand Up @@ -456,7 +475,7 @@ describe('assertTransactionIsFullySigned', () => {
};

expect(() => assertTransactionIsFullySigned(transaction)).toThrow(
'Transaction is missing signature for address `C`',
'Transaction is missing signatures for addresses: C',
);
});

Expand Down
9 changes: 7 additions & 2 deletions packages/transactions/src/signatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,15 @@ export function assertTransactionIsFullySigned<TTransaction extends CompilableTr
.map(a => a.address);
const requiredSigners = new Set([transaction.feePayer, ...signerAddressesFromInstructions]);

const missingSigs: Address[] = [];
requiredSigners.forEach(address => {
if (!transaction.signatures[address]) {
// TODO coded error
throw new Error(`Transaction is missing signature for address \`${address}\``);
missingSigs.push(address);
}
});

if (missingSigs.length > 0) {
// TODO coded error
throw new Error('Transaction is missing signatures for addresses: ' + missingSigs.join(', '));
}
}

0 comments on commit 6b33c7e

Please sign in to comment.