@aztec/end-to-end 5.0.0-rc.1 → 5.0.0

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 (257) hide show
  1. package/README.md +215 -27
  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 +17 -24
  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 +22 -28
  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 +1 -1
  25. package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
  26. package/dest/bench/client_flows/benchmark.js +3 -1
  27. package/dest/bench/client_flows/client_flows_benchmark.d.ts +4 -4
  28. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  29. package/dest/bench/client_flows/client_flows_benchmark.js +25 -10
  30. package/dest/bench/utils.d.ts +1 -1
  31. package/dest/composed/ha/ha_full_setup.d.ts +77 -0
  32. package/dest/composed/ha/ha_full_setup.d.ts.map +1 -0
  33. package/dest/composed/ha/ha_full_setup.js +383 -0
  34. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts +12 -0
  35. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts.map +1 -0
  36. package/dest/fixtures/e2e_prover_test.d.ts +10 -7
  37. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  38. package/dest/fixtures/e2e_prover_test.js +33 -14
  39. package/dest/fixtures/fixtures.d.ts +8 -5
  40. package/dest/fixtures/fixtures.d.ts.map +1 -1
  41. package/dest/fixtures/fixtures.js +12 -4
  42. package/dest/fixtures/ha_setup.d.ts +3 -3
  43. package/dest/fixtures/ha_setup.d.ts.map +1 -1
  44. package/dest/fixtures/ha_setup.js +4 -1
  45. package/dest/fixtures/index.d.ts +2 -1
  46. package/dest/fixtures/index.d.ts.map +1 -1
  47. package/dest/fixtures/index.js +1 -0
  48. package/dest/fixtures/setup.d.ts +35 -9
  49. package/dest/fixtures/setup.d.ts.map +1 -1
  50. package/dest/fixtures/setup.js +175 -142
  51. package/dest/fixtures/setup_p2p_test.d.ts +1 -1
  52. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  53. package/dest/fixtures/setup_p2p_test.js +3 -3
  54. package/dest/fixtures/standard_contracts_genesis.d.ts +16 -0
  55. package/dest/fixtures/standard_contracts_genesis.d.ts.map +1 -0
  56. package/dest/fixtures/standard_contracts_genesis.js +25 -0
  57. package/dest/fixtures/timing.d.ts +42 -0
  58. package/dest/fixtures/timing.d.ts.map +1 -0
  59. package/dest/fixtures/timing.js +72 -0
  60. package/dest/fixtures/token_utils.d.ts +22 -4
  61. package/dest/fixtures/token_utils.d.ts.map +1 -1
  62. package/dest/fixtures/token_utils.js +21 -1
  63. package/dest/fixtures/wait_helpers.d.ts +135 -0
  64. package/dest/fixtures/wait_helpers.d.ts.map +1 -0
  65. package/dest/fixtures/wait_helpers.js +154 -0
  66. package/dest/forward-compatibility/wallet_service.js +1 -1
  67. package/dest/multi-node/block-production/setup.d.ts +97 -0
  68. package/dest/multi-node/block-production/setup.d.ts.map +1 -0
  69. package/dest/multi-node/block-production/setup.js +158 -0
  70. package/dest/multi-node/governance/setup.d.ts +67 -0
  71. package/dest/multi-node/governance/setup.d.ts.map +1 -0
  72. package/dest/multi-node/governance/setup.js +126 -0
  73. package/dest/multi-node/multi_node_test_context.d.ts +212 -0
  74. package/dest/multi-node/multi_node_test_context.d.ts.map +1 -0
  75. package/dest/multi-node/multi_node_test_context.js +347 -0
  76. package/dest/multi-node/slashing/inactivity_setup.d.ts +27 -0
  77. package/dest/multi-node/slashing/inactivity_setup.d.ts.map +1 -0
  78. package/dest/multi-node/slashing/inactivity_setup.js +111 -0
  79. package/dest/multi-node/slashing/setup.d.ts +167 -0
  80. package/dest/multi-node/slashing/setup.d.ts.map +1 -0
  81. package/dest/multi-node/slashing/setup.js +275 -0
  82. package/dest/{e2e_p2p → p2p}/p2p_network.d.ts +10 -2
  83. package/dest/p2p/p2p_network.d.ts.map +1 -0
  84. package/dest/{e2e_p2p → p2p}/p2p_network.js +36 -9
  85. package/dest/p2p/reqresp/utils.d.ts +19 -0
  86. package/dest/p2p/reqresp/utils.d.ts.map +1 -0
  87. package/dest/{e2e_p2p → p2p}/reqresp/utils.js +4 -15
  88. package/dest/p2p/shared.d.ts +72 -0
  89. package/dest/p2p/shared.d.ts.map +1 -0
  90. package/dest/p2p/shared.js +212 -0
  91. package/dest/shared/cross_chain_test_harness.d.ts +3 -3
  92. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  93. package/dest/shared/cross_chain_test_harness.js +24 -16
  94. package/dest/shared/gas_portal_test_harness.d.ts +1 -1
  95. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  96. package/dest/shared/gas_portal_test_harness.js +8 -5
  97. package/dest/shared/submit-transactions.d.ts +1 -1
  98. package/dest/shared/submit-transactions.d.ts.map +1 -1
  99. package/dest/shared/submit-transactions.js +12 -5
  100. package/dest/shared/timing_env.d.js +5 -0
  101. package/dest/shared/timing_env.js +365 -0
  102. package/dest/shared/wait_for_l1_to_l2_message.js +1 -1
  103. package/dest/simulators/lending_simulator.js +1 -1
  104. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts +75 -0
  105. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts.map +1 -0
  106. package/dest/{e2e_cross_chain_messaging → single-node/cross-chain}/cross_chain_messaging_test.js +77 -27
  107. package/dest/single-node/cross-chain/message_test_helpers.d.ts +38 -0
  108. package/dest/single-node/cross-chain/message_test_helpers.d.ts.map +1 -0
  109. package/dest/single-node/cross-chain/message_test_helpers.js +70 -0
  110. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.d.ts +1 -1
  111. package/dest/single-node/fees/bridging_race.notest.d.ts.map +1 -0
  112. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.js +17 -4
  113. package/dest/single-node/fees/fees_test.d.ts +95 -0
  114. package/dest/single-node/fees/fees_test.d.ts.map +1 -0
  115. package/dest/{e2e_fees → single-node/fees}/fees_test.js +124 -46
  116. package/dest/single-node/l1-reorgs/setup.d.ts +42 -0
  117. package/dest/single-node/l1-reorgs/setup.d.ts.map +1 -0
  118. package/dest/single-node/l1-reorgs/setup.js +57 -0
  119. package/dest/single-node/partial-proofs/setup.d.ts +5 -0
  120. package/dest/single-node/partial-proofs/setup.d.ts.map +1 -0
  121. package/dest/single-node/partial-proofs/setup.js +5 -0
  122. package/dest/single-node/proving/setup.d.ts +5 -0
  123. package/dest/single-node/proving/setup.d.ts.map +1 -0
  124. package/dest/single-node/proving/setup.js +5 -0
  125. package/dest/single-node/recovery/setup.d.ts +5 -0
  126. package/dest/single-node/recovery/setup.d.ts.map +1 -0
  127. package/dest/single-node/recovery/setup.js +5 -0
  128. package/dest/single-node/setup.d.ts +49 -0
  129. package/dest/single-node/setup.d.ts.map +1 -0
  130. package/dest/single-node/setup.js +56 -0
  131. package/dest/single-node/single_node_test_context.d.ts +373 -0
  132. package/dest/single-node/single_node_test_context.d.ts.map +1 -0
  133. package/dest/single-node/single_node_test_context.js +845 -0
  134. package/dest/spartan/setup_test_wallets.d.ts +1 -1
  135. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  136. package/dest/spartan/setup_test_wallets.js +18 -8
  137. package/dest/spartan/tx_metrics.d.ts +10 -1
  138. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  139. package/dest/spartan/tx_metrics.js +32 -0
  140. package/dest/test-wallet/test_wallet.d.ts +23 -4
  141. package/dest/test-wallet/test_wallet.d.ts.map +1 -1
  142. package/dest/test-wallet/test_wallet.js +20 -4
  143. package/dest/test-wallet/utils.d.ts +36 -1
  144. package/dest/test-wallet/utils.d.ts.map +1 -1
  145. package/dest/test-wallet/utils.js +64 -4
  146. package/dest/test-wallet/wallet_worker_script.js +5 -2
  147. package/dest/test-wallet/worker_wallet.d.ts +5 -5
  148. package/dest/test-wallet/worker_wallet.d.ts.map +1 -1
  149. package/dest/test-wallet/worker_wallet.js +2 -2
  150. package/dest/test-wallet/worker_wallet_schema.js +2 -1
  151. package/package.json +41 -41
  152. package/src/automine/README.md +60 -0
  153. package/src/automine/automine_test_context.ts +153 -0
  154. package/src/automine/delivery/interactive_handshake_responder.ts +125 -0
  155. package/src/automine/delivery/onchain_delivery_harness.ts +213 -0
  156. package/src/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.ts +19 -39
  157. package/src/{e2e_token_contract → automine/token}/token_contract_test.ts +24 -43
  158. package/src/automine/token/token_test_helpers.ts +138 -0
  159. package/src/bench/client_flows/benchmark.ts +3 -1
  160. package/src/bench/client_flows/client_flows_benchmark.ts +39 -12
  161. package/src/composed/ha/ha_full_setup.ts +466 -0
  162. package/src/fixtures/e2e_prover_test.ts +40 -23
  163. package/src/fixtures/fixtures.ts +14 -4
  164. package/src/fixtures/ha_setup.ts +7 -3
  165. package/src/fixtures/index.ts +1 -0
  166. package/src/fixtures/setup.ts +217 -146
  167. package/src/fixtures/setup_p2p_test.ts +3 -3
  168. package/src/fixtures/standard_contracts_genesis.ts +28 -0
  169. package/src/fixtures/timing.ts +97 -0
  170. package/src/fixtures/token_utils.ts +39 -4
  171. package/src/fixtures/wait_helpers.ts +333 -0
  172. package/src/forward-compatibility/wallet_service.ts +2 -2
  173. package/src/guides/up_quick_start.sh +5 -0
  174. package/src/infra/README.md +12 -0
  175. package/src/multi-node/README.md +96 -0
  176. package/src/multi-node/block-production/setup.ts +272 -0
  177. package/src/multi-node/governance/setup.ts +172 -0
  178. package/src/multi-node/multi_node_test_context.ts +447 -0
  179. package/src/multi-node/slashing/inactivity_setup.ts +139 -0
  180. package/src/multi-node/slashing/setup.ts +433 -0
  181. package/src/p2p/README.md +78 -0
  182. package/src/{e2e_p2p → p2p}/p2p_network.ts +36 -7
  183. package/src/{e2e_p2p → p2p}/reqresp/utils.ts +5 -14
  184. package/src/p2p/shared.ts +329 -0
  185. package/src/shared/cross_chain_test_harness.ts +22 -13
  186. package/src/shared/gas_portal_test_harness.ts +13 -5
  187. package/src/shared/submit-transactions.ts +13 -5
  188. package/src/shared/timing_env.d.mts +39 -0
  189. package/src/shared/timing_env.mjs +363 -0
  190. package/src/shared/wait_for_l1_to_l2_message.ts +1 -1
  191. package/src/simulators/lending_simulator.ts +1 -1
  192. package/src/single-node/README.md +66 -0
  193. package/src/{e2e_cross_chain_messaging → single-node/cross-chain}/cross_chain_messaging_test.ts +110 -39
  194. package/src/single-node/cross-chain/message_test_helpers.ts +125 -0
  195. package/src/{e2e_fees → single-node/fees}/bridging_race.notest.ts +19 -5
  196. package/src/{e2e_fees → single-node/fees}/fees_test.ts +141 -48
  197. package/src/single-node/l1-reorgs/setup.ts +93 -0
  198. package/src/single-node/partial-proofs/setup.ts +8 -0
  199. package/src/single-node/proving/setup.ts +15 -0
  200. package/src/single-node/recovery/setup.ts +8 -0
  201. package/src/single-node/setup.ts +63 -0
  202. package/src/single-node/single_node_test_context.ts +1054 -0
  203. package/src/spartan/setup_test_wallets.ts +23 -8
  204. package/src/spartan/tx_metrics.ts +26 -0
  205. package/src/test-wallet/test_wallet.ts +28 -6
  206. package/src/test-wallet/utils.ts +102 -5
  207. package/src/test-wallet/wallet_worker_script.ts +6 -3
  208. package/src/test-wallet/worker_wallet.ts +5 -9
  209. package/src/test-wallet/worker_wallet_schema.ts +1 -1
  210. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +0 -56
  211. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +0 -1
  212. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +0 -58
  213. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +0 -1
  214. package/dest/e2e_deploy_contract/deploy_test.d.ts +0 -36
  215. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +0 -1
  216. package/dest/e2e_deploy_contract/deploy_test.js +0 -42
  217. package/dest/e2e_epochs/epochs_test.d.ts +0 -137
  218. package/dest/e2e_epochs/epochs_test.d.ts.map +0 -1
  219. package/dest/e2e_epochs/epochs_test.js +0 -485
  220. package/dest/e2e_fees/bridging_race.notest.d.ts.map +0 -1
  221. package/dest/e2e_fees/fees_test.d.ts +0 -89
  222. package/dest/e2e_fees/fees_test.d.ts.map +0 -1
  223. package/dest/e2e_l1_publisher/write_json.d.ts +0 -11
  224. package/dest/e2e_l1_publisher/write_json.d.ts.map +0 -1
  225. package/dest/e2e_l1_publisher/write_json.js +0 -56
  226. package/dest/e2e_multi_validator/utils.d.ts +0 -12
  227. package/dest/e2e_multi_validator/utils.d.ts.map +0 -1
  228. package/dest/e2e_nested_contract/nested_contract_test.d.ts +0 -22
  229. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +0 -1
  230. package/dest/e2e_nested_contract/nested_contract_test.js +0 -40
  231. package/dest/e2e_p2p/inactivity_slash_test.d.ts +0 -31
  232. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +0 -1
  233. package/dest/e2e_p2p/inactivity_slash_test.js +0 -138
  234. package/dest/e2e_p2p/p2p_network.d.ts.map +0 -1
  235. package/dest/e2e_p2p/reqresp/utils.d.ts +0 -22
  236. package/dest/e2e_p2p/reqresp/utils.d.ts.map +0 -1
  237. package/dest/e2e_p2p/shared.d.ts +0 -75
  238. package/dest/e2e_p2p/shared.d.ts.map +0 -1
  239. package/dest/e2e_p2p/shared.js +0 -217
  240. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +0 -2
  241. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +0 -1
  242. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +0 -1
  243. package/dest/e2e_token_contract/token_contract_test.d.ts +0 -44
  244. package/dest/e2e_token_contract/token_contract_test.d.ts.map +0 -1
  245. package/src/e2e_deploy_contract/deploy_test.ts +0 -73
  246. package/src/e2e_epochs/epochs_test.ts +0 -596
  247. package/src/e2e_l1_publisher/write_json.ts +0 -77
  248. package/src/e2e_nested_contract/nested_contract_test.ts +0 -51
  249. package/src/e2e_p2p/inactivity_slash_test.ts +0 -181
  250. package/src/e2e_p2p/shared.ts +0 -332
  251. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.js +0 -0
  252. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.js +0 -0
  253. /package/dest/{e2e_multi_validator/utils.js → composed/web3signer/multi_validator_keystore_utils.js} +0 -0
  254. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof.json +0 -0
  255. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.ts +0 -0
  256. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.ts +0 -0
  257. /package/src/{e2e_multi_validator/utils.ts → composed/web3signer/multi_validator_keystore_utils.ts} +0 -0
