@coinbase/onchaintestkit
Version:
End-to-end testing toolkit for blockchain applications, powered by Playwright
42 lines (41 loc) • 1.7 kB
TypeScript
import { test as base } from "@playwright/test";
import { OnchainFixtures, WalletFixtureOptions } from "./types";
/**
* Creates a Playwright test instance with wallet-specific fixtures based on provided options.
*
* This function enables testing with different web3 wallets (MetaMask, Coinbase) by:
* 1. Taking wallet configuration options
* 2. Creating appropriate test fixtures for each enabled wallet
* 3. Combining multiple wallet fixtures if needed
* 4. Automatically including network interception when a local node is configured
*
* @param config - Configuration object from the config builder
* @param config.options - Wallet configuration options
* @param config.skipNodeFixture - When true, doesn't create a node fixture (useful when nodes are created in wallet fixtures)
* @returns A Playwright test instance extended with wallet-specific fixtures
* @throws Error if no wallet fixtures are found in the options
*
* @example
* ```typescript
* import { metamaskWalletConfig } from './walletConfig/metamaskWalletConfig';
* import { createOnchainTest, configure } from './onchainTestKit';
*
* const test = createOnchainTest(
* configure()
* .withLocalNode({ chainId: 1337 })
* .withMetaMask()
* .withNetwork({
* name: 'Base Sepolia',
* chainId: baseSepolia.id,
* symbol: 'ETH',
* rpcUrl: 'http://localhost:8545',
* })
* .build()
* );
*
* test('connect wallet and swap', async ({ page, metamask, node }) => {
* await metamask.handleAction(BaseActionType.CONNECT_TO_DAPP);
* });
* ```
*/
export declare function createOnchainTest(options: WalletFixtureOptions): ReturnType<typeof base.extend<OnchainFixtures>>;