-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { AlchemyTransport } from "@account-kit/infra"; | ||
import type { AlchemyAccountsConfig } from "../types"; | ||
|
||
export function getAlchemyTransport( | ||
config: AlchemyAccountsConfig | ||
): AlchemyTransport { | ||
return config.store.getState().transport; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as AACoreModule from "@aa-sdk/core"; | ||
import { avalanche } from "viem/chains"; | ||
import { alchemy } from "./alchemyTransport.js"; | ||
import { sepolia } from "./chains.js"; | ||
|
||
describe("Alchemy Transport Tests", () => { | ||
it.each([ | ||
{ rpcUrl: "/api" }, | ||
{ jwt: "test" }, | ||
{ apiKey: "key" }, | ||
{ rpcUrl: "/api", jwt: "jwt" }, | ||
])("should successfully create a non-split transport", (args) => { | ||
expect(() => | ||
alchemy({ | ||
...args, | ||
}) | ||
).not.toThrowError(); | ||
}); | ||
|
||
it.each([ | ||
{ rpcUrl: "/api" }, | ||
{ jwt: "test" }, | ||
{ apiKey: "key" }, | ||
{ rpcUrl: "/api", jwt: "jwt" }, | ||
])("should correctly create a split transport", (args) => { | ||
const splitSpy = vi.spyOn(AACoreModule, "split"); | ||
alchemy({ | ||
alchemyConnection: args, | ||
nodeRpcUrl: "/test", | ||
})({ chain: sepolia }); | ||
|
||
expect(splitSpy.mock.calls.length).toBe(1); | ||
expect(splitSpy.mock.calls[0]).toMatchSnapshot(); | ||
Check failure on line 33 in account-kit/infra/src/alchemyTransport.test.ts GitHub Actions / Build and Testsrc/alchemyTransport.test.ts > Alchemy Transport Tests > should correctly create a split transport
Check failure on line 33 in account-kit/infra/src/alchemyTransport.test.ts GitHub Actions / Build and Testsrc/alchemyTransport.test.ts > Alchemy Transport Tests > should correctly create a split transport
Check failure on line 33 in account-kit/infra/src/alchemyTransport.test.ts GitHub Actions / Build and Testsrc/alchemyTransport.test.ts > Alchemy Transport Tests > should correctly create a split transport
Check failure on line 33 in account-kit/infra/src/alchemyTransport.test.ts GitHub Actions / Build and Testsrc/alchemyTransport.test.ts > Alchemy Transport Tests > should correctly create a split transport
|
||
}); | ||
|
||
it("should correctly do runtime validation when chain is not supported by Alchemy", () => { | ||
expect(() => alchemy({ rpcUrl: "/test" })({ chain: avalanche })) | ||
.toThrowErrorMatchingInlineSnapshot(` | ||
[ZodError: [ | ||
{ | ||
"code": "custom", | ||
"message": "chain must include an alchemy rpc url. See \`createAlchemyChain\` or import a chain from \`@account-kit/infra\`.", | ||
"fatal": true, | ||
"path": [] | ||
} | ||
]] | ||
`); | ||
}); | ||
}); |