@aztec/end-to-end 5.0.0-rc.2 → 5.0.1

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 +9 -6
  40. package/dest/fixtures/fixtures.d.ts.map +1 -1
  41. package/dest/fixtures/fixtures.js +11 -7
  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 +34 -9
  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 +374 -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 +847 -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 +11 -7
  157. package/src/fixtures/ha_setup.ts +7 -3
  158. package/src/fixtures/index.ts +1 -0
  159. package/src/fixtures/setup.ts +204 -162
  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 +1058 -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
@@ -3,13 +3,23 @@ import { basename } from 'node:path';
3
3
  import CustomEnvironment from '../../../foundation/src/jest/env.mjs';
4
4
  // Per-test e2e timing environment. Gated entirely on the TEST_TIMING_FILE env var: when unset, this
5
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 merges in the
7
- // function-level time captured by setup.ts/teardown.ts via a collector shared on `this.global`.
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`.
8
9
  //
9
10
  // Output is one JSONL file per worker process (the env runs once per worker). Each line carries a
10
11
  // `type` discriminator and is one of:
11
12
  // - `type: 'test'` (`name` set): beforeEach hooks, the it() body, afterEach hooks for one test; or
12
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.
13
23
  export default class TimingEnvironment extends CustomEnvironment {
14
24
  constructor(config, context){
15
25
  super(config, context);
@@ -23,12 +33,18 @@ export default class TimingEnvironment extends CustomEnvironment {
23
33
  branch: process.env.TARGET_BRANCH ?? process.env.REF_NAME ?? null,
24
34
  runId: process.env.RUN_ID ?? null
25
35
  };
26
- // Shared collector. setup.ts (running in the sandbox realm) reads `globalThis.__e2eTimings`; this
27
- // env (host realm) reads `this.global.__e2eTimings` they are the same object. `current` is the
28
- // full name of the test currently running (null during beforeAll/afterAll), used to tag fn spans.
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.
29
45
  this.collector = {
30
46
  current: null,
31
- fnSpans: []
47
+ spans: []
32
48
  };
33
49
  this.global.__e2eTimings = this.collector;
34
50
  // Records to flush as JSONL on teardown. One per test plus one suite-scoped record.
@@ -46,6 +62,8 @@ export default class TimingEnvironment extends CustomEnvironment {
46
62
  this.testStarts = new Map();
47
63
  // Guards against double-flushing (we flush on both the teardown event and the teardown method).
48
64
  this.flushed = false;
65
+ // Raw per-occurrence spans retained only when TEST_TIMING_SPANS=1, emitted as `type:"span"` lines.
66
+ this.rawSpans = [];
49
67
  }
50
68
  // Flush on the teardown method too: the jest lifecycle always calls this, whereas the 'teardown'
51
69
  // event is not reliably delivered when a test run is interrupted. Whichever fires first wins.
@@ -137,7 +155,6 @@ export default class TimingEnvironment extends CustomEnvironment {
137
155
  if (record && event.test?.errors?.length) {
138
156
  record.status = 'failed';
139
157
  }
140
- this.mergeFnSpans(name, record);
141
158
  this.collector.current = null;
142
159
  break;
143
160
  }
@@ -171,45 +188,21 @@ export default class TimingEnvironment extends CustomEnvironment {
171
188
  }
172
189
  return parts.join(' ');
173
190
  }
174
- /** Moves fn spans tagged with `name` into the matching record's setup/teardown buckets. */ mergeFnSpans(name, record) {
175
- if (!record) {
176
- return;
177
- }
178
- const remaining = [];
179
- for (const span of this.collector.fnSpans){
180
- if (span.name === name) {
181
- if (span.kind === 'setup') {
182
- record.setupFnMs += span.ms;
183
- } else if (span.kind === 'teardown') {
184
- record.teardownFnMs += span.ms;
185
- }
186
- } else {
187
- remaining.push(span);
188
- }
189
- }
190
- this.collector.fnSpans = remaining;
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 = [];
191
199
  }
192
- /** Finalizes the suite-scoped record (untagged fn spans + beforeAll/afterAll) and writes all JSONL. */ finalizeAndFlush() {
200
+ /** Folds spans into records, finalizes the suite-scoped record, and writes all JSONL. */ finalizeAndFlush() {
193
201
  if (this.flushed || !this.timingFile) {
194
202
  return;
195
203
  }
196
204
  this.flushed = true;
197
- const suite = {
198
- setupFnMs: 0,
199
- beforeHooksMs: this.suiteRecord.beforeHooksMs,
200
- teardownFnMs: 0,
201
- afterHooksMs: this.suiteRecord.afterHooksMs
202
- };
203
- for (const span of this.collector.fnSpans){
204
- if (span.name === null || span.name === undefined) {
205
- if (span.kind === 'setup') {
206
- suite.setupFnMs += span.ms;
207
- } else if (span.kind === 'teardown') {
208
- suite.teardownFnMs += span.ms;
209
- }
210
- }
211
- }
212
- this.collector.fnSpans = [];
205
+ this.foldSpans();
213
206
  const lines = [];
214
207
  for (const record of this.records){
215
208
  lines.push(this.toLine({
@@ -220,12 +213,21 @@ export default class TimingEnvironment extends CustomEnvironment {
220
213
  type: 'suite',
221
214
  name: null,
222
215
  status: 'passed',
223
- setupFnMs: suite.setupFnMs,
224
- beforeHooksMs: suite.beforeHooksMs,
225
- teardownFnMs: suite.teardownFnMs,
226
- afterHooksMs: suite.afterHooksMs,
227
- totalMs: suite.beforeHooksMs + suite.afterHooksMs
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
228
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
+ }
229
231
  const payload = lines.join('\n') + '\n';
230
232
  try {
231
233
  // One file per worker process, but a worker may run several suites: append so we keep them all.
@@ -238,7 +240,7 @@ export default class TimingEnvironment extends CustomEnvironment {
238
240
  }
239
241
  }
240
242
  }
241
- /** Flattens metadata onto a record and serializes to a single JSON line. */ toLine(record) {
243
+ /** Flattens metadata onto a record and serializes to a single JSON line, rounding all Ms fields. */ toLine(record) {
242
244
  const obj = {
243
245
  suite: this.suite,
244
246
  ...record,
@@ -249,6 +251,115 @@ export default class TimingEnvironment extends CustomEnvironment {
249
251
  obj[key] = Math.round(obj[key]);
250
252
  }
251
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
+ }
252
264
  return JSON.stringify(obj);
253
265
  }
254
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
  }
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3Jvc3NfY2hhaW5fbWVzc2FnaW5nX3Rlc3QuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zaW5nbGUtbm9kZS9jcm9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Addresses } 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
32
  l1HarnessAccountIndex;
25
- logger;
26
- context;
33
+ deployTokenBridge;
34
+ /** L1 token portal + ERC20 deployed before the node started (under automine) by the setup hook. */ preDeployedCrossChainL1;
35
+ testName;
27
36
  aztecNode;
28
37
  aztecNodeConfig;
29
38
  aztecNodeAdmin;
30
- l1Client;
31
39
  wallet;
32
40
  ownerAddress;
33
41
  user1Address;
34
42
  user2Address;
35
43
  crossChainTestHarness;
36
44
  ethAccount;
45
+ /** L1 client used for cross-chain L1 interactions (token portal, inbox), tied to `l1HarnessAccountIndex`. */ harnessL1Client;
37
46
  l2Token;
38
47
  l2Bridge;
39
- rollup;
40
48
  inbox;
41
49
  outbox;
42
50
  cheatCodes;
@@ -49,7 +57,9 @@ export class CrossChainMessagingTest {
49
57
  * `await t.epochTestSettler?.stop()`.
50
58
  */ epochTestSettler;
51
59
  deployL1ContractsValues;
52
- constructor(testName, opts = {}, deployL1ContractsArgs = {}, pxeOpts = {}, l1HarnessAccountIndex){
60
+ constructor(testName, opts = {}, deployL1ContractsArgs = {}, pxeOpts = {}, crossChainOpts = {}){
61
+ super();
62
+ this.testName = testName;
53
63
  this.logger = createLogger(`e2e:e2e_cross_chain_messaging:${testName}`);
54
64
  this.setupOptions = opts;
55
65
  this.deployL1ContractsArgs = {
@@ -57,14 +67,15 @@ export class CrossChainMessagingTest {
57
67
  ...deployL1ContractsArgs
58
68
  };
59
69
  this.pxeOpts = pxeOpts;
60
- this.l1HarnessAccountIndex = l1HarnessAccountIndex;
70
+ this.l1HarnessAccountIndex = crossChainOpts.l1HarnessAccountIndex;
71
+ this.deployTokenBridge = crossChainOpts.deployTokenBridge ?? true;
61
72
  this.requireEpochProven = opts.startProverNode ?? false;
62
73
  }
63
74
  async setup(opts = {}, pxeOpts = {}) {
64
75
  this.logger.info('Setting up cross chain messaging test');
65
76
  // Recompute requireEpochProven from the merged options so per-call startProverNode is honored.
66
77
  this.requireEpochProven = opts.startProverNode ?? this.setupOptions.startProverNode ?? false;
67
- this.context = await setup(3, {
78
+ const context = await setup(3, {
68
79
  ...this.setupOptions,
69
80
  ...opts,
70
81
  fundSponsoredFPC: true,
@@ -80,11 +91,39 @@ export class CrossChainMessagingTest {
80
91
  ...this.setupOptions.proverNodeConfig,
81
92
  ...opts.proverNodeConfig,
82
93
  txGatheringTimeoutMs: opts.proverNodeConfig?.txGatheringTimeoutMs ?? 10 * 60 * 1000
83
- }
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
84
118
  }, {
85
119
  ...this.pxeOpts,
86
120
  ...pxeOpts
87
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}`);
88
127
  await this.applyBaseSetup();
