@aztec/end-to-end 0.0.1-commit.c7c42ec → 0.0.1-commit.d1f2d6c

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 (166) hide show
  1. package/dest/bench/client_flows/benchmark.d.ts +3 -2
  2. package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
  3. package/dest/bench/client_flows/benchmark.js +21 -1
  4. package/dest/bench/client_flows/client_flows_benchmark.d.ts +12 -13
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  6. package/dest/bench/client_flows/client_flows_benchmark.js +118 -133
  7. package/dest/bench/client_flows/data_extractor.js +3 -1
  8. package/dest/bench/utils.d.ts +9 -8
  9. package/dest/bench/utils.d.ts.map +1 -1
  10. package/dest/bench/utils.js +17 -12
  11. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +6 -7
  12. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  13. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +96 -112
  14. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +15 -10
  15. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  16. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +89 -70
  17. package/dest/e2e_deploy_contract/deploy_test.d.ts +4 -3
  18. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  19. package/dest/e2e_deploy_contract/deploy_test.js +18 -13
  20. package/dest/e2e_epochs/epochs_test.d.ts +1 -1
  21. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  22. package/dest/e2e_epochs/epochs_test.js +5 -2
  23. package/dest/e2e_fees/bridging_race.notest.js +3 -5
  24. package/dest/e2e_fees/fees_test.d.ts +13 -13
  25. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  26. package/dest/e2e_fees/fees_test.js +123 -141
  27. package/dest/e2e_l1_publisher/write_json.d.ts +2 -2
  28. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -1
  29. package/dest/e2e_l1_publisher/write_json.js +19 -15
  30. package/dest/e2e_nested_contract/nested_contract_test.d.ts +6 -9
  31. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  32. package/dest/e2e_nested_contract/nested_contract_test.js +31 -39
  33. package/dest/e2e_p2p/inactivity_slash_test.d.ts +3 -3
  34. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -1
  35. package/dest/e2e_p2p/inactivity_slash_test.js +3 -3
  36. package/dest/e2e_p2p/p2p_network.d.ts +7 -6
  37. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  38. package/dest/e2e_p2p/p2p_network.js +109 -103
  39. package/dest/e2e_p2p/shared.d.ts +6 -6
  40. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  41. package/dest/e2e_p2p/shared.js +11 -18
  42. package/dest/e2e_token_contract/token_contract_test.d.ts +16 -9
  43. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  44. package/dest/e2e_token_contract/token_contract_test.js +89 -91
  45. package/dest/fixtures/e2e_prover_test.d.ts +8 -14
  46. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  47. package/dest/fixtures/e2e_prover_test.js +85 -94
  48. package/dest/fixtures/setup.d.ts +216 -0
  49. package/dest/fixtures/setup.d.ts.map +1 -0
  50. package/dest/fixtures/setup.js +684 -0
  51. package/dest/fixtures/token_utils.d.ts +1 -1
  52. package/dest/fixtures/token_utils.d.ts.map +1 -1
  53. package/dest/fixtures/token_utils.js +7 -4
  54. package/dest/fixtures/utils.d.ts +5 -194
  55. package/dest/fixtures/utils.d.ts.map +1 -1
  56. package/dest/fixtures/utils.js +4 -619
  57. package/dest/quality_of_service/grafana_client.d.ts +41 -0
  58. package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
  59. package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
  60. package/dest/quality_of_service/prometheus_client.d.ts +38 -0
  61. package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
  62. package/dest/quality_of_service/prometheus_client.js +67 -0
  63. package/dest/shared/cross_chain_test_harness.d.ts +16 -6
  64. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  65. package/dest/shared/cross_chain_test_harness.js +13 -13
  66. package/dest/shared/gas_portal_test_harness.d.ts +11 -1
  67. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  68. package/dest/shared/gas_portal_test_harness.js +1 -1
  69. package/dest/shared/index.d.ts +2 -2
  70. package/dest/shared/index.d.ts.map +1 -1
  71. package/dest/shared/submit-transactions.d.ts +3 -3
  72. package/dest/shared/submit-transactions.d.ts.map +1 -1
  73. package/dest/shared/submit-transactions.js +9 -11
  74. package/dest/shared/uniswap_l1_l2.d.ts +3 -28
  75. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  76. package/dest/shared/uniswap_l1_l2.js +51 -33
  77. package/dest/simulators/lending_simulator.d.ts +5 -1
  78. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  79. package/dest/simulators/lending_simulator.js +2 -2
  80. package/dest/spartan/setup_test_wallets.d.ts +4 -3
  81. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  82. package/dest/spartan/setup_test_wallets.js +61 -34
  83. package/dest/spartan/tx_metrics.d.ts +17 -2
  84. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  85. package/dest/spartan/tx_metrics.js +183 -6
  86. package/dest/spartan/utils/bot.d.ts +27 -0
  87. package/dest/spartan/utils/bot.d.ts.map +1 -0
  88. package/dest/spartan/utils/bot.js +141 -0
  89. package/dest/spartan/utils/chaos.d.ts +79 -0
  90. package/dest/spartan/utils/chaos.d.ts.map +1 -0
  91. package/dest/spartan/utils/chaos.js +142 -0
  92. package/dest/spartan/utils/clients.d.ts +39 -0
  93. package/dest/spartan/utils/clients.d.ts.map +1 -0
  94. package/dest/spartan/utils/clients.js +90 -0
  95. package/dest/spartan/utils/config.d.ts +36 -0
  96. package/dest/spartan/utils/config.d.ts.map +1 -0
  97. package/dest/spartan/utils/config.js +20 -0
  98. package/dest/spartan/utils/health.d.ts +63 -0
  99. package/dest/spartan/utils/health.d.ts.map +1 -0
  100. package/dest/spartan/utils/health.js +202 -0
  101. package/dest/spartan/utils/helm.d.ts +15 -0
  102. package/dest/spartan/utils/helm.d.ts.map +1 -0
  103. package/dest/spartan/utils/helm.js +47 -0
  104. package/dest/spartan/utils/index.d.ts +9 -0
  105. package/dest/spartan/utils/index.d.ts.map +1 -0
  106. package/dest/spartan/utils/index.js +18 -0
  107. package/dest/spartan/utils/k8s.d.ts +98 -0
  108. package/dest/spartan/utils/k8s.d.ts.map +1 -0
  109. package/dest/spartan/utils/k8s.js +257 -0
  110. package/dest/spartan/utils/nodes.d.ts +31 -0
  111. package/dest/spartan/utils/nodes.d.ts.map +1 -0
  112. package/dest/spartan/utils/nodes.js +290 -0
  113. package/dest/spartan/utils/scripts.d.ts +16 -0
  114. package/dest/spartan/utils/scripts.d.ts.map +1 -0
  115. package/dest/spartan/utils/scripts.js +66 -0
  116. package/dest/spartan/utils.d.ts +2 -253
  117. package/dest/spartan/utils.d.ts.map +1 -1
  118. package/dest/spartan/utils.js +1 -892
  119. package/package.json +40 -39
  120. package/src/bench/client_flows/benchmark.ts +24 -2
  121. package/src/bench/client_flows/client_flows_benchmark.ts +138 -204
  122. package/src/bench/client_flows/data_extractor.ts +1 -1
  123. package/src/bench/utils.ts +20 -14
  124. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +104 -142
  125. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +127 -116
  126. package/src/e2e_deploy_contract/deploy_test.ts +21 -14
  127. package/src/e2e_epochs/epochs_test.ts +31 -26
  128. package/src/e2e_fees/bridging_race.notest.ts +3 -9
  129. package/src/e2e_fees/fees_test.ts +172 -220
  130. package/src/e2e_l1_publisher/write_json.ts +21 -16
  131. package/src/e2e_nested_contract/nested_contract_test.ts +33 -56
  132. package/src/e2e_p2p/inactivity_slash_test.ts +5 -5
  133. package/src/e2e_p2p/p2p_network.ts +171 -168
  134. package/src/e2e_p2p/shared.ts +16 -25
  135. package/src/e2e_token_contract/token_contract_test.ts +103 -118
  136. package/src/fixtures/e2e_prover_test.ts +98 -133
  137. package/src/fixtures/setup.ts +1006 -0
  138. package/src/fixtures/token_utils.ts +6 -5
  139. package/src/fixtures/utils.ts +27 -907
  140. package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +1 -1
  141. package/src/quality_of_service/prometheus_client.ts +113 -0
  142. package/src/shared/cross_chain_test_harness.ts +16 -36
  143. package/src/shared/gas_portal_test_harness.ts +1 -1
  144. package/src/shared/index.ts +1 -1
  145. package/src/shared/submit-transactions.ts +9 -15
  146. package/src/shared/uniswap_l1_l2.ts +58 -77
  147. package/src/simulators/lending_simulator.ts +2 -2
  148. package/src/spartan/setup_test_wallets.ts +79 -25
  149. package/src/spartan/tx_metrics.ts +129 -9
  150. package/src/spartan/utils/bot.ts +185 -0
  151. package/src/spartan/utils/chaos.ts +253 -0
  152. package/src/spartan/utils/clients.ts +100 -0
  153. package/src/spartan/utils/config.ts +26 -0
  154. package/src/spartan/utils/health.ts +255 -0
  155. package/src/spartan/utils/helm.ts +84 -0
  156. package/src/spartan/utils/index.ts +62 -0
  157. package/src/spartan/utils/k8s.ts +375 -0
  158. package/src/spartan/utils/nodes.ts +323 -0
  159. package/src/spartan/utils/scripts.ts +63 -0
  160. package/src/spartan/utils.ts +1 -1158
  161. package/dest/fixtures/snapshot_manager.d.ts +0 -93
  162. package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
  163. package/dest/fixtures/snapshot_manager.js +0 -493
  164. package/dest/quality_of_service/alert_checker.d.ts +0 -41
  165. package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
  166. package/src/fixtures/snapshot_manager.ts +0 -651
