Skip to content

Commit

Permalink
Update @solana/eslint-config-solana and repair all the unresolved p…
Browse files Browse the repository at this point in the history
…romise lint errors (#3361)

# Summary

In this PR we get strict about creating promises that are resolved neither through `await` nor `then()` nor `catch()`. This new lint rule actually found some bugs that we were able to fix in PRs earlier in the stack.

You might be thinking, ‘are you serious, a `catch()` in every test where I don't care about the result?’ This will actually help make test failures more clear because {the thing you're actually testing} will no longer be accompanied by {unhandled rejection}.
  • Loading branch information
steveluscher authored Oct 11, 2024
1 parent 50e98f5 commit 441fa3a
Show file tree
Hide file tree
Showing 67 changed files with 380 additions and 337 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-shrimps-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@solana/assertions': patch
---

Fixed a bug where calls to `isEd25519CurveSupported()` might have resulted in uncaught rejections bubbling up through the app, in cases where Ed25519 is not supported
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export function SolanaSignAndSendTransactionFeaturePanel({ account }: Props) {
);
assertIsTransactionMessageWithSingleSendingSigner(message);
const signature = await signAndSendTransactionMessageWithSigners(message);
mutate({ address: transactionSendingSigner.address, chain: currentChain });
mutate({ address: recipientAccount.address, chain: currentChain });
void mutate({ address: transactionSendingSigner.address, chain: currentChain });
void mutate({ address: recipientAccount.address, chain: currentChain });
setLastSignature(signature);
setSolQuantityString('');
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.9",
"@solana/build-scripts": "workspace:*",
"@solana/eslint-config-solana": "^3.0.5",
"@solana/eslint-config-solana": "^3.0.6",
"@solana/prettier-config-solana": "0.0.5",
"@solana/test-config": "workspace:*",
"@solana/test-matchers": "workspace:*",
Expand Down
2 changes: 2 additions & 0 deletions packages/accounts/src/__typetests__/fetch-account-typetest.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-floating-promises */

import type { Address } from '@solana/addresses';
import type { Rpc } from '@solana/rpc-spec';

