From d973a941f52a2be84707f1eee73ec5d049144620 Mon Sep 17 00:00:00 2001 From: Jade Hamilton Date: Fri, 20 Dec 2024 08:30:04 -0700 Subject: [PATCH] test(test-d): add test-d files for vitest typechecking: --- .github/workflows/on-pull-request.yml | 4 + .vitest/vitest.shared.ts | 3 + CONTRIBUTING.md | 4 +- aa-sdk/core/package.json | 1 + aa-sdk/core/tsconfig.build.json | 1 + aa-sdk/ethers/package.json | 1 + aa-sdk/ethers/tsconfig.build.json | 1 + account-kit/core/package.json | 1 + account-kit/core/tsconfig.build.json | 1 + account-kit/infra/package.json | 1 + account-kit/infra/tsconfig.build.json | 1 + account-kit/logging/package.json | 1 + account-kit/logging/tsconfig.build.json | 1 + account-kit/plugingen/package.json | 1 + account-kit/plugingen/tsconfig.build.json | 1 + account-kit/react/package.json | 1 + account-kit/react/tsconfig.build.json | 1 + account-kit/react/tsconfig.storybook.json | 1 + account-kit/signer/package.json | 1 + account-kit/signer/tsconfig.build.json | 1 + account-kit/smart-contracts/package.json | 1 + .../light-account/clients/client.test-d.ts | 125 ++++++++++++++++++ .../src/light-account/clients/client.test.ts | 92 +------------ .../smart-contracts/tsconfig.build.json | 1 + doc-gen/package.json | 1 + doc-gen/tsconfig.build.json | 1 + package.json | 1 + .../infra/functions/isAlchemyTransport.mdx | 36 ----- 28 files changed, 157 insertions(+), 129 deletions(-) create mode 100644 account-kit/smart-contracts/src/light-account/clients/client.test-d.ts delete mode 100644 site/pages/reference/account-kit/infra/functions/isAlchemyTransport.mdx diff --git a/.github/workflows/on-pull-request.yml b/.github/workflows/on-pull-request.yml index d8e8c49db6..deeb9f23d7 100644 --- a/.github/workflows/on-pull-request.yml +++ b/.github/workflows/on-pull-request.yml @@ -101,6 +101,9 @@ jobs: - name: Unit Test run: yarn test:ci + + - name: Typecheck Test + run: yarn test:typecheck build_ios: name: Build iOS @@ -131,3 +134,4 @@ jobs: - name: Build example for iOS run: | yarn turbo run build:ios + diff --git a/.vitest/vitest.shared.ts b/.vitest/vitest.shared.ts index c085cdec58..50c85b8d64 100644 --- a/.vitest/vitest.shared.ts +++ b/.vitest/vitest.shared.ts @@ -3,6 +3,9 @@ import { configDefaults, defineConfig } from "vitest/config"; export const sharedConfig = defineConfig({ test: { + typecheck: { + ignoreSourceErrors: true, + }, alias: { "~test": join(__dirname, "./src"), }, diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9c1a8dba3d..1378393894 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,11 +12,11 @@ We are excited to have you contribute to the `aa-sdk`. Here's a step-by-step gui - Use the Node version specified in `package.json` (currently 18.16.0). Run `node -v` to check your version. - Build the project with `yarn build`. - - Run existing tests using `yarn test` to ensure everything is working correctly. + - Run existing tests using `yarn test` & `yarn test:typecheck` to ensure everything is working correctly. 4. **Make Changes**: Now, you can start making changes to the packages or docs. When updating or adding new functionality, update or add a new doc in `site/packages/*` corresponding to the package you have worked on to document the changes. -5. **Re-verify Tests**: After making your changes, re-run `yarn test` to ensure all tests still pass. +5. **Re-verify Tests**: After making your changes, re-run `yarn test` & `yarn test:typecheck` to ensure all tests still pass. 6. **Code Formatting**: diff --git a/aa-sdk/core/package.json b/aa-sdk/core/package.json index cb2334c52e..58074ccf1b 100644 --- a/aa-sdk/core/package.json +++ b/aa-sdk/core/package.json @@ -17,6 +17,7 @@ "!vitest.config.ts", "!.env", "!src/**/*.test.ts", + "!src/**/*.test-d.ts", "!src/__tests__/**/*" ], "exports": { diff --git a/aa-sdk/core/tsconfig.build.json b/aa-sdk/core/tsconfig.build.json index 7bae05bd62..5de5b77262 100644 --- a/aa-sdk/core/tsconfig.build.json +++ b/aa-sdk/core/tsconfig.build.json @@ -4,6 +4,7 @@ "node_modules", "**/*/__tests__", "**/*/*.test.ts", + "**/*/*.test-d.ts", "**/*/*.e2e.test.ts", "vitest.config.ts", "vitest.config.e2e.ts" diff --git a/aa-sdk/ethers/package.json b/aa-sdk/ethers/package.json index c31329ea67..fb78a6b8a3 100644 --- a/aa-sdk/ethers/package.json +++ b/aa-sdk/ethers/package.json @@ -17,6 +17,7 @@ "!.env", "!dist/**/*.tsbuildinfo", "!src/**/*.test.ts", + "!src/**/*.test-d.ts", "!src/__tests__/**/*" ], "exports": { diff --git a/aa-sdk/ethers/tsconfig.build.json b/aa-sdk/ethers/tsconfig.build.json index 8f0730ac86..795defce57 100644 --- a/aa-sdk/ethers/tsconfig.build.json +++ b/aa-sdk/ethers/tsconfig.build.json @@ -5,6 +5,7 @@ "**/*/__tests__", "**/*/*.e2e.test.ts", "**/*/*.test.ts", + "**/*/*.test-d.ts", "vitest.config.ts" ], "include": ["src"], diff --git a/account-kit/core/package.json b/account-kit/core/package.json index 3a3c113d8f..b9fa5fc246 100644 --- a/account-kit/core/package.json +++ b/account-kit/core/package.json @@ -18,6 +18,7 @@ "!vitest.config.ts", "!.env", "!src/**/*.test.ts", + "!src/**/*.test-d.ts", "!src/__tests__/**/*" ], "exports": { diff --git a/account-kit/core/tsconfig.build.json b/account-kit/core/tsconfig.build.json index 605911996a..a9532f066c 100644 --- a/account-kit/core/tsconfig.build.json +++ b/account-kit/core/tsconfig.build.json @@ -4,6 +4,7 @@ "node_modules", "**/*/__tests__", "**/*/*.test.ts", + "**/*/*.test-d.ts", "**/*/*.e2e.test.ts", "vitest.config.ts", "vitest.config.e2e.ts" diff --git a/account-kit/infra/package.json b/account-kit/infra/package.json index 488f71a639..b4fa69f26c 100644 --- a/account-kit/infra/package.json +++ b/account-kit/infra/package.json @@ -18,6 +18,7 @@ "!vitest.config.ts", "!.env", "!src/**/*.test.ts", + "!src/**/*.test-d.ts", "!src/__tests__/**/*" ], "exports": { diff --git a/account-kit/infra/tsconfig.build.json b/account-kit/infra/tsconfig.build.json index 605911996a..a9532f066c 100644 --- a/account-kit/infra/tsconfig.build.json +++ b/account-kit/infra/tsconfig.build.json @@ -4,6 +4,7 @@ "node_modules", "**/*/__tests__", "**/*/*.test.ts", + "**/*/*.test-d.ts", "**/*/*.e2e.test.ts", "vitest.config.ts", "vitest.config.e2e.ts" diff --git a/account-kit/logging/package.json b/account-kit/logging/package.json index a5b5114a5d..6eb3c326d8 100644 --- a/account-kit/logging/package.json +++ b/account-kit/logging/package.json @@ -18,6 +18,7 @@ "!vitest.config.ts", "!.env", "!src/**/*.test.ts", + "!src/**/*.test-d.ts", "!src/__tests__/**/*" ], "exports": { diff --git a/account-kit/logging/tsconfig.build.json b/account-kit/logging/tsconfig.build.json index 7bae05bd62..5de5b77262 100644 --- a/account-kit/logging/tsconfig.build.json +++ b/account-kit/logging/tsconfig.build.json @@ -4,6 +4,7 @@ "node_modules", "**/*/__tests__", "**/*/*.test.ts", + "**/*/*.test-d.ts", "**/*/*.e2e.test.ts", "vitest.config.ts", "vitest.config.e2e.ts" diff --git a/account-kit/plugingen/package.json b/account-kit/plugingen/package.json index 9ab34ff9ef..9072a882a4 100644 --- a/account-kit/plugingen/package.json +++ b/account-kit/plugingen/package.json @@ -17,6 +17,7 @@ "!vitest.config.ts", "!.env", "!src/**/*.test.ts", + "!src/**/*.test-d.ts", "!src/__tests__/**/*" ], "exports": { diff --git a/account-kit/plugingen/tsconfig.build.json b/account-kit/plugingen/tsconfig.build.json index 7bae05bd62..5de5b77262 100644 --- a/account-kit/plugingen/tsconfig.build.json +++ b/account-kit/plugingen/tsconfig.build.json @@ -4,6 +4,7 @@ "node_modules", "**/*/__tests__", "**/*/*.test.ts", + "**/*/*.test-d.ts", "**/*/*.e2e.test.ts", "vitest.config.ts", "vitest.config.e2e.ts" diff --git a/account-kit/react/package.json b/account-kit/react/package.json index 76ce505f70..4575d589ac 100644 --- a/account-kit/react/package.json +++ b/account-kit/react/package.json @@ -19,6 +19,7 @@ "!vitest.config.ts", "!.env", "!src/**/*.test.ts", + "!src/**/*.test-d.ts", "!src/__tests__/**/*" ], "exports": { diff --git a/account-kit/react/tsconfig.build.json b/account-kit/react/tsconfig.build.json index 96bf1023be..8c0c953a27 100644 --- a/account-kit/react/tsconfig.build.json +++ b/account-kit/react/tsconfig.build.json @@ -4,6 +4,7 @@ "node_modules", "**/*/__tests__", "**/*/*.test.ts", + "**/*/*.test-d.ts", "**/*/*.e2e.test.ts", "vitest.config.ts", "vitest.config.e2e.ts", diff --git a/account-kit/react/tsconfig.storybook.json b/account-kit/react/tsconfig.storybook.json index 7b12f187f6..76cb4c347c 100644 --- a/account-kit/react/tsconfig.storybook.json +++ b/account-kit/react/tsconfig.storybook.json @@ -9,6 +9,7 @@ "exclude": [ "src/**/*.spec.ts", "src/**/*.test.ts", + "src/**/*.test-d.ts", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.tsx", diff --git a/account-kit/signer/package.json b/account-kit/signer/package.json index c980d074b5..05f465e776 100644 --- a/account-kit/signer/package.json +++ b/account-kit/signer/package.json @@ -18,6 +18,7 @@ "!vitest.config.ts", "!.env", "!src/**/*.test.ts", + "!src/**/*.test-d.ts", "!src/__tests__/**/*" ], "exports": { diff --git a/account-kit/signer/tsconfig.build.json b/account-kit/signer/tsconfig.build.json index 605911996a..a9532f066c 100644 --- a/account-kit/signer/tsconfig.build.json +++ b/account-kit/signer/tsconfig.build.json @@ -4,6 +4,7 @@ "node_modules", "**/*/__tests__", "**/*/*.test.ts", + "**/*/*.test-d.ts", "**/*/*.e2e.test.ts", "vitest.config.ts", "vitest.config.e2e.ts" diff --git a/account-kit/smart-contracts/package.json b/account-kit/smart-contracts/package.json index 2b7853ef55..68fa1cb562 100644 --- a/account-kit/smart-contracts/package.json +++ b/account-kit/smart-contracts/package.json @@ -19,6 +19,7 @@ "!vitest.config.ts", "!.env", "!src/**/*.test.ts", + "!src/**/*.test-d.ts", "!src/__tests__/**/*" ], "exports": { diff --git a/account-kit/smart-contracts/src/light-account/clients/client.test-d.ts b/account-kit/smart-contracts/src/light-account/clients/client.test-d.ts new file mode 100644 index 0000000000..5b6eb292a2 --- /dev/null +++ b/account-kit/smart-contracts/src/light-account/clients/client.test-d.ts @@ -0,0 +1,125 @@ +import { + erc7677Middleware, + LocalAccountSigner, + type SmartAccountClient, + type SmartAccountSigner, +} from "@aa-sdk/core"; +import { + custom, + type Address, + type Chain, + type Client, + type CustomTransport, +} from "viem"; +import { accounts } from "~test/constants.js"; +import { local060Instance } from "~test/instances.js"; +import type { LightAccountVersion } from "../types.js"; +import { createLightAccountClient } from "./client.js"; +import { + alchemy, + polygonMumbai, + alchemyEnhancedApiActions, + type AlchemyTransport, + type AlchemySmartAccountClient, + type AlchemyEnhancedApis, +} from "@account-kit/infra"; +import { Alchemy, Network } from "alchemy-sdk"; + +describe("Types: Light Account Tests", () => { + const instance = local060Instance; + const signer: SmartAccountSigner = new LocalAccountSigner( + accounts.fundedAccountOwner + ); + + const givenConnectedProvider = ({ + signer, + version = "v1.1.0", + accountAddress, + usePaymaster = false, + }: { + signer: SmartAccountSigner; + version?: LightAccountVersion<"LightAccount">; + usePaymaster?: boolean; + accountAddress?: Address; + }) => + createLightAccountClient({ + signer, + accountAddress, + version, + transport: custom(instance.getClient()), + chain: instance.chain, + ...(usePaymaster ? erc7677Middleware() : {}), + }); + + const givenAlchemyConnectedProvider = async ({ + signer, + chain, + }: { + signer: SmartAccountSigner; + chain: Chain; + }) => + createLightAccountClient({ + transport: alchemy({ + jwt: "test", + }), + chain, + signer, + accountAddress: "0x86f3B0211764971Ad0Fc8C8898d31f5d792faD84", + }); + it("Should have some alchemy specific types", async () => { + const alchemy = new Alchemy({ + network: Network.MATIC_MUMBAI, + apiKey: "test", + }); + const chain = polygonMumbai; + + const provider = ( + await givenAlchemyConnectedProvider({ signer, chain }) + ).extend(alchemyEnhancedApiActions(alchemy)); + + assertType>(provider); + assertType(provider); + assertType(provider); + assertType(provider); + assertType( + // @ts-expect-error + await givenAlchemyConnectedProvider({ signer, chain }) + ); + // @ts-expect-error + assertType>(provider); + }); + it("Should have some non-alchemy specific types", async () => { + const chain = polygonMumbai; + + const signer: SmartAccountSigner = new LocalAccountSigner( + accounts.fundedAccountOwner + ); + const provider = await givenConnectedProvider({ + signer, + version: "v1.0.1", + }); + + assertType(provider); + assertType>(provider); + assertType( + // @ts-expect-error + await givenAlchemyConnectedProvider({ signer, chain }) + ); + // @ts-expect-error + assertType>(provider); + // @ts-expect-error + assertType(provider); + // @ts-expect-error + assertType(provider); + + expect(() => { + const alchemy = new Alchemy({ + network: Network.MATIC_MUMBAI, + apiKey: "test", + }); + + // @ts-expect-error + provider.extend(alchemyEnhancedApiActions(alchemy)); + }).not.toBeFalsy(); + }); +}); diff --git a/account-kit/smart-contracts/src/light-account/clients/client.test.ts b/account-kit/smart-contracts/src/light-account/clients/client.test.ts index 25442a97da..0c58a7c142 100644 --- a/account-kit/smart-contracts/src/light-account/clients/client.test.ts +++ b/account-kit/smart-contracts/src/light-account/clients/client.test.ts @@ -4,21 +4,12 @@ import { erc7677Middleware, LocalAccountSigner, type BatchUserOperationCallData, - type SmartAccountClient, type SmartAccountSigner, type UserOperationCallData, type UserOperationOverrides, type UserOperationStruct, } from "@aa-sdk/core"; -import { - custom, - parseEther, - type Address, - publicActions, - type Chain, - type Client, - type CustomTransport, -} from "viem"; +import { custom, parseEther, type Address, publicActions } from "viem"; import { setBalance } from "viem/actions"; import { resetBalance } from "~test/accounts.js"; import { accounts } from "~test/constants.js"; @@ -30,15 +21,6 @@ import { getMSCAUpgradeToData } from "../../msca/utils.js"; import type { LightAccountVersion } from "../types.js"; import { AccountVersionRegistry } from "../utils.js"; import { createLightAccountClient } from "./client.js"; -import { - alchemy, - polygonMumbai, - alchemyEnhancedApiActions, - type AlchemyTransport, - type AlchemySmartAccountClient, - type AlchemyEnhancedApis, -} from "@account-kit/infra"; -import { Alchemy, Network } from "alchemy-sdk"; const versions = Object.keys( AccountVersionRegistry.LightAccount @@ -405,76 +387,4 @@ describe("Light Account Tests", () => { chain: instance.chain, ...(usePaymaster ? erc7677Middleware() : {}), }); - - const givenAlchemyConnectedProvider = async ({ - signer, - chain, - }: { - signer: SmartAccountSigner; - chain: Chain; - }) => - createLightAccountClient({ - transport: alchemy({ - jwt: "test", - }), - chain, - signer, - accountAddress: "0x86f3B0211764971Ad0Fc8C8898d31f5d792faD84", - }); - it("Should have some alchemy specific types", async () => { - const alchemy = new Alchemy({ - network: Network.MATIC_MUMBAI, - apiKey: "test", - }); - const chain = polygonMumbai; - - const provider = ( - await givenAlchemyConnectedProvider({ signer, chain }) - ).extend(alchemyEnhancedApiActions(alchemy)); - - assertType>(provider); - assertType(provider); - assertType(provider); - assertType(provider); - assertType( - // @ts-expect-error - await givenAlchemyConnectedProvider({ signer, chain }) - ); - // @ts-expect-error - assertType>(provider); - }); - it("Should have some non-alchemy specific types", async () => { - const chain = polygonMumbai; - - const signer: SmartAccountSigner = new LocalAccountSigner( - accounts.fundedAccountOwner - ); - const provider = await givenConnectedProvider({ - signer, - version: "v1.0.1", - }); - - assertType(provider); - assertType>(provider); - assertType( - // @ts-expect-error - await givenAlchemyConnectedProvider({ signer, chain }) - ); - // @ts-expect-error - assertType>(provider); - // @ts-expect-error - assertType(provider); - // @ts-expect-error - assertType(provider); - - expect(() => { - const alchemy = new Alchemy({ - network: Network.MATIC_MUMBAI, - apiKey: "test", - }); - - // @ts-expect-error - provider.extend(alchemyEnhancedApiActions(alchemy)); - }).not.toBeFalsy(); - }); }); diff --git a/account-kit/smart-contracts/tsconfig.build.json b/account-kit/smart-contracts/tsconfig.build.json index 2c54d60030..563e06f2ca 100644 --- a/account-kit/smart-contracts/tsconfig.build.json +++ b/account-kit/smart-contracts/tsconfig.build.json @@ -4,6 +4,7 @@ "node_modules", "**/*/__tests__", "**/*/*.test.ts", + "**/*/*.test-d.ts", "**/*/*.e2e.test.ts", "vitest.config.ts", "vitest.config.e2e.ts" diff --git a/doc-gen/package.json b/doc-gen/package.json index 99b37e0c35..fd0a585d77 100644 --- a/doc-gen/package.json +++ b/doc-gen/package.json @@ -17,6 +17,7 @@ "!vitest.config.ts", "!.env", "!src/**/*.test.ts", + "!src/**/*.test-d.ts", "!src/__tests__/**/*" ], "exports": { diff --git a/doc-gen/tsconfig.build.json b/doc-gen/tsconfig.build.json index 1eed8a513d..0f3429ff0a 100644 --- a/doc-gen/tsconfig.build.json +++ b/doc-gen/tsconfig.build.json @@ -4,6 +4,7 @@ "node_modules", "**/*/__tests__", "**/*/*.test.ts", + "**/*/*.test-d.ts", "**/*/*.e2e.test.ts", "vitest.config.ts", "vitest.config.e2e.ts" diff --git a/package.json b/package.json index 21d4b67145..f2d077d767 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "docs:gen": "turbo run docs:gen", "test": "vitest dev", "test:ci": "vitest run", + "test:typecheck": "TYPECHECK=true vitest --typecheck --typecheck.only ", "lint:write": "eslint . --fix && yarn docs:gen && prettier --loglevel warn --write --ignore-unknown .", "lint:check": "eslint . && prettier --check .", "prepare": "husky install && yarn turbo prepare", diff --git a/site/pages/reference/account-kit/infra/functions/isAlchemyTransport.mdx b/site/pages/reference/account-kit/infra/functions/isAlchemyTransport.mdx deleted file mode 100644 index 8e3c9944c1..0000000000 --- a/site/pages/reference/account-kit/infra/functions/isAlchemyTransport.mdx +++ /dev/null @@ -1,36 +0,0 @@ ---- -# This file is autogenerated -title: isAlchemyTransport -description: Overview of the isAlchemyTransport method ---- - -# isAlchemyTransport - -Checks whether the given transport is an AlchemyTransport. - -## Import - -```ts -import { isAlchemyTransport } from "@account-kit/infra"; -``` - -## Usage - -```ts -import { isAlchemyTransport } from "@account-kit/infra"; -if (isAlchemyTransport(transport)) { - // do things here that are only when transport is an AlchemyTransport -} -``` - -## Parameters - -### x - -`Transport | AlchemyTransport` -The transport to check. - -## Returns - -`boolean` -True if the transport is of type AlchemyTransport, otherwise false.