@aztec/end-to-end 0.0.0-test.0 → 0.0.1-commit.001888fc

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 (293) hide show
  1. package/dest/bench/client_flows/benchmark.d.ts +62 -0
  2. package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
  3. package/dest/bench/client_flows/benchmark.js +281 -0
  4. package/dest/bench/client_flows/client_flows_benchmark.d.ts +79 -0
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
  6. package/dest/bench/client_flows/client_flows_benchmark.js +329 -0
  7. package/dest/bench/client_flows/config.d.ts +14 -0
  8. package/dest/bench/client_flows/config.d.ts.map +1 -0
  9. package/dest/bench/client_flows/config.js +124 -0
  10. package/dest/bench/client_flows/data_extractor.d.ts +2 -0
  11. package/dest/bench/client_flows/data_extractor.d.ts.map +1 -0
  12. package/dest/bench/client_flows/data_extractor.js +79 -0
  13. package/dest/bench/utils.d.ts +16 -41
  14. package/dest/bench/utils.d.ts.map +1 -1
  15. package/dest/bench/utils.js +44 -72
  16. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +28 -19
  17. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  18. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +125 -103
  19. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +32 -32
  20. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  21. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +105 -104
  22. package/dest/e2e_deploy_contract/deploy_test.d.ts +19 -10
  23. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  24. package/dest/e2e_deploy_contract/deploy_test.js +26 -27
  25. package/dest/e2e_epochs/epochs_test.d.ts +75 -24
  26. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  27. package/dest/e2e_epochs/epochs_test.js +290 -58
  28. package/dest/e2e_fees/bridging_race.notest.d.ts +2 -0
  29. package/dest/e2e_fees/bridging_race.notest.d.ts.map +1 -0
  30. package/dest/e2e_fees/bridging_race.notest.js +61 -0
  31. package/dest/e2e_fees/fees_test.d.ts +38 -23
  32. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  33. package/dest/e2e_fees/fees_test.js +169 -183
  34. package/dest/e2e_l1_publisher/write_json.d.ts +11 -0
  35. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
  36. package/dest/e2e_l1_publisher/write_json.js +56 -0
  37. package/dest/e2e_multi_validator/utils.d.ts +12 -0
  38. package/dest/e2e_multi_validator/utils.d.ts.map +1 -0
  39. package/dest/e2e_multi_validator/utils.js +214 -0
  40. package/dest/e2e_nested_contract/nested_contract_test.d.ts +15 -15
  41. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  42. package/dest/e2e_nested_contract/nested_contract_test.js +36 -42
  43. package/dest/e2e_p2p/inactivity_slash_test.d.ts +31 -0
  44. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -0
  45. package/dest/e2e_p2p/inactivity_slash_test.js +136 -0
  46. package/dest/e2e_p2p/p2p_network.d.ts +282 -27
  47. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  48. package/dest/e2e_p2p/p2p_network.js +255 -176
  49. package/dest/e2e_p2p/reqresp/utils.d.ts +22 -0
  50. package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -0
  51. package/dest/e2e_p2p/reqresp/utils.js +190 -0
  52. package/dest/e2e_p2p/shared.d.ts +64 -8
  53. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  54. package/dest/e2e_p2p/shared.js +200 -27
  55. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +2 -0
  56. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +1 -0
  57. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.js +184 -0
  58. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts +18 -0
  59. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +1 -0
  60. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.js +120 -0
  61. package/dest/e2e_token_contract/token_contract_test.d.ts +29 -14
  62. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  63. package/dest/e2e_token_contract/token_contract_test.js +107 -75
  64. package/dest/fixtures/authwit_proxy.d.ts +15 -0
  65. package/dest/fixtures/authwit_proxy.d.ts.map +1 -0
  66. package/dest/fixtures/authwit_proxy.js +30 -0
  67. package/dest/fixtures/e2e_prover_test.d.ts +55 -0
  68. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
  69. package/dest/fixtures/e2e_prover_test.js +271 -0
  70. package/dest/fixtures/elu_monitor.d.ts +21 -0
  71. package/dest/fixtures/elu_monitor.d.ts.map +1 -0
  72. package/dest/fixtures/elu_monitor.js +102 -0
  73. package/dest/fixtures/fixtures.d.ts +10 -8
  74. package/dest/fixtures/fixtures.d.ts.map +1 -1
  75. package/dest/fixtures/fixtures.js +11 -5
  76. package/dest/fixtures/get_acvm_config.d.ts +2 -2
  77. package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
  78. package/dest/fixtures/get_acvm_config.js +3 -15
  79. package/dest/fixtures/get_bb_config.d.ts +2 -2
  80. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  81. package/dest/fixtures/get_bb_config.js +10 -17
  82. package/dest/fixtures/ha_setup.d.ts +71 -0
  83. package/dest/fixtures/ha_setup.d.ts.map +1 -0
  84. package/dest/fixtures/ha_setup.js +116 -0
  85. package/dest/fixtures/index.d.ts +2 -1
  86. package/dest/fixtures/index.d.ts.map +1 -1
  87. package/dest/fixtures/index.js +1 -0
  88. package/dest/fixtures/l1_to_l2_messaging.d.ts +11 -7
  89. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  90. package/dest/fixtures/l1_to_l2_messaging.js +45 -19
  91. package/dest/fixtures/logging.d.ts +1 -1
  92. package/dest/fixtures/setup.d.ts +239 -0
  93. package/dest/fixtures/setup.d.ts.map +1 -0
  94. package/dest/fixtures/setup.js +606 -0
  95. package/dest/fixtures/setup_p2p_test.d.ts +23 -15
  96. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  97. package/dest/fixtures/setup_p2p_test.js +102 -31
  98. package/dest/fixtures/token_utils.d.ts +10 -4
  99. package/dest/fixtures/token_utils.d.ts.map +1 -1
  100. package/dest/fixtures/token_utils.js +33 -13
  101. package/dest/fixtures/utils.d.ts +5 -153
  102. package/dest/fixtures/utils.d.ts.map +1 -1
  103. package/dest/fixtures/utils.js +4 -552
  104. package/dest/fixtures/web3signer.d.ts +5 -0
  105. package/dest/fixtures/web3signer.d.ts.map +1 -0
  106. package/dest/fixtures/web3signer.js +53 -0
  107. package/dest/fixtures/with_telemetry_utils.d.ts +2 -2
  108. package/dest/fixtures/with_telemetry_utils.d.ts.map +1 -1
  109. package/dest/fixtures/with_telemetry_utils.js +2 -2
  110. package/dest/index.d.ts +1 -1
  111. package/dest/quality_of_service/grafana_client.d.ts +41 -0
  112. package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
  113. package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
  114. package/dest/quality_of_service/prometheus_client.d.ts +38 -0
  115. package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
  116. package/dest/quality_of_service/prometheus_client.js +67 -0
  117. package/dest/shared/cross_chain_test_harness.d.ts +44 -27
  118. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  119. package/dest/shared/cross_chain_test_harness.js +107 -53
  120. package/dest/shared/gas_portal_test_harness.d.ts +33 -25
  121. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  122. package/dest/shared/gas_portal_test_harness.js +51 -30
  123. package/dest/shared/index.d.ts +3 -2
  124. package/dest/shared/index.d.ts.map +1 -1
  125. package/dest/shared/index.js +1 -0
  126. package/dest/shared/jest_setup.d.ts +1 -1
  127. package/dest/shared/jest_setup.js +42 -2
  128. package/dest/shared/mock_state_view.d.ts +86 -0
  129. package/dest/shared/mock_state_view.d.ts.map +1 -0
  130. package/dest/shared/mock_state_view.js +186 -0
  131. package/dest/shared/submit-transactions.d.ts +6 -4
  132. package/dest/shared/submit-transactions.d.ts.map +1 -1
  133. package/dest/shared/submit-transactions.js +15 -16
  134. package/dest/shared/uniswap_l1_l2.d.ts +3 -25
  135. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  136. package/dest/shared/uniswap_l1_l2.js +175 -126
  137. package/dest/simulators/index.d.ts +1 -1
  138. package/dest/simulators/lending_simulator.d.ts +7 -7
  139. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  140. package/dest/simulators/lending_simulator.js +17 -18
  141. package/dest/simulators/token_simulator.d.ts +6 -3
  142. package/dest/simulators/token_simulator.d.ts.map +1 -1
  143. package/dest/simulators/token_simulator.js +12 -30
  144. package/dest/spartan/setup_test_wallets.d.ts +36 -11
  145. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  146. package/dest/spartan/setup_test_wallets.js +276 -62
  147. package/dest/spartan/tx_metrics.d.ts +88 -0
  148. package/dest/spartan/tx_metrics.d.ts.map +1 -0
  149. package/dest/spartan/tx_metrics.js +422 -0
  150. package/dest/spartan/utils/bot.d.ts +28 -0
  151. package/dest/spartan/utils/bot.d.ts.map +1 -0
  152. package/dest/spartan/utils/bot.js +142 -0
  153. package/dest/spartan/utils/chaos.d.ts +79 -0
  154. package/dest/spartan/utils/chaos.d.ts.map +1 -0
  155. package/dest/spartan/utils/chaos.js +142 -0
  156. package/dest/spartan/utils/clients.d.ts +39 -0
  157. package/dest/spartan/utils/clients.d.ts.map +1 -0
  158. package/dest/spartan/utils/clients.js +90 -0
  159. package/dest/spartan/utils/config.d.ts +45 -0
  160. package/dest/spartan/utils/config.d.ts.map +1 -0
  161. package/dest/spartan/utils/config.js +23 -0
  162. package/dest/spartan/utils/health.d.ts +63 -0
  163. package/dest/spartan/utils/health.d.ts.map +1 -0
  164. package/dest/spartan/utils/health.js +202 -0
  165. package/dest/spartan/utils/helm.d.ts +15 -0
  166. package/dest/spartan/utils/helm.d.ts.map +1 -0
  167. package/dest/spartan/utils/helm.js +47 -0
  168. package/dest/spartan/utils/index.d.ts +11 -0
  169. package/dest/spartan/utils/index.d.ts.map +1 -0
  170. package/dest/spartan/utils/index.js +22 -0
  171. package/dest/spartan/utils/k8s.d.ts +128 -0
  172. package/dest/spartan/utils/k8s.d.ts.map +1 -0
  173. package/dest/spartan/utils/k8s.js +381 -0
  174. package/dest/spartan/utils/nodes.d.ts +40 -0
  175. package/dest/spartan/utils/nodes.d.ts.map +1 -0
  176. package/dest/spartan/utils/nodes.js +461 -0
  177. package/dest/spartan/utils/pod_logs.d.ts +25 -0
  178. package/dest/spartan/utils/pod_logs.d.ts.map +1 -0
  179. package/dest/spartan/utils/pod_logs.js +74 -0
  180. package/dest/spartan/utils/scripts.d.ts +30 -0
  181. package/dest/spartan/utils/scripts.d.ts.map +1 -0
  182. package/dest/spartan/utils/scripts.js +81 -0
  183. package/dest/spartan/utils.d.ts +2 -415
  184. package/dest/spartan/utils.d.ts.map +1 -1
  185. package/dest/spartan/utils.js +1 -445
  186. package/dest/test-wallet/test_wallet.d.ts +83 -0
  187. package/dest/test-wallet/test_wallet.d.ts.map +1 -0
  188. package/dest/test-wallet/test_wallet.js +214 -0
  189. package/dest/test-wallet/utils.d.ts +41 -0
  190. package/dest/test-wallet/utils.d.ts.map +1 -0
  191. package/dest/test-wallet/utils.js +71 -0
  192. package/dest/test-wallet/wallet_worker_script.d.ts +2 -0
  193. package/dest/test-wallet/wallet_worker_script.d.ts.map +1 -0
  194. package/dest/test-wallet/wallet_worker_script.js +48 -0
  195. package/dest/test-wallet/worker_wallet.d.ts +52 -0
  196. package/dest/test-wallet/worker_wallet.d.ts.map +1 -0
  197. package/dest/test-wallet/worker_wallet.js +151 -0
  198. package/dest/test-wallet/worker_wallet_schema.d.ts +274 -0
  199. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -0
  200. package/dest/test-wallet/worker_wallet_schema.js +10 -0
  201. package/package.json +72 -62
  202. package/src/bench/client_flows/benchmark.ts +363 -0
  203. package/src/bench/client_flows/client_flows_benchmark.ts +388 -0
  204. package/src/bench/client_flows/config.ts +69 -0
  205. package/src/bench/client_flows/data_extractor.ts +89 -0
  206. package/src/bench/utils.ts +47 -86
  207. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +149 -171
  208. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +155 -182
  209. package/src/e2e_deploy_contract/deploy_test.ts +40 -48
  210. package/src/e2e_epochs/epochs_test.ts +364 -93
  211. package/src/e2e_fees/bridging_race.notest.ts +74 -0
  212. package/src/e2e_fees/fees_test.ts +213 -259
  213. package/src/e2e_l1_publisher/write_json.ts +77 -0
  214. package/src/e2e_multi_validator/utils.ts +258 -0
  215. package/src/e2e_nested_contract/nested_contract_test.ts +48 -59
  216. package/src/e2e_p2p/inactivity_slash_test.ts +179 -0
  217. package/src/e2e_p2p/p2p_network.ts +367 -234
  218. package/src/e2e_p2p/reqresp/utils.ts +256 -0
  219. package/src/e2e_p2p/shared.ts +315 -39
  220. package/src/e2e_storage_proof/fixtures/storage_proof.json +915 -0
  221. package/src/e2e_storage_proof/fixtures/storage_proof_fetcher.ts +190 -0
  222. package/src/e2e_storage_proof/fixtures/storage_proof_fixture.ts +173 -0
  223. package/src/e2e_token_contract/token_contract_test.ts +132 -126
  224. package/src/fixtures/authwit_proxy.ts +50 -0
  225. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  226. package/src/fixtures/e2e_prover_test.ts +332 -0
  227. package/src/fixtures/elu_monitor.ts +126 -0
  228. package/src/fixtures/fixtures.ts +15 -7
  229. package/src/fixtures/get_acvm_config.ts +4 -12
  230. package/src/fixtures/get_bb_config.ts +18 -13
  231. package/src/fixtures/ha_setup.ts +186 -0
  232. package/src/fixtures/index.ts +1 -0
  233. package/src/fixtures/l1_to_l2_messaging.ts +56 -24
  234. package/src/fixtures/setup.ts +903 -0
  235. package/src/fixtures/setup_p2p_test.ts +134 -50
  236. package/src/fixtures/token_utils.ts +37 -16
  237. package/src/fixtures/utils.ts +27 -820
  238. package/src/fixtures/web3signer.ts +63 -0
  239. package/src/fixtures/with_telemetry_utils.ts +2 -2
  240. package/src/guides/up_quick_start.sh +9 -17
  241. package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +2 -2
  242. package/src/quality_of_service/prometheus_client.ts +113 -0
  243. package/src/shared/cross_chain_test_harness.ts +110 -94
  244. package/src/shared/gas_portal_test_harness.ts +59 -50
  245. package/src/shared/index.ts +2 -1
  246. package/src/shared/jest_setup.ts +52 -2
  247. package/src/shared/mock_state_view.ts +188 -0
  248. package/src/shared/submit-transactions.ts +19 -20
  249. package/src/shared/uniswap_l1_l2.ts +207 -226
  250. package/src/simulators/lending_simulator.ts +18 -17
  251. package/src/simulators/token_simulator.ts +18 -34
  252. package/src/spartan/DEVELOP.md +128 -0
  253. package/src/spartan/setup_test_wallets.ts +393 -95
  254. package/src/spartan/tx_metrics.ts +376 -0
  255. package/src/spartan/utils/bot.ts +188 -0
  256. package/src/spartan/utils/chaos.ts +253 -0
  257. package/src/spartan/utils/clients.ts +100 -0
  258. package/src/spartan/utils/config.ts +29 -0
  259. package/src/spartan/utils/health.ts +255 -0
  260. package/src/spartan/utils/helm.ts +84 -0
  261. package/src/spartan/utils/index.ts +71 -0
  262. package/src/spartan/utils/k8s.ts +535 -0
  263. package/src/spartan/utils/nodes.ts +543 -0
  264. package/src/spartan/utils/pod_logs.ts +99 -0
  265. package/src/spartan/utils/scripts.ts +99 -0
  266. package/src/spartan/utils.ts +1 -582
  267. package/src/test-wallet/test_wallet.ts +306 -0
  268. package/src/test-wallet/utils.ts +112 -0
  269. package/src/test-wallet/wallet_worker_script.ts +60 -0
  270. package/src/test-wallet/worker_wallet.ts +213 -0
  271. package/src/test-wallet/worker_wallet_schema.ts +13 -0
  272. package/dest/e2e_prover/e2e_prover_test.d.ts +0 -56
  273. package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
  274. package/dest/e2e_prover/e2e_prover_test.js +0 -291
  275. package/dest/fixtures/setup_l1_contracts.d.ts +0 -6
  276. package/dest/fixtures/setup_l1_contracts.d.ts.map +0 -1
  277. package/dest/fixtures/setup_l1_contracts.js +0 -17
  278. package/dest/fixtures/snapshot_manager.d.ts +0 -87
  279. package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
  280. package/dest/fixtures/snapshot_manager.js +0 -479
  281. package/dest/quality_of_service/alert_checker.d.ts +0 -41
  282. package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
  283. package/dest/sample-dapp/connect.js +0 -12
  284. package/dest/sample-dapp/contracts.js +0 -10
  285. package/dest/sample-dapp/deploy.js +0 -35
  286. package/dest/sample-dapp/index.js +0 -98
  287. package/src/e2e_prover/e2e_prover_test.ts +0 -418
  288. package/src/fixtures/setup_l1_contracts.ts +0 -27
  289. package/src/fixtures/snapshot_manager.ts +0 -617
  290. package/src/sample-dapp/connect.mjs +0 -16
  291. package/src/sample-dapp/contracts.mjs +0 -14
  292. package/src/sample-dapp/deploy.mjs +0 -40
  293. package/src/sample-dapp/index.mjs +0 -128
