diff --git a/packages/core/src/actions/getClient.test-d.ts b/packages/core/src/actions/getClient.test-d.ts deleted file mode 100644 index 0e2f3602ff..0000000000 --- a/packages/core/src/actions/getClient.test-d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { chain, config } from '@wagmi/test' -import { expectTypeOf, test } from 'vitest' - -import { getClient } from './getClient.js' - -test('default', () => { - const client = getClient(config) - expectTypeOf(client.chain).toEqualTypeOf() - expectTypeOf(client.transport.type).toEqualTypeOf<'http'>() -}) - -test('parameters: chainId', () => { - const client = getClient(config, { - chainId: chain.mainnet.id, - }) - expectTypeOf(client.chain).toEqualTypeOf() - expectTypeOf(client.chain).not.toEqualTypeOf() - expectTypeOf(client.transport.type).toEqualTypeOf<'http'>() -}) - -test('behavior: unconfigured chain', () => { - const client = getClient(config, { - // @ts-expect-error - chainId: 123456, - }) - expectTypeOf(client).toEqualTypeOf() -}) diff --git a/packages/core/src/actions/getClient.test.ts b/packages/core/src/actions/getClient.test.ts index 9eb0fa574b..ec93998a34 100644 --- a/packages/core/src/actions/getClient.test.ts +++ b/packages/core/src/actions/getClient.test.ts @@ -1,6 +1,10 @@ -import { config } from '@wagmi/test' -import { expect, test } from 'vitest' +import { chain, config } from '@wagmi/test' +import { expect, expectTypeOf, test } from 'vitest' +import { http } from 'viem' +import { waitForTransactionReceipt } from '../actions/waitForTransactionReceipt.js' +import { createConfig } from '../createConfig.js' +import { optimism, optimismSepolia } from '../exports/chains.js' import { getClient } from './getClient.js' test('default', () => { @@ -15,3 +19,50 @@ test('behavior: unconfigured chain', () => { }), ).toBeUndefined() }) + +test('default', () => { + const client = getClient(config) + expectTypeOf(client.chain).toEqualTypeOf() + expectTypeOf(client.transport.type).toEqualTypeOf<'http'>() +}) + +test('parameters: chainId', () => { + const client = getClient(config, { + chainId: chain.mainnet.id, + }) + expectTypeOf(client.chain).toEqualTypeOf() + expectTypeOf(client.chain).not.toEqualTypeOf() + expectTypeOf(client.transport.type).toEqualTypeOf<'http'>() +}) + +test('behavior: viem actions', () => { + const viemActionChains = [optimismSepolia, optimism] as const + const viemActionsTransports = { + [optimismSepolia.id]: http(), + [optimism.id]: http(), + } as const + const configObject = { + chains: viemActionChains, + transports: viemActionsTransports, + } as const + + const config = createConfig(configObject) + + const client = getClient(config) + + waitForTransactionReceipt( + { + ...config, + client, + }, + { hash: '0x…' }, + ) +}) + +test('behavior: unconfigured chain', () => { + const client = getClient(config, { + // @ts-expect-error + chainId: 123456, + }) + expectTypeOf(client).toEqualTypeOf() +}) diff --git a/playgrounds/vite-react/src/App.tsx b/playgrounds/vite-react/src/App.tsx index 86c0b11266..f9e44e36d5 100644 --- a/playgrounds/vite-react/src/App.tsx +++ b/playgrounds/vite-react/src/App.tsx @@ -7,6 +7,7 @@ import { useBalance, useBlockNumber, useChainId, + useClient, useConnect, useConnections, useConnectorClient, @@ -24,6 +25,7 @@ import { import { optimism } from 'wagmi/chains' import { wagmiContractConfig } from './contracts' +import { ChainIds, config } from './wagmi' function App() { useAccountEffect({ @@ -138,7 +140,7 @@ function SwitchChain() {