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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/README.md +229 -14
  2. package/dest/automine/automine_test_context.d.ts +85 -0
  3. package/dest/automine/automine_test_context.d.ts.map +1 -0
  4. package/dest/automine/automine_test_context.js +98 -0
  5. package/dest/automine/contracts/fixtures/storage_proof_fetcher.d.ts +2 -0
  6. package/dest/automine/contracts/fixtures/storage_proof_fetcher.d.ts.map +1 -0
  7. package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.d.ts +1 -1
  8. package/dest/automine/contracts/fixtures/storage_proof_fixture.d.ts.map +1 -0
  9. package/dest/automine/delivery/interactive_handshake_responder.d.ts +48 -0
  10. package/dest/automine/delivery/interactive_handshake_responder.d.ts.map +1 -0
  11. package/dest/automine/delivery/interactive_handshake_responder.js +76 -0
  12. package/dest/automine/delivery/onchain_delivery_harness.d.ts +19 -0
  13. package/dest/automine/delivery/onchain_delivery_harness.d.ts.map +1 -0
  14. package/dest/automine/delivery/onchain_delivery_harness.js +141 -0
  15. package/dest/automine/token/blacklist_token_contract_test.d.ts +49 -0
  16. package/dest/automine/token/blacklist_token_contract_test.d.ts.map +1 -0
  17. package/dest/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.js +23 -36
  18. package/dest/automine/token/token_contract_test.d.ts +40 -0
  19. package/dest/automine/token/token_contract_test.d.ts.map +1 -0
  20. package/dest/{e2e_token_contract → automine/token}/token_contract_test.js +24 -39
  21. package/dest/automine/token/token_test_helpers.d.ts +73 -0
  22. package/dest/automine/token/token_test_helpers.d.ts.map +1 -0
  23. package/dest/automine/token/token_test_helpers.js +97 -0
  24. package/dest/bench/client_flows/benchmark.d.ts +15 -1
  25. package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
  26. package/dest/bench/client_flows/benchmark.js +19 -0
  27. package/dest/bench/client_flows/client_flows_benchmark.d.ts +5 -5
  28. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  29. package/dest/bench/client_flows/client_flows_benchmark.js +45 -29
  30. package/dest/bench/utils.d.ts +3 -3
  31. package/dest/bench/utils.d.ts.map +1 -1
  32. package/dest/bench/utils.js +97 -6
  33. package/dest/composed/ha/ha_full_setup.d.ts +77 -0
  34. package/dest/composed/ha/ha_full_setup.d.ts.map +1 -0
  35. package/dest/composed/ha/ha_full_setup.js +383 -0
  36. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts +12 -0
  37. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts.map +1 -0
  38. package/dest/fixtures/authwit_proxy.d.ts +1 -1
  39. package/dest/fixtures/authwit_proxy.d.ts.map +1 -1
  40. package/dest/fixtures/authwit_proxy.js +4 -0
  41. package/dest/fixtures/e2e_prover_test.d.ts +12 -9
  42. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  43. package/dest/fixtures/e2e_prover_test.js +51 -30
  44. package/dest/fixtures/fixtures.d.ts +79 -1
  45. package/dest/fixtures/fixtures.d.ts.map +1 -1
  46. package/dest/fixtures/fixtures.js +80 -0
  47. package/dest/fixtures/ha_setup.d.ts +4 -4
  48. package/dest/fixtures/ha_setup.d.ts.map +1 -1
  49. package/dest/fixtures/ha_setup.js +5 -2
  50. package/dest/fixtures/index.d.ts +2 -1
  51. package/dest/fixtures/index.d.ts.map +1 -1
  52. package/dest/fixtures/index.js +1 -0
  53. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts +25 -0
  54. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts.map +1 -0
  55. package/dest/fixtures/schnorr_hardcoded_account_contract.js +37 -0
  56. package/dest/fixtures/setup.d.ts +81 -42
  57. package/dest/fixtures/setup.d.ts.map +1 -1
  58. package/dest/fixtures/setup.js +289 -198
  59. package/dest/fixtures/setup_p2p_test.d.ts +10 -6
  60. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  61. package/dest/fixtures/setup_p2p_test.js +11 -11
  62. package/dest/fixtures/standard_contracts_genesis.d.ts +16 -0
  63. package/dest/fixtures/standard_contracts_genesis.d.ts.map +1 -0
  64. package/dest/fixtures/standard_contracts_genesis.js +25 -0
  65. package/dest/fixtures/timing.d.ts +42 -0
  66. package/dest/fixtures/timing.d.ts.map +1 -0
  67. package/dest/fixtures/timing.js +72 -0
  68. package/dest/fixtures/token_utils.d.ts +22 -4
  69. package/dest/fixtures/token_utils.d.ts.map +1 -1
  70. package/dest/fixtures/token_utils.js +21 -1
  71. package/dest/fixtures/utils.d.ts +2 -2
  72. package/dest/fixtures/utils.d.ts.map +1 -1
  73. package/dest/fixtures/utils.js +1 -1
  74. package/dest/fixtures/wait_helpers.d.ts +135 -0
  75. package/dest/fixtures/wait_helpers.d.ts.map +1 -0
  76. package/dest/fixtures/wait_helpers.js +154 -0
  77. package/dest/forward-compatibility/wallet_rpc_client.d.ts +7 -0
  78. package/dest/forward-compatibility/wallet_rpc_client.d.ts.map +1 -0
  79. package/dest/forward-compatibility/wallet_rpc_client.js +15 -0
  80. package/dest/forward-compatibility/wallet_service.d.ts +3 -0
  81. package/dest/forward-compatibility/wallet_service.d.ts.map +1 -0
  82. package/dest/forward-compatibility/wallet_service.js +109 -0
  83. package/dest/install_legacy_contracts.d.cts +13 -0
  84. package/dest/install_legacy_contracts.d.cts.map +1 -0
  85. package/dest/legacy-jest-resolver.d.cts +3 -0
  86. package/dest/legacy-jest-resolver.d.cts.map +1 -0
  87. package/dest/multi-node/block-production/setup.d.ts +97 -0
  88. package/dest/multi-node/block-production/setup.d.ts.map +1 -0
  89. package/dest/multi-node/block-production/setup.js +158 -0
  90. package/dest/multi-node/governance/setup.d.ts +67 -0
  91. package/dest/multi-node/governance/setup.d.ts.map +1 -0
  92. package/dest/multi-node/governance/setup.js +126 -0
  93. package/dest/multi-node/multi_node_test_context.d.ts +212 -0
  94. package/dest/multi-node/multi_node_test_context.d.ts.map +1 -0
  95. package/dest/multi-node/multi_node_test_context.js +347 -0
  96. package/dest/multi-node/slashing/inactivity_setup.d.ts +27 -0
  97. package/dest/multi-node/slashing/inactivity_setup.d.ts.map +1 -0
  98. package/dest/multi-node/slashing/inactivity_setup.js +111 -0
  99. package/dest/multi-node/slashing/setup.d.ts +167 -0
  100. package/dest/multi-node/slashing/setup.d.ts.map +1 -0
  101. package/dest/multi-node/slashing/setup.js +275 -0
  102. package/dest/{e2e_p2p → p2p}/p2p_network.d.ts +19 -10
  103. package/dest/p2p/p2p_network.d.ts.map +1 -0
  104. package/dest/{e2e_p2p → p2p}/p2p_network.js +82 -38
  105. package/dest/p2p/reqresp/utils.d.ts +19 -0
  106. package/dest/p2p/reqresp/utils.d.ts.map +1 -0
  107. package/dest/{e2e_p2p → p2p}/reqresp/utils.js +32 -29
  108. package/dest/p2p/shared.d.ts +72 -0
  109. package/dest/p2p/shared.d.ts.map +1 -0
  110. package/dest/p2p/shared.js +212 -0
  111. package/dest/shared/cross_chain_test_harness.d.ts +6 -4
  112. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  113. package/dest/shared/cross_chain_test_harness.js +33 -21
  114. package/dest/shared/gas_portal_test_harness.d.ts +8 -5
  115. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  116. package/dest/shared/gas_portal_test_harness.js +24 -12
  117. package/dest/shared/submit-transactions.d.ts +1 -1
  118. package/dest/shared/submit-transactions.d.ts.map +1 -1
  119. package/dest/shared/submit-transactions.js +12 -5
  120. package/dest/shared/timing_env.d.js +5 -0
  121. package/dest/shared/timing_env.js +365 -0
  122. package/dest/shared/uniswap_l1_l2.d.ts +1 -1
  123. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  124. package/dest/shared/uniswap_l1_l2.js +50 -37
  125. package/dest/shared/wait_for_l1_to_l2_message.d.ts +13 -0
  126. package/dest/shared/wait_for_l1_to_l2_message.d.ts.map +1 -0
  127. package/dest/shared/wait_for_l1_to_l2_message.js +10 -0
  128. package/dest/simulators/lending_simulator.d.ts +10 -3
  129. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  130. package/dest/simulators/lending_simulator.js +24 -12
  131. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts +75 -0
  132. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts.map +1 -0
  133. package/dest/single-node/cross-chain/cross_chain_messaging_test.js +209 -0
  134. package/dest/single-node/cross-chain/message_test_helpers.d.ts +38 -0
  135. package/dest/single-node/cross-chain/message_test_helpers.d.ts.map +1 -0
  136. package/dest/single-node/cross-chain/message_test_helpers.js +70 -0
  137. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.d.ts +1 -1
  138. package/dest/single-node/fees/bridging_race.notest.d.ts.map +1 -0
  139. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.js +17 -4
  140. package/dest/single-node/fees/fees_test.d.ts +95 -0
  141. package/dest/single-node/fees/fees_test.d.ts.map +1 -0
  142. package/dest/single-node/fees/fees_test.js +347 -0
  143. package/dest/single-node/l1-reorgs/setup.d.ts +42 -0
  144. package/dest/single-node/l1-reorgs/setup.d.ts.map +1 -0
  145. package/dest/single-node/l1-reorgs/setup.js +57 -0
  146. package/dest/single-node/partial-proofs/setup.d.ts +5 -0
  147. package/dest/single-node/partial-proofs/setup.d.ts.map +1 -0
  148. package/dest/single-node/partial-proofs/setup.js +5 -0
  149. package/dest/single-node/proving/setup.d.ts +5 -0
  150. package/dest/single-node/proving/setup.d.ts.map +1 -0
  151. package/dest/single-node/proving/setup.js +5 -0
  152. package/dest/single-node/recovery/setup.d.ts +5 -0
  153. package/dest/single-node/recovery/setup.d.ts.map +1 -0
  154. package/dest/single-node/recovery/setup.js +5 -0
  155. package/dest/single-node/setup.d.ts +49 -0
  156. package/dest/single-node/setup.d.ts.map +1 -0
  157. package/dest/single-node/setup.js +56 -0
  158. package/dest/single-node/single_node_test_context.d.ts +374 -0
  159. package/dest/single-node/single_node_test_context.d.ts.map +1 -0
  160. package/dest/single-node/single_node_test_context.js +847 -0
  161. package/dest/spartan/setup_test_wallets.d.ts +1 -1
  162. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  163. package/dest/spartan/setup_test_wallets.js +31 -46
  164. package/dest/spartan/tx_metrics.d.ts +27 -4
  165. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  166. package/dest/spartan/tx_metrics.js +105 -20
  167. package/dest/spartan/utils/config.d.ts +9 -35
  168. package/dest/spartan/utils/config.d.ts.map +1 -1
  169. package/dest/spartan/utils/gossip_metrics.d.ts +9 -0
  170. package/dest/spartan/utils/gossip_metrics.d.ts.map +1 -0
  171. package/dest/spartan/utils/gossip_metrics.js +77 -0
  172. package/dest/spartan/utils/index.d.ts +2 -1
  173. package/dest/spartan/utils/index.d.ts.map +1 -1
  174. package/dest/spartan/utils/index.js +2 -0
  175. package/dest/spartan/utils/nodes.js +2 -2
  176. package/dest/test-wallet/test_wallet.d.ts +39 -10
  177. package/dest/test-wallet/test_wallet.d.ts.map +1 -1
  178. package/dest/test-wallet/test_wallet.js +166 -59
  179. package/dest/test-wallet/utils.d.ts +38 -3
  180. package/dest/test-wallet/utils.d.ts.map +1 -1
  181. package/dest/test-wallet/utils.js +65 -10
  182. package/dest/test-wallet/wallet_worker_script.js +12 -4
  183. package/dest/test-wallet/worker_wallet.d.ts +9 -8
  184. package/dest/test-wallet/worker_wallet.d.ts.map +1 -1
  185. package/dest/test-wallet/worker_wallet.js +10 -4
  186. package/dest/test-wallet/worker_wallet_schema.d.ts +3 -273
  187. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -1
  188. package/dest/test-wallet/worker_wallet_schema.js +15 -2
  189. package/package.json +48 -43
  190. package/src/automine/README.md +60 -0
  191. package/src/automine/automine_test_context.ts +153 -0
  192. package/src/automine/delivery/interactive_handshake_responder.ts +125 -0
  193. package/src/automine/delivery/onchain_delivery_harness.ts +213 -0
  194. package/src/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.ts +24 -47
  195. package/src/{e2e_token_contract → automine/token}/token_contract_test.ts +25 -48
  196. package/src/automine/token/token_test_helpers.ts +138 -0
  197. package/src/bench/client_flows/benchmark.ts +21 -0
  198. package/src/bench/client_flows/client_flows_benchmark.ts +77 -56
  199. package/src/bench/utils.ts +110 -6
  200. package/src/composed/ha/ha_full_setup.ts +466 -0
  201. package/src/fixtures/authwit_proxy.ts +4 -0
  202. package/src/fixtures/e2e_prover_test.ts +66 -48
  203. package/src/fixtures/fixtures.ts +100 -0
  204. package/src/fixtures/ha_setup.ts +11 -5
  205. package/src/fixtures/index.ts +1 -0
  206. package/src/fixtures/schnorr_hardcoded_account_contract.ts +49 -0
  207. package/src/fixtures/setup.ts +361 -256
  208. package/src/fixtures/setup_p2p_test.ts +15 -11
  209. package/src/fixtures/standard_contracts_genesis.ts +28 -0
  210. package/src/fixtures/timing.ts +97 -0
  211. package/src/fixtures/token_utils.ts +39 -4
  212. package/src/fixtures/utils.ts +2 -3
  213. package/src/fixtures/wait_helpers.ts +333 -0
  214. package/src/forward-compatibility/wallet_rpc_client.ts +14 -0
  215. package/src/forward-compatibility/wallet_service.ts +106 -0
  216. package/src/guides/up_quick_start.sh +5 -2
  217. package/src/infra/README.md +12 -0
  218. package/src/install_legacy_contracts.cjs +81 -0
  219. package/src/legacy-jest-resolver.cjs +98 -0
  220. package/src/multi-node/README.md +96 -0
  221. package/src/multi-node/block-production/setup.ts +272 -0
  222. package/src/multi-node/governance/setup.ts +172 -0
  223. package/src/multi-node/multi_node_test_context.ts +447 -0
  224. package/src/multi-node/slashing/inactivity_setup.ts +139 -0
  225. package/src/multi-node/slashing/setup.ts +433 -0
  226. package/src/p2p/README.md +78 -0
  227. package/src/{e2e_p2p → p2p}/p2p_network.ts +95 -50
  228. package/src/{e2e_p2p → p2p}/reqresp/utils.ts +35 -28
  229. package/src/p2p/shared.ts +329 -0
  230. package/src/shared/cross_chain_test_harness.ts +36 -17
  231. package/src/shared/gas_portal_test_harness.ts +32 -14
  232. package/src/shared/submit-transactions.ts +13 -5
  233. package/src/shared/timing_env.d.mts +39 -0
  234. package/src/shared/timing_env.mjs +363 -0
  235. package/src/shared/uniswap_l1_l2.ts +80 -43
  236. package/src/shared/wait_for_l1_to_l2_message.ts +23 -0
  237. package/src/simulators/lending_simulator.ts +28 -14
  238. package/src/single-node/README.md +66 -0
  239. package/src/single-node/cross-chain/cross_chain_messaging_test.ts +302 -0
  240. package/src/single-node/cross-chain/message_test_helpers.ts +125 -0
  241. package/src/{e2e_fees → single-node/fees}/bridging_race.notest.ts +19 -5
  242. package/src/{e2e_fees → single-node/fees}/fees_test.ts +176 -70
  243. package/src/single-node/l1-reorgs/setup.ts +93 -0
  244. package/src/single-node/partial-proofs/setup.ts +8 -0
  245. package/src/single-node/proving/setup.ts +15 -0
  246. package/src/single-node/recovery/setup.ts +8 -0
  247. package/src/single-node/setup.ts +63 -0
  248. package/src/single-node/single_node_test_context.ts +1058 -0
  249. package/src/spartan/setup_test_wallets.ts +32 -41
  250. package/src/spartan/tx_metrics.ts +107 -23
  251. package/src/spartan/utils/gossip_metrics.ts +108 -0
  252. package/src/spartan/utils/index.ts +3 -0
  253. package/src/spartan/utils/nodes.ts +2 -2
  254. package/src/test-wallet/test_wallet.ts +185 -60
  255. package/src/test-wallet/utils.ts +104 -11
  256. package/src/test-wallet/wallet_worker_script.ts +11 -5
  257. package/src/test-wallet/worker_wallet.ts +19 -16
  258. package/src/test-wallet/worker_wallet_schema.ts +4 -3
  259. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +0 -55
  260. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +0 -1
  261. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +0 -47
  262. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +0 -1
  263. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +0 -129
  264. package/dest/e2e_deploy_contract/deploy_test.d.ts +0 -37
  265. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +0 -1
  266. package/dest/e2e_deploy_contract/deploy_test.js +0 -50
  267. package/dest/e2e_epochs/epochs_test.d.ts +0 -104
  268. package/dest/e2e_epochs/epochs_test.d.ts.map +0 -1
  269. package/dest/e2e_epochs/epochs_test.js +0 -389
  270. package/dest/e2e_fees/bridging_race.notest.d.ts.map +0 -1
  271. package/dest/e2e_fees/fees_test.d.ts +0 -88
  272. package/dest/e2e_fees/fees_test.d.ts.map +0 -1
  273. package/dest/e2e_fees/fees_test.js +0 -255
  274. package/dest/e2e_l1_publisher/write_json.d.ts +0 -11
  275. package/dest/e2e_l1_publisher/write_json.d.ts.map +0 -1
  276. package/dest/e2e_l1_publisher/write_json.js +0 -56
  277. package/dest/e2e_multi_validator/utils.d.ts +0 -12
  278. package/dest/e2e_multi_validator/utils.d.ts.map +0 -1
  279. package/dest/e2e_nested_contract/nested_contract_test.d.ts +0 -26
  280. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +0 -1
  281. package/dest/e2e_nested_contract/nested_contract_test.js +0 -54
  282. package/dest/e2e_p2p/inactivity_slash_test.d.ts +0 -31
  283. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +0 -1
  284. package/dest/e2e_p2p/inactivity_slash_test.js +0 -136
  285. package/dest/e2e_p2p/p2p_network.d.ts.map +0 -1
  286. package/dest/e2e_p2p/reqresp/utils.d.ts +0 -22
  287. package/dest/e2e_p2p/reqresp/utils.d.ts.map +0 -1
  288. package/dest/e2e_p2p/shared.d.ts +0 -66
  289. package/dest/e2e_p2p/shared.d.ts.map +0 -1
  290. package/dest/e2e_p2p/shared.js +0 -212
  291. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +0 -2
  292. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +0 -1
  293. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +0 -1
  294. package/dest/e2e_token_contract/token_contract_test.d.ts +0 -44
  295. package/dest/e2e_token_contract/token_contract_test.d.ts.map +0 -1
  296. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +0 -193
  297. package/src/e2e_deploy_contract/deploy_test.ts +0 -85
  298. package/src/e2e_epochs/epochs_test.ts +0 -499
  299. package/src/e2e_l1_publisher/write_json.ts +0 -77
  300. package/src/e2e_nested_contract/nested_contract_test.ts +0 -75
  301. package/src/e2e_p2p/inactivity_slash_test.ts +0 -179
  302. package/src/e2e_p2p/shared.ts +0 -343
  303. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.js +0 -0
  304. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.js +0 -0
  305. /package/dest/{e2e_multi_validator/utils.js → composed/web3signer/multi_validator_keystore_utils.js} +0 -0
  306. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof.json +0 -0
  307. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.ts +0 -0
  308. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.ts +0 -0
  309. /package/src/{e2e_multi_validator/utils.ts → composed/web3signer/multi_validator_keystore_utils.ts} +0 -0
