@aztec/end-to-end 0.0.0-test.0 → 0.0.1-commit.001888fc

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 (293) hide show
  1. package/dest/bench/client_flows/benchmark.d.ts +62 -0
  2. package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
  3. package/dest/bench/client_flows/benchmark.js +281 -0
  4. package/dest/bench/client_flows/client_flows_benchmark.d.ts +79 -0
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
  6. package/dest/bench/client_flows/client_flows_benchmark.js +329 -0
  7. package/dest/bench/client_flows/config.d.ts +14 -0
  8. package/dest/bench/client_flows/config.d.ts.map +1 -0
  9. package/dest/bench/client_flows/config.js +124 -0
  10. package/dest/bench/client_flows/data_extractor.d.ts +2 -0
  11. package/dest/bench/client_flows/data_extractor.d.ts.map +1 -0
  12. package/dest/bench/client_flows/data_extractor.js +79 -0
  13. package/dest/bench/utils.d.ts +16 -41
  14. package/dest/bench/utils.d.ts.map +1 -1
  15. package/dest/bench/utils.js +44 -72
  16. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +28 -19
  17. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  18. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +125 -103
  19. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +32 -32
  20. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  21. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +105 -104
  22. package/dest/e2e_deploy_contract/deploy_test.d.ts +19 -10
  23. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  24. package/dest/e2e_deploy_contract/deploy_test.js +26 -27
  25. package/dest/e2e_epochs/epochs_test.d.ts +75 -24
  26. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  27. package/dest/e2e_epochs/epochs_test.js +290 -58
  28. package/dest/e2e_fees/bridging_race.notest.d.ts +2 -0
  29. package/dest/e2e_fees/bridging_race.notest.d.ts.map +1 -0
  30. package/dest/e2e_fees/bridging_race.notest.js +61 -0
  31. package/dest/e2e_fees/fees_test.d.ts +38 -23
  32. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  33. package/dest/e2e_fees/fees_test.js +169 -183
  34. package/dest/e2e_l1_publisher/write_json.d.ts +11 -0
  35. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
  36. package/dest/e2e_l1_publisher/write_json.js +56 -0
  37. package/dest/e2e_multi_validator/utils.d.ts +12 -0
  38. package/dest/e2e_multi_validator/utils.d.ts.map +1 -0
  39. package/dest/e2e_multi_validator/utils.js +214 -0
  40. package/dest/e2e_nested_contract/nested_contract_test.d.ts +15 -15
  41. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  42. package/dest/e2e_nested_contract/nested_contract_test.js +36 -42
  43. package/dest/e2e_p2p/inactivity_slash_test.d.ts +31 -0
  44. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -0
  45. package/dest/e2e_p2p/inactivity_slash_test.js +136 -0
  46. package/dest/e2e_p2p/p2p_network.d.ts +282 -27
  47. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  48. package/dest/e2e_p2p/p2p_network.js +255 -176
  49. package/dest/e2e_p2p/reqresp/utils.d.ts +22 -0
  50. package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -0
  51. package/dest/e2e_p2p/reqresp/utils.js +190 -0
  52. package/dest/e2e_p2p/shared.d.ts +64 -8
  53. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  54. package/dest/e2e_p2p/shared.js +200 -27
  55. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +2 -0
  56. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +1 -0
  57. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.js +184 -0
  58. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts +18 -0
  59. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +1 -0
  60. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.js +120 -0
  61. package/dest/e2e_token_contract/token_contract_test.d.ts +29 -14
  62. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  63. package/dest/e2e_token_contract/token_contract_test.js +107 -75
  64. package/dest/fixtures/authwit_proxy.d.ts +15 -0
  65. package/dest/fixtures/authwit_proxy.d.ts.map +1 -0
  66. package/dest/fixtures/authwit_proxy.js +30 -0
  67. package/dest/fixtures/e2e_prover_test.d.ts +55 -0
  68. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
  69. package/dest/fixtures/e2e_prover_test.js +271 -0
  70. package/dest/fixtures/elu_monitor.d.ts +21 -0
  71. package/dest/fixtures/elu_monitor.d.ts.map +1 -0
  72. package/dest/fixtures/elu_monitor.js +102 -0
  73. package/dest/fixtures/fixtures.d.ts +10 -8
  74. package/dest/fixtures/fixtures.d.ts.map +1 -1
  75. package/dest/fixtures/fixtures.js +11 -5
  76. package/dest/fixtures/get_acvm_config.d.ts +2 -2
  77. package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
  78. package/dest/fixtures/get_acvm_config.js +3 -15
  79. package/dest/fixtures/get_bb_config.d.ts +2 -2
  80. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  81. package/dest/fixtures/get_bb_config.js +10 -17
  82. package/dest/fixtures/ha_setup.d.ts +71 -0
  83. package/dest/fixtures/ha_setup.d.ts.map +1 -0
  84. package/dest/fixtures/ha_setup.js +116 -0
  85. package/dest/fixtures/index.d.ts +2 -1
  86. package/dest/fixtures/index.d.ts.map +1 -1
  87. package/dest/fixtures/index.js +1 -0
  88. package/dest/fixtures/l1_to_l2_messaging.d.ts +11 -7
  89. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  90. package/dest/fixtures/l1_to_l2_messaging.js +45 -19
  91. package/dest/fixtures/logging.d.ts +1 -1
  92. package/dest/fixtures/setup.d.ts +239 -0
  93. package/dest/fixtures/setup.d.ts.map +1 -0
  94. package/dest/fixtures/setup.js +606 -0
  95. package/dest/fixtures/setup_p2p_test.d.ts +23 -15
  96. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  97. package/dest/fixtures/setup_p2p_test.js +102 -31
  98. package/dest/fixtures/token_utils.d.ts +10 -4
  99. package/dest/fixtures/token_utils.d.ts.map +1 -1
  100. package/dest/fixtures/token_utils.js +33 -13
  101. package/dest/fixtures/utils.d.ts +5 -153
  102. package/dest/fixtures/utils.d.ts.map +1 -1
  103. package/dest/fixtures/utils.js +4 -552
  104. package/dest/fixtures/web3signer.d.ts +5 -0
  105. package/dest/fixtures/web3signer.d.ts.map +1 -0
  106. package/dest/fixtures/web3signer.js +53 -0
  107. package/dest/fixtures/with_telemetry_utils.d.ts +2 -2
  108. package/dest/fixtures/with_telemetry_utils.d.ts.map +1 -1
  109. package/dest/fixtures/with_telemetry_utils.js +2 -2
  110. package/dest/index.d.ts +1 -1
  111. package/dest/quality_of_service/grafana_client.d.ts +41 -0
  112. package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
  113. package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
  114. package/dest/quality_of_service/prometheus_client.d.ts +38 -0
  115. package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
  116. package/dest/quality_of_service/prometheus_client.js +67 -0
  117. package/dest/shared/cross_chain_test_harness.d.ts +44 -27
  118. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  119. package/dest/shared/cross_chain_test_harness.js +107 -53
  120. package/dest/shared/gas_portal_test_harness.d.ts +33 -25
  121. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  122. package/dest/shared/gas_portal_test_harness.js +51 -30
  123. package/dest/shared/index.d.ts +3 -2
  124. package/dest/shared/index.d.ts.map +1 -1
  125. package/dest/shared/index.js +1 -0
  126. package/dest/shared/jest_setup.d.ts +1 -1
  127. package/dest/shared/jest_setup.js +42 -2
  128. package/dest/shared/mock_state_view.d.ts +86 -0
  129. package/dest/shared/mock_state_view.d.ts.map +1 -0
  130. package/dest/shared/mock_state_view.js +186 -0
  131. package/dest/shared/submit-transactions.d.ts +6 -4
  132. package/dest/shared/submit-transactions.d.ts.map +1 -1
  133. package/dest/shared/submit-transactions.js +15 -16
  134. package/dest/shared/uniswap_l1_l2.d.ts +3 -25
  135. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  136. package/dest/shared/uniswap_l1_l2.js +175 -126
  137. package/dest/simulators/index.d.ts +1 -1
  138. package/dest/simulators/lending_simulator.d.ts +7 -7
  139. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  140. package/dest/simulators/lending_simulator.js +17 -18
  141. package/dest/simulators/token_simulator.d.ts +6 -3
  142. package/dest/simulators/token_simulator.d.ts.map +1 -1
  143. package/dest/simulators/token_simulator.js +12 -30
  144. package/dest/spartan/setup_test_wallets.d.ts +36 -11
  145. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  146. package/dest/spartan/setup_test_wallets.js +276 -62
  147. package/dest/spartan/tx_metrics.d.ts +88 -0
  148. package/dest/spartan/tx_metrics.d.ts.map +1 -0
  149. package/dest/spartan/tx_metrics.js +422 -0
  150. package/dest/spartan/utils/bot.d.ts +28 -0
  151. package/dest/spartan/utils/bot.d.ts.map +1 -0
  152. package/dest/spartan/utils/bot.js +142 -0
  153. package/dest/spartan/utils/chaos.d.ts +79 -0
  154. package/dest/spartan/utils/chaos.d.ts.map +1 -0
  155. package/dest/spartan/utils/chaos.js +142 -0
  156. package/dest/spartan/utils/clients.d.ts +39 -0
  157. package/dest/spartan/utils/clients.d.ts.map +1 -0
  158. package/dest/spartan/utils/clients.js +90 -0
  159. package/dest/spartan/utils/config.d.ts +45 -0
  160. package/dest/spartan/utils/config.d.ts.map +1 -0
  161. package/dest/spartan/utils/config.js +23 -0
  162. package/dest/spartan/utils/health.d.ts +63 -0
  163. package/dest/spartan/utils/health.d.ts.map +1 -0
  164. package/dest/spartan/utils/health.js +202 -0
  165. package/dest/spartan/utils/helm.d.ts +15 -0
  166. package/dest/spartan/utils/helm.d.ts.map +1 -0
  167. package/dest/spartan/utils/helm.js +47 -0
  168. package/dest/spartan/utils/index.d.ts +11 -0
  169. package/dest/spartan/utils/index.d.ts.map +1 -0
  170. package/dest/spartan/utils/index.js +22 -0
  171. package/dest/spartan/utils/k8s.d.ts +128 -0
  172. package/dest/spartan/utils/k8s.d.ts.map +1 -0
  173. package/dest/spartan/utils/k8s.js +381 -0
  174. package/dest/spartan/utils/nodes.d.ts +40 -0
  175. package/dest/spartan/utils/nodes.d.ts.map +1 -0
  176. package/dest/spartan/utils/nodes.js +461 -0
  177. package/dest/spartan/utils/pod_logs.d.ts +25 -0
  178. package/dest/spartan/utils/pod_logs.d.ts.map +1 -0
  179. package/dest/spartan/utils/pod_logs.js +74 -0
  180. package/dest/spartan/utils/scripts.d.ts +30 -0
  181. package/dest/spartan/utils/scripts.d.ts.map +1 -0
  182. package/dest/spartan/utils/scripts.js +81 -0
  183. package/dest/spartan/utils.d.ts +2 -415
  184. package/dest/spartan/utils.d.ts.map +1 -1
  185. package/dest/spartan/utils.js +1 -445
  186. package/dest/test-wallet/test_wallet.d.ts +83 -0
  187. package/dest/test-wallet/test_wallet.d.ts.map +1 -0
  188. package/dest/test-wallet/test_wallet.js +214 -0
  189. package/dest/test-wallet/utils.d.ts +41 -0
  190. package/dest/test-wallet/utils.d.ts.map +1 -0
  191. package/dest/test-wallet/utils.js +71 -0
  192. package/dest/test-wallet/wallet_worker_script.d.ts +2 -0
  193. package/dest/test-wallet/wallet_worker_script.d.ts.map +1 -0
  194. package/dest/test-wallet/wallet_worker_script.js +48 -0
  195. package/dest/test-wallet/worker_wallet.d.ts +52 -0
  196. package/dest/test-wallet/worker_wallet.d.ts.map +1 -0
  197. package/dest/test-wallet/worker_wallet.js +151 -0
  198. package/dest/test-wallet/worker_wallet_schema.d.ts +274 -0
  199. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -0
  200. package/dest/test-wallet/worker_wallet_schema.js +10 -0
  201. package/package.json +72 -62
  202. package/src/bench/client_flows/benchmark.ts +363 -0
  203. package/src/bench/client_flows/client_flows_benchmark.ts +388 -0
  204. package/src/bench/client_flows/config.ts +69 -0
  205. package/src/bench/client_flows/data_extractor.ts +89 -0
  206. package/src/bench/utils.ts +47 -86
  207. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +149 -171
  208. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +155 -182
  209. package/src/e2e_deploy_contract/deploy_test.ts +40 -48
  210. package/src/e2e_epochs/epochs_test.ts +364 -93
  211. package/src/e2e_fees/bridging_race.notest.ts +74 -0
  212. package/src/e2e_fees/fees_test.ts +213 -259
  213. package/src/e2e_l1_publisher/write_json.ts +77 -0
  214. package/src/e2e_multi_validator/utils.ts +258 -0
  215. package/src/e2e_nested_contract/nested_contract_test.ts +48 -59
  216. package/src/e2e_p2p/inactivity_slash_test.ts +179 -0
  217. package/src/e2e_p2p/p2p_network.ts +367 -234
  218. package/src/e2e_p2p/reqresp/utils.ts +256 -0
  219. package/src/e2e_p2p/shared.ts +315 -39
  220. package/src/e2e_storage_proof/fixtures/storage_proof.json +915 -0
  221. package/src/e2e_storage_proof/fixtures/storage_proof_fetcher.ts +190 -0
  222. package/src/e2e_storage_proof/fixtures/storage_proof_fixture.ts +173 -0
  223. package/src/e2e_token_contract/token_contract_test.ts +132 -126
  224. package/src/fixtures/authwit_proxy.ts +50 -0
  225. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  226. package/src/fixtures/e2e_prover_test.ts +332 -0
  227. package/src/fixtures/elu_monitor.ts +126 -0
  228. package/src/fixtures/fixtures.ts +15 -7
  229. package/src/fixtures/get_acvm_config.ts +4 -12
  230. package/src/fixtures/get_bb_config.ts +18 -13
  231. package/src/fixtures/ha_setup.ts +186 -0
  232. package/src/fixtures/index.ts +1 -0
  233. package/src/fixtures/l1_to_l2_messaging.ts +56 -24
  234. package/src/fixtures/setup.ts +903 -0
  235. package/src/fixtures/setup_p2p_test.ts +134 -50
  236. package/src/fixtures/token_utils.ts +37 -16
  237. package/src/fixtures/utils.ts +27 -820
  238. package/src/fixtures/web3signer.ts +63 -0
  239. package/src/fixtures/with_telemetry_utils.ts +2 -2
  240. package/src/guides/up_quick_start.sh +9 -17
  241. package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +2 -2
  242. package/src/quality_of_service/prometheus_client.ts +113 -0
  243. package/src/shared/cross_chain_test_harness.ts +110 -94
  244. package/src/shared/gas_portal_test_harness.ts +59 -50
  245. package/src/shared/index.ts +2 -1
  246. package/src/shared/jest_setup.ts +52 -2
  247. package/src/shared/mock_state_view.ts +188 -0
  248. package/src/shared/submit-transactions.ts +19 -20
  249. package/src/shared/uniswap_l1_l2.ts +207 -226
  250. package/src/simulators/lending_simulator.ts +18 -17
  251. package/src/simulators/token_simulator.ts +18 -34
  252. package/src/spartan/DEVELOP.md +128 -0
  253. package/src/spartan/setup_test_wallets.ts +393 -95
  254. package/src/spartan/tx_metrics.ts +376 -0
  255. package/src/spartan/utils/bot.ts +188 -0
  256. package/src/spartan/utils/chaos.ts +253 -0
  257. package/src/spartan/utils/clients.ts +100 -0
  258. package/src/spartan/utils/config.ts +29 -0
  259. package/src/spartan/utils/health.ts +255 -0
  260. package/src/spartan/utils/helm.ts +84 -0
  261. package/src/spartan/utils/index.ts +71 -0
  262. package/src/spartan/utils/k8s.ts +535 -0
  263. package/src/spartan/utils/nodes.ts +543 -0
  264. package/src/spartan/utils/pod_logs.ts +99 -0
  265. package/src/spartan/utils/scripts.ts +99 -0
  266. package/src/spartan/utils.ts +1 -582
  267. package/src/test-wallet/test_wallet.ts +306 -0
  268. package/src/test-wallet/utils.ts +112 -0
  269. package/src/test-wallet/wallet_worker_script.ts +60 -0
  270. package/src/test-wallet/worker_wallet.ts +213 -0
  271. package/src/test-wallet/worker_wallet_schema.ts +13 -0
  272. package/dest/e2e_prover/e2e_prover_test.d.ts +0 -56
  273. package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
  274. package/dest/e2e_prover/e2e_prover_test.js +0 -291
  275. package/dest/fixtures/setup_l1_contracts.d.ts +0 -6
  276. package/dest/fixtures/setup_l1_contracts.d.ts.map +0 -1
  277. package/dest/fixtures/setup_l1_contracts.js +0 -17
  278. package/dest/fixtures/snapshot_manager.d.ts +0 -87
  279. package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
  280. package/dest/fixtures/snapshot_manager.js +0 -479
  281. package/dest/quality_of_service/alert_checker.d.ts +0 -41
  282. package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
  283. package/dest/sample-dapp/connect.js +0 -12
  284. package/dest/sample-dapp/contracts.js +0 -10
  285. package/dest/sample-dapp/deploy.js +0 -35
  286. package/dest/sample-dapp/index.js +0 -98
  287. package/src/e2e_prover/e2e_prover_test.ts +0 -418
  288. package/src/fixtures/setup_l1_contracts.ts +0 -27
  289. package/src/fixtures/snapshot_manager.ts +0 -617
  290. package/src/sample-dapp/connect.mjs +0 -16
  291. package/src/sample-dapp/contracts.mjs +0 -14
  292. package/src/sample-dapp/deploy.mjs +0 -40
  293. package/src/sample-dapp/index.mjs +0 -128