@@ -0,0 +1,365 @@
1
+ import { appendFileSync, writeFileSync } from 'node:fs';
2
+ import { basename } from 'node:path';
3
+ import CustomEnvironment from '../../../foundation/src/jest/env.mjs';
4
+ // Per-test e2e timing environment. Gated entirely on the TEST_TIMING_FILE env var: when unset, this
5
+ // behaves exactly like the base CustomEnvironment (it only delegates). When set, it records, per test
6
+ // worker process, the time spent in jest before/after hooks and the test body, and folds in the named
7
+ // spans recorded via the `testSpan()` wrapper (fixtures/timing.ts) through a collector shared on
8
+ // `this.global`.
9
+ //
10
+ // Output is one JSONL file per worker process (the env runs once per worker). Each line carries a
11
+ // `type` discriminator and is one of:
12
+ // - `type: 'test'` (`name` set): beforeEach hooks, the it() body, afterEach hooks for one test; or
13
+ // - `type: 'suite'` (`name: null`): the suite-scoped beforeAll/afterAll hooks for the whole file.
14
+ //
15
+ // Each line also gains a `spans` map: per `category:label` tag the test/suite touched, the collector
16
+ // records `{ count, totalMs, busyMs, maxMs }`. `busyMs` is the duration of the union of the spans'
17
+ // `[start, end)` intervals on the shared `performance.now()` clock, so concurrent spans (Promise.all
18
+ // fan-out) do not inflate it the way `totalMs` does. The legacy `setupFnMs`/`teardownFnMs` fields are
19
+ // kept for back-compat, derived from the `setup:env`/`teardown:env` spans.
20
+ //
21
+ // When `TEST_TIMING_SPANS=1`, the collector additionally retains every raw span occurrence and emits
22
+ // one `type:"span"` line per occurrence (owner, name, ms) for deep dives, at the cost of a larger file.
23
+ export default class TimingEnvironment extends CustomEnvironment {
24
+ constructor(config, context){
25
+ super(config, context);
26
+ this.timingFile = process.env.TEST_TIMING_FILE;
27
+ if (!this.timingFile) {
28
+ return;
29
+ }
30
+ this.suite = basename(context?.testPath ?? config?.testPath ?? 'unknown').replace(/\.test\.[cm]?[jt]s$/, '');
31
+ this.meta = {
32
+ commit: process.env.COMMIT_HASH ?? null,
33
+ branch: process.env.TARGET_BRANCH ?? process.env.REF_NAME ?? null,
34
+ runId: process.env.RUN_ID ?? null
35
+ };
36
+ // Opt-in per-occurrence emission for deep dives (off by default keeps the JSONL one line per test).
37
+ this.emitSpanLines = process.env.TEST_TIMING_SPANS === '1';
38
+ // Shared collector. The instrumented helpers (running in the sandbox realm) read
39
+ // `globalThis.__e2eTimings`; this env (host realm) reads `this.global.__e2eTimings` — they are the
40
+ // same object. `current` is the full name of the test currently running (null during
41
+ // beforeAll/afterAll), used to attribute each span to a test or to the suite-scoped line. `spans`
42
+ // accumulates every recorded span until flush. The `start`/`end` timestamps come from the sandbox
43
+ // realm's `performance.now()`; Node's perf clock is process-wide (one monotonic origin across all
44
+ // realms), so merging the intervals here for `busyMs` is valid.
45
+ this.collector = {
46
+ current: null,
47
+ spans: []
48
+ };
49
+ this.global.__e2eTimings = this.collector;
50
+ // Records to flush as JSONL on teardown. One per test plus one suite-scoped record.
51
+ this.records = [];
52
+ this.recordsByName = new Map();
53
+ // The suite-scoped record (beforeAll/afterAll); bodyMs/totalMs are computed at flush time.
54
+ this.suiteRecord = {
55
+ name: null,
56
+ status: 'passed',
57
+ beforeHooksMs: 0,
58
+ afterHooksMs: 0
59
+ };
60
+ // Start times keyed by hook type (beforeAll/beforeEach/afterAll/afterEach).
61
+ this.hookStarts = {};
62
+ this.testStarts = new Map();
63
+ // Guards against double-flushing (we flush on both the teardown event and the teardown method).
64
+ this.flushed = false;
65
+ // Raw per-occurrence spans retained only when TEST_TIMING_SPANS=1, emitted as `type:"span"` lines.
66
+ this.rawSpans = [];
67
+ }
68
+ // Flush on the teardown method too: the jest lifecycle always calls this, whereas the 'teardown'
69
+ // event is not reliably delivered when a test run is interrupted. Whichever fires first wins.
70
+ async teardown() {
71
+ this.finalizeAndFlush();
72
+ await super.teardown();
73
+ }
74
+ async handleTestEvent(event, state) {
75
+ // Run the base env first so its unhandledRejection patching for after-hooks stays intact.
76
+ await super.handleTestEvent(event, state);
77
+ if (!this.timingFile) {
78
+ return;
79
+ }
80
+ const now = Date.now();
81
+ switch(event.name){
82
+ case 'hook_start':
83
+ {
84
+ this.hookStarts[event.hook.type] = now;
85
+ break;
86
+ }
87
+ case 'hook_success':
88
+ case 'hook_failure':
89
+ {
90
+ const start = this.hookStarts[event.hook.type];
91
+ if (start === undefined) {
92
+ break;
93
+ }
94
+ delete this.hookStarts[event.hook.type];
95
+ const ms = now - start;
96
+ if (event.hook.type === 'beforeEach') {
97
+ this.addToCurrent('beforeHooksMs', ms);
98
+ } else if (event.hook.type === 'afterEach') {
99
+ this.addToCurrent('afterHooksMs', ms);
100
+ } else if (event.hook.type === 'beforeAll') {
101
+ this.suiteRecord.beforeHooksMs += ms;
102
+ } else if (event.hook.type === 'afterAll') {
103
+ this.suiteRecord.afterHooksMs += ms;
104
+ }
105
+ break;
106
+ }
107
+ case 'test_start':
108
+ {
109
+ const name = this.fullTestName(event.test);
110
+ const record = {
111
+ type: 'test',
112
+ name,
113
+ status: 'passed',
114
+ setupFnMs: 0,
115
+ beforeHooksMs: 0,
116
+ bodyMs: 0,
117
+ teardownFnMs: 0,
118
+ afterHooksMs: 0,
119
+ totalMs: 0,
120
+ startedAt: new Date(now).toISOString()
121
+ };
122
+ this.records.push(record);
123
+ this.recordsByName.set(name, record);
124
+ this.testStarts.set(name, now);
125
+ this.collector.current = name;
126
+ break;
127
+ }
128
+ case 'test_fn_start':
129
+ {
130
+ this.testStarts.set(`fn:${this.fullTestName(event.test)}`, now);
131
+ break;
132
+ }
133
+ case 'test_fn_success':
134
+ case 'test_fn_failure':
135
+ {
136
+ const name = this.fullTestName(event.test);
137
+ const start = this.testStarts.get(`fn:${name}`);
138
+ const record = this.recordsByName.get(name);
139
+ if (record && start !== undefined) {
140
+ record.bodyMs = now - start;
141
+ }
142
+ if (record && event.name === 'test_fn_failure') {
143
+ record.status = 'failed';
144
+ }
145
+ break;
146
+ }
147
+ case 'test_done':
148
+ {
149
+ const name = this.fullTestName(event.test);
150
+ const record = this.recordsByName.get(name);
151
+ const start = this.testStarts.get(name);
152
+ if (record && start !== undefined) {
153
+ record.totalMs = now - start;
154
+ }
155
+ if (record && event.test?.errors?.length) {
156
+ record.status = 'failed';
157
+ }
158
+ this.collector.current = null;
159
+ break;
160
+ }
161
+ case 'teardown':
162
+ {
163
+ this.finalizeAndFlush();
164
+ break;
165
+ }
166
+ default:
167
+ break;
168
+ }
169
+ }
170
+ /** The record for the test currently running, if any. */ currentRecord() {
171
+ return this.collector.current ? this.recordsByName.get(this.collector.current) : undefined;
172
+ }
173
+ /** Adds `ms` to a hook bucket on the current per-test record, or the suite record during beforeAll/afterAll. */ addToCurrent(field, ms) {
174
+ const record = this.currentRecord();
175
+ if (record) {
176
+ record[field] += ms;
177
+ }
178
+ }
179
+ /** Builds the full test name by walking up the describe blocks, matching jest's currentTestName. */ fullTestName(test) {
180
+ if (!test) {
181
+ return null;
182
+ }
183
+ const parts = [];
184
+ let node = test;
185
+ while(node && node.name && node.name !== 'ROOT_DESCRIBE_BLOCK'){
186
+ parts.unshift(node.name);
187
+ node = node.parent;
188
+ }
189
+ return parts.join(' ');
190
+ }
191
+ /** Folds the collected spans into the per-test / suite records via {@link foldSpansInto}, then drains the collector. */ foldSpans() {
192
+ const rawSpans = foldSpansInto(this.collector.spans, {
193
+ recordsByName: this.recordsByName,
194
+ suiteRecord: this.suiteRecord,
195
+ emitSpanLines: this.emitSpanLines
196
+ });
197
+ this.rawSpans.push(...rawSpans);
198
+ this.collector.spans = [];
199
+ }
200
+ /** Folds spans into records, finalizes the suite-scoped record, and writes all JSONL. */ finalizeAndFlush() {
201
+ if (this.flushed || !this.timingFile) {
202
+ return;
203
+ }
204
+ this.flushed = true;
205
+ this.foldSpans();
206
+ const lines = [];
207
+ for (const record of this.records){
208
+ lines.push(this.toLine({
209
+ ...record
210
+ }));
211
+ }
212
+ lines.push(this.toLine({
213
+ type: 'suite',
214
+ name: null,
215
+ status: 'passed',
216
+ setupFnMs: this.suiteRecord.setupFnMs ?? 0,
217
+ beforeHooksMs: this.suiteRecord.beforeHooksMs,
218
+ teardownFnMs: this.suiteRecord.teardownFnMs ?? 0,
219
+ afterHooksMs: this.suiteRecord.afterHooksMs,
220
+ totalMs: this.suiteRecord.beforeHooksMs + this.suiteRecord.afterHooksMs,
221
+ spans: this.suiteRecord.spans
222
+ }));
223
+ for (const raw of this.rawSpans){
224
+ lines.push(this.toLine({
225
+ type: 'span',
226
+ name: raw.owner,
227
+ span: raw.name,
228
+ ms: raw.ms
229
+ }));
230
+ }
231
+ const payload = lines.join('\n') + '\n';
232
+ try {
233
+ // One file per worker process, but a worker may run several suites: append so we keep them all.
234
+ appendFileSync(this.timingFile, payload);
235
+ } catch {
236
+ try {
237
+ writeFileSync(this.timingFile, payload);
238
+ } catch {
239
+ // Timing is best-effort; never fail a test because we couldn't write the file.
240
+ }
241
+ }
242
+ }
243
+ /** Flattens metadata onto a record and serializes to a single JSON line, rounding all Ms fields. */ toLine(record) {
244
+ const obj = {
245
+ suite: this.suite,
246
+ ...record,
247
+ ...this.meta
248
+ };
249
+ for (const key of Object.keys(obj)){
250
+ if (key.endsWith('Ms') && typeof obj[key] === 'number') {
251
+ obj[key] = Math.round(obj[key]);
252
+ }
253
+ }
254
+ // Round the nested span aggregates' Ms fields too (totalMs/busyMs/maxMs per tag).
255
+ if (obj.spans && typeof obj.spans === 'object') {
256
+ for (const agg of Object.values(obj.spans)){
257
+ for (const key of Object.keys(agg)){
258
+ if (key.endsWith('Ms') && typeof agg[key] === 'number') {
259
+ agg[key] = Math.round(agg[key]);
260
+ }
261
+ }
262
+ }
263
+ }
264
+ return JSON.stringify(obj);
265
+ }
266
+ }
267
+ /**
268
+ * Aggregates a list of `{ start, end }` spans of one tag into `{ count, totalMs, busyMs, maxMs }`.
269
+ * `totalMs` is the naive sum of per-occurrence durations (correct for serial repeats); `busyMs` is
270
+ * the duration of the union of the `[start, end)` intervals (concurrency-correct — N concurrent
271
+ * spans collapse to their wall-clock span instead of summing to ~N×); `maxMs` is the longest single
272
+ * occurrence. All durations are on the shared process-wide `performance.now()` clock. Does not mutate
273
+ * the input array.
274
+ */ export function aggregateSpans(spans) {
275
+ let totalMs = 0;
276
+ let maxMs = 0;
277
+ for (const span of spans){
278
+ const ms = span.end - span.start;
279
+ totalMs += ms;
280
+ if (ms > maxMs) {
281
+ maxMs = ms;
282
+ }
283
+ }
284
+ // busyMs: sort by start and merge overlapping intervals, summing the merged lengths.
285
+ const sorted = [
286
+ ...spans
287
+ ].sort((a, b)=>a.start - b.start);
288
+ let busyMs = 0;
289
+ let mergeStart = null;
290
+ let mergeEnd = null;
291
+ for (const span of sorted){
292
+ if (mergeStart === null) {
293
+ mergeStart = span.start;
294
+ mergeEnd = span.end;
295
+ } else if (span.start <= mergeEnd) {
296
+ if (span.end > mergeEnd) {
297
+ mergeEnd = span.end;
298
+ }
299
+ } else {
300
+ busyMs += mergeEnd - mergeStart;
301
+ mergeStart = span.start;
302
+ mergeEnd = span.end;
303
+ }
304
+ }
305
+ if (mergeStart !== null) {
306
+ busyMs += mergeEnd - mergeStart;
307
+ }
308
+ return {
309
+ count: spans.length,
310
+ totalMs,
311
+ busyMs,
312
+ maxMs
313
+ };
314
+ }
315
+ /**
316
+ * Groups `spans` by owner, then by tag, and attaches a `spans` map of aggregates to the matching
317
+ * per-test record (looked up in `recordsByName`) or, for `null`-owner spans, to `suiteRecord`. Also
318
+ * derives the back-compat `setupFnMs` / `teardownFnMs` fields from the `setup:env:<mode>` /
319
+ * `teardown:env` aggregates (additive over any pre-existing value). Spans whose owner matches no
320
+ * record (e.g. the pinned `other:mempool-feeder` owner) are dropped. Returns the raw per-occurrence
321
+ * list (`{ owner, name, ms }`), which is empty unless `emitSpanLines` is set.
322
+ */ export function foldSpansInto(spans, { recordsByName, suiteRecord, emitSpanLines = false }) {
323
+ const rawSpans = [];
324
+ // Group by owner (null owner → suite record), then by tag.
325
+ const byOwner = new Map();
326
+ for (const span of spans){
327
+ const owner = span.owner ?? null;
328
+ let byName = byOwner.get(owner);
329
+ if (!byName) {
330
+ byName = new Map();
331
+ byOwner.set(owner, byName);
332
+ }
333
+ let list = byName.get(span.name);
334
+ if (!list) {
335
+ list = [];
336
+ byName.set(span.name, list);
337
+ }
338
+ list.push(span);
339
+ if (emitSpanLines) {
340
+ rawSpans.push({
341
+ owner,
342
+ name: span.name,
343
+ ms: span.end - span.start
344
+ });
345
+ }
346
+ }
347
+ for (const [owner, byName] of byOwner){
348
+ const record = owner === null ? suiteRecord : recordsByName.get(owner);
349
+ if (!record) {
350
+ continue;
351
+ }
352
+ const aggregates = {};
353
+ for (const [name, list] of byName){
354
+ aggregates[name] = aggregateSpans(list);
355
+ }
356
+ record.spans = aggregates;
357
+ // Back-compat: the legacy fn-span buckets are derived from the top-level env setup/teardown tags.
358
+ // The top-level setup is tagged `setup:env:<proverMode>` (the mode is a closed set, distinct from
359
+ // the `:anvil`/`:l1-deploy`/... sub-phase tags), so sum those three exact tags.
360
+ const setupFnMs = (aggregates['setup:env:none']?.totalMs ?? 0) + (aggregates['setup:env:fake']?.totalMs ?? 0) + (aggregates['setup:env:real']?.totalMs ?? 0);
361
+ record.setupFnMs = setupFnMs + (record.setupFnMs ?? 0);
362
+ record.teardownFnMs = (aggregates['teardown:env']?.totalMs ?? 0) + (record.teardownFnMs ?? 0);
363
+ }
364
+ return rawSpans;
365
+ }
@@ -6,5 +6,5 @@ import { retryUntil } from '@aztec/foundation/retry';
6
6
  * the message has been picked up from L1. Use this in tests that explicitly produce L2
