@aztec/end-to-end 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0

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 (404) hide show
  1. package/README.md +217 -14
  2. package/dest/automine/automine_test_context.d.ts +85 -0
  3. package/dest/automine/automine_test_context.d.ts.map +1 -0
  4. package/dest/automine/automine_test_context.js +98 -0
  5. package/dest/automine/contracts/fixtures/storage_proof_fetcher.d.ts +2 -0
  6. package/dest/automine/contracts/fixtures/storage_proof_fetcher.d.ts.map +1 -0
  7. package/dest/automine/contracts/fixtures/storage_proof_fetcher.js +184 -0
  8. package/dest/automine/contracts/fixtures/storage_proof_fixture.d.ts +18 -0
  9. package/dest/automine/contracts/fixtures/storage_proof_fixture.d.ts.map +1 -0
  10. package/dest/automine/contracts/fixtures/storage_proof_fixture.js +120 -0
  11. package/dest/automine/delivery/interactive_handshake_responder.d.ts +48 -0
  12. package/dest/automine/delivery/interactive_handshake_responder.d.ts.map +1 -0
  13. package/dest/automine/delivery/interactive_handshake_responder.js +76 -0
  14. package/dest/automine/delivery/onchain_delivery_harness.d.ts +19 -0
  15. package/dest/automine/delivery/onchain_delivery_harness.d.ts.map +1 -0
  16. package/dest/automine/delivery/onchain_delivery_harness.js +141 -0
  17. package/dest/automine/token/blacklist_token_contract_test.d.ts +49 -0
  18. package/dest/automine/token/blacklist_token_contract_test.d.ts.map +1 -0
  19. package/dest/automine/token/blacklist_token_contract_test.js +166 -0
  20. package/dest/automine/token/token_contract_test.d.ts +40 -0
  21. package/dest/automine/token/token_contract_test.d.ts.map +1 -0
  22. package/dest/automine/token/token_contract_test.js +119 -0
  23. package/dest/automine/token/token_test_helpers.d.ts +73 -0
  24. package/dest/automine/token/token_test_helpers.d.ts.map +1 -0
  25. package/dest/automine/token/token_test_helpers.js +97 -0
  26. package/dest/bench/client_flows/benchmark.d.ts +17 -2
  27. package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
  28. package/dest/bench/client_flows/benchmark.js +40 -1
  29. package/dest/bench/client_flows/client_flows_benchmark.d.ts +19 -20
  30. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  31. package/dest/bench/client_flows/client_flows_benchmark.js +155 -159
  32. package/dest/bench/client_flows/config.d.ts +2 -2
  33. package/dest/bench/client_flows/config.d.ts.map +1 -1
  34. package/dest/bench/client_flows/config.js +18 -0
  35. package/dest/bench/client_flows/data_extractor.js +4 -1
  36. package/dest/bench/utils.d.ts +11 -10
  37. package/dest/bench/utils.d.ts.map +1 -1
  38. package/dest/bench/utils.js +126 -23
  39. package/dest/composed/ha/ha_full_setup.d.ts +77 -0
  40. package/dest/composed/ha/ha_full_setup.d.ts.map +1 -0
  41. package/dest/composed/ha/ha_full_setup.js +383 -0
  42. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts +12 -0
  43. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts.map +1 -0
  44. package/dest/{e2e_multi_validator/utils.js → composed/web3signer/multi_validator_keystore_utils.js} +1 -1
  45. package/dest/fixtures/authwit_proxy.d.ts +15 -0
  46. package/dest/fixtures/authwit_proxy.d.ts.map +1 -0
  47. package/dest/fixtures/authwit_proxy.js +34 -0
  48. package/dest/fixtures/e2e_prover_test.d.ts +25 -29
  49. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  50. package/dest/fixtures/e2e_prover_test.js +147 -151
  51. package/dest/fixtures/elu_monitor.d.ts +21 -0
  52. package/dest/fixtures/elu_monitor.d.ts.map +1 -0
  53. package/dest/fixtures/elu_monitor.js +102 -0
  54. package/dest/fixtures/fixtures.d.ts +84 -3
  55. package/dest/fixtures/fixtures.d.ts.map +1 -1
  56. package/dest/fixtures/fixtures.js +87 -2
  57. package/dest/fixtures/get_acvm_config.js +1 -1
  58. package/dest/fixtures/get_bb_config.d.ts +1 -1
  59. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  60. package/dest/fixtures/get_bb_config.js +5 -5
  61. package/dest/fixtures/ha_setup.d.ts +71 -0
  62. package/dest/fixtures/ha_setup.d.ts.map +1 -0
  63. package/dest/fixtures/ha_setup.js +119 -0
  64. package/dest/fixtures/index.d.ts +3 -1
  65. package/dest/fixtures/index.d.ts.map +1 -1
  66. package/dest/fixtures/index.js +2 -0
  67. package/dest/fixtures/l1_to_l2_messaging.d.ts +4 -3
  68. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  69. package/dest/fixtures/l1_to_l2_messaging.js +2 -2
  70. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts +25 -0
  71. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts.map +1 -0
  72. package/dest/fixtures/schnorr_hardcoded_account_contract.js +37 -0
  73. package/dest/fixtures/setup.d.ts +269 -0
  74. package/dest/fixtures/setup.d.ts.map +1 -0
  75. package/dest/fixtures/setup.js +688 -0
  76. package/dest/fixtures/setup_p2p_test.d.ts +22 -11
  77. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  78. package/dest/fixtures/setup_p2p_test.js +49 -38
  79. package/dest/fixtures/timing.d.ts +42 -0
  80. package/dest/fixtures/timing.d.ts.map +1 -0
  81. package/dest/fixtures/timing.js +72 -0
  82. package/dest/fixtures/token_utils.d.ts +22 -4
  83. package/dest/fixtures/token_utils.d.ts.map +1 -1
  84. package/dest/fixtures/token_utils.js +28 -7
  85. package/dest/fixtures/utils.d.ts +5 -638
  86. package/dest/fixtures/utils.d.ts.map +1 -1
  87. package/dest/fixtures/utils.js +4 -647
  88. package/dest/fixtures/wait_helpers.d.ts +135 -0
  89. package/dest/fixtures/wait_helpers.d.ts.map +1 -0
  90. package/dest/fixtures/wait_helpers.js +154 -0
  91. package/dest/fixtures/web3signer.js +1 -1
  92. package/dest/fixtures/with_telemetry_utils.d.ts +2 -2
  93. package/dest/fixtures/with_telemetry_utils.d.ts.map +1 -1
  94. package/dest/fixtures/with_telemetry_utils.js +2 -2
  95. package/dest/forward-compatibility/wallet_rpc_client.d.ts +7 -0
  96. package/dest/forward-compatibility/wallet_rpc_client.d.ts.map +1 -0
  97. package/dest/forward-compatibility/wallet_rpc_client.js +15 -0
  98. package/dest/forward-compatibility/wallet_service.d.ts +3 -0
  99. package/dest/forward-compatibility/wallet_service.d.ts.map +1 -0
  100. package/dest/forward-compatibility/wallet_service.js +109 -0
  101. package/dest/install_legacy_contracts.d.cts +10 -0
  102. package/dest/install_legacy_contracts.d.cts.map +1 -0
  103. package/dest/legacy-jest-resolver.d.cts +3 -0
  104. package/dest/legacy-jest-resolver.d.cts.map +1 -0
  105. package/dest/multi-node/block-production/setup.d.ts +97 -0
  106. package/dest/multi-node/block-production/setup.d.ts.map +1 -0
  107. package/dest/multi-node/block-production/setup.js +158 -0
  108. package/dest/multi-node/governance/setup.d.ts +67 -0
  109. package/dest/multi-node/governance/setup.d.ts.map +1 -0
  110. package/dest/multi-node/governance/setup.js +126 -0
  111. package/dest/multi-node/multi_node_test_context.d.ts +212 -0
  112. package/dest/multi-node/multi_node_test_context.d.ts.map +1 -0
  113. package/dest/multi-node/multi_node_test_context.js +347 -0
  114. package/dest/multi-node/slashing/inactivity_setup.d.ts +27 -0
  115. package/dest/multi-node/slashing/inactivity_setup.d.ts.map +1 -0
  116. package/dest/multi-node/slashing/inactivity_setup.js +111 -0
  117. package/dest/multi-node/slashing/setup.d.ts +167 -0
  118. package/dest/multi-node/slashing/setup.d.ts.map +1 -0
  119. package/dest/multi-node/slashing/setup.js +275 -0
  120. package/dest/{e2e_p2p → p2p}/p2p_network.d.ts +33 -21
  121. package/dest/p2p/p2p_network.d.ts.map +1 -0
  122. package/dest/p2p/p2p_network.js +389 -0
  123. package/dest/p2p/reqresp/utils.d.ts +19 -0
  124. package/dest/p2p/reqresp/utils.d.ts.map +1 -0
  125. package/dest/p2p/reqresp/utils.js +193 -0
  126. package/dest/p2p/shared.d.ts +72 -0
  127. package/dest/p2p/shared.d.ts.map +1 -0
  128. package/dest/p2p/shared.js +212 -0
  129. package/dest/quality_of_service/grafana_client.d.ts +41 -0
  130. package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
  131. package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
  132. package/dest/quality_of_service/prometheus_client.d.ts +38 -0
  133. package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
  134. package/dest/quality_of_service/prometheus_client.js +67 -0
  135. package/dest/shared/cross_chain_test_harness.d.ts +22 -9
  136. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  137. package/dest/shared/cross_chain_test_harness.js +45 -40
  138. package/dest/shared/gas_portal_test_harness.d.ts +19 -6
  139. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  140. package/dest/shared/gas_portal_test_harness.js +27 -15
  141. package/dest/shared/index.d.ts +3 -2
  142. package/dest/shared/index.d.ts.map +1 -1
  143. package/dest/shared/index.js +1 -0
  144. package/dest/shared/jest_setup.js +41 -1
  145. package/dest/shared/mock_state_view.d.ts +86 -0
  146. package/dest/shared/mock_state_view.d.ts.map +1 -0
  147. package/dest/shared/mock_state_view.js +186 -0
  148. package/dest/shared/submit-transactions.d.ts +4 -4
  149. package/dest/shared/submit-transactions.d.ts.map +1 -1
  150. package/dest/shared/submit-transactions.js +19 -14
  151. package/dest/shared/timing_env.d.js +5 -0
  152. package/dest/shared/timing_env.js +365 -0
  153. package/dest/shared/uniswap_l1_l2.d.ts +3 -27
  154. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  155. package/dest/shared/uniswap_l1_l2.js +86 -54
  156. package/dest/shared/wait_for_l1_to_l2_message.d.ts +13 -0
  157. package/dest/shared/wait_for_l1_to_l2_message.d.ts.map +1 -0
  158. package/dest/shared/wait_for_l1_to_l2_message.js +10 -0
  159. package/dest/simulators/lending_simulator.d.ts +15 -4
  160. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  161. package/dest/simulators/lending_simulator.js +29 -17
  162. package/dest/simulators/token_simulator.d.ts +1 -1
  163. package/dest/simulators/token_simulator.d.ts.map +1 -1
  164. package/dest/simulators/token_simulator.js +3 -24
  165. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts +75 -0
  166. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts.map +1 -0
  167. package/dest/single-node/cross-chain/cross_chain_messaging_test.js +209 -0
  168. package/dest/single-node/cross-chain/message_test_helpers.d.ts +38 -0
  169. package/dest/single-node/cross-chain/message_test_helpers.d.ts.map +1 -0
  170. package/dest/single-node/cross-chain/message_test_helpers.js +70 -0
  171. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.d.ts +1 -1
  172. package/dest/single-node/fees/bridging_race.notest.d.ts.map +1 -0
  173. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.js +21 -10
  174. package/dest/single-node/fees/fees_test.d.ts +93 -0
  175. package/dest/single-node/fees/fees_test.d.ts.map +1 -0
  176. package/dest/single-node/fees/fees_test.js +274 -0
  177. package/dest/single-node/l1-reorgs/setup.d.ts +42 -0
  178. package/dest/single-node/l1-reorgs/setup.d.ts.map +1 -0
  179. package/dest/single-node/l1-reorgs/setup.js +57 -0
  180. package/dest/single-node/partial-proofs/setup.d.ts +5 -0
  181. package/dest/single-node/partial-proofs/setup.d.ts.map +1 -0
  182. package/dest/single-node/partial-proofs/setup.js +5 -0
  183. package/dest/single-node/proving/setup.d.ts +5 -0
  184. package/dest/single-node/proving/setup.d.ts.map +1 -0
  185. package/dest/single-node/proving/setup.js +5 -0
  186. package/dest/single-node/recovery/setup.d.ts +5 -0
  187. package/dest/single-node/recovery/setup.d.ts.map +1 -0
  188. package/dest/single-node/recovery/setup.js +5 -0
  189. package/dest/single-node/setup.d.ts +49 -0
  190. package/dest/single-node/setup.d.ts.map +1 -0
  191. package/dest/single-node/setup.js +56 -0
  192. package/dest/single-node/single_node_test_context.d.ts +360 -0
  193. package/dest/single-node/single_node_test_context.d.ts.map +1 -0
  194. package/dest/single-node/single_node_test_context.js +833 -0
  195. package/dest/spartan/setup_test_wallets.d.ts +15 -5
  196. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  197. package/dest/spartan/setup_test_wallets.js +155 -50
  198. package/dest/spartan/tx_metrics.d.ts +111 -0
  199. package/dest/spartan/tx_metrics.d.ts.map +1 -0
  200. package/dest/spartan/tx_metrics.js +507 -0
  201. package/dest/spartan/utils/bot.d.ts +28 -0
  202. package/dest/spartan/utils/bot.d.ts.map +1 -0
  203. package/dest/spartan/utils/bot.js +142 -0
  204. package/dest/spartan/utils/chaos.d.ts +79 -0
  205. package/dest/spartan/utils/chaos.d.ts.map +1 -0
  206. package/dest/spartan/utils/chaos.js +142 -0
  207. package/dest/spartan/utils/clients.d.ts +39 -0
  208. package/dest/spartan/utils/clients.d.ts.map +1 -0
  209. package/dest/spartan/utils/clients.js +90 -0
  210. package/dest/spartan/utils/config.d.ts +19 -0
  211. package/dest/spartan/utils/config.d.ts.map +1 -0
  212. package/dest/spartan/utils/config.js +23 -0
  213. package/dest/spartan/utils/health.d.ts +63 -0
  214. package/dest/spartan/utils/health.d.ts.map +1 -0
  215. package/dest/spartan/utils/health.js +202 -0
  216. package/dest/spartan/utils/helm.d.ts +15 -0
  217. package/dest/spartan/utils/helm.d.ts.map +1 -0
  218. package/dest/spartan/utils/helm.js +47 -0
  219. package/dest/spartan/utils/index.d.ts +11 -0
  220. package/dest/spartan/utils/index.d.ts.map +1 -0
  221. package/dest/spartan/utils/index.js +22 -0
  222. package/dest/spartan/utils/k8s.d.ts +128 -0
  223. package/dest/spartan/utils/k8s.d.ts.map +1 -0
  224. package/dest/spartan/utils/k8s.js +381 -0
  225. package/dest/spartan/utils/nodes.d.ts +40 -0
  226. package/dest/spartan/utils/nodes.d.ts.map +1 -0
  227. package/dest/spartan/utils/nodes.js +461 -0
  228. package/dest/spartan/utils/pod_logs.d.ts +25 -0
  229. package/dest/spartan/utils/pod_logs.d.ts.map +1 -0
  230. package/dest/spartan/utils/pod_logs.js +74 -0
  231. package/dest/spartan/utils/scripts.d.ts +30 -0
  232. package/dest/spartan/utils/scripts.d.ts.map +1 -0
  233. package/dest/spartan/utils/scripts.js +81 -0
  234. package/dest/spartan/utils.d.ts +2 -221
  235. package/dest/spartan/utils.d.ts.map +1 -1
  236. package/dest/spartan/utils.js +1 -782
  237. package/dest/test-wallet/test_wallet.d.ts +105 -0
  238. package/dest/test-wallet/test_wallet.d.ts.map +1 -0
  239. package/dest/test-wallet/test_wallet.js +320 -0
  240. package/dest/test-wallet/utils.d.ts +76 -0
  241. package/dest/test-wallet/utils.d.ts.map +1 -0
  242. package/dest/test-wallet/utils.js +126 -0
  243. package/dest/test-wallet/wallet_worker_script.d.ts +2 -0
  244. package/dest/test-wallet/wallet_worker_script.d.ts.map +1 -0
  245. package/dest/test-wallet/wallet_worker_script.js +56 -0
  246. package/dest/test-wallet/worker_wallet.d.ts +53 -0
  247. package/dest/test-wallet/worker_wallet.d.ts.map +1 -0
  248. package/dest/test-wallet/worker_wallet.js +157 -0
  249. package/dest/test-wallet/worker_wallet_schema.d.ts +4 -0
  250. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -0
  251. package/dest/test-wallet/worker_wallet_schema.js +23 -0
  252. package/package.json +54 -46
  253. package/src/automine/README.md +60 -0
  254. package/src/automine/automine_test_context.ts +153 -0
  255. package/src/automine/contracts/fixtures/storage_proof.json +915 -0
  256. package/src/automine/contracts/fixtures/storage_proof_fetcher.ts +190 -0
  257. package/src/automine/contracts/fixtures/storage_proof_fixture.ts +173 -0
  258. package/src/automine/delivery/interactive_handshake_responder.ts +125 -0
  259. package/src/automine/delivery/onchain_delivery_harness.ts +213 -0
  260. package/src/automine/token/blacklist_token_contract_test.ts +208 -0
  261. package/src/automine/token/token_contract_test.ts +146 -0
  262. package/src/automine/token/token_test_helpers.ts +138 -0
  263. package/src/bench/client_flows/benchmark.ts +45 -2
  264. package/src/bench/client_flows/client_flows_benchmark.ts +222 -251
  265. package/src/bench/client_flows/config.ts +9 -1
  266. package/src/bench/client_flows/data_extractor.ts +2 -1
  267. package/src/bench/utils.ts +144 -25
  268. package/src/composed/ha/ha_full_setup.ts +466 -0
  269. package/src/{e2e_multi_validator/utils.ts → composed/web3signer/multi_validator_keystore_utils.ts} +1 -1
  270. package/src/fixtures/authwit_proxy.ts +54 -0
  271. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  272. package/src/fixtures/e2e_prover_test.ts +172 -205
  273. package/src/fixtures/elu_monitor.ts +126 -0
  274. package/src/fixtures/fixtures.ts +111 -3
  275. package/src/fixtures/get_acvm_config.ts +1 -1
  276. package/src/fixtures/get_bb_config.ts +7 -6
  277. package/src/fixtures/ha_setup.ts +192 -0
  278. package/src/fixtures/index.ts +2 -0
  279. package/src/fixtures/l1_to_l2_messaging.ts +4 -2
  280. package/src/fixtures/schnorr_hardcoded_account_contract.ts +49 -0
  281. package/src/fixtures/setup.ts +987 -0
  282. package/src/fixtures/setup_p2p_test.ts +57 -57
  283. package/src/fixtures/timing.ts +97 -0
  284. package/src/fixtures/token_utils.ts +46 -10
  285. package/src/fixtures/utils.ts +26 -966
  286. package/src/fixtures/wait_helpers.ts +333 -0
  287. package/src/fixtures/web3signer.ts +1 -1
  288. package/src/fixtures/with_telemetry_utils.ts +2 -2
  289. package/src/forward-compatibility/wallet_rpc_client.ts +14 -0
  290. package/src/forward-compatibility/wallet_service.ts +106 -0
  291. package/src/guides/up_quick_start.sh +7 -4
  292. package/src/infra/README.md +12 -0
  293. package/src/install_legacy_contracts.cjs +75 -0
  294. package/src/legacy-jest-resolver.cjs +112 -0
  295. package/src/multi-node/README.md +95 -0
  296. package/src/multi-node/block-production/setup.ts +272 -0
  297. package/src/multi-node/governance/setup.ts +172 -0
  298. package/src/multi-node/multi_node_test_context.ts +447 -0
  299. package/src/multi-node/slashing/inactivity_setup.ts +139 -0
  300. package/src/multi-node/slashing/setup.ts +433 -0
  301. package/src/p2p/README.md +78 -0
  302. package/src/p2p/p2p_network.ts +542 -0
  303. package/src/p2p/reqresp/utils.ts +263 -0
  304. package/src/p2p/shared.ts +329 -0
  305. package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +1 -1
  306. package/src/quality_of_service/prometheus_client.ts +113 -0
  307. package/src/shared/cross_chain_test_harness.ts +51 -44
  308. package/src/shared/gas_portal_test_harness.ts +35 -17
  309. package/src/shared/index.ts +2 -1
  310. package/src/shared/jest_setup.ts +51 -1
  311. package/src/shared/mock_state_view.ts +188 -0
  312. package/src/shared/submit-transactions.ts +22 -19
  313. package/src/shared/timing_env.d.mts +39 -0
  314. package/src/shared/timing_env.mjs +363 -0
  315. package/src/shared/uniswap_l1_l2.ts +136 -115
  316. package/src/shared/wait_for_l1_to_l2_message.ts +23 -0
  317. package/src/simulators/lending_simulator.ts +36 -18
  318. package/src/simulators/token_simulator.ts +6 -30
  319. package/src/single-node/README.md +60 -0
  320. package/src/single-node/cross-chain/cross_chain_messaging_test.ts +302 -0
  321. package/src/single-node/cross-chain/message_test_helpers.ts +125 -0
  322. package/src/{e2e_fees → single-node/fees}/bridging_race.notest.ts +23 -15
  323. package/src/single-node/fees/fees_test.ts +368 -0
  324. package/src/single-node/l1-reorgs/setup.ts +93 -0
  325. package/src/single-node/partial-proofs/setup.ts +8 -0
  326. package/src/single-node/proving/setup.ts +15 -0
  327. package/src/single-node/recovery/setup.ts +8 -0
  328. package/src/single-node/setup.ts +63 -0
  329. package/src/single-node/single_node_test_context.ts +1041 -0
  330. package/src/spartan/setup_test_wallets.ts +217 -36
  331. package/src/spartan/tx_metrics.ts +460 -0
  332. package/src/spartan/utils/bot.ts +188 -0
  333. package/src/spartan/utils/chaos.ts +253 -0
  334. package/src/spartan/utils/clients.ts +100 -0
  335. package/src/spartan/utils/config.ts +29 -0
  336. package/src/spartan/utils/health.ts +255 -0
  337. package/src/spartan/utils/helm.ts +84 -0
  338. package/src/spartan/utils/index.ts +71 -0
  339. package/src/spartan/utils/k8s.ts +535 -0
  340. package/src/spartan/utils/nodes.ts +543 -0
  341. package/src/spartan/utils/pod_logs.ts +99 -0
  342. package/src/spartan/utils/scripts.ts +99 -0
  343. package/src/spartan/utils.ts +1 -983
  344. package/src/test-wallet/test_wallet.ts +426 -0
  345. package/src/test-wallet/utils.ts +205 -0
  346. package/src/test-wallet/wallet_worker_script.ts +66 -0
  347. package/src/test-wallet/worker_wallet.ts +216 -0
  348. package/src/test-wallet/worker_wallet_schema.ts +14 -0
  349. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +0 -54
  350. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +0 -1
  351. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +0 -185
  352. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +0 -41
  353. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +0 -1
  354. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +0 -108
  355. package/dest/e2e_deploy_contract/deploy_test.d.ts +0 -36
  356. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +0 -1
  357. package/dest/e2e_deploy_contract/deploy_test.js +0 -45
  358. package/dest/e2e_epochs/epochs_test.d.ts +0 -93
  359. package/dest/e2e_epochs/epochs_test.d.ts.map +0 -1
  360. package/dest/e2e_epochs/epochs_test.js +0 -337
  361. package/dest/e2e_fees/bridging_race.notest.d.ts.map +0 -1
  362. package/dest/e2e_fees/fees_test.d.ts +0 -85
  363. package/dest/e2e_fees/fees_test.d.ts.map +0 -1
  364. package/dest/e2e_fees/fees_test.js +0 -263
  365. package/dest/e2e_l1_publisher/write_json.d.ts +0 -10
  366. package/dest/e2e_l1_publisher/write_json.d.ts.map +0 -1
  367. package/dest/e2e_l1_publisher/write_json.js +0 -58
  368. package/dest/e2e_multi_validator/utils.d.ts +0 -12
  369. package/dest/e2e_multi_validator/utils.d.ts.map +0 -1
  370. package/dest/e2e_nested_contract/nested_contract_test.d.ts +0 -29
  371. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +0 -1
  372. package/dest/e2e_nested_contract/nested_contract_test.js +0 -64
  373. package/dest/e2e_p2p/inactivity_slash_test.d.ts +0 -31
  374. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +0 -1
  375. package/dest/e2e_p2p/inactivity_slash_test.js +0 -139
  376. package/dest/e2e_p2p/p2p_network.d.ts.map +0 -1
  377. package/dest/e2e_p2p/p2p_network.js +0 -320
  378. package/dest/e2e_p2p/shared.d.ts +0 -46
  379. package/dest/e2e_p2p/shared.d.ts.map +0 -1
  380. package/dest/e2e_p2p/shared.js +0 -184
  381. package/dest/e2e_token_contract/token_contract_test.d.ts +0 -35
  382. package/dest/e2e_token_contract/token_contract_test.d.ts.map +0 -1
  383. package/dest/e2e_token_contract/token_contract_test.js +0 -126
  384. package/dest/fixtures/setup_l1_contracts.d.ts +0 -477
  385. package/dest/fixtures/setup_l1_contracts.d.ts.map +0 -1
  386. package/dest/fixtures/setup_l1_contracts.js +0 -17
  387. package/dest/fixtures/snapshot_manager.d.ts +0 -95
  388. package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
  389. package/dest/fixtures/snapshot_manager.js +0 -505
  390. package/dest/quality_of_service/alert_checker.d.ts +0 -41
  391. package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
  392. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +0 -256
  393. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +0 -179
  394. package/src/e2e_deploy_contract/deploy_test.ts +0 -78
  395. package/src/e2e_epochs/epochs_test.ts +0 -438
  396. package/src/e2e_fees/fees_test.ts +0 -382
  397. package/src/e2e_l1_publisher/write_json.ts +0 -77
  398. package/src/e2e_nested_contract/nested_contract_test.ts +0 -96
  399. package/src/e2e_p2p/inactivity_slash_test.ts +0 -182
  400. package/src/e2e_p2p/p2p_network.ts +0 -476
  401. package/src/e2e_p2p/shared.ts +0 -285
  402. package/src/e2e_token_contract/token_contract_test.ts +0 -167
  403. package/src/fixtures/setup_l1_contracts.ts +0 -26
  404. package/src/fixtures/snapshot_manager.ts +0 -665
