datahaven/test/cli/handlers/launch/validator.ts
Gonza Montiel dc0f0673e2
test: Update validator set e2e test (#126)
## Add E2E validator-set update flow

- feat: `test/utils/validators.ts` for on-demand validator
orchestration.
- feat: `test/suites/validator-set-update.test.ts` covering allowlist →
register → update.
- some minor launcher updates: avoid docker cache, add `--platform` when
building datahaven image, avoid sending validator-set update on launch.
- Helpers: ABI shortcut in `test/utils/contracts.ts`; config tweaks in
`test/configs/validator-set.json`.
- Minor cleanup/formatting across `test/launcher/*`,
`test/scripts/setup-validators.ts`, and related tests.
- added `keepAlive` flag to `BaseTestSuite`, in order to avoid tearing
down the network while debugging. Defaults, obviously, to false.
- added a `failOnTomeout` option on to waitForDataHavenEvents() so the
test fails of the timeout is reached and no event was captured.

### Coverage
- The test simulates an scenario in which we have two active authorities
(alice and bob), which are running, and registered as operators, which
is the normal state after the chain launches. Then:
- It launches two more nodes (charlie and dave)
- It add the nodes to allowlist and register them as operators
- It sends the validator set update message
- Checks that the validator update message was propagated through the
gateway and arrived the external-validators pallet
- Checks that the chain continues producing blocks
 
### Notes
The last test case has a timeout of 10 minutes. This is to respect
propagation times of the message through the relayers. We are testing
that the external validators pallet actually updated the validator set.
Locally, I could expect 5~6 minutes, I just wanted to be on the safe
side. CI is passing showing that this was enough indeed.

---------

Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
2025-10-02 11:23:40 +00:00

91 lines
2.8 KiB
TypeScript

import { confirmWithTimeout, logger, printDivider, printHeader } from "utils";
import { fundValidators, setupValidators, updateValidatorSet } from "../../../launcher/validators";
import type { LaunchOptions } from "..";
export const performValidatorOperations = async (
options: LaunchOptions,
networkRpcUrl: string,
contractsDeployed: boolean
) => {
printHeader("Funding DataHaven Validators");
// If not specified, prompt for funding
let shouldFundValidators = options.fundValidators;
if (shouldFundValidators === undefined) {
shouldFundValidators = await confirmWithTimeout(
"Do you want to fund validators with tokens and ETH?",
true,
10
);
} else {
logger.info(
`🏳️ Using flag option: ${shouldFundValidators ? "will fund" : "will not fund"} validators`
);
}
if (shouldFundValidators) {
if (!contractsDeployed) {
logger.warn(
"⚠️ Funding validators but contracts were not deployed in this CLI run. Could have unexpected results."
);
}
await fundValidators({ rpcUrl: networkRpcUrl });
printDivider();
} else {
logger.info("👍 Skipping validator funding");
printDivider();
}
printHeader("Setting Up DataHaven Validators");
// If not specified, prompt for setup
let shouldSetupValidators = options.setupValidators;
if (shouldSetupValidators === undefined) {
shouldSetupValidators = await confirmWithTimeout(
"Do you want to register validators in EigenLayer?",
true,
10
);
} else {
logger.info(
`🏳️ Using flag option: ${shouldSetupValidators ? "will register" : "will not register"} validators`
);
}
if (shouldSetupValidators) {
if (!contractsDeployed) {
logger.warn(
"⚠️ Setting up validators but contracts were not deployed in this CLI run. Could have unexpected results."
);
}
await setupValidators({ rpcUrl: networkRpcUrl });
printDivider();
}
};
/**
* Performs the validator set update operation based on user options
* This function is now separate so it can be called after relayers are set up
*
* @param options - CLI options for the validator set update
* @param networkRpcUrl - RPC URL for the Ethereum network
* @param contractsDeployed - Flag indicating if contracts were deployed in this CLI run
* @returns Promise resolving when the operation is complete
*/
export const performValidatorSetUpdate = async (
networkRpcUrl: string,
contractsDeployed: boolean
) => {
printHeader("Updating DataHaven Validator Set");
if (!contractsDeployed) {
logger.warn(
"⚠️ Updating validator set but contracts were not deployed in this CLI run. Could have unexpected results."
);
}
await updateValidatorSet({ rpcUrl: networkRpcUrl });
printDivider();
};