@aztec/end-to-end 0.0.1-commit.2ed92850 → 0.0.1-commit.2f68f620

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 (234) hide show
  1. package/README.md +27 -0
  2. package/dest/bench/client_flows/benchmark.d.ts +15 -1
  3. package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
  4. package/dest/bench/client_flows/benchmark.js +17 -0
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts +3 -3
  6. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  7. package/dest/bench/client_flows/client_flows_benchmark.js +36 -39
  8. package/dest/bench/client_flows/config.d.ts +2 -2
  9. package/dest/bench/client_flows/config.d.ts.map +1 -1
  10. package/dest/bench/client_flows/config.js +18 -0
  11. package/dest/bench/utils.d.ts +1 -1
  12. package/dest/bench/utils.d.ts.map +1 -1
  13. package/dest/bench/utils.js +8 -3
  14. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +8 -5
  15. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  16. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +36 -17
  17. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +16 -5
  18. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  19. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +42 -9
  20. package/dest/e2e_deploy_contract/deploy_test.d.ts +4 -4
  21. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  22. package/dest/e2e_deploy_contract/deploy_test.js +2 -1
  23. package/dest/e2e_epochs/epochs_test.d.ts +39 -8
  24. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  25. package/dest/e2e_epochs/epochs_test.js +170 -52
  26. package/dest/e2e_fees/fees_test.d.ts +6 -3
  27. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  28. package/dest/e2e_fees/fees_test.js +50 -17
  29. package/dest/e2e_l1_publisher/write_json.d.ts +3 -2
  30. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -1
  31. package/dest/e2e_l1_publisher/write_json.js +1 -7
  32. package/dest/e2e_nested_contract/nested_contract_test.d.ts +3 -3
  33. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  34. package/dest/e2e_nested_contract/nested_contract_test.js +6 -7
  35. package/dest/e2e_p2p/inactivity_slash_test.d.ts +1 -1
  36. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -1
  37. package/dest/e2e_p2p/inactivity_slash_test.js +4 -3
  38. package/dest/e2e_p2p/p2p_network.d.ts +14 -12
  39. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  40. package/dest/e2e_p2p/p2p_network.js +70 -34
  41. package/dest/e2e_p2p/reqresp/utils.d.ts +22 -0
  42. package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -0
  43. package/dest/e2e_p2p/reqresp/utils.js +206 -0
  44. package/dest/e2e_p2p/shared.d.ts +37 -8
  45. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  46. package/dest/e2e_p2p/shared.js +93 -53
  47. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +2 -0
  48. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +1 -0
  49. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.js +184 -0
  50. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts +18 -0
  51. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +1 -0
  52. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.js +120 -0
  53. package/dest/e2e_token_contract/token_contract_test.d.ts +6 -4
  54. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  55. package/dest/e2e_token_contract/token_contract_test.js +23 -11
  56. package/dest/fixtures/authwit_proxy.d.ts +15 -0
  57. package/dest/fixtures/authwit_proxy.d.ts.map +1 -0
  58. package/dest/fixtures/authwit_proxy.js +34 -0
  59. package/dest/fixtures/e2e_prover_test.d.ts +9 -8
  60. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  61. package/dest/fixtures/e2e_prover_test.js +40 -51
  62. package/dest/fixtures/elu_monitor.d.ts +21 -0
  63. package/dest/fixtures/elu_monitor.d.ts.map +1 -0
  64. package/dest/fixtures/elu_monitor.js +102 -0
  65. package/dest/fixtures/fixtures.d.ts +74 -1
  66. package/dest/fixtures/fixtures.d.ts.map +1 -1
  67. package/dest/fixtures/fixtures.js +71 -0
  68. package/dest/fixtures/get_bb_config.d.ts +1 -1
  69. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  70. package/dest/fixtures/get_bb_config.js +5 -5
  71. package/dest/fixtures/ha_setup.d.ts +71 -0
  72. package/dest/fixtures/ha_setup.d.ts.map +1 -0
  73. package/dest/fixtures/ha_setup.js +116 -0
  74. package/dest/fixtures/index.d.ts +2 -1
  75. package/dest/fixtures/index.d.ts.map +1 -1
  76. package/dest/fixtures/index.js +1 -0
  77. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts +25 -0
  78. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts.map +1 -0
  79. package/dest/fixtures/schnorr_hardcoded_account_contract.js +37 -0
  80. package/dest/fixtures/setup.d.ts +88 -34
  81. package/dest/fixtures/setup.d.ts.map +1 -1
  82. package/dest/fixtures/setup.js +225 -180
  83. package/dest/fixtures/setup_p2p_test.d.ts +22 -11
  84. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  85. package/dest/fixtures/setup_p2p_test.js +43 -32
  86. package/dest/fixtures/token_utils.d.ts +2 -2
  87. package/dest/fixtures/token_utils.d.ts.map +1 -1
  88. package/dest/fixtures/token_utils.js +5 -7
  89. package/dest/fixtures/utils.d.ts +2 -2
  90. package/dest/fixtures/utils.d.ts.map +1 -1
  91. package/dest/fixtures/utils.js +1 -1
  92. package/dest/forward-compatibility/wallet_rpc_client.d.ts +7 -0
  93. package/dest/forward-compatibility/wallet_rpc_client.d.ts.map +1 -0
  94. package/dest/forward-compatibility/wallet_rpc_client.js +15 -0
  95. package/dest/forward-compatibility/wallet_service.d.ts +3 -0
  96. package/dest/forward-compatibility/wallet_service.d.ts.map +1 -0
  97. package/dest/forward-compatibility/wallet_service.js +109 -0
  98. package/dest/install_legacy_contracts.d.cts +10 -0
  99. package/dest/install_legacy_contracts.d.cts.map +1 -0
  100. package/dest/legacy-jest-resolver.d.cts +3 -0
  101. package/dest/legacy-jest-resolver.d.cts.map +1 -0
  102. package/dest/shared/cross_chain_test_harness.d.ts +4 -2
  103. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  104. package/dest/shared/cross_chain_test_harness.js +22 -18
  105. package/dest/shared/gas_portal_test_harness.d.ts +8 -5
  106. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  107. package/dest/shared/gas_portal_test_harness.js +19 -10
  108. package/dest/shared/index.d.ts +2 -1
  109. package/dest/shared/index.d.ts.map +1 -1
  110. package/dest/shared/index.js +1 -0
  111. package/dest/shared/jest_setup.js +41 -1
  112. package/dest/shared/mock_state_view.d.ts +86 -0
  113. package/dest/shared/mock_state_view.d.ts.map +1 -0
  114. package/dest/shared/mock_state_view.js +186 -0
  115. package/dest/shared/submit-transactions.d.ts +2 -2
  116. package/dest/shared/submit-transactions.d.ts.map +1 -1
  117. package/dest/shared/submit-transactions.js +1 -1
  118. package/dest/shared/uniswap_l1_l2.d.ts +1 -1
  119. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  120. package/dest/shared/uniswap_l1_l2.js +57 -40
  121. package/dest/shared/wait_for_l1_to_l2_message.d.ts +13 -0
  122. package/dest/shared/wait_for_l1_to_l2_message.d.ts.map +1 -0
  123. package/dest/shared/wait_for_l1_to_l2_message.js +10 -0
  124. package/dest/simulators/lending_simulator.d.ts +10 -3
  125. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  126. package/dest/simulators/lending_simulator.js +26 -14
  127. package/dest/simulators/token_simulator.d.ts +1 -1
  128. package/dest/simulators/token_simulator.d.ts.map +1 -1
  129. package/dest/simulators/token_simulator.js +3 -24
  130. package/dest/spartan/setup_test_wallets.d.ts +12 -3
  131. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  132. package/dest/spartan/setup_test_wallets.js +108 -41
  133. package/dest/spartan/tx_metrics.d.ts +52 -4
  134. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  135. package/dest/spartan/tx_metrics.js +224 -21
  136. package/dest/spartan/utils/bot.d.ts +3 -2
  137. package/dest/spartan/utils/bot.d.ts.map +1 -1
  138. package/dest/spartan/utils/bot.js +2 -1
  139. package/dest/spartan/utils/config.d.ts +11 -28
  140. package/dest/spartan/utils/config.d.ts.map +1 -1
  141. package/dest/spartan/utils/config.js +4 -1
  142. package/dest/spartan/utils/index.d.ts +6 -4
  143. package/dest/spartan/utils/index.d.ts.map +1 -1
  144. package/dest/spartan/utils/index.js +6 -2
  145. package/dest/spartan/utils/k8s.d.ts +31 -1
  146. package/dest/spartan/utils/k8s.d.ts.map +1 -1
  147. package/dest/spartan/utils/k8s.js +124 -0
  148. package/dest/spartan/utils/nodes.d.ts +14 -5
  149. package/dest/spartan/utils/nodes.d.ts.map +1 -1
  150. package/dest/spartan/utils/nodes.js +204 -33
  151. package/dest/spartan/utils/pod_logs.d.ts +25 -0
  152. package/dest/spartan/utils/pod_logs.d.ts.map +1 -0
  153. package/dest/spartan/utils/pod_logs.js +74 -0
  154. package/dest/spartan/utils/scripts.d.ts +18 -4
  155. package/dest/spartan/utils/scripts.d.ts.map +1 -1
  156. package/dest/spartan/utils/scripts.js +19 -4
  157. package/dest/test-wallet/test_wallet.d.ts +85 -0
  158. package/dest/test-wallet/test_wallet.d.ts.map +1 -0
  159. package/dest/test-wallet/test_wallet.js +273 -0
  160. package/dest/test-wallet/utils.d.ts +41 -0
  161. package/dest/test-wallet/utils.d.ts.map +1 -0
  162. package/dest/test-wallet/utils.js +66 -0
  163. package/dest/test-wallet/wallet_worker_script.d.ts +2 -0
  164. package/dest/test-wallet/wallet_worker_script.d.ts.map +1 -0
  165. package/dest/test-wallet/wallet_worker_script.js +53 -0
  166. package/dest/test-wallet/worker_wallet.d.ts +53 -0
  167. package/dest/test-wallet/worker_wallet.d.ts.map +1 -0
  168. package/dest/test-wallet/worker_wallet.js +155 -0
  169. package/dest/test-wallet/worker_wallet_schema.d.ts +160 -0
  170. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -0
  171. package/dest/test-wallet/worker_wallet_schema.js +22 -0
  172. package/package.json +52 -45
  173. package/src/bench/client_flows/benchmark.ts +19 -0
  174. package/src/bench/client_flows/client_flows_benchmark.ts +64 -49
  175. package/src/bench/client_flows/config.ts +9 -1
  176. package/src/bench/utils.ts +10 -4
  177. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +52 -25
  178. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +56 -19
  179. package/src/e2e_deploy_contract/deploy_test.ts +6 -5
  180. package/src/e2e_epochs/epochs_test.ts +196 -77
  181. package/src/e2e_fees/bridging_race.notest.ts +1 -1
  182. package/src/e2e_fees/fees_test.ts +57 -32
  183. package/src/e2e_l1_publisher/write_json.ts +1 -6
  184. package/src/e2e_nested_contract/nested_contract_test.ts +10 -6
  185. package/src/e2e_p2p/inactivity_slash_test.ts +8 -7
  186. package/src/e2e_p2p/p2p_network.ts +93 -49
  187. package/src/e2e_p2p/reqresp/utils.ts +274 -0
  188. package/src/e2e_p2p/shared.ts +117 -65
  189. package/src/e2e_storage_proof/fixtures/storage_proof.json +915 -0
  190. package/src/e2e_storage_proof/fixtures/storage_proof_fetcher.ts +190 -0
  191. package/src/e2e_storage_proof/fixtures/storage_proof_fixture.ts +173 -0
  192. package/src/e2e_token_contract/token_contract_test.ts +38 -11
  193. package/src/fixtures/authwit_proxy.ts +54 -0
  194. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  195. package/src/fixtures/e2e_prover_test.ts +50 -57
  196. package/src/fixtures/elu_monitor.ts +126 -0
  197. package/src/fixtures/fixtures.ts +93 -0
  198. package/src/fixtures/get_bb_config.ts +7 -6
  199. package/src/fixtures/ha_setup.ts +188 -0
  200. package/src/fixtures/index.ts +1 -0
  201. package/src/fixtures/schnorr_hardcoded_account_contract.ts +49 -0
  202. package/src/fixtures/setup.ts +282 -243
  203. package/src/fixtures/setup_p2p_test.ts +52 -52
  204. package/src/fixtures/token_utils.ts +3 -3
  205. package/src/fixtures/utils.ts +2 -0
  206. package/src/forward-compatibility/wallet_rpc_client.ts +14 -0
  207. package/src/forward-compatibility/wallet_service.ts +104 -0
  208. package/src/guides/up_quick_start.sh +3 -5
  209. package/src/install_legacy_contracts.cjs +75 -0
  210. package/src/legacy-jest-resolver.cjs +112 -0
  211. package/src/shared/cross_chain_test_harness.ts +27 -13
  212. package/src/shared/gas_portal_test_harness.ts +21 -11
  213. package/src/shared/index.ts +1 -0
  214. package/src/shared/jest_setup.ts +51 -1
  215. package/src/shared/mock_state_view.ts +188 -0
  216. package/src/shared/submit-transactions.ts +3 -2
  217. package/src/shared/uniswap_l1_l2.ts +103 -54
  218. package/src/shared/wait_for_l1_to_l2_message.ts +23 -0
  219. package/src/simulators/lending_simulator.ts +32 -14
  220. package/src/simulators/token_simulator.ts +6 -30
  221. package/src/spartan/setup_test_wallets.ts +146 -35
  222. package/src/spartan/tx_metrics.ts +208 -24
  223. package/src/spartan/utils/bot.ts +4 -1
  224. package/src/spartan/utils/config.ts +3 -0
  225. package/src/spartan/utils/index.ts +10 -1
  226. package/src/spartan/utils/k8s.ts +160 -0
  227. package/src/spartan/utils/nodes.ts +251 -31
  228. package/src/spartan/utils/pod_logs.ts +99 -0
  229. package/src/spartan/utils/scripts.ts +43 -7
  230. package/src/test-wallet/test_wallet.ts +376 -0
  231. package/src/test-wallet/utils.ts +108 -0
  232. package/src/test-wallet/wallet_worker_script.ts +63 -0
  233. package/src/test-wallet/worker_wallet.ts +218 -0
  234. package/src/test-wallet/worker_wallet_schema.ts +13 -0
