@aztec/end-to-end 0.0.1-commit.e3c1de76 → 0.0.1-commit.e57c76e

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 (230) hide show
  1. package/README.md +27 -0
  2. package/dest/bench/client_flows/benchmark.d.ts +15 -1
  3. package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
  4. package/dest/bench/client_flows/benchmark.js +17 -0
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts +3 -3
  6. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  7. package/dest/bench/client_flows/client_flows_benchmark.js +36 -39
  8. package/dest/bench/client_flows/config.d.ts +2 -2
  9. package/dest/bench/client_flows/config.d.ts.map +1 -1
  10. package/dest/bench/client_flows/config.js +18 -0
  11. package/dest/bench/utils.d.ts +1 -1
  12. package/dest/bench/utils.d.ts.map +1 -1
  13. package/dest/bench/utils.js +8 -3
  14. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +8 -5
  15. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  16. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +36 -17
  17. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +16 -5
  18. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  19. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +42 -9
  20. package/dest/e2e_deploy_contract/deploy_test.d.ts +4 -4
  21. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  22. package/dest/e2e_deploy_contract/deploy_test.js +2 -1
  23. package/dest/e2e_epochs/epochs_test.d.ts +33 -8
  24. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  25. package/dest/e2e_epochs/epochs_test.js +143 -44
  26. package/dest/e2e_fees/fees_test.d.ts +6 -3
  27. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  28. package/dest/e2e_fees/fees_test.js +50 -17
  29. package/dest/e2e_nested_contract/nested_contract_test.d.ts +3 -3
  30. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  31. package/dest/e2e_nested_contract/nested_contract_test.js +6 -7
  32. package/dest/e2e_p2p/inactivity_slash_test.d.ts +1 -1
  33. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -1
  34. package/dest/e2e_p2p/inactivity_slash_test.js +4 -3
  35. package/dest/e2e_p2p/p2p_network.d.ts +14 -12
  36. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  37. package/dest/e2e_p2p/p2p_network.js +70 -34
  38. package/dest/e2e_p2p/reqresp/utils.d.ts +3 -3
  39. package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -1
  40. package/dest/e2e_p2p/reqresp/utils.js +67 -14
  41. package/dest/e2e_p2p/shared.d.ts +37 -8
  42. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  43. package/dest/e2e_p2p/shared.js +91 -51
  44. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +2 -0
  45. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +1 -0
  46. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.js +184 -0
  47. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts +18 -0
  48. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +1 -0
  49. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.js +120 -0
  50. package/dest/e2e_token_contract/token_contract_test.d.ts +6 -4
  51. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  52. package/dest/e2e_token_contract/token_contract_test.js +23 -11
  53. package/dest/fixtures/authwit_proxy.d.ts +15 -0
  54. package/dest/fixtures/authwit_proxy.d.ts.map +1 -0
  55. package/dest/fixtures/authwit_proxy.js +34 -0
  56. package/dest/fixtures/e2e_prover_test.d.ts +9 -8
  57. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  58. package/dest/fixtures/e2e_prover_test.js +39 -50
  59. package/dest/fixtures/elu_monitor.d.ts +21 -0
  60. package/dest/fixtures/elu_monitor.d.ts.map +1 -0
  61. package/dest/fixtures/elu_monitor.js +102 -0
  62. package/dest/fixtures/fixtures.d.ts +74 -1
  63. package/dest/fixtures/fixtures.d.ts.map +1 -1
  64. package/dest/fixtures/fixtures.js +71 -0
  65. package/dest/fixtures/get_bb_config.d.ts +1 -1
  66. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  67. package/dest/fixtures/get_bb_config.js +5 -5
  68. package/dest/fixtures/ha_setup.d.ts +71 -0
  69. package/dest/fixtures/ha_setup.d.ts.map +1 -0
  70. package/dest/fixtures/ha_setup.js +116 -0
  71. package/dest/fixtures/index.d.ts +2 -1
  72. package/dest/fixtures/index.d.ts.map +1 -1
  73. package/dest/fixtures/index.js +1 -0
  74. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts +25 -0
  75. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts.map +1 -0
  76. package/dest/fixtures/schnorr_hardcoded_account_contract.js +37 -0
  77. package/dest/fixtures/setup.d.ts +86 -32
  78. package/dest/fixtures/setup.d.ts.map +1 -1
  79. package/dest/fixtures/setup.js +209 -169
  80. package/dest/fixtures/setup_p2p_test.d.ts +22 -10
  81. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  82. package/dest/fixtures/setup_p2p_test.js +23 -17
  83. package/dest/fixtures/token_utils.d.ts +2 -2
  84. package/dest/fixtures/token_utils.d.ts.map +1 -1
  85. package/dest/fixtures/token_utils.js +5 -7
  86. package/dest/fixtures/utils.d.ts +2 -2
  87. package/dest/fixtures/utils.d.ts.map +1 -1
  88. package/dest/fixtures/utils.js +1 -1
  89. package/dest/forward-compatibility/wallet_rpc_client.d.ts +7 -0
  90. package/dest/forward-compatibility/wallet_rpc_client.d.ts.map +1 -0
  91. package/dest/forward-compatibility/wallet_rpc_client.js +15 -0
  92. package/dest/forward-compatibility/wallet_service.d.ts +3 -0
  93. package/dest/forward-compatibility/wallet_service.d.ts.map +1 -0
  94. package/dest/forward-compatibility/wallet_service.js +109 -0
  95. package/dest/install_legacy_contracts.d.cts +10 -0
  96. package/dest/install_legacy_contracts.d.cts.map +1 -0
  97. package/dest/legacy-jest-resolver.d.cts +3 -0
  98. package/dest/legacy-jest-resolver.d.cts.map +1 -0
  99. package/dest/shared/cross_chain_test_harness.d.ts +4 -2
  100. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  101. package/dest/shared/cross_chain_test_harness.js +22 -18
  102. package/dest/shared/gas_portal_test_harness.d.ts +8 -5
  103. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  104. package/dest/shared/gas_portal_test_harness.js +19 -10
  105. package/dest/shared/index.d.ts +2 -1
  106. package/dest/shared/index.d.ts.map +1 -1
  107. package/dest/shared/index.js +1 -0
  108. package/dest/shared/jest_setup.js +41 -1
  109. package/dest/shared/mock_state_view.d.ts +86 -0
  110. package/dest/shared/mock_state_view.d.ts.map +1 -0
  111. package/dest/shared/mock_state_view.js +186 -0
  112. package/dest/shared/submit-transactions.d.ts +2 -2
  113. package/dest/shared/submit-transactions.d.ts.map +1 -1
  114. package/dest/shared/submit-transactions.js +1 -1
  115. package/dest/shared/uniswap_l1_l2.d.ts +1 -1
  116. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  117. package/dest/shared/uniswap_l1_l2.js +57 -40
  118. package/dest/shared/wait_for_l1_to_l2_message.d.ts +13 -0
  119. package/dest/shared/wait_for_l1_to_l2_message.d.ts.map +1 -0
  120. package/dest/shared/wait_for_l1_to_l2_message.js +10 -0
  121. package/dest/simulators/lending_simulator.d.ts +10 -3
  122. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  123. package/dest/simulators/lending_simulator.js +26 -14
  124. package/dest/simulators/token_simulator.d.ts +1 -1
  125. package/dest/simulators/token_simulator.d.ts.map +1 -1
  126. package/dest/simulators/token_simulator.js +3 -24
  127. package/dest/spartan/setup_test_wallets.d.ts +12 -3
  128. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  129. package/dest/spartan/setup_test_wallets.js +108 -41
  130. package/dest/spartan/tx_metrics.d.ts +18 -4
  131. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  132. package/dest/spartan/tx_metrics.js +74 -21
  133. package/dest/spartan/utils/bot.d.ts +3 -2
  134. package/dest/spartan/utils/bot.d.ts.map +1 -1
  135. package/dest/spartan/utils/bot.js +2 -1
  136. package/dest/spartan/utils/config.d.ts +11 -28
  137. package/dest/spartan/utils/config.d.ts.map +1 -1
  138. package/dest/spartan/utils/config.js +4 -1
  139. package/dest/spartan/utils/index.d.ts +5 -3
  140. package/dest/spartan/utils/index.d.ts.map +1 -1
  141. package/dest/spartan/utils/index.js +5 -1
  142. package/dest/spartan/utils/k8s.d.ts +3 -1
  143. package/dest/spartan/utils/k8s.d.ts.map +1 -1
  144. package/dest/spartan/utils/k8s.js +6 -0
  145. package/dest/spartan/utils/nodes.d.ts +4 -5
  146. package/dest/spartan/utils/nodes.d.ts.map +1 -1
  147. package/dest/spartan/utils/nodes.js +11 -11
  148. package/dest/spartan/utils/pod_logs.d.ts +25 -0
  149. package/dest/spartan/utils/pod_logs.d.ts.map +1 -0
  150. package/dest/spartan/utils/pod_logs.js +74 -0
  151. package/dest/spartan/utils/scripts.d.ts +18 -4
  152. package/dest/spartan/utils/scripts.d.ts.map +1 -1
  153. package/dest/spartan/utils/scripts.js +19 -4
  154. package/dest/test-wallet/test_wallet.d.ts +85 -0
  155. package/dest/test-wallet/test_wallet.d.ts.map +1 -0
  156. package/dest/test-wallet/test_wallet.js +273 -0
  157. package/dest/test-wallet/utils.d.ts +41 -0
  158. package/dest/test-wallet/utils.d.ts.map +1 -0
  159. package/dest/test-wallet/utils.js +66 -0
  160. package/dest/test-wallet/wallet_worker_script.d.ts +2 -0
  161. package/dest/test-wallet/wallet_worker_script.d.ts.map +1 -0
  162. package/dest/test-wallet/wallet_worker_script.js +53 -0
  163. package/dest/test-wallet/worker_wallet.d.ts +53 -0
  164. package/dest/test-wallet/worker_wallet.d.ts.map +1 -0
  165. package/dest/test-wallet/worker_wallet.js +155 -0
  166. package/dest/test-wallet/worker_wallet_schema.d.ts +160 -0
  167. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -0
  168. package/dest/test-wallet/worker_wallet_schema.js +22 -0
  169. package/package.json +52 -45
  170. package/src/bench/client_flows/benchmark.ts +19 -0
  171. package/src/bench/client_flows/client_flows_benchmark.ts +64 -49
  172. package/src/bench/client_flows/config.ts +9 -1
  173. package/src/bench/utils.ts +10 -4
  174. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +52 -25
  175. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +56 -19
  176. package/src/e2e_deploy_contract/deploy_test.ts +6 -5
  177. package/src/e2e_epochs/epochs_test.ts +166 -68
  178. package/src/e2e_fees/bridging_race.notest.ts +1 -1
  179. package/src/e2e_fees/fees_test.ts +57 -32
  180. package/src/e2e_nested_contract/nested_contract_test.ts +10 -6
  181. package/src/e2e_p2p/inactivity_slash_test.ts +8 -7
  182. package/src/e2e_p2p/p2p_network.ts +93 -49
  183. package/src/e2e_p2p/reqresp/utils.ts +84 -17
  184. package/src/e2e_p2p/shared.ts +109 -65
  185. package/src/e2e_storage_proof/fixtures/storage_proof.json +915 -0
  186. package/src/e2e_storage_proof/fixtures/storage_proof_fetcher.ts +190 -0
  187. package/src/e2e_storage_proof/fixtures/storage_proof_fixture.ts +173 -0
  188. package/src/e2e_token_contract/token_contract_test.ts +38 -11
  189. package/src/fixtures/authwit_proxy.ts +54 -0
  190. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  191. package/src/fixtures/e2e_prover_test.ts +49 -56
  192. package/src/fixtures/elu_monitor.ts +126 -0
  193. package/src/fixtures/fixtures.ts +93 -0
  194. package/src/fixtures/get_bb_config.ts +7 -6
  195. package/src/fixtures/ha_setup.ts +188 -0
  196. package/src/fixtures/index.ts +1 -0
  197. package/src/fixtures/schnorr_hardcoded_account_contract.ts +49 -0
  198. package/src/fixtures/setup.ts +272 -233
  199. package/src/fixtures/setup_p2p_test.ts +37 -32
  200. package/src/fixtures/token_utils.ts +3 -3
  201. package/src/fixtures/utils.ts +2 -0
  202. package/src/forward-compatibility/wallet_rpc_client.ts +14 -0
  203. package/src/forward-compatibility/wallet_service.ts +104 -0
  204. package/src/guides/up_quick_start.sh +3 -5
  205. package/src/install_legacy_contracts.cjs +75 -0
  206. package/src/legacy-jest-resolver.cjs +112 -0
  207. package/src/shared/cross_chain_test_harness.ts +27 -13
  208. package/src/shared/gas_portal_test_harness.ts +21 -11
  209. package/src/shared/index.ts +1 -0
  210. package/src/shared/jest_setup.ts +51 -1
  211. package/src/shared/mock_state_view.ts +188 -0
  212. package/src/shared/submit-transactions.ts +3 -2
  213. package/src/shared/uniswap_l1_l2.ts +103 -54
  214. package/src/shared/wait_for_l1_to_l2_message.ts +23 -0
  215. package/src/simulators/lending_simulator.ts +32 -14
  216. package/src/simulators/token_simulator.ts +6 -30
  217. package/src/spartan/setup_test_wallets.ts +146 -35
  218. package/src/spartan/tx_metrics.ts +82 -24
  219. package/src/spartan/utils/bot.ts +4 -1
  220. package/src/spartan/utils/config.ts +3 -0
  221. package/src/spartan/utils/index.ts +8 -1
  222. package/src/spartan/utils/k8s.ts +8 -0
  223. package/src/spartan/utils/nodes.ts +17 -12
  224. package/src/spartan/utils/pod_logs.ts +99 -0
  225. package/src/spartan/utils/scripts.ts +43 -7
  226. package/src/test-wallet/test_wallet.ts +376 -0
  227. package/src/test-wallet/utils.ts +108 -0
  228. package/src/test-wallet/wallet_worker_script.ts +63 -0
  229. package/src/test-wallet/worker_wallet.ts +218 -0
  230. package/src/test-wallet/worker_wallet_schema.ts +13 -0