@@ -1,23 +1,22 @@
1
- import { getSchnorrAccount } from '@aztec/accounts/schnorr';
2
- import { Fr, GrumpkinScalar, TxStatus } from '@aztec/aztec.js';
1
+ import { NO_WAIT } from '@aztec/aztec.js/contracts';
2
+ import { Fr, GrumpkinScalar } from '@aztec/aztec.js/fields';
3
+ import { TxStatus } from '@aztec/aztec.js/tx';
3
4
  import { times } from '@aztec/foundation/collection';
4
- // submits a set of transactions to the provided Private eXecution Environment (PXE)
5
- export const submitTxsTo = async (pxe, numTxs, wallet, logger)=>{
6
- const txs = [];
5
+ // submits a set of transactions to the provided Wallet
6
+ export const submitTxsTo = async (wallet, submitter, numTxs, logger)=>{
7
+ const txHashes = [];
7
8
  await Promise.all(times(numTxs, async ()=>{
8
- const accountManager = await getSchnorrAccount(pxe, Fr.random(), GrumpkinScalar.random(), Fr.random());
9
- const tx = accountManager.deploy({
10
- deployWallet: wallet
9
+ const accountManager = await wallet.createSchnorrAccount(Fr.random(), Fr.random(), GrumpkinScalar.random());
10
+ const deployMethod = await accountManager.getDeployMethod();
11
+ const { txHash } = await deployMethod.send({
12
+ from: submitter,
13
+ wait: NO_WAIT
11
14
  });
12
- const txHash = await tx.getTxHash();
13
15
  logger.info(`Tx sent with hash ${txHash}`);
14
- const receipt = await tx.getReceipt();
15
- expect(receipt).toEqual(expect.objectContaining({
16
- status: TxStatus.PENDING,
17
- error: ''
18
- }));
16
+ const receipt = await wallet.getTxReceipt(txHash);
17
+ expect(receipt.status).toBe(TxStatus.PENDING);
19
18
  logger.info(`Receipt received for ${txHash}`);
20
- txs.push(tx);
19
+ txHashes.push(txHash);
21
20
  }));
22
- return txs;
21
+ return txHashes;
23
22
  };
@@ -1,25 +1,3 @@
1
- import { type AccountWallet, type AztecNode, type CheatCodes, type Logger, type PXE } from '@aztec/aztec.js';
2
- import { type DeployL1ContractsReturnType, type ViemPublicClient, type ViemWalletClient } from '@aztec/ethereum';
3
- /** Objects to be returned by the uniswap setup function */
4
- export type UniswapSetupContext = {
5
- /** Aztec Node instance */
6
- aztecNode: AztecNode;
7
- /** The Private eXecution Environment (PXE). */
8
- pxe: PXE;
9
- /** Logger instance named as the current test. */
10
- logger: Logger;
11
- /** Viem Public client instance. */
12
- publicClient: ViemPublicClient;
13
- /** Viem Wallet Client instance. */
14
- walletClient: ViemWalletClient;
15
- /** The owner wallet. */
16
- ownerWallet: AccountWallet;
17
- /** The sponsor wallet. */
18
- sponsorWallet: AccountWallet;
19
- /** */
20
- deployL1ContractsValues: DeployL1ContractsReturnType;
21
- /** Cheat codes instance. */
22
- cheatCodes: CheatCodes;
23
- };
24
- export declare const uniswapL1L2TestSuite: (setup: () => Promise<UniswapSetupContext>, cleanup: () => Promise<void>, expectedForkBlockNumber?: number) => void;
25
- //# sourceMappingURL=uniswap_l1_l2.d.ts.map
1
+ import { type EndToEndContext } from '../fixtures/utils.js';
2
+ export declare const uniswapL1L2TestSuite: (setup: () => Promise<EndToEndContext>, cleanup: () => Promise<void>, expectedForkBlockNumber?: number) => void;
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5pc3dhcF9sMV9sMi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3NoYXJlZC91bmlzd2FwX2wxX2wyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQXVCQSxPQUFPLEVBQUUsS0FBSyxlQUFlLEVBQW1DLE1BQU0sc0JBQXNCLENBQUM7QUFhN0YsZUFBTyxNQUFNLG9CQUFvQixpSEF1K0JoQyxDQUFDIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"uniswap_l1_l2.d.ts","sourceRoot":"","sources":["../../src/shared/uniswap_l1_l2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,SAAS,EACd,KAAK,UAAU,EAGf,KAAK,MAAM,EACX,KAAK,GAAG,EAGT,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,2BAA2B,EAChC,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAGtB,MAAM,iBAAiB,CAAC;AAqBzB,2DAA2D;AAC3D,MAAM,MAAM,mBAAmB,GAAG;IAChC,0BAA0B;IAC1B,SAAS,EAAE,SAAS,CAAC;IACrB,+CAA+C;IAC/C,GAAG,EAAE,GAAG,CAAC;IACT,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,YAAY,EAAE,gBAAgB,CAAC;IAC/B,mCAAmC;IACnC,YAAY,EAAE,gBAAgB,CAAC;IAC/B,wBAAwB;IACxB,WAAW,EAAE,aAAa,CAAC;IAC3B,0BAA0B;IAC1B,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO;IACP,uBAAuB,EAAE,2BAA2B,CAAC;IACrD,4BAA4B;IAC5B,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAGF,eAAO,MAAM,oBAAoB,UACxB,MAAM,QAAQ,mBAAmB,CAAC,WAChC,MAAM,QAAQ,IAAI,CAAC,2CA89B7B,CAAC"}
1
+ {"version":3,"file":"uniswap_l1_l2.d.ts","sourceRoot":"","sources":["../../src/shared/uniswap_l1_l2.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,KAAK,eAAe,EAAmC,MAAM,sBAAsB,CAAC;AAa7F,eAAO,MAAM,oBAAoB,iHAu+BhC,CAAC"}
@@ -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 { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
5
12
  import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
13
+ import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
14
+ import { computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
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 } 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
25
  const TIMEOUT = 360_000;
18
- // docs:end:uniswap_l1_l2_test_setup_const
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,54 +47,54 @@ 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
  ]);
64
66
  logger.info('Deploying DAI Portal, initializing and deploying l2 contract...');
65
- daiCrossChainHarness = await CrossChainTestHarness.new(aztecNode, pxe, publicClient, walletClient, ownerWallet, logger, DAI_ADDRESS);
67
+ daiCrossChainHarness = await CrossChainTestHarness.new(aztecNode, deployL1ContractsValues.l1Client, wallet, ownerAddress, logger, DAI_ADDRESS);
66
68
  logger.info('Deploying WETH Portal, initializing and deploying l2 contract...');
67
- wethCrossChainHarness = await CrossChainTestHarness.new(aztecNode, pxe, publicClient, walletClient, ownerWallet, logger, WETH9_ADDRESS);
69
+ wethCrossChainHarness = await CrossChainTestHarness.new(aztecNode, l1Client, wallet, ownerAddress, logger, WETH9_ADDRESS);
68
70
  logger.info('Deploy Uniswap portal on L1 and L2...');
69
- uniswapPortalAddress = await deployL1Contract(walletClient, publicClient, UniswapPortalAbi, UniswapPortalBytecode).then(({ address })=>address);
71
+ uniswapPortalAddress = await deployL1Contract(l1Client, UniswapPortalAbi, UniswapPortalBytecode).then(({ address })=>address);
70
72
  uniswapPortal = getContract({
71
73
  address: uniswapPortalAddress.toString(),
72
74
  abi: UniswapPortalAbi,
73
- client: walletClient
75
+ client: l1Client
74
76
  });
75
77
  // 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;
78
+ ({ contract: uniswapL2Contract } = await UniswapContract.deploy(wallet, uniswapPortalAddress).send({
79
+ from: ownerAddress
80
+ }));
81
+ const registryAddress = (await aztecNode.getNodeInfo()).l1ContractAddresses.registryAddress;
78
82
  await uniswapPortal.write.initialize([
79
83
  registryAddress.toString(),
80
84
  uniswapL2Contract.address.toString()
81
85
  ], {});
82
86
  // Give me some WETH so I can deposit to L2 and do the swap...
83
87
  logger.info('Getting some weth');
84
- const hash = await walletClient.sendTransaction({
88
+ const hash = await l1Client.sendTransaction({
85
89
  to: WETH9_ADDRESS.toString(),
86
90
  value: parseEther('1000')
87
91
  });
88
- await publicClient.waitForTransactionReceipt({
92
+ await l1Client.waitForTransactionReceipt({
89
93
  hash
90
94
  });
91
95
  const wethBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
92
96
  expect(wethBalance).toBe(parseEther('1000'));
93
97
  });
94
- // docs:end:uniswap_l1_l2_test_beforeAll
95
98
  afterAll(async ()=>{
96
99
  await cleanup();
97
100
  });
@@ -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,52 @@ 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
+ const swapResult = await computeL2ToL1MembershipWitness(aztecNode, swapPrivateLeaf, l2UniswapInteractionReceipt.txHash);
170
+ const { epochNumber: epoch } = swapResult;
171
+ await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
172
+ await waitForProven(aztecNode, l2UniswapInteractionReceipt, {
173
+ provenTimeout: 300
174
+ });
162
175
  // 5. Consume L2 to L1 message by calling uniswapPortal.swap_private()
163
176
  logger.info('Execute withdraw and swap on the uniswapPortal!');
164
177
  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);
178
+ const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawLeaf, l2UniswapInteractionReceipt.txHash);
179
+ const swapPrivateL2MessageIndex = swapResult.leafIndex;
180
+ const swapPrivateSiblingPath = swapResult.siblingPath;
181
+ const withdrawL2MessageIndex = withdrawResult.leafIndex;
182
+ const withdrawSiblingPath = withdrawResult.siblingPath;
167
183
  const withdrawMessageMetadata = {
168
- _l2BlockNumber: BigInt(l2UniswapInteractionReceipt.blockNumber),
184
+ _epoch: BigInt(epoch),
169
185
  _leafIndex: BigInt(withdrawL2MessageIndex),
170
186
  _path: withdrawSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
171
187
  };
172
188
  const swapPrivateMessageMetadata = {
173
- _l2BlockNumber: BigInt(l2UniswapInteractionReceipt.blockNumber),
189
+ _epoch: BigInt(epoch),
174
190
  _leafIndex: BigInt(swapPrivateL2MessageIndex),
175
191
  _path: swapPrivateSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
176
192
  };
@@ -188,7 +204,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
188
204
  ]
189
205
  ];
190
206
  // this should also insert a message into the inbox.
191
- const txReceipt = await daiCrossChainHarness.publicClient.waitForTransactionReceipt({
207
+ const txReceipt = await daiCrossChainHarness.l1Client.waitForTransactionReceipt({
192
208
  hash: await uniswapPortal.write.swapPrivate(swapArgs)
193
209
  });
194
210
  // We get the msg leaf from event so that we can later wait for it to be available for consumption
@@ -297,9 +313,9 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
297
313
  // ownerEthAddress,
298
314
  // nonceForSwap,
299
315
  // );
300
- // await ownerWallet.setPublicAuthWit({ caller: sponsorAddress, action }, true).send().wait();
316
+ // await ownerWallet.setPublicAuthWit({ caller: sponsorAddress, action }, true).send();
301
317
  // // 4.2 Call swap_public from user2 on behalf of owner
302
- // const uniswapL2Interaction = await action.send().wait();
318
+ // const uniswapL2Interaction = await action.send();
303
319
  // const swapPublicContent = sha256ToField([
304
320
  // Buffer.from(
305
321
  // toFunctionSelector('swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)').substring(
@@ -352,14 +368,14 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
352
368
  // withdrawLeaf,
353
369
  // );
354
370
  // const withdrawMessageMetadata = {
355
- // _l2BlockNumber: BigInt(uniswapL2Interaction.blockNumber!),
371
+ // _epoch: epoch,
356
372
  // _leafIndex: BigInt(withdrawL2MessageIndex),
357
373
  // _path: withdrawSiblingPath
358
374
  // .toBufferArray()
359
375
  // .map((buf: Buffer) => `0x${buf.toString('hex')}`) as readonly `0x${string}`[],
360
376
  // };
361
377
  // const swapPrivateMessageMetadata = {
362
- // _l2BlockNumber: BigInt(uniswapL2Interaction.blockNumber!),
378
+ // _epoch: epoch,
363
379
  // _leafIndex: BigInt(swapPrivateL2MessageIndex),
364
380
  // _path: swapPrivateSiblingPath
365
381
  // .toBufferArray()
@@ -432,12 +448,11 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
432
448
  const nonceForWETHTransferToPublicApproval = new Fr(2n);
433
449
  const expectedMessageHash = await computeAuthWitMessageHash({
434
450
  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()}`);
451
+ call: await wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval).getFunctionCall()
452
+ }, await wallet.getChainInfo());
453
+ await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).simulate({
454
+ from: ownerAddress
455
+ })).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`);
441
456
  });
442
457
  it("can't swap if user passes a token different to what the bridge tracks", async ()=>{
443
458
  // 1. give user private funds on L2:
@@ -446,13 +461,18 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
446
461
  // 2. owner gives uniswap approval to transfer the funds to public:
447
462
  logger.info('Approving uniswap to transfer funds to public to self on my behalf');
448
463
  const nonceForWETHTransferToPublicApproval = new Fr(3n);
449
- await ownerWallet.createAuthWit({
464
+ const transferToPublicAuthwith = await wallet.createAuthWit(ownerAddress, {
450
465
  caller: uniswapL2Contract.address,
451
466
  action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
452
467
  });
453
468
  // 3. Swap but send the wrong token address
454
469
  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');
470
+ await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, daiCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).send({
471
+ from: ownerAddress,
472
+ authWitnesses: [
473
+ transferToPublicAuthwith
474
+ ]
475
+ })).rejects.toThrow('Assertion failed: input_asset address is not the same as seen in the bridge contract');
456
476
  });
457
477
  // edge cases for public flow:
458
478
  it("I don't need approval to call swap_public if I'm swapping on my own behalf", async ()=>{
@@ -460,14 +480,16 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
460
480
  await wethCrossChainHarness.mintTokensPublicOnL2(wethAmountToBridge);
461
481
  // 2. Give approval to uniswap to transfer funds to itself
462
482
  const nonceForWETHTransferApproval = new Fr(2n);
463
- const validateActionInteraction = await ownerWallet.setPublicAuthWit({
483
+ const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
464
484
  caller: uniswapL2Contract.address,
465
485
  action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
466
486
  }, true);
467
- await validateActionInteraction.send().wait();
487
+ await validateActionInteraction.send();
468
488
  // No approval to call `swap` but should work even without it:
469
489
  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();
490
+ await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send({
491
+ from: ownerAddress
492
+ });
471
493
  // check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
472
494
  await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
473
495
  });
@@ -477,23 +499,27 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
477
499
  const nonceForWETHTransferApproval = new Fr(3n);
478
500
  const nonceForSwap = new Fr(3n);
479
501
  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({
502
+ const action = uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, nonceForSwap);
503
+ const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
482
504
  caller: approvedUser,
483
505
  action
484
506
  }, true);