@@ -0,0 +1,213 @@
1
+ import { type InitialAccountData, generateSchnorrAccounts } from '@aztec/accounts/testing';
2
+ import type { FieldLike } from '@aztec/aztec.js/abi';
3
+ import { NO_FROM } from '@aztec/aztec.js/account';
4
+ import type { AztecAddress, CompleteAddress } from '@aztec/aztec.js/addresses';
5
+ import type { AztecNode } from '@aztec/aztec.js/node';
6
+ import type { AccountManager } from '@aztec/aztec.js/wallet';
7
+ import { BlockNumber } from '@aztec/foundation/branded-types';
8
+ import { type DeliveryEvent, OnchainDeliveryTestContract } from '@aztec/noir-test-contracts.js/OnchainDeliveryTest';
9
+ import type { CustomRequest, ResolveCustomRequest, ResolveTaggingSecretStrategy } from '@aztec/pxe/config';
10
+ import type { AztecNodeDebug } from '@aztec/stdlib/interfaces/client';
11
+
12
+ import { jest } from '@jest/globals';
13
+
14
+ import { AUTOMINE_E2E_OPTS } from '../../fixtures/fixtures.js';
15
+ import { ensureHandshakeRegistryPublished, setup, setupPXEAndGetWallet } from '../../fixtures/setup.js';
16
+ import { TestWallet } from '../../test-wallet/test_wallet.js';
17
+
18
+ // Builds the hook serving custom requests issued during the sender's simulations. Installed on the sender PXE at
19
+ // creation but built only once the recipient exists, since serving typically needs the recipient's wallet and keys.
20
+ export type CustomRequestResponder = (
21
+ recipient: TestWallet,
22
+ recipientAccount: InitialAccountData,
23
+ recipientCompleteAddress: CompleteAddress,
24
+ ) => ResolveCustomRequest;
25
+
26
+ export type Mode = 'constrained' | 'unconstrained';
27
+
28
+ // A single mode applies to both the event and note sends; `{ events, notes }` sends each in its own mode, which
29
+ // exercises cross-mode handshake reuse: bootstrap in one mode, deliver in the other on the same handshake.
30
+ export type DeliveryMode = Mode | { events: Mode; notes: Mode };
31
+
32
+ const formatMode = (mode: DeliveryMode): string => (typeof mode === 'string' ? mode : `${mode.events}->${mode.notes}`);
33
+
34
+ // Onchain private delivery has two orthogonal axes: the delivery MODE (constrained = nullifier-chained sequence;
35
+ // unconstrained = no nullifier, windowed scan) and the tagging-secret SOURCE, which the wallet's
36
+ // `resolveTaggingSecretStrategy` hook selects. This harness exercises (strategy, mode) cells end to end across two
37
+ // PXEs that share only a node: the sender PXE sends, the recipient PXE discovers purely from onchain logs plus the
38
+ // HandshakeRegistry.
39
+ //
40
+ // Cross-PXE is the meaningful setup: the recipient PXE holds no sender state, so a cell only "discovers" a message if
41
+ // the source truly reached it.
42
+ export function buildMessageDeliveryTest(opts: {
43
+ // Names the tagging-secret source, e.g. 'non-interactive handshake' or 'arbitrary secret'. The describe title is
44
+ // derived as `${strategy} x ${mode}`.
45
+ strategy: string;
46
+ mode: DeliveryMode;
47
+ // Required: every cell states its source explicitly rather than leaning on the PXE default (covered by unit tests).
48
+ senderHook: ResolveTaggingSecretStrategy;
49
+ // Recipient-side setup the source requires (e.g. registering a raw arbitrary secret); runs once after deployment.
50
+ recipientRegistration?: (
51
+ recipient: TestWallet,
52
+ recipientAddress: AztecAddress,
53
+ sender: AztecAddress,
54
+ ) => Promise<void>;
55
+ // Serves the custom requests issued during the sender's simulations (e.g. the registry's interactive-handshake
56
+ // signature request).
57
+ customRequestResponder?: CustomRequestResponder;
58
+ // Extra `it()`s to register in this cell's suite, e.g. assertions against state a custom `senderHook` recorded.
59
+ // Called inside the same `describe`, after the two baseline assertions below, so it shares their `beforeAll`
60
+ // instead of depending on Jest's cross-`describe` execution order.
61
+ additionalTests?: () => void;
62
+ }) {
63
+ const { strategy, mode, senderHook, recipientRegistration, customRequestResponder, additionalTests } = opts;
64
+ const description = `${strategy} x ${formatMode(mode)}`;
65
+
66
+ describe(description, () => {
67
+ jest.setTimeout(300_000);
68
+
69
+ const eventValues = [10n, 20n, 30n];
70
+ const noteValues = [40n, 50n, 60n];
71
+
72
+ let aztecNode: AztecNode & AztecNodeDebug;
73
+ let walletSender: TestWallet;
74
+ let walletRecipient: TestWallet;
75
+ let sender: AztecAddress;
76
+ let recipient: AztecAddress;
77
+ let contractSender: OnchainDeliveryTestContract;
78
+ let teardownSender: () => Promise<void>;
79
+ let teardownRecipient: () => Promise<void>;
80
+ // Discovery results captured in beforeAll, so the assertions in the actual tests below stay pure.
81
+ // A failure during delivery fails beforeAll loudly instead of being swallowed as an expected red.
82
+ let discoveredEvents: FieldLike[];
83
+ let readNotes: bigint[];
84
+
85
+ const { events: eventMode, notes: noteMode } = typeof mode === 'string' ? { events: mode, notes: mode } : mode;
86
+ const sendEvent = (value: bigint) =>
87
+ eventMode === 'constrained'
88
+ ? contractSender.methods.emit_event(recipient, value)
89
+ : contractSender.methods.emit_event_unconstrained(recipient, value);
90
+ const sendNote = (value: bigint) =>
91
+ noteMode === 'constrained'
92
+ ? contractSender.methods.emit_note(recipient, value)
93
+ : contractSender.methods.emit_note_unconstrained(recipient, value);
94
+
95
+ let additionallyFundedAccounts: InitialAccountData[];
96
+ let recipientAccount: AccountManager | undefined;
97
+ let customRequestCount = 0;
98
+
99
+ beforeAll(async () => {
100
+ // The sender PXE holds the sender and carries this cell's tagging-secret-strategy hook. The recipient is funded
101
+ // at genesis here but created and deployed on the isolated recipient PXE below, so it carries no sender state
102
+ // from other cells.
103
+ ({
104
+ aztecNode,
105
+ additionallyFundedAccounts,
106
+ wallet: walletSender,
107
+ accounts: [sender],
108
+ teardown: teardownSender,
109
+ } = await setup(1, {
110
+ ...AUTOMINE_E2E_OPTS,
111
+ additionallyFundedAccounts: await generateSchnorrAccounts(1, 'schnorr'),
112
+ pxeCreationOptions: {
113
+ hooks: {
114
+ resolveTaggingSecretStrategy: senderHook,
115
+ resolveCustomRequest: async (request: CustomRequest) => {
116
+ if (!customRequestResponder) {
117
+ throw new Error('A custom request arrived but this test cell has no customRequestResponder configured');
118
+ }
119
+ if (!recipientAccount) {
120
+ throw new Error('A custom request arrived before the recipient wallet was created');
121
+ }
122
+ customRequestCount++;
123
+ const respond = customRequestResponder(
124
+ walletRecipient,
125
+ additionallyFundedAccounts[0],
126
+ await recipientAccount.getCompleteAddress(),
127
+ );
128
+ return respond(request);
129
+ },
130
+ },
131
+ },
132
+ }));
133
+
134
+ ({ wallet: walletRecipient, teardown: teardownRecipient } = await setupPXEAndGetWallet(
135
+ aztecNode,
136
+ aztecNode,
137
+ {},
138
+ undefined,
139
+ 'pxe-recipient',
140
+ ));
141
+ recipientAccount = await walletRecipient.createSchnorrAccount(
142
+ additionallyFundedAccounts[0].secret,
143
+ additionallyFundedAccounts[0].salt,
144
+ additionallyFundedAccounts[0].signingKey,
145
+ );
146
+ await (await recipientAccount.getDeployMethod()).send({ from: NO_FROM });
147
+ recipient = recipientAccount.address;
148
+
149
+ await ensureHandshakeRegistryPublished(walletSender, sender);
150
+ const { contract: deployed, instance } = await OnchainDeliveryTestContract.deploy(walletSender).send({
151
+ from: sender,
152
+ });
153
+ contractSender = deployed;
154
+
155
+ await ensureHandshakeRegistryPublished(walletRecipient, recipient);
156
+ await walletRecipient.registerContract(instance, OnchainDeliveryTestContract.artifact);
157
+
158
+ await recipientRegistration?.(walletRecipient, recipient, sender);
159
+
160
+ // Constrained sends to one pair are strictly ordered, so deliver one tx at a time. The first send bootstraps the
161
+ // handshake (when the source is a handshake); the rest reuse it.
162
+ const blockNumbers: number[] = [];
163
+ for (const value of eventValues) {
164
+ const { receipt } = await sendEvent(value).send({ from: sender });
165
+ blockNumbers.push(receipt.blockNumber!);
166
+ }
167
+ for (const value of noteValues) {
168
+ await sendNote(value).send({ from: sender });
169
+ }
170
+
171
+ await walletRecipient.sync();
172
+
173
+ const events = await walletRecipient.getPrivateEvents<DeliveryEvent>(
174
+ OnchainDeliveryTestContract.events.DeliveryEvent,
175
+ {
176
+ contractAddress: contractSender.address,
177
+ fromBlock: BlockNumber(Math.min(...blockNumbers)),
178
+ toBlock: BlockNumber(Math.max(...blockNumbers) + 1),
179
+ scopes: [recipient],
180
+ },
181
+ );
182
+ discoveredEvents = events.map(e => e.event.value);
183
+
184
+ const contractRecipient = OnchainDeliveryTestContract.at(contractSender.address, walletRecipient);
185
+ const { result } = await contractRecipient.methods.get_note_values(recipient).simulate({ from: recipient });
186
+ readNotes = result.storage.slice(0, Number(result.len));
187
+ });
188
+
189
+ afterAll(async () => {
190
+ await teardownRecipient();
191
+ await teardownSender();
192
+ });
193
+
194
+ it('the recipient PXE discovers the events delivered by the sender PXE', () => {
195
+ expect(discoveredEvents.length).toBe(eventValues.length);
196
+ for (const value of eventValues) {
197
+ expect(discoveredEvents).toContainEqual(value);
198
+ }
199
+ });
200
+
201
+ it('the recipient PXE reads back the notes delivered by the sender PXE', () => {
202
+ expect(readNotes).toEqual(noteValues);
203
+ });
204
+
205
+ if (customRequestResponder) {
206
+ it('the custom request hook fires exactly once, on the send that bootstraps the tagging secret', () => {
207
+ expect(customRequestCount).toBe(1);
208
+ });
209
+ }
210
+
211
+ additionalTests?.();
212
+ });
213
+ }
@@ -1,21 +1,18 @@
1
1
  import { AztecAddress } from '@aztec/aztec.js/addresses';
