@aztec/end-to-end 5.0.0-rc.2 → 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 (246) 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 +1 -1
  28. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  29. package/dest/bench/client_flows/client_flows_benchmark.js +16 -4
  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 +30 -11
  39. package/dest/fixtures/fixtures.d.ts +7 -5
  40. package/dest/fixtures/fixtures.d.ts.map +1 -1
  41. package/dest/fixtures/fixtures.js +6 -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 +32 -8
  49. package/dest/fixtures/setup.d.ts.map +1 -1
  50. package/dest/fixtures/setup.js +165 -160
  51. package/dest/fixtures/standard_contracts_genesis.d.ts +16 -0
  52. package/dest/fixtures/standard_contracts_genesis.d.ts.map +1 -0
  53. package/dest/fixtures/standard_contracts_genesis.js +25 -0
  54. package/dest/fixtures/timing.d.ts +42 -0
  55. package/dest/fixtures/timing.d.ts.map +1 -0
  56. package/dest/fixtures/timing.js +72 -0
  57. package/dest/fixtures/wait_helpers.d.ts +135 -0
  58. package/dest/fixtures/wait_helpers.d.ts.map +1 -0
  59. package/dest/fixtures/wait_helpers.js +154 -0
  60. package/dest/forward-compatibility/wallet_service.js +1 -1
  61. package/dest/multi-node/block-production/setup.d.ts +97 -0
  62. package/dest/multi-node/block-production/setup.d.ts.map +1 -0
  63. package/dest/multi-node/block-production/setup.js +158 -0
  64. package/dest/multi-node/governance/setup.d.ts +67 -0
  65. package/dest/multi-node/governance/setup.d.ts.map +1 -0
  66. package/dest/multi-node/governance/setup.js +126 -0
  67. package/dest/multi-node/multi_node_test_context.d.ts +212 -0
  68. package/dest/multi-node/multi_node_test_context.d.ts.map +1 -0
  69. package/dest/multi-node/multi_node_test_context.js +347 -0
  70. package/dest/multi-node/slashing/inactivity_setup.d.ts +27 -0
  71. package/dest/multi-node/slashing/inactivity_setup.d.ts.map +1 -0
  72. package/dest/multi-node/slashing/inactivity_setup.js +111 -0
  73. package/dest/multi-node/slashing/setup.d.ts +167 -0
  74. package/dest/multi-node/slashing/setup.d.ts.map +1 -0
  75. package/dest/multi-node/slashing/setup.js +275 -0
  76. package/dest/{e2e_p2p → p2p}/p2p_network.d.ts +9 -1
  77. package/dest/p2p/p2p_network.d.ts.map +1 -0
  78. package/dest/{e2e_p2p → p2p}/p2p_network.js +26 -1
  79. package/dest/p2p/reqresp/utils.d.ts +19 -0
  80. package/dest/p2p/reqresp/utils.d.ts.map +1 -0
  81. package/dest/{e2e_p2p → p2p}/reqresp/utils.js +4 -15
  82. package/dest/p2p/shared.d.ts +72 -0
  83. package/dest/p2p/shared.d.ts.map +1 -0
  84. package/dest/p2p/shared.js +212 -0
  85. package/dest/shared/cross_chain_test_harness.d.ts +3 -3
  86. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  87. package/dest/shared/cross_chain_test_harness.js +24 -16
  88. package/dest/shared/gas_portal_test_harness.d.ts +1 -1
  89. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  90. package/dest/shared/gas_portal_test_harness.js +8 -5
  91. package/dest/shared/submit-transactions.d.ts +1 -1
  92. package/dest/shared/submit-transactions.d.ts.map +1 -1
  93. package/dest/shared/submit-transactions.js +12 -5
  94. package/dest/shared/timing_env.d.js +5 -0
  95. package/dest/shared/timing_env.js +158 -47
  96. package/dest/shared/wait_for_l1_to_l2_message.js +1 -1
  97. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts +75 -0
  98. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts.map +1 -0
  99. package/dest/{e2e_cross_chain_messaging → single-node/cross-chain}/cross_chain_messaging_test.js +74 -26
  100. package/dest/single-node/cross-chain/message_test_helpers.d.ts +38 -0
  101. package/dest/single-node/cross-chain/message_test_helpers.d.ts.map +1 -0
  102. package/dest/single-node/cross-chain/message_test_helpers.js +70 -0
  103. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.d.ts +1 -1
  104. package/dest/single-node/fees/bridging_race.notest.d.ts.map +1 -0
  105. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.js +9 -6
  106. package/dest/single-node/fees/fees_test.d.ts +95 -0
  107. package/dest/single-node/fees/fees_test.d.ts.map +1 -0
  108. package/dest/{e2e_fees → single-node/fees}/fees_test.js +121 -45
  109. package/dest/single-node/l1-reorgs/setup.d.ts +42 -0
  110. package/dest/single-node/l1-reorgs/setup.d.ts.map +1 -0
  111. package/dest/single-node/l1-reorgs/setup.js +57 -0
  112. package/dest/single-node/partial-proofs/setup.d.ts +5 -0
  113. package/dest/single-node/partial-proofs/setup.d.ts.map +1 -0
  114. package/dest/single-node/partial-proofs/setup.js +5 -0
  115. package/dest/single-node/proving/setup.d.ts +5 -0
  116. package/dest/single-node/proving/setup.d.ts.map +1 -0
  117. package/dest/single-node/proving/setup.js +5 -0
  118. package/dest/single-node/recovery/setup.d.ts +5 -0
  119. package/dest/single-node/recovery/setup.d.ts.map +1 -0
  120. package/dest/single-node/recovery/setup.js +5 -0
  121. package/dest/single-node/setup.d.ts +49 -0
  122. package/dest/single-node/setup.d.ts.map +1 -0
  123. package/dest/single-node/setup.js +56 -0
  124. package/dest/single-node/single_node_test_context.d.ts +373 -0
  125. package/dest/single-node/single_node_test_context.d.ts.map +1 -0
  126. package/dest/single-node/single_node_test_context.js +845 -0
  127. package/dest/spartan/setup_test_wallets.d.ts +1 -1
  128. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  129. package/dest/spartan/setup_test_wallets.js +13 -7
  130. package/dest/spartan/tx_metrics.d.ts +10 -1
  131. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  132. package/dest/spartan/tx_metrics.js +32 -0
  133. package/dest/test-wallet/test_wallet.d.ts +23 -4
  134. package/dest/test-wallet/test_wallet.d.ts.map +1 -1
  135. package/dest/test-wallet/test_wallet.js +20 -4
  136. package/dest/test-wallet/utils.d.ts +36 -1
  137. package/dest/test-wallet/utils.d.ts.map +1 -1
  138. package/dest/test-wallet/utils.js +64 -4
  139. package/dest/test-wallet/wallet_worker_script.js +5 -2
  140. package/dest/test-wallet/worker_wallet.d.ts +5 -5
  141. package/dest/test-wallet/worker_wallet.d.ts.map +1 -1
  142. package/dest/test-wallet/worker_wallet.js +2 -2
  143. package/dest/test-wallet/worker_wallet_schema.js +2 -1
  144. package/package.json +40 -40
  145. package/src/automine/README.md +60 -0
  146. package/src/automine/automine_test_context.ts +153 -0
  147. package/src/automine/delivery/interactive_handshake_responder.ts +125 -0
  148. package/src/automine/delivery/onchain_delivery_harness.ts +213 -0
  149. package/src/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.ts +19 -39
  150. package/src/{e2e_token_contract → automine/token}/token_contract_test.ts +24 -43
  151. package/src/automine/token/token_test_helpers.ts +138 -0
  152. package/src/bench/client_flows/benchmark.ts +3 -1
  153. package/src/bench/client_flows/client_flows_benchmark.ts +17 -4
  154. package/src/composed/ha/ha_full_setup.ts +466 -0
  155. package/src/fixtures/e2e_prover_test.ts +36 -20
  156. package/src/fixtures/fixtures.ts +6 -4
  157. package/src/fixtures/ha_setup.ts +7 -3
  158. package/src/fixtures/index.ts +1 -0
  159. package/src/fixtures/setup.ts +202 -161
  160. package/src/fixtures/standard_contracts_genesis.ts +28 -0
  161. package/src/fixtures/timing.ts +97 -0
  162. package/src/fixtures/wait_helpers.ts +333 -0
  163. package/src/forward-compatibility/wallet_service.ts +2 -2
  164. package/src/infra/README.md +12 -0
  165. package/src/multi-node/README.md +96 -0
  166. package/src/multi-node/block-production/setup.ts +272 -0
  167. package/src/multi-node/governance/setup.ts +172 -0
  168. package/src/multi-node/multi_node_test_context.ts +447 -0
  169. package/src/multi-node/slashing/inactivity_setup.ts +139 -0
  170. package/src/multi-node/slashing/setup.ts +433 -0
  171. package/src/p2p/README.md +78 -0
  172. package/src/{e2e_p2p → p2p}/p2p_network.ts +26 -0
  173. package/src/{e2e_p2p → p2p}/reqresp/utils.ts +5 -14
  174. package/src/p2p/shared.ts +329 -0
  175. package/src/shared/cross_chain_test_harness.ts +22 -13
  176. package/src/shared/gas_portal_test_harness.ts +13 -5
  177. package/src/shared/submit-transactions.ts +13 -5
  178. package/src/shared/timing_env.d.mts +39 -0
  179. package/src/shared/timing_env.mjs +152 -48
  180. package/src/shared/wait_for_l1_to_l2_message.ts +1 -1
  181. package/src/single-node/README.md +66 -0
  182. package/src/{e2e_cross_chain_messaging → single-node/cross-chain}/cross_chain_messaging_test.ts +100 -38
  183. package/src/single-node/cross-chain/message_test_helpers.ts +125 -0
  184. package/src/{e2e_fees → single-node/fees}/bridging_race.notest.ts +11 -7
  185. package/src/{e2e_fees → single-node/fees}/fees_test.ts +132 -47
  186. package/src/single-node/l1-reorgs/setup.ts +93 -0
  187. package/src/single-node/partial-proofs/setup.ts +8 -0
  188. package/src/single-node/proving/setup.ts +15 -0
  189. package/src/single-node/recovery/setup.ts +8 -0
  190. package/src/single-node/setup.ts +63 -0
  191. package/src/single-node/single_node_test_context.ts +1054 -0
  192. package/src/spartan/setup_test_wallets.ts +19 -7
  193. package/src/spartan/tx_metrics.ts +26 -0
  194. package/src/test-wallet/test_wallet.ts +28 -6
  195. package/src/test-wallet/utils.ts +102 -5
  196. package/src/test-wallet/wallet_worker_script.ts +6 -3
  197. package/src/test-wallet/worker_wallet.ts +5 -9
  198. package/src/test-wallet/worker_wallet_schema.ts +1 -1
  199. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +0 -56
  200. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +0 -1
  201. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +0 -59
  202. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +0 -1
  203. package/dest/e2e_deploy_contract/deploy_test.d.ts +0 -36
  204. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +0 -1
  205. package/dest/e2e_deploy_contract/deploy_test.js +0 -42
  206. package/dest/e2e_epochs/epochs_test.d.ts +0 -137
  207. package/dest/e2e_epochs/epochs_test.d.ts.map +0 -1
  208. package/dest/e2e_epochs/epochs_test.js +0 -485
  209. package/dest/e2e_fees/bridging_race.notest.d.ts.map +0 -1
  210. package/dest/e2e_fees/fees_test.d.ts +0 -89
  211. package/dest/e2e_fees/fees_test.d.ts.map +0 -1
  212. package/dest/e2e_l1_publisher/write_json.d.ts +0 -11
  213. package/dest/e2e_l1_publisher/write_json.d.ts.map +0 -1
  214. package/dest/e2e_l1_publisher/write_json.js +0 -57
  215. package/dest/e2e_multi_validator/utils.d.ts +0 -12
  216. package/dest/e2e_multi_validator/utils.d.ts.map +0 -1
  217. package/dest/e2e_nested_contract/nested_contract_test.d.ts +0 -22
  218. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +0 -1
  219. package/dest/e2e_nested_contract/nested_contract_test.js +0 -40
  220. package/dest/e2e_p2p/inactivity_slash_test.d.ts +0 -31
  221. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +0 -1
  222. package/dest/e2e_p2p/inactivity_slash_test.js +0 -138
  223. package/dest/e2e_p2p/p2p_network.d.ts.map +0 -1
  224. package/dest/e2e_p2p/reqresp/utils.d.ts +0 -22
  225. package/dest/e2e_p2p/reqresp/utils.d.ts.map +0 -1
  226. package/dest/e2e_p2p/shared.d.ts +0 -100
  227. package/dest/e2e_p2p/shared.d.ts.map +0 -1
  228. package/dest/e2e_p2p/shared.js +0 -257
  229. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +0 -2
  230. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +0 -1
  231. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +0 -1
  232. package/dest/e2e_token_contract/token_contract_test.d.ts +0 -44
  233. package/dest/e2e_token_contract/token_contract_test.d.ts.map +0 -1
  234. package/src/e2e_deploy_contract/deploy_test.ts +0 -73
  235. package/src/e2e_epochs/epochs_test.ts +0 -596
  236. package/src/e2e_l1_publisher/write_json.ts +0 -78
  237. package/src/e2e_nested_contract/nested_contract_test.ts +0 -51
  238. package/src/e2e_p2p/inactivity_slash_test.ts +0 -181
  239. package/src/e2e_p2p/shared.ts +0 -391
  240. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.js +0 -0
  241. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.js +0 -0
  242. /package/dest/{e2e_multi_validator/utils.js → composed/web3signer/multi_validator_keystore_utils.js} +0 -0
  243. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof.json +0 -0
  244. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.ts +0 -0
  245. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.ts +0 -0
  246. /package/src/{e2e_multi_validator/utils.ts → composed/web3signer/multi_validator_keystore_utils.ts} +0 -0
