|
| 1 | +# AI Coding Agents Configuration |
| 2 | + |
| 3 | +This directory contains configuration and guidelines for AI coding agents working with the Onchain Test Kit repository. These instructions help coding agents understand the project structure, development workflows, and best practices. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The Onchain Test Kit is an end-to-end testing toolkit for blockchain applications, powered by Playwright. This repository supports multiple AI coding agents with specialized instructions to help them work effectively on blockchain testing scenarios. |
| 8 | + |
| 9 | +## Quick Start for Agents |
| 10 | + |
| 11 | +```bash |
| 12 | +# 1. Setup the development environment |
| 13 | +npm install && npm run build && npm run test |
| 14 | + |
| 15 | +# 2. Prepare wallet extensions for testing |
| 16 | +npm run prepare-metamask |
| 17 | + |
| 18 | +# 3. Configure environment variables |
| 19 | +cp .env.example .env |
| 20 | +# Edit .env to add E2E_TEST_SEED_PHRASE (test-only seed phrase) |
| 21 | +``` |
| 22 | + |
| 23 | +## Documentation Structure |
| 24 | + |
| 25 | +### Primary Instructions |
| 26 | +- **[`.github/copilot-instructions.md`](../copilot-instructions.md)** - Main instructions for GitHub Copilot and general AI agents |
| 27 | +- **[`AGENTS.md`](../../AGENTS.md)** - Comprehensive guide for all AI coding agents |
| 28 | +- **[`CLAUDE.md`](../../CLAUDE.md)** - Claude AI-specific optimizations and patterns |
| 29 | +- **[`GEMINI.md`](../../GEMINI.md)** - Gemini AI rapid development workflows |
| 30 | + |
| 31 | +### Specialized Instructions |
| 32 | +- **[`development.instructions.md`](../instructions/development.instructions.md)** - Development environment and coding standards |
| 33 | +- **[`testing.instructions.md`](../instructions/testing.instructions.md)** - Comprehensive testing strategies |
| 34 | +- **[`wallet-integration.instructions.md`](../instructions/wallet-integration.instructions.md)** - Wallet-specific implementation patterns |
| 35 | + |
| 36 | +## Key Concepts for Agents |
| 37 | + |
| 38 | +### Repository Purpose |
| 39 | +This toolkit enables end-to-end testing of blockchain applications with: |
| 40 | +- Automated wallet interactions (MetaMask, Coinbase Wallet, Phantom) |
| 41 | +- Fork mode testing against real blockchain data |
| 42 | +- Type-safe configuration using TypeScript |
| 43 | +- Cross-chain testing capabilities |
| 44 | + |
| 45 | +### Core Technologies |
| 46 | +- **TypeScript** (strict mode, no `any` types) |
| 47 | +- **Playwright** for browser automation |
| 48 | +- **Viem** for Ethereum interactions |
| 49 | +- **Biome** for linting and formatting |
| 50 | +- **Anvil/Foundry** for local blockchain nodes |
| 51 | + |
| 52 | +### Architecture Principles |
| 53 | + |
| 54 | +#### 1. Fluent Configuration API |
| 55 | +```typescript |
| 56 | +const config = configure() |
| 57 | + .withLocalNode({ fork: rpcUrl, chainId: 1 }) |
| 58 | + .withMetaMask() |
| 59 | + .withSeedPhrase({ seedPhrase, password }) |
| 60 | + .withNetwork({ name, rpcUrl, chainId, symbol }) |
| 61 | + .build(); |
| 62 | +``` |
| 63 | + |
| 64 | +#### 2. Test Creation Pattern |
| 65 | +```typescript |
| 66 | +const test = createOnchainTest(config); |
| 67 | + |
| 68 | +test('wallet interaction', async ({ page, metamask, node }) => { |
| 69 | + await page.goto('http://localhost:3000'); |
| 70 | + await metamask.handleAction('connect', { shouldApprove: true }); |
| 71 | + await expect(page.getByTestId('connected')).toBeVisible(); |
| 72 | +}); |
| 73 | +``` |
| 74 | + |
| 75 | +#### 3. Wallet Action Abstraction |
| 76 | +All wallet interactions use a unified action interface: |
| 77 | +- `connect` - Connect wallet to DApp |
| 78 | +- `transaction` - Approve/reject transactions |
| 79 | +- `signature` - Sign messages |
| 80 | +- `switchNetwork` - Change networks |
| 81 | +- `tokenApproval` - Approve token spending |
| 82 | + |
| 83 | +## Development Guidelines |
| 84 | + |
| 85 | +### Code Quality Standards |
| 86 | +- **TypeScript strict mode** - No implicit `any`, proper typing required |
| 87 | +- **Biome linting** - Run `npm run lint:fix` before committing |
| 88 | +- **Comprehensive testing** - All features require tests |
| 89 | +- **Documentation** - Update README and docs for API changes |
| 90 | + |
| 91 | +### Build and Test Workflow |
| 92 | +```bash |
| 93 | +# Standard development cycle |
| 94 | +npm run build # Compile TypeScript |
| 95 | +npm run lint:fix # Fix formatting and style |
| 96 | +npm run test # Run Playwright tests |
| 97 | +``` |
| 98 | + |
| 99 | +### Testing Philosophy |
| 100 | +- **End-to-end focus** - Test complete user workflows |
| 101 | +- **Fork mode realism** - Use real blockchain data when possible |
| 102 | +- **Cross-wallet compatibility** - Ensure features work with all supported wallets |
| 103 | +- **Type safety** - Leverage TypeScript for compile-time verification |
| 104 | + |
| 105 | +## Agent-Specific Guidance |
| 106 | + |
| 107 | +### For GitHub Copilot |
| 108 | +- Use descriptive function/variable names for better suggestions |
| 109 | +- Add JSDoc comments for complex functions |
| 110 | +- Follow existing patterns for consistent completions |
| 111 | +- Read `.github/copilot-instructions.md` for detailed guidance |
| 112 | + |
| 113 | +### For Claude AI |
| 114 | +- Focus on comprehensive analysis and edge cases |
| 115 | +- Design thorough test coverage strategies |
| 116 | +- Consider blockchain complexity and multi-chain scenarios |
| 117 | +- Read `CLAUDE.md` for deep analysis patterns |
| 118 | + |
| 119 | +### For Gemini AI |
| 120 | +- Start with simple, working implementations |
| 121 | +- Iterate quickly with fast feedback cycles |
| 122 | +- Focus on user experience and performance |
| 123 | +- Read `GEMINI.md` for rapid development workflows |
| 124 | + |
| 125 | +### For Other Agents |
| 126 | +- Follow patterns in `AGENTS.md` |
| 127 | +- Maintain consistency with established code structure |
| 128 | +- Prioritize type safety and comprehensive testing |
| 129 | +- Adapt guidelines as needed for your specific capabilities |
| 130 | + |
| 131 | +## Critical Files for Agents |
| 132 | + |
| 133 | +### Core API Surface |
| 134 | +- **`src/configBuilder.ts`** - Main configuration API (changes affect all users) |
| 135 | +- **`src/createOnchainTest.ts`** - Core test setup logic |
| 136 | +- **`src/wallets/*/index.ts`** - Wallet-specific implementations |
| 137 | + |
| 138 | +### Build and CLI |
| 139 | +- **`package.json`** - Build scripts and dependencies |
| 140 | +- **`tsconfig.json`** - TypeScript configuration |
| 141 | +- **`biome.json`** - Linting and formatting rules |
| 142 | +- **`src/cli/*.mjs`** - Wallet preparation scripts |
| 143 | + |
| 144 | +### Testing Infrastructure |
| 145 | +- **`tests/`** - Test files and fixtures |
| 146 | +- **`playwright.config.ts`** - Playwright configuration |
| 147 | + |
| 148 | +## Common Tasks |
| 149 | + |
| 150 | +### Adding Wallet Support |
| 151 | +1. Create `src/wallets/NewWallet/` directory |
| 152 | +2. Implement wallet class extending BaseWallet |
| 153 | +3. Add Playwright fixtures |
| 154 | +4. Create CLI preparation script |
| 155 | +5. Update configuration builder |
| 156 | +6. Add comprehensive tests |
| 157 | + |
| 158 | +### Adding Wallet Actions |
| 159 | +1. Define action type in base interfaces |
| 160 | +2. Implement in all wallet classes |
| 161 | +3. Add parameter validation |
| 162 | +4. Create tests for all wallets |
| 163 | +5. Update documentation |
| 164 | + |
| 165 | +### Configuration Changes |
| 166 | +1. Maintain backward compatibility |
| 167 | +2. Add validation for new parameters |
| 168 | +3. Update type definitions |
| 169 | +4. Provide migration guides if breaking |
| 170 | + |
| 171 | +## Known Issues |
| 172 | + |
| 173 | +### Wallet Extensions |
| 174 | +- ✅ **MetaMask** - Works correctly |
| 175 | +- ⚠️ **Coinbase Wallet** - Extension download currently broken (upstream issue) |
| 176 | +- ⚠️ **Phantom** - Extension download currently broken (upstream issue) |
| 177 | + |
| 178 | +### Environment Requirements |
| 179 | +- Node.js >= 14.0.0 (recommended >= 18.0.0) |
| 180 | +- Foundry for local blockchain testing |
| 181 | +- Test-only seed phrases (NEVER use real funds) |
| 182 | + |
| 183 | +## Best Practices for Agents |
| 184 | + |
| 185 | +### 1. Understand Before Changing |
| 186 | +- Read relevant instruction files before making changes |
| 187 | +- Build and test to understand current state |
| 188 | +- Identify patterns in existing code |
| 189 | +- Check for similar implementations |
| 190 | + |
| 191 | +### 2. Make Minimal Changes |
| 192 | +- Focus on the specific issue or feature |
| 193 | +- Avoid refactoring unrelated code |
| 194 | +- Maintain existing patterns and style |
| 195 | +- Test changes incrementally |
| 196 | + |
| 197 | +### 3. Maintain Type Safety |
| 198 | +- Use proper TypeScript types throughout |
| 199 | +- Leverage discriminated unions for action types |
| 200 | +- Ensure proper async/await typing |
| 201 | +- Avoid using `any` type |
| 202 | + |
| 203 | +### 4. Comprehensive Testing |
| 204 | +- Add tests for new functionality |
| 205 | +- Test edge cases and error conditions |
| 206 | +- Ensure cross-wallet compatibility |
| 207 | +- Use fork mode for realistic scenarios |
| 208 | + |
| 209 | +### 5. Documentation |
| 210 | +- Update README for API changes |
| 211 | +- Add JSDoc comments for public APIs |
| 212 | +- Include usage examples |
| 213 | +- Keep documentation current |
| 214 | + |
| 215 | +## Getting Help |
| 216 | + |
| 217 | +If you encounter issues or need clarification: |
| 218 | +1. Check the relevant instruction files listed above |
| 219 | +2. Review existing code for similar patterns |
| 220 | +3. Consult CONTRIBUTING.md for contribution guidelines |
| 221 | +4. Check README.md for project overview |
| 222 | + |
| 223 | +## Security Considerations |
| 224 | + |
| 225 | +- Never commit real seed phrases or private keys |
| 226 | +- Use test-only credentials in .env files |
| 227 | +- Validate user inputs in wallet interactions |
| 228 | +- Handle sensitive data appropriately |
| 229 | + |
| 230 | +--- |
| 231 | + |
| 232 | +**Remember**: This toolkit focuses on making blockchain testing accessible and reliable. Prioritize clear APIs, comprehensive error handling, and type safety over premature optimization. |
0 commit comments