@aztec/end-to-end 0.0.1-commit.24de95ac → 0.0.1-commit.2606882

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 (299) hide show
  1. package/README.md +27 -0
  2. package/dest/bench/client_flows/benchmark.d.ts +17 -2
  3. package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
  4. package/dest/bench/client_flows/benchmark.js +38 -1
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts +23 -17
  6. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  7. package/dest/bench/client_flows/client_flows_benchmark.js +143 -136
  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/client_flows/data_extractor.d.ts +1 -1
  12. package/dest/bench/client_flows/data_extractor.js +7 -27
  13. package/dest/bench/utils.d.ts +8 -7
  14. package/dest/bench/utils.d.ts.map +1 -1
  15. package/dest/bench/utils.js +33 -19
  16. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +12 -10
  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 +120 -117
  19. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +33 -16
  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 +124 -70
  22. package/dest/e2e_deploy_contract/deploy_test.d.ts +7 -6
  23. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  24. package/dest/e2e_deploy_contract/deploy_test.js +20 -14
  25. package/dest/e2e_epochs/epochs_test.d.ts +49 -16
  26. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  27. package/dest/e2e_epochs/epochs_test.js +188 -64
  28. package/dest/e2e_fees/bridging_race.notest.d.ts +1 -1
  29. package/dest/e2e_fees/bridging_race.notest.js +5 -7
  30. package/dest/e2e_fees/fees_test.d.ts +25 -18
  31. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  32. package/dest/e2e_fees/fees_test.js +162 -141
  33. package/dest/e2e_l1_publisher/write_json.d.ts +4 -3
  34. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -1
  35. package/dest/e2e_l1_publisher/write_json.js +18 -19
  36. package/dest/e2e_multi_validator/utils.d.ts +1 -1
  37. package/dest/e2e_multi_validator/utils.js +1 -1
  38. package/dest/e2e_nested_contract/nested_contract_test.d.ts +7 -10
  39. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  40. package/dest/e2e_nested_contract/nested_contract_test.js +32 -40
  41. package/dest/e2e_p2p/inactivity_slash_test.d.ts +3 -3
  42. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -1
  43. package/dest/e2e_p2p/inactivity_slash_test.js +11 -9
  44. package/dest/e2e_p2p/p2p_network.d.ts +237 -28
  45. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  46. package/dest/e2e_p2p/p2p_network.js +176 -129
  47. package/dest/e2e_p2p/reqresp/utils.d.ts +22 -0
  48. package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -0
  49. package/dest/e2e_p2p/reqresp/utils.js +206 -0
  50. package/dest/e2e_p2p/shared.d.ts +44 -15
  51. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  52. package/dest/e2e_p2p/shared.js +102 -68
  53. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +2 -0
  54. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +1 -0
  55. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.js +184 -0
  56. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts +18 -0
  57. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +1 -0
  58. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.js +120 -0
  59. package/dest/e2e_token_contract/token_contract_test.d.ts +20 -11
  60. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  61. package/dest/e2e_token_contract/token_contract_test.js +103 -93
  62. package/dest/fixtures/authwit_proxy.d.ts +15 -0
  63. package/dest/fixtures/authwit_proxy.d.ts.map +1 -0
  64. package/dest/fixtures/authwit_proxy.js +34 -0
  65. package/dest/fixtures/e2e_prover_test.d.ts +19 -24
  66. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  67. package/dest/fixtures/e2e_prover_test.js +126 -145
  68. package/dest/fixtures/elu_monitor.d.ts +21 -0
  69. package/dest/fixtures/elu_monitor.d.ts.map +1 -0
  70. package/dest/fixtures/elu_monitor.js +102 -0
  71. package/dest/fixtures/fixtures.d.ts +75 -3
  72. package/dest/fixtures/fixtures.d.ts.map +1 -1
  73. package/dest/fixtures/fixtures.js +73 -3
  74. package/dest/fixtures/get_acvm_config.d.ts +1 -1
  75. package/dest/fixtures/get_acvm_config.js +1 -1
  76. package/dest/fixtures/get_bb_config.d.ts +1 -1
  77. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  78. package/dest/fixtures/get_bb_config.js +5 -5
  79. package/dest/fixtures/ha_setup.d.ts +71 -0
  80. package/dest/fixtures/ha_setup.d.ts.map +1 -0
  81. package/dest/fixtures/ha_setup.js +116 -0
  82. package/dest/fixtures/index.d.ts +2 -1
  83. package/dest/fixtures/index.d.ts.map +1 -1
  84. package/dest/fixtures/index.js +1 -0
  85. package/dest/fixtures/l1_to_l2_messaging.d.ts +4 -3
  86. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  87. package/dest/fixtures/l1_to_l2_messaging.js +2 -2
  88. package/dest/fixtures/logging.d.ts +1 -1
  89. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts +25 -0
  90. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts.map +1 -0
  91. package/dest/fixtures/schnorr_hardcoded_account_contract.js +37 -0
  92. package/dest/fixtures/setup.d.ts +272 -0
  93. package/dest/fixtures/setup.d.ts.map +1 -0
  94. package/dest/fixtures/setup.js +735 -0
  95. package/dest/fixtures/setup_p2p_test.d.ts +22 -11
  96. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  97. package/dest/fixtures/setup_p2p_test.js +57 -38
  98. package/dest/fixtures/token_utils.d.ts +6 -3
  99. package/dest/fixtures/token_utils.d.ts.map +1 -1
  100. package/dest/fixtures/token_utils.js +13 -9
  101. package/dest/fixtures/utils.d.ts +5 -192
  102. package/dest/fixtures/utils.d.ts.map +1 -1
  103. package/dest/fixtures/utils.js +4 -648
  104. package/dest/fixtures/web3signer.d.ts +1 -1
  105. package/dest/fixtures/web3signer.js +1 -1
  106. package/dest/fixtures/with_telemetry_utils.d.ts +2 -2
  107. package/dest/fixtures/with_telemetry_utils.d.ts.map +1 -1
  108. package/dest/fixtures/with_telemetry_utils.js +2 -2
  109. package/dest/forward-compatibility/wallet_rpc_client.d.ts +7 -0
  110. package/dest/forward-compatibility/wallet_rpc_client.d.ts.map +1 -0
  111. package/dest/forward-compatibility/wallet_rpc_client.js +15 -0
  112. package/dest/forward-compatibility/wallet_service.d.ts +3 -0
  113. package/dest/forward-compatibility/wallet_service.d.ts.map +1 -0
  114. package/dest/forward-compatibility/wallet_service.js +109 -0
  115. package/dest/index.d.ts +1 -1
  116. package/dest/install_legacy_contracts.d.cts +10 -0
  117. package/dest/install_legacy_contracts.d.cts.map +1 -0
  118. package/dest/legacy-jest-resolver.d.cts +3 -0
  119. package/dest/legacy-jest-resolver.d.cts.map +1 -0
  120. package/dest/quality_of_service/grafana_client.d.ts +41 -0
  121. package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
  122. package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
  123. package/dest/quality_of_service/prometheus_client.d.ts +38 -0
  124. package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
  125. package/dest/quality_of_service/prometheus_client.js +67 -0
  126. package/dest/shared/cross_chain_test_harness.d.ts +9 -6
  127. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  128. package/dest/shared/cross_chain_test_harness.js +34 -30
  129. package/dest/shared/gas_portal_test_harness.d.ts +9 -6
  130. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  131. package/dest/shared/gas_portal_test_harness.js +21 -12
  132. package/dest/shared/index.d.ts +3 -2
  133. package/dest/shared/index.d.ts.map +1 -1
  134. package/dest/shared/index.js +1 -0
  135. package/dest/shared/jest_setup.d.ts +1 -1
  136. package/dest/shared/jest_setup.js +41 -1
  137. package/dest/shared/mock_state_view.d.ts +86 -0
  138. package/dest/shared/mock_state_view.d.ts.map +1 -0
  139. package/dest/shared/mock_state_view.js +186 -0
  140. package/dest/shared/submit-transactions.d.ts +4 -4
  141. package/dest/shared/submit-transactions.d.ts.map +1 -1
  142. package/dest/shared/submit-transactions.js +9 -11
  143. package/dest/shared/uniswap_l1_l2.d.ts +3 -27
  144. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  145. package/dest/shared/uniswap_l1_l2.js +87 -50
  146. package/dest/shared/wait_for_l1_to_l2_message.d.ts +13 -0
  147. package/dest/shared/wait_for_l1_to_l2_message.d.ts.map +1 -0
  148. package/dest/shared/wait_for_l1_to_l2_message.js +10 -0
  149. package/dest/simulators/index.d.ts +1 -1
  150. package/dest/simulators/lending_simulator.d.ts +11 -4
  151. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  152. package/dest/simulators/lending_simulator.js +32 -18
  153. package/dest/simulators/token_simulator.d.ts +1 -1
  154. package/dest/simulators/token_simulator.d.ts.map +1 -1
  155. package/dest/simulators/token_simulator.js +3 -24
  156. package/dest/spartan/setup_test_wallets.d.ts +18 -6
  157. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  158. package/dest/spartan/setup_test_wallets.js +159 -30
  159. package/dest/spartan/tx_metrics.d.ts +102 -0
  160. package/dest/spartan/tx_metrics.d.ts.map +1 -0
  161. package/dest/spartan/tx_metrics.js +475 -0
  162. package/dest/spartan/utils/bot.d.ts +28 -0
  163. package/dest/spartan/utils/bot.d.ts.map +1 -0
  164. package/dest/spartan/utils/bot.js +142 -0
  165. package/dest/spartan/utils/chaos.d.ts +79 -0
  166. package/dest/spartan/utils/chaos.d.ts.map +1 -0
  167. package/dest/spartan/utils/chaos.js +142 -0
  168. package/dest/spartan/utils/clients.d.ts +39 -0
  169. package/dest/spartan/utils/clients.d.ts.map +1 -0
  170. package/dest/spartan/utils/clients.js +90 -0
  171. package/dest/spartan/utils/config.d.ts +19 -0
  172. package/dest/spartan/utils/config.d.ts.map +1 -0
  173. package/dest/spartan/utils/config.js +23 -0
  174. package/dest/spartan/utils/health.d.ts +63 -0
  175. package/dest/spartan/utils/health.d.ts.map +1 -0
  176. package/dest/spartan/utils/health.js +202 -0
  177. package/dest/spartan/utils/helm.d.ts +15 -0
  178. package/dest/spartan/utils/helm.d.ts.map +1 -0
  179. package/dest/spartan/utils/helm.js +47 -0
  180. package/dest/spartan/utils/index.d.ts +11 -0
  181. package/dest/spartan/utils/index.d.ts.map +1 -0
  182. package/dest/spartan/utils/index.js +22 -0
  183. package/dest/spartan/utils/k8s.d.ts +128 -0
  184. package/dest/spartan/utils/k8s.d.ts.map +1 -0
  185. package/dest/spartan/utils/k8s.js +381 -0
  186. package/dest/spartan/utils/nodes.d.ts +40 -0
  187. package/dest/spartan/utils/nodes.d.ts.map +1 -0
  188. package/dest/spartan/utils/nodes.js +461 -0
  189. package/dest/spartan/utils/pod_logs.d.ts +25 -0
  190. package/dest/spartan/utils/pod_logs.d.ts.map +1 -0
  191. package/dest/spartan/utils/pod_logs.js +74 -0
  192. package/dest/spartan/utils/scripts.d.ts +30 -0
  193. package/dest/spartan/utils/scripts.d.ts.map +1 -0
  194. package/dest/spartan/utils/scripts.js +81 -0
  195. package/dest/spartan/utils.d.ts +2 -218
  196. package/dest/spartan/utils.d.ts.map +1 -1
  197. package/dest/spartan/utils.js +1 -749
  198. package/dest/test-wallet/test_wallet.d.ts +85 -0
  199. package/dest/test-wallet/test_wallet.d.ts.map +1 -0
  200. package/dest/test-wallet/test_wallet.js +273 -0
  201. package/dest/test-wallet/utils.d.ts +41 -0
  202. package/dest/test-wallet/utils.d.ts.map +1 -0
  203. package/dest/test-wallet/utils.js +66 -0
  204. package/dest/test-wallet/wallet_worker_script.d.ts +2 -0
  205. package/dest/test-wallet/wallet_worker_script.d.ts.map +1 -0
  206. package/dest/test-wallet/wallet_worker_script.js +53 -0
  207. package/dest/test-wallet/worker_wallet.d.ts +53 -0
  208. package/dest/test-wallet/worker_wallet.d.ts.map +1 -0
  209. package/dest/test-wallet/worker_wallet.js +155 -0
  210. package/dest/test-wallet/worker_wallet_schema.d.ts +160 -0
  211. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -0
  212. package/dest/test-wallet/worker_wallet_schema.js +22 -0
  213. package/package.json +56 -46
  214. package/src/bench/client_flows/benchmark.ts +43 -2
  215. package/src/bench/client_flows/client_flows_benchmark.ts +203 -206
  216. package/src/bench/client_flows/config.ts +9 -1
  217. package/src/bench/client_flows/data_extractor.ts +6 -28
  218. package/src/bench/utils.ts +38 -22
  219. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +141 -152
  220. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +180 -127
  221. package/src/e2e_deploy_contract/deploy_test.ts +25 -17
  222. package/src/e2e_epochs/epochs_test.ts +254 -116
  223. package/src/e2e_fees/bridging_race.notest.ts +6 -12
  224. package/src/e2e_fees/fees_test.ts +215 -229
  225. package/src/e2e_l1_publisher/write_json.ts +20 -19
  226. package/src/e2e_multi_validator/utils.ts +1 -1
  227. package/src/e2e_nested_contract/nested_contract_test.ts +38 -56
  228. package/src/e2e_p2p/inactivity_slash_test.ts +12 -10
  229. package/src/e2e_p2p/p2p_network.ts +246 -201
  230. package/src/e2e_p2p/reqresp/utils.ts +274 -0
  231. package/src/e2e_p2p/shared.ts +132 -82
  232. package/src/e2e_storage_proof/fixtures/storage_proof.json +915 -0
  233. package/src/e2e_storage_proof/fixtures/storage_proof_fetcher.ts +190 -0
  234. package/src/e2e_storage_proof/fixtures/storage_proof_fixture.ts +173 -0
  235. package/src/e2e_token_contract/token_contract_test.ts +129 -117
  236. package/src/fixtures/authwit_proxy.ts +54 -0
  237. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  238. package/src/fixtures/e2e_prover_test.ts +154 -199
  239. package/src/fixtures/elu_monitor.ts +126 -0
  240. package/src/fixtures/fixtures.ts +95 -5
  241. package/src/fixtures/get_acvm_config.ts +1 -1
  242. package/src/fixtures/get_bb_config.ts +7 -6
  243. package/src/fixtures/ha_setup.ts +188 -0
  244. package/src/fixtures/index.ts +1 -0
  245. package/src/fixtures/l1_to_l2_messaging.ts +4 -2
  246. package/src/fixtures/schnorr_hardcoded_account_contract.ts +49 -0
  247. package/src/fixtures/setup.ts +1056 -0
  248. package/src/fixtures/setup_p2p_test.ts +70 -56
  249. package/src/fixtures/token_utils.ts +9 -8
  250. package/src/fixtures/utils.ts +29 -947
  251. package/src/fixtures/web3signer.ts +1 -1
  252. package/src/fixtures/with_telemetry_utils.ts +2 -2
  253. package/src/forward-compatibility/wallet_rpc_client.ts +14 -0
  254. package/src/forward-compatibility/wallet_service.ts +104 -0
  255. package/src/guides/up_quick_start.sh +4 -6
  256. package/src/install_legacy_contracts.cjs +75 -0
  257. package/src/legacy-jest-resolver.cjs +112 -0
  258. package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +1 -1
  259. package/src/quality_of_service/prometheus_client.ts +113 -0
  260. package/src/shared/cross_chain_test_harness.ts +37 -40
  261. package/src/shared/gas_portal_test_harness.ts +24 -14
  262. package/src/shared/index.ts +2 -1
  263. package/src/shared/jest_setup.ts +51 -1
  264. package/src/shared/mock_state_view.ts +188 -0
  265. package/src/shared/submit-transactions.ts +11 -16
  266. package/src/shared/uniswap_l1_l2.ts +142 -114
  267. package/src/shared/wait_for_l1_to_l2_message.ts +23 -0
  268. package/src/simulators/lending_simulator.ts +39 -19
  269. package/src/simulators/token_simulator.ts +6 -30
  270. package/src/spartan/DEVELOP.md +7 -0
  271. package/src/spartan/setup_test_wallets.ts +234 -32
  272. package/src/spartan/tx_metrics.ts +434 -0
  273. package/src/spartan/utils/bot.ts +188 -0
  274. package/src/spartan/utils/chaos.ts +253 -0
  275. package/src/spartan/utils/clients.ts +100 -0
  276. package/src/spartan/utils/config.ts +29 -0
  277. package/src/spartan/utils/health.ts +255 -0
  278. package/src/spartan/utils/helm.ts +84 -0
  279. package/src/spartan/utils/index.ts +71 -0
  280. package/src/spartan/utils/k8s.ts +535 -0
  281. package/src/spartan/utils/nodes.ts +543 -0
  282. package/src/spartan/utils/pod_logs.ts +99 -0
  283. package/src/spartan/utils/scripts.ts +99 -0
  284. package/src/spartan/utils.ts +1 -942
  285. package/src/test-wallet/test_wallet.ts +376 -0
  286. package/src/test-wallet/utils.ts +108 -0
  287. package/src/test-wallet/wallet_worker_script.ts +63 -0
  288. package/src/test-wallet/worker_wallet.ts +218 -0
  289. package/src/test-wallet/worker_wallet_schema.ts +13 -0
  290. package/dest/fixtures/setup_l1_contracts.d.ts +0 -6
  291. package/dest/fixtures/setup_l1_contracts.d.ts.map +0 -1
  292. package/dest/fixtures/setup_l1_contracts.js +0 -17
  293. package/dest/fixtures/snapshot_manager.d.ts +0 -95
  294. package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
  295. package/dest/fixtures/snapshot_manager.js +0 -505
  296. package/dest/quality_of_service/alert_checker.d.ts +0 -41
  297. package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
  298. package/src/fixtures/setup_l1_contracts.ts +0 -26
  299. package/src/fixtures/snapshot_manager.ts +0 -665
