mirror of
https://github.com/datahaven-xyz/datahaven
synced 2026-05-23 17:28:23 +00:00
This PR significantly refactors and improves the end-to-end testing framework and infrastructure. The primary focus was on simplifying the test suites, improving reliability through better resource management, and hardening the relayer infrastructure. All E2E tests are now passing on the CI and demonstrate consistent reliability when run locally. ### Key Changes #### 1. E2E Test Suite Refactor & Cleanup * **Simplified Test Logic**: Heavily refactored the core test suites (`native-token-transfer.test.ts`, `rewards-message.test.ts`, and `validator-set-update.test.ts`). The new implementation is much cleaner, utilizing shared helpers to reduce boilerplate. * **Utility Consolidation**: Removed redundant utility files (`storage.ts`, `rewards-helpers.ts`) and simplified `events.ts`. Event waiting now uses `rxjs` for Substrate and native `viem` watchers for Ethereum, which is more robust and easier to maintain. * **Better Connector Management**: Unified the creation and cleanup of test clients in `ConnectorFactory`. It now handles the lifecycle of WebSocket connections more gracefully, including clearing the `socketClientCache` to prevent reconnection noise during teardown. #### 2. Infrastructure & Stability * **Relayer Relaunch Policy**: Added a restart policy for Snowbridge relayer containers. They are now configured with `--restart on-failure:5`, ensuring that relayers automatically relaunch if they crash during the sensitive initialization phase. * **WebSocket Integration**: * Updated the `ConnectorFactory` to prefer **WebSockets** for the Ethereum public client, which is essential for efficient, event-heavy E2E testing. * Enhanced `launchKurtosisNetwork` to correctly identify and register the Execution Layer's WebSocket endpoint from Kurtosis. * **Disabled Contract Injection**: This PR temporarily disables the automatic injection of contracts into the genesis state by default. * *Reason*: I encountered issues generating a valid `state-diff.json` for the latest contract versions. Even after applying several workarounds, the injected state remained unstable. As a result, I've reverted to manual contract deployment during the launch sequence for better reliability for now. #### 3. Documentation & Maintenance * Removed obsolete documentation (`event-utilities-guide.md`) that no longer reflects the simplified event-handling API. * Cleaned up `test/launcher/validators.ts` and moved logic into more appropriate helpers. --------- Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
89 lines
3 KiB
TypeScript
89 lines
3 KiB
TypeScript
import { fundValidators as fundValidatorsScript } from "scripts/fund-validators";
|
|
import { setupValidators as setupValidatorsScript } from "scripts/setup-validators";
|
|
import { updateValidatorSet as updateValidatorSetScript } from "scripts/update-validator-set";
|
|
import { ANVIL_FUNDED_ACCOUNTS, logger } from "utils";
|
|
import { privateKeyToAccount } from "viem/accounts";
|
|
|
|
/**
|
|
* Configuration options for validator operations.
|
|
*/
|
|
export interface ValidatorOptions {
|
|
rpcUrl: string;
|
|
}
|
|
|
|
/**
|
|
* Funds validators with tokens and ETH.
|
|
*
|
|
* This function ensures validators have the necessary funds to operate by:
|
|
* - Sending ETH for gas fees
|
|
* - Sending required tokens for staking
|
|
* - Verifying balances after funding
|
|
*
|
|
* @param options - Configuration options for funding
|
|
* @param options.rpcUrl - The RPC URL of the Ethereum network
|
|
*
|
|
* @throws {Error} If funding transactions fail
|
|
* @throws {Error} If the network is unreachable
|
|
*/
|
|
export const fundValidators = async (options: ValidatorOptions): Promise<void> => {
|
|
logger.info("💰 Funding validators with tokens and ETH...");
|
|
|
|
await fundValidatorsScript({
|
|
rpcUrl: options.rpcUrl
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Registers validators in the EigenLayer protocol.
|
|
*
|
|
* This function handles the validator registration process:
|
|
* - Creates operator registrations in EigenLayer
|
|
* - Registers operators with the AVS (Actively Validated Service)
|
|
* - Sets up delegation relationships
|
|
* - Configures operator metadata
|
|
*
|
|
* @param options - Configuration options for setup
|
|
* @param options.rpcUrl - The RPC URL of the Ethereum network
|
|
*
|
|
* @throws {Error} If registration transactions fail
|
|
* @throws {Error} If validators are already registered
|
|
* @throws {Error} If required contracts are not deployed
|
|
*/
|
|
export const setupValidators = async (options: ValidatorOptions): Promise<void> => {
|
|
logger.info("📝 Registering validators in EigenLayer...");
|
|
|
|
await setupValidatorsScript({
|
|
rpcUrl: options.rpcUrl
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Updates the validator set on the Substrate chain.
|
|
*
|
|
* This function synchronizes the validator set between Ethereum and Substrate:
|
|
* - Fetches the current validator set from EigenLayer
|
|
* - Prepares validator set update transaction
|
|
* - Submits the update through the bridge
|
|
* - Waits for confirmation on the Substrate side
|
|
*
|
|
* @param options - Configuration options for the update
|
|
* @param options.rpcUrl - The RPC URL of the Ethereum network
|
|
*
|
|
* @throws {Error} If the update transaction fails
|
|
* @throws {Error} If the bridge is not initialized
|
|
* @throws {Error} If validators are not properly registered
|
|
*/
|
|
export const updateValidatorSet = async (options: ValidatorOptions): Promise<void> => {
|
|
logger.info("🔄 Updating validator set on Substrate chain...");
|
|
|
|
await updateValidatorSetScript({
|
|
rpcUrl: options.rpcUrl
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Gets the owner account for validator operations.
|
|
*/
|
|
export function getOwnerAccount() {
|
|
return privateKeyToAccount(ANVIL_FUNDED_ACCOUNTS[6].privateKey as `0x${string}`);
|
|
}
|