89
128
  }
90
129
  async advanceToEpochProven(l2TxReceipt) {
@@ -111,7 +150,7 @@ export class CrossChainMessagingTest {
111
150
  }
112
151
  async teardown() {
113
152
  await this.epochTestSettler?.stop();
114
- await teardown(this.context);
153
+ await super.teardown();
115
154
  }
116
155
  async applyBaseSetup() {
117
156
  // Set up base context fields
@@ -136,13 +175,28 @@ export class CrossChainMessagingTest {
136
175
  this.logger.info('Applying e2e_cross_chain_messaging setup');
137
176
  await ensureAuthRegistryPublished(this.wallet, this.ownerAddress);
138
177
  const harnessL1Client = createExtendedL1Client(this.aztecNodeConfig.l1RpcUrls, MNEMONIC, undefined, undefined, this.l1HarnessAccountIndex);
139
- const underlyingERC20Address = await deployL1Contract(harnessL1Client, TestERC20Abi, TestERC20Bytecode, [
140
- 'Underlying',
141
- 'UND',
142
- harnessL1Client.account.address
143
- ]).then(({ address })=>address);
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;
144
198
  this.logger.verbose(`Setting up cross chain harness...`);
145
- this.crossChainTestHarness = await CrossChainTestHarness.new(this.aztecNode, harnessL1Client, this.wallet, this.ownerAddress, this.logger, underlyingERC20Address);
199
+ this.crossChainTestHarness = await CrossChainTestHarness.new(this.aztecNode, harnessL1Client, this.wallet, this.ownerAddress, this.logger, underlyingERC20Address, predeployedTokenPortalAddress);
146
200
  this.logger.verbose(`L2 token deployed to: ${this.crossChainTestHarness.l2Token.address}`);
147
201
  const crossChainContext = this.crossChainTestHarness.toCrossChainContext();
148
202
  this.l2Token = TokenContract.at(crossChainContext.l2Token, this.wallet);
@@ -150,12 +204,6 @@ export class CrossChainMessagingTest {
150
204
  // There is an issue with the reviver so we are getting strings sometimes. Working around it here.
151
205
  this.ethAccount = EthAddress.fromString(crossChainContext.ethAccount.toString());
152
206
  const tokenPortalAddress = EthAddress.fromString(crossChainContext.tokenPortal.toString());
153
- const l1Client = createExtendedL1Client(this.aztecNodeConfig.l1RpcUrls, MNEMONIC);
154
- this.l1Client = l1Client;
155
- const l1Contracts = pickL1ContractAddresses(this.aztecNodeConfig);
156
- this.rollup = new RollupContract(l1Client, l1Contracts.rollupAddress.toString());
157
- this.inbox = new InboxContract(l1Client, l1Contracts.inboxAddress.toString());
158
- this.outbox = new OutboxContract(l1Client, l1Contracts.outboxAddress.toString());
159
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);
160
208
  }
161
209
  }
@@ -0,0 +1,38 @@
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import type { Fr } from '@aztec/aztec.js/fields';
3
+ import type { Logger } from '@aztec/aztec.js/log';
4
+ import type { AztecNode } from '@aztec/aztec.js/node';
5
+ import type { Wallet } from '@aztec/aztec.js/wallet';
6
+ import type { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
7
+ import { sendL1ToL2Message } from '../../fixtures/l1_to_l2_messaging.js';
8
+ import type { CrossChainMessagingTest } from './cross_chain_messaging_test.js';
9
+ /** Scope from which an L1→L2 message is consumed on L2. */
10
+ export type L1ToL2MessageScope = 'private' | 'public';
11
+ /** Dependencies the L1→L2 message helpers close over. */
12
+ export interface L1ToL2MessageHelperDeps {
13
+ t: CrossChainMessagingTest;
14
+ aztecNode: AztecNode;
15
+ wallet: Wallet;
16
+ user1Address: AztecAddress;
17
+ log: Logger;
18
+ /** Marks the current pending tip proven on L1, subject to the caller's proving policy. */
19
+ markAsProven: () => Promise<void>;
20
+ }
21
+ /** Helpers for driving L1→L2 messages through the inbox, shared across the L1→L2 messaging suites. */
22
+ export interface L1ToL2MessageHelpers {
23
+ sendMessageToL2(message: {
24
+ recipient: AztecAddress;
25
+ content: Fr;
26
+ secretHash: Fr;
27
+ }): ReturnType<typeof sendL1ToL2Message>;
28
+ advanceBlock(): Promise<BlockNumber>;
29
+ waitForMessageFetched(msgHash: Fr): Promise<CheckpointNumber>;
30
+ waitForMessageReady(msgHash: Fr, scope: L1ToL2MessageScope, onNotReady?: (blockNumber: BlockNumber) => Promise<void>): Promise<void>;
31
+ }
32
+ /**
33
+ * Builds the L1→L2 message helpers over a running {@link CrossChainMessagingTest}. The `markAsProven`
34
+ * dependency lets each suite plug in its own proving policy: suites that never pause proving pass an
35
+ * unconditional mark, while the inbox-drift suite gates it behind a flag it toggles mid-test.
36
+ */
37
+ export declare function createL1ToL2MessageHelpers(deps: L1ToL2MessageHelperDeps): L1ToL2MessageHelpers;
38
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVzc2FnZV90ZXN0X2hlbHBlcnMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zaW5nbGUtbm9kZS9jcm9zcy1jaGFpbi9tZX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