-
Notifications
You must be signed in to change notification settings - Fork 135
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ import { configDefaults, defineConfig } from "vitest/config"; | |
|
||
export const sharedConfig = defineConfig({ | ||
test: { | ||
typecheck: { | ||
ignoreSourceErrors: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"), | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
"!vitest.config.ts", | ||
"!.env", | ||
"!src/**/*.test.ts", | ||
"!src/**/*.test-d.ts", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anyplace that I found |
||
"!src/__tests__/**/*" | ||
], | ||
"exports": { | ||
|
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(); | ||
}); | ||
}); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.