@aztec/end-to-end 0.0.0-test.1 → 0.0.1-commit.017a351

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 (316) hide show
  1. package/README.md +27 -0
  2. package/dest/bench/client_flows/benchmark.d.ts +76 -0
  3. package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
  4. package/dest/bench/client_flows/benchmark.js +298 -0
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts +79 -0
  6. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
  7. package/dest/bench/client_flows/client_flows_benchmark.js +318 -0
  8. package/dest/bench/client_flows/config.d.ts +14 -0
  9. package/dest/bench/client_flows/config.d.ts.map +1 -0
  10. package/dest/bench/client_flows/config.js +124 -0
  11. package/dest/bench/client_flows/data_extractor.d.ts +2 -0
  12. package/dest/bench/client_flows/data_extractor.d.ts.map +1 -0
  13. package/dest/bench/client_flows/data_extractor.js +79 -0
  14. package/dest/bench/utils.d.ts +16 -41
  15. package/dest/bench/utils.d.ts.map +1 -1
  16. package/dest/bench/utils.js +46 -72
  17. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +30 -20
  18. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  19. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +137 -106
  20. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +44 -33
  21. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  22. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +136 -103
  23. package/dest/e2e_deploy_contract/deploy_test.d.ts +20 -11
  24. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  25. package/dest/e2e_deploy_contract/deploy_test.js +28 -28
  26. package/dest/e2e_epochs/epochs_test.d.ts +98 -24
  27. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  28. package/dest/e2e_epochs/epochs_test.js +366 -61
  29. package/dest/e2e_fees/bridging_race.notest.d.ts +2 -0
  30. package/dest/e2e_fees/bridging_race.notest.d.ts.map +1 -0
  31. package/dest/e2e_fees/bridging_race.notest.js +61 -0
  32. package/dest/e2e_fees/fees_test.d.ts +42 -24
  33. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  34. package/dest/e2e_fees/fees_test.js +194 -182
  35. package/dest/e2e_l1_publisher/write_json.d.ts +11 -0
  36. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
  37. package/dest/e2e_l1_publisher/write_json.js +56 -0
  38. package/dest/e2e_multi_validator/utils.d.ts +12 -0
  39. package/dest/e2e_multi_validator/utils.d.ts.map +1 -0
  40. package/dest/e2e_multi_validator/utils.js +214 -0
  41. package/dest/e2e_nested_contract/nested_contract_test.d.ts +16 -16
  42. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  43. package/dest/e2e_nested_contract/nested_contract_test.js +38 -43
  44. package/dest/e2e_p2p/inactivity_slash_test.d.ts +31 -0
  45. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -0
  46. package/dest/e2e_p2p/inactivity_slash_test.js +137 -0
  47. package/dest/e2e_p2p/p2p_network.d.ts +287 -31
  48. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  49. package/dest/e2e_p2p/p2p_network.js +281 -183
  50. package/dest/e2e_p2p/reqresp/utils.d.ts +22 -0
  51. package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -0
  52. package/dest/e2e_p2p/reqresp/utils.js +206 -0
  53. package/dest/e2e_p2p/shared.d.ts +73 -8
  54. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  55. package/dest/e2e_p2p/shared.js +205 -27
  56. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +2 -0
  57. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +1 -0
  58. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.js +184 -0
  59. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts +18 -0
  60. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +1 -0
  61. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.js +120 -0
  62. package/dest/e2e_token_contract/token_contract_test.d.ts +30 -15
  63. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  64. package/dest/e2e_token_contract/token_contract_test.js +110 -76
  65. package/dest/fixtures/authwit_proxy.d.ts +15 -0
  66. package/dest/fixtures/authwit_proxy.d.ts.map +1 -0
  67. package/dest/fixtures/authwit_proxy.js +34 -0
  68. package/dest/fixtures/e2e_prover_test.d.ts +56 -0
  69. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
  70. package/dest/fixtures/e2e_prover_test.js +267 -0
  71. package/dest/fixtures/elu_monitor.d.ts +21 -0
  72. package/dest/fixtures/elu_monitor.d.ts.map +1 -0
  73. package/dest/fixtures/elu_monitor.js +102 -0
  74. package/dest/fixtures/fixtures.d.ts +79 -8
  75. package/dest/fixtures/fixtures.d.ts.map +1 -1
  76. package/dest/fixtures/fixtures.js +76 -5
  77. package/dest/fixtures/get_acvm_config.d.ts +2 -2
  78. package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
  79. package/dest/fixtures/get_acvm_config.js +3 -15
  80. package/dest/fixtures/get_bb_config.d.ts +2 -2
  81. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  82. package/dest/fixtures/get_bb_config.js +10 -17
  83. package/dest/fixtures/ha_setup.d.ts +71 -0
  84. package/dest/fixtures/ha_setup.d.ts.map +1 -0
  85. package/dest/fixtures/ha_setup.js +116 -0
  86. package/dest/fixtures/index.d.ts +2 -1
  87. package/dest/fixtures/index.d.ts.map +1 -1
  88. package/dest/fixtures/index.js +1 -0
  89. package/dest/fixtures/l1_to_l2_messaging.d.ts +11 -7
  90. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  91. package/dest/fixtures/l1_to_l2_messaging.js +45 -19
  92. package/dest/fixtures/logging.d.ts +1 -1
  93. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts +25 -0
  94. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts.map +1 -0
  95. package/dest/fixtures/schnorr_hardcoded_account_contract.js +37 -0
  96. package/dest/fixtures/setup.d.ts +272 -0
  97. package/dest/fixtures/setup.d.ts.map +1 -0
  98. package/dest/fixtures/setup.js +735 -0
  99. package/dest/fixtures/setup_p2p_test.d.ts +28 -16
  100. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  101. package/dest/fixtures/setup_p2p_test.js +103 -32
  102. package/dest/fixtures/token_utils.d.ts +10 -4
  103. package/dest/fixtures/token_utils.d.ts.map +1 -1
  104. package/dest/fixtures/token_utils.js +30 -13
  105. package/dest/fixtures/utils.d.ts +5 -153
  106. package/dest/fixtures/utils.d.ts.map +1 -1
  107. package/dest/fixtures/utils.js +4 -552
  108. package/dest/fixtures/web3signer.d.ts +5 -0
  109. package/dest/fixtures/web3signer.d.ts.map +1 -0
  110. package/dest/fixtures/web3signer.js +53 -0
  111. package/dest/fixtures/with_telemetry_utils.d.ts +2 -2
  112. package/dest/fixtures/with_telemetry_utils.d.ts.map +1 -1
  113. package/dest/fixtures/with_telemetry_utils.js +2 -2
  114. package/dest/forward-compatibility/wallet_rpc_client.d.ts +7 -0
  115. package/dest/forward-compatibility/wallet_rpc_client.d.ts.map +1 -0
  116. package/dest/forward-compatibility/wallet_rpc_client.js +15 -0
  117. package/dest/forward-compatibility/wallet_service.d.ts +3 -0
  118. package/dest/forward-compatibility/wallet_service.d.ts.map +1 -0
  119. package/dest/forward-compatibility/wallet_service.js +109 -0
  120. package/dest/index.d.ts +1 -1
  121. package/dest/install_legacy_contracts.d.cts +10 -0
  122. package/dest/install_legacy_contracts.d.cts.map +1 -0
  123. package/dest/legacy-jest-resolver.d.cts +3 -0
  124. package/dest/legacy-jest-resolver.d.cts.map +1 -0
  125. package/dest/quality_of_service/grafana_client.d.ts +41 -0
  126. package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
  127. package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
  128. package/dest/quality_of_service/prometheus_client.d.ts +38 -0
  129. package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
  130. package/dest/quality_of_service/prometheus_client.js +67 -0
  131. package/dest/shared/cross_chain_test_harness.d.ts +46 -27
  132. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  133. package/dest/shared/cross_chain_test_harness.js +113 -55
  134. package/dest/shared/gas_portal_test_harness.d.ts +39 -28
  135. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  136. package/dest/shared/gas_portal_test_harness.js +64 -34
  137. package/dest/shared/index.d.ts +3 -2
  138. package/dest/shared/index.d.ts.map +1 -1
  139. package/dest/shared/index.js +1 -0
  140. package/dest/shared/jest_setup.d.ts +1 -1
  141. package/dest/shared/jest_setup.js +42 -2
  142. package/dest/shared/mock_state_view.d.ts +86 -0
  143. package/dest/shared/mock_state_view.d.ts.map +1 -0
  144. package/dest/shared/mock_state_view.js +186 -0
  145. package/dest/shared/submit-transactions.d.ts +6 -4
  146. package/dest/shared/submit-transactions.d.ts.map +1 -1
  147. package/dest/shared/submit-transactions.js +15 -16
  148. package/dest/shared/uniswap_l1_l2.d.ts +3 -25
  149. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  150. package/dest/shared/uniswap_l1_l2.js +202 -135
  151. package/dest/shared/wait_for_l1_to_l2_message.d.ts +13 -0
  152. package/dest/shared/wait_for_l1_to_l2_message.d.ts.map +1 -0
  153. package/dest/shared/wait_for_l1_to_l2_message.js +10 -0
  154. package/dest/simulators/index.d.ts +1 -1
  155. package/dest/simulators/lending_simulator.d.ts +16 -9
  156. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  157. package/dest/simulators/lending_simulator.js +38 -27
  158. package/dest/simulators/token_simulator.d.ts +6 -3
  159. package/dest/simulators/token_simulator.d.ts.map +1 -1
  160. package/dest/simulators/token_simulator.js +12 -30
  161. package/dest/spartan/setup_test_wallets.d.ts +36 -11
  162. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  163. package/dest/spartan/setup_test_wallets.js +301 -63
  164. package/dest/spartan/tx_metrics.d.ts +102 -0
  165. package/dest/spartan/tx_metrics.d.ts.map +1 -0
  166. package/dest/spartan/tx_metrics.js +475 -0
  167. package/dest/spartan/utils/bot.d.ts +28 -0
  168. package/dest/spartan/utils/bot.d.ts.map +1 -0
  169. package/dest/spartan/utils/bot.js +142 -0
  170. package/dest/spartan/utils/chaos.d.ts +79 -0
  171. package/dest/spartan/utils/chaos.d.ts.map +1 -0
  172. package/dest/spartan/utils/chaos.js +142 -0
  173. package/dest/spartan/utils/clients.d.ts +39 -0
  174. package/dest/spartan/utils/clients.d.ts.map +1 -0
  175. package/dest/spartan/utils/clients.js +90 -0
  176. package/dest/spartan/utils/config.d.ts +19 -0
  177. package/dest/spartan/utils/config.d.ts.map +1 -0
  178. package/dest/spartan/utils/config.js +23 -0
  179. package/dest/spartan/utils/health.d.ts +63 -0
  180. package/dest/spartan/utils/health.d.ts.map +1 -0
  181. package/dest/spartan/utils/health.js +202 -0
  182. package/dest/spartan/utils/helm.d.ts +15 -0
  183. package/dest/spartan/utils/helm.d.ts.map +1 -0
  184. package/dest/spartan/utils/helm.js +47 -0
  185. package/dest/spartan/utils/index.d.ts +11 -0
  186. package/dest/spartan/utils/index.d.ts.map +1 -0
  187. package/dest/spartan/utils/index.js +22 -0
  188. package/dest/spartan/utils/k8s.d.ts +128 -0
  189. package/dest/spartan/utils/k8s.d.ts.map +1 -0
  190. package/dest/spartan/utils/k8s.js +381 -0
  191. package/dest/spartan/utils/nodes.d.ts +40 -0
  192. package/dest/spartan/utils/nodes.d.ts.map +1 -0
  193. package/dest/spartan/utils/nodes.js +461 -0
  194. package/dest/spartan/utils/pod_logs.d.ts +25 -0
  195. package/dest/spartan/utils/pod_logs.d.ts.map +1 -0
  196. package/dest/spartan/utils/pod_logs.js +74 -0
  197. package/dest/spartan/utils/scripts.d.ts +30 -0
  198. package/dest/spartan/utils/scripts.d.ts.map +1 -0
  199. package/dest/spartan/utils/scripts.js +81 -0
  200. package/dest/spartan/utils.d.ts +2 -415
  201. package/dest/spartan/utils.d.ts.map +1 -1
  202. package/dest/spartan/utils.js +1 -445
  203. package/dest/test-wallet/test_wallet.d.ts +85 -0
  204. package/dest/test-wallet/test_wallet.d.ts.map +1 -0
  205. package/dest/test-wallet/test_wallet.js +273 -0
  206. package/dest/test-wallet/utils.d.ts +41 -0
  207. package/dest/test-wallet/utils.d.ts.map +1 -0
  208. package/dest/test-wallet/utils.js +66 -0
  209. package/dest/test-wallet/wallet_worker_script.d.ts +2 -0
  210. package/dest/test-wallet/wallet_worker_script.d.ts.map +1 -0
  211. package/dest/test-wallet/wallet_worker_script.js +53 -0
  212. package/dest/test-wallet/worker_wallet.d.ts +53 -0
  213. package/dest/test-wallet/worker_wallet.d.ts.map +1 -0
  214. package/dest/test-wallet/worker_wallet.js +155 -0
  215. package/dest/test-wallet/worker_wallet_schema.d.ts +160 -0
  216. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -0
  217. package/dest/test-wallet/worker_wallet_schema.js +22 -0
  218. package/package.json +79 -64
  219. package/src/bench/client_flows/benchmark.ts +382 -0
  220. package/src/bench/client_flows/client_flows_benchmark.ts +399 -0
  221. package/src/bench/client_flows/config.ts +69 -0
  222. package/src/bench/client_flows/data_extractor.ts +89 -0
  223. package/src/bench/utils.ts +49 -87
  224. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +164 -172
  225. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +194 -183
  226. package/src/e2e_deploy_contract/deploy_test.ts +42 -49
  227. package/src/e2e_epochs/epochs_test.ts +451 -93
  228. package/src/e2e_fees/bridging_race.notest.ts +74 -0
  229. package/src/e2e_fees/fees_test.ts +249 -262
  230. package/src/e2e_l1_publisher/write_json.ts +77 -0
  231. package/src/e2e_multi_validator/utils.ts +258 -0
  232. package/src/e2e_nested_contract/nested_contract_test.ts +51 -60
  233. package/src/e2e_p2p/inactivity_slash_test.ts +180 -0
  234. package/src/e2e_p2p/p2p_network.ts +391 -240
  235. package/src/e2e_p2p/reqresp/utils.ts +274 -0
  236. package/src/e2e_p2p/shared.ts +304 -39
  237. package/src/e2e_storage_proof/fixtures/storage_proof.json +915 -0
  238. package/src/e2e_storage_proof/fixtures/storage_proof_fetcher.ts +190 -0
  239. package/src/e2e_storage_proof/fixtures/storage_proof_fixture.ts +173 -0
  240. package/src/e2e_token_contract/token_contract_test.ts +140 -124
  241. package/src/fixtures/authwit_proxy.ts +54 -0
  242. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  243. package/src/fixtures/e2e_prover_test.ts +329 -0
  244. package/src/fixtures/elu_monitor.ts +126 -0
  245. package/src/fixtures/fixtures.ts +98 -7
  246. package/src/fixtures/get_acvm_config.ts +4 -12
  247. package/src/fixtures/get_bb_config.ts +19 -13
  248. package/src/fixtures/ha_setup.ts +188 -0
  249. package/src/fixtures/index.ts +1 -0
  250. package/src/fixtures/l1_to_l2_messaging.ts +56 -24
  251. package/src/fixtures/schnorr_hardcoded_account_contract.ts +49 -0
  252. package/src/fixtures/setup.ts +1056 -0
  253. package/src/fixtures/setup_p2p_test.ts +142 -54
  254. package/src/fixtures/token_utils.ts +34 -16
  255. package/src/fixtures/utils.ts +29 -820
  256. package/src/fixtures/web3signer.ts +63 -0
  257. package/src/fixtures/with_telemetry_utils.ts +2 -2
  258. package/src/forward-compatibility/wallet_rpc_client.ts +14 -0
  259. package/src/forward-compatibility/wallet_service.ts +104 -0
  260. package/src/guides/up_quick_start.sh +9 -19
  261. package/src/install_legacy_contracts.cjs +75 -0
  262. package/src/legacy-jest-resolver.cjs +112 -0
  263. package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +2 -2
  264. package/src/quality_of_service/prometheus_client.ts +113 -0
  265. package/src/shared/cross_chain_test_harness.ts +116 -90
  266. package/src/shared/gas_portal_test_harness.ts +75 -56
  267. package/src/shared/index.ts +2 -1
  268. package/src/shared/jest_setup.ts +52 -2
  269. package/src/shared/mock_state_view.ts +188 -0
  270. package/src/shared/submit-transactions.ts +19 -20
  271. package/src/shared/uniswap_l1_l2.ts +259 -234
  272. package/src/shared/wait_for_l1_to_l2_message.ts +23 -0
  273. package/src/simulators/lending_simulator.ts +43 -26
  274. package/src/simulators/token_simulator.ts +18 -34
  275. package/src/spartan/DEVELOP.md +128 -0
  276. package/src/spartan/setup_test_wallets.ts +420 -96
  277. package/src/spartan/tx_metrics.ts +434 -0
  278. package/src/spartan/utils/bot.ts +188 -0
  279. package/src/spartan/utils/chaos.ts +253 -0
  280. package/src/spartan/utils/clients.ts +100 -0
  281. package/src/spartan/utils/config.ts +29 -0
  282. package/src/spartan/utils/health.ts +255 -0
  283. package/src/spartan/utils/helm.ts +84 -0
  284. package/src/spartan/utils/index.ts +71 -0
  285. package/src/spartan/utils/k8s.ts +535 -0
  286. package/src/spartan/utils/nodes.ts +543 -0
  287. package/src/spartan/utils/pod_logs.ts +99 -0
  288. package/src/spartan/utils/scripts.ts +99 -0
  289. package/src/spartan/utils.ts +1 -582
  290. package/src/test-wallet/test_wallet.ts +376 -0
  291. package/src/test-wallet/utils.ts +108 -0
  292. package/src/test-wallet/wallet_worker_script.ts +63 -0
  293. package/src/test-wallet/worker_wallet.ts +218 -0
  294. package/src/test-wallet/worker_wallet_schema.ts +13 -0
  295. package/dest/e2e_prover/e2e_prover_test.d.ts +0 -56
  296. package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
  297. package/dest/e2e_prover/e2e_prover_test.js +0 -291
  298. package/dest/fixtures/setup_l1_contracts.d.ts +0 -6
  299. package/dest/fixtures/setup_l1_contracts.d.ts.map +0 -1
  300. package/dest/fixtures/setup_l1_contracts.js +0 -17
  301. package/dest/fixtures/snapshot_manager.d.ts +0 -87
  302. package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
  303. package/dest/fixtures/snapshot_manager.js +0 -479
  304. package/dest/quality_of_service/alert_checker.d.ts +0 -41
  305. package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
  306. package/dest/sample-dapp/connect.js +0 -12
  307. package/dest/sample-dapp/contracts.js +0 -10
  308. package/dest/sample-dapp/deploy.js +0 -35
  309. package/dest/sample-dapp/index.js +0 -98
  310. package/src/e2e_prover/e2e_prover_test.ts +0 -418
  311. package/src/fixtures/setup_l1_contracts.ts +0 -27
  312. package/src/fixtures/snapshot_manager.ts +0 -617
  313. package/src/sample-dapp/connect.mjs +0 -16
  314. package/src/sample-dapp/contracts.mjs +0 -14
  315. package/src/sample-dapp/deploy.mjs +0 -40
  316. package/src/sample-dapp/index.mjs +0 -128
