@aztec/end-to-end 0.0.1-commit.d431d1c → 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 (366) 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/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.js +50 -54
  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/{e2e_token_contract → automine/token}/token_contract_test.js +44 -49
  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 +15 -1
  27. package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
  28. package/dest/bench/client_flows/benchmark.js +19 -0
  29. package/dest/bench/client_flows/client_flows_benchmark.d.ts +6 -6
  30. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  31. package/dest/bench/client_flows/client_flows_benchmark.js +68 -44
  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 +1 -0
  36. package/dest/bench/utils.d.ts +7 -6
  37. package/dest/bench/utils.d.ts.map +1 -1
  38. package/dest/bench/utils.js +108 -12
  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/fixtures/authwit_proxy.d.ts +15 -0
  45. package/dest/fixtures/authwit_proxy.d.ts.map +1 -0
  46. package/dest/fixtures/authwit_proxy.js +34 -0
  47. package/dest/fixtures/e2e_prover_test.d.ts +18 -14
  48. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  49. package/dest/fixtures/e2e_prover_test.js +85 -74
  50. package/dest/fixtures/elu_monitor.d.ts +21 -0
  51. package/dest/fixtures/elu_monitor.d.ts.map +1 -0
  52. package/dest/fixtures/elu_monitor.js +102 -0
  53. package/dest/fixtures/fixtures.d.ts +83 -1
  54. package/dest/fixtures/fixtures.d.ts.map +1 -1
  55. package/dest/fixtures/fixtures.js +86 -0
  56. package/dest/fixtures/get_bb_config.d.ts +1 -1
  57. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  58. package/dest/fixtures/get_bb_config.js +5 -5
  59. package/dest/fixtures/ha_setup.d.ts +71 -0
  60. package/dest/fixtures/ha_setup.d.ts.map +1 -0
  61. package/dest/fixtures/ha_setup.js +119 -0
  62. package/dest/fixtures/index.d.ts +3 -1
  63. package/dest/fixtures/index.d.ts.map +1 -1
  64. package/dest/fixtures/index.js +2 -0
  65. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts +25 -0
  66. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts.map +1 -0
  67. package/dest/fixtures/schnorr_hardcoded_account_contract.js +37 -0
  68. package/dest/fixtures/setup.d.ts +113 -60
  69. package/dest/fixtures/setup.d.ts.map +1 -1
  70. package/dest/fixtures/setup.js +330 -326
  71. package/dest/fixtures/setup_p2p_test.d.ts +22 -11
  72. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  73. package/dest/fixtures/setup_p2p_test.js +46 -35
  74. package/dest/fixtures/timing.d.ts +42 -0
  75. package/dest/fixtures/timing.d.ts.map +1 -0
  76. package/dest/fixtures/timing.js +72 -0
  77. package/dest/fixtures/token_utils.d.ts +22 -4
  78. package/dest/fixtures/token_utils.d.ts.map +1 -1
  79. package/dest/fixtures/token_utils.js +28 -7
  80. package/dest/fixtures/utils.d.ts +2 -2
  81. package/dest/fixtures/utils.d.ts.map +1 -1
  82. package/dest/fixtures/utils.js +1 -1
  83. package/dest/fixtures/wait_helpers.d.ts +135 -0
  84. package/dest/fixtures/wait_helpers.d.ts.map +1 -0
  85. package/dest/fixtures/wait_helpers.js +154 -0
  86. package/dest/forward-compatibility/wallet_rpc_client.d.ts +7 -0
  87. package/dest/forward-compatibility/wallet_rpc_client.d.ts.map +1 -0
  88. package/dest/forward-compatibility/wallet_rpc_client.js +15 -0
  89. package/dest/forward-compatibility/wallet_service.d.ts +3 -0
  90. package/dest/forward-compatibility/wallet_service.d.ts.map +1 -0
  91. package/dest/forward-compatibility/wallet_service.js +109 -0
  92. package/dest/install_legacy_contracts.d.cts +10 -0
  93. package/dest/install_legacy_contracts.d.cts.map +1 -0
  94. package/dest/legacy-jest-resolver.d.cts +3 -0
  95. package/dest/legacy-jest-resolver.d.cts.map +1 -0
  96. package/dest/multi-node/block-production/setup.d.ts +97 -0
  97. package/dest/multi-node/block-production/setup.d.ts.map +1 -0
  98. package/dest/multi-node/block-production/setup.js +158 -0
  99. package/dest/multi-node/governance/setup.d.ts +67 -0
  100. package/dest/multi-node/governance/setup.d.ts.map +1 -0
  101. package/dest/multi-node/governance/setup.js +126 -0
  102. package/dest/multi-node/multi_node_test_context.d.ts +212 -0
  103. package/dest/multi-node/multi_node_test_context.d.ts.map +1 -0
  104. package/dest/multi-node/multi_node_test_context.js +347 -0
  105. package/dest/multi-node/slashing/inactivity_setup.d.ts +27 -0
  106. package/dest/multi-node/slashing/inactivity_setup.d.ts.map +1 -0
  107. package/dest/multi-node/slashing/inactivity_setup.js +111 -0
  108. package/dest/multi-node/slashing/setup.d.ts +167 -0
  109. package/dest/multi-node/slashing/setup.d.ts.map +1 -0
  110. package/dest/multi-node/slashing/setup.js +275 -0
  111. package/dest/{e2e_p2p → p2p}/p2p_network.d.ts +22 -12
  112. package/dest/p2p/p2p_network.d.ts.map +1 -0
  113. package/dest/{e2e_p2p → p2p}/p2p_network.js +99 -35
  114. package/dest/p2p/reqresp/utils.d.ts +19 -0
  115. package/dest/p2p/reqresp/utils.d.ts.map +1 -0
  116. package/dest/p2p/reqresp/utils.js +193 -0
  117. package/dest/p2p/shared.d.ts +72 -0
  118. package/dest/p2p/shared.d.ts.map +1 -0
  119. package/dest/p2p/shared.js +212 -0
  120. package/dest/shared/cross_chain_test_harness.d.ts +8 -7
  121. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  122. package/dest/shared/cross_chain_test_harness.js +44 -39
  123. package/dest/shared/gas_portal_test_harness.d.ts +8 -5
  124. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  125. package/dest/shared/gas_portal_test_harness.js +27 -15
  126. package/dest/shared/index.d.ts +2 -1
  127. package/dest/shared/index.d.ts.map +1 -1
  128. package/dest/shared/index.js +1 -0
  129. package/dest/shared/jest_setup.js +41 -1
  130. package/dest/shared/mock_state_view.d.ts +86 -0
  131. package/dest/shared/mock_state_view.d.ts.map +1 -0
  132. package/dest/shared/mock_state_view.js +186 -0
  133. package/dest/shared/submit-transactions.d.ts +4 -4
  134. package/dest/shared/submit-transactions.d.ts.map +1 -1
  135. package/dest/shared/submit-transactions.js +19 -14
  136. package/dest/shared/timing_env.d.js +5 -0
  137. package/dest/shared/timing_env.js +365 -0
  138. package/dest/shared/uniswap_l1_l2.d.ts +1 -1
  139. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  140. package/dest/shared/uniswap_l1_l2.js +67 -55
  141. package/dest/shared/wait_for_l1_to_l2_message.d.ts +13 -0
  142. package/dest/shared/wait_for_l1_to_l2_message.d.ts.map +1 -0
  143. package/dest/shared/wait_for_l1_to_l2_message.js +10 -0
  144. package/dest/simulators/lending_simulator.d.ts +10 -3
  145. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  146. package/dest/simulators/lending_simulator.js +29 -17
  147. package/dest/simulators/token_simulator.d.ts +1 -1
  148. package/dest/simulators/token_simulator.d.ts.map +1 -1
  149. package/dest/simulators/token_simulator.js +3 -24
  150. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts +75 -0
  151. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts.map +1 -0
  152. package/dest/single-node/cross-chain/cross_chain_messaging_test.js +209 -0
  153. package/dest/single-node/cross-chain/message_test_helpers.d.ts +38 -0
  154. package/dest/single-node/cross-chain/message_test_helpers.d.ts.map +1 -0
  155. package/dest/single-node/cross-chain/message_test_helpers.js +70 -0
  156. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.d.ts +1 -1
  157. package/dest/single-node/fees/bridging_race.notest.d.ts.map +1 -0
  158. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.js +18 -5
  159. package/dest/single-node/fees/fees_test.d.ts +93 -0
  160. package/dest/single-node/fees/fees_test.d.ts.map +1 -0
  161. package/dest/{e2e_fees → single-node/fees}/fees_test.js +96 -70
  162. package/dest/single-node/l1-reorgs/setup.d.ts +42 -0
  163. package/dest/single-node/l1-reorgs/setup.d.ts.map +1 -0
  164. package/dest/single-node/l1-reorgs/setup.js +57 -0
  165. package/dest/single-node/partial-proofs/setup.d.ts +5 -0
  166. package/dest/single-node/partial-proofs/setup.d.ts.map +1 -0
  167. package/dest/single-node/partial-proofs/setup.js +5 -0
  168. package/dest/single-node/proving/setup.d.ts +5 -0
  169. package/dest/single-node/proving/setup.d.ts.map +1 -0
  170. package/dest/single-node/proving/setup.js +5 -0
  171. package/dest/single-node/recovery/setup.d.ts +5 -0
  172. package/dest/single-node/recovery/setup.d.ts.map +1 -0
  173. package/dest/single-node/recovery/setup.js +5 -0
  174. package/dest/single-node/setup.d.ts +49 -0
  175. package/dest/single-node/setup.d.ts.map +1 -0
  176. package/dest/single-node/setup.js +56 -0
  177. package/dest/single-node/single_node_test_context.d.ts +360 -0
  178. package/dest/single-node/single_node_test_context.d.ts.map +1 -0
  179. package/dest/single-node/single_node_test_context.js +833 -0
  180. package/dest/spartan/setup_test_wallets.d.ts +12 -3
  181. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  182. package/dest/spartan/setup_test_wallets.js +153 -49
  183. package/dest/spartan/tx_metrics.d.ts +64 -5
  184. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  185. package/dest/spartan/tx_metrics.js +280 -21
  186. package/dest/spartan/utils/bot.d.ts +28 -0
  187. package/dest/spartan/utils/bot.d.ts.map +1 -0
  188. package/dest/spartan/utils/bot.js +142 -0
  189. package/dest/spartan/utils/chaos.d.ts +79 -0
  190. package/dest/spartan/utils/chaos.d.ts.map +1 -0
  191. package/dest/spartan/utils/chaos.js +142 -0
  192. package/dest/spartan/utils/clients.d.ts +39 -0
  193. package/dest/spartan/utils/clients.d.ts.map +1 -0
  194. package/dest/spartan/utils/clients.js +90 -0
  195. package/dest/spartan/utils/config.d.ts +19 -0
  196. package/dest/spartan/utils/config.d.ts.map +1 -0
  197. package/dest/spartan/utils/config.js +23 -0
  198. package/dest/spartan/utils/health.d.ts +63 -0
  199. package/dest/spartan/utils/health.d.ts.map +1 -0
  200. package/dest/spartan/utils/health.js +202 -0
  201. package/dest/spartan/utils/helm.d.ts +15 -0
  202. package/dest/spartan/utils/helm.d.ts.map +1 -0
  203. package/dest/spartan/utils/helm.js +47 -0
  204. package/dest/spartan/utils/index.d.ts +11 -0
  205. package/dest/spartan/utils/index.d.ts.map +1 -0
  206. package/dest/spartan/utils/index.js +22 -0
  207. package/dest/spartan/utils/k8s.d.ts +128 -0
  208. package/dest/spartan/utils/k8s.d.ts.map +1 -0
  209. package/dest/spartan/utils/k8s.js +381 -0
  210. package/dest/spartan/utils/nodes.d.ts +40 -0
  211. package/dest/spartan/utils/nodes.d.ts.map +1 -0
  212. package/dest/spartan/utils/nodes.js +461 -0
  213. package/dest/spartan/utils/pod_logs.d.ts +25 -0
  214. package/dest/spartan/utils/pod_logs.d.ts.map +1 -0
  215. package/dest/spartan/utils/pod_logs.js +74 -0
  216. package/dest/spartan/utils/scripts.d.ts +30 -0
  217. package/dest/spartan/utils/scripts.d.ts.map +1 -0
  218. package/dest/spartan/utils/scripts.js +81 -0
  219. package/dest/spartan/utils.d.ts +2 -260
  220. package/dest/spartan/utils.d.ts.map +1 -1
  221. package/dest/spartan/utils.js +1 -942
  222. package/dest/test-wallet/test_wallet.d.ts +105 -0
  223. package/dest/test-wallet/test_wallet.d.ts.map +1 -0
  224. package/dest/test-wallet/test_wallet.js +320 -0
  225. package/dest/test-wallet/utils.d.ts +76 -0
  226. package/dest/test-wallet/utils.d.ts.map +1 -0
  227. package/dest/test-wallet/utils.js +126 -0
  228. package/dest/test-wallet/wallet_worker_script.d.ts +2 -0
  229. package/dest/test-wallet/wallet_worker_script.d.ts.map +1 -0
  230. package/dest/test-wallet/wallet_worker_script.js +56 -0
  231. package/dest/test-wallet/worker_wallet.d.ts +53 -0
  232. package/dest/test-wallet/worker_wallet.d.ts.map +1 -0
  233. package/dest/test-wallet/worker_wallet.js +157 -0
  234. package/dest/test-wallet/worker_wallet_schema.d.ts +4 -0
  235. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -0
  236. package/dest/test-wallet/worker_wallet_schema.js +23 -0
  237. package/package.json +53 -46
  238. package/src/automine/README.md +60 -0
  239. package/src/automine/automine_test_context.ts +153 -0
  240. package/src/automine/contracts/fixtures/storage_proof.json +915 -0
  241. package/src/automine/contracts/fixtures/storage_proof_fetcher.ts +190 -0
  242. package/src/automine/contracts/fixtures/storage_proof_fixture.ts +173 -0
  243. package/src/automine/delivery/interactive_handshake_responder.ts +125 -0
  244. package/src/automine/delivery/onchain_delivery_harness.ts +213 -0
  245. package/src/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.ts +56 -69
  246. package/src/{e2e_token_contract → automine/token}/token_contract_test.ts +51 -59
  247. package/src/automine/token/token_test_helpers.ts +138 -0
  248. package/src/bench/client_flows/benchmark.ts +21 -0
  249. package/src/bench/client_flows/client_flows_benchmark.ts +111 -90
  250. package/src/bench/client_flows/config.ts +9 -1
  251. package/src/bench/client_flows/data_extractor.ts +1 -0
  252. package/src/bench/utils.ts +123 -12
  253. package/src/composed/ha/ha_full_setup.ts +466 -0
  254. package/src/fixtures/authwit_proxy.ts +54 -0
  255. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  256. package/src/fixtures/e2e_prover_test.ts +102 -103
  257. package/src/fixtures/elu_monitor.ts +126 -0
  258. package/src/fixtures/fixtures.ts +110 -0
  259. package/src/fixtures/get_bb_config.ts +7 -6
  260. package/src/fixtures/ha_setup.ts +192 -0
  261. package/src/fixtures/index.ts +2 -0
  262. package/src/fixtures/schnorr_hardcoded_account_contract.ts +49 -0
  263. package/src/fixtures/setup.ts +421 -444
  264. package/src/fixtures/setup_p2p_test.ts +54 -54
  265. package/src/fixtures/timing.ts +97 -0
  266. package/src/fixtures/token_utils.ts +46 -10
  267. package/src/fixtures/utils.ts +2 -3
  268. package/src/fixtures/wait_helpers.ts +333 -0
  269. package/src/forward-compatibility/wallet_rpc_client.ts +14 -0
  270. package/src/forward-compatibility/wallet_service.ts +106 -0
  271. package/src/guides/up_quick_start.sh +7 -4
  272. package/src/infra/README.md +12 -0
  273. package/src/install_legacy_contracts.cjs +75 -0
  274. package/src/legacy-jest-resolver.cjs +112 -0
  275. package/src/multi-node/README.md +95 -0
  276. package/src/multi-node/block-production/setup.ts +272 -0
  277. package/src/multi-node/governance/setup.ts +172 -0
  278. package/src/multi-node/multi_node_test_context.ts +447 -0
  279. package/src/multi-node/slashing/inactivity_setup.ts +139 -0
  280. package/src/multi-node/slashing/setup.ts +433 -0
  281. package/src/p2p/README.md +78 -0
  282. package/src/{e2e_p2p → p2p}/p2p_network.ts +132 -57
  283. package/src/p2p/reqresp/utils.ts +263 -0
  284. package/src/p2p/shared.ts +329 -0
  285. package/src/shared/cross_chain_test_harness.ts +52 -41
  286. package/src/shared/gas_portal_test_harness.ts +34 -16
  287. package/src/shared/index.ts +1 -0
  288. package/src/shared/jest_setup.ts +51 -1
  289. package/src/shared/mock_state_view.ts +188 -0
  290. package/src/shared/submit-transactions.ts +22 -19
  291. package/src/shared/timing_env.d.mts +39 -0
  292. package/src/shared/timing_env.mjs +363 -0
  293. package/src/shared/uniswap_l1_l2.ts +109 -74
  294. package/src/shared/wait_for_l1_to_l2_message.ts +23 -0
  295. package/src/simulators/lending_simulator.ts +35 -17
  296. package/src/simulators/token_simulator.ts +6 -30
  297. package/src/single-node/README.md +60 -0
  298. package/src/single-node/cross-chain/cross_chain_messaging_test.ts +302 -0
  299. package/src/single-node/cross-chain/message_test_helpers.ts +125 -0
  300. package/src/{e2e_fees → single-node/fees}/bridging_race.notest.ts +20 -9
  301. package/src/{e2e_fees → single-node/fees}/fees_test.ts +120 -95
  302. package/src/single-node/l1-reorgs/setup.ts +93 -0
  303. package/src/single-node/partial-proofs/setup.ts +8 -0
  304. package/src/single-node/proving/setup.ts +15 -0
  305. package/src/single-node/recovery/setup.ts +8 -0
  306. package/src/single-node/setup.ts +63 -0
  307. package/src/single-node/single_node_test_context.ts +1041 -0
  308. package/src/spartan/setup_test_wallets.ts +208 -34
  309. package/src/spartan/tx_metrics.ts +255 -26
  310. package/src/spartan/utils/bot.ts +188 -0
  311. package/src/spartan/utils/chaos.ts +253 -0
  312. package/src/spartan/utils/clients.ts +100 -0
  313. package/src/spartan/utils/config.ts +29 -0
  314. package/src/spartan/utils/health.ts +255 -0
  315. package/src/spartan/utils/helm.ts +84 -0
  316. package/src/spartan/utils/index.ts +71 -0
  317. package/src/spartan/utils/k8s.ts +535 -0
  318. package/src/spartan/utils/nodes.ts +543 -0
  319. package/src/spartan/utils/pod_logs.ts +99 -0
  320. package/src/spartan/utils/scripts.ts +99 -0
  321. package/src/spartan/utils.ts +1 -1246
  322. package/src/test-wallet/test_wallet.ts +426 -0
  323. package/src/test-wallet/utils.ts +205 -0
  324. package/src/test-wallet/wallet_worker_script.ts +66 -0
  325. package/src/test-wallet/worker_wallet.ts +216 -0
  326. package/src/test-wallet/worker_wallet_schema.ts +14 -0
  327. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +0 -53
  328. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +0 -1
  329. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +0 -47
  330. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +0 -1
  331. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +0 -128
  332. package/dest/e2e_deploy_contract/deploy_test.d.ts +0 -37
  333. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +0 -1
  334. package/dest/e2e_deploy_contract/deploy_test.js +0 -50
  335. package/dest/e2e_epochs/epochs_test.d.ts +0 -94
  336. package/dest/e2e_epochs/epochs_test.d.ts.map +0 -1
  337. package/dest/e2e_epochs/epochs_test.js +0 -339
  338. package/dest/e2e_fees/bridging_race.notest.d.ts.map +0 -1
  339. package/dest/e2e_fees/fees_test.d.ts +0 -88
  340. package/dest/e2e_fees/fees_test.d.ts.map +0 -1
  341. package/dest/e2e_l1_publisher/write_json.d.ts +0 -10
  342. package/dest/e2e_l1_publisher/write_json.d.ts.map +0 -1
  343. package/dest/e2e_l1_publisher/write_json.js +0 -62
  344. package/dest/e2e_multi_validator/utils.d.ts +0 -12
  345. package/dest/e2e_multi_validator/utils.d.ts.map +0 -1
  346. package/dest/e2e_nested_contract/nested_contract_test.d.ts +0 -26
  347. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +0 -1
  348. package/dest/e2e_nested_contract/nested_contract_test.js +0 -56
  349. package/dest/e2e_p2p/inactivity_slash_test.d.ts +0 -31
  350. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +0 -1
  351. package/dest/e2e_p2p/inactivity_slash_test.js +0 -136
  352. package/dest/e2e_p2p/p2p_network.d.ts.map +0 -1
  353. package/dest/e2e_p2p/shared.d.ts +0 -46
  354. package/dest/e2e_p2p/shared.d.ts.map +0 -1
  355. package/dest/e2e_p2p/shared.js +0 -184
  356. package/dest/e2e_token_contract/token_contract_test.d.ts +0 -42
  357. package/dest/e2e_token_contract/token_contract_test.d.ts.map +0 -1
  358. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +0 -194
  359. package/src/e2e_deploy_contract/deploy_test.ts +0 -85
  360. package/src/e2e_epochs/epochs_test.ts +0 -451
  361. package/src/e2e_l1_publisher/write_json.ts +0 -82
  362. package/src/e2e_nested_contract/nested_contract_test.ts +0 -75
  363. package/src/e2e_p2p/inactivity_slash_test.ts +0 -179
  364. package/src/e2e_p2p/shared.ts +0 -290
  365. /package/dest/{e2e_multi_validator/utils.js → composed/web3signer/multi_validator_keystore_utils.js} +0 -0
  366. /package/src/{e2e_multi_validator/utils.ts → composed/web3signer/multi_validator_keystore_utils.ts} +0 -0
