UNPKG

@coinbase/onchaintestkit

Version:

End-to-end testing toolkit for blockchain applications, powered by Playwright

134 lines (133 loc) 4.15 kB
import { NodeConfig } from "./node/types"; import { WalletFixtureOptions } from "./types"; import { BaseWalletConfig, WalletSetupContext } from "./wallets/BaseWallet"; import { CoinbaseWallet } from "./wallets/Coinbase"; import { MetaMask } from "./wallets/MetaMask"; /** * Configuration builder for E2E testing with different wallet types. * Provides a fluent interface for configuring wallet behavior and setup. * * @example Basic Usage * ```typescript * const test = createOnchainTest( * configure() * .withLocalNode({ chainId: 1337 }) * .withMetaMask() * .withNetwork({ * name: 'Base Sepolia', * rpcUrl: 'https://sepolia.base.org', * chainId: 84532, * symbol: 'ETH', * }) * .build() * ); * ``` * * @example Complete Setup * ```typescript * const test = createOnchainTest( * configure() * .withLocalNode({ chainId: 1337 }) * .withMetaMask() * .withNetwork({ * name: 'Base Sepolia', * rpcUrl: 'https://sepolia.base.org', * chainId: 84532, * symbol: 'ETH', * }) * .withSeedPhrase({ * seedPhrase: 'your seed phrase', * password: 'your password', * }) * .withCustomSetup(async (wallet) => { * await wallet.importToken('0x...'); * }) * .build() * ); * ``` */ import { NetworkConfig } from "./wallets/types"; type WalletType = MetaMask | CoinbaseWallet; /** * Base configuration builder that handles common wallet setup */ declare abstract class BaseWalletBuilder<T extends WalletType> { protected nodeConfig?: NodeConfig; protected config: Partial<BaseWalletConfig>; constructor(config: Partial<BaseWalletConfig>); /** * Helper method to chain multiple setup functions together. * Ensures setup functions are executed in the order they were added. */ protected chainSetup(newSetup: (wallet: T, context: WalletSetupContext) => Promise<void>): void; /** * Configure wallet with a seed phrase and optional password * @param seedPhrase - The wallet's seed phrase * @param password - Optional password for the wallet */ withSeedPhrase({ seedPhrase, password, }: { seedPhrase: string; password?: string; }): this; /** * Add custom setup steps to the wallet configuration * @param setupFn - Custom function to perform additional wallet setup */ withCustomSetup(setupFn: (wallet: T) => Promise<void>): this; setNodeConfig(config?: NodeConfig): void; /** * Build the final wallet configuration * @returns WalletFixtureOptions ready to be used with createOnchainTest */ build(): WalletFixtureOptions; } /** * MetaMask-specific configuration builder * Extends base builder with MetaMask-specific functionality */ declare class MetaMaskConfigBuilder extends BaseWalletBuilder<MetaMask> { withNetwork(network: NetworkConfig): this; } /** * Coinbase-specific configuration builder * Extends base builder with Coinbase-specific functionality */ declare class CoinbaseConfigBuilder extends BaseWalletBuilder<CoinbaseWallet> { withNetwork(network: NetworkConfig): this; } /** * Main configuration builder that initializes wallet-specific builders */ export declare class ConfigBuilder { private config; private nodeConfig?; /** * Initialize MetaMask configuration * @returns MetaMask-specific builder */ withMetaMask(): MetaMaskConfigBuilder; /** * Initialize Coinbase configuration * @returns Coinbase-specific builder */ withCoinbase(): CoinbaseConfigBuilder; /** * Configure the local Anvil node * @param config - Node configuration options * @returns This builder for chaining */ withLocalNode(config?: NodeConfig): this; /** * Build the final configuration * @returns Configuration object ready to be used with createOnchainTest */ build(): { options: WalletFixtureOptions; }; } /** * Creates a new configuration builder * @returns ConfigBuilder instance */ export declare function configure(): ConfigBuilder; export {};