7
7
  * blocks afterwards to make the message consumable.
8
8
  */ export function waitForL1ToL2MessageSeen(node, l1ToL2MessageHash, opts) {
9
- return retryUntil(async ()=>await node.getL1ToL2MessageCheckpoint(l1ToL2MessageHash) !== undefined, `L1 to L2 message ${l1ToL2MessageHash.toString()} seen`, opts.timeoutSeconds, 1);
9
+ return retryUntil(async ()=>await node.getL1ToL2MessageCheckpoint(l1ToL2MessageHash) !== undefined, `L1 to L2 message ${l1ToL2MessageHash.toString()} seen`, opts.timeoutSeconds, 0.25);
10
10
  }
@@ -172,7 +172,7 @@ const computeMultiplier = (rate, dt)=>{
172
172
  expect(asset['last_updated_ts']).toEqual(BigInt(this.time));
173
173
  for (const key of [
174
174
  this.account.address,
175
- AztecAddress.fromField(await this.account.key())
175
+ AztecAddress.fromFieldUnsafe(await this.account.key())
176
176
  ]){
177
177
  const { result: privatePos } = await this.lendingContract.methods.get_position(key).simulate({
178
178
  from: this.account.address
@@ -0,0 +1,75 @@
1
+ import type { AztecNodeConfig } from '@aztec/aztec-node';
2
+ import { AztecAddress, EthAddress } from '@aztec/aztec.js/addresses';
3
+ import type { AztecNode } from '@aztec/aztec.js/node';
4
+ import type { TxReceipt } from '@aztec/aztec.js/tx';
5
+ import { CheatCodes, EpochTestSettler } from '@aztec/aztec/testing';
6
+ import { InboxContract, OutboxContract } from '@aztec/ethereum/contracts';
7
+ import type { DeployAztecL1ContractsArgs, DeployAztecL1ContractsReturnType } from '@aztec/ethereum/deploy-aztec-l1-contracts';
8
+ import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
9
+ import { EpochNumber } from '@aztec/foundation/branded-types';
10
+ import { TokenContract } from '@aztec/noir-contracts.js/Token';
11
+ import { TokenBridgeContract } from '@aztec/noir-contracts.js/TokenBridge';
12
+ import type { PXEConfig } from '@aztec/pxe/server';
13
+ import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
14
+ import { type SetupOptions } from '../../fixtures/setup.js';
15
+ import { CrossChainTestHarness } from '../../shared/cross_chain_test_harness.js';
16
+ import type { TestWallet } from '../../test-wallet/test_wallet.js';
17
+ import { SingleNodeTestContext, type SingleNodeTestOpts } from '../single_node_test_context.js';
18
+ /** Optional configuration for {@link CrossChainMessagingTest}. */
19
+ export type CrossChainMessagingTestOpts = {
20
+ /** Mnemonic account index for the harness L1 client (token portal, inbox, minting). Defaults to the first account. */
21
+ l1HarnessAccountIndex?: number;
22
+ /** Whether to deploy the L1/L2 token bridge. Set to false for suites that only pass arbitrary messages. Defaults to true. */
23
+ deployTokenBridge?: boolean;
24
+ };
25
+ /**
26
+ * The cross-chain-messaging harness over the single-node topology: extends {@link SingleNodeTestContext}
27
+ * so it reuses the base node tracking / chain monitor / teardown machinery, but builds its environment
28
+ * with the bespoke cross-chain opts below (optional prover node, sponsored-FPC funding, a generous
29
+ * prover tx-gathering window for the epoch warps) rather than the base's default node config, and owns
30
+ * the {@link CrossChainTestHarness} domain object plus the L1 inbox/outbox handles.
31
+ */
32
+ export declare class CrossChainMessagingTest extends SingleNodeTestContext {
33
+ private requireEpochProven;
34
+ private setupOptions;
35
+ private deployL1ContractsArgs;
36
+ private pxeOpts;
37
+ private l1HarnessAccountIndex?;
38
+ private deployTokenBridge;
39
+ /** L1 token portal + ERC20 deployed before the node started (under automine) by the setup hook. */
40
+ private preDeployedCrossChainL1?;
41
+ private testName;
42
+ aztecNode: AztecNode;
43
+ aztecNodeConfig: AztecNodeConfig;
44
+ aztecNodeAdmin: AztecNodeAdmin;
45
+ wallet: TestWallet;
46
+ ownerAddress: AztecAddress;
47
+ user1Address: AztecAddress;
48
+ user2Address: AztecAddress;
49
+ crossChainTestHarness: CrossChainTestHarness;
50
+ ethAccount: EthAddress;
51
+ /** L1 client used for cross-chain L1 interactions (token portal, inbox), tied to `l1HarnessAccountIndex`. */
52
+ harnessL1Client: ExtendedViemWalletClient;
53
+ l2Token: TokenContract;
54
+ l2Bridge: TokenBridgeContract;
55
+ inbox: InboxContract;
56
+ outbox: OutboxContract;
57
+ cheatCodes: CheatCodes;
58
+ /**
59
+ * Background loop that marks each completed epoch as proven on L1. Started in `applyBaseSetup`
60
+ * when the test runs without a real prover node, because the e2e fixture uses L1 interval mining
61
+ * and nothing marks blocks proven automatically. Without this, L1's `aztecProofSubmissionEpochs`
62
+ * window expires mid-test and triggers a chain prune that drops in-flight wallet txs. Tests that
63
+ * intentionally pause proving (e.g. inbox drift tests) can stop it via
64
+ * `await t.epochTestSettler?.stop()`.
65
+ */
66
+ epochTestSettler?: EpochTestSettler;
67
+ deployL1ContractsValues: DeployAztecL1ContractsReturnType;
68
+ constructor(testName: string, opts?: SetupOptions, deployL1ContractsArgs?: Partial<DeployAztecL1ContractsArgs>, pxeOpts?: Partial<PXEConfig>, crossChainOpts?: CrossChainMessagingTestOpts);
69
+ setup(opts?: SingleNodeTestOpts, pxeOpts?: Partial<PXEConfig>): Promise<void>;
70
+ advanceToEpochProven(l2TxReceipt: TxReceipt): Promise<EpochNumber>;
71
+ catchUpProvenChain(): Promise<void>;
72
+ teardown(): Promise<void>;
73
+ applyBaseSetup(): Promise<void>;
74
+ }
75
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3Jvc3NfY2hhaW5fbWVzc2FnaW5nX3Rlc3QuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zaW5nbGUtbm9kZS9jcm9zcy1jaGFpbi9jcm9zc19jaGFpbl9tZXNzYWdpbmdfdGVzdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxlQUFlLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUN6RCxPQUFPLEVBQUUsWUFBWSxFQUFFLFVBQVUsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBR3JFLE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQ3RELE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBQ3BELE9BQU8sRUFBRSxVQUFVLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUVwRSxPQUFPLEVBQUUsYUFBYSxFQUFFLGNBQWMsRUFBa0IsTUFBTSwyQkFBMkIsQ0FBQztBQUMxRixPQUFPLEtBQUssRUFDViwwQkFBMEIsRUFDMUIsZ0NBQWdDLEVBQ2pDLE1BQU0sMkNBQTJDLENBQU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AC;IAExB;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC,uBAAuB,EAAG,gCAAgC,CAAC;IAE3D,YACE,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,YAAiB,EACvB,qBAAqB,GAAE,OAAO,CAAC,0BAA0B,CAAM,EAC/D,OAAO,GAAE,OAAO,CAAC,SAAS,CAAM,EAChC,cAAc,GAAE,2BAAgC,EAcjD;IAEc,KAAK,CAAC,IAAI,GAAE,kBAAuB,EAAE,OAAO,GAAE,OAAO,CAAC,SAAS,CAAM,iBA4DnF;IAEK,oBAAoB,CAAC,WAAW,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAgBvE;IAEK,kBAAkB,kBAKvB;IAEc,QAAQ,kBAGtB;IAEK,cAAc,kBAiGnB;CACF"}
@@ -9,33 +9,42 @@ import { pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
9
9
  import { EpochNumber } from '@aztec/foundation/branded-types';
10
10
  import { retryUntil } from '@aztec/foundation/retry';
11
11
  import { sleep } from '@aztec/foundation/sleep';
12
- import { TestERC20Abi, TestERC20Bytecode } from '@aztec/l1-artifacts';
12
+ import { TestERC20Abi, TestERC20Bytecode, TokenPortalAbi, TokenPortalBytecode } from '@aztec/l1-artifacts';
13
13
  import { TokenContract } from '@aztec/noir-contracts.js/Token';
14
14
  import { TokenBridgeContract } from '@aztec/noir-contracts.js/TokenBridge';
15
15
  import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
16
- import { MNEMONIC } from '../fixtures/fixtures.js';
17
- import { ensureAuthRegistryPublished, setup, teardown } from '../fixtures/setup.js';
18
- import { CrossChainTestHarness } from '../shared/cross_chain_test_harness.js';
19
- export class CrossChainMessagingTest {
16
+ import { mnemonicToAccount } from 'viem/accounts';
17
+ import { MNEMONIC } from '../../fixtures/fixtures.js';
18
+ import { ensureAuthRegistryPublished, setup } from '../../fixtures/setup.js';
19
+ import { CrossChainTestHarness } from '../../shared/cross_chain_test_harness.js';
20
+ import { SingleNodeTestContext } from '../single_node_test_context.js';
21
+ /**
22
+ * The cross-chain-messaging harness over the single-node topology: extends {@link SingleNodeTestContext}
23
+ * so it reuses the base node tracking / chain monitor / teardown machinery, but builds its environment
24
+ * with the bespoke cross-chain opts below (optional prover node, sponsored-FPC funding, a generous
25
+ * prover tx-gathering window for the epoch warps) rather than the base's default node config, and owns
26
+ * the {@link CrossChainTestHarness} domain object plus the L1 inbox/outbox handles.
27
+ */ export class CrossChainMessagingTest extends SingleNodeTestContext {
20
28
  requireEpochProven;
21
29
  setupOptions;
22
30
  deployL1ContractsArgs;
23
31
  pxeOpts;
24
- logger;
25
- context;
32
+ l1HarnessAccountIndex;
33
+ deployTokenBridge;
34
+ /** L1 token portal + ERC20 deployed before the node started (under automine) by the setup hook. */ preDeployedCrossChainL1;
35
+ testName;
26
36
  aztecNode;
27
37
  aztecNodeConfig;
28
38
  aztecNodeAdmin;
29
- l1Client;
30
39
  wallet;
31
40
  ownerAddress;
32
41
  user1Address;
33
42
  user2Address;
34
43
  crossChainTestHarness;
35
44
  ethAccount;
45
+ /** L1 client used for cross-chain L1 interactions (token portal, inbox), tied to `l1HarnessAccountIndex`. */ harnessL1Client;
36
46
  l2Token;
37
47
  l2Bridge;
38
- rollup;
39
48
  inbox;
40
49
  outbox;
41
50
  cheatCodes;
@@ -48,7 +57,9 @@ export class CrossChainMessagingTest {
48
57
  * `await t.epochTestSettler?.stop()`.
49
58
  */ epochTestSettler;
50
59
  deployL1ContractsValues;
51
- constructor(testName, opts = {}, deployL1ContractsArgs = {}, pxeOpts = {}){
60
+ constructor(testName, opts = {}, deployL1ContractsArgs = {}, pxeOpts = {}, crossChainOpts = {}){
61
+ super();
62
+ this.testName = testName;
52
63
  this.logger = createLogger(`e2e:e2e_cross_chain_messaging:${testName}`);
53
64
  this.setupOptions = opts;
54
65
  this.deployL1ContractsArgs = {
@@ -56,13 +67,15 @@ export class CrossChainMessagingTest {
56
67
  ...deployL1ContractsArgs
57
68
  };
58
69
  this.pxeOpts = pxeOpts;
70
+ this.l1HarnessAccountIndex = crossChainOpts.l1HarnessAccountIndex;
71
+ this.deployTokenBridge = crossChainOpts.deployTokenBridge ?? true;
59
72
  this.requireEpochProven = opts.startProverNode ?? false;
60
73
  }
61
74
  async setup(opts = {}, pxeOpts = {}) {
62
75
  this.logger.info('Setting up cross chain messaging test');
63
76
  // Recompute requireEpochProven from the merged options so per-call startProverNode is honored.
64
77
  this.requireEpochProven = opts.startProverNode ?? this.setupOptions.startProverNode ?? false;
65
- this.context = await setup(3, {
78
+ const context = await setup(3, {
66
79
  ...this.setupOptions,
67
80
  ...opts,
68
81
  fundSponsoredFPC: true,
@@ -78,11 +91,39 @@ export class CrossChainMessagingTest {
78
91
  ...this.setupOptions.proverNodeConfig,
79
92
  ...opts.proverNodeConfig,
80
93
  txGatheringTimeoutMs: opts.proverNodeConfig?.txGatheringTimeoutMs ?? 10 * 60 * 1000
81
- }
94
+ },
95
+ // Deploy the cross-chain token portal + ERC20 before the node starts, while anvil is still
96
+ // automining, instead of paying the L1 block interval for them once the sequencer is live.
97
+ deployExtraL1Contracts: this.deployTokenBridge ? async ({ l1Client, logger })=>{
98
+ // The harness mints the underlying ERC20 from `l1HarnessAccountIndex` and `TestERC20.mint`
99
+ // is onlyMinter, so its owner/initial-minter must be that account even though setup's
100
+ // publisher client sends the deploy tx.
101
+ const harnessAddress = mnemonicToAccount(MNEMONIC, {
102
+ addressIndex: this.l1HarnessAccountIndex ?? 0
103
+ }).address;
104
+ const { address: underlyingERC20Address } = await deployL1Contract(l1Client, TestERC20Abi, TestERC20Bytecode, [
105
+ 'Underlying',
106
+ 'UND',
107
+ harnessAddress
108
+ ]);
109
+ // The TokenPortal's initialize is permissionless, so it can be deployed by the publisher.
110
+ const { address: tokenPortalAddress } = await deployL1Contract(l1Client, TokenPortalAbi, TokenPortalBytecode);
111
+ this.preDeployedCrossChainL1 = {
112
+ underlyingERC20Address,
113
+ tokenPortalAddress
114
+ };
115
+ logger.verbose(`Pre-deployed cross-chain L1 ERC20 ${underlyingERC20Address} and portal ${tokenPortalAddress}`);
116
+ return this.preDeployedCrossChainL1;
117
+ } : undefined
82
118
  }, {
83
119
  ...this.pxeOpts,
84
120
  ...pxeOpts
85
121
  });
122
+ // Reuse the base context machinery (rollup, epoch cache, chain monitor, node tracking, teardown)
123
+ // over the environment built above. Restore the CrossChainMessagingTest-named logger afterwards,
124
+ // since hydrateFromContext repoints `this.logger` at the context logger.
125
+ await this.hydrateFromContext(context);
126
+ this.logger = createLogger(`e2e:e2e_cross_chain_messaging:${this.testName}`);
86
127
  await this.applyBaseSetup();
87
128
  }
88
129
  async advanceToEpochProven(l2TxReceipt) {
@@ -109,7 +150,7 @@ export class CrossChainMessagingTest {
109
150
  }
110
151
  async teardown() {
111
152
  await this.epochTestSettler?.stop();
112
- await teardown(this.context);
153
+ await super.teardown();
113
154
  }
114
155
  async applyBaseSetup() {
115
156
  // Set up base context fields
@@ -133,14 +174,29 @@ export class CrossChainMessagingTest {
133
174
  // Set up cross chain messaging
134
175
  this.logger.info('Applying e2e_cross_chain_messaging setup');
135
176
  await ensureAuthRegistryPublished(this.wallet, this.ownerAddress);
136
- this.l1Client = createExtendedL1Client(this.aztecNodeConfig.l1RpcUrls, MNEMONIC);
137
- const underlyingERC20Address = await deployL1Contract(this.l1Client, TestERC20Abi, TestERC20Bytecode, [
138
- 'Underlying',
139
- 'UND',
140
- this.l1Client.account.address
141
- ]).then(({ address })=>address);
177
+ const harnessL1Client = createExtendedL1Client(this.aztecNodeConfig.l1RpcUrls, MNEMONIC, undefined, undefined, this.l1HarnessAccountIndex);
178
+ this.harnessL1Client = harnessL1Client;
179
+ this.ethAccount = EthAddress.fromString((await harnessL1Client.getAddresses())[0]);
180
+ // L1 contract handles every cross-chain test needs, independent of the token bridge.
181
+ const l1Client = createExtendedL1Client(this.aztecNodeConfig.l1RpcUrls, MNEMONIC);
182
+ this.l1Client = l1Client;
183
+ const l1Contracts = pickL1ContractAddresses(this.aztecNodeConfig);
184
+ this.rollup = new RollupContract(l1Client, l1Contracts.rollupAddress.toString());
185
+ this.inbox = new InboxContract(l1Client, l1Contracts.inboxAddress.toString());
186
+ this.outbox = new OutboxContract(l1Client, l1Contracts.outboxAddress.toString());
187
+ // Tests that only pass arbitrary L1<->L2 messages (not token bridging) never touch the L2 token,
188
+ // bridge, or portal. Skip the token+portal+bridge deploy (an L1 ERC20, an L1 portal, and two L2
189
+ // contract deploys plus their init txs) entirely for them.
190
+ if (!this.deployTokenBridge) {
191
+ this.logger.info('Skipping token bridge deploy; test only needs L1 handles and ethAccount');
192
+ return;
193
+ }
194
+ // The ERC20 and token portal were deployed before the node started (under automine) by the
195
+ // `deployExtraL1Contracts` setup hook above; the harness reuses them and only deploys the L2 token,
196
+ // L2 bridge, and the portal init that need the running node.
197
+ const { underlyingERC20Address, tokenPortalAddress: predeployedTokenPortalAddress } = this.preDeployedCrossChainL1;
142
198
  this.logger.verbose(`Setting up cross chain harness...`);
143
- this.crossChainTestHarness = await CrossChainTestHarness.new(this.aztecNode, this.l1Client, this.wallet, this.ownerAddress, this.logger, underlyingERC20Address);
199
+ this.crossChainTestHarness = await CrossChainTestHarness.new(this.aztecNode, harnessL1Client, this.wallet, this.ownerAddress, this.logger, underlyingERC20Address, predeployedTokenPortalAddress);
144
200
  this.logger.verbose(`L2 token deployed to: ${this.crossChainTestHarness.l2Token.address}`);
145
201
  const crossChainContext = this.crossChainTestHarness.toCrossChainContext();
146
202
  this.l2Token = TokenContract.at(crossChainContext.l2Token, this.wallet);
@@ -148,12 +204,6 @@ export class CrossChainMessagingTest {
148
204
  // There is an issue with the reviver so we are getting strings sometimes. Working around it here.
149
205
  this.ethAccount = EthAddress.fromString(crossChainContext.ethAccount.toString());
150
206
  const tokenPortalAddress = EthAddress.fromString(crossChainContext.tokenPortal.toString());
151
- const l1Client = createExtendedL1Client(this.aztecNodeConfig.l1RpcUrls, MNEMONIC);
152
- this.l1Client = l1Client;
153
- const l1Contracts = pickL1ContractAddresses(this.aztecNodeConfig);
154
- this.rollup = new RollupContract(l1Client, l1Contracts.rollupAddress.toString());
155
- this.inbox = new InboxContract(l1Client, l1Contracts.inboxAddress.toString());
156
- this.outbox = new OutboxContract(l1Client, l1Contracts.outboxAddress.toString());
157
- this.crossChainTestHarness = new CrossChainTestHarness(this.aztecNode, this.logger, this.l2Token, this.l2Bridge, this.ethAccount, tokenPortalAddress, crossChainContext.underlying, l1Client, pickL1ContractAddresses(this.aztecNodeConfig), this.wallet, this.ownerAddress);
207
+ this.crossChainTestHarness = new CrossChainTestHarness(this.aztecNode, this.logger, this.l2Token, this.l2Bridge, this.ethAccount, tokenPortalAddress, crossChainContext.underlying, harnessL1Client, pickL1ContractAddresses(this.aztecNodeConfig), this.wallet, this.ownerAddress);
158
208
  }
159
209
  }