@aztec/end-to-end 0.0.1-commit.3469e52 → 0.0.1-commit.54489865

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dest/bench/client_flows/client_flows_benchmark.d.ts +1 -1
  2. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  3. package/dest/bench/client_flows/client_flows_benchmark.js +28 -13
  4. package/dest/bench/utils.d.ts +5 -4
  5. package/dest/bench/utils.d.ts.map +1 -1
  6. package/dest/bench/utils.js +9 -7
  7. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +1 -1
  8. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  9. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +7 -8
  10. package/dest/e2e_epochs/epochs_test.d.ts +7 -1
  11. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  12. package/dest/e2e_epochs/epochs_test.js +29 -7
  13. package/dest/e2e_fees/bridging_race.notest.js +1 -1
  14. package/dest/e2e_fees/fees_test.d.ts +1 -1
  15. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  16. package/dest/e2e_fees/fees_test.js +6 -6
  17. package/dest/e2e_l1_publisher/write_json.d.ts +4 -3
  18. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -1
  19. package/dest/e2e_l1_publisher/write_json.js +1 -7
  20. package/dest/e2e_nested_contract/nested_contract_test.d.ts +1 -1
  21. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  22. package/dest/e2e_nested_contract/nested_contract_test.js +2 -2
  23. package/dest/e2e_p2p/p2p_network.d.ts +1 -1
  24. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  25. package/dest/e2e_p2p/p2p_network.js +6 -2
  26. package/dest/e2e_p2p/shared.d.ts +6 -6
  27. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  28. package/dest/e2e_p2p/shared.js +9 -16
  29. package/dest/e2e_token_contract/token_contract_test.d.ts +1 -1
  30. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  31. package/dest/e2e_token_contract/token_contract_test.js +3 -3
  32. package/dest/fixtures/e2e_prover_test.d.ts +1 -1
  33. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  34. package/dest/fixtures/e2e_prover_test.js +8 -5
  35. package/dest/fixtures/setup.d.ts +5 -3
  36. package/dest/fixtures/setup.d.ts.map +1 -1
  37. package/dest/fixtures/setup.js +31 -20
  38. package/dest/fixtures/setup_p2p_test.d.ts +4 -5
  39. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  40. package/dest/fixtures/setup_p2p_test.js +24 -19
  41. package/dest/fixtures/token_utils.d.ts +1 -1
  42. package/dest/fixtures/token_utils.d.ts.map +1 -1
  43. package/dest/fixtures/token_utils.js +7 -4
  44. package/dest/shared/cross_chain_test_harness.d.ts +3 -4
  45. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  46. package/dest/shared/cross_chain_test_harness.js +11 -11
  47. package/dest/shared/gas_portal_test_harness.js +1 -1
  48. package/dest/shared/submit-transactions.d.ts +3 -3
  49. package/dest/shared/submit-transactions.d.ts.map +1 -1
  50. package/dest/shared/submit-transactions.js +9 -11
  51. package/dest/shared/uniswap_l1_l2.d.ts +1 -1
  52. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  53. package/dest/shared/uniswap_l1_l2.js +12 -12
  54. package/dest/simulators/lending_simulator.js +2 -2
  55. package/dest/spartan/setup_test_wallets.d.ts +1 -1
  56. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  57. package/dest/spartan/setup_test_wallets.js +61 -34
  58. package/dest/spartan/tx_metrics.d.ts +38 -2
  59. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  60. package/dest/spartan/tx_metrics.js +178 -4
  61. package/dest/spartan/utils/bot.d.ts +27 -0
  62. package/dest/spartan/utils/bot.d.ts.map +1 -0
  63. package/dest/spartan/utils/bot.js +141 -0
  64. package/dest/spartan/utils/chaos.d.ts +79 -0
  65. package/dest/spartan/utils/chaos.d.ts.map +1 -0
  66. package/dest/spartan/utils/chaos.js +142 -0
  67. package/dest/spartan/utils/clients.d.ts +39 -0
  68. package/dest/spartan/utils/clients.d.ts.map +1 -0
  69. package/dest/spartan/utils/clients.js +90 -0
  70. package/dest/spartan/utils/config.d.ts +36 -0
  71. package/dest/spartan/utils/config.d.ts.map +1 -0
  72. package/dest/spartan/utils/config.js +20 -0
  73. package/dest/spartan/utils/health.d.ts +63 -0
  74. package/dest/spartan/utils/health.d.ts.map +1 -0
  75. package/dest/spartan/utils/health.js +202 -0
  76. package/dest/spartan/utils/helm.d.ts +15 -0
  77. package/dest/spartan/utils/helm.d.ts.map +1 -0
  78. package/dest/spartan/utils/helm.js +47 -0
  79. package/dest/spartan/utils/index.d.ts +9 -0
  80. package/dest/spartan/utils/index.d.ts.map +1 -0
  81. package/dest/spartan/utils/index.js +18 -0
  82. package/dest/spartan/utils/k8s.d.ts +126 -0
  83. package/dest/spartan/utils/k8s.d.ts.map +1 -0
  84. package/dest/spartan/utils/k8s.js +375 -0
  85. package/dest/spartan/utils/nodes.d.ts +41 -0
  86. package/dest/spartan/utils/nodes.d.ts.map +1 -0
  87. package/dest/spartan/utils/nodes.js +455 -0
  88. package/dest/spartan/utils/scripts.d.ts +16 -0
  89. package/dest/spartan/utils/scripts.d.ts.map +1 -0
  90. package/dest/spartan/utils/scripts.js +66 -0
  91. package/dest/spartan/utils.d.ts +2 -260
  92. package/dest/spartan/utils.d.ts.map +1 -1
  93. package/dest/spartan/utils.js +1 -942
  94. package/package.json +39 -39
  95. package/src/bench/client_flows/client_flows_benchmark.ts +11 -24
  96. package/src/bench/utils.ts +9 -7
  97. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +9 -12
  98. package/src/e2e_epochs/epochs_test.ts +58 -32
  99. package/src/e2e_fees/bridging_race.notest.ts +1 -4
  100. package/src/e2e_fees/fees_test.ts +10 -14
  101. package/src/e2e_l1_publisher/write_json.ts +3 -8
  102. package/src/e2e_nested_contract/nested_contract_test.ts +2 -4
  103. package/src/e2e_p2p/p2p_network.ts +15 -9
  104. package/src/e2e_p2p/shared.ts +20 -22
  105. package/src/e2e_token_contract/token_contract_test.ts +3 -5
  106. package/src/fixtures/e2e_prover_test.ts +4 -9
  107. package/src/fixtures/setup.ts +33 -26
  108. package/src/fixtures/setup_p2p_test.ts +15 -20
  109. package/src/fixtures/token_utils.ts +6 -5
  110. package/src/shared/cross_chain_test_harness.ts +13 -27
  111. package/src/shared/gas_portal_test_harness.ts +1 -1
  112. package/src/shared/submit-transactions.ts +9 -15
  113. package/src/shared/uniswap_l1_l2.ts +12 -19
  114. package/src/simulators/lending_simulator.ts +2 -2
  115. package/src/spartan/setup_test_wallets.ts +72 -24
  116. package/src/spartan/tx_metrics.ts +152 -7
  117. package/src/spartan/utils/bot.ts +185 -0
  118. package/src/spartan/utils/chaos.ts +253 -0
  119. package/src/spartan/utils/clients.ts +100 -0
  120. package/src/spartan/utils/config.ts +26 -0
  121. package/src/spartan/utils/health.ts +255 -0
  122. package/src/spartan/utils/helm.ts +84 -0
  123. package/src/spartan/utils/index.ts +64 -0
  124. package/src/spartan/utils/k8s.ts +527 -0
  125. package/src/spartan/utils/nodes.ts +535 -0
  126. package/src/spartan/utils/scripts.ts +63 -0
  127. package/src/spartan/utils.ts +1 -1246
