mirror of
https://github.com/datahaven-xyz/datahaven
synced 2026-05-24 01:38:32 +00:00
In this PR we add an environment variable `INJECT_CONTRACTS`. This environment variable specify if the contracts should be injected in the e2e tests. By default it is false. The environment variable is set to `true` in the CI job that run the e2e tests. We are using a environment variable because `bun test` doesn't allow for passing extra arguments. A note about the new variable has been added in the documentation to inform about the new behavior. --------- Co-authored-by: Gonza Montiel <gonzamontiel@users.noreply.github.com>
4.7 KiB
4.7 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
NOTES: Adding the environment variable INJECT_CONTRACTS=true will inject the contracts when starting the tests to speed up setup.
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