485
- await validateActionInteraction.send().wait();
486
- await expect(action.simulate()).rejects.toThrow(/unauthorized/);
507
+ await validateActionInteraction.send();
508
+ await expect(action.simulate({
509
+ from: sponsorAddress
510
+ })).rejects.toThrow(/unauthorized/);
487
511
  });
488
512
  it("uniswap can't pull funds without transfer approval", async ()=>{
489
513
  // swap should fail since no transfer approval to uniswap:
490
514
  const nonceForWETHTransferApproval = new Fr(4n);
491
- const validateActionInteraction = await ownerWallet.setPublicAuthWit({
515
+ const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
492
516
  caller: uniswapL2Contract.address,
493
517
  action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
494
518
  }, 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/);
519
+ await validateActionInteraction.send();
520
+ 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({
521
+ from: ownerAddress
522
+ })).rejects.toThrow(/unauthorized/);
497
523
  });
498
524
  // tests when trying to mix private and public flows:
499
525
  it("can't call swap_public on L1 if called swap_private on L2", async ()=>{
@@ -503,7 +529,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
503
529
  // Owner gives uniswap approval to transfer the funds to public to self on its behalf
504
530
  logger.info('Approving uniswap to transfer the funds to public to self on my behalf');
505
531
  const nonceForWETHTransferToPublicApproval = new Fr(4n);
506
- await ownerWallet.createAuthWit({
532
+ const transferToPublicAuhtwit = await wallet.createAuthWit(ownerAddress, {
507
533
  caller: uniswapL2Contract.address,
508
534
  action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
509
535
  });
@@ -511,7 +537,12 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
511
537
  // Swap
512
538
  logger.info('Withdrawing weth to L1 and sending message to swap to dai');
513
539
  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();
540
+ const { receipt: withdrawReceipt } = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send({
541
+ from: ownerAddress,
542
+ authWitnesses: [
543
+ transferToPublicAuhtwit
544
+ ]
545
+ });
515
546
  const swapPrivateContent = sha256ToField([
516
547
  Buffer.from(toFunctionSelector('swap_private(address,uint256,uint24,address,uint256,bytes32,address)').substring(2), 'hex'),
517
548
  wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
@@ -522,42 +553,50 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
522
553
  secretHashForDepositingSwappedDai,
523
554
  ownerEthAddress.toBuffer32()
524
555
  ]);
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
- ]);
556
+ const swapPrivateLeaf = computeL2ToL1MessageHash({
557
+ l2Sender: uniswapL2Contract.address,
558
+ l1Recipient: EthAddress.fromString(uniswapPortal.address),
559
+ content: swapPrivateContent,
560
+ rollupVersion: new Fr(version),
561
+ chainId: new Fr(l1Client.chain.id)
562
+ });
532
563
  const withdrawContent = sha256ToField([
533
564
  Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
534
565
  uniswapPortalAddress.toBuffer32(),
535
566
  new Fr(wethAmountToBridge),
536
567
  uniswapPortalAddress.toBuffer32()
537
568
  ]);
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);
569
+ const withdrawLeaf = computeL2ToL1MessageHash({
570
+ l2Sender: wethCrossChainHarness.l2Bridge.address,
571
+ l1Recipient: wethCrossChainHarness.tokenPortalAddress,
572
+ content: withdrawContent,
573
+ rollupVersion: new Fr(version),
574
+ chainId: new Fr(l1Client.chain.id)
575
+ });
576
+ const swapResult = await computeL2ToL1MembershipWitness(aztecNode, swapPrivateLeaf, withdrawReceipt.txHash);
577
+ const { epochNumber: epoch } = swapResult;
578
+ const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawLeaf, withdrawReceipt.txHash);
579
+ const swapPrivateL2MessageIndex = swapResult.leafIndex;
580
+ const swapPrivateSiblingPath = swapResult.siblingPath;
581
+ const withdrawL2MessageIndex = withdrawResult.leafIndex;
582
+ const withdrawSiblingPath = withdrawResult.siblingPath;
547
583
  const withdrawMessageMetadata = {
548
- _l2BlockNumber: BigInt(withdrawReceipt.blockNumber),
584
+ _epoch: BigInt(epoch),
549
585
  _leafIndex: BigInt(withdrawL2MessageIndex),
550
586
  _path: withdrawSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
551
587
  };
