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 Jan 8, 2025
1 parent a0fdd71 commit d973a94
Show file tree
Hide file tree
Showing 28 changed files with 157 additions and 129 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ jobs:

- name: Unit Test
run: yarn test:ci

- name: Typecheck Test
run: yarn test:typecheck

build_ios:
name: Build iOS
Expand Down Expand Up @@ -131,3 +134,4 @@ jobs:
- name: Build example for iOS
run: |
yarn turbo run build:ios
3 changes: 3 additions & 0 deletions .vitest/vitest.shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { configDefaults, defineConfig } from "vitest/config";

export const sharedConfig = defineConfig({
test: {
typecheck: {
ignoreSourceErrors: true,
},
alias: {
"~test": join(__dirname, "./src"),
},
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**:

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 d973a94

Please sign in to comment.