mirror of
https://github.com/datahaven-xyz/datahaven
synced 2026-05-23 17:28:23 +00:00
## Implement E2E Testing Framework with Isolated Networks ### Summary Refactors the existing E2E testing infrastructure to provide isolated test environments with parallel execution support. Each test suite now runs in its own network namespace, preventing resource conflicts. ### Key Changes - **New Testing Framework** (`test/framework/`): Base classes for test lifecycle management with automatic setup/teardown - **Launcher Module** (`test/launcher/`): Extracted network orchestration logic from CLI handlers for reusability - **Parallel Execution**: Added `test-parallel.ts` script with concurrency limits to prevent resource exhaustion - **Test Isolation**: Each suite gets unique network IDs (format: `suiteName-timestamp`) and Docker networks - **Improved Test Organization**: Migrated tests to new framework, deprecated old test structure ### Test Improvements - Added 4 new test suites demonstrating framework usage. : - `contracts.test.ts` - Smart contract deployment/interaction - `datahaven-substrate.test.ts` - Substrate API operations - `cross-chain.test.ts` - Snowbridge cross-chain messaging - `ethereum-basic.test.ts` - Ethereum network operations > [!WARNING] The test suites themselves are bad and shouldn't be consider examples of good tests. They were AI generated just to test the concurrency of test runners ### Documentation - Added comprehensive framework overview (`E2E_FRAMEWORK_OVERVIEW.md`) - Updated README with parallel testing commands - Added test patterns and best practices ### Breaking Changes - Old test suites moved to `e2e - DEPRECATED/` directory - Test execution now requires extending `BaseTestSuite` class ### Testing Run tests with: `bun test:e2e` or `bun test:e2e:parallel` (with concurrency limits) ### TODO - [ ] Implement good test examples. - [ ] Implement useful test utils (like waiting for an event to show up in DataHaven or Ethereum). - [ ] Enforce tests with CI (currently cannot be done due to intermittent error when sending a transaction with PAPI). --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: undercover-cactus <lola@moonsonglabs.com>
4.6 KiB
4.6 KiB
E2E Testing Framework Overview
This document provides a concise overview of the DataHaven E2E testing framework architecture and usage.
Architecture
The E2E testing framework creates isolated test environments for comprehensive integration testing of the DataHaven network, including EigenLayer AVS integration, EVM compatibility, and cross-chain functionality.
Directory Structure
test/
├── suites/ # Test files (*.test.ts)
├── framework/ # Base classes and test utilities
├── launcher/ # Network orchestration code
├── utils/ # Common helpers and utilities
├── configs/ # Component configuration files
├── scripts/ # Automation scripts
└── cli/ # Interactive network management
Test Isolation
- Each test suite extends
BaseTestSuitefor lifecycle management - Unique network IDs prevent resource conflicts (format:
suiteName-timestamp) - Automatic setup/teardown via
beforeAll/afterAllhooks - Independent Docker networks per test suite
Infrastructure Stack
Core Components
-
Kurtosis: Orchestrates Ethereum test networks
- Runs EL (reth) and CL (lodestar) clients
- Configurable parameters (slot time, validators)
- Optional Blockscout explorer integration
-
Docker: Containerizes all components
- DataHaven validator nodes
- Snowbridge relayers
- Test infrastructure
- Cross-platform support (Linux/macOS)
-
Bun: TypeScript runtime and test runner
- Parallel test execution
- Resource management
- Interactive CLI tooling
Network Launch Sequence
The launchNetwork function orchestrates the following steps:
- Validation: Check dependencies, create unique network ID
- DataHaven Launch: Start validator nodes (Alice, Bob) in Docker
- Ethereum Network: Spin up via Kurtosis with fast slot times
- Contract Deployment: Deploy EigenLayer AVS contracts via Forge
- Configuration: Fund accounts, setup validators, set parameters
- Snowbridge: Launch relayers for cross-chain messaging
- Cleanup: Automatic teardown on completion/failure
Test Development
Basic Test Structure
import { BaseTestSuite } from "../framework/base-test-suite";
class MyTestSuite extends BaseTestSuite {
constructor() {
super({ suiteName: "my-test" });
this.setupHooks(); // Manages lifecycle
}
}
const suite = new MyTestSuite();
describe("My Test Suite", () => {
test("should do something", async () => {
const connectors = suite.getTestConnectors();
// Use connectors.publicClient, walletClient, dhApi, papiClient
});
});
Available Connectors
publicClient: Viem public client for Ethereum readswalletClient: Viem wallet client for transactionsdhApi: DataHaven Substrate APIpapiClient: Polkadot-API client
Key Tools & Dependencies
Blockchain Interaction
- Viem: Ethereum client library
- Wagmi: Contract TypeScript bindings
- Polkadot-API: Substrate chain interactions
- Forge: Smart contract toolchain
Development Tools
- TypeScript: Type safety
- Biome: Code formatting/linting
- Zod: Runtime validation
- Commander: CLI framework
Common Commands
# Install dependencies
bun i
# Launch interactive network manager
bun cli
# Run all E2E tests
bun test:e2e
# Run tests with concurrency limit
bun test:e2e:parallel
# Run specific test suite
bun test suites/contracts.test.ts
# Generate contract bindings
bun generate:wagmi
# Generate Polkadot types
bun generate:types
# Format code
bun fmt:fix
# Type checking
bun typecheck
Network Configuration
Default Test Network
- DataHaven: 2 validator nodes (Alice, Bob)
- Ethereum: 2 EL/CL pairs, 1-second slots
- Contracts: Full EigenLayer AVS deployment
- Snowbridge: Beacon and Ethereum relayers
Customization Options
- Build local Docker images
- Enable Blockscout verification
- Adjust slot times
- Configure validator counts
Troubleshooting
- Dependency Issues: Ensure Docker, Kurtosis, and Bun are installed
- Port Conflicts: Check for existing services on required ports
- Resource Limits: Adjust test concurrency if running out of resources
- Cleanup Failures: Use
bun cli stop --Ato manually clean up networks
Best Practices
- Always extend
BaseTestSuitefor proper lifecycle management - Use unique suite names to avoid conflicts
- Keep tests isolated and independent
- Clean up resources in test teardown
- Use the interactive CLI for debugging network issues
- Regenerate types after contract or runtime changes