@@ -5,7 +5,7 @@
5
5
  export { type TestConfig, setupEnvironment } from './config.js';
6
6
 
7
7
  // Scripts
8
- export { getGitProjectRoot, getAztecBin, runAztecBin, runProjectScript } from './scripts.js';
8
+ export { type ScriptResult, getGitProjectRoot, getAztecBin, runAztecBin, runProjectScript } from './scripts.js';
9
9
 
10
10
  // K8s operations
11
11
  export {
@@ -25,6 +25,7 @@ export {
25
25
  getRPCEndpoint,
26
26
  getEthereumEndpoint,
27
27
  createResilientPrometheusConnection,
28
+ scaleProverAgents,
28
29
  } from './k8s.js';
29
30
 
30
31
  // Chaos Mesh
@@ -40,6 +41,9 @@ export {
40
41
  applyNetworkShaping,
41
42
  } from './chaos.js';
42
43
 
44
+ // Helm
45
+ export { hasDeployedHelmRelease } from './helm.js';
46
+
43
47
  // Bot management
44
48
  export { restartBot, installTransferBot, uninstallTransferBot } from './bot.js';
45
49
 
@@ -62,3 +66,6 @@ export { getPublicViemClient, getL1DeploymentAddresses, getNodeClient } from './
62
66
 
63
67
  // Health checks
64
68
  export { ChainHealth, type ChainHealthSnapshot } from './health.js';
69
+
70
+ // Pod log extraction
71
+ export { type BlockBuiltLogEntry, fetchBlockBuiltLogs } from './pod_logs.js';
@@ -522,6 +522,14 @@ export function createResilientPrometheusConnection(
522
522
  return { connect, runAlertCheck };
523
523
  }
524
524
 
525
+ /** Scales the prover-agent Deployment to the given number of replicas. */
526
+ export async function scaleProverAgents(namespace: string, replicas: number, log: Logger): Promise<void> {
527
+ const label = 'app.kubernetes.io/component=prover-agent';
528
+ const command = `kubectl scale deployment -l ${label} -n ${namespace} --replicas=${replicas} --timeout=2m`;
529
+ log.info(`Scaling prover agents to ${replicas}: ${command}`);
530
+ await execAsync(command);
531
+ }
532
+
525
533
  export function getChartDir(spartanDir: string, chartName: string) {
526
534
  return path.join(spartanDir.trim(), chartName);
527
535
  }
@@ -71,7 +71,7 @@ export async function waitForProvenToAdvance(
71
71
  // Get current proven block number
72
72
  let initialProvenBlock: number;
73
73
  try {
74
- const tips = await node.getL2Tips();
74
+ const tips = await node.getChainTips();
75
75
  initialProvenBlock = Number(tips.proven.block.number);
76
76
  log.info(`Current proven block: ${initialProvenBlock}. Waiting for it to increase...`);
77
77
  } catch (err) {
@@ -82,7 +82,7 @@ export async function waitForProvenToAdvance(
82
82
  await retryUntil(
83
83
  async () => {
84
84
  try {
85
- const tips = await node.getL2Tips();
85
+ const tips = await node.getChainTips();
86
86
  const currentProvenBlock = Number(tips.proven.block.number);
87
87
  const proposedBlock = Number(tips.proposed.number);
88
88
 
@@ -173,7 +173,7 @@ export async function withSequencersAdmin<T>(env: TestConfig, fn: (node: AztecNo
173
173
  if (statusRes.status !== 200) {
174
174
  throw new Error(`Admin endpoint returned status ${statusRes.status}`);
175
175
  }
176
- const client = createAztecNodeAdminClient(url);
176
+ const client = createAztecNodeAdminClient(url, {}, undefined, env.AZTEC_ADMIN_API_KEY);
177
177
  return { result: await fn(client), process };
178
178
  } catch (err) {
179
179
  // Kill the port-forward before retrying
@@ -255,21 +255,18 @@ export async function initHADb(namespace: string): Promise<void> {
255
255
  }
256
256
 
257
257
  /**
258
- * Enables or disables probabilistic transaction dropping on validators and waits for rollout.
259
- * Wired to env vars P2P_DROP_TX and P2P_DROP_TX_CHANCE via Helm values.
258
+ * Sets probabilistic transaction dropping on validators and waits for rollout.
259
+ * Use probability=0 to disable. Wired to env var P2P_DROP_TX_CHANCE via Helm values.
260
260
  */
261
261
  export async function setValidatorTxDrop({
262
262
  namespace,
263
- enabled,
264
263
  probability,
265
264
  logger: log,
266
265
  }: {
267
266
  namespace: string;
268
- enabled: boolean;
269
267
  probability: number;
270
268
  logger: Logger;
271
269
  }) {
272
- const drop = enabled ? 'true' : 'false';
273
270
  const prob = String(probability);
274
271
 
275
272
  const selectors = ['app.kubernetes.io/name=validator', 'app.kubernetes.io/component=validator', 'app=validator'];
@@ -284,7 +281,7 @@ export async function setValidatorTxDrop({
284
281
  if (names.length === 0) {
285
282
  continue;
286
283
  }
287
- const cmd = `kubectl set env statefulset -l ${selector} -n ${namespace} P2P_DROP_TX=${drop} P2P_DROP_TX_CHANCE=${prob}`;
284
+ const cmd = `kubectl set env statefulset -l ${selector} -n ${namespace} P2P_DROP_TX_CHANCE=${prob}`;
288
285
  log.info(`command: ${cmd}`);
289
286
  await execAsync(cmd);
290
287
  updated = true;
@@ -366,16 +363,24 @@ export async function enableValidatorDynamicBootNode(
366
363
  */
367
364
  export async function rollAztecPods(namespace: string, clearState: boolean = false) {
368
365
  // Pod components use 'validator', but StatefulSets and PVCs use 'sequencer-node' for validators
366
+ // RPC nodes have nodeType='rpc-node' in Helm values, so their component label is 'rpc-node' (not 'rpc')
369
367
  const podComponents = [
370
368
  'p2p-bootstrap',
371
369
  'prover-node',
372
370
  'prover-broker',
373
371
  'prover-agent',
374
372
  'sequencer-node',
375
- 'rpc',
373
+ 'rpc-node',
374
+ 'validator-ha-db',
375
+ ];
376
+ const pvcComponents = [
377
+ 'p2p-bootstrap',
378
+ 'prover-node',
379
+ 'prover-broker',
380
+ 'sequencer-node',
381
+ 'rpc-node',
376
382
  'validator-ha-db',
377
383
  ];
378
- const pvcComponents = ['p2p-bootstrap', 'prover-node', 'prover-broker', 'sequencer-node', 'rpc', 'validator-ha-db'];
379
384
  // StatefulSet components that need to be scaled down before PVC deletion
380
385
  // Note: validators use 'sequencer-node' as component label, not 'validator'
381
386
  const statefulSetComponents = [
@@ -383,7 +388,7 @@ export async function rollAztecPods(namespace: string, clearState: boolean = fal
383
388
  'prover-node',
384
389
  'prover-broker',
385
390
  'sequencer-node',
386
- 'rpc',
391
+ 'rpc-node',
387
392
  'validator-ha-db',
388
393
  ];
389
394
 
@@ -0,0 +1,99 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+
3
+ import { exec } from 'child_process';
4
+ import { promisify } from 'util';
5
+
6
+ import { getSequencers } from './nodes.js';
7
+
8
+ const execAsync = promisify(exec);
9
+
10
+ /** Parsed l2-block-built stats from a sequencer pod log line. */
11
+ export type BlockBuiltLogEntry = {
12
+ blockNumber: number;
13
+ txCount: number;
14
+ duration: number;
15
+ publicProcessDuration: number;
16
+ manaPerSec: number;
17
+ privateLogCount: number;
18
+ publicLogCount: number;
19
+ contractClassLogCount: number;
20
+ contractClassLogSize: number;
21
+ };
22
+
23
+ const FIELDS: (keyof BlockBuiltLogEntry)[] = [
24
+ 'blockNumber',
25
+ 'txCount',
26
+ 'duration',
27
+ 'publicProcessDuration',
28
+ 'manaPerSec',
29
+ 'privateLogCount',
30
+ 'publicLogCount',
31
+ 'contractClassLogCount',
32
+ 'contractClassLogSize',
33
+ ];
34
+
35
+ /**
36
+ * Fetches l2-block-built log entries from sequencer pods for given block numbers.
37
+ * Queries all validator pods (only the proposer will have the log for a given block).
38
+ *
39
+ * @param namespace - Kubernetes namespace
40
+ * @param sinceTime - ISO 8601 timestamp to limit log search (e.g., from before block building was re-enabled)
41
+ * @param blockNumbers - Set of block numbers to filter for
42
+ * @param logger - Logger instance
43
+ * @returns Array of parsed BlockBuiltLogEntry, de-duplicated by blockNumber, sorted ascending
44
+ */
45
+ export async function fetchBlockBuiltLogs(
46
+ namespace: string,
47
+ sinceTime: string,
48
+ blockNumbers: Set<number>,
49
+ logger: Logger,
50
+ ): Promise<BlockBuiltLogEntry[]> {
51
+ const pods = await getSequencers(namespace);
52
+ const entriesByBlock = new Map<number, BlockBuiltLogEntry>();
53
+
54
+ // Subtract 60s from sinceTime to account for clock skew between test runner and k8s pods.
55
+ // Block number filtering ensures we only match the right blocks, so extra lines are harmless.
56
+ const sinceDate = new Date(new Date(sinceTime).getTime() - 60_000);
57
+ const sinceFlag = sinceDate.toISOString();
58
+
59
+ for (const pod of pods) {
60
+ try {
61
+ const cmd = `kubectl logs ${pod} -n ${namespace} -c aztec --since-time=${sinceFlag}`;
62
+ logger.info(`Fetching logs: ${cmd}`);
63
+ const { stdout } = await execAsync(cmd, { maxBuffer: 10 * 1024 * 1024 });
64
+
65
+ const lines = stdout.split('\n');
66
+ const matchingLines = lines.filter(l => l.includes('l2-block-built'));
67
+ logger.info(`Pod ${pod}: ${lines.length} log lines, ${matchingLines.length} contain l2-block-built`);
68
+
69
+ for (const line of matchingLines) {
70
+ try {
71
+ const parsed = JSON.parse(line);
72
+ if (parsed.eventName !== 'l2-block-built' || !blockNumbers.has(parsed.blockNumber)) {
73
+ continue;
74
+ }
75
+ if (entriesByBlock.has(parsed.blockNumber)) {
76
+ continue;
77
+ }
78
+ const entry: BlockBuiltLogEntry = {} as BlockBuiltLogEntry;
79
+ for (const field of FIELDS) {
80
+ entry[field] = parsed[field] ?? 0;
81
+ }
82
+ entriesByBlock.set(entry.blockNumber, entry);
83
+ logger.verbose(`Parsed l2-block-built log for block ${entry.blockNumber}`, entry);
84
+ } catch {
85
+ // Not valid JSON, skip
86
+ }
87
+ }
88
+ } catch (err) {
89
+ logger.warn(`Failed to fetch logs from pod ${pod}: ${err}`);
90
+ }
91
+ }
92
+
93
+ if (entriesByBlock.size < blockNumbers.size) {
94
+ const missing = [...blockNumbers].filter(bn => !entriesByBlock.has(bn));
95
+ logger.warn(`Missing l2-block-built logs for block(s): ${missing.join(', ')}`);
96
+ }
97
+
98
+ return [...entriesByBlock.values()].sort((a, b) => a.blockNumber - b.blockNumber);
99
+ }
@@ -3,24 +3,47 @@ import type { Logger } from '@aztec/foundation/log';
3
3
  import { execSync, spawn } from 'child_process';
4
4
  import path from 'path';
5
5
 
6
+ /** Result from running a script */
7
+ export type ScriptResult = {
8
+ exitCode: number;
9
+ stdout: string;
10
+ stderr: string;
11
+ };
12
+
6
13
  /**
7
14
  * @param scriptPath - The path to the script, relative to the project root
8
15
  * @param args - The arguments to pass to the script
9
16
  * @param logger - The logger to use
10
- * @returns The exit code of the script
17
+ * @returns The exit code, stdout, and stderr of the script
11
18
  */
12
- function runScript(scriptPath: string, args: string[], logger: Logger, env?: Record<string, string>) {
19
+ function runScript(
20
+ scriptPath: string,
21
+ args: string[],
22
+ logger: Logger,
23
+ env?: Record<string, string>,
24
+ ): Promise<ScriptResult> {
13
25
  const childProcess = spawn(scriptPath, args, {
14
26
  stdio: ['ignore', 'pipe', 'pipe'],
15
27
  env: env ? { ...process.env, ...env } : process.env,
16
28
  });
17
- return new Promise<number>((resolve, reject) => {
18
- childProcess.on('close', (code: number | null) => resolve(code ?? 0));
29
+ const stdoutChunks: Buffer[] = [];
30
+ const stderrChunks: Buffer[] = [];
31
+
32
+ return new Promise<ScriptResult>((resolve, reject) => {
33
+ childProcess.on('close', (code: number | null) =>
34
+ resolve({
35
+ exitCode: code ?? 0,
36
+ stdout: Buffer.concat(stdoutChunks).toString(),
37
+ stderr: Buffer.concat(stderrChunks).toString(),
38
+ }),
39
+ );
19
40
  childProcess.on('error', reject);
20
41
  childProcess.stdout?.on('data', (data: Buffer) => {
42
+ stdoutChunks.push(data);
21
43
  logger.info(data.toString());
22
44
  });
23
45
  childProcess.stderr?.on('data', (data: Buffer) => {
46
+ stderrChunks.push(data);
24
47
  logger.error(data.toString());
25
48
  });
26
49
  });
@@ -51,13 +74,26 @@ export function getAztecBin() {
51
74
  * @param args - The arguments to pass to the Aztec binary
52
75
  * @param logger - The logger to use
53
76
  * @param env - Optional environment variables to set for the process
54
- * @returns The exit code of the Aztec binary
77
+ * @returns The exit code, stdout, and stderr of the Aztec binary
55
78
  */
56
- export function runAztecBin(args: string[], logger: Logger, env?: Record<string, string>) {
79
+ export function runAztecBin(args: string[], logger: Logger, env?: Record<string, string>): Promise<ScriptResult> {
57
80
  return runScript('node', [getAztecBin(), ...args], logger, env);
58
81
  }
59
82
 
60
- export function runProjectScript(script: string, args: string[], logger: Logger, env?: Record<string, string>) {
83
+ /**
84
+ * Runs a script from the project root
85
+ * @param script - The path to the script, relative to the project root
86
+ * @param args - The arguments to pass to the script
87
+ * @param logger - The logger to use
88
+ * @param env - Optional environment variables to set for the process
89
+ * @returns The exit code, stdout, and stderr of the script
90
+ */
91
+ export function runProjectScript(
92
+ script: string,
93
+ args: string[],
94
+ logger: Logger,
95
+ env?: Record<string, string>,
96
+ ): Promise<ScriptResult> {
61
97
  const scriptPath = script.startsWith('/') ? script : path.join(getGitProjectRoot(), script);
62
98
  return runScript(scriptPath, args, logger, env);
63
99
  }