2
2
  import { computeSecretHash } from '@aztec/aztec.js/crypto';
3
3
  import { Fr } from '@aztec/aztec.js/fields';
4
- import { type Logger, createLogger } from '@aztec/aztec.js/log';
5
- import type { AztecNode } from '@aztec/aztec.js/node';
4
+ import { createLogger } from '@aztec/aztec.js/log';
6
5
  import type { TxHash } from '@aztec/aztec.js/tx';
7
- import type { CheatCodes } from '@aztec/aztec/testing';
8
6
  import type { TokenContract } from '@aztec/noir-contracts.js/Token';
9
7
  import { TokenBlacklistContract } from '@aztec/noir-contracts.js/TokenBlacklist';
10
8
  import { GenericProxyContract } from '@aztec/noir-test-contracts.js/GenericProxy';
11
9
  import { InvalidAccountContract } from '@aztec/noir-test-contracts.js/InvalidAccount';
12
- import type { SequencerClient } from '@aztec/sequencer-client';
13
10
 
14
11
  import { jest } from '@jest/globals';
15
12
 
16
- import { type EndToEndContext, deployAccounts, publicDeployAccounts, setup, teardown } from '../fixtures/setup.js';
17
- import { TokenSimulator } from '../simulators/token_simulator.js';
18
- import type { TestWallet } from '../test-wallet/test_wallet.js';
13
+ import { ensureAuthRegistryPublished } from '../../fixtures/setup.js';
14
+ import { TokenSimulator } from '../../simulators/token_simulator.js';
15
+ import { AutomineTestContext, type AutomineTestOpts } from '../automine_test_context.js';
19
16
 
