Skip to content

Commit

Permalink
test(test-d): add test-d files for vitest typechecking:
Browse files Browse the repository at this point in the history
  • Loading branch information
Blu-J committed Dec 20, 2024
1 parent cca9ba3 commit d97b716
Show file tree
Hide file tree
Showing 27 changed files with 156 additions and 127 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ jobs:
- name: Unit Test
run: yarn test:ci

- name: Typecheck Test
run: yarn test:typecheck

5 changes: 5 additions & 0 deletions .vitest/vitest.shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { configDefaults, defineConfig } from "vitest/config";

export const sharedConfig = defineConfig({
test: {
typecheck: {
enabled: process.env.TYPECHECK === "true",
only: process.env.TYPECHECK === "true",
ignoreSourceErrors: true,
},
alias: {
"~test": join(__dirname, "./src"),
},
Expand Down
1 change: 1 addition & 0 deletions aa-sdk/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"!vitest.config.ts",
"!.env",
"!src/**/*.test.ts",
"!src/**/*.test-d.ts",
"!src/__tests__/**/*"
],
"exports": {
Expand Down
1 change: 1 addition & 0 deletions aa-sdk/core/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"node_modules",
"**/*/__tests__",
"**/*/*.test.ts",
"**/*/*.test-d.ts",
"**/*/*.e2e.test.ts",
"vitest.config.ts",
"vitest.config.e2e.ts"
Expand Down
1 change: 1 addition & 0 deletions aa-sdk/ethers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"!.env",
"!dist/**/*.tsbuildinfo",
"!src/**/*.test.ts",
"!src/**/*.test-d.ts",
"!src/__tests__/**/*"
],
"exports": {
Expand Down
1 change: 1 addition & 0 deletions aa-sdk/ethers/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"**/*/__tests__",
"**/*/*.e2e.test.ts",
"**/*/*.test.ts",
"**/*/*.test-d.ts",
"vitest.config.ts"
],
"include": ["src"],
Expand Down
1 change: 1 addition & 0 deletions account-kit/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"!vitest.config.ts",
"!.env",
"!src/**/*.test.ts",
"!src/**/*.test-d.ts",
"!src/__tests__/**/*"
],
"exports": {
Expand Down
1 change: 1 addition & 0 deletions account-kit/core/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"node_modules",
"**/*/__tests__",
"**/*/*.test.ts",
"**/*/*.test-d.ts",
"**/*/*.e2e.test.ts",
"vitest.config.ts",
"vitest.config.e2e.ts"
Expand Down
1 change: 1 addition & 0 deletions account-kit/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"!vitest.config.ts",
"!.env",
"!src/**/*.test.ts",
"!src/**/*.test-d.ts",
"!src/__tests__/**/*"
],
"exports": {
Expand Down
1 change: 1 addition & 0 deletions account-kit/infra/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"node_modules",
"**/*/__tests__",
"**/*/*.test.ts",
"**/*/*.test-d.ts",
"**/*/*.e2e.test.ts",
"vitest.config.ts",
"vitest.config.e2e.ts"
Expand Down
1 change: 1 addition & 0 deletions account-kit/logging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"!vitest.config.ts",
"!.env",
"!src/**/*.test.ts",
"!src/**/*.test-d.ts",
"!src/__tests__/**/*"
],
"exports": {
Expand Down
1 change: 1 addition & 0 deletions account-kit/logging/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"node_modules",
"**/*/__tests__",
"**/*/*.test.ts",
"**/*/*.test-d.ts",
"**/*/*.e2e.test.ts",
"vitest.config.ts",
"vitest.config.e2e.ts"
Expand Down
1 change: 1 addition & 0 deletions account-kit/plugingen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"!vitest.config.ts",
"!.env",
"!src/**/*.test.ts",
"!src/**/*.test-d.ts",
"!src/__tests__/**/*"
],
"exports": {
Expand Down
1 change: 1 addition & 0 deletions account-kit/plugingen/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"node_modules",
"**/*/__tests__",
"**/*/*.test.ts",
"**/*/*.test-d.ts",
"**/*/*.e2e.test.ts",
"vitest.config.ts",
"vitest.config.e2e.ts"
Expand Down
1 change: 1 addition & 0 deletions account-kit/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"!vitest.config.ts",
"!.env",
"!src/**/*.test.ts",
"!src/**/*.test-d.ts",
"!src/__tests__/**/*"
],
"exports": {
Expand Down
1 change: 1 addition & 0 deletions account-kit/react/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"node_modules",
"**/*/__tests__",
"**/*/*.test.ts",
"**/*/*.test-d.ts",
"**/*/*.e2e.test.ts",
"vitest.config.ts",
"vitest.config.e2e.ts",
Expand Down
1 change: 1 addition & 0 deletions account-kit/react/tsconfig.storybook.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"exclude": [
"src/**/*.spec.ts",
"src/**/*.test.ts",
"src/**/*.test-d.ts",
"src/**/*.spec.js",
"src/**/*.test.js",
"src/**/*.spec.tsx",
Expand Down
1 change: 1 addition & 0 deletions account-kit/signer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"!vitest.config.ts",
"!.env",
"!src/**/*.test.ts",
"!src/**/*.test-d.ts",
"!src/__tests__/**/*"
],
"exports": {
Expand Down
1 change: 1 addition & 0 deletions account-kit/signer/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"node_modules",
"**/*/__tests__",
"**/*/*.test.ts",
"**/*/*.test-d.ts",
"**/*/*.e2e.test.ts",
"vitest.config.ts",
"vitest.config.e2e.ts"
Expand Down
1 change: 1 addition & 0 deletions account-kit/smart-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"!vitest.config.ts",
"!.env",
"!src/**/*.test.ts",
"!src/**/*.test-d.ts",
"!src/__tests__/**/*"
],
"exports": {
Expand Down
125 changes: 125 additions & 0 deletions account-kit/smart-contracts/src/light-account/clients/client.test-d.ts
Original file line number Diff line number Diff line change
@@ -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<Client<AlchemyTransport>>(provider);
assertType<AlchemySmartAccountClient>(provider);
assertType<SmartAccountClient>(provider);
assertType<AlchemyEnhancedApis>(provider);
assertType<AlchemyEnhancedApis>(
// @ts-expect-error
await givenAlchemyConnectedProvider({ signer, chain })
);
// @ts-expect-error
assertType<Client<CustomTransport>>(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<SmartAccountClient>(provider);
assertType<Client<CustomTransport>>(provider);
assertType<AlchemyEnhancedApis>(
// @ts-expect-error
await givenAlchemyConnectedProvider({ signer, chain })
);
// @ts-expect-error
assertType<Client<AlchemyTransport>>(provider);
// @ts-expect-error
assertType<AlchemySmartAccountClient>(provider);
// @ts-expect-error
assertType<AlchemyEnhancedApis>(provider);

expect(() => {
const alchemy = new Alchemy({
network: Network.MATIC_MUMBAI,
apiKey: "test",
});

// @ts-expect-error
provider.extend(alchemyEnhancedApiActions(alchemy));
}).not.toBeFalsy();
});
});
Loading

0 comments on commit d97b716

Please sign in to comment.