@@ -0,0 +1,253 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+
3
+ import { exec } from 'child_process';
4
+ import { promisify } from 'util';
5
+
6
+ import { execHelmCommand } from './helm.js';
7
+ import { deleteResourceByLabel, getChartDir } from './k8s.js';
8
+
9
+ const execAsync = promisify(exec);
10
+
11
+ export async function uninstallChaosMesh(instanceName: string, namespace: string, log: Logger) {
12
+ // uninstall the helm chart if it exists
13
+ log.info(`Uninstalling helm chart ${instanceName}`);
14
+ await execAsync(`helm uninstall ${instanceName} --namespace ${namespace} --wait --ignore-not-found`);
15
+ // and delete the chaos-mesh resources created by this release
16
+ const deleteByLabel = async (resource: string) => {
17
+ const args = {
18
+ resource,
19
+ namespace: namespace,
20
+ label: `app.kubernetes.io/instance=${instanceName}`,
21
+ } as const;
22
+ log.info(`Deleting ${resource} resources for release ${instanceName}`);
23
+ await deleteResourceByLabel(args).catch(e => {
24
+ log.error(`Error deleting ${resource}: ${e}`);
25
+ log.info(`Force deleting ${resource}`);
26
+ return deleteResourceByLabel({ ...args, force: true });
27
+ });
28
+ };
29
+
30
+ await deleteByLabel('podchaos');
31
+ await deleteByLabel('networkchaos');
32
+ await deleteByLabel('podnetworkchaos');
33
+ await deleteByLabel('workflows');
34
+ await deleteByLabel('workflownodes');
35
+ }
36
+
37
+ /**
38
+ * Installs a Helm chart with the given parameters.
39
+ * @param instanceName - The name of the Helm chart instance.
40
+ * @param targetNamespace - The namespace with the resources to be affected by the Helm chart.
41
+ * @param valuesFile - The values file to use for the Helm chart.
42
+ * @param chaosMeshNamespace - The namespace to install the Helm chart in.
43
+ * @param timeout - The timeout for the Helm command.
44
+ * @param clean - Whether to clean up the Helm chart before installing it.
45
+ * @returns The stdout of the Helm command.
46
+ * @throws If the Helm command fails.
47
+ *
48
+ * Example usage:
49
+ * ```typescript
50
+ * const stdout = await installChaosMeshChart({ instanceName: 'force-reorg', targetNamespace: 'smoke', valuesFile: 'prover-failure.yaml'});
51
+ * console.log(stdout);
52
+ * ```
53
+ */
54
+ export async function installChaosMeshChart({
55
+ instanceName,
56
+ targetNamespace,
57
+ valuesFile,
58
+ helmChartDir,
59
+ timeout = '10m',
60
+ clean = true,
61
+ values = {},
62
+ logger: log,
63
+ }: {
64
+ instanceName: string;
65
+ targetNamespace: string;
66
+ valuesFile: string;
67
+ helmChartDir: string;
68
+ chaosMeshNamespace?: string;
69
+ timeout?: string;
70
+ clean?: boolean;
71
+ values?: Record<string, string | number>;
72
+ logger: Logger;
73
+ }) {
74
+ if (clean) {
75
+ await uninstallChaosMesh(instanceName, targetNamespace, log);
76
+ }
77
+
78
+ return execHelmCommand({
79
+ instanceName,
80
+ helmChartDir,
81
+ namespace: targetNamespace,
82
+ valuesFile,
83
+ timeout,
84
+ values: { ...values, 'global.targetNamespace': targetNamespace },
85
+ });
86
+ }
87
+
88
+ export function applyProverFailure({
89
+ namespace,
90
+ spartanDir,
91
+ durationSeconds,
92
+ logger: log,
93
+ }: {
94
+ namespace: string;
95
+ spartanDir: string;
96
+ durationSeconds: number;
97
+ logger: Logger;
98
+ }) {
99
+ return installChaosMeshChart({
100
+ instanceName: 'prover-failure',
101
+ targetNamespace: namespace,
102
+ valuesFile: 'prover-failure.yaml',
103
+ helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
104
+ values: {
105
+ 'proverFailure.duration': `${durationSeconds}s`,
106
+ },
107
+ logger: log,
108
+ });
109
+ }
110
+
111
+ export function applyValidatorFailure({
112
+ namespace,
113
+ spartanDir,
114
+ logger: log,
115
+ values,
116
+ instanceName,
117
+ }: {
118
+ namespace: string;
119
+ spartanDir: string;
120
+ logger: Logger;
121
+ values?: Record<string, string | number>;
122
+ instanceName?: string;
123
+ }) {
124
+ return installChaosMeshChart({
125
+ instanceName: instanceName ?? 'validator-failure',
126
+ targetNamespace: namespace,
127
+ valuesFile: 'validator-failure.yaml',
128
+ helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
129
+ values,
130
+ logger: log,
131
+ });
132
+ }
133
+
134
+ export function applyProverKill({
135
+ namespace,
136
+ spartanDir,
137
+ logger: log,
138
+ values,
139
+ }: {
140
+ namespace: string;
141
+ spartanDir: string;
142
+ logger: Logger;
143
+ values?: Record<string, string | number>;
144
+ }) {
145
+ return installChaosMeshChart({
146
+ instanceName: 'prover-kill',
147
+ targetNamespace: namespace,
148
+ valuesFile: 'prover-kill.yaml',
149
+ helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
150
+ chaosMeshNamespace: namespace,
151
+ clean: true,
152
+ logger: log,
153
+ values,
154
+ });
155
+ }
156
+
157
+ export function applyProverBrokerKill({
158
+ namespace,
159
+ spartanDir,
160
+ logger: log,
161
+ values,
162
+ }: {
163
+ namespace: string;
164
+ spartanDir: string;
165
+ logger: Logger;
166
+ values?: Record<string, string | number>;
167
+ }) {
168
+ return installChaosMeshChart({
169
+ instanceName: 'prover-broker-kill',
170
+ targetNamespace: namespace,
171
+ valuesFile: 'prover-broker-kill.yaml',
172
+ helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
173
+ clean: true,
174
+ logger: log,
175
+ values,
176
+ });
177
+ }
178
+
179
+ export function applyBootNodeFailure({
180
+ instanceName = 'boot-node-failure',
181
+ namespace,
182
+ spartanDir,
183
+ durationSeconds,
184
+ logger: log,
185
+ values,
186
+ }: {
187
+ instanceName?: string;
188
+ namespace: string;
189
+ spartanDir: string;
190
+ durationSeconds: number;
191
+ logger: Logger;
192
+ values?: Record<string, string | number>;
193
+ }) {
194
+ return installChaosMeshChart({
195
+ instanceName,
196
+ targetNamespace: namespace,
197
+ valuesFile: 'boot-node-failure.yaml',
198
+ helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
199
+ values: {
200
+ 'bootNodeFailure.duration': `${durationSeconds}s`,
201
+ ...(values ?? {}),
202
+ },
203
+ logger: log,
204
+ });
205
+ }
206
+
207
+ export function applyValidatorKill({
208
+ instanceName = 'validator-kill',
209
+ namespace,
210
+ spartanDir,
211
+ logger: log,
212
+ values,
213
+ clean = true,
214
+ }: {
215
+ instanceName?: string;
216
+ namespace: string;
217
+ spartanDir: string;
218
+ logger: Logger;
219
+ values?: Record<string, string | number>;
220
+ clean?: boolean;
221
+ }) {
222
+ return installChaosMeshChart({
223
+ instanceName: instanceName ?? 'validator-kill',
224
+ targetNamespace: namespace,
225
+ valuesFile: 'validator-kill.yaml',
226
+ helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
227
+ clean,
228
+ logger: log,
229
+ values,
230
+ });
231
+ }
232
+
233
+ export function applyNetworkShaping({
234
+ instanceName = 'network-shaping',
235
+ valuesFile,
236
+ namespace,
237
+ spartanDir,
238
+ logger: log,
239
+ }: {
240
+ instanceName?: string;
241
+ valuesFile: string;
242
+ namespace: string;
243
+ spartanDir: string;
244
+ logger: Logger;
245
+ }) {
246
+ return installChaosMeshChart({
247
+ instanceName,
248
+ targetNamespace: namespace,
249
+ valuesFile,
250
+ helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
251
+ logger: log,
252
+ });
253
+ }
@@ -0,0 +1,100 @@
1
+ import { createLogger } from '@aztec/aztec.js/log';
2
+ import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
3
+ import type { ViemPublicClient } from '@aztec/ethereum/types';
4
+ import { makeBackoff, retry } from '@aztec/foundation/retry';
5
+ import { createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
6
+
7
+ import type { ChildProcess } from 'child_process';
8
+ import { createPublicClient, fallback, http } from 'viem';
9
+
10
+ import type { TestConfig } from './config.js';
11
+ import { type ServiceEndpoint, getEthereumEndpoint, getRPCEndpoint } from './k8s.js';
12
+
13
+ const logger = createLogger('e2e:k8s-utils');
14
+
15
+ /**
16
+ * Returns a public viem client to the eth execution node.
17
+ * Tries external IP first, falls back to port-forward.
18
+ * If CREATE_ETH_DEVNET is false, uses the external RPC url from L1_RPC_URLS_JSON.
19
+ *
20
+ * @param env - Test environment config
21
+ * @param forcePortForward - If true, skip external IP and use port-forward directly
22
+ * @returns URL, client, and optional process (if port-forward was used). Caller must kill process when done.
23
+ */
24
+ export async function getPublicViemClient(
25
+ env: TestConfig,
26
+ forcePortForward?: boolean,
27
+ ): Promise<{
28
+ url: string;
29
+ client: ViemPublicClient;
30
+ process?: ChildProcess;
31
+ }> {
32
+ const { NAMESPACE, CREATE_ETH_DEVNET, L1_RPC_URLS_JSON } = env;
33
+ if (CREATE_ETH_DEVNET) {
34
+ logger.info(`Connecting to eth execution node in namespace ${NAMESPACE}`);
35
+ const endpoint = await getEthereumEndpoint(NAMESPACE, forcePortForward);
36
+ const client: ViemPublicClient = createPublicClient({
37
+ transport: fallback([http(endpoint.url, { batch: false })]),
38
+ });
39
+ return { url: endpoint.url, client, process: endpoint.process };
40
+ } else {
41
+ logger.info(`Connecting to the eth execution node at ${L1_RPC_URLS_JSON}`);
42
+ if (!L1_RPC_URLS_JSON) {
43
+ throw new Error(`L1_RPC_URLS_JSON is not defined`);
44
+ }
45
+ const client: ViemPublicClient = createPublicClient({
46
+ transport: fallback([http(L1_RPC_URLS_JSON, { batch: false })]),
47
+ });
48
+ return { url: L1_RPC_URLS_JSON, client };
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Queries an Aztec node for the L1 deployment addresses.
54
+ *
55
+ * @param env - Test environment config
56
+ * @param forcePortForward - If true, skip external IP and use port-forward directly
57
+ */
58
+ export async function getL1DeploymentAddresses(
59
+ env: TestConfig,
60
+ forcePortForward?: boolean,
61
+ ): Promise<L1ContractAddresses> {
62
+ let endpoint: ServiceEndpoint | undefined;
63
+ try {
64
+ endpoint = await getRPCEndpoint(env.NAMESPACE, forcePortForward);
65
+ const node = createAztecNodeClient(endpoint.url);
66
+ return await retry(
67
+ () => node.getNodeInfo().then(i => i.l1ContractAddresses),
68
+ 'get node info',
69
+ makeBackoff([1, 3, 6]),
70
+ logger,
71
+ );
72
+ } finally {
73
+ endpoint?.process?.kill();
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Returns a client to the RPC node.
79
+ * Tries external IP first, falls back to port-forward.
80
+ *
81
+ * @param env - Test environment config
82
+ * @param forcePortForward - If true, skip external IP and use port-forward directly
83
+ */
84
+ export async function getNodeClient(
85
+ env: TestConfig,
86
+ forcePortForward?: boolean,
87
+ ): Promise<{ node: ReturnType<typeof createAztecNodeClient>; url: string; process?: ChildProcess }> {
88
+ const namespace = env.NAMESPACE;
89
+
90
+ const endpoint = await getRPCEndpoint(namespace, forcePortForward);
91
+ await retry(
92
+ () => fetch(`${endpoint.url}/status`).then(res => res.status === 200),
93
+ 'check RPC endpoint',
94
+ makeBackoff([1, 1, 2, 6]),
95
+ logger,
96
+ true,
97
+ );
98
+ const client = createAztecNodeClient(endpoint.url);
99
+ return { node: client, url: endpoint.url, process: endpoint.process };
100
+ }
@@ -0,0 +1,26 @@
1
+ import { createLogger } from '@aztec/aztec.js/log';
2
+ import { schemas } from '@aztec/foundation/schemas';
3
+
4
+ import { z } from 'zod';
5
+
6
+ const logger = createLogger('e2e:k8s-utils');
7
+
8
+ const testConfigSchema = z.object({
9
+ NAMESPACE: z.string().default('scenario'),
10
+ REAL_VERIFIER: schemas.Boolean.optional().default(true),
11
+ CREATE_ETH_DEVNET: schemas.Boolean.optional().default(false),
12
+ L1_RPC_URLS_JSON: z.string().optional(),
13
+ L1_ACCOUNT_MNEMONIC: z.string().optional(),
14
+ AZTEC_SLOT_DURATION: z.coerce.number().optional().default(24),
15
+ AZTEC_EPOCH_DURATION: z.coerce.number().optional().default(32),
16
+ AZTEC_PROOF_SUBMISSION_WINDOW: z.coerce.number().optional().default(5),
17
+ AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET: z.coerce.number().optional().default(2),
18
+ });
19
+
20
+ export type TestConfig = z.infer<typeof testConfigSchema>;
21
+
22
+ export function setupEnvironment(env: unknown): TestConfig {
23
+ const config = testConfigSchema.parse(env);
24
+ logger.warn(`Loaded env config`, config);
25
+ return config;
26
+ }
@@ -0,0 +1,255 @@
1
+ import { createAztecNodeClient } from '@aztec/aztec.js/node';
2
+ import { createEthereumChain } from '@aztec/ethereum/chain';
3
+ import { RollupContract } from '@aztec/ethereum/contracts';
4
+ import type { ViemPublicClient } from '@aztec/ethereum/types';
5
+ import { CheckpointNumber } from '@aztec/foundation/branded-types';
6
+ import type { Logger } from '@aztec/foundation/log';
7
+
8
+ import { createPublicClient, fallback, http } from 'viem';
9
+
10
+ import { type ServiceEndpoint, getEthereumEndpoint, getRPCEndpoint } from './k8s.js';
11
+
12
+ /**
13
+ * Snapshot of chain state captured during setup for comparison in teardown.
14
+ */
15
+ export interface ChainHealthSnapshot {
16
+ blockNumber: number;
17
+ checkpointNumber: CheckpointNumber;
18
+ timestamp: number;
19
+ }
20
+
21
+ /**
22
+ * Pre-flight and post-flight health checks for the Aztec network.
23
+ *
24
+ * Use in beforeAll/afterAll to validate the chain is healthy before tests run
25
+ * and verify it continued progressing during the test.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const health = new ChainHealth(config.NAMESPACE, logger);
30
+ *
31
+ * beforeAll(async () => {
32
+ * await health.setup();
33
+ * });
34
+ *
35
+ * afterAll(async () => {
36
+ * await health.teardown();
37
+ * });
38
+ * ```
39
+ */
40
+ export class ChainHealth {
41
+ private namespace: string;
42
+ private logger: Logger;
43
+ private snapshot?: ChainHealthSnapshot;
44
+
45
+ constructor(namespace: string, logger: Logger) {
46
+ this.namespace = namespace;
47
+ this.logger = logger;
48
+ }
49
+
50
+ /**
51
+ * Pre-flight health check. Validates chain is in a testable state and captures
52
+ * initial state for comparison in teardown.
53
+ *
54
+ * Checks performed:
55
+ * - Node is reachable and returns valid info
56
+ * - ENR exists
57
+ * - L1 is accessible
58
+ * - At least 1 L2 block has been mined
59
+ * - Committee exists
60
+ * - At least 1 checkpoint has been reached
61
+ *
62
+ * @throws Error if any health check fails
63
+ */
64
+ async setup(): Promise<void> {
65
+ const endpoints: ServiceEndpoint[] = [];
66
+
67
+ try {
68
+ // Establish connections (LB or port-forward)
69
+ const rpcEndpoint = await getRPCEndpoint(this.namespace);
70
+ endpoints.push(rpcEndpoint);
71
+
72
+ const ethEndpoint = await getEthereumEndpoint(this.namespace);
73
+ endpoints.push(ethEndpoint);
74
+
75
+ const nodeUrl = rpcEndpoint.url;
76
+ const ethereumUrl = ethEndpoint.url;
77
+
78
+ // Create clients
79
+ const node = createAztecNodeClient(nodeUrl);
80
+
81
+ // Check 1: Node is reachable
82
+ let nodeInfo;
83
+ try {
84
+ nodeInfo = await node.getNodeInfo();
85
+ } catch (err) {
86
+ throw new Error(`Health check failed: Node is not reachable at ${nodeUrl}. Error: ${err}`);
87
+ }
88
+
89
+ if (!nodeInfo) {
90
+ throw new Error('Health check failed: Node returned empty info');
91
+ }
92
+
93
+ // Check 2: ENR exists (P2P identity)
94
+ if (!nodeInfo.enr || !nodeInfo.enr.startsWith('enr:-')) {
95
+ throw new Error(`Health check failed: Invalid or missing ENR. Got: ${nodeInfo.enr}`);
96
+ }
97
+
98
+ // Check 3: L1 is accessible
99
+ const chain = createEthereumChain([ethereumUrl], nodeInfo.l1ChainId);
100
+ const ethereumClient: ViemPublicClient = createPublicClient({
101
+ chain: chain.chainInfo,
102
+ transport: fallback([http(ethereumUrl, { batch: false })]),
103
+ });
104
+
105
+ try {
106
+ await ethereumClient.getBlockNumber();
107
+ } catch (err) {
108
+ throw new Error(`Health check failed: L1 is not accessible at ${ethereumUrl}. Error: ${err}`);
109
+ }
110
+
111
+ // Check 4: At least 1 L2 block mined
112
+ let l2BlockNumber;
113
+ try {
114
+ l2BlockNumber = await node.getBlockNumber();
115
+ } catch (err) {
116
+ throw new Error(`Health check failed: Could not get L2 block number. Error: ${err}`);
117
+ }
118
+
119
+ if (l2BlockNumber < 1) {
120
+ throw new Error(`Health check failed: No L2 blocks mined yet. Block number: ${l2BlockNumber}`);
121
+ }
122
+
123
+ // Check 5: Committee exists
124
+ const rollup = new RollupContract(ethereumClient, nodeInfo.l1ContractAddresses.rollupAddress);
125
+
126
+ let committee;
127
+ try {
128
+ committee = await rollup.getCurrentEpochCommittee();
129
+ } catch (err) {
130
+ throw new Error(`Health check failed: Could not get committee. Error: ${err}`);
131
+ }
132
+
133
+ if (!committee || committee.length === 0) {
134
+ throw new Error('Health check failed: No committee exists. Validators may not be registered yet.');
135
+ }
136
+
137
+ // Check 6: At least 1 checkpoint reached
138
+ let checkpointNumber;
139
+ try {
140
+ checkpointNumber = await rollup.getCheckpointNumber();
141
+ } catch (err) {
142
+ throw new Error(`Health check failed: Could not get checkpoint number. Error: ${err}`);
143
+ }
144
+
145
+ if (checkpointNumber < CheckpointNumber(1)) {
146
+ throw new Error(
147
+ `Health check failed: No checkpoint reached yet. Checkpoint number: ${checkpointNumber}. ` +
148
+ 'The proving pipeline may not have completed a proof yet.',
149
+ );
150
+ }
151
+
152
+ // Capture snapshot for teardown comparison
153
+ this.snapshot = {
154
+ blockNumber: l2BlockNumber,
155
+ checkpointNumber,
156
+ timestamp: Date.now(),
157
+ };
158
+
159
+ this.logger.info('Pre-flight health check passed');
160
+ } finally {
161
+ endpoints.forEach(e => e.process?.kill());
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Post-flight health check. Verifies the chain continued progressing during the test.
167
+ *
168
+ * For tests that ran longer than the threshold, checks:
169
+ * - Block number increased since setup
170
+ * - Checkpoint number increased since setup
171
+ *
172
+ * For shorter tests, skips the check.
173
+ *
174
+ * @throws Error if chain did not progress
175
+ */
176
+ async teardown(): Promise<void> {
177
+ if (!this.snapshot) {
178
+ this.logger.warn('Teardown called without setup - skipping chain progress check');
179
+ return;
180
+ }
181
+
182
+ const endpoints: ServiceEndpoint[] = [];
183
+ // Minimum test duration to check chain progression
184
+ const PROGRESS_CHECK_THRESHOLD_SECONDS = 120;
185
+
186
+ try {
187
+ const elapsedSeconds = Math.round((Date.now() - this.snapshot.timestamp) / 1000);
188
+
189
+ // Skip progress check for short tests
190
+ if (elapsedSeconds <= PROGRESS_CHECK_THRESHOLD_SECONDS) {
191
+ this.logger.info('Post-flight health check passed (skipped progress check - test too short)');
192
+ return;
193
+ }
194
+
195
+ const rpcEndpoint = await getRPCEndpoint(this.namespace);
196
+ endpoints.push(rpcEndpoint);
197
+
198
+ const ethEndpoint = await getEthereumEndpoint(this.namespace);
199
+ endpoints.push(ethEndpoint);
200
+
201
+ const nodeUrl = rpcEndpoint.url;
202
+ const ethereumUrl = ethEndpoint.url;
203
+ const node = createAztecNodeClient(nodeUrl);
204
+
205
+ // Check that block number increased
206
+ let currentBlockNumber;
207
+ try {
208
+ currentBlockNumber = await node.getBlockNumber();
209
+ } catch (err) {
210
+ throw new Error(`Teardown health check failed: Could not get block number. Error: ${err}`);
211
+ }
212
+
213
+ if (currentBlockNumber <= this.snapshot.blockNumber) {
214
+ throw new Error(
215
+ `Chain did not progress during test. ` +
216
+ `Block number at setup: ${this.snapshot.blockNumber}, ` +
217
+ `Block number at teardown: ${currentBlockNumber}, ` +
218
+ `Elapsed time: ${elapsedSeconds}s. ` +
219
+ `The chain may have stalled during the test.`,
220
+ );
221
+ }
222
+
223
+ // Check that checkpoint number increased
224
+ const nodeInfo = await node.getNodeInfo();
225
+ const chain = createEthereumChain([ethereumUrl], nodeInfo.l1ChainId);
226
+ const ethereumClient: ViemPublicClient = createPublicClient({
227
+ chain: chain.chainInfo,
228
+ transport: fallback([http(ethereumUrl, { batch: false })]),
229
+ });
230
+
231
+ const rollup = new RollupContract(ethereumClient, nodeInfo.l1ContractAddresses.rollupAddress);
232
+ let currentCheckpoint;
233
+ try {
234
+ currentCheckpoint = await rollup.getCheckpointNumber();
235
+ } catch (err) {
236
+ throw new Error(`Teardown health check failed: Could not get checkpoint number. Error: ${err}`);
237
+ }
238
+
239
+ if (currentCheckpoint <= this.snapshot.checkpointNumber) {
240
+ throw new Error(
241
+ `Proving pipeline did not progress during test. ` +
242
+ `Checkpoint at setup: ${this.snapshot.checkpointNumber}, ` +
243
+ `Checkpoint at teardown: ${currentCheckpoint}, ` +
244
+ `Elapsed time: ${elapsedSeconds}s. ` +
245
+ `The proving pipeline may have stalled during the test.`,
246
+ );
247
+ }
248
+
249
+ this.logger.info('Post-flight health check passed');
250
+ } finally {
251
+ endpoints.forEach(e => e.process?.kill());
252
+ this.snapshot = undefined;
253
+ }
254
+ }
255
+ }