@@ -11,18 +11,22 @@ import type { DeployAztecL1ContractsReturnType } from '@aztec/ethereum/deploy-az
11
11
  import { deployL1Contract } from '@aztec/ethereum/deploy-l1-contract';
12
12
  import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
13
13
  import { extractEvent } from '@aztec/ethereum/utils';
14
- import { CheckpointNumber, EpochNumber } from '@aztec/foundation/branded-types';
14
+ import { EpochNumber } from '@aztec/foundation/branded-types';
15
15
  import { sha256ToField } from '@aztec/foundation/crypto/sha256';
16
+ import { retryUntil } from '@aztec/foundation/retry';
16
17
  import { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
17
18
  import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
18
19
  import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
19
- import { computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
20
- import type { TestWallet } from '@aztec/test-wallet/server';
21
20
 
22
21
  import { jest } from '@jest/globals';
23
22
  import { type GetContractReturnType, getContract, parseEther, toFunctionSelector } from 'viem';
24
23
 
25
- import { type EndToEndContext, ensureAccountContractsPublished } from '../fixtures/utils.js';
24
+ import {
25
+ type EndToEndContext,
26
+ ensureAccountContractsPublished,
27
+ ensureAuthRegistryPublished,
28
+ } from '../fixtures/utils.js';
29
+ import type { TestWallet } from '../test-wallet/test_wallet.js';
26
30
  import { CrossChainTestHarness } from './cross_chain_test_harness.js';
27
31
 
28
32
  // PSA: This tests works on forked mainnet. There is a dump of the data in `dumpedState` such that we
@@ -32,7 +36,7 @@ import { CrossChainTestHarness } from './cross_chain_test_harness.js';
32
36
  // anvil --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c --fork-block-number 17514288 --chain-id 31337
33
37
  // For CI, this is configured in `run_tests.sh` and `docker-compose-images.yml`
34
38
 
35
- const TIMEOUT = 360_000;
39
+ const TIMEOUT = 15 * 60 * 1000;
36
40
 
37
41
  export const uniswapL1L2TestSuite = (
38
42
  setup: () => Promise<EndToEndContext>,
@@ -84,7 +88,7 @@ export const uniswapL1L2TestSuite = (
84
88
 
85
89
  l1Client = deployL1ContractsValues.l1Client;
86
90
 
87
- t.watcher?.setIsMarkingAsProven(false);
91
+ t.watcher.setIsMarkingAsProven(false);
88
92
 
89
93
  if (Number(await l1Client.getBlockNumber()) < expectedForkBlockNumber) {
90
94
  throw new Error('This test must be run on a fork of mainnet with the expected fork block');
@@ -98,6 +102,7 @@ export const uniswapL1L2TestSuite = (
98
102
  ownerEthAddress = EthAddress.fromString((await l1Client.getAddresses())[0]);
99
103
 
100
104
  await ensureAccountContractsPublished(wallet, [ownerAddress, sponsorAddress]);
105
+ await ensureAuthRegistryPublished(wallet, ownerAddress);
101
106
 
102
107
  logger.info('Deploying DAI Portal, initializing and deploying l2 contract...');
103
108
  daiCrossChainHarness = await CrossChainTestHarness.new(
@@ -130,7 +135,9 @@ export const uniswapL1L2TestSuite = (
130
135
  client: l1Client,
131
136
  });
132
137
  // deploy l2 uniswap contract and attach to portal
133
- uniswapL2Contract = await UniswapContract.deploy(wallet, uniswapPortalAddress).send({ from: ownerAddress });
138
+ ({ contract: uniswapL2Contract } = await UniswapContract.deploy(wallet, uniswapPortalAddress).send({
139
+ from: ownerAddress,
140
+ }));
134
141
 
135
142
  const registryAddress = (await aztecNode.getNodeInfo()).l1ContractAddresses.registryAddress;
136
143
 
@@ -152,7 +159,6 @@ export const uniswapL1L2TestSuite = (
152
159
  await cleanup();
153
160
  });
154
161
 
155
- // docs:start:uniswap_private
156
162
  it('should uniswap trade on L1 from L2 funds privately (swaps WETH -> DAI)', async () => {
157
163
  const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
158
164
 
@@ -195,7 +201,7 @@ export const uniswapL1L2TestSuite = (
195
201
  logger.info('Withdrawing weth to L1 and sending message to swap to dai');
196
202
  const [secretForDepositingSwappedDai, secretHashForDepositingSwappedDai] = await generateClaimSecret();
197
203
 
198
- const l2UniswapInteractionReceipt = await uniswapL2Contract.methods
204
+ const { receipt: l2UniswapInteractionReceipt } = await uniswapL2Contract.methods
199
205
  .swap_private(
200
206
  wethCrossChainHarness.l2Token.address,
201
207
  wethCrossChainHarness.l2Bridge.address,
@@ -249,10 +255,13 @@ export const uniswapL1L2TestSuite = (
249
255
  // ensure that uniswap contract didn't eat the funds.
250
256
  await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n);
251
257
 
252
- // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
253
- const checkpointNumber = CheckpointNumber.fromBlockNumber(l2UniswapInteractionReceipt.blockNumber!);
254
- const epoch = await rollup.getEpochNumberForCheckpoint(checkpointNumber);
255
- await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
258
+ // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch
259
+ // before we can ask the witness helper for a covering root.
260
+ const minedReceipt = await aztecNode.getTxReceipt(l2UniswapInteractionReceipt.txHash);
261
+ if (minedReceipt.epochNumber === undefined) {
262
+ throw new Error('L2 Uniswap interaction tx is not yet in an epoch');
263
+ }
264
+ await cheatCodes.rollup.advanceToEpoch(EpochNumber(minedReceipt.epochNumber + 1));
256
265
  await waitForProven(aztecNode, l2UniswapInteractionReceipt, { provenTimeout: 300 });
257
266
 
258
267
  // 5. Consume L2 to L1 message by calling uniswapPortal.swap_private()
@@ -260,17 +269,29 @@ export const uniswapL1L2TestSuite = (
260
269
  const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf(
261
270
  daiCrossChainHarness.tokenPortalAddress,
262
271
  );
263
- const swapResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, swapPrivateLeaf);
264
- const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, withdrawLeaf);
272
+ const swapResult = await retryUntil(
273
+ () => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, swapPrivateLeaf),
274
+ 'swap private l2 to l1 witness',
275
+ 60,
276
+ 1,
277
+ );
278
+ const { epochNumber: epoch, numCheckpointsInEpoch } = swapResult;
279
+ const withdrawResult = await retryUntil(
280
+ () => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, withdrawLeaf),
281
+ 'withdraw l2 to l1 witness',
282
+ 60,
283
+ 1,
284
+ );
265
285
 
266
- const swapPrivateL2MessageIndex = swapResult!.leafIndex;
267
- const swapPrivateSiblingPath = swapResult!.siblingPath;
286
+ const swapPrivateL2MessageIndex = swapResult.leafIndex;
287
+ const swapPrivateSiblingPath = swapResult.siblingPath;
268
288
 
269
- const withdrawL2MessageIndex = withdrawResult!.leafIndex;
270
- const withdrawSiblingPath = withdrawResult!.siblingPath;
289
+ const withdrawL2MessageIndex = withdrawResult.leafIndex;
290
+ const withdrawSiblingPath = withdrawResult.siblingPath;
271
291
 
272
292
  const withdrawMessageMetadata = {
273
293
  _epoch: BigInt(epoch),
294
+ _numCheckpointsInEpoch: BigInt(withdrawResult.numCheckpointsInEpoch),
274
295
  _leafIndex: BigInt(withdrawL2MessageIndex),
275
296
  _path: withdrawSiblingPath
276
297
  .toBufferArray()
@@ -279,6 +300,7 @@ export const uniswapL1L2TestSuite = (
279
300
 
280
301
  const swapPrivateMessageMetadata = {
281
302
  _epoch: BigInt(epoch),
303
+ _numCheckpointsInEpoch: BigInt(numCheckpointsInEpoch),
282
304
  _leafIndex: BigInt(swapPrivateL2MessageIndex),
283
305
  _path: swapPrivateSiblingPath
284
306
  .toBufferArray()
@@ -336,10 +358,8 @@ export const uniswapL1L2TestSuite = (
336
358
  logger.info('WETH balance after swap : ', wethL2BalanceAfterSwap.toString());
337
359
  logger.info('DAI balance after swap : ', daiL2BalanceAfterSwap.toString());
338
360
  });
339
- // docs:end:uniswap_private
340
361
 
341
362
  // TODO(#7463): reenable look into this failure https://github.com/AztecProtocol/aztec-packages/actions/runs/9912612912/job/27388320150?pr=7462
342
- // // docs:start:uniswap_public
343
363
  // it('should uniswap trade on L1 from L2 funds publicly (swaps WETH -> DAI)', async () => {
344
364
  // const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
345
365
 
@@ -572,7 +592,6 @@ export const uniswapL1L2TestSuite = (
572
592
  // logger.info('WETH balance after swap : ', wethL2BalanceAfterSwap.toString());
573
593
  // logger.info('DAI balance after swap : ', daiL2BalanceAfterSwap.toString());
574
594
  // });
575
- // // docs:end:uniswap_public
576
595
 
577
596
  // Edge cases for the private flow:
578
597
  // note - tests for uniswapPortal.sol and minting asset on L2 are covered in other tests.
@@ -787,7 +806,7 @@ export const uniswapL1L2TestSuite = (
787
806
  logger.info('Withdrawing weth to L1 and sending message to swap to dai');
788
807
 
789
808
  const [, secretHashForDepositingSwappedDai] = await generateClaimSecret();
790
- const withdrawReceipt = await uniswapL2Contract.methods
809
+ const { receipt: withdrawReceipt } = await uniswapL2Contract.methods
791
810
  .swap_private(
792
811
  wethCrossChainHarness.l2Token.address,
793
812
  wethCrossChainHarness.l2Bridge.address,
@@ -838,20 +857,41 @@ export const uniswapL1L2TestSuite = (
838
857
  chainId: new Fr(l1Client.chain.id),
839
858
  });
840
859
 
841
- const epoch = await rollup.getEpochNumberForCheckpoint(
842
- CheckpointNumber.fromBlockNumber(withdrawReceipt.blockNumber!),
860
+ // ensure that user's funds were burnt
861
+ await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
862
+
863
+ // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch
864
+ // before we can ask the witness helper for a covering root.
865
+ const minedReceipt = await aztecNode.getTxReceipt(withdrawReceipt.txHash);
866
+ if (minedReceipt.epochNumber === undefined) {
867
+ throw new Error('Withdraw tx is not yet in an epoch');
868
+ }
869
+ await cheatCodes.rollup.advanceToEpoch(EpochNumber(minedReceipt.epochNumber + 1));
870
+ await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
871
+
872
+ const swapResult = await retryUntil(
873
+ () => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, swapPrivateLeaf),
874
+ 'swap private l2 to l1 witness',
875
+ 60,
876
+ 1,
877
+ );
878
+ const { epochNumber: epoch, numCheckpointsInEpoch } = swapResult;
879
+ const withdrawResult = await retryUntil(
880
+ () => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, withdrawLeaf),
881
+ 'withdraw l2 to l1 witness',
882
+ 60,
883
+ 1,
843
884
  );
844
- const swapResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, swapPrivateLeaf);
845
- const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, withdrawLeaf);
846
885
 
847
- const swapPrivateL2MessageIndex = swapResult!.leafIndex;
848
- const swapPrivateSiblingPath = swapResult!.siblingPath;
886
+ const swapPrivateL2MessageIndex = swapResult.leafIndex;
887
+ const swapPrivateSiblingPath = swapResult.siblingPath;
849
888
 
850
- const withdrawL2MessageIndex = withdrawResult!.leafIndex;
851
- const withdrawSiblingPath = withdrawResult!.siblingPath;
889
+ const withdrawL2MessageIndex = withdrawResult.leafIndex;
890
+ const withdrawSiblingPath = withdrawResult.siblingPath;
852
891
 
853
892
  const withdrawMessageMetadata = {
854
893
  _epoch: BigInt(epoch),
894
+ _numCheckpointsInEpoch: BigInt(withdrawResult.numCheckpointsInEpoch),
855
895
  _leafIndex: BigInt(withdrawL2MessageIndex),
856
896
  _path: withdrawSiblingPath
857
897
  .toBufferArray()
@@ -860,19 +900,13 @@ export const uniswapL1L2TestSuite = (
860
900
 
861
901
  const swapPrivateMessageMetadata = {
862
902
  _epoch: BigInt(epoch),
903
+ _numCheckpointsInEpoch: BigInt(numCheckpointsInEpoch),
863
904
  _leafIndex: BigInt(swapPrivateL2MessageIndex),
864
905
  _path: swapPrivateSiblingPath
865
906
  .toBufferArray()
866
907
  .map((buf: Buffer) => `0x${buf.toString('hex')}`) as readonly `0x${string}`[],
867
908
  };
868
909
 
869
- // ensure that user's funds were burnt
870
- await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
871
-
872
- // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
873
- await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
874
- await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
875
-
876
910
  // On L1 call swap_public!
877
911
  logger.info('call swap_public on L1');
878
912
  const swapArgs = [
@@ -916,7 +950,7 @@ export const uniswapL1L2TestSuite = (
916
950
 
917
951
  // Call swap_public on L2
918
952
  const secretHashForDepositingSwappedDai = Fr.random();
919
- const withdrawReceipt = await uniswapL2Contract.methods
953
+ const { receipt: withdrawReceipt } = await uniswapL2Contract.methods
920
954
  .swap_public(
921
955
  ownerAddress,
922
956
  wethCrossChainHarness.l2Bridge.address,
@@ -972,20 +1006,41 @@ export const uniswapL1L2TestSuite = (
972
1006
  chainId: new Fr(l1Client.chain.id),
973
1007
  });
974
1008
 
975
- const epoch = await rollup.getEpochNumberForCheckpoint(
976
- CheckpointNumber.fromBlockNumber(withdrawReceipt.blockNumber!),
1009
+ // check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
1010
+ await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
1011
+
1012
+ // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch
1013
+ // before we can ask the witness helper for a covering root.
1014
+ const minedReceipt = await aztecNode.getTxReceipt(withdrawReceipt.txHash);
1015
+ if (minedReceipt.epochNumber === undefined) {
1016
+ throw new Error('Withdraw tx is not yet in an epoch');
1017
+ }
1018
+ await cheatCodes.rollup.advanceToEpoch(EpochNumber(minedReceipt.epochNumber + 1));
1019
+ await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
1020
+
1021
+ const swapResult = await retryUntil(
1022
+ () => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, swapPublicLeaf),
1023
+ 'swap public l2 to l1 witness',
1024
+ 60,
1025
+ 1,
1026
+ );
1027
+ const { epochNumber: epoch, numCheckpointsInEpoch } = swapResult;
1028
+ const withdrawResult = await retryUntil(
1029
+ () => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, withdrawLeaf),
1030
+ 'withdraw l2 to l1 witness',
1031
+ 60,
1032
+ 1,
977
1033
  );
978
- const swapResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, swapPublicLeaf);
979
- const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, withdrawLeaf);
980
1034
 
981
- const swapPublicL2MessageIndex = swapResult!.leafIndex;
982
- const swapPublicSiblingPath = swapResult!.siblingPath;
1035
+ const swapPublicL2MessageIndex = swapResult.leafIndex;
1036
+ const swapPublicSiblingPath = swapResult.siblingPath;
983
1037
 
984
- const withdrawL2MessageIndex = withdrawResult!.leafIndex;
985
- const withdrawSiblingPath = withdrawResult!.siblingPath;
1038
+ const withdrawL2MessageIndex = withdrawResult.leafIndex;
1039
+ const withdrawSiblingPath = withdrawResult.siblingPath;
986
1040
 
987
1041
  const withdrawMessageMetadata = {
988
1042
  _epoch: BigInt(epoch),
1043
+ _numCheckpointsInEpoch: BigInt(withdrawResult.numCheckpointsInEpoch),
989
1044
  _leafIndex: BigInt(withdrawL2MessageIndex),
990
1045
  _path: withdrawSiblingPath
991
1046
  .toBufferArray()
@@ -994,19 +1049,13 @@ export const uniswapL1L2TestSuite = (
994
1049
 
995
1050
  const swapPublicMessageMetadata = {
996
1051
  _epoch: BigInt(epoch),
1052
+ _numCheckpointsInEpoch: BigInt(numCheckpointsInEpoch),
997
1053
  _leafIndex: BigInt(swapPublicL2MessageIndex),
998
1054
  _path: swapPublicSiblingPath
999
1055
  .toBufferArray()
1000
1056
  .map((buf: Buffer) => `0x${buf.toString('hex')}`) as readonly `0x${string}`[],
1001
1057
  };
1002
1058
 
1003
- // check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
1004
- await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
1005
-
1006
- // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
1007
- await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
1008
- await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
1009
-
1010
1059
  // Call swap_private on L1
1011
1060
  logger.info('Execute withdraw and swap on the uniswapPortal!');
1012
1061
 
@@ -0,0 +1,23 @@
1
+ import type { Fr } from '@aztec/aztec.js/fields';
2
+ import type { AztecNode } from '@aztec/aztec.js/node';
3
+ import { retryUntil } from '@aztec/foundation/retry';
4
+
5
+ /**
6
+ * Waits until the archiver has seen the L1 to L2 message and indexed it. Unlike
7
+ * {@link waitForL1ToL2MessageReady} from `@aztec/aztec.js/messaging`, this does not
8
+ * require the L2 chain to have advanced to the message's checkpoint — it only confirms
9
+ * the message has been picked up from L1. Use this in tests that explicitly produce L2
10
+ * blocks afterwards to make the message consumable.
11
+ */
12
+ export function waitForL1ToL2MessageSeen(
13
+ node: Pick<AztecNode, 'getL1ToL2MessageCheckpoint'>,
14
+ l1ToL2MessageHash: Fr,
15
+ opts: { timeoutSeconds: number },
16
+ ) {
17
+ return retryUntil(
18
+ async () => (await node.getL1ToL2MessageCheckpoint(l1ToL2MessageHash)) !== undefined,
19
+ `L1 to L2 message ${l1ToL2MessageHash.toString()} seen`,
20
+ opts.timeoutSeconds,
21
+ 1,
22
+ );
23
+ }
@@ -7,6 +7,7 @@ import { SlotNumber } from '@aztec/foundation/branded-types';
7
7
  import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
8
8
  import type { TestDateProvider } from '@aztec/foundation/timer';
9
9
  import type { LendingContract } from '@aztec/noir-contracts.js/Lending';
10
+ import type { AztecNode, AztecNodeDebug } from '@aztec/stdlib/interfaces/client';
10
11
 
11
12
  import type { TokenSimulator } from './token_simulator.js';
12
13
 
@@ -92,30 +93,45 @@ export class LendingSimulator {
92
93
  public stableCoin: TokenSimulator,
93
94
  ) {}
94
95
 
95
- async prepare() {
96
+ prepare() {
96
97
  this.accumulator = BASE;
97
- const slot = await this.rollup.getSlotAt(BigInt(await this.cc.eth.timestamp()) + BigInt(this.ethereumSlotDuration));
98
- this.time = Number(await this.rollup.getTimestampForSlot(slot));
98
+ this.time = 0;
99
99
  }
100
100
 
101
- async progressSlots(diff: number, dateProvider?: TestDateProvider) {
101
+ /**
102
+ * Advances the simulator's accumulator and clock to match a block timestamp observed on chain.
103
+ * Call this BEFORE applying any accumulator-sensitive mutation (borrow/repay) so the mutation
104
+ * sees the same accumulator as the contract did during execution.
105
+ */
106
+ observeBlockTimestamp(ts: number) {
107
+ const diff = ts - this.time;
108
+ if (diff > 0) {
109
+ this.accumulator = muldivDown(this.accumulator, computeMultiplier(this.rate, BigInt(diff)), BASE);
110
+ }
111
+ this.time = ts;
112
+ }
113
+
114
+ async progressSlots(diff: number, _dateProvider?: TestDateProvider, node?: AztecNode & AztecNodeDebug) {
102
115
  if (diff <= 1) {
103
116
  return;
104
117
  }
105
118
 
106
- const slot = await this.rollup.getSlotAt(BigInt(await this.cc.eth.timestamp()));
119
+ const slot = await this.rollup.getSlotAt(BigInt(await this.cc.eth.lastBlockTimestamp()));
107
120
  const targetSlot = SlotNumber(slot + diff);
108
121
  const ts = Number(await this.rollup.getTimestampForSlot(targetSlot));
109
- const timeDiff = ts - this.time;
110
- this.time = ts;
111
122
 
112
- // Mine ethereum blocks such that the next block will be in a new slot
113
- await this.cc.eth.warp(this.time - this.ethereumSlotDuration);
114
- if (dateProvider) {
115
- dateProvider.setTime(this.time * 1000);
123
+ // Queue-aware warp under AutomineSequencer: atomic warp + mineBlock that advances L2 time to the
124
+ // target slot. The cheat code routes through the AutomineSequencer queue when one is installed,
125
+ // and otherwise falls back to a manual warp + mineBlock loop.
126
+ if (node) {
127
+ await this.cc.warpL2TimeAtLeastTo(node, ts);
128
+ } else {
129
+ await this.cc.eth.warp(ts - this.ethereumSlotDuration);
116
130
  }
131
+
132
+ // Mark the latest checkpoint as proven so the rollup does not reorg pending checkpoints when
133
+ // time jumps far enough forward to cross an unproven epoch boundary.
117
134
  await this.cc.rollup.markAsProven(await this.rollup.getCheckpointNumber());
118
- this.accumulator = muldivDown(this.accumulator, computeMultiplier(this.rate, BigInt(timeDiff)), BASE);
119
135
  }
120
136
 
121
137
  depositPrivate(from: AztecAddress, onBehalfOf: Fr, amount: bigint) {
@@ -186,14 +202,16 @@ export class LendingSimulator {
186
202
 
187
203
  expect(this.borrowed).toEqual(this.stableCoin.totalSupply - this.mintedOutside);
188
204
 
189
- const asset = await this.lendingContract.methods.get_asset(0).simulate({ from: this.account.address });
205
+ const { result: asset } = await this.lendingContract.methods.get_asset(0).simulate({ from: this.account.address });
190
206
 
191
207
  const interestAccumulator = asset['interest_accumulator'];
192
208
  expect(interestAccumulator).toEqual(this.accumulator);
193
209
  expect(asset['last_updated_ts']).toEqual(BigInt(this.time));
194
210
 
195
211
  for (const key of [this.account.address, AztecAddress.fromField(await this.account.key())]) {
196
- const privatePos = await this.lendingContract.methods.get_position(key).simulate({ from: this.account.address });
212
+ const { result: privatePos } = await this.lendingContract.methods
213
+ .get_position(key)
214
+ .simulate({ from: this.account.address });
197
215
  expect(new Fr(privatePos['collateral'])).toEqual(this.collateral[key.toString()] ?? Fr.ZERO);
198
216
  expect(new Fr(privatePos['static_debt'])).toEqual(this.staticDebt[key.toString()] ?? Fr.ZERO);
199
217
  expect(privatePos['debt']).toEqual(
@@ -109,7 +109,9 @@ export class TokenSimulator {
109
109
  await Promise.all(
110
110
  chunk(calls, 5).map(batch => new BatchCall(this.defaultWallet, batch).simulate({ from: this.defaultAddress })),
111
111
  )
112
- ).flat();
112
+ )
113
+ .flatMap(r => r.result)
114
+ .map(r => r.result);
113
115
  expect(results[0]).toEqual(this.totalSupply);
114
116
 
115
117
  // Check that all our balances match
@@ -119,39 +121,13 @@ export class TokenSimulator {
119
121
  }
120
122
 
121
123
  async checkPrivate() {
122
- // Private calls
123
- const defaultLookups = [];
124
- const nonDefaultLookups = [];
125
-
126
124
  for (const address of this.accounts) {
127
- if (this.lookupProvider.has(address.toString())) {
128
- nonDefaultLookups.push(address);
129
- } else {
130
- defaultLookups.push(address);
131
- }
132
- }
133
-
134
- const defaultCalls = defaultLookups.map(address => this.token.methods.balance_of_private(address));
135
- const results = (
136
- await Promise.all(
137
- chunk(defaultCalls, 4).map(batch =>
138
- new BatchCall(this.defaultWallet, batch).simulate({ from: this.defaultAddress }),
139
- ),
140
- )
141
- ).flat();
142
- for (let i = 0; i < defaultLookups.length; i++) {
143
- expect(results[i]).toEqual(this.balanceOfPrivate(defaultLookups[i]));
144
- }
145
-
146
- // We are just running individual calls for the non-default lookups
147
- // @todo We should also batch these
148
- for (const address of nonDefaultLookups) {
149
125
  const wallet = this.lookupProvider.get(address.toString());
150
126
  const asset = wallet ? this.token.withWallet(wallet) : this.token;
151
127
 
152
- const actualPrivateBalance = await asset.methods
153
- .balance_of_private({ address })
154
- .simulate({ from: this.defaultAddress });
128
+ const { result: actualPrivateBalance } = await asset.methods
129
+ .balance_of_private(address)
130
+ .simulate({ from: address });
155
131
  expect(actualPrivateBalance).toEqual(this.balanceOfPrivate(address));
156
132
  }
157
133
  }