@@ -0,0 +1,84 @@
1
+ import { createLogger } from '@aztec/aztec.js/log';
2
+ import type { Logger } from '@aztec/foundation/log';
3
+
4
+ import { exec } from 'child_process';
5
+ import { promisify } from 'util';
6
+
7
+ const execAsync = promisify(exec);
8
+
9
+ const logger = createLogger('e2e:k8s-utils');
10
+
11
+ function shellQuote(value: string) {
12
+ // Single-quote safe shell escaping: ' -> '\''
13
+ return `'${value.replace(/'/g, "'\\''")}'`;
14
+ }
15
+
16
+ function valuesToArgs(values: Record<string, string | number | boolean>) {
17
+ return Object.entries(values)
18
+ .map(([key, value]) =>
19
+ typeof value === 'number' || typeof value === 'boolean'
20
+ ? `--set ${key}=${value}`
21
+ : `--set-string ${key}=${shellQuote(String(value))}`,
22
+ )
23
+ .join(' ');
24
+ }
25
+
26
+ export function createHelmCommand({
27
+ instanceName,
28
+ helmChartDir,
29
+ namespace,
30
+ valuesFile,
31
+ timeout,
32
+ values,
33
+ reuseValues = false,
34
+ }: {
35
+ instanceName: string;
36
+ helmChartDir: string;
37
+ namespace: string;
38
+ valuesFile: string | undefined;
39
+ timeout: string;
40
+ values: Record<string, string | number | boolean>;
41
+ reuseValues?: boolean;
42
+ }) {
43
+ const valuesFileArgs = valuesFile ? `--values ${helmChartDir}/values/${valuesFile}` : '';
44
+ const reuseValuesArgs = reuseValues ? '--reuse-values' : '';
45
+ return `helm upgrade --install ${instanceName} ${helmChartDir} --namespace ${namespace} ${valuesFileArgs} ${reuseValuesArgs} --wait --timeout=${timeout} ${valuesToArgs(
46
+ values,
47
+ )}`;
48
+ }
49
+
50
+ export async function execHelmCommand(args: Parameters<typeof createHelmCommand>[0]) {
51
+ const helmCommand = createHelmCommand(args);
52
+ logger.info(`helm command: ${helmCommand}`);
53
+ const { stdout } = await execAsync(helmCommand);
54
+ return stdout;
55
+ }
56
+
57
+ export async function getHelmReleaseStatus(instanceName: string, namespace: string): Promise<string | undefined> {
58
+ try {
59
+ const { stdout } = await execAsync(
60
+ `helm list --namespace ${namespace} --all --filter '^${instanceName}$' --output json | cat`,
61
+ );
62
+ const parsed = JSON.parse(stdout) as Array<{ name?: string; status?: string }>;
63
+ const row = parsed.find(r => r.name === instanceName);
64
+ return row?.status;
65
+ } catch {
66
+ return undefined;
67
+ }
68
+ }
69
+
70
+ export async function forceDeleteHelmReleaseRecord(instanceName: string, namespace: string, log?: Logger) {
71
+ const labelSelector = `owner=helm,name=${instanceName}`;
72
+ const cmd = `kubectl delete secret -n ${namespace} -l ${labelSelector} --ignore-not-found=true`;
73
+ (log ?? logger).warn(`Force deleting Helm release record: ${cmd}`);
74
+ await execAsync(cmd).catch(() => undefined);
75
+ }
76
+
77
+ export async function hasDeployedHelmRelease(instanceName: string, namespace: string): Promise<boolean> {
78
+ try {
79
+ const status = await getHelmReleaseStatus(instanceName, namespace);
80
+ return status?.toLowerCase() === 'deployed';
81
+ } catch {
82
+ return false;
83
+ }
84
+ }
@@ -0,0 +1,62 @@
1
+ // Re-export all utilities from individual modules
2
+ // Note: Internal helpers (helm commands, etc.) are not re-exported to maintain the original public API
3
+
4
+ // Config
5
+ export { type TestConfig, setupEnvironment } from './config.js';
6
+
7
+ // Scripts
8
+ export { getGitProjectRoot, getAztecBin, runAztecBin, runProjectScript } from './scripts.js';
9
+
10
+ // K8s operations
11
+ export {
12
+ startPortForward,
13
+ getExternalIP,
14
+ startPortForwardForPrometeheus,
15
+ startPortForwardForRPC,
16
+ startPortForwardForEthereum,
17
+ deleteResourceByName,
18
+ deleteResourceByLabel,
19
+ waitForResourceByLabel,
20
+ waitForResourceByName,
21
+ waitForResourcesByName,
22
+ getChartDir,
23
+ type ServiceEndpoint,
24
+ getServiceEndpoint,
25
+ getRPCEndpoint,
26
+ getEthereumEndpoint,
27
+ } from './k8s.js';
28
+
29
+ // Chaos Mesh
30
+ export {
31
+ uninstallChaosMesh,
32
+ installChaosMeshChart,
33
+ applyProverFailure,
34
+ applyValidatorFailure,
35
+ applyProverKill,
36
+ applyProverBrokerKill,
37
+ applyBootNodeFailure,
38
+ applyValidatorKill,
39
+ applyNetworkShaping,
40
+ } from './chaos.js';
41
+
42
+ // Bot management
43
+ export { restartBot, installTransferBot, uninstallTransferBot } from './bot.js';
44
+
45
+ // Node operations (sequencers, validators, pods)
46
+ export {
47
+ awaitCheckpointNumber,
48
+ getSequencers,
49
+ updateSequencersConfig,
50
+ getSequencersConfig,
51
+ withSequencersAdmin,
52
+ setValidatorTxDrop,
53
+ restartValidators,
54
+ enableValidatorDynamicBootNode,
55
+ rollAztecPods,
56
+ } from './nodes.js';
57
+
58
+ // Client utilities
59
+ export { getPublicViemClient, getL1DeploymentAddresses, getNodeClient } from './clients.js';
60
+
61
+ // Health checks
62
+ export { ChainHealth, type ChainHealthSnapshot } from './health.js';
@@ -0,0 +1,375 @@
1
+ import { createLogger } from '@aztec/aztec.js/log';
2
+ import { promiseWithResolvers } from '@aztec/foundation/promise';
3
+ import { retryUntil } from '@aztec/foundation/retry';
4
+
5
+ import { type ChildProcess, exec, spawn } from 'child_process';
6
+ import path from 'path';
7
+ import { promisify } from 'util';
8
+
9
+ const execAsync = promisify(exec);
10
+
11
+ const logger = createLogger('e2e:k8s-utils');
12
+
13
+ /**
14
+ * Represents an endpoint to reach a K8s service.
15
+ * May be a LoadBalancer external IP or a port-forward.
16
+ */
17
+ export interface ServiceEndpoint {
18
+ url: string;
19
+ process?: ChildProcess;
20
+ }
21
+
22
+ export async function startPortForward({
23
+ resource,
24
+ namespace,
25
+ containerPort,
26
+ hostPort,
27
+ }: {
28
+ resource: string;
29
+ namespace: string;
30
+ containerPort: number;
31
+ // If not provided, the port will be chosen automatically
32
+ hostPort?: number;
33
+ }): Promise<{
34
+ process: ChildProcess;
35
+ port: number;
36
+ }> {
37
+ const hostPortAsString = hostPort ? hostPort.toString() : '';
38
+
39
+ logger.debug(`kubectl port-forward -n ${namespace} ${resource} ${hostPortAsString}:${containerPort}`);
40
+
41
+ const process = spawn(
42
+ 'kubectl',
43
+ ['port-forward', '-n', namespace, resource, `${hostPortAsString}:${containerPort}`],
44
+ {
45
+ detached: true,
46
+ windowsHide: true,
47
+ stdio: ['ignore', 'pipe', 'pipe'],
48
+ },
49
+ );
50
+
51
+ let isResolved = false;
52
+ const connected = new Promise<number>((resolve, reject) => {
53
+ process.stdout?.on('data', data => {
54
+ const str = data.toString() as string;
55
+ if (!isResolved && str.includes('Forwarding from')) {
56
+ isResolved = true;
57
+ logger.debug(`Port forward for ${resource}: ${str}`);
58
+ const port = str.search(/:\d+/);
59
+ if (port === -1) {
60
+ reject(new Error('Port not found in port forward output'));
61
+ return;
62
+ }
63
+ const portNumber = parseInt(str.slice(port + 1));
64
+ logger.verbose(`Port forwarded for ${resource} at ${portNumber}:${containerPort}`);
65
+ resolve(portNumber);
66
+ } else {
67
+ logger.silent(str);
68
+ }
69
+ });
70
+ process.stderr?.on('data', data => {
71
+ logger.verbose(`Port forward for ${resource}: ${data.toString()}`);
72
+ // It's a strange thing:
73
+ // If we don't pipe stderr, then the port forwarding does not work.
74
+ // Log to silent because this doesn't actually report errors,
75
+ // just extremely verbose debug logs.
76
+ logger.silent(data.toString());
77
+ });
78
+ process.on('close', () => {
79
+ if (!isResolved) {
80
+ isResolved = true;
81
+ const msg = `Port forward for ${resource} closed before connection established`;
82
+ logger.warn(msg);
83
+ reject(new Error(msg));
84
+ }
85
+ });
86
+ process.on('error', error => {
87
+ if (!isResolved) {
88
+ isResolved = true;
89
+ const msg = `Port forward for ${resource} error: ${error}`;
90
+ logger.error(msg);
91
+ reject(new Error(msg));
92
+ }
93
+ });
94
+ process.on('exit', code => {
95
+ if (!isResolved) {
96
+ isResolved = true;
97
+ const msg = `Port forward for ${resource} exited with code ${code}`;
98
+ logger.verbose(msg);
99
+ reject(new Error(msg));
100
+ }
101
+ });
102
+ });
103
+
104
+ const port = await connected;
105
+
106
+ return { process, port };
107
+ }
108
+
109
+ export function getExternalIP(namespace: string, serviceName: string): Promise<string> {
110
+ const { promise, resolve, reject } = promiseWithResolvers<string>();
111
+ const process = spawn(
112
+ 'kubectl',
113
+ [
114
+ 'get',
115
+ 'service',
116
+ '-n',
117
+ namespace,
118
+ `${namespace}-${serviceName}`,
119
+ '--output',
120
+ "jsonpath='{.status.loadBalancer.ingress[0].ip}'",
121
+ ],
122
+ {
123
+ stdio: 'pipe',
124
+ },
125
+ );
126
+
127
+ let ip = '';
128
+ process.stdout.on('data', data => {
129
+ ip += data;
130
+ });
131
+ process.on('error', err => {
132
+ reject(err);
133
+ });
134
+ process.on('exit', () => {
135
+ // kubectl prints JSON. Remove the quotes
136
+ resolve(ip.replace(/"|'/g, ''));
137
+ });
138
+
139
+ return promise;
140
+ }
141
+
142
+ /**
143
+ * Gets an endpoint for a K8s service.
144
+ * By default, tries to get the external IP first and falls back to port-forward if unavailable.
145
+ *
146
+ * @param opts.namespace - K8s namespace
147
+ * @param opts.serviceName - Service name suffix (e.g., 'rpc-aztec-node', 'eth-execution')
148
+ * @param opts.containerPort - Port the service exposes
149
+ * @param opts.usePortForward - If true, skip external IP check and always use port-forward
150
+ */
151
+ export async function getServiceEndpoint(opts: {
152
+ namespace: string;
153
+ serviceName: string;
154
+ containerPort: number;
155
+ forcePortForward?: boolean;
156
+ }): Promise<ServiceEndpoint> {
157
+ const { namespace, serviceName, containerPort, forcePortForward } = opts;
158
+
159
+ if (!forcePortForward) {
160
+ try {
161
+ const ip = await retryUntil(
162
+ async () => {
163
+ try {
164
+ const ip = await getExternalIP(namespace, serviceName);
165
+ if (ip && ip !== '' && ip !== '<pending>' && ip !== 'null') {
166
+ return ip;
167
+ }
168
+ } catch (err) {
169
+ logger.verbose(`Failed to get external IP for ${serviceName}: ${err}`);
170
+ }
171
+ return undefined;
172
+ },
173
+ `external IP for ${serviceName}`,
174
+ 30,
175
+ 5,
176
+ );
177
+ logger.info(`Using external IP for ${serviceName}: ${ip}:${containerPort}`);
178
+ return { url: `http://${ip}:${containerPort}` };
179
+ } catch {
180
+ logger.warn(`External IP not available for ${serviceName} after 5min, using port-forward`);
181
+ }
182
+ }
183
+
184
+ // Fallback to port-forward
185
+ const resource = `svc/${namespace}-${serviceName}`;
186
+
187
+ const { process, port } = await startPortForward({
188
+ resource,
189
+ namespace,
190
+ containerPort,
191
+ });
192
+
193
+ return { url: `http://127.0.0.1:${port}`, process };
194
+ }
195
+
196
+ /**
197
+ * Gets an endpoint for the RPC node service.
198
+ * Tries external IP first, falls back to port-forward.
199
+ *
200
+ * @param namespace - K8s namespace
201
+ * @param usePortForward - If true, skip external IP and use port-forward directly
202
+ */
203
+ export async function getRPCEndpoint(namespace: string, forcePortForward?: boolean): Promise<ServiceEndpoint> {
204
+ return await getServiceEndpoint({
205
+ namespace,
206
+ serviceName: 'rpc-aztec-node',
207
+ containerPort: 8080,
208
+ forcePortForward,
209
+ });
210
+ }
211
+
212
+ /**
213
+ * Gets an endpoint for the Ethereum execution service.
214
+ * Tries external IP first, falls back to port-forward.
215
+ *
216
+ * @param namespace - K8s namespace
217
+ * @param usePortForward - If true, skip external IP and use port-forward directly
218
+ */
219
+ export async function getEthereumEndpoint(namespace: string, forcePortForward?: boolean): Promise<ServiceEndpoint> {
220
+ return await getServiceEndpoint({
221
+ namespace,
222
+ serviceName: 'eth-execution',
223
+ containerPort: 8545,
224
+ forcePortForward,
225
+ });
226
+ }
227
+
228
+ export function startPortForwardForPrometeheus(namespace: string) {
229
+ return startPortForward({
230
+ resource: `svc/${namespace}-prometheus-server`,
231
+ namespace,
232
+ containerPort: 80,
233
+ });
234
+ }
235
+
236
+ export function startPortForwardForRPC(namespace: string, index = 0) {
237
+ return startPortForward({
238
+ resource: `pod/${namespace}-rpc-aztec-node-${index}`,
239
+ namespace,
240
+ containerPort: 8080,
241
+ });
242
+ }
243
+
244
+ export function startPortForwardForEthereum(namespace: string) {
245
+ return startPortForward({
246
+ resource: `services/${namespace}-eth-execution`,
247
+ namespace,
248
+ containerPort: 8545,
249
+ });
250
+ }
251
+
252
+ export async function deleteResourceByName({
253
+ resource,
254
+ namespace,
255
+ name,
256
+ force = false,
257
+ }: {
258
+ resource: string;
259
+ namespace: string;
260
+ name: string;
261
+ force?: boolean;
262
+ }) {
263
+ const command = `kubectl delete ${resource} ${name} -n ${namespace} --ignore-not-found=true --wait=true ${
264
+ force ? '--force' : ''
265
+ }`;
266
+ logger.info(`command: ${command}`);
267
+ const { stdout } = await execAsync(command);
268
+ return stdout;
269
+ }
270
+
271
+ export async function deleteResourceByLabel({
272
+ resource,
273
+ namespace,
274
+ label,
275
+ timeout = '5m',
276
+ force = false,
277
+ }: {
278
+ resource: string;
279
+ namespace: string;
280
+ label: string;
281
+ timeout?: string;
282
+ force?: boolean;
283
+ }) {
284
+ try {
285
+ // Match both plain and group-qualified names (e.g., "podchaos" or "podchaos.chaos-mesh.org")
286
+ const escaped = resource.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
287
+ const regex = `(^|\\.)${escaped}(\\.|$)`;
288
+ await execAsync(`kubectl api-resources --no-headers -o name | grep -Eq '${regex}'`);
289
+ } catch (error) {
290
+ logger.warn(`Resource type '${resource}' not found in cluster, skipping deletion ${error}`);
291
+ return '';
292
+ }
293
+
294
+ const command = `kubectl delete ${resource} -l ${label} -n ${namespace} --ignore-not-found=true --wait=true --timeout=${timeout} ${
295
+ force ? '--force' : ''
296
+ }`;
297
+ logger.info(`command: ${command}`);
298
+ const { stdout } = await execAsync(command);
299
+ return stdout;
300
+ }
301
+
302
+ export async function waitForResourceByLabel({
303
+ resource,
304
+ label,
305
+ namespace,
306
+ condition = 'Ready',
307
+ timeout = '10m',
308
+ }: {
309
+ resource: string;
310
+ label: string;
311
+ namespace: string;
312
+ condition?: string;
313
+ timeout?: string;
314
+ }) {
315
+ const command = `kubectl wait ${resource} -l ${label} --for=condition=${condition} -n ${namespace} --timeout=${timeout}`;
316
+ logger.info(`command: ${command}`);
317
+ const { stdout } = await execAsync(command);
318
+ return stdout;
319
+ }
320
+
321
+ export async function waitForResourceByName({
322
+ resource,
323
+ name,
324
+ namespace,
325
+ condition = 'Ready',
326
+ timeout = '10m',
327
+ }: {
328
+ resource: string;
329
+ name: string;
330
+ namespace: string;
331
+ condition?: string;
332
+ timeout?: string;
333
+ }) {
334
+ const command = `kubectl wait ${resource}/${name} --for=condition=${condition} -n ${namespace} --timeout=${timeout}`;
335
+ logger.info(`command: ${command}`);
336
+ const { stdout } = await execAsync(command);
337
+ return stdout;
338
+ }
339
+
340
+ export async function waitForResourcesByName({
341
+ resource,
342
+ names,
343
+ namespace,
344
+ condition = 'Ready',
345
+ timeout = '10m',
346
+ }: {
347
+ resource: string;
348
+ names: string[];
349
+ namespace: string;
350
+ condition?: string;
351
+ timeout?: string;
352
+ }) {
353
+ if (!names.length) {
354
+ throw new Error(`No ${resource} names provided to waitForResourcesByName`);
355
+ }
356
+
357
+ // Wait all in parallel; if any fails, surface which one.
358
+ await Promise.all(
359
+ names.map(async name => {
360
+ try {
361
+ await waitForResourceByName({ resource, name, namespace, condition, timeout });
362
+ } catch (err) {
363
+ throw new Error(
364
+ `Failed waiting for ${resource}/${name} condition=${condition} timeout=${timeout} namespace=${namespace}: ${String(
365
+ err,
366
+ )}`,
367
+ );
368
+ }
369
+ }),
370
+ );
371
+ }
372
+
373
+ export function getChartDir(spartanDir: string, chartName: string) {
374
+ return path.join(spartanDir.trim(), chartName);
375
+ }