-
-
Notifications
You must be signed in to change notification settings - Fork 2
Enhance fork mode documentation with plain-English explanations and comprehensive troubleshooting #26
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
Enhance fork mode documentation with plain-English explanations and comprehensive troubleshooting #26
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -367,6 +367,104 @@ const config = configure() | |||||
| .build(); | ||||||
| ``` | ||||||
|
|
||||||
| #### 7. Memory and Performance Issues | ||||||
|
|
||||||
| **Problem**: High memory usage or slow performance during testing | ||||||
|
|
||||||
| **Solutions**: | ||||||
| - Limit the number of test accounts to reduce memory overhead | ||||||
| - Use specific block numbers instead of latest to reduce state size | ||||||
| - Close nodes properly after tests to free memory | ||||||
| - Consider using lighter RPC providers for non-critical tests | ||||||
|
|
||||||
| ```typescript | ||||||
| // Memory-optimized configuration | ||||||
| const config = configure() | ||||||
| .withLocalNode({ | ||||||
| fork: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key', | ||||||
| forkBlockNumber: 18500000, // Specific block reduces memory | ||||||
| accounts: 3, // Fewer accounts = less memory | ||||||
| balance: '10000000000000000000', // 10 ETH is usually sufficient | ||||||
| gasPrice: '1000000000', // 1 gwei for faster execution | ||||||
| }) | ||||||
| .build(); | ||||||
| ``` | ||||||
|
|
||||||
| #### 8. Transaction Failures on Fork | ||||||
|
|
||||||
| **Problem**: Transactions that work on mainnet fail on the fork | ||||||
|
|
||||||
| **Solutions**: | ||||||
| - Check that the fork block has the necessary contract state | ||||||
| - Verify account balances are sufficient for the transaction | ||||||
| - Ensure gas limits are appropriate for the forked network | ||||||
| - Check that the contract exists at the expected address on the fork block | ||||||
|
|
||||||
| ```typescript | ||||||
| // Debug transaction failures | ||||||
| const config = configure() | ||||||
| .withLocalNode({ | ||||||
| fork: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key', | ||||||
| forkBlockNumber: 18500000, | ||||||
| accounts: 10, | ||||||
| balance: '1000000000000000000000', // Large balance for debugging | ||||||
| gasPrice: '20000000000', // Higher gas price | ||||||
| gasLimit: '30000000', // Higher gas limit | ||||||
| }) | ||||||
| .build(); | ||||||
| ``` | ||||||
|
|
||||||
| #### 9. RPC Rate Limiting | ||||||
|
|
||||||
| **Problem**: `Error: Too many requests` or connection timeouts | ||||||
|
|
||||||
| **Solutions**: | ||||||
| - Upgrade to a paid RPC provider plan | ||||||
| - Use multiple RPC endpoints and rotate between them | ||||||
| - Add delays between requests during setup | ||||||
| - Cache fork state when possible | ||||||
|
|
||||||
| ```typescript | ||||||
| // Rate limit friendly configuration | ||||||
| const config = configure() | ||||||
| .withLocalNode({ | ||||||
| fork: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key', | ||||||
| forkBlockNumber: 18500000, // Specific block reduces requests | ||||||
| accounts: 5, // Fewer accounts = fewer setup requests | ||||||
| }) | ||||||
| .build(); | ||||||
| ``` | ||||||
|
|
||||||
| #### 10. Network-Specific Issues | ||||||
|
|
||||||
| **Problem**: Certain features don't work as expected on different networks | ||||||
|
|
||||||
| **Solutions**: | ||||||
| - Verify the network supports the features you're testing | ||||||
| - Check block explorer for contract deployment blocks | ||||||
| - Use network-appropriate gas prices and limits | ||||||
| - Verify the RPC endpoint supports the specific network features | ||||||
|
|
||||||
| ```typescript | ||||||
| // Network-specific optimizations | ||||||
| const polygonConfig = configure() | ||||||
| .withLocalNode({ | ||||||
| fork: 'https://polygon-mainnet.g.alchemy.com/v2/your-api-key', | ||||||
| chainId: 137, | ||||||
| gasPrice: '30000000000', // Higher gas price for Polygon | ||||||
| forkBlockNumber: 50000000, // Recent Polygon block | ||||||
| }) | ||||||
| .build(); | ||||||
|
|
||||||
| const arbitrumConfig = configure() | ||||||
| .withLocalNode({ | ||||||
| fork: 'https://arb-mainnet.g.alchemy.com/v2/your-api-key', | ||||||
| chainId: 42161, | ||||||
| gasPrice: '100000000', // Lower gas price for Arbitrum | ||||||
| }) | ||||||
| .build(); | ||||||
| ``` | ||||||
|
|
||||||
| ### Performance Optimization | ||||||
|
|
||||||
| #### 1. Choose the Right Block Number | ||||||
|
|
@@ -404,4 +502,57 @@ const config = configure() | |||||
| 4. **Cache fork state** when possible to speed up subsequent runs | ||||||
| 5. **Monitor RPC usage** to avoid hitting rate limits | ||||||
| 6. **Clean up nodes** after tests to free resources | ||||||
| 7. **Use appropriate gas settings** for your test scenarios | ||||||
| 7. **Use appropriate gas settings** for your test scenarios | ||||||
|
|
||||||
| ### Debugging Tips | ||||||
|
|
||||||
| When fork mode isn't working as expected, here are some debugging strategies: | ||||||
|
|
||||||
| #### Enable Verbose Logging | ||||||
|
|
||||||
| ```typescript | ||||||
| // Add logging to understand what's happening | ||||||
| const config = configure() | ||||||
| .withLocalNode({ | ||||||
| fork: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key', | ||||||
| forkBlockNumber: 18500000, | ||||||
| // Add these for debugging | ||||||
| verbose: true, // Enable detailed logging | ||||||
| debug: true, // Show debug information | ||||||
| }) | ||||||
| .build(); | ||||||
| ``` | ||||||
|
|
||||||
| #### Test Fork Connection First | ||||||
|
|
||||||
| ```typescript | ||||||
| // Simple test to verify fork is working | ||||||
| test('verify fork connection', async ({ node }) => { | ||||||
| // Check that we can query basic blockchain data | ||||||
| const blockNumber = await node.getBlockNumber(); | ||||||
| expect(blockNumber).toBeGreaterThan(18500000); | ||||||
|
|
||||||
| // Check that we have test accounts with balance | ||||||
| const balance = await node.getBalance('0x...'); // Your test account address | ||||||
|
||||||
| const balance = await node.getBalance('0x...'); // Your test account address | |
| const balance = await node.getBalance('0x1234...5678'); // Your test account address |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -67,16 +67,19 @@ const test = createOnchainTest( | |||||||||
|
|
||||||||||
| ### Testing DeFi Interactions | ||||||||||
|
|
||||||||||
| This example shows how to test lending protocol interactions using real Aave contracts and liquidity: | ||||||||||
|
|
||||||||||
| ```typescript | ||||||||||
| // Test lending protocol interactions with real liquidity | ||||||||||
| const test = createOnchainTest( | ||||||||||
| configure() | ||||||||||
| .withLocalNode({ | ||||||||||
| fork: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key', | ||||||||||
| forkBlockNumber: 18500000, | ||||||||||
| forkBlockNumber: 18500000, // Use a known good block with stable state | ||||||||||
|
||||||||||
| forkBlockNumber: 18500000, // Use a known good block with stable state | |
| forkBlockNumber: 18500000, // Use a recent, finalized block where the protocol state is stable. | |
| // Choose a block that is not during a major upgrade or reorg, and ideally after all relevant transactions have settled. | |
| // You can find suitable block numbers using a block explorer (e.g., Etherscan) by looking for blocks just before or after important events. |
Copilot
AI
Sep 24, 2025
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.
[nitpick] Using a specific NFT collection (BAYC) in the example may become outdated or unavailable. Consider using a more generic example or explaining how developers should substitute their own collection URLs.
| await page.goto('https://opensea.io/collection/bored-ape-yacht-club'); | |
| // Replace <your-nft-collection> with your desired NFT collection slug | |
| await page.goto('https://opensea.io/collection/<your-nft-collection>'); |
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.
The comment suggests that using a specific block number reduces memory usage, but this isn't necessarily accurate. Specific block numbers provide reproducibility, while using 'latest' might actually use more memory due to ongoing state changes. The comment should clarify this distinction.