Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(test-d): add test-d files for vitest typechecking: #1248

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to make sure that during the run we test our new function

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

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,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When testing, files that just don't typecheck, ie the multisig account
Will fail this step without this set as true
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah we should just exclude this file from the test sets since later we'll delete this file. That way the other tests can at least get caught as well. We've had cases where code built no prob but it ruined some branch of the types and we didn't notice cuz the tests don't get type checked

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They already are excluded in the tests btw, just the typecheck will check non test files that are excluded.

},
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",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyplace that I found .test.ts I add the test-dvariant

"!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
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
Loading