@@ -5,13 +5,23 @@ import CustomEnvironment from '../../../foundation/src/jest/env.mjs';
5
5
 
6
6
  // Per-test e2e timing environment. Gated entirely on the TEST_TIMING_FILE env var: when unset, this
7
7
  // behaves exactly like the base CustomEnvironment (it only delegates). When set, it records, per test
8
- // worker process, the time spent in jest before/after hooks and the test body, and merges in the
9
- // function-level time captured by setup.ts/teardown.ts via a collector shared on `this.global`.
8
+ // worker process, the time spent in jest before/after hooks and the test body, and folds in the named
9
+ // spans recorded via the `testSpan()` wrapper (fixtures/timing.ts) through a collector shared on
10
+ // `this.global`.
10
11
  //
11
12
  // Output is one JSONL file per worker process (the env runs once per worker). Each line carries a
12
13
  // `type` discriminator and is one of:
13
14
  // - `type: 'test'` (`name` set): beforeEach hooks, the it() body, afterEach hooks for one test; or
14
15
  // - `type: 'suite'` (`name: null`): the suite-scoped beforeAll/afterAll hooks for the whole file.
16
+ //
17
+ // Each line also gains a `spans` map: per `category:label` tag the test/suite touched, the collector
18
+ // records `{ count, totalMs, busyMs, maxMs }`. `busyMs` is the duration of the union of the spans'
19
+ // `[start, end)` intervals on the shared `performance.now()` clock, so concurrent spans (Promise.all
20
+ // fan-out) do not inflate it the way `totalMs` does. The legacy `setupFnMs`/`teardownFnMs` fields are
21
+ // kept for back-compat, derived from the `setup:env`/`teardown:env` spans.
22
+ //
23
+ // When `TEST_TIMING_SPANS=1`, the collector additionally retains every raw span occurrence and emits
24
+ // one `type:"span"` line per occurrence (owner, name, ms) for deep dives, at the cost of a larger file.
15
25
  export default class TimingEnvironment extends CustomEnvironment {
16
26
  constructor(config, context) {
17
27
  super(config, context);
@@ -28,10 +38,17 @@ export default class TimingEnvironment extends CustomEnvironment {
28
38
  runId: process.env.RUN_ID ?? null,
29
39
  };
30
40
 
31
- // Shared collector. setup.ts (running in the sandbox realm) reads `globalThis.__e2eTimings`; this
32
- // env (host realm) reads `this.global.__e2eTimings` they are the same object. `current` is the
33
- // full name of the test currently running (null during beforeAll/afterAll), used to tag fn spans.
34
- this.collector = { current: null, fnSpans: [] };
41
+ // Opt-in per-occurrence emission for deep dives (off by default keeps the JSONL one line per test).
42
+ this.emitSpanLines = process.env.TEST_TIMING_SPANS === '1';
43
+
44
+ // Shared collector. The instrumented helpers (running in the sandbox realm) read
45
+ // `globalThis.__e2eTimings`; this env (host realm) reads `this.global.__e2eTimings` — they are the
46
+ // same object. `current` is the full name of the test currently running (null during
47
+ // beforeAll/afterAll), used to attribute each span to a test or to the suite-scoped line. `spans`
48
+ // accumulates every recorded span until flush. The `start`/`end` timestamps come from the sandbox
49
+ // realm's `performance.now()`; Node's perf clock is process-wide (one monotonic origin across all
50
+ // realms), so merging the intervals here for `busyMs` is valid.
51
+ this.collector = { current: null, spans: [] };
35
52
  this.global.__e2eTimings = this.collector;
36
53
 
37
54
  // Records to flush as JSONL on teardown. One per test plus one suite-scoped record.
@@ -44,6 +61,8 @@ export default class TimingEnvironment extends CustomEnvironment {
44
61
  this.testStarts = new Map();
45
62
  // Guards against double-flushing (we flush on both the teardown event and the teardown method).
46
63
  this.flushed = false;
64
+ // Raw per-occurrence spans retained only when TEST_TIMING_SPANS=1, emitted as `type:"span"` lines.
65
+ this.rawSpans = [];
47
66
  }
48
67
 
49
68
  // Flush on the teardown method too: the jest lifecycle always calls this, whereas the 'teardown'
@@ -133,7 +152,6 @@ export default class TimingEnvironment extends CustomEnvironment {
133
152
  if (record && event.test?.errors?.length) {
134
153
  record.status = 'failed';
135
154
  }
136
- this.mergeFnSpans(name, record);
137
155
  this.collector.current = null;
138
156
  break;
139
157
  }
@@ -173,48 +191,24 @@ export default class TimingEnvironment extends CustomEnvironment {
173
191
  return parts.join(' ');
174
192
  }
175
193
 
176
- /** Moves fn spans tagged with `name` into the matching record's setup/teardown buckets. */
177
- mergeFnSpans(name, record) {
178
- if (!record) {
179
- return;
180
- }
181
- const remaining = [];
182
- for (const span of this.collector.fnSpans) {
183
- if (span.name === name) {
184
- if (span.kind === 'setup') {
185
- record.setupFnMs += span.ms;
186
- } else if (span.kind === 'teardown') {
187
- record.teardownFnMs += span.ms;
188
- }
189
- } else {
190
- remaining.push(span);
191
- }
192
- }
193
- this.collector.fnSpans = remaining;
194
+ /** Folds the collected spans into the per-test / suite records via {@link foldSpansInto}, then drains the collector. */
195
+ foldSpans() {
196
+ const rawSpans = foldSpansInto(this.collector.spans, {
197
+ recordsByName: this.recordsByName,
198
+ suiteRecord: this.suiteRecord,
199
+ emitSpanLines: this.emitSpanLines,
200
+ });
201
+ this.rawSpans.push(...rawSpans);
202
+ this.collector.spans = [];
194
203
  }
195
204
 
196
- /** Finalizes the suite-scoped record (untagged fn spans + beforeAll/afterAll) and writes all JSONL. */
205
+ /** Folds spans into records, finalizes the suite-scoped record, and writes all JSONL. */
197
206
  finalizeAndFlush() {
198
207
  if (this.flushed || !this.timingFile) {
199
208
  return;
200
209
  }
201
210
  this.flushed = true;
202
- const suite = {
203
- setupFnMs: 0,
204
- beforeHooksMs: this.suiteRecord.beforeHooksMs,
205
- teardownFnMs: 0,
206
- afterHooksMs: this.suiteRecord.afterHooksMs,
207
- };
208
- for (const span of this.collector.fnSpans) {
209
- if (span.name === null || span.name === undefined) {
210
- if (span.kind === 'setup') {
211
- suite.setupFnMs += span.ms;
212
- } else if (span.kind === 'teardown') {
213
- suite.teardownFnMs += span.ms;
214
- }
215
- }
216
- }
217
- this.collector.fnSpans = [];
211
+ this.foldSpans();
218
212
 
219
213
  const lines = [];
220
214
  for (const record of this.records) {
@@ -225,13 +219,17 @@ export default class TimingEnvironment extends CustomEnvironment {
225
219
  type: 'suite',
226
220
  name: null,
227
221
  status: 'passed',
228
- setupFnMs: suite.setupFnMs,
229
- beforeHooksMs: suite.beforeHooksMs,
230
- teardownFnMs: suite.teardownFnMs,
231
- afterHooksMs: suite.afterHooksMs,
232
- totalMs: suite.beforeHooksMs + suite.afterHooksMs,
222
+ setupFnMs: this.suiteRecord.setupFnMs ?? 0,
223
+ beforeHooksMs: this.suiteRecord.beforeHooksMs,
224
+ teardownFnMs: this.suiteRecord.teardownFnMs ?? 0,
225
+ afterHooksMs: this.suiteRecord.afterHooksMs,
226
+ totalMs: this.suiteRecord.beforeHooksMs + this.suiteRecord.afterHooksMs,
227
+ spans: this.suiteRecord.spans,
233
228
  }),
234
229
  );
230
+ for (const raw of this.rawSpans) {
231
+ lines.push(this.toLine({ type: 'span', name: raw.owner, span: raw.name, ms: raw.ms }));
232
+ }
235
233
 
236
234
  const payload = lines.join('\n') + '\n';
237
235
  try {
@@ -246,7 +244,7 @@ export default class TimingEnvironment extends CustomEnvironment {
246
244
  }
247
245
  }
248
246
 
249
- /** Flattens metadata onto a record and serializes to a single JSON line. */
247
+ /** Flattens metadata onto a record and serializes to a single JSON line, rounding all Ms fields. */
250
248
  toLine(record) {
251
249
  const obj = { suite: this.suite, ...record, ...this.meta };
252
250
  for (const key of Object.keys(obj)) {
@@ -254,6 +252,112 @@ export default class TimingEnvironment extends CustomEnvironment {
254
252
  obj[key] = Math.round(obj[key]);
255
253
  }
256
254
  }
255
+ // Round the nested span aggregates' Ms fields too (totalMs/busyMs/maxMs per tag).
256
+ if (obj.spans && typeof obj.spans === 'object') {
257
+ for (const agg of Object.values(obj.spans)) {
258
+ for (const key of Object.keys(agg)) {
259
+ if (key.endsWith('Ms') && typeof agg[key] === 'number') {
260
+ agg[key] = Math.round(agg[key]);
261
+ }
262
+ }
263
+ }
264
+ }
257
265
  return JSON.stringify(obj);
258
266
  }
259
267
  }
268
+
269
+ /**
270
+ * Aggregates a list of `{ start, end }` spans of one tag into `{ count, totalMs, busyMs, maxMs }`.
271
+ * `totalMs` is the naive sum of per-occurrence durations (correct for serial repeats); `busyMs` is
272
+ * the duration of the union of the `[start, end)` intervals (concurrency-correct — N concurrent
273
+ * spans collapse to their wall-clock span instead of summing to ~N×); `maxMs` is the longest single
274
+ * occurrence. All durations are on the shared process-wide `performance.now()` clock. Does not mutate
275
+ * the input array.
276
+ */
277
+ export function aggregateSpans(spans) {
278
+ let totalMs = 0;
279
+ let maxMs = 0;
280
+ for (const span of spans) {
281
+ const ms = span.end - span.start;
282
+ totalMs += ms;
283
+ if (ms > maxMs) {
284
+ maxMs = ms;
285
+ }
286
+ }
287
+ // busyMs: sort by start and merge overlapping intervals, summing the merged lengths.
288
+ const sorted = [...spans].sort((a, b) => a.start - b.start);
289
+ let busyMs = 0;
290
+ let mergeStart = null;
291
+ let mergeEnd = null;
292
+ for (const span of sorted) {
293
+ if (mergeStart === null) {
294
+ mergeStart = span.start;
295
+ mergeEnd = span.end;
296
+ } else if (span.start <= mergeEnd) {
297
+ if (span.end > mergeEnd) {
298
+ mergeEnd = span.end;
299
+ }
300
+ } else {
301
+ busyMs += mergeEnd - mergeStart;
302
+ mergeStart = span.start;
303
+ mergeEnd = span.end;
304
+ }
305
+ }
306
+ if (mergeStart !== null) {
307
+ busyMs += mergeEnd - mergeStart;
308
+ }
309
+ return { count: spans.length, totalMs, busyMs, maxMs };
310
+ }
311
+
312
+ /**
313
+ * Groups `spans` by owner, then by tag, and attaches a `spans` map of aggregates to the matching
314
+ * per-test record (looked up in `recordsByName`) or, for `null`-owner spans, to `suiteRecord`. Also
315
+ * derives the back-compat `setupFnMs` / `teardownFnMs` fields from the `setup:env:<mode>` /
316
+ * `teardown:env` aggregates (additive over any pre-existing value). Spans whose owner matches no
317
+ * record (e.g. the pinned `other:mempool-feeder` owner) are dropped. Returns the raw per-occurrence
318
+ * list (`{ owner, name, ms }`), which is empty unless `emitSpanLines` is set.
319
+ */
320
+ export function foldSpansInto(spans, { recordsByName, suiteRecord, emitSpanLines = false }) {
321
+ const rawSpans = [];
322
+ // Group by owner (null owner → suite record), then by tag.
323
+ const byOwner = new Map();
324
+ for (const span of spans) {
325
+ const owner = span.owner ?? null;
326
+ let byName = byOwner.get(owner);
327
+ if (!byName) {
328
+ byName = new Map();
329
+ byOwner.set(owner, byName);
330
+ }
331
+ let list = byName.get(span.name);
332
+ if (!list) {
333
+ list = [];
334
+ byName.set(span.name, list);
335
+ }
336
+ list.push(span);
337
+ if (emitSpanLines) {
338
+ rawSpans.push({ owner, name: span.name, ms: span.end - span.start });
339
+ }
340
+ }
341
+
342
+ for (const [owner, byName] of byOwner) {
343
+ const record = owner === null ? suiteRecord : recordsByName.get(owner);
344
+ if (!record) {
345
+ continue;
346
+ }
347
+ const aggregates = {};
348
+ for (const [name, list] of byName) {
349
+ aggregates[name] = aggregateSpans(list);
350
+ }
351
+ record.spans = aggregates;
352
+ // Back-compat: the legacy fn-span buckets are derived from the top-level env setup/teardown tags.
353
+ // The top-level setup is tagged `setup:env:<proverMode>` (the mode is a closed set, distinct from
354
+ // the `:anvil`/`:l1-deploy`/... sub-phase tags), so sum those three exact tags.
355
+ const setupFnMs =
356
+ (aggregates['setup:env:none']?.totalMs ?? 0) +
357
+ (aggregates['setup:env:fake']?.totalMs ?? 0) +
358
+ (aggregates['setup:env:real']?.totalMs ?? 0);
359
+ record.setupFnMs = setupFnMs + (record.setupFnMs ?? 0);
360
+ record.teardownFnMs = (aggregates['teardown:env']?.totalMs ?? 0) + (record.teardownFnMs ?? 0);
361
+ }
362
+ return rawSpans;
363
+ }
@@ -18,6 +18,6 @@ export function waitForL1ToL2MessageSeen(
18
18
  async () => (await node.getL1ToL2MessageCheckpoint(l1ToL2MessageHash)) !== undefined,
19
19
  `L1 to L2 message ${l1ToL2MessageHash.toString()} seen`,
20
20
  opts.timeoutSeconds,
21
- 1,
21
+ 0.25,
22
22
  );
23
23
  }
@@ -0,0 +1,66 @@
1
+ # `single-node` e2e test category
2
+
3
+ Single-node tests run one Aztec node with the production sequencer (and, where a test needs proving,
4
+ a prover node). They cover behavior that only requires a single sequencer and no multi-validator
5
+ committee: block building, sequencer config and governance signalling, world-state sync, the
6
+ proving/epoch lifecycle, partial proofs, L1-reorg handling, and pending-chain recovery.
7
+
8
+ ## Base class
9
+
10
+ All tests use `SingleNodeTestContext` (`single_node_test_context.ts`), which owns:
11
+
12
+ - The environment: an in-process anvil plus the L1 contract deploy.
13
+ - Node spawning: `createNonValidatorNode` and `createProverNode` (the latter wires the mock-gossip
14
+ `p2pServiceFactory`, which is harmless with a single node).
15
+ - The `ChainMonitor`.
16
+ - The epoch / checkpoint / proof-window / reorg waiters and assertion helpers (`waitUntilEpochStarts`,
17
+ `waitUntilProvenCheckpointNumber`, `waitForNodeToSync`, `verifyHistoricBlock`, …).
18
+
19
+ `MultiNodeTestContext` (in `../multi-node/`) extends this base with the N-validator topology, so the
20
+ multi-node category inherits the same environment and waiters.
21
+
22
+ Prefer these named waiters — and the node-level ones in `../fixtures/wait_helpers.ts` — over hand-rolled
23
+ `retryUntil` / `.on` / `sleep` polling in test bodies; the full catalog, including the helpers this base
24
+ class defines, is listed under [Helper surface](../multi-node/README.md#helper-surface) in the multi-node
25
+ README.
26
+
27
+ ## Setup factories
28
+
29
+ `setup.ts` holds thin factories over `SingleNodeTestContext.setup`, named by the prover mode a test
30
+ wants. Tests call the factory rather than the static method directly:
31
+
32
+ - `setupWithProver(opts)` — a single sequencer plus the context's fake in-process prover node. This is
33
+ the default the proving / partial-proofs / l1-reorgs / recovery / misc suites use.
34
+ - `setupBlockProducer(opts)` — a single production sequencer with **no prover node**, used by the
35
+ block-building / sequencer / sync suites. It raises `aztecProofSubmissionEpochs` to
36
+ `NO_REORG_SUBMISSION_EPOCHS` (1024) so unproven blocks are not pruned without a prover, and points the
37
+ PXE at `syncChainTip: 'proposed'` so tests can assert on freshly proposed blocks. Both are overridable
38
+ via `opts`.
39
+
40
+ The `prover/` suite (real Barretenberg proofs) builds its environment through `FullProverTest`, which
41
+ extends `SingleNodeTestContext` directly rather than going through a factory.
42
+
43
+ ## Organizing principle
44
+
45
+ The top level groups tests by node topology and setup model; the second level names the primary
46
+ behavior under test (the proving lifecycle, partial proofs, reorgs, recovery) rather than the shared
47
+ setup. Each file has a single top-level `describe` named to match its path, and a co-located
48
+ `setup.ts` holds any shared timeout/option wiring. A `.parallel` suffix marks files with more than one
49
+ top-level `it`; CI splits each `it` into its own job.
50
+
51
+ ## Subfolders
52
+
53
+ | Path | Contents |
54
+ |---|---|
55
+ | `block-building/` | Block assembly mechanics under the production sequencer with pipelining. `block_building` (multi-tx blocks, double-spend rejection, log ordering, regressions, and L1 reorgs), `debug_trace` (blocks proposed through a Forwarder proxy, including a failing-then-succeeding propose call), `multiple_blobs` (a block whose combined side effects span more than one EIP-4844 blob). |
56
+ | `sequencer/` | Sequencer configuration, governance signalling, and publisher management on a single node. `gov_proposal.parallel` (a 16-validator committee proposes blocks while casting governance votes, and votes even when block building is disabled), `escape_hatch_vote_only` (governance signals advance while the escape hatch is closed), `reload_keystore` (the keystore is hot-reloaded to add a validator and pick up new coinbases), `multi_eoa` (publisher rotation when an L1 tx is withheld; exercises multi-EOA publisher failover), `publisher_funding_multi` (PublisherManager auto top-up of publisher EOAs when balances drop below threshold), `runtime_config` (the former `slasher_config` and `sequencer_config` admin-API checks on one node: slasher inactivity-config getters, plus runtime `maxL2BlockGas`/`manaTarget` reconfiguration enforced via a live Bot). |
57
+ | `fees/` | Fee mechanics on a single node. `fee_asset_price_oracle` (on-chain fee-asset price-oracle convergence; starts its own Anvil instance with a MockStateView etched at the StateView address). The remaining files run on the `FeesTest` harness (`fees_test.ts`), which extends `SingleNodeTestContext` with the fee/gas domain setup (FPC funding, fee-juice bridging, banana token): `account_init` (fee payment during account-contract initialization), `failures` (fees still charged when txs revert in setup/app/teardown), `fee_juice_payments` (direct Fee Juice payment with and without initial funds), `fee_settings` (max-fee-per-gas handling, stale-fee-snapshot race, governance fee-config bump), `gas_estimation.parallel` (gas-estimation accuracy and FPC teardown gas prediction), `private_payments.parallel` (private fee payment via the BananaCoin FPC, plus the single-assertion public-FPC and sponsored-FPC payment checks folded onto the same fixture from the former `public_payments`/`sponsored_payments` files). |
58
+ | `cross-chain/` | L1↔L2 messaging on a single node, on the `CrossChainMessagingTest` harness (`cross_chain_messaging_test.ts`), which extends `SingleNodeTestContext` and owns a `CrossChainTestHarness` plus the L1 inbox/outbox handles (it auto-proves via an `EpochTestSettler` when no prover node runs). The shared L1→L2 message helpers live in `message_test_helpers.ts` (`createL1ToL2MessageHelpers`, whose injected `markAsProven` lets each suite plug in its own proving policy). `l1_to_l2` (L1→L2 message readiness and duplicate messages, over private and public scope), `l1_to_l2_inbox_drift` (inbox checkpoint drift after a rollup reorg, over private and public scope), `l2_to_l1` (L2→L1 message inclusion across single/multi-message txs and multi-block checkpoints, subtree-root balancing, and a reorg-and-remine case), `token_bridge` (private and public L1→L2 deposits and L2→L1 withdrawals via the TokenBridge — including mint-on-behalf — plus the withdrawal/claim failure cases, merged from the former three `token_bridge_*` files). |
59
+ | `bot/` | Transaction bot implementations. `bot` (transfer bot, AMM bot, and cross-chain bot; exercises fee-juice portal deposits, L2→L1 messages, and bot contract reuse). |
60
+ | `sync/` | World-state sync stress and snapshot sync. `synching` builds fixture block data (env-gated, slow) and replays it for sync benchmarks and prune/reorg scenarios (only the outer `it.each` runs in CI); `snapshot_sync` exercises the node snapshot upload/download path, syncing fresh nodes from one or multiple snapshot URLs, including fallback from a corrupted snapshot. |
61
+ | `proving/` | Epoch and proof lifecycle. `default_node` (basic proving/node coverage that shares one context-default node across three suites: consecutive epochs prove and finalized blocks are purged from world state beyond the checkpoint-history window, a proof is submitted even with no txs, and the node returns initial genesis-block data — the former `world_state_pruning`, `empty_blocks`, and `node_block_api` files), `long_proving_time` (a prover delay spanning multiple epochs), `multi_proof` (multiple prover nodes prove one epoch), `optimistic.parallel` (checkpoint-driven proving across the happy path and several mid-epoch / last-slot / during-proving reorg cases), `proof_fails.parallel` (proof not accepted after epoch end; proving aborts when the next epoch ends), `cross_chain_public_message` (an epoch with a public tx that consumes an L1→L2 message in the block it lands, guarding against a sequencer/prover state-root mismatch), `upload_failed_proof` (a failed proving job's state is uploaded and re-run on a fresh instance). |
62
+ | `prover/` | Real-proof exercises on the `FullProverTest` harness (real Barretenberg when `FAKE_PROOFS=0`, fake otherwise), split by where the proving runs so CI can size their containers independently: `client/client` (client-side proof generation and `verifyProof` for private and public transfers, no on-chain submission) and `server/full` (the end-to-end pipeline: client proves, node builds blocks, prover node generates epoch proofs, L1 verifies them). |
63
+ | `partial-proofs/` | Manually driven partial-proof submission. `single_root` (the prover node's `startProof` path on a single root) and `multi_root` (three partial-proof roots are staged and messages consume against any covering root, exercising the multi-root Outbox semantics). |
64
+ | `l1-reorgs/` | Behavior under L1 reorgs, split by what reorgs. `blocks.parallel` (prune L2 blocks when a reorg drops a proof, hold when a replacement proof lands in the window, restore blocks when a proof reappears, prune pending-chain blocks, and see new blocks added by a reorg) and `messages.parallel` (L1→L2 messages updated by a reorg, and a missed message inserted by one). `setup.ts` holds the shared `FAST_REORG_TIMING` profile and delayer wiring. |
65
+ | `recovery/` | Reorg and pending-chain recovery. `manual_rollback` (the `rollbackTo` admin API rolls back to an unfinalized block), `sync_after_reorg` (a fresh node syncs world state past an unpruned reorg window), `prune_when_cannot_build` (a solo sequencer prunes the pending chain via the fallback path when it cannot propose). |
66
+ | `misc/` | Genuine single-node outliers. `missed_l1_slot` (the sequencer builds a block after missed L1 slots once the previous checkpoint is synced). |
@@ -1,7 +1,7 @@
1
1
  import type { AztecNodeConfig } from '@aztec/aztec-node';
2
2
  import { AztecAddress, EthAddress } from '@aztec/aztec.js/addresses';
3
3
  import { waitForProven } from '@aztec/aztec.js/contracts';
4
- import { type Logger, createLogger } from '@aztec/aztec.js/log';
4
+ import { createLogger } from '@aztec/aztec.js/log';
5
5
  import type { AztecNode } from '@aztec/aztec.js/node';
6
6
  import type { TxReceipt } from '@aztec/aztec.js/tx';
7
7
  import { CheatCodes, EpochTestSettler } from '@aztec/aztec/testing';
@@ -17,48 +17,61 @@ import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
17
17
  import { EpochNumber } from '@aztec/foundation/branded-types';
18
18
  import { retryUntil } from '@aztec/foundation/retry';
19
19
  import { sleep } from '@aztec/foundation/sleep';
20
- import { TestERC20Abi, TestERC20Bytecode } from '@aztec/l1-artifacts';
20
+ import { TestERC20Abi, TestERC20Bytecode, TokenPortalAbi, TokenPortalBytecode } from '@aztec/l1-artifacts';
21
21
  import { TokenContract } from '@aztec/noir-contracts.js/Token';
22
22
  import { TokenBridgeContract } from '@aztec/noir-contracts.js/TokenBridge';
23
23
  import type { PXEConfig } from '@aztec/pxe/server';
24
24
  import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
25
25
  import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
26
26
 
27
- import { MNEMONIC } from '../fixtures/fixtures.js';
28
- import {
29
- type EndToEndContext,
30
- type SetupOptions,
31
- ensureAuthRegistryPublished,
32
- setup,
33
- teardown,
34
- } from '../fixtures/setup.js';
35
- import { CrossChainTestHarness } from '../shared/cross_chain_test_harness.js';
36
- import type { TestWallet } from '../test-wallet/test_wallet.js';
37
-
38
- export class CrossChainMessagingTest {
27
+ import { mnemonicToAccount } from 'viem/accounts';
28
+
29
+ import { MNEMONIC } from '../../fixtures/fixtures.js';
30
+ import { type SetupOptions, ensureAuthRegistryPublished, setup } from '../../fixtures/setup.js';
31
+ import { CrossChainTestHarness } from '../../shared/cross_chain_test_harness.js';
32
+ import type { TestWallet } from '../../test-wallet/test_wallet.js';
33
+ import { SingleNodeTestContext, type SingleNodeTestOpts } from '../single_node_test_context.js';
34
+
35
+ /** Optional configuration for {@link CrossChainMessagingTest}. */
36
+ export type CrossChainMessagingTestOpts = {
37
+ /** Mnemonic account index for the harness L1 client (token portal, inbox, minting). Defaults to the first account. */
38
+ l1HarnessAccountIndex?: number;
39
+ /** Whether to deploy the L1/L2 token bridge. Set to false for suites that only pass arbitrary messages. Defaults to true. */
40
+ deployTokenBridge?: boolean;
41
+ };
42
+
43
+ /**
44
+ * The cross-chain-messaging harness over the single-node topology: extends {@link SingleNodeTestContext}
45
+ * so it reuses the base node tracking / chain monitor / teardown machinery, but builds its environment
46
+ * with the bespoke cross-chain opts below (optional prover node, sponsored-FPC funding, a generous
47
+ * prover tx-gathering window for the epoch warps) rather than the base's default node config, and owns
48
+ * the {@link CrossChainTestHarness} domain object plus the L1 inbox/outbox handles.
49
+ */
50
+ export class CrossChainMessagingTest extends SingleNodeTestContext {
39
51
  private requireEpochProven: boolean;
40
52
  private setupOptions: SetupOptions;
41
53
  private deployL1ContractsArgs: Partial<DeployAztecL1ContractsArgs>;
42
54
  private pxeOpts: Partial<PXEConfig>;
43
55
  private l1HarnessAccountIndex?: number;
44
- logger: Logger;
45
- context!: EndToEndContext;
56
+ private deployTokenBridge: boolean;
57
+ /** L1 token portal + ERC20 deployed before the node started (under automine) by the setup hook. */
58
+ private preDeployedCrossChainL1?: { underlyingERC20Address: EthAddress; tokenPortalAddress: EthAddress };
59
+ private testName: string;
46
60
  aztecNode!: AztecNode;
47
61
  aztecNodeConfig!: AztecNodeConfig;
48
62
  aztecNodeAdmin!: AztecNodeAdmin;
49
63
 
50
- l1Client!: ExtendedViemWalletClient | undefined;
51
-
52
64
  wallet!: TestWallet;
53
65
  ownerAddress!: AztecAddress;
54
66
  user1Address!: AztecAddress;
55
67
  user2Address!: AztecAddress;
56
68
  crossChainTestHarness!: CrossChainTestHarness;
57
69
  ethAccount!: EthAddress;
70
+ /** L1 client used for cross-chain L1 interactions (token portal, inbox), tied to `l1HarnessAccountIndex`. */
71
+ harnessL1Client!: ExtendedViemWalletClient;
58
72
  l2Token!: TokenContract;
59
73
  l2Bridge!: TokenBridgeContract;
60
74
 
61
- rollup!: RollupContract;
62
75
  inbox!: InboxContract;
63
76
  outbox!: OutboxContract;
64
77
  cheatCodes!: CheatCodes;
@@ -80,8 +93,10 @@ export class CrossChainMessagingTest {
80
93
  opts: SetupOptions = {},
81
94
  deployL1ContractsArgs: Partial<DeployAztecL1ContractsArgs> = {},
82
95
  pxeOpts: Partial<PXEConfig> = {},
83
- l1HarnessAccountIndex?: number,
96
+ crossChainOpts: CrossChainMessagingTestOpts = {},
84
97
  ) {
98
+ super();
99
+ this.testName = testName;
85
100
  this.logger = createLogger(`e2e:e2e_cross_chain_messaging:${testName}`);
86
101
  this.setupOptions = opts;
87
102
  this.deployL1ContractsArgs = {
@@ -89,15 +104,16 @@ export class CrossChainMessagingTest {
89
104
  ...deployL1ContractsArgs,
90
105
  };
91
106
  this.pxeOpts = pxeOpts;
92
- this.l1HarnessAccountIndex = l1HarnessAccountIndex;
107
+ this.l1HarnessAccountIndex = crossChainOpts.l1HarnessAccountIndex;
108
+ this.deployTokenBridge = crossChainOpts.deployTokenBridge ?? true;
93
109
  this.requireEpochProven = opts.startProverNode ?? false;
94
110
  }
95
111
 
96
- async setup(opts: Partial<SetupOptions> = {}, pxeOpts: Partial<PXEConfig> = {}) {
112
+ override async setup(opts: SingleNodeTestOpts = {}, pxeOpts: Partial<PXEConfig> = {}) {
97
113
  this.logger.info('Setting up cross chain messaging test');
98
114
  // Recompute requireEpochProven from the merged options so per-call startProverNode is honored.
99
115
  this.requireEpochProven = opts.startProverNode ?? this.setupOptions.startProverNode ?? false;
100
- this.context = await setup(
116
+ const context = await setup(
101
117
  3,
102
118
  {
103
119
  ...this.setupOptions,
@@ -113,9 +129,45 @@ export class CrossChainMessagingTest {
113
129
  ...opts.proverNodeConfig,
114
130
  txGatheringTimeoutMs: opts.proverNodeConfig?.txGatheringTimeoutMs ?? 10 * 60 * 1000,
115
131
  },
132
+ // Deploy the cross-chain token portal + ERC20 before the node starts, while anvil is still
133
+ // automining, instead of paying the L1 block interval for them once the sequencer is live.
134
+ deployExtraL1Contracts: this.deployTokenBridge
135
+ ? async ({ l1Client, logger }) => {
136
+ // The harness mints the underlying ERC20 from `l1HarnessAccountIndex` and `TestERC20.mint`
137
+ // is onlyMinter, so its owner/initial-minter must be that account even though setup's
138
+ // publisher client sends the deploy tx.
139
+ const harnessAddress = mnemonicToAccount(MNEMONIC, {
140
+ addressIndex: this.l1HarnessAccountIndex ?? 0,
141
+ }).address;
142
+ const { address: underlyingERC20Address } = await deployL1Contract(
143
+ l1Client,
144
+ TestERC20Abi,
145
+ TestERC20Bytecode,
146
+ ['Underlying', 'UND', harnessAddress],
147
+ );
148
+ // The TokenPortal's initialize is permissionless, so it can be deployed by the publisher.
149
+ const { address: tokenPortalAddress } = await deployL1Contract(
150
+ l1Client,
151
+ TokenPortalAbi,
152
+ TokenPortalBytecode,
153
+ );
154
+ this.preDeployedCrossChainL1 = { underlyingERC20Address, tokenPortalAddress };
155
+ logger.verbose(
156
+ `Pre-deployed cross-chain L1 ERC20 ${underlyingERC20Address} and portal ${tokenPortalAddress}`,
157
+ );
158
+ return this.preDeployedCrossChainL1;
159
+ }
160
+ : undefined,
116
161
  },
117
162
  { ...this.pxeOpts, ...pxeOpts },
118
163
  );
164
+
165
+ // Reuse the base context machinery (rollup, epoch cache, chain monitor, node tracking, teardown)
166
+ // over the environment built above. Restore the CrossChainMessagingTest-named logger afterwards,
167
+ // since hydrateFromContext repoints `this.logger` at the context logger.
168
+ await this.hydrateFromContext(context);
169
+ this.logger = createLogger(`e2e:e2e_cross_chain_messaging:${this.testName}`);
170
+
119
171
  await this.applyBaseSetup();
120
172
  }
121
173
 
@@ -144,9 +196,9 @@ export class CrossChainMessagingTest {
144
196
  }
145
197
  }
146
198
 
147
- async teardown() {
199
+ override async teardown() {
148
200
  await this.epochTestSettler?.stop();
149
- await teardown(this.context);
201
+ await super.teardown();
150
202
  }
151
203
 
152
204
  async applyBaseSetup() {
@@ -187,12 +239,29 @@ export class CrossChainMessagingTest {
187
239
  undefined,
188
240
  this.l1HarnessAccountIndex,
189
241
  );
242
+ this.harnessL1Client = harnessL1Client;
243
+ this.ethAccount = EthAddress.fromString((await harnessL1Client.getAddresses())[0]);
190
244
 
191
- const underlyingERC20Address = await deployL1Contract(harnessL1Client, TestERC20Abi, TestERC20Bytecode, [
192
- 'Underlying',
193
- 'UND',
194
- harnessL1Client.account.address,
195
- ]).then(({ address }) => address);
245
+ // L1 contract handles every cross-chain test needs, independent of the token bridge.
246
+ const l1Client = createExtendedL1Client(this.aztecNodeConfig.l1RpcUrls, MNEMONIC);
247
+ this.l1Client = l1Client;
248
+ const l1Contracts = pickL1ContractAddresses(this.aztecNodeConfig);
249
+ this.rollup = new RollupContract(l1Client, l1Contracts.rollupAddress.toString());
250
+ this.inbox = new InboxContract(l1Client, l1Contracts.inboxAddress.toString());
251
+ this.outbox = new OutboxContract(l1Client, l1Contracts.outboxAddress.toString());
252
+
253
+ // Tests that only pass arbitrary L1<->L2 messages (not token bridging) never touch the L2 token,
254
+ // bridge, or portal. Skip the token+portal+bridge deploy (an L1 ERC20, an L1 portal, and two L2
255
+ // contract deploys plus their init txs) entirely for them.
256
+ if (!this.deployTokenBridge) {
257
+ this.logger.info('Skipping token bridge deploy; test only needs L1 handles and ethAccount');
258
+ return;
259
+ }
260
+
261
+ // The ERC20 and token portal were deployed before the node started (under automine) by the
262
+ // `deployExtraL1Contracts` setup hook above; the harness reuses them and only deploys the L2 token,
263
+ // L2 bridge, and the portal init that need the running node.
264
+ const { underlyingERC20Address, tokenPortalAddress: predeployedTokenPortalAddress } = this.preDeployedCrossChainL1!;
196
265
 
197
266
  this.logger.verbose(`Setting up cross chain harness...`);
198
267
  this.crossChainTestHarness = await CrossChainTestHarness.new(
@@ -202,6 +271,7 @@ export class CrossChainMessagingTest {
202
271
  this.ownerAddress,
203
272
  this.logger,
204
273
  underlyingERC20Address,
274
+ predeployedTokenPortalAddress,
205
275
  );
206
276
 
207
277
  this.logger.verbose(`L2 token deployed to: ${this.crossChainTestHarness.l2Token.address}`);
@@ -215,14 +285,6 @@ export class CrossChainMessagingTest {
215
285
  this.ethAccount = EthAddress.fromString(crossChainContext.ethAccount.toString());
216
286
  const tokenPortalAddress = EthAddress.fromString(crossChainContext.tokenPortal.toString());
217
287
 
218
- const l1Client = createExtendedL1Client(this.aztecNodeConfig.l1RpcUrls, MNEMONIC);
219
- this.l1Client = l1Client;
220
-
221
- const l1Contracts = pickL1ContractAddresses(this.aztecNodeConfig);
222
- this.rollup = new RollupContract(l1Client, l1Contracts.rollupAddress.toString());
223
- this.inbox = new InboxContract(l1Client, l1Contracts.inboxAddress.toString());
224
- this.outbox = new OutboxContract(l1Client, l1Contracts.outboxAddress.toString());
225
-
226
288
  this.crossChainTestHarness = new CrossChainTestHarness(
227
289
  this.aztecNode,
228
290
  this.logger,