@aztec/end-to-end 0.0.1-commit.a89ec08 → 0.0.1-commit.aa0c64f

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 (318) hide show
  1. package/README.md +215 -27
  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/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.d.ts +1 -1
  8. package/dest/automine/contracts/fixtures/storage_proof_fixture.d.ts.map +1 -0
  9. package/dest/automine/delivery/interactive_handshake_responder.d.ts +48 -0
  10. package/dest/automine/delivery/interactive_handshake_responder.d.ts.map +1 -0
  11. package/dest/automine/delivery/interactive_handshake_responder.js +76 -0
  12. package/dest/automine/delivery/onchain_delivery_harness.d.ts +19 -0
  13. package/dest/automine/delivery/onchain_delivery_harness.d.ts.map +1 -0
  14. package/dest/automine/delivery/onchain_delivery_harness.js +141 -0
  15. package/dest/automine/token/blacklist_token_contract_test.d.ts +49 -0
  16. package/dest/automine/token/blacklist_token_contract_test.d.ts.map +1 -0
  17. package/dest/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.js +23 -36
  18. package/dest/automine/token/token_contract_test.d.ts +40 -0
  19. package/dest/automine/token/token_contract_test.d.ts.map +1 -0
  20. package/dest/{e2e_token_contract → automine/token}/token_contract_test.js +24 -39
  21. package/dest/automine/token/token_test_helpers.d.ts +73 -0
  22. package/dest/automine/token/token_test_helpers.d.ts.map +1 -0
  23. package/dest/automine/token/token_test_helpers.js +97 -0
  24. package/dest/bench/client_flows/benchmark.d.ts +15 -1
  25. package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
  26. package/dest/bench/client_flows/benchmark.js +19 -0
  27. package/dest/bench/client_flows/client_flows_benchmark.d.ts +5 -5
  28. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  29. package/dest/bench/client_flows/client_flows_benchmark.js +53 -51
  30. package/dest/bench/client_flows/data_extractor.js +1 -0
  31. package/dest/bench/utils.d.ts +3 -3
  32. package/dest/bench/utils.d.ts.map +1 -1
  33. package/dest/bench/utils.js +97 -6
  34. package/dest/composed/ha/ha_full_setup.d.ts +77 -0
  35. package/dest/composed/ha/ha_full_setup.d.ts.map +1 -0
  36. package/dest/composed/ha/ha_full_setup.js +383 -0
  37. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts +12 -0
  38. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts.map +1 -0
  39. package/dest/fixtures/e2e_prover_test.d.ts +15 -11
  40. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  41. package/dest/fixtures/e2e_prover_test.js +56 -40
  42. package/dest/fixtures/elu_monitor.d.ts +21 -0
  43. package/dest/fixtures/elu_monitor.d.ts.map +1 -0
  44. package/dest/fixtures/elu_monitor.js +102 -0
  45. package/dest/fixtures/fixtures.d.ts +79 -1
  46. package/dest/fixtures/fixtures.d.ts.map +1 -1
  47. package/dest/fixtures/fixtures.js +80 -0
  48. package/dest/fixtures/get_bb_config.d.ts +1 -1
  49. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  50. package/dest/fixtures/get_bb_config.js +5 -5
  51. package/dest/fixtures/ha_setup.d.ts +4 -4
  52. package/dest/fixtures/ha_setup.d.ts.map +1 -1
  53. package/dest/fixtures/ha_setup.js +5 -2
  54. package/dest/fixtures/index.d.ts +2 -1
  55. package/dest/fixtures/index.d.ts.map +1 -1
  56. package/dest/fixtures/index.js +1 -0
  57. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts +25 -0
  58. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts.map +1 -0
  59. package/dest/fixtures/schnorr_hardcoded_account_contract.js +37 -0
  60. package/dest/fixtures/setup.d.ts +81 -41
  61. package/dest/fixtures/setup.d.ts.map +1 -1
  62. package/dest/fixtures/setup.js +289 -198
  63. package/dest/fixtures/setup_p2p_test.d.ts +10 -6
  64. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  65. package/dest/fixtures/setup_p2p_test.js +11 -11
  66. package/dest/fixtures/standard_contracts_genesis.d.ts +16 -0
  67. package/dest/fixtures/standard_contracts_genesis.d.ts.map +1 -0
  68. package/dest/fixtures/standard_contracts_genesis.js +25 -0
  69. package/dest/fixtures/timing.d.ts +42 -0
  70. package/dest/fixtures/timing.d.ts.map +1 -0
  71. package/dest/fixtures/timing.js +72 -0
  72. package/dest/fixtures/token_utils.d.ts +22 -4
  73. package/dest/fixtures/token_utils.d.ts.map +1 -1
  74. package/dest/fixtures/token_utils.js +23 -6
  75. package/dest/fixtures/utils.d.ts +2 -2
  76. package/dest/fixtures/utils.d.ts.map +1 -1
  77. package/dest/fixtures/utils.js +1 -1
  78. package/dest/fixtures/wait_helpers.d.ts +135 -0
  79. package/dest/fixtures/wait_helpers.d.ts.map +1 -0
  80. package/dest/fixtures/wait_helpers.js +154 -0
  81. package/dest/forward-compatibility/wallet_service.js +3 -3
  82. package/dest/install_legacy_contracts.d.cts +10 -0
  83. package/dest/install_legacy_contracts.d.cts.map +1 -0
  84. package/dest/legacy-jest-resolver.d.cts +1 -1
  85. package/dest/legacy-jest-resolver.d.cts.map +1 -1
  86. package/dest/multi-node/block-production/setup.d.ts +97 -0
  87. package/dest/multi-node/block-production/setup.d.ts.map +1 -0
  88. package/dest/multi-node/block-production/setup.js +158 -0
  89. package/dest/multi-node/governance/setup.d.ts +67 -0
  90. package/dest/multi-node/governance/setup.d.ts.map +1 -0
  91. package/dest/multi-node/governance/setup.js +126 -0
  92. package/dest/multi-node/multi_node_test_context.d.ts +212 -0
  93. package/dest/multi-node/multi_node_test_context.d.ts.map +1 -0
  94. package/dest/multi-node/multi_node_test_context.js +347 -0
  95. package/dest/multi-node/slashing/inactivity_setup.d.ts +27 -0
  96. package/dest/multi-node/slashing/inactivity_setup.d.ts.map +1 -0
  97. package/dest/multi-node/slashing/inactivity_setup.js +111 -0
  98. package/dest/multi-node/slashing/setup.d.ts +167 -0
  99. package/dest/multi-node/slashing/setup.d.ts.map +1 -0
  100. package/dest/multi-node/slashing/setup.js +275 -0
  101. package/dest/{e2e_p2p → p2p}/p2p_network.d.ts +20 -11
  102. package/dest/p2p/p2p_network.d.ts.map +1 -0
  103. package/dest/{e2e_p2p → p2p}/p2p_network.js +83 -39
  104. package/dest/p2p/reqresp/utils.d.ts +19 -0
  105. package/dest/p2p/reqresp/utils.d.ts.map +1 -0
  106. package/dest/{e2e_p2p → p2p}/reqresp/utils.js +45 -29
  107. package/dest/p2p/shared.d.ts +72 -0
  108. package/dest/p2p/shared.d.ts.map +1 -0
  109. package/dest/p2p/shared.js +212 -0
  110. package/dest/shared/cross_chain_test_harness.d.ts +6 -4
  111. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  112. package/dest/shared/cross_chain_test_harness.js +33 -21
  113. package/dest/shared/gas_portal_test_harness.d.ts +8 -5
  114. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  115. package/dest/shared/gas_portal_test_harness.js +24 -12
  116. package/dest/shared/jest_setup.js +41 -1
  117. package/dest/shared/submit-transactions.d.ts +1 -1
  118. package/dest/shared/submit-transactions.d.ts.map +1 -1
  119. package/dest/shared/submit-transactions.js +12 -5
  120. package/dest/shared/timing_env.d.js +5 -0
  121. package/dest/shared/timing_env.js +365 -0
  122. package/dest/shared/uniswap_l1_l2.d.ts +1 -1
  123. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  124. package/dest/shared/uniswap_l1_l2.js +50 -37
  125. package/dest/shared/wait_for_l1_to_l2_message.d.ts +13 -0
  126. package/dest/shared/wait_for_l1_to_l2_message.d.ts.map +1 -0
  127. package/dest/shared/wait_for_l1_to_l2_message.js +10 -0
  128. package/dest/simulators/lending_simulator.d.ts +10 -3
  129. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  130. package/dest/simulators/lending_simulator.js +24 -12
  131. package/dest/simulators/token_simulator.js +1 -1
  132. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts +75 -0
  133. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts.map +1 -0
  134. package/dest/single-node/cross-chain/cross_chain_messaging_test.js +209 -0
  135. package/dest/single-node/cross-chain/message_test_helpers.d.ts +38 -0
  136. package/dest/single-node/cross-chain/message_test_helpers.d.ts.map +1 -0
  137. package/dest/single-node/cross-chain/message_test_helpers.js +70 -0
  138. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.d.ts +1 -1
  139. package/dest/single-node/fees/bridging_race.notest.d.ts.map +1 -0
  140. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.js +17 -4
  141. package/dest/single-node/fees/fees_test.d.ts +95 -0
  142. package/dest/single-node/fees/fees_test.d.ts.map +1 -0
  143. package/dest/single-node/fees/fees_test.js +347 -0
  144. package/dest/single-node/l1-reorgs/setup.d.ts +42 -0
  145. package/dest/single-node/l1-reorgs/setup.d.ts.map +1 -0
  146. package/dest/single-node/l1-reorgs/setup.js +57 -0
  147. package/dest/single-node/partial-proofs/setup.d.ts +5 -0
  148. package/dest/single-node/partial-proofs/setup.d.ts.map +1 -0
  149. package/dest/single-node/partial-proofs/setup.js +5 -0
  150. package/dest/single-node/proving/setup.d.ts +5 -0
  151. package/dest/single-node/proving/setup.d.ts.map +1 -0
  152. package/dest/single-node/proving/setup.js +5 -0
  153. package/dest/single-node/recovery/setup.d.ts +5 -0
  154. package/dest/single-node/recovery/setup.d.ts.map +1 -0
  155. package/dest/single-node/recovery/setup.js +5 -0
  156. package/dest/single-node/setup.d.ts +49 -0
  157. package/dest/single-node/setup.d.ts.map +1 -0
  158. package/dest/single-node/setup.js +56 -0
  159. package/dest/single-node/single_node_test_context.d.ts +374 -0
  160. package/dest/single-node/single_node_test_context.d.ts.map +1 -0
  161. package/dest/single-node/single_node_test_context.js +847 -0
  162. package/dest/spartan/setup_test_wallets.d.ts +1 -1
  163. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  164. package/dest/spartan/setup_test_wallets.js +84 -50
  165. package/dest/spartan/tx_metrics.d.ts +27 -4
  166. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  167. package/dest/spartan/tx_metrics.js +106 -21
  168. package/dest/spartan/utils/config.d.ts +10 -30
  169. package/dest/spartan/utils/config.d.ts.map +1 -1
  170. package/dest/spartan/utils/config.js +3 -1
  171. package/dest/spartan/utils/index.d.ts +2 -1
  172. package/dest/spartan/utils/index.d.ts.map +1 -1
  173. package/dest/spartan/utils/index.js +2 -0
  174. package/dest/spartan/utils/nodes.d.ts +4 -5
  175. package/dest/spartan/utils/nodes.d.ts.map +1 -1
  176. package/dest/spartan/utils/nodes.js +11 -11
  177. package/dest/spartan/utils/pod_logs.d.ts +25 -0
  178. package/dest/spartan/utils/pod_logs.d.ts.map +1 -0
  179. package/dest/spartan/utils/pod_logs.js +74 -0
  180. package/dest/test-wallet/test_wallet.d.ts +25 -4
  181. package/dest/test-wallet/test_wallet.d.ts.map +1 -1
  182. package/dest/test-wallet/test_wallet.js +107 -36
  183. package/dest/test-wallet/utils.d.ts +38 -3
  184. package/dest/test-wallet/utils.d.ts.map +1 -1
  185. package/dest/test-wallet/utils.js +65 -10
  186. package/dest/test-wallet/wallet_worker_script.js +12 -4
  187. package/dest/test-wallet/worker_wallet.d.ts +6 -5
  188. package/dest/test-wallet/worker_wallet.d.ts.map +1 -1
  189. package/dest/test-wallet/worker_wallet.js +10 -4
  190. package/dest/test-wallet/worker_wallet_schema.d.ts +3 -273
  191. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -1
  192. package/dest/test-wallet/worker_wallet_schema.js +15 -2
  193. package/package.json +49 -47
  194. package/src/automine/README.md +60 -0
  195. package/src/automine/automine_test_context.ts +153 -0
  196. package/src/automine/delivery/interactive_handshake_responder.ts +125 -0
  197. package/src/automine/delivery/onchain_delivery_harness.ts +213 -0
  198. package/src/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.ts +24 -44
  199. package/src/{e2e_token_contract → automine/token}/token_contract_test.ts +25 -48
  200. package/src/automine/token/token_test_helpers.ts +138 -0
  201. package/src/bench/client_flows/benchmark.ts +21 -0
  202. package/src/bench/client_flows/client_flows_benchmark.ts +104 -74
  203. package/src/bench/client_flows/data_extractor.ts +1 -0
  204. package/src/bench/utils.ts +110 -6
  205. package/src/composed/ha/ha_full_setup.ts +466 -0
  206. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  207. package/src/fixtures/e2e_prover_test.ts +73 -63
  208. package/src/fixtures/elu_monitor.ts +126 -0
  209. package/src/fixtures/fixtures.ts +100 -0
  210. package/src/fixtures/get_bb_config.ts +7 -6
  211. package/src/fixtures/ha_setup.ts +11 -5
  212. package/src/fixtures/index.ts +1 -0
  213. package/src/fixtures/schnorr_hardcoded_account_contract.ts +49 -0
  214. package/src/fixtures/setup.ts +360 -254
  215. package/src/fixtures/setup_p2p_test.ts +15 -11
  216. package/src/fixtures/standard_contracts_genesis.ts +28 -0
  217. package/src/fixtures/timing.ts +97 -0
  218. package/src/fixtures/token_utils.ts +40 -8
  219. package/src/fixtures/utils.ts +2 -3
  220. package/src/fixtures/wait_helpers.ts +333 -0
  221. package/src/forward-compatibility/wallet_service.ts +6 -4
  222. package/src/guides/up_quick_start.sh +5 -2
  223. package/src/infra/README.md +12 -0
  224. package/src/install_legacy_contracts.cjs +75 -0
  225. package/src/legacy-jest-resolver.cjs +25 -48
  226. package/src/multi-node/README.md +96 -0
  227. package/src/multi-node/block-production/setup.ts +272 -0
  228. package/src/multi-node/governance/setup.ts +172 -0
  229. package/src/multi-node/multi_node_test_context.ts +447 -0
  230. package/src/multi-node/slashing/inactivity_setup.ts +139 -0
  231. package/src/multi-node/slashing/setup.ts +433 -0
  232. package/src/p2p/README.md +78 -0
  233. package/src/{e2e_p2p → p2p}/p2p_network.ts +96 -51
  234. package/src/{e2e_p2p → p2p}/reqresp/utils.ts +56 -28
  235. package/src/p2p/shared.ts +329 -0
  236. package/src/shared/cross_chain_test_harness.ts +36 -17
  237. package/src/shared/gas_portal_test_harness.ts +32 -14
  238. package/src/shared/jest_setup.ts +51 -1
  239. package/src/shared/submit-transactions.ts +13 -8
  240. package/src/shared/timing_env.d.mts +39 -0
  241. package/src/shared/timing_env.mjs +363 -0
  242. package/src/shared/uniswap_l1_l2.ts +80 -43
  243. package/src/shared/wait_for_l1_to_l2_message.ts +23 -0
  244. package/src/simulators/lending_simulator.ts +28 -14
  245. package/src/simulators/token_simulator.ts +1 -1
  246. package/src/single-node/README.md +66 -0
  247. package/src/single-node/cross-chain/cross_chain_messaging_test.ts +302 -0
  248. package/src/single-node/cross-chain/message_test_helpers.ts +125 -0
  249. package/src/{e2e_fees → single-node/fees}/bridging_race.notest.ts +19 -5
  250. package/src/{e2e_fees → single-node/fees}/fees_test.ts +176 -70
  251. package/src/single-node/l1-reorgs/setup.ts +93 -0
  252. package/src/single-node/partial-proofs/setup.ts +8 -0
  253. package/src/single-node/proving/setup.ts +15 -0
  254. package/src/single-node/recovery/setup.ts +8 -0
  255. package/src/single-node/setup.ts +63 -0
  256. package/src/single-node/single_node_test_context.ts +1058 -0
  257. package/src/spartan/setup_test_wallets.ts +87 -47
  258. package/src/spartan/tx_metrics.ts +108 -24
  259. package/src/spartan/utils/config.ts +2 -0
  260. package/src/spartan/utils/index.ts +3 -0
  261. package/src/spartan/utils/nodes.ts +17 -12
  262. package/src/spartan/utils/pod_logs.ts +99 -0
  263. package/src/test-wallet/test_wallet.ts +108 -33
  264. package/src/test-wallet/utils.ts +104 -11
  265. package/src/test-wallet/wallet_worker_script.ts +11 -5
  266. package/src/test-wallet/worker_wallet.ts +16 -14
  267. package/src/test-wallet/worker_wallet_schema.ts +4 -3
  268. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +0 -56
  269. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +0 -1
  270. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +0 -47
  271. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +0 -1
  272. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +0 -129
  273. package/dest/e2e_deploy_contract/deploy_test.d.ts +0 -37
  274. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +0 -1
  275. package/dest/e2e_deploy_contract/deploy_test.js +0 -50
  276. package/dest/e2e_epochs/epochs_test.d.ts +0 -104
  277. package/dest/e2e_epochs/epochs_test.d.ts.map +0 -1
  278. package/dest/e2e_epochs/epochs_test.js +0 -389
  279. package/dest/e2e_fees/bridging_race.notest.d.ts.map +0 -1
  280. package/dest/e2e_fees/fees_test.d.ts +0 -88
  281. package/dest/e2e_fees/fees_test.d.ts.map +0 -1
  282. package/dest/e2e_fees/fees_test.js +0 -255
  283. package/dest/e2e_l1_publisher/write_json.d.ts +0 -11
  284. package/dest/e2e_l1_publisher/write_json.d.ts.map +0 -1
  285. package/dest/e2e_l1_publisher/write_json.js +0 -56
  286. package/dest/e2e_multi_validator/utils.d.ts +0 -12
  287. package/dest/e2e_multi_validator/utils.d.ts.map +0 -1
  288. package/dest/e2e_nested_contract/nested_contract_test.d.ts +0 -26
  289. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +0 -1
  290. package/dest/e2e_nested_contract/nested_contract_test.js +0 -54
  291. package/dest/e2e_p2p/inactivity_slash_test.d.ts +0 -31
  292. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +0 -1
  293. package/dest/e2e_p2p/inactivity_slash_test.js +0 -137
  294. package/dest/e2e_p2p/p2p_network.d.ts.map +0 -1
  295. package/dest/e2e_p2p/reqresp/utils.d.ts +0 -22
  296. package/dest/e2e_p2p/reqresp/utils.d.ts.map +0 -1
  297. package/dest/e2e_p2p/shared.d.ts +0 -78
  298. package/dest/e2e_p2p/shared.d.ts.map +0 -1
  299. package/dest/e2e_p2p/shared.js +0 -235
  300. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +0 -2
  301. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +0 -1
  302. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +0 -1
  303. package/dest/e2e_token_contract/token_contract_test.d.ts +0 -44
  304. package/dest/e2e_token_contract/token_contract_test.d.ts.map +0 -1
  305. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +0 -193
  306. package/src/e2e_deploy_contract/deploy_test.ts +0 -85
  307. package/src/e2e_epochs/epochs_test.ts +0 -499
  308. package/src/e2e_l1_publisher/write_json.ts +0 -77
  309. package/src/e2e_nested_contract/nested_contract_test.ts +0 -75
  310. package/src/e2e_p2p/inactivity_slash_test.ts +0 -180
  311. package/src/e2e_p2p/shared.ts +0 -385
  312. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.js +0 -0
  313. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.js +0 -0
  314. /package/dest/{e2e_multi_validator/utils.js → composed/web3signer/multi_validator_keystore_utils.js} +0 -0
  315. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof.json +0 -0
  316. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.ts +0 -0
  317. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.ts +0 -0
  318. /package/src/{e2e_multi_validator/utils.ts → composed/web3signer/multi_validator_keystore_utils.ts} +0 -0