552
588
  const swapPrivateMessageMetadata = {
553
- _l2BlockNumber: BigInt(withdrawReceipt.blockNumber),
589
+ _epoch: BigInt(epoch),
554
590
  _leafIndex: BigInt(swapPrivateL2MessageIndex),
555
591
  _path: swapPrivateSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
556
592
  };
557
593
  // ensure that user's funds were burnt
558
594
  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());
595
+ // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
596
+ await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
597
+ await waitForProven(aztecNode, withdrawReceipt, {
598
+ provenTimeout: 300
599
+ });
561
600
  // On L1 call swap_public!
562
601
  logger.info('call swap_public on L1');
563
602
  const swapArgs = [
@@ -583,14 +622,16 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
583
622
  await wethCrossChainHarness.mintTokensPublicOnL2(wethAmountToBridge);
584
623
  // Owner gives uniswap approval to transfer funds on its behalf
585
624
  const nonceForWETHTransferApproval = new Fr(5n);
586
- const validateActionInteraction = await ownerWallet.setPublicAuthWit({
625
+ const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
587
626
  caller: uniswapL2Contract.address,
588
627
  action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
589
628
  }, true);
590
- await validateActionInteraction.send().wait();
629
+ await validateActionInteraction.send();
591
630
  // Call swap_public on L2
592
631
  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();
632
+ 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({
633
+ from: ownerAddress
634
+ });
594
635
  const swapPublicContent = sha256ToField([
595
636
  Buffer.from(toFunctionSelector('swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)').substring(2), 'hex'),
596
637
  wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
@@ -602,42 +643,50 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
602
643
  secretHashForDepositingSwappedDai,
603
644
  ownerEthAddress.toBuffer32()
604
645
  ]);
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
- ]);
646
+ const swapPublicLeaf = computeL2ToL1MessageHash({
647
+ l2Sender: uniswapL2Contract.address,
648
+ l1Recipient: EthAddress.fromString(uniswapPortal.address),
649
+ content: swapPublicContent,
650
+ rollupVersion: new Fr(version),
651
+ chainId: new Fr(l1Client.chain.id)
652
+ });
612
653
  const withdrawContent = sha256ToField([
613
654
  Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
614
655
  uniswapPortalAddress.toBuffer32(),
615
656
  new Fr(wethAmountToBridge),
616
657
  uniswapPortalAddress.toBuffer32()
617
658
  ]);
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);
659
+ const withdrawLeaf = computeL2ToL1MessageHash({
660
+ l2Sender: wethCrossChainHarness.l2Bridge.address,
661
+ l1Recipient: wethCrossChainHarness.tokenPortalAddress,
662
+ content: withdrawContent,
663
+ rollupVersion: new Fr(version),
664
+ chainId: new Fr(l1Client.chain.id)
665
+ });
666
+ const swapResult = await computeL2ToL1MembershipWitness(aztecNode, swapPublicLeaf, withdrawReceipt.txHash);
667
+ const { epochNumber: epoch } = swapResult;
668
+ const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawLeaf, withdrawReceipt.txHash);
669
+ const swapPublicL2MessageIndex = swapResult.leafIndex;
670
+ const swapPublicSiblingPath = swapResult.siblingPath;
671
+ const withdrawL2MessageIndex = withdrawResult.leafIndex;
672
+ const withdrawSiblingPath = withdrawResult.siblingPath;
627
673
  const withdrawMessageMetadata = {
628
- _l2BlockNumber: BigInt(withdrawReceipt.blockNumber),
674
+ _epoch: BigInt(epoch),
629
675
  _leafIndex: BigInt(withdrawL2MessageIndex),
630
676
  _path: withdrawSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
631
677
  };
632
678
  const swapPublicMessageMetadata = {
633
- _l2BlockNumber: BigInt(withdrawReceipt.blockNumber),
679
+ _epoch: BigInt(epoch),
634
680
  _leafIndex: BigInt(swapPublicL2MessageIndex),
635
681
  _path: swapPublicSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
636
682
  };
637
683
  // check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
638
684
  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());
685
+ // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
686
+ await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
687
+ await waitForProven(aztecNode, withdrawReceipt, {
688
+ provenTimeout: 300
689
+ });
641
690
  // Call swap_private on L1
642
691
  logger.info('Execute withdraw and swap on the uniswapPortal!');
643
692
  const swapArgs = [