@@ -0,0 +1,99 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+
3
+ import { execSync, spawn } from 'child_process';
4
+ import path from 'path';
5
+
6
+ /** Result from running a script */
7
+ export type ScriptResult = {
8
+ exitCode: number;
9
+ stdout: string;
10
+ stderr: string;
11
+ };
12
+
13
+ /**
14
+ * @param scriptPath - The path to the script, relative to the project root
15
+ * @param args - The arguments to pass to the script
16
+ * @param logger - The logger to use
17
+ * @returns The exit code, stdout, and stderr of the script
18
+ */
19
+ function runScript(
20
+ scriptPath: string,
21
+ args: string[],
22
+ logger: Logger,
23
+ env?: Record<string, string>,
24
+ ): Promise<ScriptResult> {
25
+ const childProcess = spawn(scriptPath, args, {
26
+ stdio: ['ignore', 'pipe', 'pipe'],
27
+ env: env ? { ...process.env, ...env } : process.env,
28
+ });
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
+ );
40
+ childProcess.on('error', reject);
41
+ childProcess.stdout?.on('data', (data: Buffer) => {
42
+ stdoutChunks.push(data);
43
+ logger.info(data.toString());
44
+ });
45
+ childProcess.stderr?.on('data', (data: Buffer) => {
46
+ stderrChunks.push(data);
47
+ logger.error(data.toString());
48
+ });
49
+ });
50
+ }
51
+
52
+ /**
53
+ * Returns the absolute path to the git repository root
54
+ */
55
+ export function getGitProjectRoot(): string {
56
+ try {
57
+ const rootDir = execSync('git rev-parse --show-toplevel', {
58
+ encoding: 'utf-8',
59
+ stdio: ['ignore', 'pipe', 'ignore'],
60
+ }).trim();
61
+
62
+ return rootDir;
63
+ } catch (error) {
64
+ throw new Error(`Failed to determine git project root: ${error}`);
65
+ }
66
+ }
67
+
68
+ export function getAztecBin() {
69
+ return path.join(getGitProjectRoot(), 'yarn-project/aztec/dest/bin/index.js');
70
+ }
71
+
72
+ /**
73
+ * Runs the Aztec binary
74
+ * @param args - The arguments to pass to the Aztec binary
75
+ * @param logger - The logger to use
76
+ * @param env - Optional environment variables to set for the process
77
+ * @returns The exit code, stdout, and stderr of the Aztec binary
78
+ */
79
+ export function runAztecBin(args: string[], logger: Logger, env?: Record<string, string>): Promise<ScriptResult> {
80
+ return runScript('node', [getAztecBin(), ...args], logger, env);
81
+ }
82
+
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> {
97
+ const scriptPath = script.startsWith('/') ? script : path.join(getGitProjectRoot(), script);
98
+ return runScript(scriptPath, args, logger, env);
99
+ }
@@ -1,582 +1 @@
1
- import { createAztecNodeClient, createLogger, sleep } from '@aztec/aztec.js';
2
- import type { RollupCheatCodes } from '@aztec/aztec.js/ethereum';
3
- import type { Logger } from '@aztec/foundation/log';
4
- import type { SequencerConfig } from '@aztec/sequencer-client';
5
-
6
- import { ChildProcess, exec, execSync, spawn } from 'child_process';
7
- import path from 'path';
8
- import { promisify } from 'util';
9
- import { z } from 'zod';
10
-
11
- import { AlertChecker, type AlertConfig } from '../quality_of_service/alert_checker.js';
12
-
13
- const execAsync = promisify(exec);
14
-
15
- const logger = createLogger('e2e:k8s-utils');
16
-
17
- const ethereumHostsSchema = z.string().refine(
18
- str =>
19
- str.split(',').every(url => {
20
- try {
21
- new URL(url.trim());
22
- return true;
23
- } catch {
24
- return false;
25
- }
26
- }),
27
- 'ETHEREUM_HOSTS must be a comma-separated list of valid URLs',
28
- );
29
-
30
- const k8sLocalConfigSchema = z.object({
31
- ETHEREUM_SLOT_DURATION: z.coerce.number().min(1, 'ETHEREUM_SLOT_DURATION env variable must be set'),
32
- AZTEC_SLOT_DURATION: z.coerce.number().min(1, 'AZTEC_SLOT_DURATION env variable must be set'),
33
- AZTEC_EPOCH_DURATION: z.coerce.number().min(1, 'AZTEC_EPOCH_DURATION env variable must be set'),
34
- AZTEC_PROOF_SUBMISSION_WINDOW: z.coerce.number().min(1, 'AZTEC_PROOF_SUBMISSION_WINDOW env variable must be set'),
35
- INSTANCE_NAME: z.string().min(1, 'INSTANCE_NAME env variable must be set'),
36
- NAMESPACE: z.string().min(1, 'NAMESPACE env variable must be set'),
37
- CONTAINER_NODE_PORT: z.coerce.number().default(8080),
38
- CONTAINER_SEQUENCER_PORT: z.coerce.number().default(8080),
39
- CONTAINER_PROVER_NODE_PORT: z.coerce.number().default(8080),
40
- CONTAINER_PXE_PORT: z.coerce.number().default(8080),
41
- CONTAINER_ETHEREUM_PORT: z.coerce.number().default(8545),
42
- CONTAINER_METRICS_PORT: z.coerce.number().default(80),
43
- GRAFANA_PASSWORD: z.string().optional(),
44
- METRICS_API_PATH: z.string().default('/api/datasources/proxy/uid/spartan-metrics-prometheus/api/v1'),
45
- SPARTAN_DIR: z.string().min(1, 'SPARTAN_DIR env variable must be set'),
46
- ETHEREUM_HOSTS: ethereumHostsSchema.optional(),
47
- L1_ACCOUNT_MNEMONIC: z.string().default('test test test test test test test test test test test junk'),
48
- SEPOLIA_RUN: z.string().default('false'),
49
- K8S: z.literal('local'),
50
- });
51
-
52
- const k8sGCloudConfigSchema = k8sLocalConfigSchema.extend({
53
- K8S: z.literal('gcloud'),
54
- CLUSTER_NAME: z.string().min(1, 'CLUSTER_NAME env variable must be set'),
55
- REGION: z.string().min(1, 'REGION env variable must be set'),
56
- });
57
-
58
- const directConfigSchema = z.object({
59
- PXE_URL: z.string().url('PXE_URL must be a valid URL'),
60
- NODE_URL: z.string().url('NODE_URL must be a valid URL'),
61
- ETHEREUM_HOSTS: ethereumHostsSchema,
62
- K8S: z.literal('false'),
63
- });
64
-
65
- const envSchema = z.discriminatedUnion('K8S', [k8sLocalConfigSchema, k8sGCloudConfigSchema, directConfigSchema]);
66
-
67
- export type K8sLocalConfig = z.infer<typeof k8sLocalConfigSchema>;
68
- export type K8sGCloudConfig = z.infer<typeof k8sGCloudConfigSchema>;
69
- export type DirectConfig = z.infer<typeof directConfigSchema>;
70
- export type EnvConfig = z.infer<typeof envSchema>;
71
-
72
- export function isK8sConfig(config: EnvConfig): config is K8sLocalConfig | K8sGCloudConfig {
73
- return config.K8S === 'local' || config.K8S === 'gcloud';
74
- }
75
-
76
- export function isGCloudConfig(config: EnvConfig): config is K8sGCloudConfig {
77
- return config.K8S === 'gcloud';
78
- }
79
-
80
- export function setupEnvironment(env: unknown): EnvConfig {
81
- const config = envSchema.parse(env);
82
- if (isGCloudConfig(config)) {
83
- const command = `gcloud container clusters get-credentials ${config.CLUSTER_NAME} --region=${config.REGION}`;
84
- execSync(command);
85
- }
86
- return config;
87
- }
88
-
89
- export async function startPortForward({
90
- resource,
91
- namespace,
92
- containerPort,
93
- hostPort,
94
- }: {
95
- resource: string;
96
- namespace: string;
97
- containerPort: number;
98
- // If not provided, the port will be chosen automatically
99
- hostPort?: number;
100
- }): Promise<{
101
- process: ChildProcess;
102
- port: number;
103
- }> {
104
- const hostPortAsString = hostPort ? hostPort.toString() : '';
105
-
106
- logger.info(`kubectl port-forward -n ${namespace} ${resource} ${hostPortAsString}:${containerPort}`);
107
-
108
- const process = spawn(
109
- 'kubectl',
110
- ['port-forward', '-n', namespace, resource, `${hostPortAsString}:${containerPort}`],
111
- {
112
- detached: true,
113
- windowsHide: true,
114
- stdio: ['ignore', 'pipe', 'pipe'],
115
- },
116
- );
117
-
118
- let isResolved = false;
119
- const connected = new Promise<number>(resolve => {
120
- process.stdout?.on('data', data => {
121
- const str = data.toString() as string;
122
- if (!isResolved && str.includes('Forwarding from')) {
123
- isResolved = true;
124
- logger.info(str);
125
- const port = str.search(/:\d+/);
126
- if (port === -1) {
127
- throw new Error('Port not found in port forward output');
128
- }
129
- const portNumber = parseInt(str.slice(port + 1));
130
- logger.info(`Port forward connected: ${portNumber}`);
131
- logger.info(`Port forward connected: ${portNumber}`);
132
- resolve(portNumber);
133
- } else {
134
- logger.silent(str);
135
- }
136
- });
137
- process.stderr?.on('data', data => {
138
- logger.info(data.toString());
139
- // It's a strange thing:
140
- // If we don't pipe stderr, then the port forwarding does not work.
141
- // Log to silent because this doesn't actually report errors,
142
- // just extremely verbose debug logs.
143
- logger.silent(data.toString());
144
- });
145
- process.on('close', () => {
146
- if (!isResolved) {
147
- isResolved = true;
148
- logger.warn('Port forward closed before connection established');
149
- resolve(0);
150
- }
151
- });
152
- process.on('error', error => {
153
- logger.error(`Port forward error: ${error}`);
154
- resolve(0);
155
- });
156
- process.on('exit', code => {
157
- logger.info(`Port forward exited with code ${code}`);
158
- resolve(0);
159
- });
160
- });
161
-
162
- const port = await connected;
163
-
164
- return { process, port };
165
- }
166
-
167
- export async function deleteResourceByName({
168
- resource,
169
- namespace,
170
- name,
171
- force = false,
172
- }: {
173
- resource: string;
174
- namespace: string;
175
- name: string;
176
- force?: boolean;
177
- }) {
178
- const command = `kubectl delete ${resource} ${name} -n ${namespace} --ignore-not-found=true --wait=true ${
179
- force ? '--force' : ''
180
- }`;
181
- logger.info(`command: ${command}`);
182
- const { stdout } = await execAsync(command);
183
- return stdout;
184
- }
185
-
186
- export async function deleteResourceByLabel({
187
- resource,
188
- namespace,
189
- label,
190
- }: {
191
- resource: string;
192
- namespace: string;
193
- label: string;
194
- }) {
195
- const command = `kubectl delete ${resource} -l ${label} -n ${namespace} --ignore-not-found=true --wait=true`;
196
- logger.info(`command: ${command}`);
197
- const { stdout } = await execAsync(command);
198
- return stdout;
199
- }
200
-
201
- export async function waitForResourceByLabel({
202
- resource,
203
- label,
204
- namespace,
205
- condition = 'Ready',
206
- timeout = '10m',
207
- }: {
208
- resource: string;
209
- label: string;
210
- namespace: string;
211
- condition?: string;
212
- timeout?: string;
213
- }) {
214
- const command = `kubectl wait ${resource} -l ${label} --for=condition=${condition} -n ${namespace} --timeout=${timeout}`;
215
- logger.info(`command: ${command}`);
216
- const { stdout } = await execAsync(command);
217
- return stdout;
218
- }
219
-
220
- export function getChartDir(spartanDir: string, chartName: string) {
221
- return path.join(spartanDir.trim(), chartName);
222
- }
223
-
224
- function valuesToArgs(values: Record<string, string | number>) {
225
- return Object.entries(values)
226
- .map(([key, value]) => `--set ${key}=${value}`)
227
- .join(' ');
228
- }
229
-
230
- function createHelmCommand({
231
- instanceName,
232
- helmChartDir,
233
- namespace,
234
- valuesFile,
235
- timeout,
236
- values,
237
- reuseValues = false,
238
- }: {
239
- instanceName: string;
240
- helmChartDir: string;
241
- namespace: string;
242
- valuesFile: string | undefined;
243
- timeout: string;
244
- values: Record<string, string | number>;
245
- reuseValues?: boolean;
246
- }) {
247
- const valuesFileArgs = valuesFile ? `--values ${helmChartDir}/values/${valuesFile}` : '';
248
- const reuseValuesArgs = reuseValues ? '--reuse-values' : '';
249
- return `helm upgrade --install ${instanceName} ${helmChartDir} --namespace ${namespace} ${valuesFileArgs} ${reuseValuesArgs} --wait --timeout=${timeout} ${valuesToArgs(
250
- values,
251
- )}`;
252
- }
253
-
254
- async function execHelmCommand(args: Parameters<typeof createHelmCommand>[0]) {
255
- const helmCommand = createHelmCommand(args);
256
- logger.info(`helm command: ${helmCommand}`);
257
- const { stdout } = await execAsync(helmCommand);
258
- return stdout;
259
- }
260
-
261
- /**
262
- * Installs a Helm chart with the given parameters.
263
- * @param instanceName - The name of the Helm chart instance.
264
- * @param targetNamespace - The namespace with the resources to be affected by the Helm chart.
265
- * @param valuesFile - The values file to use for the Helm chart.
266
- * @param chaosMeshNamespace - The namespace to install the Helm chart in.
267
- * @param timeout - The timeout for the Helm command.
268
- * @param clean - Whether to clean up the Helm chart before installing it.
269
- * @returns The stdout of the Helm command.
270
- * @throws If the Helm command fails.
271
- *
272
- * Example usage:
273
- * ```typescript
274
- * const stdout = await installChaosMeshChart({ instanceName: 'force-reorg', targetNamespace: 'smoke', valuesFile: 'prover-failure.yaml'});
275
- * console.log(stdout);
276
- * ```
277
- */
278
- export async function installChaosMeshChart({
279
- instanceName,
280
- targetNamespace,
281
- valuesFile,
282
- helmChartDir,
283
- chaosMeshNamespace = 'chaos-mesh',
284
- timeout = '5m',
285
- clean = true,
286
- values = {},
287
- logger,
288
- }: {
289
- instanceName: string;
290
- targetNamespace: string;
291
- valuesFile: string;
292
- helmChartDir: string;
293
- chaosMeshNamespace?: string;
294
- timeout?: string;
295
- clean?: boolean;
296
- values?: Record<string, string | number>;
297
- logger: Logger;
298
- }) {
299
- if (clean) {
300
- // uninstall the helm chart if it exists
301
- logger.info(`Uninstalling helm chart ${instanceName}`);
302
- await execAsync(`helm uninstall ${instanceName} --namespace ${chaosMeshNamespace} --wait --ignore-not-found`);
303
- // and delete the podchaos resource
304
- const deleteArgs = {
305
- resource: 'podchaos',
306
- namespace: chaosMeshNamespace,
307
- name: `${targetNamespace}-${instanceName}`,
308
- };
309
- logger.info(`Deleting podchaos resource`);
310
- await deleteResourceByName(deleteArgs).catch(e => {
311
- logger.error(`Error deleting podchaos resource: ${e}`);
312
- logger.info(`Force deleting podchaos resource`);
313
- return deleteResourceByName({ ...deleteArgs, force: true });
314
- });
315
- }
316
-
317
- return execHelmCommand({
318
- instanceName,
319
- helmChartDir,
320
- namespace: chaosMeshNamespace,
321
- valuesFile,
322
- timeout,
323
- values: { ...values, 'global.targetNamespace': targetNamespace },
324
- });
325
- }
326
-
327
- export function applyProverFailure({
328
- namespace,
329
- spartanDir,
330
- durationSeconds,
331
- logger,
332
- }: {
333
- namespace: string;
334
- spartanDir: string;
335
- durationSeconds: number;
336
- logger: Logger;
337
- }) {
338
- return installChaosMeshChart({
339
- instanceName: 'prover-failure',
340
- targetNamespace: namespace,
341
- valuesFile: 'prover-failure.yaml',
342
- helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
343
- values: {
344
- 'proverFailure.duration': `${durationSeconds}s`,
345
- },
346
- logger,
347
- });
348
- }
349
-
350
- export function applyProverKill({
351
- namespace,
352
- spartanDir,
353
- logger,
354
- }: {
355
- namespace: string;
356
- spartanDir: string;
357
- logger: Logger;
358
- }) {
359
- return installChaosMeshChart({
360
- instanceName: 'prover-kill',
361
- targetNamespace: namespace,
362
- valuesFile: 'prover-kill.yaml',
363
- helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
364
- clean: true,
365
- logger,
366
- });
367
- }
368
-
369
- export function applyProverBrokerKill({
370
- namespace,
371
- spartanDir,
372
- logger,
373
- }: {
374
- namespace: string;
375
- spartanDir: string;
376
- logger: Logger;
377
- }) {
378
- return installChaosMeshChart({
379
- instanceName: 'prover-broker-kill',
380
- targetNamespace: namespace,
381
- valuesFile: 'prover-broker-kill.yaml',
382
- helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
383
- clean: true,
384
- logger,
385
- });
386
- }
387
-
388
- export function applyBootNodeFailure({
389
- namespace,
390
- spartanDir,
391
- durationSeconds,
392
- logger,
393
- }: {
394
- namespace: string;
395
- spartanDir: string;
396
- durationSeconds: number;
397
- logger: Logger;
398
- }) {
399
- return installChaosMeshChart({
400
- instanceName: 'boot-node-failure',
401
- targetNamespace: namespace,
402
- valuesFile: 'boot-node-failure.yaml',
403
- helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
404
- values: {
405
- 'bootNodeFailure.duration': `${durationSeconds}s`,
406
- },
407
- logger,
408
- });
409
- }
410
-
411
- export function applyValidatorKill({
412
- namespace,
413
- spartanDir,
414
- logger,
415
- }: {
416
- namespace: string;
417
- spartanDir: string;
418
- logger: Logger;
419
- }) {
420
- return installChaosMeshChart({
421
- instanceName: 'validator-kill',
422
- targetNamespace: namespace,
423
- valuesFile: 'validator-kill.yaml',
424
- helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
425
- logger,
426
- });
427
- }
428
-
429
- export function applyNetworkShaping({
430
- valuesFile,
431
- namespace,
432
- spartanDir,
433
- logger,
434
- }: {
435
- valuesFile: string;
436
- namespace: string;
437
- spartanDir: string;
438
- logger: Logger;
439
- }) {
440
- return installChaosMeshChart({
441
- instanceName: 'network-shaping',
442
- targetNamespace: namespace,
443
- valuesFile,
444
- helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
445
- logger,
446
- });
447
- }
448
-
449
- export async function awaitL2BlockNumber(
450
- rollupCheatCodes: RollupCheatCodes,
451
- blockNumber: bigint,
452
- timeoutSeconds: number,
453
- logger: Logger,
454
- ) {
455
- logger.info(`Waiting for L2 Block ${blockNumber}`);
456
- let tips = await rollupCheatCodes.getTips();
457
- const endTime = Date.now() + timeoutSeconds * 1000;
458
- while (tips.pending < blockNumber && Date.now() < endTime) {
459
- logger.info(`At L2 Block ${tips.pending}`);
460
- await sleep(1000);
461
- tips = await rollupCheatCodes.getTips();
462
- }
463
- if (tips.pending < blockNumber) {
464
- throw new Error(`Timeout waiting for L2 Block ${blockNumber}, only reached ${tips.pending}`);
465
- } else {
466
- logger.info(`Reached L2 Block ${tips.pending}`);
467
- }
468
- }
469
-
470
- export async function restartBot(namespace: string, logger: Logger) {
471
- logger.info(`Restarting bot`);
472
- await deleteResourceByLabel({ resource: 'pods', namespace, label: 'app=bot' });
473
- await sleep(10 * 1000);
474
- await waitForResourceByLabel({ resource: 'pods', namespace, label: 'app=bot' });
475
- logger.info(`Bot restarted`);
476
- }
477
-
478
- export async function enableValidatorDynamicBootNode(
479
- instanceName: string,
480
- namespace: string,
481
- spartanDir: string,
482
- logger: Logger,
483
- ) {
484
- logger.info(`Enabling validator dynamic boot node`);
485
- await execHelmCommand({
486
- instanceName,
487
- namespace,
488
- helmChartDir: getChartDir(spartanDir, 'aztec-network'),
489
- values: {
490
- 'validator.dynamicBootNode': 'true',
491
- },
492
- valuesFile: undefined,
493
- timeout: '15m',
494
- reuseValues: true,
495
- });
496
-
497
- logger.info(`Validator dynamic boot node enabled`);
498
- }
499
-
500
- export async function runAlertCheck(config: EnvConfig, alerts: AlertConfig[], logger: Logger) {
501
- if (isK8sConfig(config)) {
502
- const { process, port } = await startPortForward({
503
- resource: `svc/metrics-grafana`,
504
- namespace: 'metrics',
505
- containerPort: config.CONTAINER_METRICS_PORT,
506
- });
507
- const alertChecker = new AlertChecker(logger, {
508
- grafanaEndpoint: `http://localhost:${port}${config.METRICS_API_PATH}`,
509
- grafanaCredentials: `admin:${config.GRAFANA_PASSWORD}`,
510
- });
511
- await alertChecker.runAlertCheck(alerts);
512
- process.kill();
513
- } else {
514
- logger.info('Not running alert check in non-k8s environment');
515
- }
516
- }
517
-
518
- export async function updateSequencerConfig(url: string, config: Partial<SequencerConfig>) {
519
- const node = createAztecNodeClient(url);
520
- await node.setConfig(config);
521
- }
522
-
523
- export async function getSequencers(namespace: string) {
524
- const command = `kubectl get pods -l app=validator -n ${namespace} -o jsonpath='{.items[*].metadata.name}'`;
525
- const { stdout } = await execAsync(command);
526
- return stdout.split(' ');
527
- }
528
-
529
- export async function updateK8sSequencersConfig(args: {
530
- containerPort: number;
531
- namespace: string;
532
- config: Partial<SequencerConfig>;
533
- }) {
534
- const { containerPort, namespace, config } = args;
535
- const sequencers = await getSequencers(namespace);
536
- for (const sequencer of sequencers) {
537
- const { process, port } = await startPortForward({
538
- resource: `pod/${sequencer}`,
539
- namespace,
540
- containerPort,
541
- });
542
-
543
- const url = `http://localhost:${port}`;
544
- await updateSequencerConfig(url, config);
545
- process.kill();
546
- }
547
- }
548
-
549
- export async function updateSequencersConfig(env: EnvConfig, config: Partial<SequencerConfig>) {
550
- if (isK8sConfig(env)) {
551
- await updateK8sSequencersConfig({
552
- containerPort: env.CONTAINER_NODE_PORT,
553
- namespace: env.NAMESPACE,
554
- config,
555
- });
556
- } else {
557
- await updateSequencerConfig(env.NODE_URL, config);
558
- }
559
- }
560
-
561
- /**
562
- * Rolls the Aztec pods in the given namespace.
563
- * @param namespace - The namespace to roll the Aztec pods in.
564
- * @dev - IMPORTANT: This function DOES NOT delete the underlying PVCs.
565
- * This means that the pods will be restarted with the same persistent storage.
566
- * This is useful for testing, but you should be aware of the implications.
567
- */
568
- export async function rollAztecPods(namespace: string) {
569
- await deleteResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=boot-node' });
570
- await deleteResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=prover-node' });
571
- await deleteResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=prover-broker' });
572
- await deleteResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=prover-agent' });
573
- await deleteResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=validator' });
574
- await deleteResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=pxe' });
575
- await sleep(10 * 1000);
576
- await waitForResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=boot-node' });
577
- await waitForResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=prover-node' });
578
- await waitForResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=prover-broker' });
579
- await waitForResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=prover-agent' });
580
- await waitForResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=validator' });
581
- await waitForResourceByLabel({ resource: 'pods', namespace: namespace, label: 'app=pxe' });
582
- }
1
+ export * from './utils/index.js';