@@ -0,0 +1,172 @@
1
+ import { RollupContract } from '@aztec/ethereum/contracts';
2
+ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
3
+ import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
4
+ import { SlotNumber } from '@aztec/foundation/branded-types';
5
+ import { retryUntil } from '@aztec/foundation/retry';
6
+ import { GovernanceAbi, GovernanceProposerAbi } from '@aztec/l1-artifacts';
7
+
8
+ import { jest } from '@jest/globals';
9
+ import { type GetContractReturnType, encodeFunctionData, getAddress, getContract } from 'viem';
10
+
11
+ import type { MultiNodeTestContext } from '../multi_node_test_context.js';
12
+
13
+ jest.setTimeout(1000 * 60 * 10);
14
+
15
+ /**
16
+ * The shortened block-time timing the governance tests run on: a 12s L2 slot, 4s L1 slot, and a long
17
+ * proof-submission window so unproven blocks are never pruned (the committee runs no prover). Spread into
18
+ * a {@link MultiNodeTestContext.setup} call alongside {@link MOCK_GOSSIP_MULTI_VALIDATOR_OPTS} and
19
+ * `initialValidators`.
20
+ */
21
+ export const GOVERNANCE_TIMING = {
22
+ aztecSlotDuration: 12,
23
+ ethereumSlotDuration: 4,
24
+ aztecProofSubmissionEpochs: 640,
25
+ } as const;
26
+
27
+ /** The current round leader's payload and its signal count, as observed by {@link GovernanceTestDriver.govInfo}. */
28
+ type GovRoundState = { round: bigint; leaderVotes: bigint };
29
+
30
+ /**
31
+ * Wraps the L1 governance-proposer / governance / rollup contracts and the round-driving mechanics shared by
32
+ * the governance suites (`add_rollup`, `upgrade_governance_proposer`): warping to round boundaries, polling
33
+ * round state, waiting for signal quorum, submitting the round winner, and voting a proposal through to
34
+ * executable. Scenario-specific payload construction, node signaling, and post-execution assertions stay in
35
+ * each test.
36
+ */
37
+ export interface GovernanceTestDriver {
38
+ governanceProposer: GetContractReturnType<typeof GovernanceProposerAbi, ExtendedViemWalletClient>;
39
+ governance: GetContractReturnType<typeof GovernanceAbi, ExtendedViemWalletClient>;
40
+ rollup: RollupContract;
41
+ roundSize: bigint;
42
+ emperor: ExtendedViemWalletClient['account'];
43
+ /** Sends a 1-wei self-transfer to mine a fresh L1 block, so warped time takes effect. */
44
+ waitL1Block: () => Promise<void>;
45
+ /** Reads the current round's leading payload and its signal count. */
46
+ govInfo: () => Promise<GovRoundState>;
47
+ /** Warps L1 to the start of the next governance-proposer round. */
48
+ warpToNextRound: () => Promise<void>;
49
+ /** Polls once per L2 slot until the round leader reaches quorum, returning the round state at that point. */
50
+ waitForQuorum: (quorumSize: bigint, timeoutSeconds: number) => Promise<GovRoundState>;
51
+ /** Submits the winning payload of `round` to the governance proposer, creating the on-chain proposal. */
52
+ submitRoundWinner: (round: bigint) => Promise<void>;
53
+ /**
54
+ * Warps past the proposal's voting delay, casts a yes vote (asserting it lands), then warps past the
55
+ * voting duration and execution delay so the proposal becomes executable.
56
+ */
57
+ voteToExecutable: () => Promise<void>;
58
+ }
59
+
60
+ /** Builds a {@link GovernanceTestDriver} over the context's L1 governance contracts. */
61
+ export async function createGovernanceTestDriver(
62
+ test: MultiNodeTestContext,
63
+ l1TxUtils: L1TxUtils,
64
+ ): Promise<GovernanceTestDriver> {
65
+ const { l1Client, l1ContractAddresses } = test.context.deployL1ContractsValues;
66
+ const rollupAddress = l1ContractAddresses.rollupAddress.toString();
67
+
68
+ const governanceProposer = getContract({
69
+ address: getAddress(l1ContractAddresses.governanceProposerAddress.toString()),
70
+ abi: GovernanceProposerAbi,
71
+ client: l1Client,
72
+ });
73
+ const governance = getContract({
74
+ address: getAddress(l1ContractAddresses.governanceAddress.toString()),
75
+ abi: GovernanceAbi,
76
+ client: l1Client,
77
+ });
78
+ const rollup = new RollupContract(l1Client, l1ContractAddresses.rollupAddress);
79
+ const roundSize = await governanceProposer.read.ROUND_SIZE();
80
+ const emperor = l1Client.account;
81
+
82
+ const waitL1Block = async () => {
83
+ await l1TxUtils.sendAndMonitorTransaction({ to: emperor.address, value: 1n });
84
+ };
85
+
86
+ const govInfo = async (): Promise<GovRoundState> => {
87
+ const bn = await test.context.cheatCodes.eth.blockNumber();
88
+ const slot = await rollup.getSlotNumber();
89
+ const round = await governanceProposer.read.computeRound([BigInt(slot)]);
90
+ const info = await governanceProposer.read.getRoundData([rollupAddress, round]);
91
+ const leaderVotes = await governanceProposer.read.signalCount([rollupAddress, round, info.payloadWithMostSignals]);
92
+ test.logger.info(
93
+ `Governance stats for round ${round} (Slot: ${slot}, BN: ${bn}). Leader: ${info.payloadWithMostSignals} have ${leaderVotes} signals`,
94
+ );
95
+ return { round, leaderVotes };
96
+ };
97
+
98
+ const warpToNextRound = async () => {
99
+ const currentSlot = await rollup.getSlotNumber();
100
+ const nextRoundSlot = SlotNumber.fromBigInt((BigInt(currentSlot) / roundSize) * roundSize + roundSize);
101
+ const nextRoundTimestamp = await rollup.getTimestampForSlot(nextRoundSlot);
102
+ await test.context.cheatCodes.eth.warp(Number(nextRoundTimestamp));
103
+ };
104
+
105
+ const waitForQuorum = (quorumSize: bigint, timeoutSeconds: number) =>
106
+ retryUntil(
107
+ async () => {
108
+ const data = await govInfo();
109
+ return data.leaderVotes >= quorumSize ? data : undefined;
110
+ },
111
+ 'governance leader reaches quorum',
112
+ timeoutSeconds,
113
+ GOVERNANCE_TIMING.aztecSlotDuration,
114
+ );
115
+
116
+ const submitRoundWinner = async (round: bigint) => {
117
+ await l1TxUtils.sendAndMonitorTransaction({
118
+ to: governanceProposer.address,
119
+ data: encodeFunctionData({ abi: GovernanceProposerAbi, functionName: 'submitRoundWinner', args: [round] }),
120
+ });
121
+ };
122
+
123
+ const voteToExecutable = async () => {
124
+ const proposal = await governance.read.getProposal([0n]);
125
+
126
+ const timeToActive = proposal.creation + proposal.config.votingDelay;
127
+ await test.context.cheatCodes.eth.warp(Number(timeToActive + 1n));
128
+ await waitL1Block();
129
+
130
+ const voteTx = await rollup.vote(l1TxUtils, 0n);
131
+ expect(voteTx.receipt?.status).toBe('success');
132
+
133
+ const timeToExecutable = timeToActive + proposal.config.votingDuration + proposal.config.executionDelay + 1n;
134
+ await test.context.cheatCodes.eth.warp(Number(timeToExecutable));
135
+ await waitL1Block();
136
+ };
137
+
138
+ return {
139
+ governanceProposer,
140
+ governance,
141
+ rollup,
142
+ roundSize,
143
+ emperor,
144
+ waitL1Block,
145
+ govInfo,
146
+ warpToNextRound,
147
+ waitForQuorum,
148
+ submitRoundWinner,
149
+ voteToExecutable,
150
+ };
151
+ }
152
+
153
+ /**
154
+ * Drives one governance round to an executable proposal: waits for the signaled payload to reach quorum,
155
+ * warps to the next round, submits the round winner, then votes the resulting proposal through its voting
156
+ * and execution delays. Returns the round state observed at quorum; the caller performs the scenario-specific
157
+ * execution and assertions.
158
+ */
159
+ export async function driveGovernanceRound(
160
+ driver: GovernanceTestDriver,
161
+ opts: { quorumTimeoutSeconds: number },
162
+ ): Promise<{ govData: GovRoundState }> {
163
+ const quorumSize = await driver.governanceProposer.read.QUORUM_SIZE();
164
+ const govData = await driver.waitForQuorum(quorumSize, opts.quorumTimeoutSeconds);
165
+ await driver.warpToNextRound();
166
+ await driver.waitL1Block();
167
+ await driver.submitRoundWinner(govData.round);
168
+ await driver.voteToExecutable();
169
+ return { govData };
170
+ }
171
+
172
+ export { jest };
@@ -0,0 +1,447 @@
1
+ import type { AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
2
+ import { EthAddress } from '@aztec/aztec.js/addresses';
3
+ import { Fr } from '@aztec/aztec.js/fields';
4
+ import { RollupContract, type SlashingProposerContract } from '@aztec/ethereum/contracts';
5
+ import type { Operator } from '@aztec/ethereum/deploy-aztec-l1-contracts';
6
+ import type { ViemClient } from '@aztec/ethereum/types';
7
+ import { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
8
+ import { times } from '@aztec/foundation/collection';
9
+ import { SecretValue } from '@aztec/foundation/config';
10
+ import { retryUntil } from '@aztec/foundation/retry';
11
+ import { bufferToHex } from '@aztec/foundation/string';
12
+ import { SlasherAbi } from '@aztec/l1-artifacts';
13
+ import type { L2Tips } from '@aztec/stdlib/block';
14
+ import type { AztecNode, BlockResponse } from '@aztec/stdlib/interfaces/client';
15
+ import type { Offense } from '@aztec/stdlib/slashing';
16
+ import { createSharedSlashingProtectionDb } from '@aztec/validator-ha-signer/factory';
17
+ import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
18
+
19
+ import { type GetContractReturnType, getAddress, getContract } from 'viem';
20
+ import { privateKeyToAccount } from 'viem/accounts';
21
+
22
+ import { testSpan } from '../fixtures/timing.js';
23
+ import { getPrivateKeyFromIndex } from '../fixtures/utils.js';
24
+ import { NO_REORG_SUBMISSION_EPOCHS } from '../single-node/setup.js';
25
+ import {
26
+ SingleNodeTestContext,
27
+ type SingleNodeTestOpts,
28
+ type TrackedSequencerEvent,
29
+ } from '../single-node/single_node_test_context.js';
30
+
31
+ export { NO_REORG_SUBMISSION_EPOCHS, PROVING_SLOT_TIMING } from '../single-node/setup.js';
32
+ export {
33
+ WORLD_STATE_CHECKPOINT_HISTORY,
34
+ WORLD_STATE_BLOCK_CHECK_INTERVAL,
35
+ ARCHIVER_POLL_INTERVAL,
36
+ DEFAULT_L1_BLOCK_TIME,
37
+ REORG_TIMING_BASE,
38
+ FAST_REORG_TIMING,
39
+ MULTI_VALIDATOR_REORG_TIMING,
40
+ MULTI_VALIDATOR_BLOCK_PRODUCTION_TIMING,
41
+ WIDE_SLOT_TIMING,
42
+ type BlockProposedEvent,
43
+ type TrackedSequencerEvent,
44
+ type SingleNodeTestOpts,
45
+ } from '../single-node/single_node_test_context.js';
46
+
47
+ /** Options for {@link MultiNodeTestContext.setup} — superset of {@link SingleNodeTestOpts}. */
48
+ export type MultiNodeTestOpts = SingleNodeTestOpts;
49
+
50
+ /** A registered validator with its on-chain operator data and the L1 private key its node signs with. */
51
+ export type RegisteredValidator = Operator & { privateKey: `0x${string}` };
52
+
53
+ /**
54
+ * Builds the deterministic validator set used across the multi-validator tests: `count` validators
55
+ * keyed from `getPrivateKeyFromIndex(i + 3)` (indices 0..2 are reserved for the setup account,
56
+ * bootstrap node, and prover node, matching the `P2PNetworkTest` convention). This replaces the
57
+ * `times(N, i => ({ attester, withdrawer, privateKey, bn254SecretKey }))` block copy-pasted in every
58
+ * direct multi-validator test.
59
+ */
60
+ export function buildMockGossipValidators(count: number): RegisteredValidator[] {
61
+ return times(count, i => {
62
+ const privateKey = bufferToHex(getPrivateKeyFromIndex(i + 3)!);
63
+ const attester = EthAddress.fromString(privateKeyToAccount(privateKey).address);
64
+ return { attester, withdrawer: attester, privateKey, bn254SecretKey: new SecretValue(Fr.random().toBigInt()) };
65
+ });
66
+ }
67
+
68
+ /**
69
+ * The shared `setup` cluster for the multi-validator tests that run a tight committee on the
70
+ * in-memory mock-gossip bus without a prover (block-production / recovery tests). Spread into the `setup`
71
+ * call alongside `initialValidators` (from {@link buildMockGossipValidators}). Tests that want a
72
+ * prover (MBPS / HA-sync) leave `startProverNode` explicit rather than adopting this preset's `false`.
73
+ */
74
+ export const MOCK_GOSSIP_MULTI_VALIDATOR_OPTS = {
75
+ mockGossipSubNetwork: true,
76
+ skipInitialSequencer: true,
77
+ startProverNode: false,
78
+ aztecProofSubmissionEpochs: NO_REORG_SUBMISSION_EPOCHS,
79
+ numberOfAccounts: 0,
80
+ } as const;
81
+
82
+ /**
83
+ * The `setup` preset for a slasher-enabled committee on the in-memory mock-gossip bus, used by the
84
+ * offense-detection tests (`slashing/`). Mirrors {@link MOCK_GOSSIP_MULTI_VALIDATOR_OPTS} but turns
85
+ * the slasher on; spread alongside `initialValidators` (from {@link buildMockGossipValidators}) and
86
+ * the per-test slashing-round/penalty config.
87
+ */
88
+ export const SLASHER_ENABLED_MULTI_VALIDATOR_OPTS = {
89
+ mockGossipSubNetwork: true,
90
+ skipInitialSequencer: true,
91
+ slasherEnabled: true,
92
+ } as const;
93
+
94
+ /** The slasher and slashing-proposer L1 contracts a slashing test interacts with. */
95
+ export type SlashingContracts = {
96
+ rollup: RollupContract;
97
+ slasherContract: GetContractReturnType<typeof SlasherAbi, ViemClient>;
98
+ slashingProposer: SlashingProposerContract | undefined;
99
+ };
100
+
101
+ /** The per-offense penalty knobs a slashing test tunes; all default to a single `unit`. */
102
+ export type SlashingPenalties = {
103
+ slashInactivityPenalty: bigint;
104
+ slashDataWithholdingPenalty: bigint;
105
+ slashBroadcastedInvalidBlockPenalty: bigint;
106
+ slashBroadcastedInvalidCheckpointProposalPenalty: bigint;
107
+ slashDuplicateProposalPenalty: bigint;
108
+ slashDuplicateAttestationPenalty: bigint;
109
+ slashProposeInvalidAttestationsPenalty: bigint;
110
+ slashProposeDescendantOfCheckpointWithInvalidAttestationsPenalty: bigint;
111
+ slashAttestInvalidCheckpointProposalPenalty: bigint;
112
+ slashUnknownPenalty: bigint;
113
+ };
114
+
115
+ /** The names of every per-offense penalty knob, in declaration order. */
116
+ const SLASHING_PENALTY_KEYS: (keyof SlashingPenalties)[] = [
117
+ 'slashInactivityPenalty',
118
+ 'slashDataWithholdingPenalty',
119
+ 'slashBroadcastedInvalidBlockPenalty',
120
+ 'slashBroadcastedInvalidCheckpointProposalPenalty',
121
+ 'slashDuplicateProposalPenalty',
122
+ 'slashDuplicateAttestationPenalty',
123
+ 'slashProposeInvalidAttestationsPenalty',
124
+ 'slashProposeDescendantOfCheckpointWithInvalidAttestationsPenalty',
125
+ 'slashAttestInvalidCheckpointProposalPenalty',
126
+ 'slashUnknownPenalty',
127
+ ];
128
+
129
+ /**
130
+ * Returns every per-offense slashing penalty set to `unit` (default `1e14` — small enough not to
131
+ * kick a validator out). Spread alongside the slashing-round/quorum config in a slashing test's
132
+ * `setup`.
133
+ */
134
+ export function defaultSlashingPenalties(unit: bigint = BigInt(1e14)): SlashingPenalties {
135
+ return Object.fromEntries(SLASHING_PENALTY_KEYS.map(key => [key, unit])) as SlashingPenalties;
136
+ }
137
+
138
+ /**
139
+ * Returns the penalties with only `offense` set to `unit` and every other offense zeroed out, so a
140
+ * test isolates a single slashing offense. Names the test's intent (which offense is under test) and
141
+ * replaces the ~9-line manual zero-out block.
142
+ */
143
+ export function withOnlyOffense(offense: keyof SlashingPenalties, unit: bigint = BigInt(1e14)): SlashingPenalties {
144
+ return Object.fromEntries(SLASHING_PENALTY_KEYS.map(key => [key, key === offense ? unit : 0n])) as SlashingPenalties;
145
+ }
146
+
147
+ /** One HA pair: its two member nodes, the two shared validator keys, and the per-node coinbases. */
148
+ export type HaPairNodes = {
149
+ nodes: [AztecNodeService, AztecNodeService];
150
+ privateKeys: [`0x${string}`, `0x${string}`];
151
+ coinbases: [EthAddress, EthAddress];
152
+ };
153
+
154
+ /**
155
+ * Stands up two HA pairs from the first four registered validators: nodes[0]/nodes[1] share keys
156
+ * pk1+pk2, nodes[2]/nodes[3] share pk3+pk4. Each pair shares an in-memory slashing-protection DB (so
157
+ * only one peer signs per duty) and each node gets a distinct coinbase. Encapsulates the ~40-line
158
+ * pair-wiring duplicated by both HA tests; the per-test divergence (publishing disabled vs. enabled,
159
+ * empty-checkpoint building) is passed through `baseOpts`.
160
+ * @returns The four nodes flat, plus the two `HaPairNodes` descriptors.
161
+ */
162
+ export async function setupHaPairs(
163
+ test: MultiNodeTestContext,
164
+ validators: RegisteredValidator[],
165
+ opts: { baseOpts?: Partial<AztecNodeConfig> & { dontStartSequencer?: boolean }; coinbases?: EthAddress[] } = {},
166
+ ): Promise<{ nodes: AztecNodeService[]; pairs: [HaPairNodes, HaPairNodes] }> {
167
+ const baseOpts = opts.baseOpts ?? {};
168
+ const coinbases = opts.coinbases ?? [1, 2, 3, 4].map(n => EthAddress.fromNumber(n));
169
+ const [pk1, pk2, pk3, pk4] = validators.map(v => v.privateKey);
170
+ const sharedDb1 = await createSharedSlashingProtectionDb(test.context.dateProvider);
171
+ const sharedDb2 = await createSharedSlashingProtectionDb(test.context.dateProvider);
172
+
173
+ const nodes = [
174
+ await test.createValidatorNode([pk1, pk2], {
175
+ ...baseOpts,
176
+ coinbase: coinbases[0],
177
+ slashingProtectionDb: sharedDb1,
178
+ }),
179
+ await test.createValidatorNode([pk1, pk2], {
180
+ ...baseOpts,
181
+ coinbase: coinbases[1],
182
+ slashingProtectionDb: sharedDb1,
183
+ }),
184
+ await test.createValidatorNode([pk3, pk4], {
185
+ ...baseOpts,
186
+ coinbase: coinbases[2],
187
+ slashingProtectionDb: sharedDb2,
188
+ }),
189
+ await test.createValidatorNode([pk3, pk4], {
190
+ ...baseOpts,
191
+ coinbase: coinbases[3],
192
+ slashingProtectionDb: sharedDb2,
193
+ }),
194
+ ];
195
+
196
+ const pairs: [HaPairNodes, HaPairNodes] = [
197
+ { nodes: [nodes[0], nodes[1]], privateKeys: [pk1, pk2], coinbases: [coinbases[0], coinbases[1]] },
198
+ { nodes: [nodes[2], nodes[3]], privateKeys: [pk3, pk4], coinbases: [coinbases[2], coinbases[3]] },
199
+ ];
200
+
201
+ return { nodes, pairs };
202
+ }
203
+
204
+ /**
205
+ * Multi-validator test base: N validator nodes sharing the in-memory `MockGossipSubNetwork` bus, with
206
+ * fast block times and short epochs. Extends {@link SingleNodeTestContext} with validator-node
207
+ * spawning and the convergence helpers (`waitForAllNodes*`, `findSlotsWithProposers`) that only make
208
+ * sense across a committee. The environment, prover lifecycle, and reorg/proving waiters live on the
209
+ * parent so the single-node-topology tests share them.
210
+ */
211
+ export class MultiNodeTestContext extends SingleNodeTestContext {
212
+ /**
213
+ * The validators registered on-chain at genesis (from `opts.initialValidators`). Tests spawn nodes
214
+ * for whichever validators they want online via {@link createValidatorNodeAt}; the rest stay
215
+ * registered-but-offline. Empty for single-validator-less topologies.
216
+ */
217
+ public validators: RegisteredValidator[] = [];
218
+
219
+ public override async setup(opts: MultiNodeTestOpts = {}) {
220
+ this.validators = (opts.initialValidators as RegisteredValidator[] | undefined) ?? [];
221
+ await super.setup(opts);
222
+ }
223
+
224
+ public createValidatorNode(
225
+ privateKeys: `0x${string}`[],
226
+ opts: Partial<AztecNodeConfig> & {
227
+ dontStartSequencer?: boolean;
228
+ slashingProtectionDb?: SlashingProtectionDatabase;
229
+ } = {},
230
+ ) {
231
+ this.logger.warn('Creating and syncing a validator node...');
232
+ return this.createNode({ ...opts, disableValidator: false, validatorPrivateKeys: new SecretValue(privateKeys) });
233
+ }
234
+
235
+ /** Returns the validator registered at on-chain index `index` (0-based into {@link validators}). */
236
+ public validatorAt(index: number): RegisteredValidator {
237
+ return this.validators[index];
238
+ }
239
+
240
+ /** The L1 attester address of the validator registered at `index`. */
241
+ public addressAt(index: number): EthAddress {
242
+ return this.validators[index].attester;
243
+ }
244
+
245
+ /** The L1 signing key of the validator registered at `index`. */
246
+ public privateKeyAt(index: number): `0x${string}` {
247
+ return this.validators[index].privateKey;
248
+ }
249
+
250
+ /**
251
+ * Spawns a validator node on the mock-gossip bus signing with the validator registered at `index`.
252
+ * Pass the same `index` to two calls (with different `coinbase`) to model an equivocating proposer
253
+ * that shares a key across two nodes.
254
+ */
255
+ public createValidatorNodeAt(
256
+ index: number,
257
+ opts: Partial<AztecNodeConfig> & { dontStartSequencer?: boolean } = {},
258
+ ): Promise<AztecNodeService> {
259
+ return this.createValidatorNode([this.privateKeyAt(index)], opts);
260
+ }
261
+
262
+ /** Resolves the rollup, slasher, and slashing-proposer L1 contracts a slashing test interacts with. */
263
+ public async getSlashingContracts(): Promise<SlashingContracts> {
264
+ const rollup = this.rollup;
265
+ const slasherContract = getContract({
266
+ address: getAddress((await rollup.getSlasherAddress()).toString()),
267
+ abi: SlasherAbi,
268
+ client: this.l1Client,
269
+ });
270
+ const slashingProposer = await rollup.getSlashingProposer();
271
+ return { rollup, slasherContract, slashingProposer };
272
+ }
273
+
274
+ /**
275
+ * Polls every node until `predicate(tips, node)` holds for all of them. The multi-node
276
+ * generalization of {@link SingleNodeTestContext.waitForNodeToSync} — replaces hand-rolled
277
+ * `Promise.all(this.nodes.map(node => retryUntil(...)))` fan-out blocks.
278
+ * @param nodes - Nodes to poll; defaults to all validator nodes (`this.nodes`).
279
+ */
280
+ public async waitForAllNodes(
281
+ predicate: (tips: L2Tips, node: AztecNode) => boolean | Promise<boolean>,
282
+ opts: { nodes?: AztecNode[]; timeout?: number; interval?: number; description?: string } = {},
283
+ ): Promise<void> {
284
+ const nodes = opts.nodes ?? this.nodes;
285
+ const timeout = opts.timeout ?? this.L2_SLOT_DURATION_IN_S * 4;
286
+ const interval = opts.interval ?? 0.5;
287
+ const description = opts.description ?? 'all nodes to reach target';
288
+ await Promise.all(
289
+ nodes.map((node, idx) =>
290
+ retryUntil(
291
+ async () => {
292
+ const tips = await node.getChainTips();
293
+ return (await predicate(tips, node)) || undefined;
294
+ },
295
+ `node ${idx} ${description}`,
296
+ timeout,
297
+ interval,
298
+ ),
299
+ ),
300
+ );
301
+ }
302
+
303
+ /** Waits until every node's proven checkpoint tip reaches `target`. */
304
+ public waitForAllNodesToReachProvenCheckpoint(
305
+ target: CheckpointNumber,
306
+ opts: { nodes?: AztecNode[]; timeout?: number; interval?: number } = {},
307
+ ): Promise<void> {
308
+ return testSpan('wait:proven-checkpoint', () =>
309
+ this.waitForAllNodes(tips => tips.proven.checkpoint.number >= target, {
310
+ ...opts,
311
+ description: `proven checkpoint >= ${target}`,
312
+ }),
313
+ );
314
+ }
315
+
316
+ /** Waits until every node's checkpointed checkpoint tip reaches `target`. */
317
+ public waitForAllNodesToReachCheckpoint(
318
+ target: CheckpointNumber,
319
+ opts: { nodes?: AztecNode[]; timeout?: number; interval?: number } = {},
320
+ ): Promise<void> {
321
+ return testSpan('wait:checkpoint', () =>
322
+ this.waitForAllNodes(tips => tips.checkpointed.checkpoint.number >= target, {
323
+ ...opts,
324
+ description: `checkpointed checkpoint >= ${target}`,
325
+ }),
326
+ );
327
+ }
328
+
329
+ /**
330
+ * Waits until every node's `proposed` or `checkpointed` tip points at a block whose slot
331
+ * satisfies `match` (defaults to "slot equals `slot`"). Polls the block referenced by the tip.
332
+ */
333
+ public waitForAllNodesToReachBlockAtSlot(
334
+ slot: SlotNumber,
335
+ tag: 'proposed' | 'checkpointed',
336
+ match: (block: BlockResponse) => boolean = block => block.header.globalVariables.slotNumber === slot,
337
+ opts: { nodes?: AztecNode[]; timeout?: number; interval?: number } = {},
338
+ ): Promise<void> {
339
+ return testSpan('wait:block', () =>
340
+ this.waitForAllNodes(
341
+ async (tips, node) => {
342
+ const blockNumber = tag === 'proposed' ? tips.proposed.number : tips.checkpointed.block.number;
343
+ if (blockNumber === 0) {
344
+ return false;
345
+ }
346
+ const block = await node.getBlock(blockNumber);
347
+ return !!block && match(block);
348
+ },
349
+ { ...opts, description: `${tag} block at slot ${slot}` },
350
+ ),
351
+ );
352
+ }
353
+
354
+ /**
355
+ * Finds `count` consecutive slots (starting from `opts.fromSlot` or the current slot plus a
356
+ * margin) whose proposers satisfy `predicate`, warping the L1 clock forward one epoch and
357
+ * retrying when the rollup reports `ValidatorSelection__EpochNotStable` for a future epoch.
358
+ * Returns the matched slots and their proposer addresses. Encapsulates the slot-search loop
359
+ * duplicated across the multi-validator tests.
360
+ */
361
+ public findSlotsWithProposers(
362
+ count: number,
363
+ predicate: (proposers: EthAddress[]) => boolean,
364
+ opts: { fromSlot?: SlotNumber; margin?: number; maxAttempts?: number } = {},
365
+ ): Promise<{ slots: SlotNumber[]; proposers: EthAddress[] }> {
366
+ return testSpan('warp:find-proposer', async () => {
367
+ const margin = opts.margin ?? 4;
368
+ const maxAttempts = opts.maxAttempts ?? 200;
369
+ let candidate = opts.fromSlot ?? SlotNumber(Number(this.epochCache.getEpochAndSlotNow().slot) + margin);
370
+
371
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
372
+ try {
373
+ const slots = Array.from({ length: count }, (_, i) => SlotNumber(candidate + i));
374
+ const maybeProposers = await Promise.all(
375
+ slots.map(slot => this.epochCache.getProposerAttesterAddressInSlot(slot)),
376
+ );
377
+ if (maybeProposers.every((p): p is EthAddress => p !== undefined) && predicate(maybeProposers)) {
378
+ return { slots, proposers: maybeProposers };
379
+ }
380
+ candidate = SlotNumber(candidate + 1);
381
+ } catch (err) {
382
+ const msg = err instanceof Error ? err.message : String(err);
383
+ if (!msg.includes('EpochNotStable')) {
384
+ throw err;
385
+ }
386
+ const block = await this.l1Client.getBlock({ includeTransactions: false });
387
+ const warpBy = this.epochDuration * this.L2_SLOT_DURATION_IN_S;
388
+ const newTs = Number(block.timestamp) + warpBy;
389
+ this.logger.warn(
390
+ `Hit EpochNotStable at candidate ${candidate}, warping L1 forward by ${warpBy}s to ${newTs}`,
391
+ );
392
+ await this.context.cheatCodes.eth.warp(newTs, { resetBlockInterval: true });
393
+ const newCurrentSlot = Number(this.epochCache.getEpochAndSlotNow().slot);
394
+ if (candidate < newCurrentSlot + margin) {
395
+ candidate = SlotNumber(newCurrentSlot + margin);
396
+ }
397
+ }
398
+ }
399
+ throw new Error(
400
+ `Could not find ${count} consecutive slots matching the proposer predicate after ${maxAttempts} attempts`,
401
+ );
402
+ });
403
+ }
404
+
405
+ /**
406
+ * Watches the sequencers of `nodes` via {@link SingleNodeTestContext.watchSequencerEvents}, pulling
407
+ * the {@link SequencerClient} off each node first. `getMetadata` tags each captured event; it
408
+ * defaults to `{ validator: this.validators[i].attester }`. Pass an override for tests that label
409
+ * their nodes differently (e.g. `['A','B','C'][i]`).
410
+ */
411
+ public watchNodeSequencerEvents(
412
+ nodes: AztecNodeService[],
413
+ getMetadata: (i: number) => Record<string, any> = i => ({ validator: this.validators[i].attester }),
414
+ ): { failEvents: TrackedSequencerEvent[]; stateChanges: TrackedSequencerEvent[] } {
415
+ return this.watchSequencerEvents(this.getSequencers(nodes), getMetadata);
416
+ }
417
+
418
+ /**
419
+ * Waits until matching slash offenses have converged across `nodes`, polling `getSlashOffenses`.
420
+ * With `opts.mode === 'all'` (the default) every node must record a matching offense; with `'any'`
421
+ * a single node suffices. Resolves with all matching offenses collected across the polled nodes.
422
+ */
423
+ public waitForOffenseOnNodes(
424
+ nodes: AztecNodeService[],
425
+ match: (offense: Offense) => boolean,
426
+ opts: { mode?: 'all' | 'any'; timeout?: number; interval?: number } = {},
427
+ ): Promise<Offense[]> {
428
+ const mode = opts.mode ?? 'all';
429
+ const timeout = opts.timeout ?? this.L2_SLOT_DURATION_IN_S * 4;
430
+ const interval = opts.interval ?? 0.5;
431
+ return testSpan('wait:offense', () =>
432
+ retryUntil(
433
+ async () => {
434
+ const perNode = await Promise.all(
435
+ nodes.map(node => node.getSlashOffenses('all').then(os => os.filter(match))),
436
+ );
437
+ const converged =
438
+ mode === 'all' ? perNode.every(matches => matches.length > 0) : perNode.some(m => m.length > 0);
439
+ return converged ? perNode.flat() : undefined;
440
+ },
441
+ `offense on ${mode} node(s)`,
442
+ timeout,
443
+ interval,
444
+ ),
445
+ );
446
+ }
447
+ }