20
17
  export class Role {
21
18
  private isAdmin = false;
@@ -44,35 +41,33 @@ export class Role {
44
41
  }
45
42
  }
46
43
 
47
- export class BlacklistTokenContractTest {
44
+ /**
45
+ * TokenBlacklist-domain harness over the automine topology: extends {@link AutomineTestContext} with a
46
+ * {@link TokenSimulator}, the {@link Role} helper, the TokenBlacklist deploy plus a bad-account and
47
+ * authwit proxy, and the role-change-delay warp. Base setup and mint run in {@link setup}.
48
+ */
49
+ export class BlacklistTokenContractTest extends AutomineTestContext {
48
50
  // This value MUST match the same value that we have in the contract
49
51
  static CHANGE_ROLES_DELAY = 86400;
50
52
 
51
- context!: EndToEndContext;
52
- logger: Logger;
53
- wallet!: TestWallet;
54
53
  asset!: TokenBlacklistContract;
55
54
  tokenSim!: TokenSimulator;
56
55
  badAccount!: InvalidAccountContract;
57
56
  authwitProxy!: GenericProxyContract;
58
- cheatCodes!: CheatCodes;
59
- sequencer!: SequencerClient;
60
- aztecNode!: AztecNode;
61
57
 
62
58
  adminAddress!: AztecAddress;
63
59
  otherAddress!: AztecAddress;
64
60
  blacklistedAddress!: AztecAddress;
65
61
 
62
+ private testName: string;
63
+
66
64
  constructor(testName: string) {
67
- this.logger = createLogger(`e2e:e2e_blacklist_token_contract:${testName}`);
65
+ super();
66
+ this.testName = testName;
68
67
  }
69
68
 
70
69
  async crossTimestampOfChange() {
71
- await this.cheatCodes.warpL2TimeAtLeastBy(
72
- this.sequencer,
73
- this.aztecNode,
74
- BlacklistTokenContractTest.CHANGE_ROLES_DELAY,
75
- );
70
+ await this.markProvenAndWarp(BlacklistTokenContractTest.CHANGE_ROLES_DELAY);
76
71
  }
77
72
 
78
73
  /**
@@ -81,30 +76,18 @@ export class BlacklistTokenContractTest {
81
76
  * 2. Publicly deploy accounts, deploy token contract and a "bad account".
82
77
  */
83
78
  async applyBaseSetup() {
84
- // Adding a timeout of 2 minutes in here such that it is propagated to the underlying tests
85
- jest.setTimeout(120_000);
86
-
87
- this.logger.info('Deploying 3 accounts');
88
- const { deployedAccounts } = await deployAccounts(
89
- 3,
90
- this.logger,
91
- )({
92
- wallet: this.context.wallet,
93
- initialFundedAccounts: this.context.initialFundedAccounts,
94
- });
79
+ // Bumped from 2 min: pipelined cadence (~24s/dependent-tx) makes the 3-account deploy plus token/bad-account/
80
+ // proxy deploys exceed the original window.
81
+ jest.setTimeout(600_000);
95
82
 
96
83
  this.cheatCodes = this.context.cheatCodes;
97
84
  this.aztecNode = this.context.aztecNodeService;
98
85
  this.sequencer = this.context.sequencer!;
99
86
  this.wallet = this.context.wallet;
100
- this.adminAddress = deployedAccounts[0].address;
101
- this.otherAddress = deployedAccounts[1].address;
102
- this.blacklistedAddress = deployedAccounts[2].address;
87
+ [this.adminAddress, this.otherAddress, this.blacklistedAddress] = this.context.accounts;
103
88
 
104
89
  this.logger.info('Setting up blacklist token contract');
105
- // Create the token contract state.
106
- this.logger.verbose(`Public deploy accounts...`);
107
- await publicDeployAccounts(this.wallet, [this.adminAddress, this.otherAddress, this.blacklistedAddress]);
90
+ await ensureAuthRegistryPublished(this.wallet, this.adminAddress);
108
91
 
109
92
  this.logger.verbose(`Deploying TokenContract...`);
110
93
  ({ contract: this.asset } = await TokenBlacklistContract.deploy(this.wallet, this.adminAddress).send({
@@ -142,19 +125,13 @@ export class BlacklistTokenContractTest {
142
125
  ).toEqual(new Role().withAdmin().toNoirStruct());
143
126
  }
144
127
 
145
- async setup() {
146
- this.logger.info('Setting up fresh context');
147
- this.context = await setup(0, {
148
- fundSponsoredFPC: true,
149
- skipAccountDeployment: true,
150
- });
128
+ override async setup(opts: AutomineTestOpts = {}) {
129
+ await super.setup({ numberOfAccounts: 3, ...opts });
130
+ // hydrateFromContext repoints `this.logger` at the context logger; restore the harness-named one.
131
+ this.logger = createLogger(`e2e:automine:blacklist:${this.testName}`);
151
132
  await this.applyBaseSetup();
152
133
  }
153
134
 
154
- async teardown() {
155
- await teardown(this.context);
156
- }
157
-
158
135
  async addPendingShieldNoteToPXE(
159
136
  contract: TokenBlacklistContract,
160
137
  recipient: AztecAddress,
@@ -1,5 +1,5 @@
1
1
  import { AztecAddress } from '@aztec/aztec.js/addresses';
2
- import { type Logger, createLogger } from '@aztec/aztec.js/log';
2
+ import { createLogger } from '@aztec/aztec.js/log';
3
3
  import type { AztecNode } from '@aztec/aztec.js/node';
4
4
  import { TokenContract } from '@aztec/noir-contracts.js/Token';
5
5
  import { GenericProxyContract } from '@aztec/noir-test-contracts.js/GenericProxy';
@@ -7,19 +7,23 @@ import { InvalidAccountContract } from '@aztec/noir-test-contracts.js/InvalidAcc
7
7
 
8
8
  import { jest } from '@jest/globals';
9
9
 
10
- import { type EndToEndContext, deployAccounts, publicDeployAccounts, setup, teardown } from '../fixtures/setup.js';
11
- import { mintTokensToPrivate } from '../fixtures/token_utils.js';
12
- import { TokenSimulator } from '../simulators/token_simulator.js';
13
- import type { TestWallet } from '../test-wallet/test_wallet.js';
10
+ import { ensureAuthRegistryPublished } from '../../fixtures/setup.js';
11
+ import { mintTokensToPrivate } from '../../fixtures/token_utils.js';
12
+ import { TokenSimulator } from '../../simulators/token_simulator.js';
13
+ import { AutomineTestContext, type AutomineTestOpts } from '../automine_test_context.js';
14
14
 
15
15
  const { METRICS_PORT: metricsPort } = process.env;
16
16
 
17
- export class TokenContractTest {
17
+ /**
18
+ * Token-domain harness over the automine topology: extends {@link AutomineTestContext} with a
19
+ * {@link TokenSimulator}, the USDC Token deploy plus a bad-account and authwit proxy, and an optional
20
+ * mint. Base setup is opt-in via {@link applyBaseSnapshots} (run during `setup()`); {@link applyMint}
21
+ * is called explicitly after `setup()`.
22
+ */
23
+ export class TokenContractTest extends AutomineTestContext {
18
24
  static TOKEN_NAME = 'USDC';
19
25
  static TOKEN_SYMBOL = 'USD';
20
26
  static TOKEN_DECIMALS = 18n;
21
- context!: EndToEndContext;
22
- logger: Logger;
23
27
  metricsPort?: number;
24
28
  asset!: TokenContract;
25
29
  tokenSim!: TokenSimulator;
@@ -27,16 +31,16 @@ export class TokenContractTest {
27
31
 
28
32
  badAccount!: InvalidAccountContract;
29
33
  authwitProxy!: GenericProxyContract;
30
- wallet!: TestWallet;
31
34
  adminAddress!: AztecAddress;
32
- account1Address!: AztecAddress;
35
+ otherAddress!: AztecAddress;
33
36
  account2Address!: AztecAddress;
34
37
 
35
38
  private shouldApplyBaseSetup = false;
36
- private shouldApplyMint = false;
39
+ private testName: string;
37
40
 
38
41
  constructor(testName: string) {
39
- this.logger = createLogger(`e2e:e2e_token_contract:${testName}`);
42
+ super();
43
+ this.testName = testName;
40
44
  this.metricsPort = metricsPort ? parseInt(metricsPort) : undefined;
41
45
  }
42
46
 
@@ -48,14 +52,6 @@ export class TokenContractTest {
48
52
  this.shouldApplyBaseSetup = true;
49
53
  }
50
54
 
51
- /**
52
- * Registers that mint should be applied during setup().
53
- * Call this before setup() to mint tokens to the admin account.
54
- */
55
- applyMintSnapshot() {
56
- this.shouldApplyMint = true;
57
- }
58
-
59
55
  /**
60
56
  * Applies base setup: deploys 3 accounts, publicly deploys accounts, token contract and a "bad account".
61
57
  */
@@ -63,22 +59,12 @@ export class TokenContractTest {
63
59
  // Adding a timeout of 2 minutes in here such that it is propagated to the underlying tests
64
60
  jest.setTimeout(120_000);
65
61
 
66
- this.logger.info('Applying base setup - deploying 3 accounts');
67
- const { deployedAccounts } = await deployAccounts(
68
- 3,
69
- this.logger,
70
- )({
71
- wallet: this.context.wallet,
72
- initialFundedAccounts: this.context.initialFundedAccounts,
73
- });
74
-
75
62
  this.node = this.context.aztecNodeService;
76
63
  this.wallet = this.context.wallet;
77
- [this.adminAddress, this.account1Address, this.account2Address] = deployedAccounts.map(acc => acc.address);
64
+ [this.adminAddress, this.otherAddress, this.account2Address] = this.context.accounts;
78
65
 
79
66
  this.logger.info('Applying base setup - deploying token contract');
80
- this.logger.verbose(`Public deploy accounts...`);
81
- await publicDeployAccounts(this.wallet, [this.adminAddress, this.account1Address]);
67
+ await ensureAuthRegistryPublished(this.wallet, this.adminAddress);
82
68
 
83
69
  this.logger.verbose(`Deploying TokenContract...`);
84
70
  ({ contract: this.asset } = await TokenContract.deploy(
@@ -107,7 +93,7 @@ export class TokenContractTest {
107
93
 
108
94
  this.tokenSim = new TokenSimulator(this.asset, this.wallet, this.adminAddress, this.logger, [
109
95
  this.adminAddress,
110
- this.account1Address,
96
+ this.otherAddress,
111
97
  ]);
112
98
 
113
99
  expect((await this.asset.methods.get_admin().simulate({ from: this.adminAddress })).result).toBe(
@@ -115,27 +101,18 @@ export class TokenContractTest {
115
101
  );
116
102
  }
117
103
 
118
- async setup() {
119
- this.context = await setup(0, {
120
- metricsPort: this.metricsPort,
121
- fundSponsoredFPC: true,
122
- skipAccountDeployment: true,
123
- });
104
+ override async setup(opts: AutomineTestOpts = {}) {
105
+ await super.setup({ numberOfAccounts: 3, metricsPort: this.metricsPort, ...opts });
106
+ // hydrateFromContext repoints `this.logger` at the context logger; restore the harness-named one.
107
+ this.logger = createLogger(`e2e:automine:token:${this.testName}`);
124
108
 
125
109
  if (this.shouldApplyBaseSetup) {
126
110
  await this.applyBaseSetup();
127
111
  }
128
-
129
- if (this.shouldApplyMint) {
130
- await this.applyMint();
131
- }
132
- }
133
-
134
- async teardown() {
135
- await teardown(this.context);
136
112
  }
137
113
 
138
- private async applyMint() {
114
+ /** Mints an initial public and private balance to the admin account. Call after {@link setup}. */
115
+ async applyMint() {
139
116
  this.logger.info('Applying mint setup');
140
117
  const { asset, adminAddress, tokenSim } = this;
141
118
  const amount = 10000n;
@@ -0,0 +1,138 @@
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import type { ContractFunctionInteraction } from '@aztec/aztec.js/contracts';
3
+ import type { Logger } from '@aztec/aztec.js/log';
4
+ import type { Wallet } from '@aztec/aztec.js/wallet';
5
+ import { AMMContract } from '@aztec/noir-contracts.js/AMM';
6
+ import type { GenericProxyContract } from '@aztec/noir-test-contracts.js/GenericProxy';
7
+
8
+ import { sendThroughAuthwitProxy } from '../../fixtures/authwit_proxy.js';
9
+ import { DUPLICATE_NULLIFIER_ERROR } from '../../fixtures/fixtures.js';
10
+ import { type AnyTokenContract, mintTokensToPrivate } from '../../fixtures/token_utils.js';
11
+ import type { TestWallet } from '../../test-wallet/test_wallet.js';
12
+
13
+ /** Whether an amount / balance is read from the private or public balance of the token. */
14
+ export type BalanceKind = 'private' | 'public';
15
+
16
+ /** The invalid-authwit-nonce assertion the contract raises when `from == msg_sender` but nonce != 0. */
17
+ export const INVALID_AUTHWIT_NONCE_ERROR =
18
+ "Assertion failed: Invalid authwit nonce. When 'from' and 'msg_sender' are the same, 'authwit_nonce' must be zero";
19
+
20
+ /** Minimal token shape needed to read balances — satisfied structurally by Token/TestToken/TokenBlacklist. */
21
+ export interface BalanceReadable {
22
+ methods: {
23
+ balance_of_private(owner: AztecAddress): { simulate(opts: { from: AztecAddress }): Promise<{ result: bigint }> };
24
+ balance_of_public(owner: AztecAddress): { simulate(opts: { from: AztecAddress }): Promise<{ result: bigint }> };
25
+ };
26
+ }
27
+
28
+ /** Reads the private or public balance of an account, simulating from that account's own scope. */
29
+ export async function balanceOf(asset: BalanceReadable, kind: BalanceKind, account: AztecAddress): Promise<bigint> {
30
+ const interaction =
31
+ kind === 'private' ? asset.methods.balance_of_private(account) : asset.methods.balance_of_public(account);
32
+ return (await interaction.simulate({ from: account })).result;
33
+ }
34
+
35
+ /** Returns half of an account's balance, asserting it is non-zero so the operation under test is meaningful. */
36
+ export async function halfBalanceOf(asset: BalanceReadable, kind: BalanceKind, owner: AztecAddress): Promise<bigint> {
37
+ const amount = (await balanceOf(asset, kind, owner)) / 2n;
38
+ expect(amount).toBeGreaterThan(0n);
39
+ return amount;
40
+ }
41
+
42
+ /** Returns an amount just above an account's balance (balance + delta), asserting it is non-zero. */
43
+ export async function amountAboveBalance(
44
+ asset: BalanceReadable,
45
+ kind: BalanceKind,
46
+ owner: AztecAddress,
47
+ delta = 1n,
48
+ ): Promise<bigint> {
49
+ const amount = (await balanceOf(asset, kind, owner)) + delta;
50
+ expect(amount).toBeGreaterThan(0n);
51
+ return amount;
52
+ }
53
+
54
+ /**
55
+ * Grants a public authwit for `caller` to run `action` on behalf of `owner`, executes it from `caller`,
56
+ * then asserts a replay of the same call reverts as unauthorized (the authwit is single-use).
57
+ *
58
+ * `onExecuted` runs after the successful execution (before the replay attempt) so callers can update
59
+ * their {@link TokenSimulator} to match the state change the executed action produced.
60
+ */
61
+ export async function assertPublicAuthwitReplayRejected(
62
+ wallet: TestWallet,
63
+ owner: AztecAddress,
64
+ action: ContractFunctionInteraction,
65
+ caller: AztecAddress,
66
+ onExecuted?: () => void,
67
+ ): Promise<void> {
68
+ const grant = await wallet.setPublicAuthWit(owner, { caller, action }, true);
69
+ await grant.send();
70
+
71
+ await action.send({ from: caller });
72
+ onExecuted?.();
73
+
74
+ await expect(action.simulate({ from: caller })).rejects.toThrow(/unauthorized/);
75
+ }
76
+
77
+ /**
78
+ * Creates a private authwit for `owner`, executes `action` through the authwit proxy (so `msg_sender`
79
+ * differs from the note owner), then asserts a replay reverts with a duplicate-nullifier error.
80
+ *
81
+ * `onExecuted` runs after the successful execution (before the replay attempt) so callers can update
82
+ * their {@link TokenSimulator} to match the state change the executed action produced.
83
+ */
84
+ export async function assertAuthwitProxyReplayRejected(
85
+ proxy: GenericProxyContract,
86
+ wallet: TestWallet,
87
+ owner: AztecAddress,
88
+ action: ContractFunctionInteraction,
89
+ onExecuted?: () => void,
90
+ ): Promise<void> {
91
+ const witness = await wallet.createAuthWit(owner, { caller: proxy.address, action });
92
+
93
+ await sendThroughAuthwitProxy(proxy, action, { from: owner, authWitnesses: [witness] });
94
+ onExecuted?.();
95
+
96
+ await expect(sendThroughAuthwitProxy(proxy, action, { from: owner, authWitnesses: [witness] })).rejects.toThrow(
97
+ DUPLICATE_NULLIFIER_ERROR,
98
+ );
99
+ }
100
+
101
+ /**
102
+ * Deploys an {@link AMMContract} over three freshly deployed tokens (token0, token1, and the liquidity
103
+ * token), makes the AMM the liquidity token's minter, and mints `initialBalance` of token0 and token1 to
104
+ * each liquidity provider plus token0 to the swapper. `deploy` selects the token flavour (Token vs
105
+ * TestToken), so the concrete token type flows through to the caller.
106
+ */
107
+ export async function deployAmmWithTokens<T extends AnyTokenContract>(
108
+ wallet: Wallet,
109
+ admin: AztecAddress,
110
+ deploy: (wallet: Wallet, admin: AztecAddress, initialBalance: bigint, logger: Logger) => Promise<{ contract: T }>,
111
+ opts: { liquidityProviders: AztecAddress[]; swapper: AztecAddress; initialBalance: bigint; logger: Logger },
112
+ ): Promise<{ token0: T; token1: T; liquidityToken: T; amm: AMMContract }> {
113
+ const { liquidityProviders, swapper, initialBalance, logger } = opts;
114
+
115
+ const { contract: token0 } = await deploy(wallet, admin, 0n, logger);
116
+ const { contract: token1 } = await deploy(wallet, admin, 0n, logger);
117
+ const { contract: liquidityToken } = await deploy(wallet, admin, 0n, logger);
118
+
119
+ const { contract: amm } = await AMMContract.deploy(
120
+ wallet,
121
+ token0.address,
122
+ token1.address,
123
+ liquidityToken.address,
124
+ ).send({ from: admin });
125
+
126
+ // TODO(#9480): consider deploying the token by some factory when the AMM is deployed, and making the AMM be the
127
+ // minter there.
128
+ await liquidityToken.methods.set_minter(amm.address, true).send({ from: admin });
129
+
130
+ for (const lp of liquidityProviders) {
131
+ await mintTokensToPrivate(token0, admin, lp, initialBalance);
132
+ await mintTokensToPrivate(token1, admin, lp, initialBalance);
133
+ }
134
+ // Note that the swapper only holds token0, not token1.
135
+ await mintTokensToPrivate(token0, admin, swapper, initialBalance);
136
+
137
+ return { token0, token1, liquidityToken, amm };
138
+ }
@@ -5,6 +5,7 @@ import {
5
5
  type ProfileInteractionOptions,
6
6
  } from '@aztec/aztec.js/contracts';
7
7
  import type { Logger } from '@aztec/aztec.js/log';
8
+ import { MAX_APPS_PER_KERNEL } from '@aztec/constants';
8
9
  import { createLogger } from '@aztec/foundation/log';
9
10
  import { type PrivateExecutionStep, serializePrivateExecutionSteps } from '@aztec/stdlib/kernel';
10
11
  import type {
@@ -320,6 +321,26 @@ export function convertProfileToGHBenchmark(benchmark: ClientFlowBenchmark): Git
320
321
  return benches;
321
322
  }
322
323
 
324
+ /**
325
+ * Computes the expected number of `PrivateExecutionStep` entries the orchestrator will produce
326
+ * for a tx with `apps` private function calls.
327
+ *
328
+ * Step layout: `apps` app circuits + kernel iterations + 1 final reset + 1 tail + 1 hiding kernel.
329
+ * Each kernel iteration absorbs up to `MAX_APPS_PER_KERNEL` apps via the `init_K` / `inner_K`
330
+ * variants, so the kernel count is `ceil(apps / MAX_APPS_PER_KERNEL)`.
331
+ *
332
+ * Caveat: this assumes no mid-flow reset is triggered, which would split a batch into two kernels
333
+ * separated by a reset. For the flows currently exercised in this benchmark suite that holds, but
334
+ * a future flow that grows large enough to overflow per-tx limits before consuming all apps will
335
+ * not match this formula.
336
+ */
337
+ export function expectedExecutionSteps(apps: number): number {
338
+ const kernels = Math.ceil(apps / MAX_APPS_PER_KERNEL);
339
+ // The final reset and tail are proved as a single circuit (reset_tail or reset_tail_to_public),
340
+ // so they share one execution step.
341
+ return apps + kernels + 1 /* reset+tail */ + 1 /* hiding */;
342
+ }
343
+
323
344
  export async function captureProfile(
324
345
  label: string,
325
346
  interaction: ContractFunctionInteraction | DeployMethod,