Skip to content

Commit

Permalink
Enable require-await linter (#2353)
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher authored Mar 26, 2024
1 parent 8af5427 commit b566e7a
Show file tree
Hide file tree
Showing 61 changed files with 2,406 additions and 2,430 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@solana/build-scripts": "workspace:*",
"@solana/eslint-config-solana": "^3.0.0",
"@solana/eslint-config-solana": "^3.0.3",
"@solana/prettier-config-solana": "0.0.4",
"@solana/test-config": "workspace:*",
"@solana/test-matchers": "workspace:*",
Expand Down
15 changes: 5 additions & 10 deletions packages/addresses/src/__tests__/curve-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,10 @@ const ON_CURVE_KEY_BYTES = [
];

describe('compressedPointBytesAreOnCurve', () => {
it.each(OFF_CURVE_KEY_BYTES)(
'returns false when a public key does not lie on the Ed25519 curve [%#]',
async bytes => {
expect.assertions(1);
await expect(compressedPointBytesAreOnCurve(bytes)).resolves.toBe(false);
},
);
it.each(ON_CURVE_KEY_BYTES)('returns true when a public key lies on the Ed25519 curve [%#]', async bytes => {
expect.assertions(1);
await expect(compressedPointBytesAreOnCurve(bytes)).resolves.toBe(true);
it.each(OFF_CURVE_KEY_BYTES)('returns false when a public key does not lie on the Ed25519 curve [%#]', bytes => {
expect(compressedPointBytesAreOnCurve(bytes)).toBe(false);
});
it.each(ON_CURVE_KEY_BYTES)('returns true when a public key lies on the Ed25519 curve [%#]', bytes => {
expect(compressedPointBytesAreOnCurve(bytes)).toBe(true);
});
});
2 changes: 1 addition & 1 deletion packages/addresses/src/curve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function decompressPointBytes(bytes: Uint8Array): bigint {
return BigInt(integerLiteralString);
}

export async function compressedPointBytesAreOnCurve(bytes: Uint8Array): Promise<boolean> {
export function compressedPointBytesAreOnCurve(bytes: Uint8Array): boolean {
if (bytes.byteLength !== 32) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/addresses/src/program-derived-address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async function createProgramDerivedAddress({ programAddress, seeds }: ProgramDer
new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES]),
);
const addressBytes = new Uint8Array(addressBytesBuffer);
if (await compressedPointBytesAreOnCurve(addressBytes)) {
if (compressedPointBytesAreOnCurve(addressBytes)) {
throw new SolanaError(SOLANA_ERROR__ADDRESSES__INVALID_SEEDS_POINT_ON_CURVE);
}
return base58EncodedAddressCodec.decode(addressBytes);
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/keypair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export async function fromLegacyKeypair(keypair: Keypair, extractable?: boolean)
const bytes = new Uint8Array(64);
bytes.set(keypair.secretKey);
bytes.set(keypair.publicKey.toBytes(), /* offset */ 32);
return createKeyPairFromBytes(bytes, extractable);
return await createKeyPairFromBytes(bytes, extractable);
}
10 changes: 4 additions & 6 deletions packages/errors/src/__tests__/message-formatter-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jest.mock('../messages', () => ({

describe('getErrorMessage', () => {
describe('in production mode', () => {
beforeEach(async () => {
beforeEach(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(globalThis as any).__DEV__ = false;
});
Expand Down Expand Up @@ -49,25 +49,23 @@ describe('getErrorMessage', () => {
);
expect(encodeContextObject).toHaveBeenCalledWith(context);
});
it('renders advice on where to decode an error with encoded context', async () => {
expect.assertions(1);
it('renders advice on where to decode an error with encoded context', () => {
jest.mocked(encodeContextObject).mockReturnValue('ENCODED_CONTEXT');
const context = { foo: 'bar' };
const message = getErrorMessage(123 as SolanaErrorCode, context);
expect(message).toBe(
"Solana error #123; Decode this error by running `npx @solana/errors decode -- 123 'ENCODED_CONTEXT'`",
);
});
it('renders no encoded context in the decoding advice when the context has no keys', async () => {
expect.assertions(1);
it('renders no encoded context in the decoding advice when the context has no keys', () => {
jest.mocked(encodeContextObject).mockReturnValue('ENCODED_CONTEXT');
const context = {};
const message = getErrorMessage(123 as SolanaErrorCode, context);
expect(message).toBe('Solana error #123; Decode this error by running `npx @solana/errors decode -- 123`');
});
});
describe('in dev mode', () => {
beforeEach(async () => {
beforeEach(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(globalThis as any).__DEV__ = true;
});
Expand Down
3 changes: 1 addition & 2 deletions packages/keys/src/__tests__/private-key-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ describe('createPrivateKeyFromBytes', () => {
beforeEach(async () => {
privateKey = await createPrivateKeyFromBytes(MOCK_PRIVATE_KEY_BYTES);
});
it('is non-extractable', async () => {
expect.assertions(1);
it('is non-extractable', () => {
expect(privateKey).toHaveProperty('extractable', false);
});
it('has the expected metadata', () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/library/src/__tests__/airdrop-internal-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ describe('requestAndConfirmAirdrop', () => {
requestAirdrop,
};
});
it('aborts the `requestAirdrop` request when aborted', async () => {
expect.assertions(2);
it('aborts the `requestAirdrop` request when aborted', () => {
const abortController = new AbortController();
requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({
abortSignal: abortController.signal,
Expand Down Expand Up @@ -68,8 +67,7 @@ describe('requestAndConfirmAirdrop', () => {
}),
);
});
it('passes the expected input to the airdrop request', async () => {
expect.assertions(1);
it('passes the expected input to the airdrop request', () => {
sendAirdropRequest.mockResolvedValue('abc' as Signature);
requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({
abortSignal: new AbortController().signal,
Expand Down
2 changes: 1 addition & 1 deletion packages/rpc-graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function createRpcGraphQL(
return {
async query(source, variableValues?) {
const contextValue = createSolanaGraphQLContext(rpc, rpcGraphQLConfig);
return graphql({
return await graphql({
contextValue,
schema,
source,
Expand Down
88 changes: 48 additions & 40 deletions packages/rpc-graphql/src/loaders/__tests__/account-loader-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import type {

import { createRpcGraphQL, RpcGraphQL } from '../../index';

const FOREVER_PROMISE = new Promise(() => {
/* never resolve */
});

describe('account loader', () => {
let rpc: {
getAccountInfo: jest.MockedFunction<Rpc<GetAccountInfoApi>['getAccountInfo']>;
Expand All @@ -24,11 +28,11 @@ describe('account loader', () => {
beforeEach(() => {
jest.useFakeTimers();
rpc = {
getAccountInfo: jest.fn(),
getBlock: jest.fn(),
getMultipleAccounts: jest.fn(),
getProgramAccounts: jest.fn(),
getTransaction: jest.fn(),
getAccountInfo: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getBlock: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getMultipleAccounts: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getProgramAccounts: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getTransaction: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
};
rpcGraphQL = createRpcGraphQL(
rpc as unknown as Rpc<
Expand Down Expand Up @@ -431,48 +435,52 @@ describe('account loader', () => {
// First we should see `getMultipleAccounts` used for the first two layers
rpc.getMultipleAccounts
.mockImplementationOnce(() => ({
send: async () =>
getMultipleAccountsMockResponse([
{
data: ['AA', 'base64'],
owner: '11111111111111111111111111111111',
},
{
data: ['AA', 'base64'],
owner: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
},
{
data: ['AA', 'base64'],
owner: 'Stake11111111111111111111111111111111111111',
},
{
data: ['AA', 'base64'],
owner: 'Vote111111111111111111111111111111111111111',
},
]),
send: () =>
Promise.resolve(
getMultipleAccountsMockResponse([
{
data: ['AA', 'base64'],
owner: '11111111111111111111111111111111',
},
{
data: ['AA', 'base64'],
owner: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
},
{
data: ['AA', 'base64'],
owner: 'Stake11111111111111111111111111111111111111',
},
{
data: ['AA', 'base64'],
owner: 'Vote111111111111111111111111111111111111111',
},
]),
),
}))
.mockImplementationOnce(() => ({
send: async () =>
getMultipleAccountsMockResponse([
{
data: ['AA', 'base64'],
owner: 'NativeLoader1111111111111111111111111111111',
},
{
data: ['AA', 'base64'],
owner: 'BPFLoader2111111111111111111111111111111111',
},
{
data: ['AA', 'base64'],
owner: 'NativeLoader1111111111111111111111111111111',
},
]),
send: () =>
Promise.resolve(
getMultipleAccountsMockResponse([
{
data: ['AA', 'base64'],
owner: 'NativeLoader1111111111111111111111111111111',
},
{
data: ['AA', 'base64'],
owner: 'BPFLoader2111111111111111111111111111111111',
},
{
data: ['AA', 'base64'],
owner: 'NativeLoader1111111111111111111111111111111',
},
]),
),
}));

// Then we should see `getAccountInfo` used for the single
// account in the last layer
rpc.getAccountInfo.mockReturnValue({
send: jest.fn().mockReturnValueOnce({
send: jest.fn().mockResolvedValueOnce({
context: {
slot: 0,
},
Expand Down
14 changes: 9 additions & 5 deletions packages/rpc-graphql/src/loaders/__tests__/block-loader-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import type { Slot } from '@solana/rpc-types';

import { createRpcGraphQL, RpcGraphQL } from '../../index';

const FOREVER_PROMISE = new Promise(() => {
/* never resolve */
});

describe('account loader', () => {
let rpc: Rpc<GetAccountInfoApi & GetBlockApi & GetMultipleAccountsApi & GetProgramAccountsApi & GetTransactionApi>;
let rpcGraphQL: RpcGraphQL;
Expand All @@ -19,11 +23,11 @@ describe('account loader', () => {
beforeEach(() => {
jest.useFakeTimers();
rpc = {
getAccountInfo: jest.fn(),
getBlock: jest.fn(),
getMultipleAccounts: jest.fn(),
getProgramAccounts: jest.fn(),
getTransaction: jest.fn(),
getAccountInfo: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getBlock: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getMultipleAccounts: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getProgramAccounts: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getTransaction: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
};
rpcGraphQL = createRpcGraphQL(rpc);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import type {

import { createRpcGraphQL, RpcGraphQL } from '../../index';

const FOREVER_PROMISE = new Promise(() => {
/* never resolve */
});

describe('account loader', () => {
let rpc: Rpc<GetAccountInfoApi & GetBlockApi & GetMultipleAccountsApi & GetProgramAccountsApi & GetTransactionApi>;
let rpcGraphQL: RpcGraphQL;
Expand All @@ -18,11 +22,11 @@ describe('account loader', () => {
beforeEach(() => {
jest.useFakeTimers();
rpc = {
getAccountInfo: jest.fn(),
getBlock: jest.fn(),
getMultipleAccounts: jest.fn(),
getProgramAccounts: jest.fn(),
getTransaction: jest.fn(),
getAccountInfo: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getBlock: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getMultipleAccounts: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getProgramAccounts: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getTransaction: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
};
rpcGraphQL = createRpcGraphQL(rpc);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import type {

import { createRpcGraphQL, RpcGraphQL } from '../../index';

const FOREVER_PROMISE = new Promise(() => {
/* never resolve */
});

describe('account loader', () => {
let rpc: Rpc<GetAccountInfoApi & GetBlockApi & GetMultipleAccountsApi & GetProgramAccountsApi & GetTransactionApi>;
let rpcGraphQL: RpcGraphQL;
Expand All @@ -18,11 +22,11 @@ describe('account loader', () => {
beforeEach(() => {
jest.useFakeTimers();
rpc = {
getAccountInfo: jest.fn(),
getBlock: jest.fn(),
getMultipleAccounts: jest.fn(),
getProgramAccounts: jest.fn(),
getTransaction: jest.fn(),
getAccountInfo: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getBlock: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getMultipleAccounts: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getProgramAccounts: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
getTransaction: jest.fn().mockReturnValue({ send: jest.fn().mockReturnValue(FOREVER_PROMISE) }),
};
rpcGraphQL = createRpcGraphQL(rpc);
});
Expand Down
6 changes: 3 additions & 3 deletions packages/rpc-graphql/src/loaders/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async function loadMultipleAccounts(
function createAccountBatchLoadFn(rpc: Rpc<GetAccountInfoApi & GetMultipleAccountsApi>, config: Config) {
const resolveAccountUsingRpc = loadAccount.bind(null, rpc);
const resolveMultipleAccountsUsingRpc = loadMultipleAccounts.bind(null, rpc);
return async (accountQueryArgs: readonly AccountLoaderArgs[]): ReturnType<AccountLoader['loadMany']> => {
return (accountQueryArgs: readonly AccountLoaderArgs[]): ReturnType<AccountLoader['loadMany']> => {
/**
* Gather all the accounts that need to be fetched, grouped by address.
*/
Expand Down Expand Up @@ -182,7 +182,7 @@ export function createAccountLoader(
): AccountLoader {
const loader = new DataLoader(createAccountBatchLoadFn(rpc, config), { cacheKeyFn });
return {
load: async args => loader.load(args),
loadMany: async args => loader.loadMany(args),
load: args => loader.load(args),
loadMany: args => loader.loadMany(args),
};
}
6 changes: 3 additions & 3 deletions packages/rpc-graphql/src/loaders/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function loadBlock(rpc: Rpc<GetBlockApi>, { slot, ...config }: BlockLoader

function createBlockBatchLoadFn(rpc: Rpc<GetBlockApi>) {
const resolveBlockUsingRpc = loadBlock.bind(null, rpc);
return async (blockQueryArgs: readonly BlockLoaderArgs[]): ReturnType<BlockLoader['loadMany']> => {
return (blockQueryArgs: readonly BlockLoaderArgs[]): ReturnType<BlockLoader['loadMany']> => {
/**
* Gather all the blocks that need to be fetched, grouped by slot.
*/
Expand Down Expand Up @@ -76,7 +76,7 @@ function createBlockBatchLoadFn(rpc: Rpc<GetBlockApi>) {
export function createBlockLoader(rpc: Rpc<GetBlockApi>): BlockLoader {
const loader = new DataLoader(createBlockBatchLoadFn(rpc), { cacheKeyFn });
return {
load: async args => loader.load({ ...args, maxSupportedTransactionVersion: 0 }),
loadMany: async args => loader.loadMany(args.map(a => ({ ...a, maxSupportedTransactionVersion: 0 }))),
load: args => loader.load({ ...args, maxSupportedTransactionVersion: 0 }),
loadMany: args => loader.loadMany(args.map(a => ({ ...a, maxSupportedTransactionVersion: 0 }))),
};
}
8 changes: 3 additions & 5 deletions packages/rpc-graphql/src/loaders/program-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ async function loadProgramAccounts(

function createProgramAccountsBatchLoadFn(rpc: Rpc<GetProgramAccountsApi>, config: Config) {
const resolveProgramAccountsUsingRpc = loadProgramAccounts.bind(null, rpc);
return async (
accountQueryArgs: readonly ProgramAccountsLoaderArgs[],
): ReturnType<ProgramAccountsLoader['loadMany']> => {
return (accountQueryArgs: readonly ProgramAccountsLoaderArgs[]): ReturnType<ProgramAccountsLoader['loadMany']> => {
/**
* Gather all the program-accounts that need to be fetched, grouped by
* program address.
Expand Down Expand Up @@ -94,7 +92,7 @@ function createProgramAccountsBatchLoadFn(rpc: Rpc<GetProgramAccountsApi>, confi
export function createProgramAccountsLoader(rpc: Rpc<GetProgramAccountsApi>, config: Config): ProgramAccountsLoader {
const loader = new DataLoader(createProgramAccountsBatchLoadFn(rpc, config), { cacheKeyFn });
return {
load: async args => loader.load(args),
loadMany: async args => loader.loadMany(args),
load: args => loader.load(args),
loadMany: args => loader.loadMany(args),
};
}
Loading

0 comments on commit b566e7a

Please sign in to comment.