@@ -1,11 +1,20 @@
1
- import { AztecAddress, EthAddress, Fr, computeAuthWitMessageHash, generateClaimSecret } from '@aztec/aztec.js';
2
- import { deployL1Contract, extractEvent } from '@aztec/ethereum';
3
- import { sha256ToField } from '@aztec/foundation/crypto';
4
- import { InboxAbi, RollupAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
1
+ import { AztecAddress, EthAddress } from '@aztec/aztec.js/addresses';
2
+ import { computeAuthWitMessageHash } from '@aztec/aztec.js/authorization';
3
+ import { waitForProven } from '@aztec/aztec.js/contracts';
4
+ import { generateClaimSecret } from '@aztec/aztec.js/ethereum';
5
+ import { Fr } from '@aztec/aztec.js/fields';
6
+ import { RollupContract } from '@aztec/ethereum/contracts';
7
+ import { deployL1Contract } from '@aztec/ethereum/deploy-l1-contract';
8
+ import { extractEvent } from '@aztec/ethereum/utils';
9
+ import { EpochNumber } from '@aztec/foundation/branded-types';
10
+ import { sha256ToField } from '@aztec/foundation/crypto/sha256';
11
+ import { retryUntil } from '@aztec/foundation/retry';
12
+ import { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
5
13
  import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
14
+ import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
6
15
  import { jest } from '@jest/globals';
7
16
  import { getContract, parseEther, toFunctionSelector } from 'viem';
8
- import { ensureAccountsPubliclyDeployed } from '../fixtures/utils.js';
17
+ import { ensureAccountContractsPublished, ensureAuthRegistryPublished } from '../fixtures/utils.js';
9
18
  import { CrossChainTestHarness } from './cross_chain_test_harness.js';
10
19
  // PSA: This tests works on forked mainnet. There is a dump of the data in `dumpedState` such that we
11
20
  // don't need to burn through RPC requests.
@@ -13,26 +22,20 @@ import { CrossChainTestHarness } from './cross_chain_test_harness.js';
13
22
  // To start an actual fork, use the command:
14
23
  // anvil --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c --fork-block-number 17514288 --chain-id 31337
15
24
  // For CI, this is configured in `run_tests.sh` and `docker-compose-images.yml`
16
- // docs:start:uniswap_l1_l2_test_setup_const
17
- const TIMEOUT = 360_000;
18
- // docs:end:uniswap_l1_l2_test_setup_const
25
+ const TIMEOUT = 15 * 60 * 1000;
19
26
  export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 17514288)=>{
20
- // docs:start:uniswap_l1_l2_test_beforeAll
21
27
  describe('uniswap_trade_on_l1_from_l2', ()=>{
22
28
  jest.setTimeout(TIMEOUT);
23
29
  const WETH9_ADDRESS = EthAddress.fromString('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2');
24
30
  const DAI_ADDRESS = EthAddress.fromString('0x6B175474E89094C44Da98b954EedeAC495271d0F');
25
31
  let aztecNode;
26
- let pxe;
27
32
  let logger;
28
- let walletClient;
29
- let publicClient;
30
- let ownerWallet;
33
+ let l1Client;
34
+ let wallet;
31
35
  let ownerAddress;
32
36
  let ownerEthAddress;
33
37
  // does transactions on behalf of owner on Aztec:
34
- let sponsorWallet;
35
- // let sponsorAddress: AztecAddress;
38
+ let sponsorAddress;
36
39
  let daiCrossChainHarness;
37
40
  let wethCrossChainHarness;
38
41
  let deployL1ContractsValues;
@@ -44,58 +47,58 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
44
47
  const uniswapFeeTier = 3000n;
45
48
  const minimumOutputAmount = 0n;
46
49
  let cheatCodes;
50
+ let version;
47
51
  beforeAll(async ()=>{
48
- ({ aztecNode, pxe, logger, publicClient, walletClient, ownerWallet, sponsorWallet, deployL1ContractsValues, cheatCodes } = await setup());
49
- if (Number(await publicClient.getBlockNumber()) < expectedForkBlockNumber) {
52
+ const t = await setup();
53
+ ({ aztecNode, logger, deployL1ContractsValues, cheatCodes, wallet, accounts: [ownerAddress, sponsorAddress] } = t);
54
+ l1Client = deployL1ContractsValues.l1Client;
55
+ t.watcher.setIsMarkingAsProven(false);
56
+ if (Number(await l1Client.getBlockNumber()) < expectedForkBlockNumber) {
50
57
  throw new Error('This test must be run on a fork of mainnet with the expected fork block');
51
58
  }
52
- rollup = getContract({
53
- address: deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(),
54
- abi: RollupAbi,
55
- client: deployL1ContractsValues.walletClient
56
- });
57
- ownerAddress = ownerWallet.getAddress();
58
- // sponsorAddress = sponsorWallet.getAddress();
59
- ownerEthAddress = EthAddress.fromString((await walletClient.getAddresses())[0]);
60
- await ensureAccountsPubliclyDeployed(ownerWallet, [
61
- ownerWallet,
62
- sponsorWallet
59
+ rollup = new RollupContract(deployL1ContractsValues.l1Client, deployL1ContractsValues.l1ContractAddresses.rollupAddress);
60
+ version = Number(await rollup.getVersion());
61
+ ownerEthAddress = EthAddress.fromString((await l1Client.getAddresses())[0]);
62
+ await ensureAccountContractsPublished(wallet, [
63
+ ownerAddress,
64
+ sponsorAddress
63
65
  ]);
66
+ await ensureAuthRegistryPublished(wallet, ownerAddress);
64
67
  logger.info('Deploying DAI Portal, initializing and deploying l2 contract...');
65
- daiCrossChainHarness = await CrossChainTestHarness.new(aztecNode, pxe, publicClient, walletClient, ownerWallet, logger, DAI_ADDRESS);
68
+ daiCrossChainHarness = await CrossChainTestHarness.new(aztecNode, deployL1ContractsValues.l1Client, wallet, ownerAddress, logger, DAI_ADDRESS);
66
69
  logger.info('Deploying WETH Portal, initializing and deploying l2 contract...');
67
- wethCrossChainHarness = await CrossChainTestHarness.new(aztecNode, pxe, publicClient, walletClient, ownerWallet, logger, WETH9_ADDRESS);
70
+ wethCrossChainHarness = await CrossChainTestHarness.new(aztecNode, l1Client, wallet, ownerAddress, logger, WETH9_ADDRESS);
68
71
  logger.info('Deploy Uniswap portal on L1 and L2...');
69
- uniswapPortalAddress = await deployL1Contract(walletClient, publicClient, UniswapPortalAbi, UniswapPortalBytecode).then(({ address })=>address);
72
+ uniswapPortalAddress = await deployL1Contract(l1Client, UniswapPortalAbi, UniswapPortalBytecode).then(({ address })=>address);
70
73
  uniswapPortal = getContract({
71
74
  address: uniswapPortalAddress.toString(),
72
75
  abi: UniswapPortalAbi,
73
- client: walletClient
76
+ client: l1Client
74
77
  });
75
78
  // deploy l2 uniswap contract and attach to portal
76
- uniswapL2Contract = await UniswapContract.deploy(ownerWallet, uniswapPortalAddress).send().deployed();
77
- const registryAddress = (await pxe.getNodeInfo()).l1ContractAddresses.registryAddress;
79
+ ({ contract: uniswapL2Contract } = await UniswapContract.deploy(wallet, uniswapPortalAddress).send({
80
+ from: ownerAddress
81
+ }));
82
+ const registryAddress = (await aztecNode.getNodeInfo()).l1ContractAddresses.registryAddress;
78
83
  await uniswapPortal.write.initialize([
79
84
  registryAddress.toString(),
80
85
  uniswapL2Contract.address.toString()
81
86
  ], {});
82
87
  // Give me some WETH so I can deposit to L2 and do the swap...
83
88
  logger.info('Getting some weth');
84
- const hash = await walletClient.sendTransaction({
89
+ const hash = await l1Client.sendTransaction({
85
90
  to: WETH9_ADDRESS.toString(),
86
91
  value: parseEther('1000')
87
92
  });
88
- await publicClient.waitForTransactionReceipt({
93
+ await l1Client.waitForTransactionReceipt({
89
94
  hash
90
95
  });
91
96
  const wethBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
92
97
  expect(wethBalance).toBe(parseEther('1000'));
93
98
  });
94
- // docs:end:uniswap_l1_l2_test_beforeAll
95
99
  afterAll(async ()=>{
96
100
  await cleanup();
97
101
  });
98
- // docs:start:uniswap_private
99
102
  it('should uniswap trade on L1 from L2 funds privately (swaps WETH -> DAI)', async ()=>{
100
103
  const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
101
104
  // 1. Approve and deposit weth to the portal and move to L2
@@ -114,14 +117,19 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
114
117
  // 3. Owner gives uniswap approval to transfer the funds to public to self on its behalf
115
118
  logger.info('Approving uniswap to transfer funds to public to self on my behalf');
116
119
  const nonceForWETHTransferToPublicApproval = new Fr(1n);
117
- await ownerWallet.createAuthWit({
120
+ const transferToPublicAuhtwit = await wallet.createAuthWit(ownerAddress, {
118
121
  caller: uniswapL2Contract.address,
119
122
  action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
120
123
  });
121
124
  // 4. Swap on L1 - sends L2 to L1 message to withdraw WETH to L1 and another message to swap assets.
122
125
  logger.info('Withdrawing weth to L1 and sending message to swap to dai');
123
126
  const [secretForDepositingSwappedDai, secretHashForDepositingSwappedDai] = await generateClaimSecret();
124
- const l2UniswapInteractionReceipt = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send().wait();
127
+ const { receipt: l2UniswapInteractionReceipt } = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send({
128
+ from: ownerAddress,
129
+ authWitnesses: [
130
+ transferToPublicAuhtwit
131
+ ]
132
+ });
125
133
  const swapPrivateFunction = 'swap_private(address,uint256,uint24,address,uint256,bytes32,address)';
126
134
  const swapPrivateContent = sha256ToField([
127
135
  Buffer.from(toFunctionSelector(swapPrivateFunction).substring(2), 'hex'),
@@ -133,44 +141,59 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
133
141
  secretHashForDepositingSwappedDai,
134
142
  ownerEthAddress.toBuffer32()
135
143
  ]);
136
- const swapPrivateLeaf = sha256ToField([
137
- uniswapL2Contract.address,
138
- new Fr(1),
139
- EthAddress.fromString(uniswapPortal.address).toBuffer32(),
140
- new Fr(publicClient.chain.id),
141
- swapPrivateContent
142
- ]);
144
+ const swapPrivateLeaf = computeL2ToL1MessageHash({
145
+ l2Sender: uniswapL2Contract.address,
146
+ l1Recipient: EthAddress.fromString(uniswapPortal.address),
147
+ content: swapPrivateContent,
148
+ rollupVersion: new Fr(version),
149
+ chainId: new Fr(l1Client.chain.id)
150
+ });
143
151
  const withdrawContent = sha256ToField([
144
152
  Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
145
153
  uniswapPortalAddress.toBuffer32(),
146
154
  new Fr(wethAmountToBridge),
147
155
  uniswapPortalAddress.toBuffer32()
148
156
  ]);
149
- const withdrawLeaf = sha256ToField([
150
- wethCrossChainHarness.l2Bridge.address,
151
- new Fr(1),
152
- wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
153
- new Fr(publicClient.chain.id),
154
- withdrawContent
155
- ]);
157
+ const withdrawLeaf = computeL2ToL1MessageHash({
158
+ l2Sender: wethCrossChainHarness.l2Bridge.address,
159
+ l1Recipient: wethCrossChainHarness.tokenPortalAddress,
160
+ content: withdrawContent,
161
+ rollupVersion: new Fr(version),
162
+ chainId: new Fr(l1Client.chain.id)
163
+ });
156
164
  // ensure that user's funds were burnt
157
165
  await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
158
166
  // ensure that uniswap contract didn't eat the funds.
159
167
  await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n);
160
- // Since the outbox is only consumable when the block is proven, we need to set the block to be proven
161
- await cheatCodes.rollup.markAsProven(await rollup.read.getPendingBlockNumber());
168
+ // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch
169
+ // before we can ask the witness helper for a covering root.
170
+ const minedReceipt = await aztecNode.getTxReceipt(l2UniswapInteractionReceipt.txHash);
171
+ if (minedReceipt.epochNumber === undefined) {
172
+ throw new Error('L2 Uniswap interaction tx is not yet in an epoch');
173
+ }
174
+ await cheatCodes.rollup.advanceToEpoch(EpochNumber(minedReceipt.epochNumber + 1));
175
+ await waitForProven(aztecNode, l2UniswapInteractionReceipt, {
176
+ provenTimeout: 300
177
+ });
162
178
  // 5. Consume L2 to L1 message by calling uniswapPortal.swap_private()
163
179
  logger.info('Execute withdraw and swap on the uniswapPortal!');
164
180
  const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf(daiCrossChainHarness.tokenPortalAddress);
165
- const [swapPrivateL2MessageIndex, swapPrivateSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(l2UniswapInteractionReceipt.blockNumber, swapPrivateLeaf);
166
- const [withdrawL2MessageIndex, withdrawSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(l2UniswapInteractionReceipt.blockNumber, withdrawLeaf);
181
+ const swapResult = await retryUntil(()=>aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, swapPrivateLeaf), 'swap private l2 to l1 witness', 60, 1);
182
+ const { epochNumber: epoch, numCheckpointsInEpoch } = swapResult;
183
+ const withdrawResult = await retryUntil(()=>aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, withdrawLeaf), 'withdraw l2 to l1 witness', 60, 1);
184
+ const swapPrivateL2MessageIndex = swapResult.leafIndex;
185
+ const swapPrivateSiblingPath = swapResult.siblingPath;
186
+ const withdrawL2MessageIndex = withdrawResult.leafIndex;
187
+ const withdrawSiblingPath = withdrawResult.siblingPath;
167
188
  const withdrawMessageMetadata = {
168
- _l2BlockNumber: BigInt(l2UniswapInteractionReceipt.blockNumber),
189
+ _epoch: BigInt(epoch),
190
+ _numCheckpointsInEpoch: BigInt(withdrawResult.numCheckpointsInEpoch),
169
191
  _leafIndex: BigInt(withdrawL2MessageIndex),
170
192
  _path: withdrawSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
171
193
  };
172
194
  const swapPrivateMessageMetadata = {
173
- _l2BlockNumber: BigInt(l2UniswapInteractionReceipt.blockNumber),
195
+ _epoch: BigInt(epoch),
196
+ _numCheckpointsInEpoch: BigInt(numCheckpointsInEpoch),
174
197
  _leafIndex: BigInt(swapPrivateL2MessageIndex),
175
198
  _path: swapPrivateSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
176
199
  };
@@ -188,7 +211,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
188
211
  ]
189
212
  ];
190
213
  // this should also insert a message into the inbox.
191
- const txReceipt = await daiCrossChainHarness.publicClient.waitForTransactionReceipt({
214
+ const txReceipt = await daiCrossChainHarness.l1Client.waitForTransactionReceipt({
192
215
  hash: await uniswapPortal.write.swapPrivate(swapArgs)
193
216
  });
194
217
  // We get the msg leaf from event so that we can later wait for it to be available for consumption
@@ -219,9 +242,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
219
242
  logger.info('WETH balance after swap : ', wethL2BalanceAfterSwap.toString());
220
243
  logger.info('DAI balance after swap : ', daiL2BalanceAfterSwap.toString());
221
244
  });
222
- // docs:end:uniswap_private
223
245
  // TODO(#7463): reenable look into this failure https://github.com/AztecProtocol/aztec-packages/actions/runs/9912612912/job/27388320150?pr=7462
224
- // // docs:start:uniswap_public
225
246
  // it('should uniswap trade on L1 from L2 funds publicly (swaps WETH -> DAI)', async () => {
226
247
  // const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
227
248
  // // 1. Approve and deposit weth to the portal and move to L2
@@ -297,9 +318,9 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
297
318
  // ownerEthAddress,
298
319
  // nonceForSwap,
299
320
  // );
300
- // await ownerWallet.setPublicAuthWit({ caller: sponsorAddress, action }, true).send().wait();
321
+ // await ownerWallet.setPublicAuthWit({ caller: sponsorAddress, action }, true).send();
301
322
  // // 4.2 Call swap_public from user2 on behalf of owner
302
- // const uniswapL2Interaction = await action.send().wait();
323
+ // const uniswapL2Interaction = await action.send();
303
324
  // const swapPublicContent = sha256ToField([
304
325
  // Buffer.from(
305
326
  // toFunctionSelector('swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)').substring(
@@ -352,14 +373,14 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
352
373
  // withdrawLeaf,
353
374
  // );
354
375
  // const withdrawMessageMetadata = {
355
- // _l2BlockNumber: BigInt(uniswapL2Interaction.blockNumber!),
376
+ // _epoch: epoch,
356
377
  // _leafIndex: BigInt(withdrawL2MessageIndex),
357
378
  // _path: withdrawSiblingPath
358
379
  // .toBufferArray()
359
380
  // .map((buf: Buffer) => `0x${buf.toString('hex')}`) as readonly `0x${string}`[],
360
381
  // };
361
382
  // const swapPrivateMessageMetadata = {
362
- // _l2BlockNumber: BigInt(uniswapL2Interaction.blockNumber!),
383
+ // _epoch: epoch,
363
384
  // _leafIndex: BigInt(swapPrivateL2MessageIndex),
364
385
  // _path: swapPrivateSiblingPath
365
386
  // .toBufferArray()
@@ -424,7 +445,6 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
424
445
  // logger.info('WETH balance after swap : ', wethL2BalanceAfterSwap.toString());
425
446
  // logger.info('DAI balance after swap : ', daiL2BalanceAfterSwap.toString());
426
447
  // });
427
- // // docs:end:uniswap_public
428
448
  // Edge cases for the private flow:
429
449
  // note - tests for uniswapPortal.sol and minting asset on L2 are covered in other tests.
430
450
  it('swap_private reverts without transfer to public approval', async ()=>{
@@ -432,12 +452,11 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
432
452
  const nonceForWETHTransferToPublicApproval = new Fr(2n);
433
453
  const expectedMessageHash = await computeAuthWitMessageHash({
434
454
  caller: uniswapL2Contract.address,
435
- action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
436
- }, {
437
- chainId: ownerWallet.getChainId(),
438
- version: ownerWallet.getVersion()
439
- });
440
- await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).prove()).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`);
455
+ call: await wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval).getFunctionCall()
456
+ }, await wallet.getChainInfo());
457
+ await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).simulate({
458
+ from: ownerAddress
459
+ })).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`);
441
460
  });
442
461
  it("can't swap if user passes a token different to what the bridge tracks", async ()=>{
443
462
  // 1. give user private funds on L2:
@@ -446,13 +465,18 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
446
465
  // 2. owner gives uniswap approval to transfer the funds to public:
447
466
  logger.info('Approving uniswap to transfer funds to public to self on my behalf');
448
467
  const nonceForWETHTransferToPublicApproval = new Fr(3n);
449
- await ownerWallet.createAuthWit({
468
+ const transferToPublicAuthwith = await wallet.createAuthWit(ownerAddress, {
450
469
  caller: uniswapL2Contract.address,
451
470
  action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
452
471
  });
453
472
  // 3. Swap but send the wrong token address
454
473
  logger.info('Swap but send the wrong token address');
455
- await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, daiCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).prove()).rejects.toThrow('Assertion failed: input_asset address is not the same as seen in the bridge contract');
474
+ await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, daiCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).send({
475
+ from: ownerAddress,
476
+ authWitnesses: [
477
+ transferToPublicAuthwith
478
+ ]
479
+ })).rejects.toThrow('Assertion failed: input_asset address is not the same as seen in the bridge contract');
456
480
  });
457
481
  // edge cases for public flow:
458
482
  it("I don't need approval to call swap_public if I'm swapping on my own behalf", async ()=>{
@@ -460,14 +484,16 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
460
484
  await wethCrossChainHarness.mintTokensPublicOnL2(wethAmountToBridge);
461
485
  // 2. Give approval to uniswap to transfer funds to itself
462
486
  const nonceForWETHTransferApproval = new Fr(2n);
463
- const validateActionInteraction = await ownerWallet.setPublicAuthWit({
487
+ const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
464
488
  caller: uniswapL2Contract.address,
465
489
  action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
466
490
  }, true);
467
- await validateActionInteraction.send().wait();
491
+ await validateActionInteraction.send();
468
492
  // No approval to call `swap` but should work even without it:
469
493
  const [_, secretHashForDepositingSwappedDai] = await generateClaimSecret();
470
- await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send().wait();
494
+ await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send({
495
+ from: ownerAddress
496
+ });
471
497
  // check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
472
498
  await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
473
499
  });
@@ -477,23 +503,27 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
477
503
  const nonceForWETHTransferApproval = new Fr(3n);
478
504
  const nonceForSwap = new Fr(3n);
479
505
  const secretHashForDepositingSwappedDai = new Fr(4n);
480
- const action = uniswapL2Contract.withWallet(sponsorWallet).methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, nonceForSwap);
481
- const validateActionInteraction = await ownerWallet.setPublicAuthWit({
506
+ const action = uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, nonceForSwap);
507
+ const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
482
508
  caller: approvedUser,
483
509
  action
484
510
  }, true);
485
- await validateActionInteraction.send().wait();
486
- await expect(action.simulate()).rejects.toThrow(/unauthorized/);
511
+ await validateActionInteraction.send();
512
+ await expect(action.simulate({
513
+ from: sponsorAddress
514
+ })).rejects.toThrow(/unauthorized/);
487
515
  });
488
516
  it("uniswap can't pull funds without transfer approval", async ()=>{
489
517
  // swap should fail since no transfer approval to uniswap:
490
518
  const nonceForWETHTransferApproval = new Fr(4n);
491
- const validateActionInteraction = await ownerWallet.setPublicAuthWit({
519
+ const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
492
520
  caller: uniswapL2Contract.address,
493
521
  action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
494
522
  }, true);
495
- await validateActionInteraction.send().wait();
496
- await expect(uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, new Fr(420), uniswapFeeTier, minimumOutputAmount, ownerAddress, Fr.random(), ownerEthAddress, Fr.ZERO).simulate()).rejects.toThrow(/unauthorized/);
523
+ await validateActionInteraction.send();
524
+ await expect(uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, new Fr(420), uniswapFeeTier, minimumOutputAmount, ownerAddress, Fr.random(), ownerEthAddress, Fr.ZERO).simulate({
525
+ from: ownerAddress
526
+ })).rejects.toThrow(/unauthorized/);
497
527
  });
498
528
  // tests when trying to mix private and public flows:
499
529
  it("can't call swap_public on L1 if called swap_private on L2", async ()=>{
@@ -503,7 +533,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
503
533
  // Owner gives uniswap approval to transfer the funds to public to self on its behalf
504
534
  logger.info('Approving uniswap to transfer the funds to public to self on my behalf');
505
535
  const nonceForWETHTransferToPublicApproval = new Fr(4n);
506
- await ownerWallet.createAuthWit({
536
+ const transferToPublicAuhtwit = await wallet.createAuthWit(ownerAddress, {
507
537
  caller: uniswapL2Contract.address,
508
538
  action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
509
539
  });
@@ -511,7 +541,12 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
511
541
  // Swap
512
542
  logger.info('Withdrawing weth to L1 and sending message to swap to dai');
513
543
  const [, secretHashForDepositingSwappedDai] = await generateClaimSecret();
514
- const withdrawReceipt = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send().wait();
544
+ const { receipt: withdrawReceipt } = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send({
545
+ from: ownerAddress,
546
+ authWitnesses: [
547
+ transferToPublicAuhtwit
548
+ ]
549
+ });
515
550
  const swapPrivateContent = sha256ToField([
516
551
  Buffer.from(toFunctionSelector('swap_private(address,uint256,uint24,address,uint256,bytes32,address)').substring(2), 'hex'),
517
552
  wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
@@ -522,42 +557,57 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
522
557
  secretHashForDepositingSwappedDai,
523
558
  ownerEthAddress.toBuffer32()
524
559
  ]);
525
- const swapPrivateLeaf = sha256ToField([
526
- uniswapL2Contract.address,
527
- new Fr(1),
528
- EthAddress.fromString(uniswapPortal.address).toBuffer32(),
529
- new Fr(publicClient.chain.id),
530
- swapPrivateContent
531
- ]);
560
+ const swapPrivateLeaf = computeL2ToL1MessageHash({
561
+ l2Sender: uniswapL2Contract.address,
562
+ l1Recipient: EthAddress.fromString(uniswapPortal.address),
563
+ content: swapPrivateContent,
564
+ rollupVersion: new Fr(version),
565
+ chainId: new Fr(l1Client.chain.id)
566
+ });
532
567
  const withdrawContent = sha256ToField([
533
568
  Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
534
569
  uniswapPortalAddress.toBuffer32(),
535
570
  new Fr(wethAmountToBridge),
536
571
  uniswapPortalAddress.toBuffer32()
537
572
  ]);
538
- const withdrawLeaf = sha256ToField([
539
- wethCrossChainHarness.l2Bridge.address,
540
- new Fr(1),
541
- wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
542
- new Fr(publicClient.chain.id),
543
- withdrawContent
544
- ]);
545
- const [swapPrivateL2MessageIndex, swapPrivateSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(withdrawReceipt.blockNumber, swapPrivateLeaf);
546
- const [withdrawL2MessageIndex, withdrawSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(withdrawReceipt.blockNumber, withdrawLeaf);
573
+ const withdrawLeaf = computeL2ToL1MessageHash({
574
+ l2Sender: wethCrossChainHarness.l2Bridge.address,
575
+ l1Recipient: wethCrossChainHarness.tokenPortalAddress,
576
+ content: withdrawContent,
577
+ rollupVersion: new Fr(version),
578
+ chainId: new Fr(l1Client.chain.id)
579
+ });
580
+ // ensure that user's funds were burnt
581
+ await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
582
+ // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch
583
+ // before we can ask the witness helper for a covering root.
584
+ const minedReceipt = await aztecNode.getTxReceipt(withdrawReceipt.txHash);
585
+ if (minedReceipt.epochNumber === undefined) {
586
+ throw new Error('Withdraw tx is not yet in an epoch');
587
+ }
588
+ await cheatCodes.rollup.advanceToEpoch(EpochNumber(minedReceipt.epochNumber + 1));
589
+ await waitForProven(aztecNode, withdrawReceipt, {
590
+ provenTimeout: 300
591
+ });
592
+ const swapResult = await retryUntil(()=>aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, swapPrivateLeaf), 'swap private l2 to l1 witness', 60, 1);
593
+ const { epochNumber: epoch, numCheckpointsInEpoch } = swapResult;
594
+ const withdrawResult = await retryUntil(()=>aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, withdrawLeaf), 'withdraw l2 to l1 witness', 60, 1);
595
+ const swapPrivateL2MessageIndex = swapResult.leafIndex;
596
+ const swapPrivateSiblingPath = swapResult.siblingPath;
597
+ const withdrawL2MessageIndex = withdrawResult.leafIndex;
598
+ const withdrawSiblingPath = withdrawResult.siblingPath;
547
599
  const withdrawMessageMetadata = {
548
- _l2BlockNumber: BigInt(withdrawReceipt.blockNumber),
600
+ _epoch: BigInt(epoch),
601
+ _numCheckpointsInEpoch: BigInt(withdrawResult.numCheckpointsInEpoch),
549
602
  _leafIndex: BigInt(withdrawL2MessageIndex),
550
603
  _path: withdrawSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
551
604
  };
552
605
  const swapPrivateMessageMetadata = {
553
- _l2BlockNumber: BigInt(withdrawReceipt.blockNumber),
606
+ _epoch: BigInt(epoch),
607
+ _numCheckpointsInEpoch: BigInt(numCheckpointsInEpoch),
554
608
  _leafIndex: BigInt(swapPrivateL2MessageIndex),
555
609
  _path: swapPrivateSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
556
610
  };
557
- // ensure that user's funds were burnt
558
- await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
559
- // Since the outbox is only consumable when the block is proven, we need to set the block to be proven
560
- await cheatCodes.rollup.markAsProven(await rollup.read.getPendingBlockNumber());
561
611
  // On L1 call swap_public!
562
612
  logger.info('call swap_public on L1');
563
613
  const swapArgs = [
@@ -583,14 +633,16 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
583
633
  await wethCrossChainHarness.mintTokensPublicOnL2(wethAmountToBridge);
584
634
  // Owner gives uniswap approval to transfer funds on its behalf
585
635
  const nonceForWETHTransferApproval = new Fr(5n);
586
- const validateActionInteraction = await ownerWallet.setPublicAuthWit({
636
+ const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
587
637
  caller: uniswapL2Contract.address,
588
638
  action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
589
639
  }, true);
590
- await validateActionInteraction.send().wait();
640
+ await validateActionInteraction.send();
591
641
  // Call swap_public on L2
592
642
  const secretHashForDepositingSwappedDai = Fr.random();
593
- const withdrawReceipt = await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send().wait();
643
+ const { receipt: withdrawReceipt } = await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send({
644
+ from: ownerAddress
645
+ });
594
646
  const swapPublicContent = sha256ToField([
595
647
  Buffer.from(toFunctionSelector('swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)').substring(2), 'hex'),
596
648
  wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
@@ -602,42 +654,57 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
602
654
  secretHashForDepositingSwappedDai,
603
655
  ownerEthAddress.toBuffer32()
604
656
  ]);
605
- const swapPublicLeaf = sha256ToField([
606
- uniswapL2Contract.address,
607
- new Fr(1),
608
- EthAddress.fromString(uniswapPortal.address).toBuffer32(),
609
- new Fr(publicClient.chain.id),
610
- swapPublicContent
611
- ]);
657
+ const swapPublicLeaf = computeL2ToL1MessageHash({
658
+ l2Sender: uniswapL2Contract.address,
659
+ l1Recipient: EthAddress.fromString(uniswapPortal.address),
660
+ content: swapPublicContent,
661
+ rollupVersion: new Fr(version),
662
+ chainId: new Fr(l1Client.chain.id)
663
+ });
612
664
  const withdrawContent = sha256ToField([
613
665
  Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
614
666
  uniswapPortalAddress.toBuffer32(),
615
667
  new Fr(wethAmountToBridge),
616
668
  uniswapPortalAddress.toBuffer32()
617
669
  ]);
618
- const withdrawLeaf = sha256ToField([
619
- wethCrossChainHarness.l2Bridge.address,
620
- new Fr(1),
621
- wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
622
- new Fr(publicClient.chain.id),
623
- withdrawContent
624
- ]);
625
- const [swapPublicL2MessageIndex, swapPublicSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(withdrawReceipt.blockNumber, swapPublicLeaf);
626
- const [withdrawL2MessageIndex, withdrawSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(withdrawReceipt.blockNumber, withdrawLeaf);
670
+ const withdrawLeaf = computeL2ToL1MessageHash({
671
+ l2Sender: wethCrossChainHarness.l2Bridge.address,
672
+ l1Recipient: wethCrossChainHarness.tokenPortalAddress,
673
+ content: withdrawContent,
674
+ rollupVersion: new Fr(version),
675
+ chainId: new Fr(l1Client.chain.id)
676
+ });
677
+ // check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
678
+ await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
679
+ // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch
680
+ // before we can ask the witness helper for a covering root.
681
+ const minedReceipt = await aztecNode.getTxReceipt(withdrawReceipt.txHash);
682
+ if (minedReceipt.epochNumber === undefined) {
683
+ throw new Error('Withdraw tx is not yet in an epoch');
684
+ }
685
+ await cheatCodes.rollup.advanceToEpoch(EpochNumber(minedReceipt.epochNumber + 1));
686
+ await waitForProven(aztecNode, withdrawReceipt, {
687
+ provenTimeout: 300
688
+ });
689
+ const swapResult = await retryUntil(()=>aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, swapPublicLeaf), 'swap public l2 to l1 witness', 60, 1);
690
+ const { epochNumber: epoch, numCheckpointsInEpoch } = swapResult;
691
+ const withdrawResult = await retryUntil(()=>aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, withdrawLeaf), 'withdraw l2 to l1 witness', 60, 1);
692
+ const swapPublicL2MessageIndex = swapResult.leafIndex;
693
+ const swapPublicSiblingPath = swapResult.siblingPath;
694
+ const withdrawL2MessageIndex = withdrawResult.leafIndex;
695
+ const withdrawSiblingPath = withdrawResult.siblingPath;
627
696
  const withdrawMessageMetadata = {
628
- _l2BlockNumber: BigInt(withdrawReceipt.blockNumber),
697
+ _epoch: BigInt(epoch),
698
+ _numCheckpointsInEpoch: BigInt(withdrawResult.numCheckpointsInEpoch),
629
699
  _leafIndex: BigInt(withdrawL2MessageIndex),
630
700
  _path: withdrawSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
631
701
  };
632
702
  const swapPublicMessageMetadata = {
633
- _l2BlockNumber: BigInt(withdrawReceipt.blockNumber),
703
+ _epoch: BigInt(epoch),
704
+ _numCheckpointsInEpoch: BigInt(numCheckpointsInEpoch),
634
705
  _leafIndex: BigInt(swapPublicL2MessageIndex),
635
706
  _path: swapPublicSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
636
707
  };
637
- // check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
638
- await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
639
- // Since the outbox is only consumable when the block is proven, we need to set the block to be proven
640
- await cheatCodes.rollup.markAsProven(await rollup.read.getPendingBlockNumber());
641
708
  // Call swap_private on L1
642
709
  logger.info('Execute withdraw and swap on the uniswapPortal!');
643
710
  const swapArgs = [
@@ -0,0 +1,13 @@
1
+ import type { Fr } from '@aztec/aztec.js/fields';
2
+ import type { AztecNode } from '@aztec/aztec.js/node';
3
+ /**
4
+ * Waits until the archiver has seen the L1 to L2 message and indexed it. Unlike
5
+ * {@link waitForL1ToL2MessageReady} from `@aztec/aztec.js/messaging`, this does not
6
+ * require the L2 chain to have advanced to the message's checkpoint — it only confirms
7
+ * the message has been picked up from L1. Use this in tests that explicitly produce L2
8
+ * blocks afterwards to make the message consumable.
9
+ */
10
+ export declare function waitForL1ToL2MessageSeen(node: Pick<AztecNode, 'getL1ToL2MessageCheckpoint'>, l1ToL2MessageHash: Fr, opts: {
11
+ timeoutSeconds: number;
12
+ }): Promise<boolean>;
13
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2FpdF9mb3JfbDFfdG9fbDJfbWVzc2FnZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3NoYXJlZC93YWl0X2Zvcl9sMV90b19sMl9tZXNzYWdlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLEVBQUUsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQ2pELE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBR3REOzs7Ozs7R0FNRztBQUNILHdCQUFnQix3QkFBd0IsQ0FDdEMsSUFBSSxFQUFFLElBQUksQ0FBQyxTQUFTLEVBQUUsNEJBQTRCLENBQUMsRUFDbkQsaUJBQWlCLEVBQUUsRUFBRSxFQUNyQixJQUFJLEVBQUU7SUFBRSxjQUFjLEVBQUUsTUFBTSxDQUFBO0NBQUUsb0JBUWpDIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait_for_l1_to_l2_message.d.ts","sourceRoot":"","sources":["../../src/shared/wait_for_l1_to_l2_message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,4BAA4B,CAAC,EACnD,iBAAiB,EAAE,EAAE,EACrB,IAAI,EAAE;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,oBAQjC"}
@@ -0,0 +1,10 @@
1
+ import { retryUntil } from '@aztec/foundation/retry';
2
+ /**
3
+ * Waits until the archiver has seen the L1 to L2 message and indexed it. Unlike
4
+ * {@link waitForL1ToL2MessageReady} from `@aztec/aztec.js/messaging`, this does not
5
+ * require the L2 chain to have advanced to the message's checkpoint — it only confirms
6
+ * the message has been picked up from L1. Use this in tests that explicitly produce L2
7
+ * blocks afterwards to make the message consumable.
8
+ */ export function waitForL1ToL2MessageSeen(node, l1ToL2MessageHash, opts) {
9
+ return retryUntil(async ()=>await node.getL1ToL2MessageCheckpoint(l1ToL2MessageHash) !== undefined, `L1 to L2 message ${l1ToL2MessageHash.toString()} seen`, opts.timeoutSeconds, 1);
10
+ }