@@ -0,0 +1,1056 @@
1
+ import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';
2
+ import { type InitialAccountData, generateSchnorrAccounts } from '@aztec/accounts/testing';
3
+ import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node';
4
+ import { NO_FROM } from '@aztec/aztec.js/account';
5
+ import { AztecAddress, EthAddress } from '@aztec/aztec.js/addresses';
6
+ import {
7
+ BatchCall,
8
+ type ContractFunctionInteraction,
9
+ type ContractMethod,
10
+ type DeployOptions,
11
+ type InteractionWaitOptions,
12
+ getContractClassFromArtifact,
13
+ waitForProven,
14
+ } from '@aztec/aztec.js/contracts';
15
+ import { publishContractClass, publishInstance } from '@aztec/aztec.js/deployment';
16
+ import { Fr } from '@aztec/aztec.js/fields';
17
+ import { type Logger, createLogger } from '@aztec/aztec.js/log';
18
+ import type { AztecNode } from '@aztec/aztec.js/node';
19
+ import type { Wallet } from '@aztec/aztec.js/wallet';
20
+ import { AnvilTestWatcher, type AnvilTestWatcherOpts, CheatCodes } from '@aztec/aztec/testing';
21
+ import { SPONSORED_FPC_SALT } from '@aztec/constants';
22
+ import { isAnvilTestChain } from '@aztec/ethereum/chain';
23
+ import { createExtendedL1Client } from '@aztec/ethereum/client';
24
+ import { getL1ContractsConfigEnvVars } from '@aztec/ethereum/config';
25
+ import { NULL_KEY } from '@aztec/ethereum/constants';
26
+ import { deployMulticall3 } from '@aztec/ethereum/contracts';
27
+ import {
28
+ type DeployAztecL1ContractsArgs,
29
+ type DeployAztecL1ContractsReturnType,
30
+ type Operator,
31
+ type ZKPassportArgs,
32
+ deployAztecL1Contracts,
33
+ } from '@aztec/ethereum/deploy-aztec-l1-contracts';
34
+ import type { Delayer } from '@aztec/ethereum/l1-tx-utils';
35
+ import { EthCheatCodes, EthCheatCodesWithState, startAnvil } from '@aztec/ethereum/test';
36
+ import type { Anvil } from '@aztec/ethereum/test';
37
+ import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
38
+ import { SecretValue } from '@aztec/foundation/config';
39
+ import { randomBytes } from '@aztec/foundation/crypto/random';
40
+ import { tryRmDir } from '@aztec/foundation/fs';
41
+ import { withLoggerBindings } from '@aztec/foundation/log/server';
42
+ import { retryUntil } from '@aztec/foundation/retry';
43
+ import { sleep } from '@aztec/foundation/sleep';
44
+ import { DateProvider, TestDateProvider } from '@aztec/foundation/timer';
45
+ import { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC';
46
+ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
47
+ import type { P2PClientDeps } from '@aztec/p2p';
48
+ import { MockGossipSubNetwork, getMockPubSubP2PServiceFactory } from '@aztec/p2p/test-helpers';
49
+ import { protocolContractsHash } from '@aztec/protocol-contracts';
50
+ import type { ProverNodeConfig } from '@aztec/prover-node';
51
+ import { type PXEConfig, type PXECreationOptions, getPXEConfig } from '@aztec/pxe/server';
52
+ import type { SequencerClient } from '@aztec/sequencer-client';
53
+ import { AuthRegistryArtifact, getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry';
54
+ import { HandshakeRegistryArtifact, getStandardHandshakeRegistry } from '@aztec/standard-contracts/handshake-registry';
55
+ import { PublicChecksArtifact, getStandardPublicChecks } from '@aztec/standard-contracts/public-checks';
56
+ import { ARTIFACT_VERSION_BEFORE_INJECTION } from '@aztec/stdlib/abi';
57
+ import { type ContractInstanceWithAddress, getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
58
+ import type { AztecNodeAdmin, AztecNodeDebug } from '@aztec/stdlib/interfaces/client';
59
+ import { tryStop } from '@aztec/stdlib/interfaces/server';
60
+ import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
61
+ import type { GenesisData } from '@aztec/stdlib/world-state';
62
+ import {
63
+ type TelemetryClient,
64
+ type TelemetryClientConfig,
65
+ getConfigEnvVars as getTelemetryConfig,
66
+ initTelemetryClient,
67
+ } from '@aztec/telemetry-client';
68
+ import { BenchmarkTelemetryClient } from '@aztec/telemetry-client/bench';
69
+ import { deployFundedSchnorrAccounts } from '@aztec/wallets/testing';
70
+ import { getGenesisValues } from '@aztec/world-state/testing';
71
+
72
+ import fs from 'fs/promises';
73
+ import { tmpdir } from 'os';
74
+ import path from 'path';
75
+ import type { Hex } from 'viem';
76
+ import {
77
+ type HDAccount,
78
+ type PrivateKeyAccount,
79
+ generatePrivateKey,
80
+ mnemonicToAccount,
81
+ privateKeyToAccount,
82
+ } from 'viem/accounts';
83
+ import { type Chain, foundry } from 'viem/chains';
84
+
85
+ import { TestWallet } from '../test-wallet/test_wallet.js';
86
+ import { MNEMONIC, TEST_MAX_PENDING_TX_POOL_COUNT, TEST_PEER_CHECK_INTERVAL_MS } from './fixtures.js';
87
+ import { getACVMConfig } from './get_acvm_config.js';
88
+ import { getBBConfig } from './get_bb_config.js';
89
+ import { isMetricsLoggingRequested, setupMetricsLogger } from './logging.js';
90
+ import { getEndToEndTestTelemetryClient } from './with_telemetry_utils.js';
91
+
92
+ export { startAnvil };
93
+
94
+ let telemetry: TelemetryClient | undefined = undefined;
95
+ async function getTelemetryClient(partialConfig: Partial<TelemetryClientConfig> & { benchmark?: boolean } = {}) {
96
+ if (!telemetry) {
97
+ const config = { ...getTelemetryConfig(), ...partialConfig };
98
+ telemetry = config.benchmark ? new BenchmarkTelemetryClient() : await initTelemetryClient(config);
99
+ }
100
+ return telemetry;
101
+ }
102
+
103
+ export const getPrivateKeyFromIndex = (index: number): Buffer | null => {
104
+ const hdAccount = mnemonicToAccount(MNEMONIC, { addressIndex: index });
105
+ const privKeyRaw = hdAccount.getHdKey().privateKey;
106
+ return privKeyRaw === null ? null : Buffer.from(privKeyRaw);
107
+ };
108
+
109
+ /**
110
+ * Sets up shared blob storage using FileStore in the data directory.
111
+ */
112
+ export async function setupSharedBlobStorage(config: { dataDirectory?: string } & Record<string, any>): Promise<void> {
113
+ const sharedBlobPath = path.join(config.dataDirectory!, 'shared-blobs');
114
+ await fs.mkdir(sharedBlobPath, { recursive: true });
115
+ config.blobFileStoreUrls = [`file://${sharedBlobPath}`];
116
+ config.blobFileStoreUploadUrl = `file://${sharedBlobPath}`;
117
+ }
118
+
119
+ /**
120
+ * Sets up Private eXecution Environment (PXE) and returns the corresponding test wallet.
121
+ * @param aztecNode - An instance of Aztec Node.
122
+ * @param opts - Partial configuration for the PXE.
123
+ * @param logger - The logger to be used.
124
+ * @param actor - Actor label to include in log output (e.g., 'pxe-test').
125
+ * @returns A test wallet, logger and teardown function.
126
+ */
127
+ export async function setupPXEAndGetWallet(
128
+ aztecNode: AztecNode,
129
+ opts: Partial<PXEConfig> = {},
130
+ logger = getLogger(),
131
+ actor?: string,
132
+ ): Promise<{
133
+ wallet: TestWallet;
134
+ logger: Logger;
135
+ teardown: () => Promise<void>;
136
+ }> {
137
+ const PXEConfig = { ...getPXEConfig(), ...opts };
138
+ // For tests we only want proving enabled if specifically requested
139
+ PXEConfig.proverEnabled = !!opts.proverEnabled;
140
+
141
+ // If no data directory provided, create a temp directory and clean up afterwards
142
+ const configuredDataDirectory = PXEConfig.dataDirectory;
143
+ if (!configuredDataDirectory) {
144
+ PXEConfig.dataDirectory = path.join(tmpdir(), randomBytes(8).toString('hex'));
145
+ }
146
+
147
+ const teardown = configuredDataDirectory ? () => Promise.resolve() : () => tryRmDir(PXEConfig.dataDirectory!);
148
+
149
+ const wallet = await TestWallet.create(aztecNode, PXEConfig, { loggerActorLabel: actor });
150
+
151
+ return {
152
+ wallet,
153
+ logger,
154
+ teardown,
155
+ };
156
+ }
157
+
158
+ /** Options for the e2e tests setup */
159
+ export type SetupOptions = {
160
+ /** State load */
161
+ stateLoad?: string;
162
+ /** Whether to enable metrics collection, if undefined, metrics collection is disabled */
163
+ metricsPort?: number | undefined;
164
+ /** Previously deployed contracts on L1 */
165
+ deployL1ContractsValues?: DeployAztecL1ContractsReturnType;
166
+ /** Initial fee juice for default accounts */
167
+ initialAccountFeeJuice?: Fr;
168
+ /** Number of initial accounts funded with fee juice */
169
+ numberOfInitialFundedAccounts?: number;
170
+ /** Data of the initial funded accounts */
171
+ initialFundedAccounts?: InitialAccountData[];
172
+ /** An initial set of validators */
173
+ initialValidators?: (Operator & { privateKey: `0x${string}` })[];
174
+ /** Anvil Start time */
175
+ l1StartTime?: number;
176
+ /** The anvil time where we should at the earliest be seeing L2 blocks */
177
+ l2StartTime?: number;
178
+ /** Whether to start a prover node */
179
+ startProverNode?: boolean;
180
+ /** Manual config for the telemetry client */
181
+ telemetryConfig?: Partial<TelemetryClientConfig> & { benchmark?: boolean };
182
+ /** Public data that will be inserted in the tree in genesis */
183
+ genesisPublicData?: PublicDataTreeLeaf[];
184
+ /** Specific config for the prover node, if set. */
185
+ proverNodeConfig?: Partial<ProverNodeConfig>;
186
+ /** Whether to use a mock gossip sub network for p2p clients. */
187
+ mockGossipSubNetwork?: boolean;
188
+ /** Whether to add simulated latency to the mock gossipsub network (in ms) */
189
+ mockGossipSubNetworkLatency?: number;
190
+ /** Whether to disable the anvil test watcher (can still be manually started) */
191
+ disableAnvilTestWatcher?: boolean;
192
+ anvilTestWatcherOpts?: AnvilTestWatcherOpts;
193
+ /** Whether to enable anvil automine during deployment of L1 contracts (consider defaulting this to true). */
194
+ automineL1Setup?: boolean;
195
+ /** How many accounts to seed and unlock in anvil. */
196
+ anvilAccounts?: number;
197
+ /** Port to start anvil (defaults to 8545) */
198
+ anvilPort?: number;
199
+ /**
200
+ * Number of slots per epoch for Anvil's finality simulation.
201
+ * Anvil reports `finalized = latest - slotsInAnEpoch * 2`.
202
+ */
203
+ anvilSlotsInAnEpoch?: number;
204
+ /** Key to use for publishing L1 contracts */
205
+ l1PublisherKey?: SecretValue<`0x${string}`>;
206
+ /** ZkPassport configuration (domain, scope, mock verifier) */
207
+ zkPassportArgs?: ZKPassportArgs;
208
+ /** Whether to fund the sponsored FPC in genesis (defaults to false). */
209
+ fundSponsoredFPC?: boolean;
210
+ /** Whether to skip deploying accounts during setup (legacy behavior for tests using deployAccounts helper). */
211
+ skipAccountDeployment?: boolean;
212
+ /** L1 contracts deployment arguments. */
213
+ l1ContractsArgs?: Partial<DeployAztecL1ContractsArgs>;
214
+ /** Wallet minimum fee padding multiplier */
215
+ walletMinFeePadding?: number;
216
+ /** Whether the initial node should be a lightweight RPC-only node (no sequencer, no validator).
217
+ * Use for tests that create their own validator nodes and don't need the initial sequencer. */
218
+ skipInitialSequencer?: boolean;
219
+ /** Whether to swap the production Sequencer for the minimal AutomineSequencer.
220
+ * Use only for single-sequencer non-block-building tests. See AUTOMINE_E2E_OPTS in `fixtures.ts`. */
221
+ useAutomineSequencer?: boolean;
222
+ /** Options forwarded to PXE creation (e.g. execution hooks). */
223
+ pxeCreationOptions?: PXECreationOptions;
224
+ } & Partial<AztecNodeConfig>;
225
+
226
+ /** Context for an end-to-end test as returned by the `setup` function */
227
+ export type EndToEndContext = {
228
+ /** The Anvil instance (only set if anvil was started locally). */
229
+ anvil: Anvil | undefined;
230
+ /** The Aztec Node service or client a connected to it. */
231
+ aztecNode: AztecNode & AztecNodeDebug;
232
+ /** The Aztec Node as a service. */
233
+ aztecNodeService: AztecNodeService;
234
+ /** Client to the Aztec Node admin interface. */
235
+ aztecNodeAdmin: AztecNodeAdmin;
236
+ /** The aztec node running the prover node subsystem (only set if startProverNode is true). */
237
+ proverNode: AztecNodeService | undefined;
238
+ /** A client to the sequencer service. */
239
+ sequencer: SequencerClient | undefined;
240
+ /** Return values from deployAztecL1Contracts function. */
241
+ deployL1ContractsValues: DeployAztecL1ContractsReturnType;
242
+ /** The Aztec Node configuration. */
243
+ config: AztecNodeConfig;
244
+ /** The Aztec Node configuration (alias for config for backward compatibility). */
245
+ aztecNodeConfig: AztecNodeConfig;
246
+ /** The data for the initial funded accounts. */
247
+ initialFundedAccounts: InitialAccountData[];
248
+ /** The wallet to be used. */
249
+ wallet: TestWallet;
250
+ /** The wallets to be used. */
251
+ accounts: AztecAddress[];
252
+ /** Logger instance named as the current test. */
253
+ logger: Logger;
254
+ /** The cheat codes. */
255
+ cheatCodes: CheatCodes;
256
+ /** The cheat codes for L1 */
257
+ ethCheatCodes: EthCheatCodes;
258
+ /** The anvil test watcher. */
259
+ watcher: AnvilTestWatcher;
260
+ /** Allows tweaking current system time, used by the epoch cache only. */
261
+ dateProvider: TestDateProvider;
262
+ /** Telemetry client */
263
+ telemetryClient: TelemetryClient;
264
+ /** Mock gossip sub network used for gossipping messages (only if mockGossipSubNetwork was set to true in opts) */
265
+ mockGossipSubNetwork: MockGossipSubNetwork | undefined;
266
+ /** Delayer for sequencer L1 txs (only when enableDelayer is true). */
267
+ sequencerDelayer: Delayer | undefined;
268
+ /** Delayer for prover node L1 txs (only when enableDelayer and startProverNode are true). */
269
+ proverDelayer: Delayer | undefined;
270
+ /** Genesis data used for setting up nodes. */
271
+ genesis: GenesisData | undefined;
272
+ /** ACVM config (only set if running locally). */
273
+ acvmConfig: Awaited<ReturnType<typeof getACVMConfig>>;
274
+ /** BB config (only set if running locally). */
275
+ bbConfig: Awaited<ReturnType<typeof getBBConfig>>;
276
+ /** Directory to cleanup on teardown. */
277
+ directoryToCleanup: string;
278
+ /** Function to stop the started services. */
279
+ teardown: () => Promise<void>;
280
+ };
281
+
282
+ /**
283
+ * When CONTRACT_ARTIFACTS_VERSION is set (backwards compatibility testing), asserts that the loaded artifact's
284
+ * aztecVersion matches the expected version. This is a sanity check verifying that the legacy artifact resolver
285
+ * actually swapped in the correct version.
286
+ */
287
+ function assertContractArtifactsVersion() {
288
+ const expected = process.env.CONTRACT_ARTIFACTS_VERSION;
289
+ if (!expected) {
290
+ return;
291
+ }
292
+ const { aztecVersion } = SponsoredFPCContract.artifact;
293
+ // TODO(F-557): Remove this bypass once pre-version artifacts are no longer tested.
294
+ if (aztecVersion === ARTIFACT_VERSION_BEFORE_INJECTION) {
295
+ createLogger('e2e:setup').info(
296
+ `Skipping artifact version check: artifact predates version injection (CONTRACT_ARTIFACTS_VERSION=${expected})`,
297
+ );
298
+ return;
299
+ }
300
+ if (aztecVersion !== expected) {
301
+ throw new Error(
302
+ `Artifact version mismatch: expected ${expected} but got ${aztecVersion}. ` +
303
+ `The legacy artifact resolver may not have swapped in the correct version.`,
304
+ );
305
+ }
306
+ }
307
+
308
+ /**
309
+ * Sets up the environment for the end-to-end tests.
310
+ * @param numberOfAccounts - The number of new accounts to be created once the PXE is initiated.
311
+ * @param opts - Options to pass to the node initialization and to the setup script.
312
+ * @param pxeOpts - Options to pass to the PXE initialization.
313
+ */
314
+ export async function setup(
315
+ numberOfAccounts = 1,
316
+ opts: SetupOptions = {},
317
+ pxeOpts: Partial<PXEConfig> = {},
318
+ chain: Chain = foundry,
319
+ ): Promise<EndToEndContext> {
320
+ assertContractArtifactsVersion();
321
+ let anvil: Anvil | undefined;
322
+ try {
323
+ opts.aztecTargetCommitteeSize ??= 0;
324
+ opts.slasherEnabled ??= false;
325
+
326
+ const config: AztecNodeConfig & SetupOptions = { ...getConfigEnvVars(), ...opts };
327
+ // use initialValidators for the node config
328
+ config.validatorPrivateKeys = new SecretValue(opts.initialValidators?.map(v => v.privateKey) ?? []);
329
+
330
+ config.peerCheckIntervalMS = TEST_PEER_CHECK_INTERVAL_MS;
331
+ config.maxPendingTxCount = opts.maxPendingTxCount ?? TEST_MAX_PENDING_TX_POOL_COUNT;
332
+ // For tests we only want proving enabled if specifically requested
333
+ config.realProofs = !!opts.realProofs;
334
+ // Only enforce the time table if requested
335
+ config.enforceTimeTable = !!opts.enforceTimeTable;
336
+ // Enable the tx delayer for tests (default config has it disabled, so we force-enable it here)
337
+ config.enableDelayer = true;
338
+ config.listenAddress = '127.0.0.1';
339
+
340
+ config.minTxPoolAgeMs = opts.minTxPoolAgeMs ?? 0;
341
+
342
+ const logger = getLogger();
343
+
344
+ // Create a temp directory for any services that need it and cleanup later
345
+ const directoryToCleanup = path.join(tmpdir(), randomBytes(8).toString('hex'));
346
+ await fs.mkdir(directoryToCleanup, { recursive: true });
347
+ if (!config.dataDirectory) {
348
+ config.dataDirectory = directoryToCleanup;
349
+ }
350
+
351
+ const dateProvider = new TestDateProvider();
352
+
353
+ if (!config.l1RpcUrls?.length) {
354
+ if (!isAnvilTestChain(chain.id)) {
355
+ throw new Error(`No ETHEREUM_HOSTS set but non anvil chain requested`);
356
+ }
357
+ const res = await startAnvil({
358
+ l1BlockTime: opts.ethereumSlotDuration,
359
+ accounts: opts.anvilAccounts,
360
+ port: opts.anvilPort ?? (process.env.ANVIL_PORT ? parseInt(process.env.ANVIL_PORT) : undefined),
361
+ slotsInAnEpoch: opts.anvilSlotsInAnEpoch,
362
+ dateProvider,
363
+ });
364
+ anvil = res.anvil;
365
+ config.l1RpcUrls = [res.rpcUrl];
366
+ }
367
+
368
+ // Enable logging metrics to a local file named after the test suite
369
+ if (isMetricsLoggingRequested()) {
370
+ const filename = path.join('log', getJobName() + '.jsonl');
371
+ logger.info(`Logging metrics to ${filename}`);
372
+ setupMetricsLogger(filename);
373
+ }
374
+ const ethCheatCodes = new EthCheatCodesWithState(config.l1RpcUrls, dateProvider);
375
+
376
+ if (opts.stateLoad) {
377
+ await ethCheatCodes.loadChainState(opts.stateLoad);
378
+ }
379
+
380
+ if (opts.l1StartTime) {
381
+ await ethCheatCodes.warp(opts.l1StartTime, { resetBlockInterval: true });
382
+ }
383
+
384
+ let publisherPrivKeyHex: `0x${string}` | undefined = undefined;
385
+ let publisherHdAccount: HDAccount | PrivateKeyAccount | undefined = undefined;
386
+
387
+ if (opts.l1PublisherKey && opts.l1PublisherKey.getValue() && opts.l1PublisherKey.getValue() != NULL_KEY) {
388
+ publisherPrivKeyHex = opts.l1PublisherKey.getValue();
389
+ publisherHdAccount = privateKeyToAccount(publisherPrivKeyHex);
390
+ } else if (
391
+ config.sequencerPublisherPrivateKeys &&
392
+ config.sequencerPublisherPrivateKeys.length > 0 &&
393
+ config.sequencerPublisherPrivateKeys[0].getValue() != NULL_KEY
394
+ ) {
395
+ publisherPrivKeyHex = config.sequencerPublisherPrivateKeys[0].getValue();
396
+ publisherHdAccount = privateKeyToAccount(publisherPrivKeyHex);
397
+ } else if (!MNEMONIC) {
398
+ throw new Error(`Mnemonic not provided and no publisher private key`);
399
+ } else {
400
+ publisherHdAccount = mnemonicToAccount(MNEMONIC, { addressIndex: 0 });
401
+ const publisherPrivKeyRaw = publisherHdAccount.getHdKey().privateKey;
402
+ const publisherPrivKey = publisherPrivKeyRaw === null ? null : Buffer.from(publisherPrivKeyRaw);
403
+ publisherPrivKeyHex = `0x${publisherPrivKey!.toString('hex')}` as const;
404
+ config.sequencerPublisherPrivateKeys = [new SecretValue(publisherPrivKeyHex)];
405
+ }
406
+
407
+ if (config.coinbase === undefined) {
408
+ config.coinbase = EthAddress.fromString(publisherHdAccount.address);
409
+ }
410
+
411
+ // Determine which addresses to fund in genesis
412
+ const initialFundedAccounts =
413
+ opts.initialFundedAccounts ??
414
+ (await generateSchnorrAccounts(opts.numberOfInitialFundedAccounts ?? Math.max(numberOfAccounts, 10)));
415
+ const addressesToFund = initialFundedAccounts.map(a => a.address);
416
+
417
+ // Optionally fund the sponsored FPC
418
+ if (opts.fundSponsoredFPC) {
419
+ const sponsoredFPCAddress = await getSponsoredFPCAddress();
420
+ addressesToFund.push(sponsoredFPCAddress);
421
+ }
422
+
423
+ const genesisTimestamp = BigInt(Math.floor(Date.now() / 1000));
424
+ const { genesisArchiveRoot, genesis, fundingNeeded } = await getGenesisValues(
425
+ addressesToFund,
426
+ opts.initialAccountFeeJuice,
427
+ opts.genesisPublicData,
428
+ genesisTimestamp,
429
+ );
430
+
431
+ const wasAutomining = await ethCheatCodes.isAutoMining();
432
+ const enableAutomine = opts.automineL1Setup && !wasAutomining && isAnvilTestChain(chain.id);
433
+ if (enableAutomine) {
434
+ await ethCheatCodes.setAutomine(true);
435
+ }
436
+
437
+ const l1Client = createExtendedL1Client(config.l1RpcUrls, publisherHdAccount!, chain);
438
+
439
+ // Deploy Multicall3 if running locally
440
+ await deployMulticall3(l1Client, logger);
441
+
442
+ // Force viem to refresh its nonce cache to avoid "nonce too low" errors in subsequent transactions
443
+ // This is necessary because deployMulticall3 sends multiple transactions and viem may cache a stale nonce
444
+ await l1Client.getTransactionCount({ address: l1Client.account.address });
445
+
446
+ const deployL1ContractsValues: DeployAztecL1ContractsReturnType = await deployAztecL1Contracts(
447
+ config.l1RpcUrls[0],
448
+ publisherPrivKeyHex!,
449
+ chain.id,
450
+ {
451
+ ...getL1ContractsConfigEnvVars(),
452
+ ...opts,
453
+ ...opts.l1ContractsArgs,
454
+ vkTreeRoot: getVKTreeRoot(),
455
+ protocolContractsHash,
456
+ genesisArchiveRoot,
457
+ initialValidators: opts.initialValidators,
458
+ feeJuicePortalInitialBalance: fundingNeeded,
459
+ realVerifier: false,
460
+ },
461
+ );
462
+
463
+ Object.assign(config, deployL1ContractsValues.l1ContractAddresses);
464
+ config.rollupVersion = deployL1ContractsValues.rollupVersion;
465
+
466
+ // Propagate L1-contracts-config overrides back to the node config so the archiver's
467
+ // `l1Constants` (and any other node-side consumer) agrees with what was actually deployed.
468
+ // Without this, a per-test override like `aztecEpochDuration: 4` lands on the rollup contract
469
+ // but the node config keeps the default (32), so `archiver.isEpochComplete(0)` computes
470
+ // `endSlot=31` and `EpochTestSettler`/`EpochMonitor` never fires — letting the
471
+ // `aztecProofSubmissionEpochs` window expire mid-test and prune the pending chain.
472
+ // Skip undefined values: callers (e.g. `P2PNetworkTest`) sometimes build `l1ContractsArgs`
473
+ // by spreading a partial `AztecNodeConfig`, which leaves unset fields (notably `dataDirectory`)
474
+ // as `undefined`. A blind Object.assign would then clobber the temp `dataDirectory` set earlier
475
+ // in this function and crash `setupSharedBlobStorage`.
476
+ if (opts.l1ContractsArgs) {
477
+ for (const [key, value] of Object.entries(opts.l1ContractsArgs)) {
478
+ if (value !== undefined) {
479
+ (config as unknown as Record<string, unknown>)[key] = value;
480
+ }
481
+ }
482
+ }
483
+
484
+ if (enableAutomine) {
485
+ await ethCheatCodes.setAutomine(false);
486
+ await ethCheatCodes.setIntervalMining(config.ethereumSlotDuration);
487
+ }
488
+
489
+ // In compose mode (no local anvil), sync dateProvider to L1 time since it may have drifted
490
+ // ahead of system time due to the local-network watcher warping time forward on each filled slot.
491
+ // When running with a local anvil, the dateProvider is kept in sync via the stdout listener.
492
+ if (!anvil) {
493
+ dateProvider.setTime((await ethCheatCodes.lastBlockTimestamp()) * 1000);
494
+ }
495
+
496
+ if (opts.l2StartTime) {
497
+ await ethCheatCodes.warp(opts.l2StartTime, { resetBlockInterval: true });
498
+ }
499
+
500
+ const watcher = new AnvilTestWatcher(
501
+ new EthCheatCodesWithState(config.l1RpcUrls, dateProvider),
502
+ deployL1ContractsValues.l1ContractAddresses.rollupAddress,
503
+ deployL1ContractsValues.l1Client,
504
+ dateProvider,
505
+ opts.anvilTestWatcherOpts,
506
+ );
507
+ if (!opts.disableAnvilTestWatcher) {
508
+ await watcher.start();
509
+ }
510
+
511
+ // Use metricsPort-based telemetry if provided, otherwise use the regular telemetry client
512
+ const telemetryClient = opts.metricsPort
513
+ ? await getEndToEndTestTelemetryClient(opts.metricsPort)
514
+ : await getTelemetryClient(opts.telemetryConfig);
515
+
516
+ await setupSharedBlobStorage(config);
517
+
518
+ logger.verbose('Creating and synching an aztec node', config);
519
+
520
+ const acvmConfig = await getACVMConfig(logger);
521
+ if (acvmConfig) {
522
+ config.acvmWorkingDirectory = acvmConfig.acvmWorkingDirectory;
523
+ config.acvmBinaryPath = acvmConfig.acvmBinaryPath;
524
+ }
525
+
526
+ const bbConfig = await getBBConfig(logger);
527
+ if (bbConfig) {
528
+ config.bbBinaryPath = bbConfig.bbBinaryPath;
529
+ config.bbWorkingDirectory = bbConfig.bbWorkingDirectory;
530
+ }
531
+
532
+ let mockGossipSubNetwork: MockGossipSubNetwork | undefined;
533
+ let p2pClientDeps: P2PClientDeps | undefined = undefined;
534
+
535
+ if (opts.mockGossipSubNetwork) {
536
+ mockGossipSubNetwork = new MockGossipSubNetwork(opts.mockGossipSubNetworkLatency);
537
+ p2pClientDeps = { p2pServiceFactory: getMockPubSubP2PServiceFactory(mockGossipSubNetwork) };
538
+ }
539
+
540
+ // Transactions built against the genesis state must be included in block 1, otherwise they are dropped.
541
+ // To avoid test failures from dropped transactions, we ensure progression beyond genesis before proceeding.
542
+ // For account deployments, we set minTxsPerBlock=1 and deploy accounts sequentially for guaranteed success.
543
+ // If no accounts need deployment, we await an empty block to confirm network progression.
544
+ const originalMinTxsPerBlock = config.minTxsPerBlock;
545
+ if (originalMinTxsPerBlock === undefined) {
546
+ throw new Error('minTxsPerBlock is undefined in e2e test setup');
547
+ }
548
+
549
+ // Whether we're deploying accounts (and therefore need reliable block inclusion past genesis)
550
+ const shouldDeployAccounts = numberOfAccounts > 0 && !opts.skipAccountDeployment;
551
+ // Only set minTxsPerBlock=0 if we need an empty block (no accounts at all, not skipped deployment)
552
+ const needsEmptyBlock = numberOfAccounts === 0 && !opts.skipAccountDeployment;
553
+ // Pipelining is always on: the proposer builds during slot N-1 for slot N. A tx submitted at
554
+ // slot N start arrives after that build, so forcing minTxsPerBlock=1 would stall the chain on
555
+ // alternating slots -- hence empty checkpoints are allowed (minTxsPerBlock=0) for account
556
+ // deployment. Automine is unaffected: its runBuild clamps mempool builds to
557
+ // Math.max(minTxsPerBlock ?? 1, 1) and still requires minValidTxs: 1.
558
+ const accountsDeployMinTxs = 0;
559
+ config.minTxsPerBlock = shouldDeployAccounts ? accountsDeployMinTxs : needsEmptyBlock ? 0 : originalMinTxsPerBlock;
560
+
561
+ config.p2pEnabled = opts.mockGossipSubNetwork || config.p2pEnabled;
562
+ config.p2pIp = opts.p2pIp ?? config.p2pIp ?? '127.0.0.1';
563
+
564
+ if (!config.disableValidator) {
565
+ if ((config.validatorPrivateKeys?.getValue().length ?? 0) === 0) {
566
+ config.validatorPrivateKeys = new SecretValue([generatePrivateKey()]);
567
+ }
568
+ }
569
+
570
+ // When skipInitialSequencer is set, the initial node is a lightweight RPC-only node.
571
+ // We apply these overrides to a copy so they don't leak into the returned config.
572
+ // Keep P2P enabled if mockGossipSubNetwork is used (needed for tx propagation to validators).
573
+ const initialNodeConfig = opts.skipInitialSequencer
574
+ ? {
575
+ ...config,
576
+ disableValidator: true,
577
+ ...(opts.mockGossipSubNetwork ? {} : { p2pEnabled: false, bootstrapNodes: [] as string[] }),
578
+ }
579
+ : config;
580
+
581
+ const aztecNodeService = await withLoggerBindings({ actor: 'node-0' }, () =>
582
+ AztecNodeService.createAndSync(
583
+ initialNodeConfig,
584
+ { dateProvider, telemetry: telemetryClient, p2pClientDeps },
585
+ { genesis, dontStartSequencer: opts.skipInitialSequencer },
586
+ ),
587
+ );
588
+ const sequencerClient = aztecNodeService.getSequencer();
589
+
590
+ let proverNode: AztecNodeService | undefined = undefined;
591
+ if (opts.startProverNode) {
592
+ logger.verbose('Creating and syncing a simulated prover node...');
593
+ const proverNodePrivateKey = getPrivateKeyFromIndex(2);
594
+ const proverNodePrivateKeyHex: Hex = `0x${proverNodePrivateKey!.toString('hex')}`;
595
+ const proverNodeDataDirectory = path.join(directoryToCleanup, randomBytes(8).toString('hex'));
596
+
597
+ const p2pClientDeps: Partial<P2PClientDeps> = {
598
+ p2pServiceFactory: mockGossipSubNetwork && getMockPubSubP2PServiceFactory(mockGossipSubNetwork!),
599
+ rpcTxProviders: [aztecNodeService],
600
+ };
601
+
602
+ ({ proverNode } = await createAndSyncProverNode(
603
+ proverNodePrivateKeyHex,
604
+ config,
605
+ {
606
+ ...config.proverNodeConfig,
607
+ dataDirectory: proverNodeDataDirectory,
608
+ },
609
+ { dateProvider, p2pClientDeps, telemetry: telemetryClient },
610
+ { genesis },
611
+ ));
612
+ }
613
+
614
+ const sequencerDelayer = sequencerClient?.getDelayer();
615
+ const proverDelayer = proverNode?.getProverNode()?.getDelayer();
616
+
617
+ logger.verbose('Creating a pxe...');
618
+ const pxeConfig = { ...getPXEConfig(), ...pxeOpts };
619
+ pxeConfig.dataDirectory = path.join(directoryToCleanup, randomBytes(8).toString('hex'));
620
+ // For tests we only want proving enabled if specifically requested
621
+ pxeConfig.proverEnabled = !!pxeOpts.proverEnabled;
622
+ const wallet = await TestWallet.create(aztecNodeService, pxeConfig, {
623
+ loggerActorLabel: 'pxe-0',
624
+ ...opts.pxeCreationOptions,
625
+ });
626
+
627
+ if (opts.walletMinFeePadding !== undefined) {
628
+ wallet.setMinFeePadding(opts.walletMinFeePadding);
629
+ }
630
+
631
+ const cheatCodes = await CheatCodes.create(
632
+ config.l1RpcUrls,
633
+ aztecNodeService,
634
+ dateProvider,
635
+ aztecNodeService.getAutomineSequencer(),
636
+ );
637
+
638
+ if (
639
+ (opts.aztecTargetCommitteeSize && opts.aztecTargetCommitteeSize > 0) ||
640
+ (opts.initialValidators && opts.initialValidators.length > 0)
641
+ ) {
642
+ // We need to advance such that the committee is set up.
643
+ await cheatCodes.rollup.advanceToEpoch(
644
+ EpochNumber.fromBigInt(
645
+ BigInt(await cheatCodes.rollup.getEpoch()) + BigInt(config.lagInEpochsForValidatorSet + 1),
646
+ ),
647
+ );
648
+ await cheatCodes.rollup.setupEpoch();
649
+ await cheatCodes.rollup.debugRollup();
650
+ }
651
+
652
+ let accounts: AztecAddress[] = [];
653
+
654
+ if (opts.skipInitialSequencer) {
655
+ logger.info('Sequencer not started on initial node, skipping block progression');
656
+ } else if (shouldDeployAccounts) {
657
+ logger.info(
658
+ `${numberOfAccounts} accounts are being deployed. Reliably progressing past genesis by waiting for the accounts to be deployed`,
659
+ );
660
+ const accountsData = initialFundedAccounts.slice(0, numberOfAccounts);
661
+ const accountManagers = await deployFundedSchnorrAccounts(wallet, accountsData);
662
+ accounts = accountManagers.map(accountManager => accountManager.address);
663
+ } else if (needsEmptyBlock) {
664
+ logger.info('No accounts are being deployed, waiting for an empty block 1 to be mined');
665
+ // AutomineSequencer only builds on tx arrival; explicitly request an empty block.
666
+ const automine = aztecNodeService.getAutomineSequencer();
667
+ if (automine) {
668
+ await automine.buildEmptyBlock();
669
+ }
670
+ while ((await aztecNodeService.getBlockNumber()) === 0) {
671
+ await sleep(2000);
672
+ }
673
+ }
674
+ // If skipAccountDeployment is true, we don't deploy or wait - tests will handle account deployment later
675
+
676
+ // Now we restore the original minTxsPerBlock setting if we changed it.
677
+ if (sequencerClient && config.minTxsPerBlock !== originalMinTxsPerBlock) {
678
+ sequencerClient.getSequencer().updateConfig({ minTxsPerBlock: originalMinTxsPerBlock });
679
+ }
680
+
681
+ if (initialFundedAccounts.length < numberOfAccounts) {
682
+ throw new Error(
683
+ `Unable to deploy ${numberOfAccounts} accounts. Only ${initialFundedAccounts.length} accounts were funded.`,
684
+ );
685
+ }
686
+
687
+ const teardown = async () => {
688
+ try {
689
+ await tryStop(wallet, logger);
690
+ await tryStop(aztecNodeService, logger);
691
+ await tryStop(proverNode, logger);
692
+
693
+ if (acvmConfig?.cleanup) {
694
+ await acvmConfig.cleanup();
695
+ }
696
+
697
+ if (bbConfig?.cleanup) {
698
+ await bbConfig.cleanup();
699
+ }
700
+
701
+ await tryStop(watcher, logger);
702
+ await tryStop(anvil, logger);
703
+
704
+ await tryRmDir(directoryToCleanup, logger);
705
+ } catch (err) {
706
+ logger.error(`Error during e2e test teardown`, err);
707
+ } finally {
708
+ try {
709
+ await telemetryClient.stop();
710
+ } catch (err) {
711
+ logger.error(`Error during telemetry client stop`, err);
712
+ }
713
+ }
714
+ };
715
+
716
+ return {
717
+ anvil,
718
+ aztecNode: aztecNodeService,
719
+ aztecNodeService,
720
+ aztecNodeAdmin: aztecNodeService,
721
+ cheatCodes,
722
+ ethCheatCodes,
723
+ config,
724
+ aztecNodeConfig: config,
725
+ dateProvider,
726
+ deployL1ContractsValues,
727
+ initialFundedAccounts,
728
+ logger,
729
+ mockGossipSubNetwork,
730
+ genesis,
731
+ proverNode,
732
+ sequencerDelayer,
733
+ proverDelayer,
734
+ sequencer: sequencerClient,
735
+ teardown,
736
+ telemetryClient,
737
+ wallet,
738
+ accounts,
739
+ watcher,
740
+ acvmConfig,
741
+ bbConfig,
742
+ directoryToCleanup,
743
+ };
744
+ } catch (err) {
745
+ await anvil?.stop();
746
+ throw err;
747
+ }
748
+ }
749
+
750
+ /** Returns the job name for the current test. */
751
+ function getJobName() {
752
+ return process.env.JOB_NAME ?? expect.getState().currentTestName?.split(' ')[0].replaceAll('/', '_') ?? 'unknown';
753
+ }
754
+
755
+ /**
756
+ * Returns a logger instance for the current test.
757
+ */
758
+ export function getLogger() {
759
+ const describeBlockName = expect.getState().currentTestName?.split(' ')[0].replaceAll('/', ':');
760
+ if (!describeBlockName) {
761
+ const name = expect.getState().testPath?.split('/').pop()?.split('.')[0] ?? 'unknown';
762
+ return createLogger('e2e:' + name);
763
+ }
764
+ return createLogger('e2e:' + describeBlockName);
765
+ }
766
+
767
+ /**
768
+ * Computes the address of the "canonical" SponsoredFPCContract.
769
+ */
770
+ export function getSponsoredFPCInstance(): Promise<ContractInstanceWithAddress> {
771
+ return Promise.resolve(
772
+ getContractInstanceFromInstantiationParams(SponsoredFPCContract.artifact, {
773
+ salt: new Fr(SPONSORED_FPC_SALT),
774
+ }),
775
+ );
776
+ }
777
+
778
+ /**
779
+ * Computes the address of the "canonical" SponsoredFPCContract.
780
+ */
781
+ export async function getSponsoredFPCAddress() {
782
+ const sponsoredFPCInstance = await getSponsoredFPCInstance();
783
+ return sponsoredFPCInstance.address;
784
+ }
785
+
786
+ /**
787
+ * Deploy a sponsored FPC contract to a running instance.
788
+ */
789
+ export async function setupSponsoredFPC(wallet: Wallet) {
790
+ const instance = await getContractInstanceFromInstantiationParams(SponsoredFPCContract.artifact, {
791
+ salt: new Fr(SPONSORED_FPC_SALT),
792
+ });
793
+
794
+ await wallet.registerContract(instance, SponsoredFPCContract.artifact);
795
+ getLogger().info(`SponsoredFPC: ${instance.address}`);
796
+ return instance;
797
+ }
798
+
799
+ /**
800
+ * Registers the SponsoredFPC in this PXE instance.
801
+ */
802
+ export async function registerSponsoredFPC(wallet: Wallet): Promise<void> {
803
+ await wallet.registerContract(await getSponsoredFPCInstance(), SponsoredFPCContract.artifact);
804
+ }
805
+
806
+ export async function waitForProvenChain(node: AztecNode, targetBlock?: BlockNumber, timeoutSec = 60, intervalSec = 1) {
807
+ targetBlock ??= await node.getBlockNumber();
808
+
809
+ await retryUntil(
810
+ async () => (await node.getBlockNumber('proven')) >= targetBlock,
811
+ 'proven chain status',
812
+ timeoutSec,
813
+ intervalSec,
814
+ );
815
+ }
816
+
817
+ /**
818
+ * Creates an AztecNodeService with the prover node enabled as a subsystem.
819
+ * Returns both the aztec node service (for lifecycle management) and the prover node (for test internals access).
820
+ */
821
+ export function createAndSyncProverNode(
822
+ proverNodePrivateKey: `0x${string}`,
823
+ baseConfig: AztecNodeConfig,
824
+ configOverrides: Pick<AztecNodeConfig, 'dataDirectory'>,
825
+ deps: {
826
+ telemetry?: TelemetryClient;
827
+ dateProvider: DateProvider;
828
+ p2pClientDeps?: P2PClientDeps;
829
+ },
830
+ options: { genesis?: GenesisData; dontStart?: boolean },
831
+ ): Promise<{ proverNode: AztecNodeService }> {
832
+ return withLoggerBindings({ actor: 'prover-0' }, async () => {
833
+ const proverNode = await AztecNodeService.createAndSync(
834
+ {
835
+ ...baseConfig,
836
+ ...configOverrides,
837
+ p2pPort: 0,
838
+ enableProverNode: true,
839
+ disableValidator: true,
840
+ proverPublisherPrivateKeys: [new SecretValue(proverNodePrivateKey)],
841
+ },
842
+ deps,
843
+ { genesis: options.genesis, dontStartProverNode: options.dontStart },
844
+ );
845
+
846
+ if (!proverNode.getProverNode()) {
847
+ throw new Error('Prover node subsystem was not created despite enableProverNode being set');
848
+ }
849
+
850
+ getLogger().info(`Created and synced prover node`);
851
+ return { proverNode };
852
+ });
853
+ }
854
+
855
+ export type BalancesFn = ReturnType<typeof getBalancesFn>;
856
+ export function getBalancesFn(
857
+ symbol: string,
858
+ method: ContractMethod,
859
+ logger: any,
860
+ ): (...addresses: (AztecAddress | { address: AztecAddress })[]) => Promise<bigint[]> {
861
+ const balances = async (...addressLikes: (AztecAddress | { address: AztecAddress })[]) => {
862
+ const addresses = addressLikes.map(addressLike => ('address' in addressLike ? addressLike.address : addressLike));
863
+ const b = await Promise.all(
864
+ addresses.map(async address => (await method(address).simulate({ from: address })).result),
865
+ );
866
+ const debugString = `${symbol} balances: ${addresses.map((address, i) => `${address}: ${b[i]}`).join(', ')}`;
867
+ logger.verbose(debugString);
868
+ return b;
869
+ };
870
+
871
+ return balances;
872
+ }
873
+
874
+ export async function expectMapping<K, V>(
875
+ fn: (...k: K[]) => Promise<V[]>,
876
+ inputs: K[],
877
+ expectedOutputs: V[],
878
+ ): Promise<void> {
879
+ expect(inputs.length).toBe(expectedOutputs.length);
880
+
881
+ const outputs = await fn(...inputs);
882
+
883
+ expect(outputs).toEqual(expectedOutputs);
884
+ }
885
+
886
+ export async function expectMappingDelta<K, V extends number | bigint>(
887
+ initialValues: V[],
888
+ fn: (...k: K[]) => Promise<V[]>,
889
+ inputs: K[],
890
+ expectedDiffs: V[],
891
+ ): Promise<void> {
892
+ expect(inputs.length).toBe(expectedDiffs.length);
893
+
894
+ const outputs = await fn(...inputs);
895
+ const diffs = outputs.map((output, i) => output - initialValues[i]);
896
+
897
+ expect(diffs).toEqual(expectedDiffs);
898
+ }
899
+
900
+ /**
901
+ * Registers the auth_registry contract class and publishes its standard instance if not already
902
+ * present, and registers the artifact with PXE. Publishing is required before exercising the public
903
+ * authwit path (which relies on the AVM's deployment-nullifier check); the PXE-side registration is
904
+ * required so revert messages from AuthRegistry calls can be enriched (otherwise assertion strings
905
+ * surface as generic "Assertion failed:" and tests that match on the real message fail).
906
+ */
907
+ export async function ensureAuthRegistryPublished(wallet: Wallet, from: AztecAddress) {
908
+ const { instance, contractClass } = await getStandardAuthRegistry();
909
+ if (!(await wallet.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered) {
910
+ await (await publishContractClass(wallet, AuthRegistryArtifact)).send({ from });
911
+ }
912
+ if (!(await wallet.getContractMetadata(instance.address)).isContractPublished) {
913
+ await publishInstance(wallet, instance).send({ from });
914
+ }
915
+ await wallet.registerContract(instance, AuthRegistryArtifact);
916
+ }
917
+
918
+ /**
919
+ * Registers the public_checks contract class and publishes its standard instance if not already
920
+ * present, and registers the artifact with PXE. Required for any contract that calls
921
+ * `privately_check_timestamp` / `privately_check_block_number` (which dispatch into the
922
+ * deployed PublicChecks contract via an enqueued public call).
923
+ */
924
+ export async function ensurePublicChecksPublished(wallet: Wallet, from: AztecAddress) {
925
+ const { instance, contractClass } = await getStandardPublicChecks();
926
+ if (!(await wallet.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered) {
927
+ await (await publishContractClass(wallet, PublicChecksArtifact)).send({ from });
928
+ }
929
+ if (!(await wallet.getContractMetadata(instance.address)).isContractPublished) {
930
+ await publishInstance(wallet, instance).send({ from });
931
+ }
932
+ await wallet.registerContract(instance, PublicChecksArtifact);
933
+ }
934
+
935
+ /**
936
+ * Registers the handshake_registry contract class and publishes its standard instance if not
937
+ * already present, and registers the artifact with PXE. Required for constrained-delivery flows
938
+ * that call into the HandshakeRegistry at its well-known address.
939
+ */
940
+ export async function ensureHandshakeRegistryPublished(wallet: Wallet, from: AztecAddress) {
941
+ const { instance, contractClass } = await getStandardHandshakeRegistry();
942
+ if (!(await wallet.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered) {
943
+ await (await publishContractClass(wallet, HandshakeRegistryArtifact)).send({ from });
944
+ }
945
+ if (!(await wallet.getContractMetadata(instance.address)).isContractPublished) {
946
+ await publishInstance(wallet, instance).send({ from });
947
+ }
948
+ await wallet.registerContract(instance, HandshakeRegistryArtifact);
949
+ }
950
+
951
+ /**
952
+ * Registers the contract class used for test accounts and publicly deploys the instances requested.
953
+ * Use this when you need to make a public call to an account contract, such as for requesting a public authwit.
954
+ */
955
+ export async function ensureAccountContractsPublished(wallet: Wallet, accountsToDeploy: AztecAddress[]) {
956
+ const accountsAndAddresses = await Promise.all(
957
+ accountsToDeploy.map(async address => {
958
+ return {
959
+ address,
960
+ deployed: (await wallet.getContractMetadata(address)).isContractPublished,
961
+ };
962
+ }),
963
+ );
964
+ const instances = (
965
+ await Promise.all(
966
+ accountsAndAddresses
967
+ .filter(({ deployed }) => !deployed)
968
+ .map(({ address }) => wallet.getContractMetadata(address)),
969
+ )
970
+ ).map(contractMetadata => contractMetadata.instance);
971
+ const contractClass = await getContractClassFromArtifact(SchnorrAccountContractArtifact);
972
+ if (!(await wallet.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered) {
973
+ await (await publishContractClass(wallet, SchnorrAccountContractArtifact)).send({ from: accountsToDeploy[0] });
974
+ }
975
+ const requests = instances.map(instance => publishInstance(wallet, instance!));
976
+ const batch = new BatchCall(wallet, requests);
977
+ await batch.send({ from: accountsToDeploy[0] });
978
+ }
979
+
980
+ /**
981
+ * Helper function to deploy accounts.
982
+ * Returns deployed account data that can be used by tests.
983
+ */
984
+ export const deployAccounts =
985
+ (numberOfAccounts: number, logger: Logger, deployOptions?: Partial<DeployOptions<InteractionWaitOptions>>) =>
986
+ async ({ wallet, initialFundedAccounts }: { wallet: TestWallet; initialFundedAccounts: InitialAccountData[] }) => {
987
+ if (initialFundedAccounts.length < numberOfAccounts) {
988
+ throw new Error(`Cannot deploy more than ${initialFundedAccounts.length} initial accounts.`);
989
+ }
990
+
991
+ logger.verbose('Deploying accounts funded with fee juice...');
992
+ const deployedAccounts = initialFundedAccounts.slice(0, numberOfAccounts);
993
+ // Serial due to https://github.com/AztecProtocol/aztec-packages/issues/12045
994
+ for (let i = 0; i < deployedAccounts.length; i++) {
995
+ const accountManager = await wallet.createSchnorrAccount(
996
+ deployedAccounts[i].secret,
997
+ deployedAccounts[i].salt,
998
+ deployedAccounts[i].signingKey,
999
+ );
1000
+ const deployMethod = await accountManager.getDeployMethod();
1001
+ await deployMethod.send({
1002
+ from: NO_FROM,
1003
+ skipClassPublication: i !== 0, // Publish the contract class at most once.
1004
+ ...deployOptions,
1005
+ });
1006
+ }
1007
+
1008
+ return { deployedAccounts };
1009
+ };
1010
+
1011
+ /**
1012
+ * Registers the contract class used for test accounts and publicly deploys the instances requested.
1013
+ * Use this when you need to make a public call to an account contract, such as for requesting a public authwit.
1014
+ */
1015
+ export async function publicDeployAccounts(
1016
+ wallet: Wallet,
1017
+ accountsToDeploy: AztecAddress[],
1018
+ waitUntilProven = false,
1019
+ node?: AztecNode,
1020
+ ) {
1021
+ const instances = (await Promise.all(accountsToDeploy.map(account => wallet.getContractMetadata(account)))).map(
1022
+ metadata => metadata.instance,
1023
+ );
1024
+
1025
+ const contractClass = await getContractClassFromArtifact(SchnorrAccountContractArtifact);
1026
+ const alreadyRegistered = (await wallet.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered;
1027
+
1028
+ const calls: ContractFunctionInteraction[] = await Promise.all([
1029
+ ...(!alreadyRegistered ? [publishContractClass(wallet, SchnorrAccountContractArtifact)] : []),
1030
+ ...instances.map(instance => publishInstance(wallet, instance!)),
1031
+ ]);
1032
+
1033
+ const batch = new BatchCall(wallet, calls);
1034
+
1035
+ const { receipt: txReceipt } = await batch.send({ from: accountsToDeploy[0] });
1036
+ if (waitUntilProven) {
1037
+ if (!node) {
1038
+ throw new Error('Need to provide an AztecNode to wait for proven.');
1039
+ } else {
1040
+ await waitForProven(node, txReceipt);
1041
+ }
1042
+ }
1043
+ }
1044
+
1045
+ /**
1046
+ * Destroys the current context.
1047
+ */
1048
+ export async function teardown(context: EndToEndContext | undefined) {
1049
+ if (!context) {
1050
+ return;
1051
+ }
1052
+ await context.teardown();
1053
+ }
1054
+
1055
+ // Re-export for backward compatibility
1056
+ export { deployAndInitializeTokenAndBridgeContracts } from '../shared/cross_chain_test_harness.js';