Expand Down
6 changes: 3 additions & 3 deletions packages/assertions/src/subtle-crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ async function isEd25519CurveSupported(subtle: SubtleCrypto): Promise<boolean> {
cachedEd25519Decision = new Promise(resolve => {
subtle
.generateKey('Ed25519', /* extractable */ false, ['sign', 'verify'])
.catch(() => {
resolve((cachedEd25519Decision = false));
})
.then(() => {
resolve((cachedEd25519Decision = true));
})
.catch(() => {
resolve((cachedEd25519Decision = false));
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/codecs-core/src/__benchmarks__/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bench
{ beforeEach: randomizeBytes },
);

(async () => {
void (async () => {
await bench.warmup();
await bench.run();

Expand Down
2 changes: 1 addition & 1 deletion packages/codecs-strings/src/__benchmarks__/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bench
},
);

(async () => {
void (async () => {
await bench.warmup();
await bench.run();

Expand Down
2 changes: 1 addition & 1 deletion packages/fetch-impl/src/__benchmarks__/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bench
beforeEach: createDispatcher.bind(null, { connections: 64, pipelining: 2 }),
});

(async () => {
void (async () => {
await bench.run();

console.table(bench.table());
Expand Down
2 changes: 1 addition & 1 deletion packages/keys/src/__benchmarks__/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bench
},
});

(async () => {
void (async () => {
await bench.run();
console.table(bench.table());
})();
1 change: 1 addition & 0 deletions packages/keys/src/__typetests__/key-pair-typetests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import { ReadonlyUint8Array } from '@solana/codecs-core';

import { createKeyPairFromBytes, createKeyPairFromPrivateKeyBytes } from '../key-pair';
Expand Down
1 change: 1 addition & 0 deletions packages/keys/src/__typetests__/private-key-typetests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import { ReadonlyUint8Array } from '@solana/codecs-core';

import { createPrivateKeyFromBytes } from '../private-key';
Expand Down
1 change: 1 addition & 0 deletions packages/keys/src/__typetests__/public-key-typetests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import { getPublicKeyFromPrivateKey } from '../public-key';

getPublicKeyFromPrivateKey(new CryptoKey()) satisfies Promise<CryptoKey>;
Expand Down
8 changes: 4 additions & 4 deletions packages/library/src/__tests__/airdrop-internal-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('requestAndConfirmAirdrop', () => {
lamports: lamports(1n),
recipientAddress: '123' as Address,
rpc,
});
}).catch(() => {});
expect(sendAirdropRequest).toHaveBeenCalledWith({
abortSignal: expect.objectContaining({ aborted: false }),
});
Expand All @@ -53,7 +53,7 @@ describe('requestAndConfirmAirdrop', () => {
lamports: lamports(1n),
recipientAddress: '123' as Address,
rpc,
});
}).catch(() => {});
await jest.runAllTimersAsync();
expect(confirmSignatureOnlyTransaction).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -76,7 +76,7 @@ describe('requestAndConfirmAirdrop', () => {
lamports: lamports(1n),
recipientAddress: '123' as Address,
rpc,
});
}).catch(() => {});
expect(requestAirdrop).toHaveBeenCalledWith('123', 1n, { commitment: 'finalized' });
});
it('passes the expected input to the transaction confirmer', async () => {
Expand All @@ -89,7 +89,7 @@ describe('requestAndConfirmAirdrop', () => {
lamports: lamports(1n),
recipientAddress: '123' as Address,
rpc,
});
}).catch(() => {});
await jest.runAllTimersAsync();
expect(confirmSignatureOnlyTransaction).toHaveBeenCalledWith({
abortSignal: expect.any(AbortSignal),
Expand Down
14 changes: 7 additions & 7 deletions packages/library/src/__tests__/compute-limit-internal-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPOR
...mockTransactionMessage,
lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT,
},
});
}).catch(() => {});
expect(sendSimulateTransactionRequest).toHaveBeenCalledWith({
abortSignal: expect.objectContaining({ aborted: false }),
});
Expand All @@ -66,7 +66,7 @@ describe('getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPOR
minContextSlot: 42n,
rpc,
transactionMessage,
});
}).catch(() => {});
expect(simulateTransaction).toHaveBeenCalledWith(
expect.any(String),
expect.objectContaining({
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPOR
getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({
rpc,
transactionMessage,
});
}).catch(() => {});
expect(compileTransaction).toHaveBeenCalledWith({
...transactionMessage,
instructions: [
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPOR
getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({
rpc,
transactionMessage,
});
}).catch(() => {});
expect(compileTransaction).toHaveBeenCalledWith(
expect.objectContaining({
instructions: [
Expand Down Expand Up @@ -196,7 +196,7 @@ describe('getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPOR
nonce: 'BzAqD6382v5r1pcELoi8HWrBDV4dSL9NGemMn2JYAhxc' as Nonce,
},
},
});
}).catch(() => {});
expect(simulateTransaction).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ replaceRecentBlockhash: false }),
Expand All @@ -209,7 +209,7 @@ describe('getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPOR
...mockTransactionMessage,
lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT,
},
});
}).catch(() => {});
expect(simulateTransaction).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ replaceRecentBlockhash: true }),
Expand All @@ -219,7 +219,7 @@ describe('getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPOR
getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({
rpc,
transactionMessage: mockTransactionMessage,
});
}).catch(() => {});
expect(simulateTransaction).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ replaceRecentBlockhash: true }),
Expand Down
24 changes: 12 additions & 12 deletions packages/library/src/__tests__/send-transaction-internal-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('sendAndConfirmTransaction', () => {
confirmRecentTransaction,
rpc,
transaction: MOCK_TRANSACTION,
});
}).catch(() => {});
expect(getBase64EncodedWireTransaction).toHaveBeenCalledWith(MOCK_TRANSACTION);
expect(createPendingRequest).toHaveBeenCalledWith('MOCK_WIRE_TRANSACTION', expect.anything());
});
Expand All @@ -63,7 +63,7 @@ describe('sendAndConfirmTransaction', () => {
confirmRecentTransaction,
rpc,
transaction: MOCK_TRANSACTION,
});
}).catch(() => {});
expect(getBase64EncodedWireTransaction).toHaveBeenCalledWith(MOCK_TRANSACTION);
expect(createPendingRequest).toHaveBeenCalledWith('MOCK_WIRE_TRANSACTION', {
...sendTransactionConfig,
Expand All @@ -87,7 +87,7 @@ describe('sendAndConfirmTransaction', () => {
confirmRecentTransaction,
rpc,
transaction: MOCK_TRANSACTION,
});
}).catch(() => {});
await jest.runAllTimersAsync();
expect(confirmRecentTransaction).toHaveBeenCalledWith({
abortSignal,
Expand All @@ -108,7 +108,7 @@ describe('sendAndConfirmTransaction', () => {
confirmRecentTransaction,
rpc,
transaction: MOCK_TRANSACTION,
});
}).catch(() => {});
expect(createPendingRequest).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('sendAndConfirmTransaction', () => {
preflightCommitment,
rpc,
transaction: MOCK_TRANSACTION,
});
}).catch(() => {});
expect(createPendingRequest).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
Expand All @@ -155,7 +155,7 @@ describe('sendAndConfirmTransaction', () => {
confirmRecentTransaction,
rpc,
transaction: MOCK_TRANSACTION,
});
}).catch(() => {});
expect(createPendingRequest.mock.lastCall![1]).not.toHaveProperty('preflightCommitment');
});
it('returns the signature of the transaction', async () => {
Expand Down Expand Up @@ -200,7 +200,7 @@ describe('sendAndConfirmDurableNonceTransaction', () => {
confirmDurableNonceTransaction,
rpc,
transaction: MOCK_DURABLE_NONCE_TRANSACTION,
});
}).catch(() => {});
expect(getBase64EncodedWireTransaction).toHaveBeenCalledWith(MOCK_DURABLE_NONCE_TRANSACTION);
expect(createPendingRequest).toHaveBeenCalledWith('MOCK_WIRE_TRANSACTION', expect.anything());
});
Expand All @@ -218,7 +218,7 @@ describe('sendAndConfirmDurableNonceTransaction', () => {
confirmDurableNonceTransaction,
rpc,
transaction: MOCK_DURABLE_NONCE_TRANSACTION,
});
}).catch(() => {});
expect(getBase64EncodedWireTransaction).toHaveBeenCalledWith(MOCK_DURABLE_NONCE_TRANSACTION);
expect(createPendingRequest).toHaveBeenCalledWith('MOCK_WIRE_TRANSACTION', {
...sendTransactionConfig,
Expand All @@ -242,7 +242,7 @@ describe('sendAndConfirmDurableNonceTransaction', () => {
confirmDurableNonceTransaction,
rpc,
transaction: MOCK_DURABLE_NONCE_TRANSACTION,
});
}).catch(() => {});
await jest.runAllTimersAsync();
expect(confirmDurableNonceTransaction).toHaveBeenCalledWith({
abortSignal,
Expand All @@ -263,7 +263,7 @@ describe('sendAndConfirmDurableNonceTransaction', () => {
confirmDurableNonceTransaction,
rpc,
transaction: MOCK_DURABLE_NONCE_TRANSACTION,
});
}).catch(() => {});
expect(createPendingRequest).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
Expand Down Expand Up @@ -293,7 +293,7 @@ describe('sendAndConfirmDurableNonceTransaction', () => {
preflightCommitment,
rpc,
transaction: MOCK_DURABLE_NONCE_TRANSACTION,
});
}).catch(() => {});
expect(createPendingRequest).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
Expand All @@ -310,7 +310,7 @@ describe('sendAndConfirmDurableNonceTransaction', () => {
confirmDurableNonceTransaction,
rpc,
transaction: MOCK_DURABLE_NONCE_TRANSACTION,
});
}).catch(() => {});
expect(createPendingRequest.mock.lastCall![1]).not.toHaveProperty('preflightCommitment');
});
it('returns the signature of the transaction', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ describe('useSignAndSendTransaction', () => {
signAndSendTransaction({
options: { minContextSlot: 123n },
transaction: new Uint8Array([1, 2, 3]),
});
}).catch(() => {});
await jest.runAllTimersAsync();
signAndSendTransaction({
options: { minContextSlot: 123n },
transaction: new Uint8Array([1, 2, 3]),
});
}).catch(() => {});
// eslint-disable-next-line jest/no-conditional-expect
expect(mockSignAndSendTransaction).toHaveBeenCalledTimes(2);
// eslint-disable-next-line jest/no-conditional-expect
Expand Down
10 changes: 5 additions & 5 deletions packages/react/src/__tests__/useSignIn-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ describe('useSignIn', () => {
describe('the function returned', () => {
it("calls the wallet's `signIn` implementation", async () => {
expect.assertions(2);
signIn({ statement: 'You will really like being signed in' });
signIn({ statement: 'You will really like being signed in' }).catch(() => {});
await jest.runAllTimersAsync();
signIn({ statement: 'You will really like being signed in' });
signIn({ statement: 'You will really like being signed in' }).catch(() => {});
// eslint-disable-next-line jest/no-conditional-expect
expect(mockSignIn).toHaveBeenCalledTimes(2);
// eslint-disable-next-line jest/no-conditional-expect
Expand Down Expand Up @@ -153,9 +153,9 @@ describe('useSignIn', () => {
describe('the function returned', () => {
it("calls the wallet's `signIn` implementation", async () => {
expect.assertions(2);
signIn({ statement: 'You will really like being signed in' });
signIn({ statement: 'You will really like being signed in' }).catch(() => {});
await jest.runAllTimersAsync();
signIn({ statement: 'You will really like being signed in' });
signIn({ statement: 'You will really like being signed in' }).catch(() => {});
// eslint-disable-next-line jest/no-conditional-expect
expect(mockSignIn).toHaveBeenCalledTimes(2);
// eslint-disable-next-line jest/no-conditional-expect
Expand All @@ -168,7 +168,7 @@ describe('useSignIn', () => {
signIn({
// @ts-expect-error Not allowed by TypeScript, but what if supplied anyway?
address: '123',
});
}).catch(() => {});
// eslint-disable-next-line jest/no-conditional-expect
expect(mockSignIn).toHaveBeenCalledWith({ address: 'abc' });
});
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/__tests__/useSignMessage-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ describe('useSignMessage', () => {
throw result.current;
} else {
const signMessage = result.current;
signMessage({ message: new Uint8Array([1, 2, 3]) });
signMessage({ message: new Uint8Array([1, 2, 3]) }).catch(() => {});
await jest.runAllTimersAsync();
signMessage({ message: new Uint8Array([1, 2, 3]) });
signMessage({ message: new Uint8Array([1, 2, 3]) }).catch(() => {});
// eslint-disable-next-line jest/no-conditional-expect
expect(mockSignMessage).toHaveBeenCalledTimes(2);
// eslint-disable-next-line jest/no-conditional-expect
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/__tests__/useSignTransaction-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ describe('useSignTransaction', () => {
signTransaction({
options: { minContextSlot: 123n },
transaction: new Uint8Array([1, 2, 3]),
});
}).catch(() => {});
await jest.runAllTimersAsync();
signTransaction({
options: { minContextSlot: 123n },
transaction: new Uint8Array([1, 2, 3]),
});
}).catch(() => {});
// eslint-disable-next-line jest/no-conditional-expect
expect(mockSignTransaction).toHaveBeenCalledTimes(2);
// eslint-disable-next-line jest/no-conditional-expect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('useWalletAccountTransactionSendingSigner', () => {
'11111111111111111111111111111114': new Uint8Array(64).fill(2) as SignatureBytes,
},
};
signAndSendTransactions([inputTransaction]);
signAndSendTransactions([inputTransaction]).catch(() => {});
// eslint-disable-next-line jest/no-conditional-expect
expect(mockEncodeTransaction).toHaveBeenCalledWith(inputTransaction);
// eslint-disable-next-line jest/no-conditional-expect
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('useWalletAccountTransactionSendingSigner', () => {
signAndSendTransactions([inputTransaction], {
abortSignal: AbortSignal.timeout(1_000_000),
...mockOptions,
});
}).catch(() => {});
// eslint-disable-next-line jest/no-conditional-expect
expect(mockSignAndSendTransaction).toHaveBeenCalledWith(mockOptions);
}
Expand Down
Loading

0 comments on commit 441fa3a

Please sign in to comment.