@@ -0,0 +1,987 @@
1
+ import { type InitialAccountData, generateSchnorrAccounts } from '@aztec/accounts/testing';
2
+ import { type AztecNodeConfig, AztecNodeService, createAztecNodeService, getConfigEnvVars } from '@aztec/aztec-node';
3
+ import { AztecAddress, EthAddress } from '@aztec/aztec.js/addresses';
4
+ import type { ContractMethod } from '@aztec/aztec.js/contracts';
5
+ import { publishContractClass, publishInstance } from '@aztec/aztec.js/deployment';
6
+ import { Fr } from '@aztec/aztec.js/fields';
7
+ import { type Logger, createLogger } from '@aztec/aztec.js/log';
8
+ import type { AztecNode } from '@aztec/aztec.js/node';
9
+ import type { Wallet } from '@aztec/aztec.js/wallet';
10
+ import { CheatCodes } from '@aztec/aztec/testing';
11
+ import { SPONSORED_FPC_SALT } from '@aztec/constants';
12
+ import { isAnvilTestChain } from '@aztec/ethereum/chain';
13
+ import { createExtendedL1Client } from '@aztec/ethereum/client';
14
+ import { getL1ContractsConfigEnvVars } from '@aztec/ethereum/config';
15
+ import { NULL_KEY } from '@aztec/ethereum/constants';
16
+ import { deployMulticall3 } from '@aztec/ethereum/contracts';
17
+ import {
18
+ type DeployAztecL1ContractsArgs,
19
+ type DeployAztecL1ContractsReturnType,
20
+ type Operator,
21
+ type ZKPassportArgs,
22
+ deployAztecL1Contracts,
23
+ } from '@aztec/ethereum/deploy-aztec-l1-contracts';
24
+ import type { Delayer } from '@aztec/ethereum/l1-tx-utils';
25
+ import { EthCheatCodes, EthCheatCodesWithState, startAnvil, warmBlobKzg } from '@aztec/ethereum/test';
26
+ import type { Anvil } from '@aztec/ethereum/test';
27
+ import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
28
+ import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
29
+ import { SecretValue } from '@aztec/foundation/config';
30
+ import { randomBytes } from '@aztec/foundation/crypto/random';
31
+ import { tryRmDir } from '@aztec/foundation/fs';
32
+ import { withLoggerBindings } from '@aztec/foundation/log/server';
33
+ import { retryUntil } from '@aztec/foundation/retry';
34
+ import { DateProvider, TestDateProvider } from '@aztec/foundation/timer';
35
+ import { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC';
36
+ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
37
+ import type { P2PClientDeps } from '@aztec/p2p';
38
+ import { MockGossipSubNetwork, getMockPubSubP2PServiceFactory } from '@aztec/p2p/test-helpers';
39
+ import { protocolContractsHash } from '@aztec/protocol-contracts';
40
+ import type { ProverNodeConfig } from '@aztec/prover-node';
41
+ import { type PXEConfig, type PXECreationOptions, getPXEConfig } from '@aztec/pxe/server';
42
+ import type { SequencerClient } from '@aztec/sequencer-client';
43
+ import { AuthRegistryArtifact, getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry';
44
+ import { HandshakeRegistryArtifact, getStandardHandshakeRegistry } from '@aztec/standard-contracts/handshake-registry';
45
+ import { PublicChecksArtifact, getStandardPublicChecks } from '@aztec/standard-contracts/public-checks';
46
+ import { ARTIFACT_VERSION_BEFORE_INJECTION } from '@aztec/stdlib/abi';
47
+ import { type ContractInstanceWithAddress, getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
48
+ import type { AztecNodeAdmin, AztecNodeDebug } from '@aztec/stdlib/interfaces/client';
49
+ import { tryStop } from '@aztec/stdlib/interfaces/server';
50
+ import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
51
+ import type { GenesisData } from '@aztec/stdlib/world-state';
52
+ import {
53
+ type TelemetryClient,
54
+ type TelemetryClientConfig,
55
+ getConfigEnvVars as getTelemetryConfig,
56
+ initTelemetryClient,
57
+ } from '@aztec/telemetry-client';
58
+ import { BenchmarkTelemetryClient } from '@aztec/telemetry-client/bench';
59
+ import { createFundedInitializerlessAccounts } from '@aztec/wallets/testing';
60
+ import { getGenesisValues } from '@aztec/world-state/testing';
61
+
62
+ import fs from 'fs/promises';
63
+ import { tmpdir } from 'os';
64
+ import path from 'path';
65
+ import type { Hex } from 'viem';
66
+ import {
67
+ type HDAccount,
68
+ type PrivateKeyAccount,
69
+ generatePrivateKey,
70
+ mnemonicToAccount,
71
+ privateKeyToAccount,
72
+ } from 'viem/accounts';
73
+ import { type Chain, foundry } from 'viem/chains';
74
+
75
+ import { TestWallet } from '../test-wallet/test_wallet.js';
76
+ import { MNEMONIC, TEST_MAX_PENDING_TX_POOL_COUNT, TEST_PEER_CHECK_INTERVAL_MS } from './fixtures.js';
77
+ import { getACVMConfig } from './get_acvm_config.js';
78
+ import { getBBConfig } from './get_bb_config.js';
79
+ import { isMetricsLoggingRequested, setupMetricsLogger } from './logging.js';
80
+ import { testSpan } from './timing.js';
81
+ import { getEndToEndTestTelemetryClient } from './with_telemetry_utils.js';
82
+
83
+ export { startAnvil };
84
+
85
+ let telemetry: TelemetryClient | undefined = undefined;
86
+ async function getTelemetryClient(partialConfig: Partial<TelemetryClientConfig> & { benchmark?: boolean } = {}) {
87
+ if (!telemetry) {
88
+ const config = { ...getTelemetryConfig(), ...partialConfig };
89
+ telemetry = config.benchmark ? new BenchmarkTelemetryClient() : await initTelemetryClient(config);
90
+ }
91
+ return telemetry;
92
+ }
93
+
94
+ export const getPrivateKeyFromIndex = (index: number): Buffer | null => {
95
+ const hdAccount = mnemonicToAccount(MNEMONIC, { addressIndex: index });
96
+ const privKeyRaw = hdAccount.getHdKey().privateKey;
97
+ return privKeyRaw === null ? null : Buffer.from(privKeyRaw);
98
+ };
99
+
100
+ /**
101
+ * Sets up shared blob storage using FileStore in the data directory.
102
+ */
103
+ export async function setupSharedBlobStorage(config: { dataDirectory?: string } & Record<string, any>): Promise<void> {
104
+ const sharedBlobPath = path.join(config.dataDirectory!, 'shared-blobs');
105
+ await fs.mkdir(sharedBlobPath, { recursive: true });
106
+ config.blobFileStoreUrls = [`file://${sharedBlobPath}`];
107
+ config.blobFileStoreUploadUrl = `file://${sharedBlobPath}`;
108
+ }
109
+
110
+ /**
111
+ * Sets up Private eXecution Environment (PXE) and returns the corresponding test wallet.
112
+ * @param aztecNode - An instance of Aztec Node.
113
+ * @param nodeDebug - The node's debug API, used to register public function signatures for named traces; pass
114
+ * `undefined` when the node does not expose it.
115
+ * @param opts - Partial configuration for the PXE.
116
+ * @param logger - The logger to be used.
117
+ * @param actor - Actor label to include in log output (e.g., 'pxe-test').
118
+ * @returns A test wallet, logger and teardown function.
119
+ */
120
+ export async function setupPXEAndGetWallet(
121
+ aztecNode: AztecNode,
122
+ nodeDebug: AztecNodeDebug | undefined,
123
+ opts: Partial<PXEConfig> = {},
124
+ logger = getLogger(),
125
+ actor?: string,
126
+ ): Promise<{
127
+ wallet: TestWallet;
128
+ logger: Logger;
129
+ teardown: () => Promise<void>;
130
+ }> {
131
+ const PXEConfig = { ...getPXEConfig(), ...opts };
132
+ // For tests we only want proving enabled if specifically requested
133
+ PXEConfig.proverEnabled = !!opts.proverEnabled;
134
+
135
+ // If no data directory provided, create a temp directory and clean up afterwards
136
+ const configuredDataDirectory = PXEConfig.dataDirectory;
137
+ if (!configuredDataDirectory) {
138
+ PXEConfig.dataDirectory = path.join(tmpdir(), randomBytes(8).toString('hex'));
139
+ }
140
+
141
+ const teardown = configuredDataDirectory ? () => Promise.resolve() : () => tryRmDir(PXEConfig.dataDirectory!);
142
+
143
+ const wallet = await TestWallet.create(aztecNode, PXEConfig, {
144
+ loggerActorLabel: actor,
145
+ nodeDebug,
146
+ });
147
+
148
+ return {
149
+ wallet,
150
+ logger,
151
+ teardown,
152
+ };
153
+ }
154
+
155
+ /** Options for the e2e tests setup */
156
+ export type SetupOptions<TDeployExtraL1ContractsReturnType = unknown> = {
157
+ /** State load */
158
+ stateLoad?: string;
159
+ /** Whether to enable metrics collection, if undefined, metrics collection is disabled */
160
+ metricsPort?: number | undefined;
161
+ /** Previously deployed contracts on L1 */
162
+ deployL1ContractsValues?: DeployAztecL1ContractsReturnType;
163
+ /** Initial fee juice for default accounts */
164
+ initialAccountFeeJuice?: Fr;
165
+ /**
166
+ * Extra accounts to fund at genesis beyond the `numberOfAccounts` initializerless accounts that setup
167
+ * creates. Setup funds these but does NOT create or deploy them — the test creates/deploys them itself
168
+ */
169
+ additionallyFundedAccounts?: InitialAccountData[];
170
+ /** An initial set of validators */
171
+ initialValidators?: (Operator & { privateKey: `0x${string}` })[];
172
+ /** Anvil Start time */
173
+ l1StartTime?: number;
174
+ /** The anvil time where we should at the earliest be seeing L2 blocks */
175
+ l2StartTime?: number;
176
+ /** Whether to start a prover node */
177
+ startProverNode?: boolean;
178
+ /** Manual config for the telemetry client */
179
+ telemetryConfig?: Partial<TelemetryClientConfig> & { benchmark?: boolean };
180
+ /** Public data that will be inserted in the tree in genesis */
181
+ genesisPublicData?: PublicDataTreeLeaf[];
182
+ /** Specific config for the prover node, if set. */
183
+ proverNodeConfig?: Partial<ProverNodeConfig>;
184
+ /** Whether to use a mock gossip sub network for p2p clients. */
185
+ mockGossipSubNetwork?: boolean;
186
+ /** Whether to add simulated latency to the mock gossipsub network (in ms) */
187
+ mockGossipSubNetworkLatency?: number;
188
+ /**
189
+ * Whether to mine the L1 setup txs (Multicall3 + rollup contract deployment) under anvil automine
190
+ * instead of waiting on the block interval. Defaults to `true` (set in `setupInner`); only suites
191
+ * that assert on genesis-relative L1 timing need to opt out with `false`.
192
+ */
193
+ automineL1Setup?: boolean;
194
+ /**
195
+ * Hook invoked after the Aztec L1 rollup contracts are deployed but BEFORE the node/sequencer
196
+ * start, while anvil automine is still enabled (when `automineL1Setup` is true, the default).
197
+ * Deploy extra L1 contracts a test needs here (e.g. a cross-chain token portal + ERC20) so they
198
+ * mine instantly under automine instead of paying the L1 block interval once the node is running
199
+ * (and racing the live sequencer/archiver). The resolved value is exposed on the returned context
200
+ * as `extraL1DeployResult`. The hook receives setup's L1 deployer client (the same one used to
201
+ * deploy Multicall3).
202
+ */
203
+ deployExtraL1Contracts?: (deps: {
204
+ l1Client: ExtendedViemWalletClient;
205
+ deployL1ContractsValues: DeployAztecL1ContractsReturnType;
206
+ logger: Logger;
207
+ }) => Promise<TDeployExtraL1ContractsReturnType>;
208
+ /** How many accounts to seed and unlock in anvil. */
209
+ anvilAccounts?: number;
210
+ /** Port to start anvil (defaults to 8545) */
211
+ anvilPort?: number;
212
+ /**
213
+ * Number of slots per epoch for Anvil's finality simulation.
214
+ * Anvil reports `finalized = latest - slotsInAnEpoch * 2`.
215
+ */
216
+ anvilSlotsInAnEpoch?: number;
217
+ /** Key to use for publishing L1 contracts */
218
+ l1PublisherKey?: SecretValue<`0x${string}`>;
219
+ /** ZkPassport configuration (domain, scope, mock verifier) */
220
+ zkPassportArgs?: ZKPassportArgs;
221
+ /** Whether to fund the sponsored FPC in genesis (defaults to false). */
222
+ fundSponsoredFPC?: boolean;
223
+ /** L1 contracts deployment arguments. */
224
+ l1ContractsArgs?: Partial<DeployAztecL1ContractsArgs>;
225
+ /** Wallet minimum fee padding multiplier */
226
+ walletMinFeePadding?: number;
227
+ /** Whether the initial node should be a lightweight RPC-only node (no sequencer, no validator).
228
+ * Use for tests that create their own validator nodes and don't need the initial sequencer. */
229
+ skipInitialSequencer?: boolean;
230
+ /** Whether to swap the production Sequencer for the minimal AutomineSequencer.
231
+ * Use only for single-sequencer non-block-building tests. See AUTOMINE_E2E_OPTS in `fixtures.ts`. */
232
+ useAutomineSequencer?: boolean;
233
+ /** Options forwarded to PXE creation (e.g. execution hooks). */
234
+ pxeCreationOptions?: PXECreationOptions;
235
+ } & Partial<AztecNodeConfig>;
236
+
237
+ /** Context for an end-to-end test as returned by the `setup` function */
238
+ export type EndToEndContext<TDeployExtraL1ContractsReturnType = unknown> = {
239
+ /** The Anvil instance (only set if anvil was started locally). */
240
+ anvil: Anvil | undefined;
241
+ /** The Aztec Node service or client a connected to it. */
242
+ aztecNode: AztecNode & AztecNodeDebug;
243
+ /** The Aztec Node as a service. */
244
+ aztecNodeService: AztecNodeService;
245
+ /** Client to the Aztec Node admin interface. */
246
+ aztecNodeAdmin: AztecNodeAdmin;
247
+ /** The aztec node running the prover node subsystem (only set if startProverNode is true). */
248
+ proverNode: AztecNodeService | undefined;
249
+ /** A client to the sequencer service. */
250
+ sequencer: SequencerClient | undefined;
251
+ /** Return values from deployAztecL1Contracts function. */
252
+ deployL1ContractsValues: DeployAztecL1ContractsReturnType;
253
+ /** The Aztec Node configuration. */
254
+ config: AztecNodeConfig;
255
+ /** The Aztec Node configuration (alias for config for backward compatibility). */
256
+ aztecNodeConfig: AztecNodeConfig;
257
+ /** Data for the extra accounts funded at genesis but not created by setup (the test creates/deploys them). */
258
+ additionallyFundedAccounts: InitialAccountData[];
259
+ /** The wallet to be used. */
260
+ wallet: TestWallet;
261
+ /** The wallets to be used. */
262
+ accounts: AztecAddress[];
263
+ /** Logger instance named as the current test. */
264
+ logger: Logger;
265
+ /** The cheat codes. */
266
+ cheatCodes: CheatCodes;
267
+ /** The cheat codes for L1 */
268
+ ethCheatCodes: EthCheatCodes;
269
+ /** Allows tweaking current system time, used by the epoch cache only. */
270
+ dateProvider: TestDateProvider;
271
+ /** Telemetry client */
272
+ telemetryClient: TelemetryClient;
273
+ /** Mock gossip sub network used for gossipping messages (only if mockGossipSubNetwork was set to true in opts) */
274
+ mockGossipSubNetwork: MockGossipSubNetwork | undefined;
275
+ /** Delayer for sequencer L1 txs (only when enableDelayer is true). */
276
+ sequencerDelayer: Delayer | undefined;
277
+ /** Delayer for prover node L1 txs (only when enableDelayer and startProverNode are true). */
278
+ proverDelayer: Delayer | undefined;
279
+ /** Genesis data used for setting up nodes. */
280
+ genesis: GenesisData | undefined;
281
+ /** Resolved value of the `deployExtraL1Contracts` setup hook, if one was provided. */
282
+ extraL1DeployResult: TDeployExtraL1ContractsReturnType;
283
+ /** ACVM config (only set if running locally). */
284
+ acvmConfig: Awaited<ReturnType<typeof getACVMConfig>>;
285
+ /** BB config (only set if running locally). */
286
+ bbConfig: Awaited<ReturnType<typeof getBBConfig>>;
287
+ /** Directory to cleanup on teardown. */
288
+ directoryToCleanup: string;
289
+ /** Function to stop the started services. */
290
+ teardown: () => Promise<void>;
291
+ };
292
+
293
+ /**
294
+ * When CONTRACT_ARTIFACTS_VERSION is set (backwards compatibility testing), asserts that the loaded artifact's
295
+ * aztecVersion matches the expected version. This is a sanity check verifying that the legacy artifact resolver
296
+ * actually swapped in the correct version.
297
+ */
298
+ function assertContractArtifactsVersion() {
299
+ const expected = process.env.CONTRACT_ARTIFACTS_VERSION;
300
+ if (!expected) {
301
+ return;
302
+ }
303
+ const { aztecVersion } = SponsoredFPCContract.artifact;
304
+ // TODO(F-557): Remove this bypass once pre-version artifacts are no longer tested.
305
+ if (aztecVersion === ARTIFACT_VERSION_BEFORE_INJECTION) {
306
+ createLogger('e2e:setup').info(
307
+ `Skipping artifact version check: artifact predates version injection (CONTRACT_ARTIFACTS_VERSION=${expected})`,
308
+ );
309
+ return;
310
+ }
311
+ if (aztecVersion !== expected) {
312
+ throw new Error(
313
+ `Artifact version mismatch: expected ${expected} but got ${aztecVersion}. ` +
314
+ `The legacy artifact resolver may not have swapped in the correct version.`,
315
+ );
316
+ }
317
+ }
318
+
319
+ /**
320
+ * Sets up the environment for the end-to-end tests.
321
+ * @param numberOfAccounts - The number of new accounts to be created once the PXE is initiated.
322
+ * @param opts - Options to pass to the node initialization and to the setup script.
323
+ * @param pxeOpts - Options to pass to the PXE initialization.
324
+ */
325
+ export function setup<TDeployExtraL1ContractsReturnType = unknown>(
326
+ numberOfAccounts = 1,
327
+ opts: SetupOptions<TDeployExtraL1ContractsReturnType> = {},
328
+ pxeOpts: Partial<PXEConfig> = {},
329
+ chain: Chain = foundry,
330
+ ): Promise<EndToEndContext<TDeployExtraL1ContractsReturnType>> {
331
+ // Tag the top-level env spin-up with the prover mode (none → fake → real), the largest config-driven
332
+ // swing in setup cost, so the three factories are comparable on the span leaderboard. The internals
333
+ // (anvil / l1-deploy / sequencer-start / pxe / wallet:create) decompose this further.
334
+ const proverMode = opts.realProofs ? 'real' : opts.startProverNode ? 'fake' : 'none';
335
+ return testSpan(`setup:env:${proverMode}`, async () => {
336
+ const ctx = await setupInner(numberOfAccounts, opts, pxeOpts, chain);
337
+ if (process.env.EXIT_E2E_AFTER_SETUP) {
338
+ ctx.logger.info('EXIT_E2E_AFTER_SETUP is set; aborting before the test body runs');
339
+ throw new Error('EXIT_E2E_AFTER_SETUP');
340
+ }
341
+ return ctx;
342
+ });
343
+ }
344
+
345
+ async function setupInner<TDeployExtraL1ContractsReturnType = unknown>(
346
+ numberOfAccounts: number,
347
+ opts: SetupOptions<TDeployExtraL1ContractsReturnType>,
348
+ pxeOpts: Partial<PXEConfig>,
349
+ chain: Chain,
350
+ ): Promise<EndToEndContext<TDeployExtraL1ContractsReturnType>> {
351
+ assertContractArtifactsVersion();
352
+ const logger = getLogger();
353
+ let anvil: Anvil | undefined;
354
+ try {
355
+ opts.aztecTargetCommitteeSize ??= 0;
356
+ opts.slasherEnabled ??= false;
357
+ // Mine the L1 setup txs (Multicall3 + rollup contract deployment) immediately instead of
358
+ // waiting on anvil's block interval — this is the dominant cost of e2e setup. Suites that
359
+ // assert on genesis-relative L1 timing can opt out by passing `automineL1Setup: false`.
360
+ opts.automineL1Setup ??= true;
361
+ logger.trace('Starting e2e test setup');
362
+
363
+ const config: AztecNodeConfig & SetupOptions = { ...getConfigEnvVars(), ...opts };
364
+ // use initialValidators for the node config
365
+ config.validatorPrivateKeys = new SecretValue(opts.initialValidators?.map(v => v.privateKey) ?? []);
366
+
367
+ config.peerCheckIntervalMS = TEST_PEER_CHECK_INTERVAL_MS;
368
+ config.maxPendingTxCount = opts.maxPendingTxCount ?? TEST_MAX_PENDING_TX_POOL_COUNT;
369
+ // For tests we only want proving enabled if specifically requested
370
+ config.realProofs = !!opts.realProofs;
371
+ // Enable the tx delayer for tests (default config has it disabled, so we force-enable it here)
372
+ config.enableDelayer = true;
373
+ config.listenAddress = '127.0.0.1';
374
+
375
+ config.minTxPoolAgeMs = opts.minTxPoolAgeMs ?? 0;
376
+
377
+ // Create a temp directory for any services that need it and cleanup later
378
+ const directoryToCleanup = path.join(tmpdir(), randomBytes(8).toString('hex'));
379
+ await fs.mkdir(directoryToCleanup, { recursive: true });
380
+ if (!config.dataDirectory) {
381
+ config.dataDirectory = directoryToCleanup;
382
+ }
383
+
384
+ const dateProvider = new TestDateProvider();
385
+
386
+ if (!config.l1RpcUrls?.length) {
387
+ if (!isAnvilTestChain(chain.id)) {
388
+ throw new Error(`No ETHEREUM_HOSTS set but non anvil chain requested`);
389
+ }
390
+ const res = await testSpan('setup:env:anvil', () =>
391
+ startAnvil({
392
+ l1BlockTime: opts.ethereumSlotDuration,
393
+ accounts: opts.anvilAccounts,
394
+ port: opts.anvilPort ?? (process.env.ANVIL_PORT ? parseInt(process.env.ANVIL_PORT) : undefined),
395
+ slotsInAnEpoch: opts.anvilSlotsInAnEpoch,
396
+ dateProvider,
397
+ }),
398
+ );
399
+ anvil = res.anvil;
400
+ config.l1RpcUrls = [res.rpcUrl];
401
+ }
402
+ logger.trace('Started anvil and L1 RPC client');
403
+
404
+ // Enable logging metrics to a local file named after the test suite
405
+ if (isMetricsLoggingRequested()) {
406
+ const filename = path.join('log', getJobName() + '.jsonl');
407
+ logger.info(`Logging metrics to ${filename}`);
408
+ setupMetricsLogger(filename);
409
+ }
410
+ const ethCheatCodes = new EthCheatCodesWithState(config.l1RpcUrls, dateProvider);
411
+
412
+ if (opts.stateLoad) {
413
+ await ethCheatCodes.loadChainState(opts.stateLoad);
414
+ }
415
+
416
+ if (opts.l1StartTime) {
417
+ await ethCheatCodes.warp(opts.l1StartTime, { resetBlockInterval: true });
418
+ }
419
+ logger.trace('Initialized L1 cheat codes and applied state/time overrides');
420
+
421
+ let publisherPrivKeyHex: `0x${string}` | undefined = undefined;
422
+ let publisherHdAccount: HDAccount | PrivateKeyAccount | undefined = undefined;
423
+
424
+ if (opts.l1PublisherKey && opts.l1PublisherKey.getValue() && opts.l1PublisherKey.getValue() != NULL_KEY) {
425
+ publisherPrivKeyHex = opts.l1PublisherKey.getValue();
426
+ publisherHdAccount = privateKeyToAccount(publisherPrivKeyHex);
427
+ } else if (
428
+ config.sequencerPublisherPrivateKeys &&
429
+ config.sequencerPublisherPrivateKeys.length > 0 &&
430
+ config.sequencerPublisherPrivateKeys[0].getValue() != NULL_KEY
431
+ ) {
432
+ publisherPrivKeyHex = config.sequencerPublisherPrivateKeys[0].getValue();
433
+ publisherHdAccount = privateKeyToAccount(publisherPrivKeyHex);
434
+ } else if (!MNEMONIC) {
435
+ throw new Error(`Mnemonic not provided and no publisher private key`);
436
+ } else {
437
+ publisherHdAccount = mnemonicToAccount(MNEMONIC, { addressIndex: 0 });
438
+ const publisherPrivKeyRaw = publisherHdAccount.getHdKey().privateKey;
439
+ const publisherPrivKey = publisherPrivKeyRaw === null ? null : Buffer.from(publisherPrivKeyRaw);
440
+ publisherPrivKeyHex = `0x${publisherPrivKey!.toString('hex')}` as const;
441
+ config.sequencerPublisherPrivateKeys = [new SecretValue(publisherPrivKeyHex)];
442
+ }
443
+
444
+ if (config.coinbase === undefined) {
445
+ config.coinbase = EthAddress.fromString(publisherHdAccount.address);
446
+ }
447
+ logger.trace('Resolved L1 publisher account');
448
+
449
+ // The accounts setup creates itself: `numberOfAccounts` initializerless accounts, generated here and
450
+ // funded at genesis so they are immediately usable.
451
+ const defaultAccounts = await generateSchnorrAccounts(numberOfAccounts);
452
+ // Extra accounts the test wants funded at genesis but will create/deploy itself.
453
+ const additionallyFundedAccounts = opts.additionallyFundedAccounts ?? [];
454
+ const addressesToFund = [...defaultAccounts, ...additionallyFundedAccounts].map(a => a.address);
455
+
456
+ // Optionally fund the sponsored FPC
457
+ if (opts.fundSponsoredFPC) {
458
+ const sponsoredFPCAddress = await getSponsoredFPCAddress();
459
+ addressesToFund.push(sponsoredFPCAddress);
460
+ }
461
+ logger.trace('Generated test accounts to fund at genesis');
462
+
463
+ const genesisTimestamp = BigInt(Math.floor(Date.now() / 1000));
464
+ const { genesisArchiveRoot, genesis, fundingNeeded } = await getGenesisValues(
465
+ addressesToFund,
466
+ opts.initialAccountFeeJuice,
467
+ opts.genesisPublicData,
468
+ genesisTimestamp,
469
+ );
470
+ logger.trace('Computed genesis values');
471
+
472
+ const wasAutomining = await ethCheatCodes.isAutoMining();
473
+ const enableAutomine = opts.automineL1Setup && !wasAutomining && isAnvilTestChain(chain.id);
474
+ if (enableAutomine) {
475
+ await ethCheatCodes.setAutomine(true);
476
+ }
477
+
478
+ const l1Client = createExtendedL1Client(config.l1RpcUrls, publisherHdAccount!, chain);
479
+
480
+ // Warm both KZG trusted setups (ours + anvil's) in parallel
481
+ if (anvil && isAnvilTestChain(chain.id)) {
482
+ await warmBlobKzg(l1Client, logger);
483
+ }
484
+
485
+ // Deploy Multicall3 if running locally
486
+ await deployMulticall3(l1Client, logger);
487
+
488
+ // Force viem to refresh its nonce cache to avoid "nonce too low" errors in subsequent transactions
489
+ // This is necessary because deployMulticall3 sends multiple transactions and viem may cache a stale nonce
490
+ await l1Client.getTransactionCount({ address: l1Client.account.address });
491
+ logger.trace('Deployed Multicall3');
492
+
493
+ const deployL1ContractsValues: DeployAztecL1ContractsReturnType = await testSpan('setup:env:l1-deploy', () =>
494
+ deployAztecL1Contracts(config.l1RpcUrls[0], publisherPrivKeyHex!, chain.id, {
495
+ ...getL1ContractsConfigEnvVars(),
496
+ ...opts,
497
+ ...opts.l1ContractsArgs,
498
+ vkTreeRoot: getVKTreeRoot(),
499
+ protocolContractsHash,
500
+ genesisArchiveRoot,
501
+ initialValidators: opts.initialValidators,
502
+ feeJuicePortalInitialBalance: fundingNeeded,
503
+ realVerifier: false,
504
+ }),
505
+ );
506
+
507
+ Object.assign(config, deployL1ContractsValues.l1ContractAddresses);
508
+ config.rollupVersion = deployL1ContractsValues.rollupVersion;
509
+
510
+ // Propagate L1-contracts-config overrides back to the node config so the archiver's
511
+ // `l1Constants` (and any other node-side consumer) agrees with what was actually deployed.
512
+ // Without this, a per-test override like `aztecEpochDuration: 4` lands on the rollup contract
513
+ // but the node config keeps the default (32), so `archiver.isEpochComplete(0)` computes
514
+ // `endSlot=31` and `EpochTestSettler`/`EpochMonitor` never fires — letting the
515
+ // `aztecProofSubmissionEpochs` window expire mid-test and prune the pending chain.
516
+ // Skip undefined values: callers (e.g. `P2PNetworkTest`) sometimes build `l1ContractsArgs`
517
+ // by spreading a partial `AztecNodeConfig`, which leaves unset fields (notably `dataDirectory`)
518
+ // as `undefined`. A blind Object.assign would then clobber the temp `dataDirectory` set earlier
519
+ // in this function and crash `setupSharedBlobStorage`.
520
+ if (opts.l1ContractsArgs) {
521
+ for (const [key, value] of Object.entries(opts.l1ContractsArgs)) {
522
+ if (value !== undefined) {
523
+ (config as unknown as Record<string, unknown>)[key] = value;
524
+ }
525
+ }
526
+ }
527
+
528
+ // Deploy any test-specific L1 contracts while automine is still on and before the node starts,
529
+ // so they mine instantly rather than paying the L1 block interval once the sequencer is live.
530
+ let extraL1DeployResult: TDeployExtraL1ContractsReturnType = undefined as TDeployExtraL1ContractsReturnType;
531
+ if (opts.deployExtraL1Contracts) {
532
+ logger.trace('Running deployExtraL1Contracts hook');
533
+ extraL1DeployResult = await opts.deployExtraL1Contracts({
534
+ l1Client,
535
+ deployL1ContractsValues,
536
+ logger,
537
+ });
538
+ // The hook reused `l1Client` to send deploy txs, so refresh viem's nonce cache to avoid a
539
+ // stale cached nonce for later transactions on the publisher account.
540
+ await l1Client.getTransactionCount({ address: l1Client.account.address });
541
+ }
542
+
543
+ if (enableAutomine) {
544
+ await ethCheatCodes.startIntervalMiningWithFreshBlock(config.ethereumSlotDuration);
545
+ }
546
+
547
+ // In compose mode (no local anvil), sync dateProvider to L1 time since it may have drifted
548
+ // ahead of system time. When running with a local anvil, the dateProvider is kept in sync via
549
+ // the stdout listener.
550
+ if (!anvil) {
551
+ dateProvider.setTime((await ethCheatCodes.lastBlockTimestamp()) * 1000);
552
+ }
553
+
554
+ if (opts.l2StartTime) {
555
+ await ethCheatCodes.warp(opts.l2StartTime, { resetBlockInterval: true });
556
+ }
557
+ logger.trace('Deployed L1 rollup contracts');
558
+
559
+ // These boot steps are independent and write disjoint config keys, so run them concurrently:
560
+ // telemetry returns a client (no config write), shared blob storage writes blobFileStore* keys,
561
+ // and the ACVM/BB config resolvers write their own acvm*/bb* keys.
562
+ const [telemetryClient, , acvmConfig, bbConfig] = await Promise.all([
563
+ // Use metricsPort-based telemetry if provided, otherwise use the regular telemetry client
564
+ opts.metricsPort ? getEndToEndTestTelemetryClient(opts.metricsPort) : getTelemetryClient(opts.telemetryConfig),
565
+ setupSharedBlobStorage(config),
566
+ getACVMConfig(logger),
567
+ getBBConfig(logger),
568
+ ]);
569
+ logger.trace('Created telemetry client');
570
+ logger.trace('Set up shared blob storage');
571
+
572
+ if (acvmConfig) {
573
+ config.acvmWorkingDirectory = acvmConfig.acvmWorkingDirectory;
574
+ config.acvmBinaryPath = acvmConfig.acvmBinaryPath;
575
+ }
576
+ logger.trace('Resolved ACVM config');
577
+
578
+ if (bbConfig) {
579
+ config.bbBinaryPath = bbConfig.bbBinaryPath;
580
+ config.bbWorkingDirectory = bbConfig.bbWorkingDirectory;
581
+ }
582
+ logger.trace('Resolved Barretenberg config');
583
+
584
+ logger.verbose('Creating and synching an aztec node', config);
585
+
586
+ let mockGossipSubNetwork: MockGossipSubNetwork | undefined;
587
+ let p2pClientDeps: P2PClientDeps | undefined = undefined;
588
+
589
+ if (opts.mockGossipSubNetwork) {
590
+ mockGossipSubNetwork = new MockGossipSubNetwork(opts.mockGossipSubNetworkLatency);
591
+ p2pClientDeps = { p2pServiceFactory: getMockPubSubP2PServiceFactory(mockGossipSubNetwork) };
592
+ }
593
+
594
+ config.p2pEnabled = opts.mockGossipSubNetwork || config.p2pEnabled;
595
+ config.p2pIp = opts.p2pIp ?? config.p2pIp ?? '127.0.0.1';
596
+
597
+ if (!config.disableValidator) {
598
+ if ((config.validatorPrivateKeys?.getValue().length ?? 0) === 0) {
599
+ config.validatorPrivateKeys = new SecretValue([generatePrivateKey()]);
600
+ }
601
+ }
602
+
603
+ // When skipInitialSequencer is set, the initial node is a lightweight RPC-only node.
604
+ // We apply these overrides to a copy so they don't leak into the returned config.
605
+ // Keep P2P enabled if mockGossipSubNetwork is used (needed for tx propagation to validators).
606
+ const initialNodeConfig = opts.skipInitialSequencer
607
+ ? {
608
+ ...config,
609
+ disableValidator: true,
610
+ ...(opts.mockGossipSubNetwork ? {} : { p2pEnabled: false, bootstrapNodes: [] as string[] }),
611
+ }
612
+ : config;
613
+ logger.trace('Prepared aztec node config');
614
+
615
+ const aztecNodeService = await testSpan('setup:env:sequencer-start', () =>
616
+ withLoggerBindings({ actor: 'node-0' }, () =>
617
+ createAztecNodeService(
618
+ initialNodeConfig,
619
+ { dateProvider, telemetry: telemetryClient, p2pClientDeps },
620
+ { genesis, dontStartSequencer: opts.skipInitialSequencer },
621
+ ),
622
+ ),
623
+ );
624
+ const sequencerClient = aztecNodeService.getSequencer();
625
+ logger.trace('Created and synced aztec node');
626
+
627
+ let proverNode: AztecNodeService | undefined = undefined;
628
+ if (opts.startProverNode) {
629
+ logger.verbose('Creating and syncing a simulated prover node...');
630
+ const proverNodePrivateKey = getPrivateKeyFromIndex(2);
631
+ const proverNodePrivateKeyHex: Hex = `0x${proverNodePrivateKey!.toString('hex')}`;
632
+ const proverNodeDataDirectory = path.join(directoryToCleanup, randomBytes(8).toString('hex'));
633
+
634
+ const p2pClientDeps: Partial<P2PClientDeps> = {
635
+ p2pServiceFactory: mockGossipSubNetwork && getMockPubSubP2PServiceFactory(mockGossipSubNetwork!),
636
+ rpcTxProviders: [aztecNodeService],
637
+ };
638
+
639
+ ({ proverNode } = await testSpan('setup:env:prover-node', () =>
640
+ createAndSyncProverNode(
641
+ proverNodePrivateKeyHex,
642
+ config,
643
+ {
644
+ ...config.proverNodeConfig,
645
+ dataDirectory: proverNodeDataDirectory,
646
+ },
647
+ { dateProvider, p2pClientDeps, telemetry: telemetryClient },
648
+ { genesis },
649
+ ),
650
+ ));
651
+ logger.trace('Created prover node');
652
+ }
653
+
654
+ const sequencerDelayer = sequencerClient?.getDelayer();
655
+ const proverDelayer = proverNode?.getProverNode()?.getDelayer();
656
+
657
+ logger.verbose('Creating a pxe...');
658
+ const pxeConfig = { ...getPXEConfig(), ...pxeOpts };
659
+ pxeConfig.dataDirectory = path.join(directoryToCleanup, randomBytes(8).toString('hex'));
660
+ // For tests we only want proving enabled if specifically requested
661
+ pxeConfig.proverEnabled = !!pxeOpts.proverEnabled;
662
+ const wallet = await testSpan('setup:env:pxe', () =>
663
+ TestWallet.create(aztecNodeService, pxeConfig, {
664
+ loggerActorLabel: 'pxe-0',
665
+ // In-process node implements the debug API, so register public function signatures for named traces.
666
+ nodeDebug: aztecNodeService,
667
+ ...opts.pxeCreationOptions,
668
+ }),
669
+ );
670
+
671
+ if (opts.walletMinFeePadding !== undefined) {
672
+ wallet.setMinFeePadding(opts.walletMinFeePadding);
673
+ }
674
+ logger.trace('Created PXE and test wallet');
675
+
676
+ const cheatCodes = await CheatCodes.create(config.l1RpcUrls, aztecNodeService, dateProvider);
677
+ logger.trace('Created cheat codes');
678
+
679
+ if (
680
+ (opts.aztecTargetCommitteeSize && opts.aztecTargetCommitteeSize > 0) ||
681
+ (opts.initialValidators && opts.initialValidators.length > 0)
682
+ ) {
683
+ // We need to advance such that the committee is set up.
684
+ await cheatCodes.rollup.advanceToEpoch(
685
+ EpochNumber.fromBigInt(
686
+ BigInt(await cheatCodes.rollup.getEpoch()) + BigInt(config.lagInEpochsForValidatorSet + 1),
687
+ ),
688
+ );
689
+ await cheatCodes.rollup.setupEpoch();
690
+ await cheatCodes.rollup.debugRollup();
691
+ logger.trace('Advanced chain to set up validator committee');
692
+ }
693
+
694
+ let accounts: AztecAddress[] = [];
695
+
696
+ // Create the default accounts. They are initializerless, so this is a PXE-side operation (registration
697
+ // + a simulated store call) with no on-chain tx, independent of the sequencer.
698
+ if (numberOfAccounts > 0) {
699
+ logger.info(`Creating ${numberOfAccounts} initializerless test accounts`);
700
+ await testSpan('wallet:create', () => createFundedInitializerlessAccounts(wallet, defaultAccounts));
701
+ accounts = defaultAccounts.map(a => a.address);
702
+ }
703
+ logger.trace('Created funded test accounts');
704
+
705
+ const teardown = () =>
706
+ testSpan('teardown:env', async () => {
707
+ try {
708
+ await tryStop(wallet, logger);
709
+ await tryStop(aztecNodeService, logger);
710
+ await tryStop(proverNode, logger);
711
+
712
+ if (acvmConfig?.cleanup) {
713
+ await acvmConfig.cleanup();
714
+ }
715
+
716
+ if (bbConfig?.cleanup) {
717
+ await bbConfig.cleanup();
718
+ }
719
+
720
+ await tryStop(anvil, logger);
721
+
722
+ await tryRmDir(directoryToCleanup, logger);
723
+ } catch (err) {
724
+ logger.error(`Error during e2e test teardown`, err);
725
+ } finally {
726
+ try {
727
+ await telemetryClient.stop();
728
+ } catch (err) {
729
+ logger.error(`Error during telemetry client stop`, err);
730
+ }
731
+ }
732
+ });
733
+
734
+ return {
735
+ anvil,
736
+ aztecNode: aztecNodeService,
737
+ aztecNodeService,
738
+ aztecNodeAdmin: aztecNodeService,
739
+ cheatCodes,
740
+ ethCheatCodes,
741
+ config,
742
+ aztecNodeConfig: config,
743
+ dateProvider,
744
+ deployL1ContractsValues,
745
+ additionallyFundedAccounts,
746
+ logger,
747
+ mockGossipSubNetwork,
748
+ genesis,
749
+ extraL1DeployResult,
750
+ proverNode,
751
+ sequencerDelayer,
752
+ proverDelayer,
753
+ sequencer: sequencerClient,
754
+ teardown,
755
+ telemetryClient,
756
+ wallet,
757
+ accounts,
758
+ acvmConfig,
759
+ bbConfig,
760
+ directoryToCleanup,
761
+ };
762
+ } catch (err) {
763
+ await anvil?.stop();
764
+ throw err;
765
+ }
766
+ }
767
+
768
+ /** Returns the job name for the current test. */
769
+ function getJobName() {
770
+ return process.env.JOB_NAME ?? expect.getState().currentTestName?.split(' ')[0].replaceAll('/', '_') ?? 'unknown';
771
+ }
772
+
773
+ /**
774
+ * Returns a logger instance for the current test.
775
+ */
776
+ export function getLogger() {
777
+ const describeBlockName = expect.getState().currentTestName?.split(' ')[0].replaceAll('/', ':');
778
+ if (!describeBlockName) {
779
+ const name = expect.getState().testPath?.split('/').pop()?.split('.')[0] ?? 'unknown';
780
+ return createLogger('e2e:' + name);
781
+ }
782
+ return createLogger('e2e:' + describeBlockName);
783
+ }
784
+
785
+ /**
786
+ * Computes the address of the "canonical" SponsoredFPCContract.
787
+ */
788
+ export function getSponsoredFPCInstance(): Promise<ContractInstanceWithAddress> {
789
+ return Promise.resolve(
790
+ getContractInstanceFromInstantiationParams(SponsoredFPCContract.artifact, {
791
+ salt: new Fr(SPONSORED_FPC_SALT),
792
+ }),
793
+ );
794
+ }
795
+
796
+ /**
797
+ * Computes the address of the "canonical" SponsoredFPCContract.
798
+ */
799
+ export async function getSponsoredFPCAddress() {
800
+ const sponsoredFPCInstance = await getSponsoredFPCInstance();
801
+ return sponsoredFPCInstance.address;
802
+ }
803
+
804
+ /**
805
+ * Deploy a sponsored FPC contract to a running instance.
806
+ */
807
+ export async function setupSponsoredFPC(wallet: Wallet) {
808
+ const instance = await getContractInstanceFromInstantiationParams(SponsoredFPCContract.artifact, {
809
+ salt: new Fr(SPONSORED_FPC_SALT),
810
+ });
811
+
812
+ await wallet.registerContract(instance, SponsoredFPCContract.artifact);
813
+ getLogger().info(`SponsoredFPC: ${instance.address}`);
814
+ return instance;
815
+ }
816
+
817
+ /**
818
+ * Registers the SponsoredFPC in this PXE instance.
819
+ */
820
+ export async function registerSponsoredFPC(wallet: Wallet): Promise<void> {
821
+ await wallet.registerContract(await getSponsoredFPCInstance(), SponsoredFPCContract.artifact);
822
+ }
823
+
824
+ export async function waitForProvenChain(
825
+ node: AztecNode,
826
+ targetBlock?: BlockNumber,
827
+ timeoutSec = 60,
828
+ intervalSec = 0.25,
829
+ ) {
830
+ targetBlock ??= await node.getBlockNumber();
831
+
832
+ await retryUntil(
833
+ async () => (await node.getBlockNumber('proven')) >= targetBlock,
834
+ 'proven chain status',
835
+ timeoutSec,
836
+ intervalSec,
837
+ );
838
+ }
839
+
840
+ /**
841
+ * Creates an AztecNodeService with the prover node enabled as a subsystem.
842
+ * Returns both the aztec node service (for lifecycle management) and the prover node (for test internals access).
843
+ */
844
+ export function createAndSyncProverNode(
845
+ proverNodePrivateKey: `0x${string}`,
846
+ baseConfig: AztecNodeConfig,
847
+ configOverrides: Pick<AztecNodeConfig, 'dataDirectory'>,
848
+ deps: {
849
+ telemetry?: TelemetryClient;
850
+ dateProvider: DateProvider;
851
+ p2pClientDeps?: P2PClientDeps;
852
+ },
853
+ options: { genesis?: GenesisData; dontStart?: boolean },
854
+ ): Promise<{ proverNode: AztecNodeService }> {
855
+ return withLoggerBindings({ actor: 'prover-0' }, async () => {
856
+ const proverNode = await createAztecNodeService(
857
+ {
858
+ ...baseConfig,
859
+ ...configOverrides,
860
+ p2pPort: 0,
861
+ enableProverNode: true,
862
+ disableValidator: true,
863
+ proverPublisherPrivateKeys: [new SecretValue(proverNodePrivateKey)],
864
+ },
865
+ deps,
866
+ { genesis: options.genesis, dontStartProverNode: options.dontStart },
867
+ );
868
+
869
+ if (!proverNode.getProverNode()) {
870
+ throw new Error('Prover node subsystem was not created despite enableProverNode being set');
871
+ }
872
+
873
+ getLogger().info(`Created and synced prover node`);
874
+ return { proverNode };
875
+ });
876
+ }
877
+
878
+ export type BalancesFn = ReturnType<typeof getBalancesFn>;
879
+ export function getBalancesFn(
880
+ symbol: string,
881
+ method: ContractMethod,
882
+ logger: any,
883
+ ): (...addresses: (AztecAddress | { address: AztecAddress })[]) => Promise<bigint[]> {
884
+ const balances = async (...addressLikes: (AztecAddress | { address: AztecAddress })[]) => {
885
+ const addresses = addressLikes.map(addressLike => ('address' in addressLike ? addressLike.address : addressLike));
886
+ const b = await Promise.all(
887
+ addresses.map(async address => (await method(address).simulate({ from: address })).result),
888
+ );
889
+ const debugString = `${symbol} balances: ${addresses.map((address, i) => `${address}: ${b[i]}`).join(', ')}`;
890
+ logger.verbose(debugString);
891
+ return b;
892
+ };
893
+
894
+ return balances;
895
+ }
896
+
897
+ export async function expectMapping<K, V>(
898
+ fn: (...k: K[]) => Promise<V[]>,
899
+ inputs: K[],
900
+ expectedOutputs: V[],
901
+ ): Promise<void> {
902
+ expect(inputs.length).toBe(expectedOutputs.length);
903
+
904
+ const outputs = await fn(...inputs);
905
+
906
+ expect(outputs).toEqual(expectedOutputs);
907
+ }
908
+
909
+ export async function expectMappingDelta<K, V extends number | bigint>(
910
+ initialValues: V[],
911
+ fn: (...k: K[]) => Promise<V[]>,
912
+ inputs: K[],
913
+ expectedDiffs: V[],
914
+ ): Promise<void> {
915
+ expect(inputs.length).toBe(expectedDiffs.length);
916
+
917
+ const outputs = await fn(...inputs);
918
+ const diffs = outputs.map((output, i) => output - initialValues[i]);
919
+
920
+ expect(diffs).toEqual(expectedDiffs);
921
+ }
922
+
923
+ /**
924
+ * Registers the auth_registry contract class and publishes its standard instance if not already
925
+ * present, and registers the artifact with PXE. Publishing is required before exercising the public
926
+ * authwit path (which relies on the AVM's deployment-nullifier check); the PXE-side registration is
927
+ * required so revert messages from AuthRegistry calls can be enriched (otherwise assertion strings
928
+ * surface as generic "Assertion failed:" and tests that match on the real message fail).
929
+ */
930
+ export async function ensureAuthRegistryPublished(wallet: Wallet, from: AztecAddress) {
931
+ await testSpan('setup:auth-registry', async () => {
932
+ const { instance, contractClass } = await getStandardAuthRegistry();
933
+ if (!(await wallet.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered) {
934
+ await (await publishContractClass(wallet, AuthRegistryArtifact)).send({ from });
935
+ }
936
+ if (!(await wallet.getContractMetadata(instance.address)).isContractPublished) {
937
+ await publishInstance(wallet, instance).send({ from });
938
+ }
939
+ await wallet.registerContract(instance, AuthRegistryArtifact);
940
+ });
941
+ }
942
+
943
+ /**
944
+ * Registers the public_checks contract class and publishes its standard instance if not already
945
+ * present, and registers the artifact with PXE. Required for any contract that calls
946
+ * `privately_check_timestamp` / `privately_check_block_number` (which dispatch into the
947
+ * deployed PublicChecks contract via an enqueued public call).
948
+ */
949
+ export async function ensurePublicChecksPublished(wallet: Wallet, from: AztecAddress) {
950
+ const { instance, contractClass } = await getStandardPublicChecks();
951
+ if (!(await wallet.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered) {
952
+ await (await publishContractClass(wallet, PublicChecksArtifact)).send({ from });
953
+ }
954
+ if (!(await wallet.getContractMetadata(instance.address)).isContractPublished) {
955
+ await publishInstance(wallet, instance).send({ from });
956
+ }
957
+ await wallet.registerContract(instance, PublicChecksArtifact);
958
+ }
959
+
960
+ /**
961
+ * Registers the handshake_registry contract class and publishes its standard instance if not
962
+ * already present, and registers the artifact with PXE. Required for constrained-delivery flows
963
+ * that call into the HandshakeRegistry at its well-known address.
964
+ */
965
+ export async function ensureHandshakeRegistryPublished(wallet: Wallet, from: AztecAddress) {
966
+ const { instance, contractClass } = await getStandardHandshakeRegistry();
967
+ if (!(await wallet.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered) {
968
+ await (await publishContractClass(wallet, HandshakeRegistryArtifact)).send({ from });
969
+ }
970
+ if (!(await wallet.getContractMetadata(instance.address)).isContractPublished) {
971
+ await publishInstance(wallet, instance).send({ from });
972
+ }
973
+ await wallet.registerContract(instance, HandshakeRegistryArtifact);
974
+ }
975
+
976
+ /**
977
+ * Destroys the current context.
978
+ */
979
+ export async function teardown(context: EndToEndContext | undefined) {
980
+ if (!context) {
981
+ return;
982
+ }
983
+ await context.teardown();
984
+ }
985
+
986
+ // Re-export for backward compatibility
987
+ export { deployAndInitializeTokenAndBridgeContracts } from '../shared/cross_chain_test_harness.js';