@aztec/end-to-end 4.0.0-nightly.20260121 → 4.0.0-nightly.20260122

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 (56) hide show
  1. package/dest/shared/cross_chain_test_harness.d.ts +3 -4
  2. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  3. package/dest/shared/submit-transactions.d.ts +1 -1
  4. package/dest/shared/submit-transactions.d.ts.map +1 -1
  5. package/dest/shared/submit-transactions.js +1 -4
  6. package/dest/spartan/tx_metrics.d.ts +11 -1
  7. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  8. package/dest/spartan/tx_metrics.js +133 -4
  9. package/dest/spartan/utils/bot.d.ts +27 -0
  10. package/dest/spartan/utils/bot.d.ts.map +1 -0
  11. package/dest/spartan/utils/bot.js +141 -0
  12. package/dest/spartan/utils/chaos.d.ts +79 -0
  13. package/dest/spartan/utils/chaos.d.ts.map +1 -0
  14. package/dest/spartan/utils/chaos.js +142 -0
  15. package/dest/spartan/utils/clients.d.ts +25 -0
  16. package/dest/spartan/utils/clients.d.ts.map +1 -0
  17. package/dest/spartan/utils/clients.js +101 -0
  18. package/dest/spartan/utils/config.d.ts +36 -0
  19. package/dest/spartan/utils/config.d.ts.map +1 -0
  20. package/dest/spartan/utils/config.js +20 -0
  21. package/dest/spartan/utils/health.d.ts +63 -0
  22. package/dest/spartan/utils/health.d.ts.map +1 -0
  23. package/dest/spartan/utils/health.js +202 -0
  24. package/dest/spartan/utils/helm.d.ts +15 -0
  25. package/dest/spartan/utils/helm.d.ts.map +1 -0
  26. package/dest/spartan/utils/helm.js +47 -0
  27. package/dest/spartan/utils/index.d.ts +9 -0
  28. package/dest/spartan/utils/index.d.ts.map +1 -0
  29. package/dest/spartan/utils/index.js +18 -0
  30. package/dest/spartan/utils/k8s.d.ts +59 -0
  31. package/dest/spartan/utils/k8s.d.ts.map +1 -0
  32. package/dest/spartan/utils/k8s.js +185 -0
  33. package/dest/spartan/utils/nodes.d.ts +31 -0
  34. package/dest/spartan/utils/nodes.d.ts.map +1 -0
  35. package/dest/spartan/utils/nodes.js +273 -0
  36. package/dest/spartan/utils/scripts.d.ts +16 -0
  37. package/dest/spartan/utils/scripts.d.ts.map +1 -0
  38. package/dest/spartan/utils/scripts.js +66 -0
  39. package/dest/spartan/utils.d.ts +2 -260
  40. package/dest/spartan/utils.d.ts.map +1 -1
  41. package/dest/spartan/utils.js +1 -942
  42. package/package.json +39 -39
  43. package/src/shared/cross_chain_test_harness.ts +2 -3
  44. package/src/shared/submit-transactions.ts +1 -6
  45. package/src/spartan/tx_metrics.ts +82 -4
  46. package/src/spartan/utils/bot.ts +185 -0
  47. package/src/spartan/utils/chaos.ts +253 -0
  48. package/src/spartan/utils/clients.ts +106 -0
  49. package/src/spartan/utils/config.ts +26 -0
  50. package/src/spartan/utils/health.ts +256 -0
  51. package/src/spartan/utils/helm.ts +84 -0
  52. package/src/spartan/utils/index.ts +58 -0
  53. package/src/spartan/utils/k8s.ts +279 -0
  54. package/src/spartan/utils/nodes.ts +308 -0
  55. package/src/spartan/utils/scripts.ts +63 -0
  56. package/src/spartan/utils.ts +1 -1246
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/end-to-end",
3
- "version": "4.0.0-nightly.20260121",
3
+ "version": "4.0.0-nightly.20260122",
4
4
  "type": "module",
5
5
  "exports": "./dest/index.js",
6
6
  "inherits": [
@@ -25,44 +25,44 @@
25
25
  "formatting": "run -T prettier --check ./src && run -T eslint ./src"
26
26
  },