@@ -0,0 +1,1041 @@
1
+ import type { InitialAccountData } from '@aztec/accounts/testing';
2
+ import type { Archiver } from '@aztec/archiver';
3
+ import { type AztecNodeConfig, AztecNodeService, createAztecNodeService } from '@aztec/aztec-node';
4
+ import { getAccountContractAddress } from '@aztec/aztec.js/account';
5
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
6
+ import { getTimestampRangeForEpoch } from '@aztec/aztec.js/block';
7
+ import { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
8
+ import { Fr } from '@aztec/aztec.js/fields';
9
+ import type { Logger } from '@aztec/aztec.js/log';
10
+ import { MerkleTreeId } from '@aztec/aztec.js/trees';
11
+ import type { Wallet } from '@aztec/aztec.js/wallet';
12
+ import type { CheatCodes } from '@aztec/aztec/testing';
13
+ import { EpochCache } from '@aztec/epoch-cache';
14
+ import { createExtendedL1Client } from '@aztec/ethereum/client';
15
+ import { DefaultL1ContractsConfig } from '@aztec/ethereum/config';
16
+ import { RollupContract } from '@aztec/ethereum/contracts';
17
+ import { Delayer, createDelayer, waitUntilL1Timestamp, wrapClientWithDelayer } from '@aztec/ethereum/l1-tx-utils';
18
+ import { ChainMonitor } from '@aztec/ethereum/test';
19
+ import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
20
+ import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
21
+ import { SecretValue } from '@aztec/foundation/config';
22
+ import { randomBytes } from '@aztec/foundation/crypto/random';
23
+ import { withLoggerBindings } from '@aztec/foundation/log/server';
24
+ import { retryUntil } from '@aztec/foundation/retry';
25
+ import { sleep } from '@aztec/foundation/sleep';
26
+ import { executeTimeout } from '@aztec/foundation/timer';
27
+ import { SpamContract } from '@aztec/noir-test-contracts.js/Spam';
28
+ import { TestContract } from '@aztec/noir-test-contracts.js/Test';
29
+ import { getMockPubSubP2PServiceFactory } from '@aztec/p2p/test-helpers';
30
+ import type { ProverNodeConfig } from '@aztec/prover-node';
31
+ import type { PXEConfig } from '@aztec/pxe/config';
32
+ import { type Sequencer, type SequencerClient, type SequencerEvents, SequencerState } from '@aztec/sequencer-client';
33
+ import { type BlockParameter, EthAddress } from '@aztec/stdlib/block';
34
+ import {
35
+ type L1RollupConstants,
36
+ getProofSubmissionDeadlineTimestamp,
37
+ getTimestampForSlot,
38
+ } from '@aztec/stdlib/epoch-helpers';
39
+ import { tryStop } from '@aztec/stdlib/interfaces/server';
40
+ import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
41
+
42
+ import { join } from 'path';
43
+ import type { Hex } from 'viem';
44
+ import { privateKeyToAccount } from 'viem/accounts';
45
+
46
+ import {
47
+ SCHNORR_HARDCODED_PRIVATE_KEY,
48
+ SchnorrHardcodedKeyAccountContract,
49
+ } from '../fixtures/schnorr_hardcoded_account_contract.js';
50
+ import { testSpan } from '../fixtures/timing.js';
51
+ import {
52
+ type EndToEndContext,
53
+ type SetupOptions,
54
+ createAndSyncProverNode,
55
+ getPrivateKeyFromIndex,
56
+ setup,
57
+ } from '../fixtures/utils.js';
58
+ import type { TestWallet } from '../test-wallet/test_wallet.js';
59
+
60
+ export const WORLD_STATE_CHECKPOINT_HISTORY = 2;
61
+ export const WORLD_STATE_BLOCK_CHECK_INTERVAL = 50;
62
+ export const ARCHIVER_POLL_INTERVAL = 50;
63
+ export const DEFAULT_L1_BLOCK_TIME = process.env.CI ? 12 : 8;
64
+
65
+ export type SingleNodeTestOpts = Partial<SetupOptions> & {
66
+ numberOfAccounts?: number;
67
+ pxeOpts?: Partial<PXEConfig>;
68
+ aztecSlotDurationInL1Slots?: number;
69
+ /** Skip creating/registering the hardcoded account during setup (for tests that handle accounts themselves). */
70
+ skipHardcodedAccount?: boolean;
71
+ /**
72
+ * Force the hardcoded-account fast-path even when an initial sequencer is running. Useful for
73
+ * tests with tight per-block gas budgets that can't fit a full account-deploy tx.
74
+ */
75
+ useHardcodedAccount?: boolean;
76
+ };
77
+
78
+ export type TrackedSequencerEvent = {
79
+ [K in keyof SequencerEvents]: Parameters<SequencerEvents[K]>[0] & {
80
+ type: K;
81
+ sequencerIndex: number;
82
+ validator: EthAddress;
83
+ };
84
+ }[keyof SequencerEvents];
85
+
86
+ /** A `block-proposed` sequencer event captured for the pipelining-offset assertion. */
87
+ export type BlockProposedEvent = { blockNumber: BlockNumber; slot: SlotNumber; buildSlot: SlotNumber };
88
+
89
+ /**
90
+ * The 36s-slot reorg cadence shared by every reorg/prune/HA test, regardless of single-node vs
91
+ * multi-validator topology: a 36s L2 slot, 8s blocks, and a 4-slot epoch. The two concrete reorg
92
+ * profiles ({@link FAST_REORG_TIMING}, {@link MULTI_VALIDATOR_REORG_TIMING}) extend this with their topology's L1
93
+ * slot duration and any extra knobs. Kept timing-only — `maxSpeedUpAttempts`, `cancelTxOnTimeout`, and
94
+ * `aztecProofSubmissionEpochs` encode per-test scenario intent and stay explicit at the call site.
95
+ */
96
+ export const REORG_TIMING_BASE = {
97
+ aztecSlotDuration: 36,
98
+ blockDurationMs: 8000,
99
+ aztecEpochDuration: 4,
100
+ } as const;
101
+
102
+ /**
103
+ * Timing-only profile shared by the fast single-node L1-reorg tests (`proving/optimistic`'s reorg
104
+ * cases and `l1-reorgs/`). Extends {@link REORG_TIMING_BASE} with mainnet-style 32-slot anvil epochs
105
+ * and a 4s L1 slot. Note: `ethereumSlotDuration` stays at 4 here (not unified to
106
+ * {@link MULTI_VALIDATOR_REORG_TIMING}'s 6) — at eth=6 the proof-submission-window timing in the
107
+ * proof-removal/proof-restore reorg assertions in `l1-reorgs/blocks` starves and times out, so the 4s
108
+ * L1 slot is required for the single-node reorg path. Tests that need a different epoch length (e.g. 8
109
+ * for the "with replacement" case) override `aztecEpochDuration` after the spread.
110
+ */
111
+ export const FAST_REORG_TIMING = {
112
+ ...REORG_TIMING_BASE,
113
+ ethereumSlotDuration: 4,
114
+ anvilSlotsInAnEpoch: 32,
115
+ } as const;
116
+
117
+ /**
118
+ * Timing-only profile naming the 36s/6s reorg-and-prune cadence copied verbatim across the
119
+ * multi-validator recovery and high-availability tests (`recovery/proposal_failure_recovery`,
120
+ * `recovery/equivocation_recovery`, `high-availability/ha_sync`,
121
+ * `high-availability/ha_checkpoint_handoff`). The multi-validator analogue of
122
+ * {@link FAST_REORG_TIMING}, adding the 0.5s attestation-propagation budget those committee tests
123
+ * need. Timing-only: committee size, `aztecProofSubmissionEpochs`, and the slasher block stay
124
+ * per-test. Spread BEFORE per-test overrides so a test can still bump e.g. `aztecEpochDuration`.
125
+ */
126
+ export const MULTI_VALIDATOR_REORG_TIMING = {
127
+ ...REORG_TIMING_BASE,
128
+ ethereumSlotDuration: 6,
129
+ attestationPropagationTime: 0.5,
130
+ } as const;
131
+
132
+ /**
133
+ * Timing-only profile naming the 36s/12s multi-validator block-production cadence copied across
134
+ * `block-production/` (`simple`, `high_tps`, `first_slot`, and `proof_boundary`). Uses
135
+ * `aztecSlotDurationInL1Slots: 3` rather than an explicit `aztecSlotDuration: 36` so the L2 slot stays
136
+ * coupled to `ethereumSlotDuration` if a test overrides eth. Deliberately omits
137
+ * `attestationPropagationTime` (per-scenario: default 2, 0.5, or 1) — set it per test. Spread BEFORE
138
+ * per-test overrides.
139
+ */
140
+ export const MULTI_VALIDATOR_BLOCK_PRODUCTION_TIMING = {
141
+ ethereumSlotDuration: 12,
142
+ aztecSlotDurationInL1Slots: 3,
143
+ blockDurationMs: 6000,
144
+ } as const;
145
+
146
+ /**
147
+ * Timing-only profile naming the 72s wide-slot multiple-blocks-per-slot cadence copied across the
148
+ * block-production and recovery tests (`block-production/`'s `setupBlockProductionWithProver`, `block-production/blob_promotion`,
149
+ * `recovery/pipeline_prune`). A-914:
150
+ * pipelined multiple-blocks-per-slot needs this 72s/12s cadence (not the tighter 36s/4s), otherwise non-proposer nodes hit
151
+ * `CheckpointNumberNotSequentialError` when the pipelined proposer races ahead of L1 confirmation. The
152
+ * larger `perBlockAllocationMultiplier` lets each of the several blocks per slot fit non-trivial txs.
153
+ * Spread BEFORE per-test overrides (e.g. `mockGossipSubNetworkLatency`, `maxTxsPerCheckpoint`).
154
+ */
155
+ export const WIDE_SLOT_TIMING = {
156
+ ethereumSlotDuration: 12,
157
+ aztecSlotDuration: 72,
158
+ blockDurationMs: 5500,
159
+ aztecEpochDuration: 4,
160
+ perBlockAllocationMultiplier: 8,
161
+ aztecTargetCommitteeSize: 3,
162
+ } as const;
163
+
164
+ /**
165
+ * Base class for the prod-sequencer single-node test topology: one node running the production
166
+ * sequencer with fast block times and short epochs, an optional fake-proof prover node, and the
167
+ * environment it runs in (in-proc anvil + L1 deploy). Owns node spawning
168
+ * (`createNonValidatorNode` / `createProverNode` incl. the mock-gossip `p2pServiceFactory` wiring,
169
+ * which is harmless with a single node), the `ChainMonitor`, and the epoch / proof-window / reorg
170
+ * waiters and assertion helpers shared by every test in the category.
171
+ *
172
+ * {@link MultiNodeTestContext} extends this with the N-validator topology (validator-node spawning,
173
+ * committee/proposal/attestation convergence helpers). Single-node-topology tests use this base
174
+ * directly from the sibling `single-node/` category.
175
+ */
176
+ export class SingleNodeTestContext {
177
+ public context!: EndToEndContext;
178
+ public l1Client!: ExtendedViemWalletClient;
179
+ public rollup!: RollupContract;
180
+ public constants!: L1RollupConstants;
181
+ public logger!: Logger;
182
+ public monitor!: ChainMonitor;
183
+ public epochCache!: EpochCache;
184
+ public proverDelayer!: Delayer;
185
+ public sequencerDelayer!: Delayer;
186
+
187
+ public proverNodes: AztecNodeService[] = [];
188
+ public nodes: AztecNodeService[] = [];
189
+
190
+ public epochDuration!: number;
191
+
192
+ public L1_BLOCK_TIME_IN_S!: number;
193
+ public L2_SLOT_DURATION_IN_S!: number;
194
+
195
+ public static async setup<T extends SingleNodeTestContext>(this: new () => T, opts: SingleNodeTestOpts = {}) {
196
+ const test = new this();
197
+ await test.setup(opts);
198
+ return test;
199
+ }
200
+
201
+ public static getSlotDurations(opts: SingleNodeTestOpts = {}) {
202
+ const envEthereumSlotDuration = process.env.L1_BLOCK_TIME
203
+ ? parseInt(process.env.L1_BLOCK_TIME)
204
+ : DEFAULT_L1_BLOCK_TIME;
205
+ const ethereumSlotDuration = opts.ethereumSlotDuration ?? envEthereumSlotDuration;
206
+ const aztecSlotDuration = opts.aztecSlotDuration ?? (opts.aztecSlotDurationInL1Slots ?? 2) * ethereumSlotDuration;
207
+ const aztecEpochDuration = opts.aztecEpochDuration ?? 6;
208
+ const aztecProofSubmissionEpochs = opts.aztecProofSubmissionEpochs ?? 1;
209
+ return {
210
+ ethereumSlotDuration,
211
+ aztecSlotDuration,
212
+ aztecEpochDuration,
213
+ aztecProofSubmissionEpochs,
214
+ };
215
+ }
216
+
217
+ public async setup(opts: SingleNodeTestOpts = {}) {
218
+ const { ethereumSlotDuration, aztecSlotDuration, aztecEpochDuration, aztecProofSubmissionEpochs } =
219
+ SingleNodeTestContext.getSlotDurations(opts);
220
+
221
+ // Auto-create a hardcoded account funded via genesis when:
222
+ // - skipInitialSequencer is set (no sequencer to deploy on-chain), or
223
+ // - useHardcodedAccount is explicitly requested (e.g. tight per-block gas budgets that
224
+ // can't fit a full account-deploy tx).
225
+ const useHardcodedAccount = (opts.skipInitialSequencer || opts.useHardcodedAccount) && !opts.skipHardcodedAccount;
226
+ let hardcodedAccountData: InitialAccountData | undefined;
227
+ if (useHardcodedAccount) {
228
+ hardcodedAccountData = await SingleNodeTestContext.getHardcodedAccountData(Fr.random(), Fr.random());
229
+ }
230
+
231
+ // Set up system without any account nor protocol contracts
232
+ // and with faster block times and shorter epochs.
233
+ const context = await setup(
234
+ useHardcodedAccount ? 0 : (opts.numberOfAccounts ?? 0),
235
+ {
236
+ automineL1Setup: true,
237
+ checkIntervalMs: 50,
238
+ archiverPollingIntervalMS: ARCHIVER_POLL_INTERVAL,
239
+ worldStateBlockCheckIntervalMS: WORLD_STATE_BLOCK_CHECK_INTERVAL,
240
+ aztecEpochDuration,
241
+ aztecSlotDuration,
242
+ ethereumSlotDuration,
243
+ aztecProofSubmissionEpochs,
244
+ aztecTargetCommitteeSize: opts.initialValidators?.length ?? 0,
245
+ minTxsPerBlock: 0,
246
+ realProofs: false,
247
+ startProverNode: true,
248
+ proverTestDelayMs: opts.proverTestDelayMs ?? 0,
249
+ proverId: EthAddress.fromNumber(1),
250
+ worldStateCheckpointHistory: WORLD_STATE_CHECKPOINT_HISTORY,
251
+ exitDelaySeconds: DefaultL1ContractsConfig.exitDelaySeconds,
252
+ slasherEnabled: false,
253
+ // `inboxLag: 2` is the intended value when running with pipelining (the production config
254
+ // default of 1 is a separate bug). Set before `...opts` so tests can still override.
255
+ inboxLag: 2,
256
+ ...opts,
257
+ ...(hardcodedAccountData ? { additionallyFundedAccounts: [hardcodedAccountData], numberOfAccounts: 0 } : {}),
258
+ },
259
+ // Use checkpointed chain tip for PXE by default to avoid issues with blocks being dropped due to pruned anchor blocks.
260
+ // Can be overridden via opts.pxeOpts.
261
+ { syncChainTip: 'checkpointed', ...opts.pxeOpts },
262
+ );
263
+
264
+ // Register the hardcoded account in PXE (local only, no on-chain deployment needed).
265
+ if (hardcodedAccountData) {
266
+ this.context = context;
267
+ await this.registerHardcodedAccount(hardcodedAccountData);
268
+ }
269
+
270
+ await this.hydrateFromContext(context);
271
+ }
272
+
273
+ /**
274
+ * Populates the context-derived state (tracked nodes, L1 client, rollup, epoch cache, chain
275
+ * monitor, delayers, timing constants) from an already-built {@link EndToEndContext}. Split out of
276
+ * {@link setup} so prover-specific subclasses that build the environment with their own bespoke
277
+ * `setup(...)` opts (e.g. `FullProverTest`) can still reuse the base node/teardown machinery
278
+ * without inheriting the base's default node config. Slot/epoch durations are read from the
279
+ * resolved `context.config` so the recorded constants match whatever the environment was deployed
280
+ * with.
281
+ */
282
+ protected async hydrateFromContext(context: EndToEndContext): Promise<void> {
283
+ this.context = context;
284
+
285
+ const { ethereumSlotDuration, aztecSlotDuration, aztecEpochDuration } = context.config;
286
+
287
+ this.L1_BLOCK_TIME_IN_S = ethereumSlotDuration;
288
+ this.L2_SLOT_DURATION_IN_S = aztecSlotDuration;
289
+
290
+ this.proverNodes = context.proverNode ? [context.proverNode] : [];
291
+ this.nodes = context.aztecNode ? [context.aztecNode as AztecNodeService] : [];
292
+ this.logger = context.logger;
293
+ this.l1Client = context.deployL1ContractsValues.l1Client;
294
+ this.rollup = RollupContract.getFromConfig(context.config);
295
+ this.epochCache = await EpochCache.create(this.rollup, context.config, { dateProvider: context.dateProvider });
296
+
297
+ // Loop that tracks L1 and L2 block numbers and logs whenever there's a new one.
298
+ this.monitor = new ChainMonitor(this.rollup, context.dateProvider, this.logger).start();
299
+
300
+ this.proverDelayer = context.proverDelayer!;
301
+ this.sequencerDelayer = context.sequencerDelayer!;
302
+
303
+ if ((context.proverNode && !this.proverDelayer) || (context.sequencer && !this.sequencerDelayer)) {
304
+ throw new Error(`Could not find prover or sequencer delayer`);
305
+ }
306
+
307
+ // Constants used for time calculation
308
+ this.epochDuration = aztecEpochDuration;
309
+ this.constants = {
310
+ epochDuration: aztecEpochDuration,
311
+ slotDuration: aztecSlotDuration,
312
+ l1StartBlock: await this.rollup.getL1StartBlock(),
313
+ l1GenesisTime: await this.rollup.getL1GenesisTime(),
314
+ ethereumSlotDuration,
315
+ proofSubmissionEpochs: Number(await this.rollup.getProofSubmissionEpochs()),
316
+ targetCommitteeSize: await this.rollup.getTargetCommitteeSize(),
317
+ rollupManaLimit: Number(await this.rollup.getManaLimit()),
318
+ };
319
+
320
+ this.logger.info(
321
+ `L2 genesis at L1 block ${this.constants.l1StartBlock} (timestamp ${this.constants.l1GenesisTime})`,
322
+ );
323
+ }
324
+
325
+ public async teardown() {
326
+ await this.monitor.stop();
327
+ await Promise.all(this.proverNodes.map(node => tryStop(node, this.logger)));
328
+ await Promise.all(this.nodes.map(node => tryStop(node, this.logger)));
329
+ await this.context.teardown();
330
+ }
331
+
332
+ /**
333
+ * Computes InitialAccountData for a SchnorrHardcodedKeyAccountContract.
334
+ * This contract has a hardcoded signing key and no initializer, so it can be used without
335
+ * on-chain deployment. Pass the returned data in `additionallyFundedAccounts` so the address
336
+ * gets funded with fee juice in genesis.
337
+ */
338
+ public static async getHardcodedAccountData(secret: Fr, salt: Fr): Promise<InitialAccountData> {
339
+ const contract = new SchnorrHardcodedKeyAccountContract();
340
+ const address = await getAccountContractAddress(contract, secret, salt);
341
+ const signingKey = SCHNORR_HARDCODED_PRIVATE_KEY;
342
+ return { secret, salt, signingKey, address };
343
+ }
344
+
345
+ /**
346
+ * Registers a SchnorrHardcodedKeyAccountContract in PXE. The account must have been funded
347
+ * at genesis (via getHardcodedAccountData). No on-chain deployment or block mining needed.
348
+ */
349
+ public async registerHardcodedAccount(accountData: InitialAccountData): Promise<AztecAddress> {
350
+ const contract = new SchnorrHardcodedKeyAccountContract();
351
+ const wallet = this.context.wallet;
352
+ const accountManager = await (wallet as TestWallet).createAccount({
353
+ secret: accountData.secret,
354
+ salt: accountData.salt,
355
+ contract,
356
+ });
357
+ this.context.accounts = [accountManager.address];
358
+ return accountManager.address;
359
+ }
360
+
361
+ public async createProverNode(opts: { dontStart?: boolean } & Partial<ProverNodeConfig> = {}) {
362
+ this.logger.warn('Creating and syncing a simulated prover node...');
363
+ const proverNodePrivateKey = this.getNextPrivateKey();
364
+ const proverIndex = this.proverNodes.length + 1;
365
+ const { mockGossipSubNetwork } = this.context;
366
+ const { proverNode } = await testSpan('setup:node', () =>
367
+ withLoggerBindings({ actor: `prover-${proverIndex}` }, () =>
368
+ createAndSyncProverNode(
369
+ proverNodePrivateKey,
370
+ {
371
+ ...this.context.config,
372
+ p2pEnabled: this.context.config.p2pEnabled || mockGossipSubNetwork !== undefined,
373
+ proverId: EthAddress.fromNumber(proverIndex),
374
+ dontStart: opts.dontStart,
375
+ ...opts,
376
+ },
377
+ {
378
+ dataDirectory: join(this.context.config.dataDirectory!, randomBytes(8).toString('hex')),
379
+ },
380
+ {
381
+ dateProvider: this.context.dateProvider,
382
+ p2pClientDeps: {
383
+ p2pServiceFactory: mockGossipSubNetwork
384
+ ? getMockPubSubP2PServiceFactory(mockGossipSubNetwork)
385
+ : undefined,
386
+ rpcTxProviders: [this.context.aztecNode],
387
+ },
388
+ },
389
+ {
390
+ genesis: this.context.genesis,
391
+ dontStart: opts.dontStart,
392
+ },
393
+ ),
394
+ ),
395
+ );
396
+ this.proverNodes.push(proverNode);
397
+ return proverNode;
398
+ }
399
+
400
+ public createNonValidatorNode(opts: Partial<AztecNodeConfig> = {}) {
401
+ this.logger.warn('Creating and syncing a node without a validator...');
402
+ return this.createNode({ ...opts, disableValidator: true });
403
+ }
404
+
405
+ protected async createNode(
406
+ opts: Partial<AztecNodeConfig> & {
407
+ dontStartSequencer?: boolean;
408
+ slashingProtectionDb?: SlashingProtectionDatabase;
409
+ } = {},
410
+ ) {
411
+ const nodeIndex = this.nodes.length + 1;
412
+ const actorPrefix = opts.disableValidator ? 'node' : 'validator';
413
+ const { mockGossipSubNetwork } = this.context;
414
+ const resolvedConfig = { ...this.context.config, ...opts };
415
+ const p2pEnabled = resolvedConfig.p2pEnabled || mockGossipSubNetwork !== undefined;
416
+ const p2pIp = resolvedConfig.p2pIp ?? (p2pEnabled ? '127.0.0.1' : undefined);
417
+ const node = await testSpan('setup:node', () =>
418
+ withLoggerBindings({ actor: `${actorPrefix}-${nodeIndex}` }, () =>
419
+ createAztecNodeService(
420
+ {
421
+ ...resolvedConfig,
422
+ dataDirectory: join(this.context.config.dataDirectory!, randomBytes(8).toString('hex')),
423
+ validatorPrivateKeys: opts.validatorPrivateKeys ?? new SecretValue([]),
424
+ nodeId: resolvedConfig.nodeId || `${actorPrefix}-${nodeIndex}`,
425
+ p2pEnabled,
426
+ p2pIp,
427
+ },
428
+ {
429
+ dateProvider: this.context.dateProvider,
430
+ p2pClientDeps: {
431
+ p2pServiceFactory: mockGossipSubNetwork
432
+ ? getMockPubSubP2PServiceFactory(mockGossipSubNetwork)
433
+ : undefined,
434
+ },
435
+ slashingProtectionDb: opts.slashingProtectionDb,
436
+ },
437
+ {
438
+ genesis: this.context.genesis,
439
+ ...opts,
440
+ },
441
+ ),
442
+ ),
443
+ );
444
+
445
+ this.nodes.push(node);
446
+ return node;
447
+ }
448
+
449
+ protected getNextPrivateKey(): Hex {
450
+ const key = getPrivateKeyFromIndex(this.nodes.length + this.proverNodes.length + 1);
451
+ return `0x${key!.toString('hex')}`;
452
+ }
453
+
454
+ /** Waits until the epoch begins (ie until the immediately previous L1 block is mined). */
455
+ public async waitUntilEpochStarts(epoch: number) {
456
+ const [start] = getTimestampRangeForEpoch(EpochNumber(epoch), this.constants);
457
+ this.logger.info(`Waiting until L1 timestamp ${start} is reached as the start of epoch ${epoch}`);
458
+ // Cover at least two full epochs of wall time so callers issuing the wait mid-epoch
459
+ // still have headroom — the prior `30 * epochDuration` mixed units (slots vs seconds)
460
+ // and timed out at 120s for configs whose epoch wall time is 144s+.
461
+ await testSpan('wait:epoch', () =>
462
+ waitUntilL1Timestamp(
463
+ this.l1Client,
464
+ start - BigInt(this.L1_BLOCK_TIME_IN_S),
465
+ undefined,
466
+ 2 * this.epochDuration * this.L2_SLOT_DURATION_IN_S,
467
+ ),
468
+ );
469
+ return start;
470
+ }
471
+
472
+ /**
473
+ * Waits until the next epoch boundary and returns that epoch's number. Anchors tests
474
+ * on a guaranteed-fresh epoch regardless of how much wall time `beforeEach` consumed —
475
+ * `waitUntilEpochStarts(1)` returns immediately when the chain has already advanced past
476
+ * slot 4, which under CI load can leave only seconds of the target epoch remaining.
477
+ *
478
+ * If the chain has more than two slots of headroom before the target boundary, warps
479
+ * the L1 clock to within two slots of the boundary instead of waiting in wall-clock.
480
+ * The two-slot tail is intentional — it lets the sequencer/builder settle so the first
481
+ * checkpoint of the target epoch lands correctly.
482
+ */
483
+ public async waitUntilNextEpochStarts(): Promise<EpochNumber> {
484
+ const { epoch } = this.epochCache.getEpochAndSlotNow();
485
+ const target = EpochNumber(Number(epoch) + 1);
486
+ const [targetTs] = getTimestampRangeForEpoch(target, this.constants);
487
+ const safeTs = targetTs - BigInt(2 * this.L2_SLOT_DURATION_IN_S);
488
+ const currentTs = BigInt(await this.context.cheatCodes.eth.lastBlockTimestamp());
489
+ if (currentTs < safeTs) {
490
+ this.logger.info(`Warping L1 from ${currentTs} to ${safeTs} (2 slots before epoch ${target})`);
491
+ await this.context.cheatCodes.eth.warp(Number(safeTs), { resetBlockInterval: true });
492
+ }
493
+ await this.waitUntilEpochStarts(Number(target));
494
+ return target;
495
+ }
496
+
497
+ /**
498
+ * Warps the L1 clock to within `leadSlots` slots of the start of `epoch`, then waits for that boundary in
499
+ * wall-clock, skipping the dead stretch where the chain just advances one L1 block per slot until an epoch
500
+ * ends. Anything the post-warp assertions depend on must already be produced before calling this — warping
501
+ * the tail away does not change what gets proven, and the shared `TestDateProvider` moves the
502
+ * prover/node/sequencer clocks together so the epoch finalizes right after the warp. The `leadSlots` tail
503
+ * (default 2) is left in real time so the sequencer can publish the epoch's final checkpoint before the
504
+ * boundary, and so any post-warp sampler observes an in-epoch slot rather than the epoch's last slot.
505
+ * Forward-only, so a no-op when already within `leadSlots` of the boundary.
506
+ */
507
+ public async warpToEpochStart(epoch: number, opts: { leadSlots?: number } = {}): Promise<bigint> {
508
+ const leadSlots = opts.leadSlots ?? 2;
509
+ const [targetTs] = getTimestampRangeForEpoch(EpochNumber(epoch), this.constants);
510
+ const safeTs = targetTs - BigInt(leadSlots * this.L2_SLOT_DURATION_IN_S);
511
+ const currentTs = BigInt(await this.context.cheatCodes.eth.lastBlockTimestamp());
512
+ if (currentTs < safeTs) {
513
+ this.logger.info(`Warping L1 from ${currentTs} to ${safeTs} (${leadSlots} slots before epoch ${epoch})`);
514
+ await this.context.cheatCodes.eth.warp(Number(safeTs), { resetBlockInterval: true });
515
+ }
516
+ return this.waitUntilEpochStarts(epoch);
517
+ }
518
+
519
+ /**
520
+ * Most of a proof-submission window is dead wall-clock time, so warp the L1 clock forward to `leadSlots`
521
+ * (default 2) L2 slots before the window's last slot. A subsequent
522
+ * {@link waitUntilLastSlotOfProofSubmissionWindow} then only sleeps out the few remaining real slots,
523
+ * leaving enough real time for any in-flight proving, pruning, and recovery to happen organically. Only
524
+ * warps forward, so it is a no-op when the chain is already within `leadSlots`+1 slots of the window end.
525
+ */
526
+ public async warpNearSubmissionWindowEnd(epoch: number, opts: { leadSlots?: number } = {}): Promise<void> {
527
+ const leadSlots = opts.leadSlots ?? 2;
528
+ const { slotDuration } = this.constants;
529
+ const deadline = getProofSubmissionDeadlineTimestamp(EpochNumber(epoch), this.constants);
530
+ // Mirror waitUntilLastSlotOfProofSubmissionWindow's target (one slot before the deadline).
531
+ const lastSlotTs = deadline - BigInt(slotDuration);
532
+ const target = lastSlotTs - BigInt(leadSlots * slotDuration);
533
+ const currentTs = BigInt(await this.context.cheatCodes.eth.lastBlockTimestamp());
534
+ if (currentTs < target) {
535
+ this.logger.warn(`Warping L1 to ${leadSlots} slots before end of epoch ${epoch} submission window`, {
536
+ currentTs,
537
+ target,
538
+ epoch,
539
+ });
540
+ await this.context.cheatCodes.eth.warp(Number(target), { resetBlockInterval: true });
541
+ }
542
+ }
543
+
544
+ /** Waits until the given checkpoint number is mined. */
545
+ public async waitUntilCheckpointNumber(target: CheckpointNumber, timeout = 120) {
546
+ await testSpan('wait:checkpoint', () =>
547
+ retryUntil(
548
+ () => Promise.resolve(target <= this.monitor.checkpointNumber),
549
+ `Wait until checkpoint ${target}`,
550
+ timeout,
551
+ 0.1,
552
+ ),
553
+ );
554
+ }
555
+
556
+ /** Waits until the given checkpoint number is marked as proven. */
557
+ public async waitUntilProvenCheckpointNumber(target: CheckpointNumber, timeout = 120) {
558
+ await testSpan('wait:proven-checkpoint', () =>
559
+ retryUntil(
560
+ () => Promise.resolve(target <= this.monitor.provenCheckpointNumber),
561
+ `Wait proven checkpoint ${target}`,
562
+ timeout,
563
+ 0.1,
564
+ ),
565
+ );
566
+ return this.monitor.provenCheckpointNumber;
567
+ }
568
+
569
+ /** Waits until the last slot of the proof submission window for a given epoch. */
570
+ public async waitUntilLastSlotOfProofSubmissionWindow(epochNumber: number | bigint) {
571
+ const deadline = getProofSubmissionDeadlineTimestamp(EpochNumber.fromBigInt(BigInt(epochNumber)), this.constants);
572
+ const oneSlotBefore = deadline - BigInt(this.constants.slotDuration);
573
+ const date = new Date(Number(oneSlotBefore) * 1000);
574
+ this.logger.info(`Waiting until last slot of submission window for epoch ${epochNumber} at ${date}`, {
575
+ oneSlotBefore,
576
+ });
577
+ // Use a timeout that accounts for the full proof submission window
578
+ const proofSubmissionWindowDuration =
579
+ this.constants.proofSubmissionEpochs * this.epochDuration * this.L2_SLOT_DURATION_IN_S;
580
+ await testSpan('wait:proof-window', () =>
581
+ waitUntilL1Timestamp(this.l1Client, oneSlotBefore, undefined, proofSubmissionWindowDuration * 2),
582
+ );
583
+ }
584
+
585
+ /**
586
+ * Timestamp one L1 block before L2 `slot` begins — the instant a pipelined proposer starts
587
+ * building for that slot. `opts.lead` overrides the default one-L1-block lead (e.g. when a test
588
+ * needs an extra block-duration margin to guarantee sub-slot 1 is reachable).
589
+ */
590
+ public buildWindowTimestampForSlot(slot: SlotNumber, opts: { lead?: number } = {}): bigint {
591
+ const lead = opts.lead ?? this.L1_BLOCK_TIME_IN_S;
592
+ return getTimestampForSlot(slot, this.constants) - BigInt(lead);
593
+ }
594
+
595
+ /**
596
+ * Warps the L1 clock to the build window of `slot` (one L1 block before the slot begins) with
597
+ * `resetBlockInterval`, so a pipelined proposer engages cleanly when its sequencer starts.
598
+ * @returns The slot warped to.
599
+ */
600
+ public async warpToBuildWindowForSlot(slot: SlotNumber): Promise<SlotNumber> {
601
+ const target = this.buildWindowTimestampForSlot(slot);
602
+ this.logger.info(`Warping L1 to build window of slot ${slot}`, { slot, target });
603
+ await this.context.cheatCodes.eth.warp(Number(target), { resetBlockInterval: true });
604
+ return slot;
605
+ }
606
+
607
+ /**
608
+ * Waits (in wall-clock, without warping) until the L1 clock reaches the build window of `slot`.
609
+ * For production-sequencer tests that can't warp. `opts.lead` extends the lead beyond the default
610
+ * one L1 block; `opts.timeout` bounds the wait (defaults to three L2 slots).
611
+ * @returns The slot waited for.
612
+ */
613
+ public async waitForBuildWindowForSlot(
614
+ slot: SlotNumber,
615
+ opts: { lead?: number; timeout?: number } = {},
616
+ ): Promise<SlotNumber> {
617
+ const target = this.buildWindowTimestampForSlot(slot, { lead: opts.lead });
618
+ const timeout = opts.timeout ?? this.L2_SLOT_DURATION_IN_S * 3;
619
+ this.logger.info(`Waiting until L1 reaches build window of slot ${slot}`, { slot, target });
620
+ await testSpan('wait:slot', () => waitUntilL1Timestamp(this.l1Client, target, undefined, timeout));
621
+ return slot;
622
+ }
623
+
624
+ /** Waits for the aztec node to sync to the target block number. */
625
+ public async waitForNodeToSync(blockNumber: BlockNumber, type: 'proven' | 'finalized' | 'historic') {
626
+ const waitTime = ARCHIVER_POLL_INTERVAL + WORLD_STATE_BLOCK_CHECK_INTERVAL;
627
+ await testSpan('wait:node-sync', async () => {
628
+ let synched = false;
629
+ while (!synched) {
630
+ await sleep(waitTime);
631
+ const [syncState, tips] = await Promise.all([
632
+ this.context.aztecNode.getWorldStateSyncStatus(),
633
+ await this.context.aztecNode.getChainTips(),
634
+ ]);
635
+ this.logger.info(`Wait for node synch ${blockNumber} ${type}`, { blockNumber, type, syncState, tips });
636
+ if (type === 'proven') {
637
+ synched = tips.proven.block.number >= blockNumber && syncState.latestBlockNumber >= blockNumber;
638
+ } else if (type === 'finalized') {
639
+ synched = syncState.finalizedBlockNumber >= blockNumber;
640
+ } else {
641
+ synched = syncState.oldestHistoricBlockNumber >= blockNumber;
642
+ }
643
+ }
644
+ });
645
+ }
646
+
647
+ /**
648
+ * Waits until every prover node has submitted a proof for `epoch` (of length `epochLength`
649
+ * checkpoints) on L1. Polls `rollup.getHasSubmittedProof` for each prover registered in
650
+ * {@link proverNodes}.
651
+ */
652
+ public async waitForAllProversToSubmit(
653
+ epoch: EpochNumber,
654
+ epochLength: number,
655
+ opts: { timeout?: number } = {},
656
+ ): Promise<void> {
657
+ const proverIds = this.proverNodes.map(node => node.getProverNode()!.getProverId());
658
+ await testSpan('wait:proof-submitted', () =>
659
+ retryUntil(
660
+ async () => {
661
+ const haveSubmitted = await Promise.all(
662
+ proverIds.map(proverId => this.rollup.getHasSubmittedProof(epoch, epochLength, proverId)),
663
+ );
664
+ this.logger.info(`Proof submissions: ${haveSubmitted.join(', ')}`);
665
+ return haveSubmitted.every(submitted => submitted);
666
+ },
667
+ 'Provers have submitted proofs',
668
+ opts.timeout ?? 120,
669
+ ),
670
+ );
671
+ }
672
+
673
+ /** Registers the SpamContract on the given wallet. */
674
+ public async registerSpamContract(wallet: Wallet, salt = Fr.ZERO) {
675
+ const instance = await getContractInstanceFromInstantiationParams(SpamContract.artifact, {
676
+ constructorArgs: [],
677
+ constructorArtifact: undefined,
678
+ salt,
679
+ publicKeys: undefined,
680
+ deployer: undefined,
681
+ });
682
+ await wallet.registerContract(instance, SpamContract.artifact);
683
+ return SpamContract.at(instance.address, wallet);
684
+ }
685
+
686
+ /** Registers the TestContract on the given wallet. */
687
+ public async registerTestContract(wallet: Wallet, salt = Fr.ZERO) {
688
+ const instance = await getContractInstanceFromInstantiationParams(TestContract.artifact, {
689
+ constructorArgs: [],
690
+ constructorArtifact: undefined,
691
+ salt,
692
+ publicKeys: undefined,
693
+ deployer: undefined,
694
+ });
695
+ await wallet.registerContract(instance, TestContract.artifact);
696
+ return TestContract.at(instance.address, wallet);
697
+ }
698
+
699
+ /** Creates an L1 client using a fresh account with funds from anvil, with a tx delayer already set up. */
700
+ public async createL1Client() {
701
+ const rawClient = createExtendedL1Client(
702
+ [...this.l1Client.chain.rpcUrls.default.http],
703
+ privateKeyToAccount(this.getNextPrivateKey()),
704
+ this.l1Client.chain,
705
+ );
706
+ const delayer = createDelayer(this.context.dateProvider, { ethereumSlotDuration: this.L1_BLOCK_TIME_IN_S }, {});
707
+ const client = wrapClientWithDelayer(rawClient, delayer);
708
+ expect(await client.getBalance({ address: client.account.address })).toBeGreaterThan(0n);
709
+ return { client, delayer };
710
+ }
711
+
712
+ /** Verifies whether the given block number is found on the aztec node. */
713
+ public async verifyHistoricBlock(blockNumber: BlockParameter, expectedSuccess: boolean) {
714
+ // We use `findLeavesIndexes` here, but could use any function that queries the world-state
715
+ // at a particular block, so we know whether that historic block is available or has been
716
+ // pruned. Note that `getBlock` would not work here, since it only hits the archiver.
717
+ const result = await this.context.aztecNode
718
+ .findLeavesIndexes(blockNumber, MerkleTreeId.NULLIFIER_TREE, [Fr.ZERO])
719
+ .then(_ => true)
720
+ .catch(_ => false);
721
+ expect(result).toBe(expectedSuccess);
722
+ }
723
+
724
+ /**
725
+ * Verifies that at least one checkpoint has `targetBlockCount` blocks and that block numbering is
726
+ * contiguous within every checkpoint (MBPS validation).
727
+ *
728
+ * Two optional wait modes (both poll before reading checkpoints):
729
+ * - `opts.wait`: waits until some checkpoint reaches `targetBlockCount` blocks (the proposed-tip
730
+ * MBPS setup case), and
731
+ * - `opts.targetBlock`: waits until the archiver's checkpointed tip reaches that block number
732
+ * (the pipeline-prune recovery case).
733
+ *
734
+ * Reads from `opts.archiver` when given (e.g. a specific validator node's block source); otherwise
735
+ * from the initial node's archiver.
736
+ * @returns The number of the first checkpoint with at least `targetBlockCount` blocks.
737
+ */
738
+ public async assertMultipleBlocksPerSlot(
739
+ targetBlockCount: number,
740
+ opts: { wait?: boolean; targetBlock?: BlockNumber; archiver?: Archiver; timeout?: number } = {},
741
+ ): Promise<CheckpointNumber> {
742
+ const archiver = opts.archiver ?? ((this.context.aztecNode as AztecNodeService).getBlockSource() as Archiver);
743
+ const waitTimeout = opts.timeout ?? this.L2_SLOT_DURATION_IN_S * 3;
744
+
745
+ if (opts.targetBlock !== undefined) {
746
+ const targetBlock = opts.targetBlock;
747
+ await retryUntil(
748
+ async () => {
749
+ const checkpointed = await archiver.getBlockNumber({ tag: 'checkpointed' });
750
+ return checkpointed !== undefined && checkpointed >= targetBlock;
751
+ },
752
+ `archiver checkpointed block ${targetBlock}`,
753
+ 10,
754
+ 0.1,
755
+ );
756
+ }
757
+
758
+ if (opts.wait) {
759
+ await retryUntil(
760
+ async () => {
761
+ const found = await archiver.getCheckpoints({ from: CheckpointNumber(1), limit: 50 });
762
+ return found.some(pc => pc.checkpoint.blocks.length >= targetBlockCount) || undefined;
763
+ },
764
+ `checkpoint with at least ${targetBlockCount} blocks`,
765
+ waitTimeout,
766
+ 0.5,
767
+ );
768
+ }
769
+
770
+ const checkpoints = await archiver.getCheckpoints({ from: CheckpointNumber(1), limit: 50 });
771
+
772
+ this.logger.warn(`Retrieved ${checkpoints.length} checkpoints from archiver`, {
773
+ checkpoints: checkpoints.map(pc => pc.checkpoint.getStats()),
774
+ });
775
+
776
+ let expectedBlockNumber = checkpoints[0].checkpoint.blocks[0].number;
777
+ let multiBlockCheckpointNumber: CheckpointNumber | undefined;
778
+
779
+ for (const checkpoint of checkpoints) {
780
+ const blockCount = checkpoint.checkpoint.blocks.length;
781
+ if (blockCount >= targetBlockCount && multiBlockCheckpointNumber === undefined) {
782
+ multiBlockCheckpointNumber = checkpoint.checkpoint.number;
783
+ }
784
+
785
+ this.logger.verbose(`Checkpoint ${checkpoint.checkpoint.number} has ${blockCount} blocks`, {
786
+ checkpoint: checkpoint.checkpoint.getStats(),
787
+ });
788
+
789
+ for (let i = 0; i < blockCount; i++) {
790
+ const block = checkpoint.checkpoint.blocks[i];
791
+ expect(block.indexWithinCheckpoint).toBe(i);
792
+ expect(block.checkpointNumber).toBe(checkpoint.checkpoint.number);
793
+ expect(block.number).toBe(expectedBlockNumber);
794
+ expectedBlockNumber++;
795
+ }
796
+ }
797
+
798
+ expect(multiBlockCheckpointNumber).toBeDefined();
799
+ return multiBlockCheckpointNumber!;
800
+ }
801
+
802
+ /**
803
+ * Asserts pipelining by comparing the build slot (from block-proposed events) against the
804
+ * submission slot (from block headers). With pipelining, the block is built in slot N but its
805
+ * header carries submission slot N+1. Also checks each block's coinbase matches the expected
806
+ * proposer for its submission slot. Reads checkpoints from `archiver` (typically a validator
807
+ * node's block source).
808
+ */
809
+ public async assertProposerPipelining(
810
+ archiver: Archiver,
811
+ blockProposedEvents: BlockProposedEvent[],
812
+ logger: Logger,
813
+ ): Promise<void> {
814
+ const checkpoints = await archiver.getCheckpoints({ from: CheckpointNumber(1), limit: 50 });
815
+ const allBlocks = checkpoints.flatMap(pc => pc.checkpoint.blocks);
816
+
817
+ logger.warn(`assertProposerPipelining: ${allBlocks.length} blocks, ${blockProposedEvents.length} events`, {
818
+ blockNumbers: allBlocks.map(b => b.number),
819
+ eventBlockNumbers: blockProposedEvents.map(e => e.blockNumber),
820
+ });
821
+
822
+ let foundPipelining = false;
823
+
824
+ for (const block of allBlocks) {
825
+ const headerSlot = block.header.globalVariables.slotNumber; // submission slot (N+1)
826
+ const coinbase = block.header.globalVariables.coinbase;
827
+
828
+ // Find the block-proposed event for this block (use Number() for safe comparison)
829
+ const event = blockProposedEvents.find(e => Number(e.blockNumber) === Number(block.number));
830
+ // if there is no event, then it was probably block number one - which was proposed in setup
831
+ if (!event) {
832
+ continue;
833
+ }
834
+
835
+ const buildSlot = event.buildSlot; // build slot (N)
836
+
837
+ // Verify the pipelining offset: block built in slot N, submitted in slot N+1
838
+ expect(Number(headerSlot)).toBe(Number(buildSlot) + 1);
839
+ foundPipelining = true;
840
+
841
+ // Verify coinbase matches the expected proposer for the submission slot
842
+ const expectedProposer = await this.rollup.getProposerAt(getTimestampForSlot(headerSlot, this.constants));
843
+ expect(coinbase).toEqual(expectedProposer);
844
+
845
+ logger.warn(`Block ${block.number}: buildSlot=${buildSlot}, submissionSlot=${headerSlot}, coinbase=${coinbase}`, {
846
+ blockNumber: block.number,
847
+ buildSlot,
848
+ headerSlot,
849
+ coinbase: coinbase.toString(),
850
+ expectedProposer: expectedProposer.toString(),
851
+ });
852
+ }
853
+
854
+ expect(foundPipelining).toBe(true);
855
+ logger.warn(`Pipelining assertion passed for ${allBlocks.length} blocks`);
856
+ }
857
+
858
+ public watchSequencerEvents(
859
+ sequencers: SequencerClient[],
860
+ getMetadata: (i: number) => Record<string, any> = () => ({}),
861
+ additionalFailEventKeys: (keyof SequencerEvents)[] = [],
862
+ ) {
863
+ const stateChanges: TrackedSequencerEvent[] = [];
864
+ const failEvents: TrackedSequencerEvent[] = [];
865
+
866
+ // Note we do not include the 'block-tx-count-check-failed' event here, since it is fine if we dont build
867
+ // due to lack of txs available.
868
+ const failEventsKeys: (keyof SequencerEvents)[] = [
869
+ 'block-build-failed',
870
+ 'checkpoint-publish-failed',
871
+ 'proposer-rollup-check-failed',
872
+ 'checkpoint-error',
873
+ 'checkpoint-publish-failed',
874
+ 'header-validation-failed',
875
+ 'pipelined-checkpoint-discarded',
876
+ ...additionalFailEventKeys,
877
+ ];
878
+
879
+ const makeEvent = (
880
+ i: number,
881
+ eventName: keyof SequencerEvents,
882
+ args: Parameters<SequencerEvents[keyof SequencerEvents]>[0],
883
+ ) =>
884
+ ({
885
+ ...args,
886
+ type: eventName,
887
+ sequencerIndex: i + 2,
888
+ ...getMetadata(i),
889
+ }) as TrackedSequencerEvent;
890
+
891
+ sequencers.forEach((sequencer, i) => {
892
+ const sequencerIndex = i + 2;
893
+ sequencer.getSequencer().on('state-changed', (args: Parameters<SequencerEvents['state-changed']>[0]) => {
894
+ const noisyStates = [SequencerState.IDLE, SequencerState.PROPOSER_CHECK, SequencerState.SYNCHRONIZING];
895
+ if (!noisyStates.includes(args.newState)) {
896
+ const evt = makeEvent(i, 'state-changed', args);
897
+ stateChanges.push(evt);
898
+ this.logger.verbose(
899
+ `Sequencer ${sequencerIndex} transitioned from state ${args.oldState} to state ${args.newState}`,
900
+ evt,
901
+ );
902
+ }
903
+ });
904
+ failEventsKeys.forEach(eventName => {
905
+ sequencer.getSequencer().on(eventName, (args: Parameters<SequencerEvents[typeof eventName]>[0]) => {
906
+ // Skip benign block-build-failed events where the builder rejected the block because it
907
+ // could not collect enough valid txs. This is the same "not enough txs" case as
908
+ // block-tx-count-check-failed (which is already excluded above), just detected after we
909
+ // started processing txs rather than before.
910
+ if (eventName === 'block-build-failed' && (args as { reason?: string }).reason === 'Insufficient valid txs') {
911
+ return;
912
+ }
913
+ const evt = makeEvent(i, eventName, args);
914
+ failEvents.push(evt);
915
+ this.logger.error(`Failed event ${eventName} from sequencer ${sequencerIndex}`, undefined, evt);
916
+ });
917
+ });
918
+ });
919
+
920
+ return { failEvents, stateChanges };
921
+ }
922
+
923
+ /**
924
+ * Resolves with the event args the first time `sequencer` emits `event` with args matching
925
+ * `match`. Rejects after `opts.timeout` ms (default 60s). Wraps the
926
+ * `executeTimeout(signal => new Promise(...))` one-shot subscription boilerplate, cleaning up
927
+ * the listener on both the resolve and the abort paths.
928
+ */
929
+ public waitForSequencerEvent<E extends keyof SequencerEvents>(
930
+ sequencer: Sequencer,
931
+ event: E,
932
+ match: (args: Parameters<SequencerEvents[E]>[0]) => boolean = () => true,
933
+ opts: { timeout?: number } = {},
934
+ ): Promise<Parameters<SequencerEvents[E]>[0]> {
935
+ const timeout = opts.timeout ?? 60_000;
936
+ return testSpan('wait:sequencer-state', () =>
937
+ executeTimeout(
938
+ signal =>
939
+ new Promise<Parameters<SequencerEvents[E]>[0]>(resolve => {
940
+ const listener = (args: Parameters<SequencerEvents[E]>[0]) => {
941
+ if (match(args)) {
942
+ sequencer.off(event, listener as SequencerEvents[E]);
943
+ resolve(args);
944
+ }
945
+ };
946
+ signal.addEventListener('abort', () => sequencer.off(event, listener as SequencerEvents[E]), {
947
+ once: true,
948
+ });
949
+ sequencer.on(event, listener as SequencerEvents[E]);
950
+ }),
951
+ timeout,
952
+ `wait for sequencer event ${String(event)}`,
953
+ ),
954
+ );
955
+ }
956
+
957
+ /** Returns the {@link SequencerClient} of each given node, throwing if any node has no sequencer. */
958
+ public getSequencers(nodes: AztecNodeService[]): SequencerClient[] {
959
+ return nodes.map(node => {
960
+ const sequencer = node.getSequencer();
961
+ if (!sequencer) {
962
+ throw new Error('Node has no sequencer');
963
+ }
964
+ return sequencer;
965
+ });
966
+ }
967
+
968
+ /** Starts the sequencer on each given node in parallel. */
969
+ public async startSequencers(nodes: AztecNodeService[]): Promise<void> {
970
+ await Promise.all(this.getSequencers(nodes).map(sequencer => sequencer.start()));
971
+ }
972
+
973
+ /**
974
+ * Resolves once `sequencer` is in `state`, returning immediately if it is already there. Use to
975
+ * flush in-flight work (e.g. wait for `IDLE` so pending L1 publishes have been issued) before
976
+ * sampling chain state. Builds on {@link waitForSequencerEvent} for the not-yet-there path.
977
+ */
978
+ public async waitForSequencerState(
979
+ sequencer: Sequencer,
980
+ state: SequencerState,
981
+ opts: { timeout?: number } = {},
982
+ ): Promise<void> {
983
+ if (sequencer.status().state === state) {
984
+ return;
985
+ }
986
+ await this.waitForSequencerEvent(sequencer, 'state-changed', args => args.newState === state, opts);
987
+ }
988
+
989
+ public assertNoFailuresFromSequencers(failEvents: TrackedSequencerEvent[]) {
990
+ if (failEvents.length > 0) {
991
+ this.logger.error(`Failed events from sequencers`, failEvents);
992
+ }
993
+ expect(failEvents).toEqual([]);
994
+ }
995
+
996
+ /**
997
+ * Warps the L1 clock to `target` with every given node's sequencer paused, then resumes them
998
+ * (pass `restart: false` to leave them paused, e.g. until some clock-driven effect is confirmed).
999
+ *
1000
+ * Warping the shared date provider under live sequencers interrupts whatever iteration is mid-build,
1001
+ * producing spurious `block-build-failed` / `checkpoint-error` events and dropped checkpoints. The
1002
+ * sequencers are therefore paused first: the poll loop halts and the in-flight iteration, its pending L1
1003
+ * submission, and any pending fallback vote all finish untouched before the warp, so nothing fires with a
1004
+ * stale slot afterwards. Pausing leaves the validator clients (and their slashing-protection stores) and
1005
+ * publishers running, so a later {@link SequencerClient.start} cleanly resumes; archivers, provers, and
1006
+ * the chain monitor keep running throughout, so clock-driven effects of the warp (e.g. an orphan-block
1007
+ * prune) still fire.
1008
+ *
1009
+ * The warp is performed here (rather than via a caller-supplied callback) so it happens only after the
1010
+ * pause has drained. Draining can take several slots, so a `target` computed before the pause may already
1011
+ * lie in the past by the time the sequencers are down. The warp is therefore skipped when the L1 clock has
1012
+ * already reached or passed `target` — `evm_setNextBlockTimestamp` rejects a non-advancing timestamp, so
1013
+ * warping there would throw "timestamp in the past".
1014
+ */
1015
+ public async warpWithSequencersPaused(
1016
+ nodes: AztecNodeService[],
1017
+ cheatCodes: CheatCodes,
1018
+ target: bigint,
1019
+ opts: { restart?: boolean } = {},
1020
+ ): Promise<void> {
1021
+ const sequencers = this.getSequencers(nodes);
1022
+ await testSpan('warp:sequencers-paused', async () => {
1023
+ this.logger.warn(`Pausing ${sequencers.length} sequencers before warp`);
1024
+ await Promise.all(sequencers.map(sequencer => sequencer.pause()));
1025
+ const currentTs = BigInt(await cheatCodes.eth.lastBlockTimestamp());
1026
+ if (currentTs < target) {
1027
+ this.logger.warn(`Warping L1 to ${target} with all sequencers paused`, { currentTs, target });
1028
+ await cheatCodes.eth.warp(Number(target), { resetBlockInterval: true });
1029
+ } else {
1030
+ this.logger.verbose(`Skipping warp: L1 clock ${currentTs} already at or past target ${target}`, {
1031
+ currentTs,
1032
+ target,
1033
+ });
1034
+ }
1035
+ if (opts.restart ?? true) {
1036
+ this.logger.warn(`Resuming ${sequencers.length} sequencers after warp`);
1037
+ await Promise.all(sequencers.map(sequencer => sequencer.start()));
1038
+ }
1039
+ });
1040
+ }
1041
+ }