Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove bailout behavior from missing sig func #2006

Merged
merged 8 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(', '));
}
}