27
27
  "dependencies": {
28
- "@aztec/accounts": "4.0.0-nightly.20260121",
29
- "@aztec/archiver": "4.0.0-nightly.20260121",
30
- "@aztec/aztec": "4.0.0-nightly.20260121",
31
- "@aztec/aztec-node": "4.0.0-nightly.20260121",
32
- "@aztec/aztec.js": "4.0.0-nightly.20260121",
33
- "@aztec/bb-prover": "4.0.0-nightly.20260121",
34
- "@aztec/bb.js": "4.0.0-nightly.20260121",
35
- "@aztec/blob-client": "4.0.0-nightly.20260121",
36
- "@aztec/blob-lib": "4.0.0-nightly.20260121",
37
- "@aztec/bot": "4.0.0-nightly.20260121",
38
- "@aztec/cli": "4.0.0-nightly.20260121",
39
- "@aztec/constants": "4.0.0-nightly.20260121",
40
- "@aztec/entrypoints": "4.0.0-nightly.20260121",
41
- "@aztec/epoch-cache": "4.0.0-nightly.20260121",
42
- "@aztec/ethereum": "4.0.0-nightly.20260121",
43
- "@aztec/foundation": "4.0.0-nightly.20260121",
44
- "@aztec/kv-store": "4.0.0-nightly.20260121",
45
- "@aztec/l1-artifacts": "4.0.0-nightly.20260121",
46
- "@aztec/merkle-tree": "4.0.0-nightly.20260121",
47
- "@aztec/node-keystore": "4.0.0-nightly.20260121",
48
- "@aztec/noir-contracts.js": "4.0.0-nightly.20260121",
49
- "@aztec/noir-noirc_abi": "4.0.0-nightly.20260121",
50
- "@aztec/noir-protocol-circuits-types": "4.0.0-nightly.20260121",
51
- "@aztec/noir-test-contracts.js": "4.0.0-nightly.20260121",
52
- "@aztec/p2p": "4.0.0-nightly.20260121",
53
- "@aztec/protocol-contracts": "4.0.0-nightly.20260121",
54
- "@aztec/prover-client": "4.0.0-nightly.20260121",
55
- "@aztec/prover-node": "4.0.0-nightly.20260121",
56
- "@aztec/pxe": "4.0.0-nightly.20260121",
57
- "@aztec/sequencer-client": "4.0.0-nightly.20260121",
58
- "@aztec/simulator": "4.0.0-nightly.20260121",
59
- "@aztec/slasher": "4.0.0-nightly.20260121",
60
- "@aztec/stdlib": "4.0.0-nightly.20260121",
61
- "@aztec/telemetry-client": "4.0.0-nightly.20260121",
62
- "@aztec/test-wallet": "4.0.0-nightly.20260121",
63
- "@aztec/validator-client": "4.0.0-nightly.20260121",
64
- "@aztec/validator-ha-signer": "4.0.0-nightly.20260121",
65
- "@aztec/world-state": "4.0.0-nightly.20260121",
28
+ "@aztec/accounts": "4.0.0-nightly.20260122",
29
+ "@aztec/archiver": "4.0.0-nightly.20260122",
30
+ "@aztec/aztec": "4.0.0-nightly.20260122",
31
+ "@aztec/aztec-node": "4.0.0-nightly.20260122",
32
+ "@aztec/aztec.js": "4.0.0-nightly.20260122",
33
+ "@aztec/bb-prover": "4.0.0-nightly.20260122",
34
+ "@aztec/bb.js": "4.0.0-nightly.20260122",
35
+ "@aztec/blob-client": "4.0.0-nightly.20260122",
36
+ "@aztec/blob-lib": "4.0.0-nightly.20260122",
37
+ "@aztec/bot": "4.0.0-nightly.20260122",
38
+ "@aztec/cli": "4.0.0-nightly.20260122",
39
+ "@aztec/constants": "4.0.0-nightly.20260122",
40
+ "@aztec/entrypoints": "4.0.0-nightly.20260122",
41
+ "@aztec/epoch-cache": "4.0.0-nightly.20260122",
42
+ "@aztec/ethereum": "4.0.0-nightly.20260122",
43
+ "@aztec/foundation": "4.0.0-nightly.20260122",
44
+ "@aztec/kv-store": "4.0.0-nightly.20260122",
45
+ "@aztec/l1-artifacts": "4.0.0-nightly.20260122",
46
+ "@aztec/merkle-tree": "4.0.0-nightly.20260122",
47
+ "@aztec/node-keystore": "4.0.0-nightly.20260122",
48
+ "@aztec/noir-contracts.js": "4.0.0-nightly.20260122",
49
+ "@aztec/noir-noirc_abi": "4.0.0-nightly.20260122",
50
+ "@aztec/noir-protocol-circuits-types": "4.0.0-nightly.20260122",
51
+ "@aztec/noir-test-contracts.js": "4.0.0-nightly.20260122",
52
+ "@aztec/p2p": "4.0.0-nightly.20260122",
53
+ "@aztec/protocol-contracts": "4.0.0-nightly.20260122",
54
+ "@aztec/prover-client": "4.0.0-nightly.20260122",
55
+ "@aztec/prover-node": "4.0.0-nightly.20260122",
56
+ "@aztec/pxe": "4.0.0-nightly.20260122",
57
+ "@aztec/sequencer-client": "4.0.0-nightly.20260122",
58
+ "@aztec/simulator": "4.0.0-nightly.20260122",
59
+ "@aztec/slasher": "4.0.0-nightly.20260122",
60
+ "@aztec/stdlib": "4.0.0-nightly.20260122",
61
+ "@aztec/telemetry-client": "4.0.0-nightly.20260122",
62
+ "@aztec/test-wallet": "4.0.0-nightly.20260122",
63
+ "@aztec/validator-client": "4.0.0-nightly.20260122",
64
+ "@aztec/validator-ha-signer": "4.0.0-nightly.20260122",
65
+ "@aztec/world-state": "4.0.0-nightly.20260122",
66
66
  "@iarna/toml": "^2.2.5",
67
67
  "@jest/globals": "^30.0.0",
68
68
  "@noble/curves": "=1.0.0",
@@ -18,7 +18,6 @@ import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses'
18
18
  import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
19
19
  import { EpochNumber } from '@aztec/foundation/branded-types';
20
20
  import { retryUntil } from '@aztec/foundation/retry';
21
- import type { FieldsOf } from '@aztec/foundation/types';
22
21
  import { TestERC20Abi, TokenPortalAbi, TokenPortalBytecode } from '@aztec/l1-artifacts';
23
22
  import { TokenContract } from '@aztec/noir-contracts.js/Token';
24
23
  import { TokenBridgeContract } from '@aztec/noir-contracts.js/TokenBridge';
@@ -276,7 +275,7 @@ export class CrossChainTestHarness {
276
275
  withdrawAmount: bigint,
277
276
  authwitNonce: Fr = Fr.ZERO,
278
277
  authWitness: AuthWitness,
279
- ): Promise<FieldsOf<TxReceipt>> {
278
+ ): Promise<TxReceipt> {
280
279
  const withdrawReceipt = await this.l2Bridge.methods
281
280
  .exit_to_l1_private(this.l2Token.address, this.ethAccount, withdrawAmount, EthAddress.ZERO, authwitNonce)
282
281
  .send({ authWitnesses: [authWitness], from: this.ownerAddress })
@@ -285,7 +284,7 @@ export class CrossChainTestHarness {
285
284
  return withdrawReceipt;
286
285
  }
287
286
 
288
- async withdrawPublicFromAztecToL1(withdrawAmount: bigint, authwitNonce: Fr = Fr.ZERO): Promise<FieldsOf<TxReceipt>> {
287
+ async withdrawPublicFromAztecToL1(withdrawAmount: bigint, authwitNonce: Fr = Fr.ZERO): Promise<TxReceipt> {
289
288
  const withdrawReceipt = await this.l2Bridge.methods
290
289
  .exit_to_l1_public(this.ethAccount, withdrawAmount, EthAddress.ZERO, authwitNonce)
291
290
  .send({ from: this.ownerAddress })
@@ -23,12 +23,7 @@ export const submitTxsTo = async (
23
23
 
24
24
  logger.info(`Tx sent with hash ${txHash}`);
25
25
  const receipt = await tx.getReceipt();
26
- expect(receipt).toEqual(
27
- expect.objectContaining({
28
- status: TxStatus.PENDING,
29
- error: '',
30
- }),
31
- );
26
+ expect(receipt.status).toBe(TxStatus.PENDING);
32
27
  logger.info(`Receipt received for ${txHash}`);
33
28
  txs.push(tx);
34
29
  }),
@@ -1,7 +1,7 @@
1
1
  import type { AztecNode } from '@aztec/aztec.js/node';
2
2
  import type { L2BlockNew } from '@aztec/stdlib/block';
3
3
  import type { TopicType } from '@aztec/stdlib/p2p';
4
- import { Tx, type TxReceipt, TxStatus } from '@aztec/stdlib/tx';
4
+ import { Tx, type TxReceipt } from '@aztec/stdlib/tx';
5
5
 
6
6
  import { createHistogram } from 'perf_hooks';
7
7
 
@@ -24,6 +24,14 @@ export class TxInclusionMetrics {
24
24
 
25
25
  private p2pGossipLatencyByTopic: Partial<Record<TopicType, { p50: number; p95: number }>> = {};
26
26
 
27
+ private attestationLatency: { p50: number; p95: number } | undefined;
28
+ private attestationCounts: { success: number; failedBad: number; failedNode: number } | undefined;
29
+ private reqRespStats: { fraction: number; delayP50: number; delayP95: number } | undefined;
30
+ private peerStats: { avgCount: number; connectionDurationP50: number; connectionDurationP95: number } | undefined;
31
+ private mempoolMinedDelay:
32
+ | { txP50: number; txP95: number; attestationP50: number; attestationP95: number }
33
+ | undefined;
34
+
27
35
  constructor(private aztecNode: AztecNode) {}
28
36
 
29
37
  recordSentTx(tx: Tx, group: string): void {
@@ -45,8 +53,8 @@ export class TxInclusionMetrics {
45
53
  }
46
54
 
47
55
  async recordMinedTx(txReceipt: TxReceipt): Promise<void> {
48
- const { status, txHash, blockNumber } = txReceipt;
49
- if (status !== TxStatus.SUCCESS || !blockNumber) {
56
+ const { txHash, blockNumber } = txReceipt;
57
+ if (!txReceipt.isMined() || !txReceipt.hasExecutionSucceeded() || !blockNumber) {
50
58
  return;
51
59
  }
52
60
 
@@ -111,6 +119,26 @@ export class TxInclusionMetrics {
111
119
  this.p2pGossipLatencyByTopic[topicName] = { p50, p95 };
112
120
  }
113
121
 
122
+ public recordAttestationLatency(p50: number, p95: number): void {
123
+ this.attestationLatency = { p50, p95 };
124
+ }
125
+
126
+ public recordAttestationCounts(success: number, failedBad: number, failedNode: number): void {
127
+ this.attestationCounts = { success, failedBad, failedNode };
128
+ }
129
+
130
+ public recordReqRespStats(fraction: number, delayP50: number, delayP95: number): void {
131
+ this.reqRespStats = { fraction, delayP50, delayP95 };
132
+ }
133
+
134
+ public recordPeerStats(avgCount: number, connectionDurationP50: number, connectionDurationP95: number): void {
135
+ this.peerStats = { avgCount, connectionDurationP50, connectionDurationP95 };
136
+ }
137
+
138
+ public recordMempoolMinedDelay(txP50: number, txP95: number, attestationP50: number, attestationP95: number): void {
139
+ this.mempoolMinedDelay = { txP50, txP95, attestationP50, attestationP95 };
140
+ }
141
+
114
142
  toGithubActionBenchmarkJSON(): Array<{ name: string; unit: string; value: number; range?: number; extra?: string }> {
115
143
  const data: Array<{ name: string; unit: string; value: number; range?: number; extra?: string }> = [];
116
144
  for (const group of this.groups) {
@@ -148,6 +176,56 @@ export class TxInclusionMetrics {
148
176
  });
149
177
  }
150
178
 
151
- return data;
179
+ if (this.attestationLatency) {
180
+ data.push(
181
+ { name: 'attestation_latency/p50', unit: 'ms', value: this.attestationLatency.p50 },
182
+ { name: 'attestation_latency/p95', unit: 'ms', value: this.attestationLatency.p95 },
183
+ );
184
+ }
185
+
186
+ if (this.attestationCounts) {
187
+ const { success, failedBad, failedNode } = this.attestationCounts;
188
+ const total = success + failedBad + failedNode;
189
+ const ratio = total > 0 ? success / total : 0;
190
+ data.push(
191
+ { name: 'attestation/success_count', unit: 'count', value: success },
192
+ { name: 'attestation/failed_bad_proposal_count', unit: 'count', value: failedBad },
193
+ { name: 'attestation/failed_node_issue_count', unit: 'count', value: failedNode },
194
+ { name: 'attestation/success_ratio', unit: 'ratio', value: ratio },
195
+ );
196
+ }
197
+
198
+ if (this.reqRespStats) {
199
+ data.push(
200
+ { name: 'req_resp/txs_requested_fraction', unit: 'ratio', value: this.reqRespStats.fraction },
201
+ { name: 'req_resp/delay_p50', unit: 'ms', value: this.reqRespStats.delayP50 },
202
+ { name: 'req_resp/delay_p95', unit: 'ms', value: this.reqRespStats.delayP95 },
203
+ );
204
+ }
205
+
206
+ if (this.peerStats) {
207
+ data.push(
208
+ { name: 'peers/avg_count', unit: 'peers', value: this.peerStats.avgCount },
209
+ { name: 'peers/connection_duration_p50', unit: 'ms', value: this.peerStats.connectionDurationP50 },
210
+ { name: 'peers/connection_duration_p95', unit: 'ms', value: this.peerStats.connectionDurationP95 },
211
+ );
212
+ }
213
+
214
+ if (this.mempoolMinedDelay) {
215
+ data.push(
216
+ { name: 'mempool/tx_mined_delay_p50', unit: 'ms', value: this.mempoolMinedDelay.txP50 },
217
+ { name: 'mempool/tx_mined_delay_p95', unit: 'ms', value: this.mempoolMinedDelay.txP95 },
218
+ { name: 'mempool/attestation_mined_delay_p50', unit: 'ms', value: this.mempoolMinedDelay.attestationP50 },
219
+ { name: 'mempool/attestation_mined_delay_p95', unit: 'ms', value: this.mempoolMinedDelay.attestationP95 },
220
+ );
221
+ }
222
+
223
+ const scenario = process.env.BENCH_SCENARIO?.trim();
224
+ if (!scenario) {
225
+ return data;
226
+ }
227
+
228
+ const scenarioPrefix = `scenario/${scenario}/`;
229
+ return data.map(entry => ({ ...entry, name: `${scenarioPrefix}${entry.name}` }));
152
230
  }
153
231
  }
@@ -0,0 +1,185 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+ import { sleep } from '@aztec/foundation/sleep';
3
+
4
+ import { exec } from 'child_process';
5
+ import { promisify } from 'util';
6
+
7
+ import { execHelmCommand, forceDeleteHelmReleaseRecord, getHelmReleaseStatus, hasDeployedHelmRelease } from './helm.js';
8
+ import { deleteResourceByLabel, getChartDir, waitForResourceByLabel } from './k8s.js';
9
+
10
+ const execAsync = promisify(exec);
11
+
12
+ export async function restartBot(namespace: string, log: Logger) {
13
+ log.info(`Restarting bot`);
14
+ await deleteResourceByLabel({ resource: 'pods', namespace, label: 'app.kubernetes.io/name=bot' });
15
+ await sleep(10 * 1000);
16
+ // Some bot images may take time to report Ready due to heavy boot-time proving.
17
+ // Waiting for PodReadyToStartContainers ensures the pod is scheduled and starting without blocking on full readiness.
18
+ await waitForResourceByLabel({
19
+ resource: 'pods',
20
+ namespace,
21
+ label: 'app.kubernetes.io/name=bot',
22
+ condition: 'PodReadyToStartContainers',
23
+ });
24
+ log.info(`Bot restarted`);
25
+ }
26
+
27
+ /**
28
+ * Installs or upgrades the transfer bot Helm release for the given namespace.
29
+ * Intended for test setup to enable L2 traffic generation only when needed.
30
+ */
31
+ export async function installTransferBot({
32
+ namespace,
33
+ spartanDir,
34
+ logger: log,
35
+ replicas = 1,
36
+ txIntervalSeconds = 10,
37
+ followChain = 'PENDING',
38
+ mnemonic = process.env.LABS_INFRA_MNEMONIC ?? 'test test test test test test test test test test test junk',
39
+ mnemonicStartIndex,
40
+ botPrivateKey = process.env.BOT_TRANSFERS_L2_PRIVATE_KEY ?? '0xcafe01',
41
+ nodeUrl,
42
+ timeout = '15m',
43
+ reuseValues = true,
44
+ aztecSlotDuration = Number(process.env.AZTEC_SLOT_DURATION ?? 12),
45
+ }: {
46
+ namespace: string;
47
+ spartanDir: string;
48
+ logger: Logger;
49
+ replicas?: number;
50
+ txIntervalSeconds?: number;
51
+ followChain?: string;
52
+ mnemonic?: string;
53
+ mnemonicStartIndex?: number | string;
54
+ botPrivateKey?: string;
55
+ nodeUrl?: string;
56
+ timeout?: string;
57
+ reuseValues?: boolean;
58
+ aztecSlotDuration?: number;
59
+ }) {
60
+ const instanceName = `${namespace}-bot-transfers`;
61
+ const helmChartDir = getChartDir(spartanDir, 'aztec-bot');
62
+ const resolvedNodeUrl = nodeUrl ?? `http://${namespace}-rpc-aztec-node.${namespace}.svc.cluster.local:8080`;
63
+
64
+ log.info(`Installing/upgrading transfer bot: replicas=${replicas}, followChain=${followChain}`);
65
+
66
+ const values: Record<string, string | number | boolean> = {
67
+ 'bot.replicaCount': replicas,
68
+ 'bot.txIntervalSeconds': txIntervalSeconds,
69
+ 'bot.followChain': followChain,
70
+ 'bot.botPrivateKey': botPrivateKey,
71
+ 'bot.nodeUrl': resolvedNodeUrl,
72
+ 'bot.mnemonic': mnemonic,
73
+ 'bot.feePaymentMethod': 'fee_juice',
74
+ 'aztec.slotDuration': aztecSlotDuration,
75
+ // Ensure bot can reach its own PXE started in-process (default rpc.port is 8080)
76
+ // Note: since aztec-bot depends on aztec-node with alias `bot`, env vars go under `bot.node.env`.
77
+ 'bot.node.env.BOT_PXE_URL': 'http://127.0.0.1:8080',
78
+ // Provide L1 execution RPC for bridging fee juice
79
+ 'bot.node.env.ETHEREUM_HOSTS': `http://${namespace}-eth-execution.${namespace}.svc.cluster.local:8545`,
80
+ // Provide L1 mnemonic for bridging (falls back to labs mnemonic)
81
+ 'bot.node.env.BOT_L1_MNEMONIC': mnemonic,
82
+
83
+ // The bot does not need Kubernetes API access. Disable RBAC + ServiceAccount creation so the chart
84
+ // can be installed by users without cluster-scoped RBAC permissions.
85
+ 'bot.rbac.create': false,
86
+ 'bot.serviceAccount.create': false,
87
+ 'bot.serviceAccount.name': 'default',
88
+ };
89
+ // Ensure we derive a funded L1 key (index 0 is funded on anvil default mnemonic)
90
+ if (mnemonicStartIndex === undefined) {
91
+ values['bot.mnemonicStartIndex'] = 0;
92
+ }
93
+ // Also pass a funded private key directly if available
94
+ if (process.env.FUNDING_PRIVATE_KEY) {
95
+ values['bot.node.env.BOT_L1_PRIVATE_KEY'] = process.env.FUNDING_PRIVATE_KEY;
96
+ }
97
+ // Align bot image with the running network image: prefer env var, else detect from a validator pod
98
+ let repositoryFromEnv: string | undefined;
99
+ let tagFromEnv: string | undefined;
100
+ const aztecDockerImage = process.env.AZTEC_DOCKER_IMAGE;
101
+ if (aztecDockerImage && aztecDockerImage.includes(':')) {
102
+ const lastColon = aztecDockerImage.lastIndexOf(':');
103
+ repositoryFromEnv = aztecDockerImage.slice(0, lastColon);
104
+ tagFromEnv = aztecDockerImage.slice(lastColon + 1);
105
+ }
106
+
107
+ let repository = repositoryFromEnv;
108
+ let tag = tagFromEnv;
109
+ if (!repository || !tag) {
110
+ try {
111
+ const { stdout } = await execAsync(
112
+ `kubectl get pods -l app.kubernetes.io/name=validator -n ${namespace} -o jsonpath='{.items[0].spec.containers[?(@.name=="aztec")].image}' | cat`,
113
+ );
114
+ const image = stdout.trim().replace(/^'|'$/g, '');
115
+ if (image && image.includes(':')) {
116
+ const lastColon = image.lastIndexOf(':');
117
+ repository = image.slice(0, lastColon);
118
+ tag = image.slice(lastColon + 1);
119
+ }
120
+ } catch (err) {
121
+ log.warn(`Could not detect aztec image from validator pod: ${String(err)}`);
122
+ }
123
+ }
124
+ if (repository && tag) {
125
+ values['global.aztecImage.repository'] = repository;
126
+ values['global.aztecImage.tag'] = tag;
127
+ }
128
+ if (mnemonicStartIndex !== undefined) {
129
+ values['bot.mnemonicStartIndex'] =
130
+ typeof mnemonicStartIndex === 'string' ? mnemonicStartIndex : Number(mnemonicStartIndex);
131
+ }
132
+
133
+ // If a previous install attempt left the release in a non-deployed state (e.g. FAILED),
134
+ // `helm upgrade --install` can error with "has no deployed releases".
135
+ // In that case, clear the release record and do a clean install.
136
+ const existingStatus = await getHelmReleaseStatus(instanceName, namespace);
137
+ if (existingStatus && existingStatus.toLowerCase() !== 'deployed') {
138
+ log.warn(`Transfer bot release ${instanceName} is in status '${existingStatus}'. Reinstalling cleanly.`);
139
+ await execAsync(`helm uninstall ${instanceName} --namespace ${namespace} --wait --ignore-not-found`).catch(
140
+ () => undefined,
141
+ );
142
+ // If helm left the release in `uninstalling`, force-delete the record so we can reinstall.
143
+ const afterUninstallStatus = await getHelmReleaseStatus(instanceName, namespace);
144
+ if (afterUninstallStatus?.toLowerCase() === 'uninstalling') {
145
+ await forceDeleteHelmReleaseRecord(instanceName, namespace, log);
146
+ }
147
+ }
148
+
149
+ // `--reuse-values` fails if the release has never successfully deployed (e.g. first install, or a previous failed install).
150
+ // Only reuse values when we have a deployed release to reuse from.
151
+ const effectiveReuseValues = reuseValues && (await hasDeployedHelmRelease(instanceName, namespace));
152
+
153
+ await execHelmCommand({
154
+ instanceName,
155
+ helmChartDir,
156
+ namespace,
157
+ valuesFile: undefined,
158
+ timeout,
159
+ values: values as unknown as Record<string, string | number | boolean>,
160
+ reuseValues: effectiveReuseValues,
161
+ });
162
+
163
+ if (replicas > 0) {
164
+ await waitForResourceByLabel({
165
+ resource: 'pods',
166
+ namespace,
167
+ label: 'app.kubernetes.io/name=bot',
168
+ condition: 'PodReadyToStartContainers',
169
+ });
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Uninstalls the transfer bot Helm release from the given namespace.
175
+ * Intended for test teardown to clean up bot resources.
176
+ */
177
+ export async function uninstallTransferBot(namespace: string, log: Logger) {
178
+ const instanceName = `${namespace}-bot-transfers`;
179
+ log.info(`Uninstalling transfer bot release ${instanceName}`);
180
+ await execAsync(`helm uninstall ${instanceName} --namespace ${namespace} --wait --ignore-not-found`);
181
+ // Ensure any leftover pods are removed
182
+ await deleteResourceByLabel({ resource: 'pods', namespace, label: 'app.kubernetes.io/name=bot' }).catch(
183
+ () => undefined,
184
+ );
185
+ }