@aztec/end-to-end 0.0.1-commit.42ee6df9b → 0.0.1-commit.431c48d

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 (309) hide show
  1. package/README.md +229 -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/{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 +45 -29
  30. package/dest/bench/utils.d.ts +3 -3
  31. package/dest/bench/utils.d.ts.map +1 -1
  32. package/dest/bench/utils.js +97 -6
  33. package/dest/composed/ha/ha_full_setup.d.ts +77 -0
  34. package/dest/composed/ha/ha_full_setup.d.ts.map +1 -0
  35. package/dest/composed/ha/ha_full_setup.js +383 -0
  36. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts +12 -0
  37. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts.map +1 -0
  38. package/dest/fixtures/authwit_proxy.d.ts +1 -1
  39. package/dest/fixtures/authwit_proxy.d.ts.map +1 -1
  40. package/dest/fixtures/authwit_proxy.js +4 -0
  41. package/dest/fixtures/e2e_prover_test.d.ts +12 -9
  42. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  43. package/dest/fixtures/e2e_prover_test.js +51 -30
  44. package/dest/fixtures/fixtures.d.ts +79 -1
  45. package/dest/fixtures/fixtures.d.ts.map +1 -1
  46. package/dest/fixtures/fixtures.js +80 -0
  47. package/dest/fixtures/ha_setup.d.ts +4 -4
  48. package/dest/fixtures/ha_setup.d.ts.map +1 -1
  49. package/dest/fixtures/ha_setup.js +5 -2
  50. package/dest/fixtures/index.d.ts +2 -1
  51. package/dest/fixtures/index.d.ts.map +1 -1
  52. package/dest/fixtures/index.js +1 -0
  53. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts +25 -0
  54. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts.map +1 -0
  55. package/dest/fixtures/schnorr_hardcoded_account_contract.js +37 -0
  56. package/dest/fixtures/setup.d.ts +81 -42
  57. package/dest/fixtures/setup.d.ts.map +1 -1
  58. package/dest/fixtures/setup.js +289 -198
  59. package/dest/fixtures/setup_p2p_test.d.ts +10 -6
  60. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  61. package/dest/fixtures/setup_p2p_test.js +11 -11
  62. package/dest/fixtures/standard_contracts_genesis.d.ts +16 -0
  63. package/dest/fixtures/standard_contracts_genesis.d.ts.map +1 -0
  64. package/dest/fixtures/standard_contracts_genesis.js +25 -0
  65. package/dest/fixtures/timing.d.ts +42 -0
  66. package/dest/fixtures/timing.d.ts.map +1 -0
  67. package/dest/fixtures/timing.js +72 -0
  68. package/dest/fixtures/token_utils.d.ts +22 -4
  69. package/dest/fixtures/token_utils.d.ts.map +1 -1
  70. package/dest/fixtures/token_utils.js +21 -1
  71. package/dest/fixtures/utils.d.ts +2 -2
  72. package/dest/fixtures/utils.d.ts.map +1 -1
  73. package/dest/fixtures/utils.js +1 -1
  74. package/dest/fixtures/wait_helpers.d.ts +135 -0
  75. package/dest/fixtures/wait_helpers.d.ts.map +1 -0
  76. package/dest/fixtures/wait_helpers.js +154 -0
  77. package/dest/forward-compatibility/wallet_rpc_client.d.ts +7 -0
  78. package/dest/forward-compatibility/wallet_rpc_client.d.ts.map +1 -0
  79. package/dest/forward-compatibility/wallet_rpc_client.js +15 -0
  80. package/dest/forward-compatibility/wallet_service.d.ts +3 -0
  81. package/dest/forward-compatibility/wallet_service.d.ts.map +1 -0
  82. package/dest/forward-compatibility/wallet_service.js +109 -0
  83. package/dest/install_legacy_contracts.d.cts +13 -0
  84. package/dest/install_legacy_contracts.d.cts.map +1 -0
  85. package/dest/legacy-jest-resolver.d.cts +3 -0
  86. package/dest/legacy-jest-resolver.d.cts.map +1 -0
  87. package/dest/multi-node/block-production/setup.d.ts +97 -0
  88. package/dest/multi-node/block-production/setup.d.ts.map +1 -0
  89. package/dest/multi-node/block-production/setup.js +158 -0
  90. package/dest/multi-node/governance/setup.d.ts +67 -0
  91. package/dest/multi-node/governance/setup.d.ts.map +1 -0
  92. package/dest/multi-node/governance/setup.js +126 -0
  93. package/dest/multi-node/multi_node_test_context.d.ts +212 -0
  94. package/dest/multi-node/multi_node_test_context.d.ts.map +1 -0
  95. package/dest/multi-node/multi_node_test_context.js +347 -0
  96. package/dest/multi-node/slashing/inactivity_setup.d.ts +27 -0
  97. package/dest/multi-node/slashing/inactivity_setup.d.ts.map +1 -0
  98. package/dest/multi-node/slashing/inactivity_setup.js +111 -0
  99. package/dest/multi-node/slashing/setup.d.ts +167 -0
  100. package/dest/multi-node/slashing/setup.d.ts.map +1 -0
  101. package/dest/multi-node/slashing/setup.js +275 -0
  102. package/dest/{e2e_p2p → p2p}/p2p_network.d.ts +19 -10
  103. package/dest/p2p/p2p_network.d.ts.map +1 -0
  104. package/dest/{e2e_p2p → p2p}/p2p_network.js +82 -38
  105. package/dest/p2p/reqresp/utils.d.ts +19 -0
  106. package/dest/p2p/reqresp/utils.d.ts.map +1 -0
  107. package/dest/{e2e_p2p → p2p}/reqresp/utils.js +32 -29
  108. package/dest/p2p/shared.d.ts +72 -0
  109. package/dest/p2p/shared.d.ts.map +1 -0
  110. package/dest/p2p/shared.js +212 -0
  111. package/dest/shared/cross_chain_test_harness.d.ts +6 -4
  112. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  113. package/dest/shared/cross_chain_test_harness.js +33 -21
  114. package/dest/shared/gas_portal_test_harness.d.ts +8 -5
  115. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  116. package/dest/shared/gas_portal_test_harness.js +24 -12
  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/single-node/cross-chain/cross_chain_messaging_test.d.ts +75 -0
  132. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts.map +1 -0
  133. package/dest/single-node/cross-chain/cross_chain_messaging_test.js +209 -0
  134. package/dest/single-node/cross-chain/message_test_helpers.d.ts +38 -0
  135. package/dest/single-node/cross-chain/message_test_helpers.d.ts.map +1 -0
  136. package/dest/single-node/cross-chain/message_test_helpers.js +70 -0
  137. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.d.ts +1 -1
  138. package/dest/single-node/fees/bridging_race.notest.d.ts.map +1 -0
  139. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.js +17 -4
  140. package/dest/single-node/fees/fees_test.d.ts +95 -0
  141. package/dest/single-node/fees/fees_test.d.ts.map +1 -0
  142. package/dest/single-node/fees/fees_test.js +347 -0
  143. package/dest/single-node/l1-reorgs/setup.d.ts +42 -0
  144. package/dest/single-node/l1-reorgs/setup.d.ts.map +1 -0
  145. package/dest/single-node/l1-reorgs/setup.js +57 -0
  146. package/dest/single-node/partial-proofs/setup.d.ts +5 -0
  147. package/dest/single-node/partial-proofs/setup.d.ts.map +1 -0
  148. package/dest/single-node/partial-proofs/setup.js +5 -0
  149. package/dest/single-node/proving/setup.d.ts +5 -0
  150. package/dest/single-node/proving/setup.d.ts.map +1 -0
  151. package/dest/single-node/proving/setup.js +5 -0
  152. package/dest/single-node/recovery/setup.d.ts +5 -0
  153. package/dest/single-node/recovery/setup.d.ts.map +1 -0
  154. package/dest/single-node/recovery/setup.js +5 -0
  155. package/dest/single-node/setup.d.ts +49 -0
  156. package/dest/single-node/setup.d.ts.map +1 -0
  157. package/dest/single-node/setup.js +56 -0
  158. package/dest/single-node/single_node_test_context.d.ts +374 -0
  159. package/dest/single-node/single_node_test_context.d.ts.map +1 -0
  160. package/dest/single-node/single_node_test_context.js +847 -0
  161. package/dest/spartan/setup_test_wallets.d.ts +1 -1
  162. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  163. package/dest/spartan/setup_test_wallets.js +31 -46
  164. package/dest/spartan/tx_metrics.d.ts +27 -4
  165. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  166. package/dest/spartan/tx_metrics.js +105 -20
  167. package/dest/spartan/utils/config.d.ts +9 -35
  168. package/dest/spartan/utils/config.d.ts.map +1 -1
  169. package/dest/spartan/utils/gossip_metrics.d.ts +9 -0
  170. package/dest/spartan/utils/gossip_metrics.d.ts.map +1 -0
  171. package/dest/spartan/utils/gossip_metrics.js +77 -0
  172. package/dest/spartan/utils/index.d.ts +2 -1
  173. package/dest/spartan/utils/index.d.ts.map +1 -1
  174. package/dest/spartan/utils/index.js +2 -0
  175. package/dest/spartan/utils/nodes.js +2 -2
  176. package/dest/test-wallet/test_wallet.d.ts +39 -10
  177. package/dest/test-wallet/test_wallet.d.ts.map +1 -1
  178. package/dest/test-wallet/test_wallet.js +166 -59
  179. package/dest/test-wallet/utils.d.ts +38 -3
  180. package/dest/test-wallet/utils.d.ts.map +1 -1
  181. package/dest/test-wallet/utils.js +65 -10
  182. package/dest/test-wallet/wallet_worker_script.js +12 -4
  183. package/dest/test-wallet/worker_wallet.d.ts +9 -8
  184. package/dest/test-wallet/worker_wallet.d.ts.map +1 -1
  185. package/dest/test-wallet/worker_wallet.js +10 -4
  186. package/dest/test-wallet/worker_wallet_schema.d.ts +3 -273
  187. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -1
  188. package/dest/test-wallet/worker_wallet_schema.js +15 -2
  189. package/package.json +48 -43
  190. package/src/automine/README.md +60 -0
  191. package/src/automine/automine_test_context.ts +153 -0
  192. package/src/automine/delivery/interactive_handshake_responder.ts +125 -0
  193. package/src/automine/delivery/onchain_delivery_harness.ts +213 -0
  194. package/src/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.ts +24 -47
  195. package/src/{e2e_token_contract → automine/token}/token_contract_test.ts +25 -48
  196. package/src/automine/token/token_test_helpers.ts +138 -0
  197. package/src/bench/client_flows/benchmark.ts +21 -0
  198. package/src/bench/client_flows/client_flows_benchmark.ts +77 -56
  199. package/src/bench/utils.ts +110 -6
  200. package/src/composed/ha/ha_full_setup.ts +466 -0
  201. package/src/fixtures/authwit_proxy.ts +4 -0
  202. package/src/fixtures/e2e_prover_test.ts +66 -48
  203. package/src/fixtures/fixtures.ts +100 -0
  204. package/src/fixtures/ha_setup.ts +11 -5
  205. package/src/fixtures/index.ts +1 -0
  206. package/src/fixtures/schnorr_hardcoded_account_contract.ts +49 -0
  207. package/src/fixtures/setup.ts +361 -256
  208. package/src/fixtures/setup_p2p_test.ts +15 -11
  209. package/src/fixtures/standard_contracts_genesis.ts +28 -0
  210. package/src/fixtures/timing.ts +97 -0
  211. package/src/fixtures/token_utils.ts +39 -4
  212. package/src/fixtures/utils.ts +2 -3
  213. package/src/fixtures/wait_helpers.ts +333 -0
  214. package/src/forward-compatibility/wallet_rpc_client.ts +14 -0
  215. package/src/forward-compatibility/wallet_service.ts +106 -0
  216. package/src/guides/up_quick_start.sh +5 -2
  217. package/src/infra/README.md +12 -0
  218. package/src/install_legacy_contracts.cjs +81 -0
  219. package/src/legacy-jest-resolver.cjs +98 -0
  220. package/src/multi-node/README.md +96 -0
  221. package/src/multi-node/block-production/setup.ts +272 -0
  222. package/src/multi-node/governance/setup.ts +172 -0
  223. package/src/multi-node/multi_node_test_context.ts +447 -0
  224. package/src/multi-node/slashing/inactivity_setup.ts +139 -0
  225. package/src/multi-node/slashing/setup.ts +433 -0
  226. package/src/p2p/README.md +78 -0
  227. package/src/{e2e_p2p → p2p}/p2p_network.ts +95 -50
  228. package/src/{e2e_p2p → p2p}/reqresp/utils.ts +35 -28
  229. package/src/p2p/shared.ts +329 -0
  230. package/src/shared/cross_chain_test_harness.ts +36 -17
  231. package/src/shared/gas_portal_test_harness.ts +32 -14
  232. package/src/shared/submit-transactions.ts +13 -5
  233. package/src/shared/timing_env.d.mts +39 -0
  234. package/src/shared/timing_env.mjs +363 -0
  235. package/src/shared/uniswap_l1_l2.ts +80 -43
  236. package/src/shared/wait_for_l1_to_l2_message.ts +23 -0
  237. package/src/simulators/lending_simulator.ts +28 -14
  238. package/src/single-node/README.md +66 -0
  239. package/src/single-node/cross-chain/cross_chain_messaging_test.ts +302 -0
  240. package/src/single-node/cross-chain/message_test_helpers.ts +125 -0
  241. package/src/{e2e_fees → single-node/fees}/bridging_race.notest.ts +19 -5
  242. package/src/{e2e_fees → single-node/fees}/fees_test.ts +176 -70
  243. package/src/single-node/l1-reorgs/setup.ts +93 -0
  244. package/src/single-node/partial-proofs/setup.ts +8 -0
  245. package/src/single-node/proving/setup.ts +15 -0
  246. package/src/single-node/recovery/setup.ts +8 -0
  247. package/src/single-node/setup.ts +63 -0
  248. package/src/single-node/single_node_test_context.ts +1058 -0
  249. package/src/spartan/setup_test_wallets.ts +32 -41
  250. package/src/spartan/tx_metrics.ts +107 -23
  251. package/src/spartan/utils/gossip_metrics.ts +108 -0
  252. package/src/spartan/utils/index.ts +3 -0
  253. package/src/spartan/utils/nodes.ts +2 -2
  254. package/src/test-wallet/test_wallet.ts +185 -60
  255. package/src/test-wallet/utils.ts +104 -11
  256. package/src/test-wallet/wallet_worker_script.ts +11 -5
  257. package/src/test-wallet/worker_wallet.ts +19 -16
  258. package/src/test-wallet/worker_wallet_schema.ts +4 -3
  259. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +0 -55
  260. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +0 -1
  261. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +0 -47
  262. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +0 -1
  263. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +0 -129
  264. package/dest/e2e_deploy_contract/deploy_test.d.ts +0 -37
  265. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +0 -1
  266. package/dest/e2e_deploy_contract/deploy_test.js +0 -50
  267. package/dest/e2e_epochs/epochs_test.d.ts +0 -104
  268. package/dest/e2e_epochs/epochs_test.d.ts.map +0 -1
  269. package/dest/e2e_epochs/epochs_test.js +0 -389
  270. package/dest/e2e_fees/bridging_race.notest.d.ts.map +0 -1
  271. package/dest/e2e_fees/fees_test.d.ts +0 -88
  272. package/dest/e2e_fees/fees_test.d.ts.map +0 -1
  273. package/dest/e2e_fees/fees_test.js +0 -255
  274. package/dest/e2e_l1_publisher/write_json.d.ts +0 -11
  275. package/dest/e2e_l1_publisher/write_json.d.ts.map +0 -1
  276. package/dest/e2e_l1_publisher/write_json.js +0 -56
  277. package/dest/e2e_multi_validator/utils.d.ts +0 -12
  278. package/dest/e2e_multi_validator/utils.d.ts.map +0 -1
  279. package/dest/e2e_nested_contract/nested_contract_test.d.ts +0 -26
  280. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +0 -1
  281. package/dest/e2e_nested_contract/nested_contract_test.js +0 -54
  282. package/dest/e2e_p2p/inactivity_slash_test.d.ts +0 -31
  283. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +0 -1
  284. package/dest/e2e_p2p/inactivity_slash_test.js +0 -136
  285. package/dest/e2e_p2p/p2p_network.d.ts.map +0 -1
  286. package/dest/e2e_p2p/reqresp/utils.d.ts +0 -22
  287. package/dest/e2e_p2p/reqresp/utils.d.ts.map +0 -1
  288. package/dest/e2e_p2p/shared.d.ts +0 -66
  289. package/dest/e2e_p2p/shared.d.ts.map +0 -1
  290. package/dest/e2e_p2p/shared.js +0 -212
  291. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +0 -2
  292. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +0 -1
  293. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +0 -1
  294. package/dest/e2e_token_contract/token_contract_test.d.ts +0 -44
  295. package/dest/e2e_token_contract/token_contract_test.d.ts.map +0 -1
  296. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +0 -193
  297. package/src/e2e_deploy_contract/deploy_test.ts +0 -85
  298. package/src/e2e_epochs/epochs_test.ts +0 -499
  299. package/src/e2e_l1_publisher/write_json.ts +0 -77
  300. package/src/e2e_nested_contract/nested_contract_test.ts +0 -75
  301. package/src/e2e_p2p/inactivity_slash_test.ts +0 -179
  302. package/src/e2e_p2p/shared.ts +0 -343
  303. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.js +0 -0
  304. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.js +0 -0
  305. /package/dest/{e2e_multi_validator/utils.js → composed/web3signer/multi_validator_keystore_utils.js} +0 -0
  306. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof.json +0 -0
  307. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.ts +0 -0
  308. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.ts +0 -0
  309. /package/src/{e2e_multi_validator/utils.ts → composed/web3signer/multi_validator_keystore_utils.ts} +0 -0
@@ -0,0 +1,363 @@
1
+ import { appendFileSync, writeFileSync } from 'node:fs';
2
+ import { basename } from 'node:path';
3
+
4
+ import CustomEnvironment from '../../../foundation/src/jest/env.mjs';
5
+
6
+ // Per-test e2e timing environment. Gated entirely on the TEST_TIMING_FILE env var: when unset, this
7
+ // behaves exactly like the base CustomEnvironment (it only delegates). When set, it records, per test
8
+ // worker process, the time spent in jest before/after hooks and the test body, and folds in the named
9
+ // spans recorded via the `testSpan()` wrapper (fixtures/timing.ts) through a collector shared on
10
+ // `this.global`.
11
+ //
12
+ // Output is one JSONL file per worker process (the env runs once per worker). Each line carries a
13
+ // `type` discriminator and is one of:
14
+ // - `type: 'test'` (`name` set): beforeEach hooks, the it() body, afterEach hooks for one test; or
15
+ // - `type: 'suite'` (`name: null`): the suite-scoped beforeAll/afterAll hooks for the whole file.
16
+ //
17
+ // Each line also gains a `spans` map: per `category:label` tag the test/suite touched, the collector
18
+ // records `{ count, totalMs, busyMs, maxMs }`. `busyMs` is the duration of the union of the spans'
19
+ // `[start, end)` intervals on the shared `performance.now()` clock, so concurrent spans (Promise.all
20
+ // fan-out) do not inflate it the way `totalMs` does. The legacy `setupFnMs`/`teardownFnMs` fields are
21
+ // kept for back-compat, derived from the `setup:env`/`teardown:env` spans.
22
+ //
23
+ // When `TEST_TIMING_SPANS=1`, the collector additionally retains every raw span occurrence and emits
24
+ // one `type:"span"` line per occurrence (owner, name, ms) for deep dives, at the cost of a larger file.
25
+ export default class TimingEnvironment extends CustomEnvironment {
26
+ constructor(config, context) {
27
+ super(config, context);
28
+
29
+ this.timingFile = process.env.TEST_TIMING_FILE;
30
+ if (!this.timingFile) {
31
+ return;
32
+ }
33
+
34
+ this.suite = basename(context?.testPath ?? config?.testPath ?? 'unknown').replace(/\.test\.[cm]?[jt]s$/, '');
35
+ this.meta = {
36
+ commit: process.env.COMMIT_HASH ?? null,
37
+ branch: process.env.TARGET_BRANCH ?? process.env.REF_NAME ?? null,
38
+ runId: process.env.RUN_ID ?? null,
39
+ };
40
+
41
+ // Opt-in per-occurrence emission for deep dives (off by default keeps the JSONL one line per test).
42
+ this.emitSpanLines = process.env.TEST_TIMING_SPANS === '1';
43
+
44
+ // Shared collector. The instrumented helpers (running in the sandbox realm) read
45
+ // `globalThis.__e2eTimings`; this env (host realm) reads `this.global.__e2eTimings` — they are the
46
+ // same object. `current` is the full name of the test currently running (null during
47
+ // beforeAll/afterAll), used to attribute each span to a test or to the suite-scoped line. `spans`
48
+ // accumulates every recorded span until flush. The `start`/`end` timestamps come from the sandbox
49
+ // realm's `performance.now()`; Node's perf clock is process-wide (one monotonic origin across all
50
+ // realms), so merging the intervals here for `busyMs` is valid.
51
+ this.collector = { current: null, spans: [] };
52
+ this.global.__e2eTimings = this.collector;
53
+
54
+ // Records to flush as JSONL on teardown. One per test plus one suite-scoped record.
55
+ this.records = [];
56
+ this.recordsByName = new Map();
57
+ // The suite-scoped record (beforeAll/afterAll); bodyMs/totalMs are computed at flush time.
58
+ this.suiteRecord = { name: null, status: 'passed', beforeHooksMs: 0, afterHooksMs: 0 };
59
+ // Start times keyed by hook type (beforeAll/beforeEach/afterAll/afterEach).
60
+ this.hookStarts = {};
61
+ this.testStarts = new Map();
62
+ // Guards against double-flushing (we flush on both the teardown event and the teardown method).
63
+ this.flushed = false;
64
+ // Raw per-occurrence spans retained only when TEST_TIMING_SPANS=1, emitted as `type:"span"` lines.
65
+ this.rawSpans = [];
66
+ }
67
+
68
+ // Flush on the teardown method too: the jest lifecycle always calls this, whereas the 'teardown'
69
+ // event is not reliably delivered when a test run is interrupted. Whichever fires first wins.
70
+ async teardown() {
71
+ this.finalizeAndFlush();
72
+ await super.teardown();
73
+ }
74
+
75
+ async handleTestEvent(event, state) {
76
+ // Run the base env first so its unhandledRejection patching for after-hooks stays intact.
77
+ await super.handleTestEvent(event, state);
78
+
79
+ if (!this.timingFile) {
80
+ return;
81
+ }
82
+
83
+ const now = Date.now();
84
+ switch (event.name) {
85
+ case 'hook_start': {
86
+ this.hookStarts[event.hook.type] = now;
87
+ break;
88
+ }
89
+ case 'hook_success':
90
+ case 'hook_failure': {
91
+ const start = this.hookStarts[event.hook.type];
92
+ if (start === undefined) {
93
+ break;
94
+ }
95
+ delete this.hookStarts[event.hook.type];
96
+ const ms = now - start;
97
+ if (event.hook.type === 'beforeEach') {
98
+ this.addToCurrent('beforeHooksMs', ms);
99
+ } else if (event.hook.type === 'afterEach') {
100
+ this.addToCurrent('afterHooksMs', ms);
101
+ } else if (event.hook.type === 'beforeAll') {
102
+ this.suiteRecord.beforeHooksMs += ms;
103
+ } else if (event.hook.type === 'afterAll') {
104
+ this.suiteRecord.afterHooksMs += ms;
105
+ }
106
+ break;
107
+ }
108
+ case 'test_start': {
109
+ const name = this.fullTestName(event.test);
110
+ const record = {
111
+ type: 'test',
112
+ name,
113
+ status: 'passed',
114
+ setupFnMs: 0,
115
+ beforeHooksMs: 0,
116
+ bodyMs: 0,
117
+ teardownFnMs: 0,
118
+ afterHooksMs: 0,
119
+ totalMs: 0,
120
+ startedAt: new Date(now).toISOString(),
121
+ };
122
+ this.records.push(record);
123
+ this.recordsByName.set(name, record);
124
+ this.testStarts.set(name, now);
125
+ this.collector.current = name;
126
+ break;
127
+ }
128
+ case 'test_fn_start': {
129
+ this.testStarts.set(`fn:${this.fullTestName(event.test)}`, now);
130
+ break;
131
+ }
132
+ case 'test_fn_success':
133
+ case 'test_fn_failure': {
134
+ const name = this.fullTestName(event.test);
135
+ const start = this.testStarts.get(`fn:${name}`);
136
+ const record = this.recordsByName.get(name);
137
+ if (record && start !== undefined) {
138
+ record.bodyMs = now - start;
139
+ }
140
+ if (record && event.name === 'test_fn_failure') {
141
+ record.status = 'failed';
142
+ }
143
+ break;
144
+ }
145
+ case 'test_done': {
146
+ const name = this.fullTestName(event.test);
147
+ const record = this.recordsByName.get(name);
148
+ const start = this.testStarts.get(name);
149
+ if (record && start !== undefined) {
150
+ record.totalMs = now - start;
151
+ }
152
+ if (record && event.test?.errors?.length) {
153
+ record.status = 'failed';
154
+ }
155
+ this.collector.current = null;
156
+ break;
157
+ }
158
+ case 'teardown': {
159
+ this.finalizeAndFlush();
160
+ break;
161
+ }
162
+ default:
163
+ break;
164
+ }
165
+ }
166
+
167
+ /** The record for the test currently running, if any. */
168
+ currentRecord() {
169
+ return this.collector.current ? this.recordsByName.get(this.collector.current) : undefined;
170
+ }
171
+
172
+ /** Adds `ms` to a hook bucket on the current per-test record, or the suite record during beforeAll/afterAll. */
173
+ addToCurrent(field, ms) {
174
+ const record = this.currentRecord();
175
+ if (record) {
176
+ record[field] += ms;
177
+ }
178
+ }
179
+
180
+ /** Builds the full test name by walking up the describe blocks, matching jest's currentTestName. */
181
+ fullTestName(test) {
182
+ if (!test) {
183
+ return null;
184
+ }
185
+ const parts = [];
186
+ let node = test;
187
+ while (node && node.name && node.name !== 'ROOT_DESCRIBE_BLOCK') {
188
+ parts.unshift(node.name);
189
+ node = node.parent;
190
+ }
191
+ return parts.join(' ');
192
+ }
193
+
194
+ /** Folds the collected spans into the per-test / suite records via {@link foldSpansInto}, then drains the collector. */
195
+ foldSpans() {
196
+ const rawSpans = foldSpansInto(this.collector.spans, {
197
+ recordsByName: this.recordsByName,
198
+ suiteRecord: this.suiteRecord,
199
+ emitSpanLines: this.emitSpanLines,
200
+ });
201
+ this.rawSpans.push(...rawSpans);
202
+ this.collector.spans = [];
203
+ }
204
+
205
+ /** Folds spans into records, finalizes the suite-scoped record, and writes all JSONL. */
206
+ finalizeAndFlush() {
207
+ if (this.flushed || !this.timingFile) {
208
+ return;
209
+ }
210
+ this.flushed = true;
211
+ this.foldSpans();
212
+
213
+ const lines = [];
214
+ for (const record of this.records) {
215
+ lines.push(this.toLine({ ...record }));
216
+ }
217
+ lines.push(
218
+ this.toLine({
219
+ type: 'suite',
220
+ name: null,
221
+ status: 'passed',
222
+ setupFnMs: this.suiteRecord.setupFnMs ?? 0,
223
+ beforeHooksMs: this.suiteRecord.beforeHooksMs,
224
+ teardownFnMs: this.suiteRecord.teardownFnMs ?? 0,
225
+ afterHooksMs: this.suiteRecord.afterHooksMs,
226
+ totalMs: this.suiteRecord.beforeHooksMs + this.suiteRecord.afterHooksMs,
227
+ spans: this.suiteRecord.spans,
228
+ }),
229
+ );
230
+ for (const raw of this.rawSpans) {
231
+ lines.push(this.toLine({ type: 'span', name: raw.owner, span: raw.name, ms: raw.ms }));
232
+ }
233
+
234
+ const payload = lines.join('\n') + '\n';
235
+ try {
236
+ // One file per worker process, but a worker may run several suites: append so we keep them all.
237
+ appendFileSync(this.timingFile, payload);
238
+ } catch {
239
+ try {
240
+ writeFileSync(this.timingFile, payload);
241
+ } catch {
242
+ // Timing is best-effort; never fail a test because we couldn't write the file.
243
+ }
244
+ }
245
+ }
246
+
247
+ /** Flattens metadata onto a record and serializes to a single JSON line, rounding all Ms fields. */
248
+ toLine(record) {
249
+ const obj = { suite: this.suite, ...record, ...this.meta };
250
+ for (const key of Object.keys(obj)) {
251
+ if (key.endsWith('Ms') && typeof obj[key] === 'number') {
252
+ obj[key] = Math.round(obj[key]);
253
+ }
254
+ }
255
+ // Round the nested span aggregates' Ms fields too (totalMs/busyMs/maxMs per tag).
256
+ if (obj.spans && typeof obj.spans === 'object') {
257
+ for (const agg of Object.values(obj.spans)) {
258
+ for (const key of Object.keys(agg)) {
259
+ if (key.endsWith('Ms') && typeof agg[key] === 'number') {
260
+ agg[key] = Math.round(agg[key]);
261
+ }
262
+ }
263
+ }
264
+ }
265
+ return JSON.stringify(obj);
266
+ }
267
+ }
268
+
269
+ /**
270
+ * Aggregates a list of `{ start, end }` spans of one tag into `{ count, totalMs, busyMs, maxMs }`.
271
+ * `totalMs` is the naive sum of per-occurrence durations (correct for serial repeats); `busyMs` is
272
+ * the duration of the union of the `[start, end)` intervals (concurrency-correct — N concurrent
273
+ * spans collapse to their wall-clock span instead of summing to ~N×); `maxMs` is the longest single
274
+ * occurrence. All durations are on the shared process-wide `performance.now()` clock. Does not mutate
275
+ * the input array.
276
+ */
277
+ export function aggregateSpans(spans) {
278
+ let totalMs = 0;
279
+ let maxMs = 0;
280
+ for (const span of spans) {
281
+ const ms = span.end - span.start;
282
+ totalMs += ms;
283
+ if (ms > maxMs) {
284
+ maxMs = ms;
285
+ }
286
+ }
287
+ // busyMs: sort by start and merge overlapping intervals, summing the merged lengths.
288
+ const sorted = [...spans].sort((a, b) => a.start - b.start);
289
+ let busyMs = 0;
290
+ let mergeStart = null;
291
+ let mergeEnd = null;
292
+ for (const span of sorted) {
293
+ if (mergeStart === null) {
294
+ mergeStart = span.start;
295
+ mergeEnd = span.end;
296
+ } else if (span.start <= mergeEnd) {
297
+ if (span.end > mergeEnd) {
298
+ mergeEnd = span.end;
299
+ }
300
+ } else {
301
+ busyMs += mergeEnd - mergeStart;
302
+ mergeStart = span.start;
303
+ mergeEnd = span.end;
304
+ }
305
+ }
306
+ if (mergeStart !== null) {
307
+ busyMs += mergeEnd - mergeStart;
308
+ }
309
+ return { count: spans.length, totalMs, busyMs, maxMs };
310
+ }
311
+
312
+ /**
313
+ * Groups `spans` by owner, then by tag, and attaches a `spans` map of aggregates to the matching
314
+ * per-test record (looked up in `recordsByName`) or, for `null`-owner spans, to `suiteRecord`. Also
315
+ * derives the back-compat `setupFnMs` / `teardownFnMs` fields from the `setup:env:<mode>` /
316
+ * `teardown:env` aggregates (additive over any pre-existing value). Spans whose owner matches no
317
+ * record (e.g. the pinned `other:mempool-feeder` owner) are dropped. Returns the raw per-occurrence
318
+ * list (`{ owner, name, ms }`), which is empty unless `emitSpanLines` is set.
319
+ */
320
+ export function foldSpansInto(spans, { recordsByName, suiteRecord, emitSpanLines = false }) {
321
+ const rawSpans = [];
322
+ // Group by owner (null owner → suite record), then by tag.
323
+ const byOwner = new Map();
324
+ for (const span of spans) {
325
+ const owner = span.owner ?? null;
326
+ let byName = byOwner.get(owner);
327
+ if (!byName) {
328
+ byName = new Map();
329
+ byOwner.set(owner, byName);
330
+ }
331
+ let list = byName.get(span.name);
332
+ if (!list) {
333
+ list = [];
334
+ byName.set(span.name, list);
335
+ }
336
+ list.push(span);
337
+ if (emitSpanLines) {
338
+ rawSpans.push({ owner, name: span.name, ms: span.end - span.start });
339
+ }
340
+ }
341
+
342
+ for (const [owner, byName] of byOwner) {
343
+ const record = owner === null ? suiteRecord : recordsByName.get(owner);
344
+ if (!record) {
345
+ continue;
346
+ }
347
+ const aggregates = {};
348
+ for (const [name, list] of byName) {
349
+ aggregates[name] = aggregateSpans(list);
350
+ }
351
+ record.spans = aggregates;
352
+ // Back-compat: the legacy fn-span buckets are derived from the top-level env setup/teardown tags.
353
+ // The top-level setup is tagged `setup:env:<proverMode>` (the mode is a closed set, distinct from
354
+ // the `:anvil`/`:l1-deploy`/... sub-phase tags), so sum those three exact tags.
355
+ const setupFnMs =
356
+ (aggregates['setup:env:none']?.totalMs ?? 0) +
357
+ (aggregates['setup:env:fake']?.totalMs ?? 0) +
358
+ (aggregates['setup:env:real']?.totalMs ?? 0);
359
+ record.setupFnMs = setupFnMs + (record.setupFnMs ?? 0);
360
+ record.teardownFnMs = (aggregates['teardown:env']?.totalMs ?? 0) + (record.teardownFnMs ?? 0);
361
+ }
362
+ return rawSpans;
363
+ }
@@ -13,15 +13,15 @@ import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
13
13
  import { extractEvent } from '@aztec/ethereum/utils';
14
14
  import { EpochNumber } from '@aztec/foundation/branded-types';
15
15
  import { sha256ToField } from '@aztec/foundation/crypto/sha256';
16
+ import { retryUntil } from '@aztec/foundation/retry';
16
17
  import { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
17
18
  import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
18
19
  import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
19
- import { computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
20
20
 
21
21
  import { jest } from '@jest/globals';
22
22
  import { type GetContractReturnType, getContract, parseEther, toFunctionSelector } from 'viem';
23
23
 
24
- import { type EndToEndContext, ensureAccountContractsPublished } from '../fixtures/utils.js';
24
+ import { type EndToEndContext, ensureAuthRegistryPublished } from '../fixtures/utils.js';
25
25
  import type { TestWallet } from '../test-wallet/test_wallet.js';
26
26
  import { CrossChainTestHarness } from './cross_chain_test_harness.js';
27
27
 
@@ -32,7 +32,7 @@ import { CrossChainTestHarness } from './cross_chain_test_harness.js';
32
32
  // anvil --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c --fork-block-number 17514288 --chain-id 31337
33
33
  // For CI, this is configured in `run_tests.sh` and `docker-compose-images.yml`
34
34
 
35
- const TIMEOUT = 360_000;
35
+ const TIMEOUT = 15 * 60 * 1000;
36
36
 
37
37
  export const uniswapL1L2TestSuite = (
38
38
  setup: () => Promise<EndToEndContext>,
@@ -84,8 +84,6 @@ export const uniswapL1L2TestSuite = (
84
84
 
85
85
  l1Client = deployL1ContractsValues.l1Client;
86
86
 
87
- t.watcher.setIsMarkingAsProven(false);
88
-
89
87
  if (Number(await l1Client.getBlockNumber()) < expectedForkBlockNumber) {
90
88
  throw new Error('This test must be run on a fork of mainnet with the expected fork block');
91
89
  }
@@ -97,7 +95,7 @@ export const uniswapL1L2TestSuite = (
97
95
  version = Number(await rollup.getVersion());
98
96
  ownerEthAddress = EthAddress.fromString((await l1Client.getAddresses())[0]);
99
97
 
100
- await ensureAccountContractsPublished(wallet, [ownerAddress, sponsorAddress]);
98
+ await ensureAuthRegistryPublished(wallet, ownerAddress);
101
99
 
102
100
  logger.info('Deploying DAI Portal, initializing and deploying l2 contract...');
103
101
  daiCrossChainHarness = await CrossChainTestHarness.new(
@@ -154,7 +152,6 @@ export const uniswapL1L2TestSuite = (
154
152
  await cleanup();
155
153
  });
156
154
 
157
- // docs:start:uniswap_private
158
155
  it('should uniswap trade on L1 from L2 funds privately (swaps WETH -> DAI)', async () => {
159
156
  const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
160
157
 
@@ -251,14 +248,13 @@ export const uniswapL1L2TestSuite = (
251
248
  // ensure that uniswap contract didn't eat the funds.
252
249
  await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n);
253
250
 
254
- // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
255
- const swapResult = (await computeL2ToL1MembershipWitness(
256
- aztecNode,
257
- swapPrivateLeaf,
258
- l2UniswapInteractionReceipt.txHash,
259
- ))!;
260
- const { epochNumber: epoch } = swapResult;
261
- await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
251
+ // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch
252
+ // before we can ask the witness helper for a covering root.
253
+ const minedReceipt = await aztecNode.getTxReceipt(l2UniswapInteractionReceipt.txHash);
254
+ if (minedReceipt.epochNumber === undefined) {
255
+ throw new Error('L2 Uniswap interaction tx is not yet in an epoch');
256
+ }
257
+ await cheatCodes.rollup.advanceToEpoch(EpochNumber(minedReceipt.epochNumber + 1));
262
258
  await waitForProven(aztecNode, l2UniswapInteractionReceipt, { provenTimeout: 300 });
263
259
 
264
260
  // 5. Consume L2 to L1 message by calling uniswapPortal.swap_private()
@@ -266,11 +262,19 @@ export const uniswapL1L2TestSuite = (
266
262
  const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf(
267
263
  daiCrossChainHarness.tokenPortalAddress,
268
264
  );
269
- const withdrawResult = (await computeL2ToL1MembershipWitness(
270
- aztecNode,
271
- withdrawLeaf,
272
- l2UniswapInteractionReceipt.txHash,
273
- ))!;
265
+ const swapResult = await retryUntil(
266
+ () => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, swapPrivateLeaf),
267
+ 'swap private l2 to l1 witness',
268
+ 60,
269
+ 1,
270
+ );
271
+ const { epochNumber: epoch, numCheckpointsInEpoch } = swapResult;
272
+ const withdrawResult = await retryUntil(
273
+ () => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, withdrawLeaf),
274
+ 'withdraw l2 to l1 witness',
275
+ 60,
276
+ 1,
277
+ );
274
278
 
275
279
  const swapPrivateL2MessageIndex = swapResult.leafIndex;
276
280
  const swapPrivateSiblingPath = swapResult.siblingPath;
@@ -280,6 +284,7 @@ export const uniswapL1L2TestSuite = (
280
284
 
281
285
  const withdrawMessageMetadata = {
282
286
  _epoch: BigInt(epoch),
287
+ _numCheckpointsInEpoch: BigInt(withdrawResult.numCheckpointsInEpoch),
283
288
  _leafIndex: BigInt(withdrawL2MessageIndex),
284
289
  _path: withdrawSiblingPath
285
290
  .toBufferArray()
@@ -288,6 +293,7 @@ export const uniswapL1L2TestSuite = (
288
293
 
289
294
  const swapPrivateMessageMetadata = {
290
295
  _epoch: BigInt(epoch),
296
+ _numCheckpointsInEpoch: BigInt(numCheckpointsInEpoch),
291
297
  _leafIndex: BigInt(swapPrivateL2MessageIndex),
292
298
  _path: swapPrivateSiblingPath
293
299
  .toBufferArray()
@@ -345,10 +351,8 @@ export const uniswapL1L2TestSuite = (
345
351
  logger.info('WETH balance after swap : ', wethL2BalanceAfterSwap.toString());
346
352
  logger.info('DAI balance after swap : ', daiL2BalanceAfterSwap.toString());
347
353
  });
348
- // docs:end:uniswap_private
349
354
 
350
355
  // TODO(#7463): reenable look into this failure https://github.com/AztecProtocol/aztec-packages/actions/runs/9912612912/job/27388320150?pr=7462
351
- // // docs:start:uniswap_public
352
356
  // it('should uniswap trade on L1 from L2 funds publicly (swaps WETH -> DAI)', async () => {
353
357
  // const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
354
358
 
@@ -581,7 +585,6 @@ export const uniswapL1L2TestSuite = (
581
585
  // logger.info('WETH balance after swap : ', wethL2BalanceAfterSwap.toString());
582
586
  // logger.info('DAI balance after swap : ', daiL2BalanceAfterSwap.toString());
583
587
  // });
584
- // // docs:end:uniswap_public
585
588
 
586
589
  // Edge cases for the private flow:
587
590
  // note - tests for uniswapPortal.sol and minting asset on L2 are covered in other tests.
@@ -847,9 +850,31 @@ export const uniswapL1L2TestSuite = (
847
850
  chainId: new Fr(l1Client.chain.id),
848
851
  });
849
852
 
850
- const swapResult = (await computeL2ToL1MembershipWitness(aztecNode, swapPrivateLeaf, withdrawReceipt.txHash))!;
851
- const { epochNumber: epoch } = swapResult;
852
- const withdrawResult = (await computeL2ToL1MembershipWitness(aztecNode, withdrawLeaf, withdrawReceipt.txHash))!;
853
+ // ensure that user's funds were burnt
854
+ await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
855
+
856
+ // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch
857
+ // before we can ask the witness helper for a covering root.
858
+ const minedReceipt = await aztecNode.getTxReceipt(withdrawReceipt.txHash);
859
+ if (minedReceipt.epochNumber === undefined) {
860
+ throw new Error('Withdraw tx is not yet in an epoch');
861
+ }
862
+ await cheatCodes.rollup.advanceToEpoch(EpochNumber(minedReceipt.epochNumber + 1));
863
+ await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
864
+
865
+ const swapResult = await retryUntil(
866
+ () => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, swapPrivateLeaf),
867
+ 'swap private l2 to l1 witness',
868
+ 60,
869
+ 1,
870
+ );
871
+ const { epochNumber: epoch, numCheckpointsInEpoch } = swapResult;
872
+ const withdrawResult = await retryUntil(
873
+ () => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, withdrawLeaf),
874
+ 'withdraw l2 to l1 witness',
875
+ 60,
876
+ 1,
877
+ );
853
878
 
854
879
  const swapPrivateL2MessageIndex = swapResult.leafIndex;
855
880
  const swapPrivateSiblingPath = swapResult.siblingPath;
@@ -859,6 +884,7 @@ export const uniswapL1L2TestSuite = (
859
884
 
860
885
  const withdrawMessageMetadata = {
861
886
  _epoch: BigInt(epoch),
887
+ _numCheckpointsInEpoch: BigInt(withdrawResult.numCheckpointsInEpoch),
862
888
  _leafIndex: BigInt(withdrawL2MessageIndex),
863
889
  _path: withdrawSiblingPath
864
890
  .toBufferArray()
@@ -867,19 +893,13 @@ export const uniswapL1L2TestSuite = (
867
893
 
868
894
  const swapPrivateMessageMetadata = {
869
895
  _epoch: BigInt(epoch),
896
+ _numCheckpointsInEpoch: BigInt(numCheckpointsInEpoch),
870
897
  _leafIndex: BigInt(swapPrivateL2MessageIndex),
871
898
  _path: swapPrivateSiblingPath
872
899
  .toBufferArray()
873
900
  .map((buf: Buffer) => `0x${buf.toString('hex')}`) as readonly `0x${string}`[],
874
901
  };
875
902
 
876
- // ensure that user's funds were burnt
877
- await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
878
-
879
- // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
880
- await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
881
- await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
882
-
883
903
  // On L1 call swap_public!
884
904
  logger.info('call swap_public on L1');
885
905
  const swapArgs = [
@@ -979,9 +999,31 @@ export const uniswapL1L2TestSuite = (
979
999
  chainId: new Fr(l1Client.chain.id),
980
1000
  });
981
1001
 
982
- const swapResult = (await computeL2ToL1MembershipWitness(aztecNode, swapPublicLeaf, withdrawReceipt.txHash))!;
983
- const { epochNumber: epoch } = swapResult;
984
- const withdrawResult = (await computeL2ToL1MembershipWitness(aztecNode, withdrawLeaf, withdrawReceipt.txHash))!;
1002
+ // check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
1003
+ await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
1004
+
1005
+ // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch
1006
+ // before we can ask the witness helper for a covering root.
1007
+ const minedReceipt = await aztecNode.getTxReceipt(withdrawReceipt.txHash);
1008
+ if (minedReceipt.epochNumber === undefined) {
1009
+ throw new Error('Withdraw tx is not yet in an epoch');
1010
+ }
1011
+ await cheatCodes.rollup.advanceToEpoch(EpochNumber(minedReceipt.epochNumber + 1));
1012
+ await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
1013
+
1014
+ const swapResult = await retryUntil(
1015
+ () => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, swapPublicLeaf),
1016
+ 'swap public l2 to l1 witness',
1017
+ 60,
1018
+ 1,
1019
+ );
1020
+ const { epochNumber: epoch, numCheckpointsInEpoch } = swapResult;
1021
+ const withdrawResult = await retryUntil(
1022
+ () => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, withdrawLeaf),
1023
+ 'withdraw l2 to l1 witness',
1024
+ 60,
1025
+ 1,
1026
+ );
985
1027
 
986
1028
  const swapPublicL2MessageIndex = swapResult.leafIndex;
987
1029
  const swapPublicSiblingPath = swapResult.siblingPath;
@@ -991,6 +1033,7 @@ export const uniswapL1L2TestSuite = (
991
1033
 
992
1034
  const withdrawMessageMetadata = {
993
1035
  _epoch: BigInt(epoch),
1036
+ _numCheckpointsInEpoch: BigInt(withdrawResult.numCheckpointsInEpoch),
994
1037
  _leafIndex: BigInt(withdrawL2MessageIndex),
995
1038
  _path: withdrawSiblingPath
996
1039
  .toBufferArray()
@@ -999,19 +1042,13 @@ export const uniswapL1L2TestSuite = (
999
1042
 
1000
1043
  const swapPublicMessageMetadata = {
1001
1044
  _epoch: BigInt(epoch),
1045
+ _numCheckpointsInEpoch: BigInt(numCheckpointsInEpoch),
1002
1046
  _leafIndex: BigInt(swapPublicL2MessageIndex),
1003
1047
  _path: swapPublicSiblingPath
1004
1048
  .toBufferArray()
1005
1049
  .map((buf: Buffer) => `0x${buf.toString('hex')}`) as readonly `0x${string}`[],
1006
1050
  };
1007
1051
 
1008
- // check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
1009
- await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
1010
-
1011
- // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
1012
- await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
1013
- await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
1014
-
1015
1052
  // Call swap_private on L1
1016
1053
  logger.info('Execute withdraw and swap on the uniswapPortal!');
1017
1054
 
@@ -0,0 +1,23 @@
1
+ import type { Fr } from '@aztec/aztec.js/fields';
2
+ import type { AztecNode } from '@aztec/aztec.js/node';
3
+ import { retryUntil } from '@aztec/foundation/retry';
4
+
5
+ /**
6
+ * Waits until the archiver has seen the L1 to L2 message and indexed it. Unlike
7
+ * {@link waitForL1ToL2MessageReady} from `@aztec/aztec.js/messaging`, this does not
8
+ * require the L2 chain to have advanced to the message's checkpoint — it only confirms
9
+ * the message has been picked up from L1. Use this in tests that explicitly produce L2
10
+ * blocks afterwards to make the message consumable.
11
+ */
12
+ export function waitForL1ToL2MessageSeen(
13
+ node: Pick<AztecNode, 'getL1ToL2MessageCheckpoint'>,
14
+ l1ToL2MessageHash: Fr,
15
+ opts: { timeoutSeconds: number },
16
+ ) {
17
+ return retryUntil(
18
+ async () => (await node.getL1ToL2MessageCheckpoint(l1ToL2MessageHash)) !== undefined,
19
+ `L1 to L2 message ${l1ToL2MessageHash.toString()} seen`,
20
+ opts.timeoutSeconds,
21
+ 0.25,
22
+ );
23
+ }