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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/README.md +215 -27
  2. package/dest/automine/automine_test_context.d.ts +85 -0
  3. package/dest/automine/automine_test_context.d.ts.map +1 -0
  4. package/dest/automine/automine_test_context.js +98 -0
  5. package/dest/automine/contracts/fixtures/storage_proof_fetcher.d.ts +2 -0
  6. package/dest/automine/contracts/fixtures/storage_proof_fetcher.d.ts.map +1 -0
  7. package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.d.ts +1 -1
  8. package/dest/automine/contracts/fixtures/storage_proof_fixture.d.ts.map +1 -0
  9. package/dest/automine/delivery/interactive_handshake_responder.d.ts +48 -0
  10. package/dest/automine/delivery/interactive_handshake_responder.d.ts.map +1 -0
  11. package/dest/automine/delivery/interactive_handshake_responder.js +76 -0
  12. package/dest/automine/delivery/onchain_delivery_harness.d.ts +19 -0
  13. package/dest/automine/delivery/onchain_delivery_harness.d.ts.map +1 -0
  14. package/dest/automine/delivery/onchain_delivery_harness.js +141 -0
  15. package/dest/automine/token/blacklist_token_contract_test.d.ts +49 -0
  16. package/dest/automine/token/blacklist_token_contract_test.d.ts.map +1 -0
  17. package/dest/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.js +17 -24
  18. package/dest/automine/token/token_contract_test.d.ts +40 -0
  19. package/dest/automine/token/token_contract_test.d.ts.map +1 -0
  20. package/dest/{e2e_token_contract → automine/token}/token_contract_test.js +22 -28
  21. package/dest/automine/token/token_test_helpers.d.ts +73 -0
  22. package/dest/automine/token/token_test_helpers.d.ts.map +1 -0
  23. package/dest/automine/token/token_test_helpers.js +97 -0
  24. package/dest/bench/client_flows/benchmark.d.ts +1 -1
  25. package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
  26. package/dest/bench/client_flows/benchmark.js +3 -1
  27. package/dest/bench/client_flows/client_flows_benchmark.d.ts +4 -4
  28. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  29. package/dest/bench/client_flows/client_flows_benchmark.js +25 -10
  30. package/dest/bench/utils.d.ts +1 -1
  31. package/dest/composed/ha/ha_full_setup.d.ts +77 -0
  32. package/dest/composed/ha/ha_full_setup.d.ts.map +1 -0
  33. package/dest/composed/ha/ha_full_setup.js +383 -0
  34. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts +12 -0
  35. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts.map +1 -0
  36. package/dest/fixtures/e2e_prover_test.d.ts +10 -7
  37. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  38. package/dest/fixtures/e2e_prover_test.js +33 -14
  39. package/dest/fixtures/fixtures.d.ts +8 -5
  40. package/dest/fixtures/fixtures.d.ts.map +1 -1
  41. package/dest/fixtures/fixtures.js +12 -4
  42. package/dest/fixtures/ha_setup.d.ts +3 -3
  43. package/dest/fixtures/ha_setup.d.ts.map +1 -1
  44. package/dest/fixtures/ha_setup.js +4 -1
  45. package/dest/fixtures/index.d.ts +2 -1
  46. package/dest/fixtures/index.d.ts.map +1 -1
  47. package/dest/fixtures/index.js +1 -0
  48. package/dest/fixtures/setup.d.ts +35 -9
  49. package/dest/fixtures/setup.d.ts.map +1 -1
  50. package/dest/fixtures/setup.js +175 -142
  51. package/dest/fixtures/setup_p2p_test.d.ts +1 -1
  52. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  53. package/dest/fixtures/setup_p2p_test.js +3 -3
  54. package/dest/fixtures/standard_contracts_genesis.d.ts +16 -0
  55. package/dest/fixtures/standard_contracts_genesis.d.ts.map +1 -0
  56. package/dest/fixtures/standard_contracts_genesis.js +25 -0
  57. package/dest/fixtures/timing.d.ts +42 -0
  58. package/dest/fixtures/timing.d.ts.map +1 -0
  59. package/dest/fixtures/timing.js +72 -0
  60. package/dest/fixtures/token_utils.d.ts +22 -4
  61. package/dest/fixtures/token_utils.d.ts.map +1 -1
  62. package/dest/fixtures/token_utils.js +21 -1
  63. package/dest/fixtures/wait_helpers.d.ts +135 -0
  64. package/dest/fixtures/wait_helpers.d.ts.map +1 -0
  65. package/dest/fixtures/wait_helpers.js +154 -0
  66. package/dest/forward-compatibility/wallet_service.js +1 -1
  67. package/dest/multi-node/block-production/setup.d.ts +97 -0
  68. package/dest/multi-node/block-production/setup.d.ts.map +1 -0
  69. package/dest/multi-node/block-production/setup.js +158 -0
  70. package/dest/multi-node/governance/setup.d.ts +67 -0
  71. package/dest/multi-node/governance/setup.d.ts.map +1 -0
  72. package/dest/multi-node/governance/setup.js +126 -0
  73. package/dest/multi-node/multi_node_test_context.d.ts +212 -0
  74. package/dest/multi-node/multi_node_test_context.d.ts.map +1 -0
  75. package/dest/multi-node/multi_node_test_context.js +347 -0
  76. package/dest/multi-node/slashing/inactivity_setup.d.ts +27 -0
  77. package/dest/multi-node/slashing/inactivity_setup.d.ts.map +1 -0
  78. package/dest/multi-node/slashing/inactivity_setup.js +111 -0
  79. package/dest/multi-node/slashing/setup.d.ts +167 -0
  80. package/dest/multi-node/slashing/setup.d.ts.map +1 -0
  81. package/dest/multi-node/slashing/setup.js +275 -0
  82. package/dest/{e2e_p2p → p2p}/p2p_network.d.ts +10 -2
  83. package/dest/p2p/p2p_network.d.ts.map +1 -0
  84. package/dest/{e2e_p2p → p2p}/p2p_network.js +36 -9
  85. package/dest/p2p/reqresp/utils.d.ts +19 -0
  86. package/dest/p2p/reqresp/utils.d.ts.map +1 -0
  87. package/dest/{e2e_p2p → p2p}/reqresp/utils.js +4 -15
  88. package/dest/p2p/shared.d.ts +72 -0
  89. package/dest/p2p/shared.d.ts.map +1 -0
  90. package/dest/p2p/shared.js +212 -0
  91. package/dest/shared/cross_chain_test_harness.d.ts +3 -3
  92. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  93. package/dest/shared/cross_chain_test_harness.js +24 -16
  94. package/dest/shared/gas_portal_test_harness.d.ts +1 -1
  95. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  96. package/dest/shared/gas_portal_test_harness.js +8 -5
  97. package/dest/shared/submit-transactions.d.ts +1 -1
  98. package/dest/shared/submit-transactions.d.ts.map +1 -1
  99. package/dest/shared/submit-transactions.js +12 -5
  100. package/dest/shared/timing_env.d.js +5 -0
  101. package/dest/shared/timing_env.js +365 -0
  102. package/dest/shared/wait_for_l1_to_l2_message.js +1 -1
  103. package/dest/simulators/lending_simulator.js +1 -1
  104. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts +75 -0
  105. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts.map +1 -0
  106. package/dest/{e2e_cross_chain_messaging → single-node/cross-chain}/cross_chain_messaging_test.js +77 -27
  107. package/dest/single-node/cross-chain/message_test_helpers.d.ts +38 -0
  108. package/dest/single-node/cross-chain/message_test_helpers.d.ts.map +1 -0
  109. package/dest/single-node/cross-chain/message_test_helpers.js +70 -0
  110. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.d.ts +1 -1
  111. package/dest/single-node/fees/bridging_race.notest.d.ts.map +1 -0
  112. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.js +17 -4
  113. package/dest/single-node/fees/fees_test.d.ts +95 -0
  114. package/dest/single-node/fees/fees_test.d.ts.map +1 -0
  115. package/dest/{e2e_fees → single-node/fees}/fees_test.js +124 -46
  116. package/dest/single-node/l1-reorgs/setup.d.ts +42 -0
  117. package/dest/single-node/l1-reorgs/setup.d.ts.map +1 -0
  118. package/dest/single-node/l1-reorgs/setup.js +57 -0
  119. package/dest/single-node/partial-proofs/setup.d.ts +5 -0
  120. package/dest/single-node/partial-proofs/setup.d.ts.map +1 -0
  121. package/dest/single-node/partial-proofs/setup.js +5 -0
  122. package/dest/single-node/proving/setup.d.ts +5 -0
  123. package/dest/single-node/proving/setup.d.ts.map +1 -0
  124. package/dest/single-node/proving/setup.js +5 -0
  125. package/dest/single-node/recovery/setup.d.ts +5 -0
  126. package/dest/single-node/recovery/setup.d.ts.map +1 -0
  127. package/dest/single-node/recovery/setup.js +5 -0
  128. package/dest/single-node/setup.d.ts +49 -0
  129. package/dest/single-node/setup.d.ts.map +1 -0
  130. package/dest/single-node/setup.js +56 -0
  131. package/dest/single-node/single_node_test_context.d.ts +373 -0
  132. package/dest/single-node/single_node_test_context.d.ts.map +1 -0
  133. package/dest/single-node/single_node_test_context.js +845 -0
  134. package/dest/spartan/setup_test_wallets.d.ts +1 -1
  135. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  136. package/dest/spartan/setup_test_wallets.js +18 -8
  137. package/dest/spartan/tx_metrics.d.ts +10 -1
  138. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  139. package/dest/spartan/tx_metrics.js +32 -0
  140. package/dest/test-wallet/test_wallet.d.ts +23 -4
  141. package/dest/test-wallet/test_wallet.d.ts.map +1 -1
  142. package/dest/test-wallet/test_wallet.js +20 -4
  143. package/dest/test-wallet/utils.d.ts +36 -1
  144. package/dest/test-wallet/utils.d.ts.map +1 -1
  145. package/dest/test-wallet/utils.js +64 -4
  146. package/dest/test-wallet/wallet_worker_script.js +5 -2
  147. package/dest/test-wallet/worker_wallet.d.ts +5 -5
  148. package/dest/test-wallet/worker_wallet.d.ts.map +1 -1
  149. package/dest/test-wallet/worker_wallet.js +2 -2
  150. package/dest/test-wallet/worker_wallet_schema.js +2 -1
  151. package/package.json +41 -41
  152. package/src/automine/README.md +60 -0
  153. package/src/automine/automine_test_context.ts +153 -0
  154. package/src/automine/delivery/interactive_handshake_responder.ts +125 -0
  155. package/src/automine/delivery/onchain_delivery_harness.ts +213 -0
  156. package/src/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.ts +19 -39
  157. package/src/{e2e_token_contract → automine/token}/token_contract_test.ts +24 -43
  158. package/src/automine/token/token_test_helpers.ts +138 -0
  159. package/src/bench/client_flows/benchmark.ts +3 -1
  160. package/src/bench/client_flows/client_flows_benchmark.ts +39 -12
  161. package/src/composed/ha/ha_full_setup.ts +466 -0
  162. package/src/fixtures/e2e_prover_test.ts +40 -23
  163. package/src/fixtures/fixtures.ts +14 -4
  164. package/src/fixtures/ha_setup.ts +7 -3
  165. package/src/fixtures/index.ts +1 -0
  166. package/src/fixtures/setup.ts +217 -146
  167. package/src/fixtures/setup_p2p_test.ts +3 -3
  168. package/src/fixtures/standard_contracts_genesis.ts +28 -0
  169. package/src/fixtures/timing.ts +97 -0
  170. package/src/fixtures/token_utils.ts +39 -4
  171. package/src/fixtures/wait_helpers.ts +333 -0
  172. package/src/forward-compatibility/wallet_service.ts +2 -2
  173. package/src/guides/up_quick_start.sh +5 -0
  174. package/src/infra/README.md +12 -0
  175. package/src/multi-node/README.md +96 -0
  176. package/src/multi-node/block-production/setup.ts +272 -0
  177. package/src/multi-node/governance/setup.ts +172 -0
  178. package/src/multi-node/multi_node_test_context.ts +447 -0
  179. package/src/multi-node/slashing/inactivity_setup.ts +139 -0
  180. package/src/multi-node/slashing/setup.ts +433 -0
  181. package/src/p2p/README.md +78 -0
  182. package/src/{e2e_p2p → p2p}/p2p_network.ts +36 -7
  183. package/src/{e2e_p2p → p2p}/reqresp/utils.ts +5 -14
  184. package/src/p2p/shared.ts +329 -0
  185. package/src/shared/cross_chain_test_harness.ts +22 -13
  186. package/src/shared/gas_portal_test_harness.ts +13 -5
  187. package/src/shared/submit-transactions.ts +13 -5
  188. package/src/shared/timing_env.d.mts +39 -0
  189. package/src/shared/timing_env.mjs +363 -0
  190. package/src/shared/wait_for_l1_to_l2_message.ts +1 -1
  191. package/src/simulators/lending_simulator.ts +1 -1
  192. package/src/single-node/README.md +66 -0
  193. package/src/{e2e_cross_chain_messaging → single-node/cross-chain}/cross_chain_messaging_test.ts +110 -39
  194. package/src/single-node/cross-chain/message_test_helpers.ts +125 -0
  195. package/src/{e2e_fees → single-node/fees}/bridging_race.notest.ts +19 -5
  196. package/src/{e2e_fees → single-node/fees}/fees_test.ts +141 -48
  197. package/src/single-node/l1-reorgs/setup.ts +93 -0
  198. package/src/single-node/partial-proofs/setup.ts +8 -0
  199. package/src/single-node/proving/setup.ts +15 -0
  200. package/src/single-node/recovery/setup.ts +8 -0
  201. package/src/single-node/setup.ts +63 -0
  202. package/src/single-node/single_node_test_context.ts +1054 -0
  203. package/src/spartan/setup_test_wallets.ts +23 -8
  204. package/src/spartan/tx_metrics.ts +26 -0
  205. package/src/test-wallet/test_wallet.ts +28 -6
  206. package/src/test-wallet/utils.ts +102 -5
  207. package/src/test-wallet/wallet_worker_script.ts +6 -3
  208. package/src/test-wallet/worker_wallet.ts +5 -9
  209. package/src/test-wallet/worker_wallet_schema.ts +1 -1
  210. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +0 -56
  211. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +0 -1
  212. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +0 -58
  213. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +0 -1
  214. package/dest/e2e_deploy_contract/deploy_test.d.ts +0 -36
  215. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +0 -1
  216. package/dest/e2e_deploy_contract/deploy_test.js +0 -42
  217. package/dest/e2e_epochs/epochs_test.d.ts +0 -137
  218. package/dest/e2e_epochs/epochs_test.d.ts.map +0 -1
  219. package/dest/e2e_epochs/epochs_test.js +0 -485
  220. package/dest/e2e_fees/bridging_race.notest.d.ts.map +0 -1
  221. package/dest/e2e_fees/fees_test.d.ts +0 -89
  222. package/dest/e2e_fees/fees_test.d.ts.map +0 -1
  223. package/dest/e2e_l1_publisher/write_json.d.ts +0 -11
  224. package/dest/e2e_l1_publisher/write_json.d.ts.map +0 -1
  225. package/dest/e2e_l1_publisher/write_json.js +0 -56
  226. package/dest/e2e_multi_validator/utils.d.ts +0 -12
  227. package/dest/e2e_multi_validator/utils.d.ts.map +0 -1
  228. package/dest/e2e_nested_contract/nested_contract_test.d.ts +0 -22
  229. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +0 -1
  230. package/dest/e2e_nested_contract/nested_contract_test.js +0 -40
  231. package/dest/e2e_p2p/inactivity_slash_test.d.ts +0 -31
  232. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +0 -1
  233. package/dest/e2e_p2p/inactivity_slash_test.js +0 -138
  234. package/dest/e2e_p2p/p2p_network.d.ts.map +0 -1
  235. package/dest/e2e_p2p/reqresp/utils.d.ts +0 -22
  236. package/dest/e2e_p2p/reqresp/utils.d.ts.map +0 -1
  237. package/dest/e2e_p2p/shared.d.ts +0 -75
  238. package/dest/e2e_p2p/shared.d.ts.map +0 -1
  239. package/dest/e2e_p2p/shared.js +0 -217
  240. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +0 -2
  241. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +0 -1
  242. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +0 -1
  243. package/dest/e2e_token_contract/token_contract_test.d.ts +0 -44
  244. package/dest/e2e_token_contract/token_contract_test.d.ts.map +0 -1
  245. package/src/e2e_deploy_contract/deploy_test.ts +0 -73
  246. package/src/e2e_epochs/epochs_test.ts +0 -596
  247. package/src/e2e_l1_publisher/write_json.ts +0 -77
  248. package/src/e2e_nested_contract/nested_contract_test.ts +0 -51
  249. package/src/e2e_p2p/inactivity_slash_test.ts +0 -181
  250. package/src/e2e_p2p/shared.ts +0 -332
  251. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.js +0 -0
  252. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.js +0 -0
  253. /package/dest/{e2e_multi_validator/utils.js → composed/web3signer/multi_validator_keystore_utils.js} +0 -0
  254. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof.json +0 -0
  255. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.ts +0 -0
  256. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.ts +0 -0
  257. /package/src/{e2e_multi_validator/utils.ts → composed/web3signer/multi_validator_keystore_utils.ts} +0 -0
@@ -0,0 +1,363 @@
1
+ import { appendFileSync, writeFileSync } from 'node:fs';
2
+ import { basename } from 'node:path';
3
+
4
+ import CustomEnvironment from '../../../foundation/src/jest/env.mjs';
5
+
6
+ // Per-test e2e timing environment. Gated entirely on the TEST_TIMING_FILE env var: when unset, this
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 folds in the named
9
+ // spans recorded via the `testSpan()` wrapper (fixtures/timing.ts) through a collector shared on
10
+ // `this.global`.
11
+ //
12
+ // Output is one JSONL file per worker process (the env runs once per worker). Each line carries a
13
+ // `type` discriminator and is one of:
14
+ // - `type: 'test'` (`name` set): beforeEach hooks, the it() body, afterEach hooks for one test; or
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.
25
+ export default class TimingEnvironment extends CustomEnvironment {
26
+ constructor(config, context) {
27
+ super(config, context);
28
+
29
+ this.timingFile = process.env.TEST_TIMING_FILE;
30
+ if (!this.timingFile) {
31
+ return;
32
+ }
33
+
34
+ this.suite = basename(context?.testPath ?? config?.testPath ?? 'unknown').replace(/\.test\.[cm]?[jt]s$/, '');
35
+ this.meta = {
36
+ commit: process.env.COMMIT_HASH ?? null,
37
+ branch: process.env.TARGET_BRANCH ?? process.env.REF_NAME ?? null,
38
+ runId: process.env.RUN_ID ?? null,
39
+ };
40
+
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: [] };
52
+ this.global.__e2eTimings = this.collector;
53
+
54
+ // Records to flush as JSONL on teardown. One per test plus one suite-scoped record.
55
+ this.records = [];
56
+ this.recordsByName = new Map();
57
+ // The suite-scoped record (beforeAll/afterAll); bodyMs/totalMs are computed at flush time.
58
+ this.suiteRecord = { name: null, status: 'passed', beforeHooksMs: 0, afterHooksMs: 0 };
59
+ // Start times keyed by hook type (beforeAll/beforeEach/afterAll/afterEach).
60
+ this.hookStarts = {};
61
+ this.testStarts = new Map();
62
+ // Guards against double-flushing (we flush on both the teardown event and the teardown method).
63
+ this.flushed = false;
64
+ // Raw per-occurrence spans retained only when TEST_TIMING_SPANS=1, emitted as `type:"span"` lines.
65
+ this.rawSpans = [];
66
+ }
67
+
68
+ // Flush on the teardown method too: the jest lifecycle always calls this, whereas the 'teardown'
69
+ // event is not reliably delivered when a test run is interrupted. Whichever fires first wins.
70
+ async teardown() {
71
+ this.finalizeAndFlush();
72
+ await super.teardown();
73
+ }
74
+
75
+ async handleTestEvent(event, state) {
76
+ // Run the base env first so its unhandledRejection patching for after-hooks stays intact.
77
+ await super.handleTestEvent(event, state);
78
+
79
+ if (!this.timingFile) {
80
+ return;
81
+ }
82
+
83
+ const now = Date.now();
84
+ switch (event.name) {
85
+ case 'hook_start': {
86
+ this.hookStarts[event.hook.type] = now;
87
+ break;
88
+ }
89
+ case 'hook_success':
90
+ case 'hook_failure': {
91
+ const start = this.hookStarts[event.hook.type];
92
+ if (start === undefined) {
93
+ break;
94
+ }
95
+ delete this.hookStarts[event.hook.type];
96
+ const ms = now - start;
97
+ if (event.hook.type === 'beforeEach') {
98
+ this.addToCurrent('beforeHooksMs', ms);
99
+ } else if (event.hook.type === 'afterEach') {
100
+ this.addToCurrent('afterHooksMs', ms);
101
+ } else if (event.hook.type === 'beforeAll') {
102
+ this.suiteRecord.beforeHooksMs += ms;
103
+ } else if (event.hook.type === 'afterAll') {
104
+ this.suiteRecord.afterHooksMs += ms;
105
+ }
106
+ break;
107
+ }
108
+ case 'test_start': {
109
+ const name = this.fullTestName(event.test);
110
+ const record = {
111
+ type: 'test',
112
+ name,
113
+ status: 'passed',
114
+ setupFnMs: 0,
115
+ beforeHooksMs: 0,
116
+ bodyMs: 0,
117
+ teardownFnMs: 0,
118
+ afterHooksMs: 0,
119
+ totalMs: 0,
120
+ startedAt: new Date(now).toISOString(),
121
+ };
122
+ this.records.push(record);
123
+ this.recordsByName.set(name, record);
124
+ this.testStarts.set(name, now);
125
+ this.collector.current = name;
126
+ break;
127
+ }
128
+ case 'test_fn_start': {
129
+ this.testStarts.set(`fn:${this.fullTestName(event.test)}`, now);
130
+ break;
131
+ }
132
+ case 'test_fn_success':
133
+ case 'test_fn_failure': {
134
+ const name = this.fullTestName(event.test);
135
+ const start = this.testStarts.get(`fn:${name}`);
136
+ const record = this.recordsByName.get(name);
137
+ if (record && start !== undefined) {
138
+ record.bodyMs = now - start;
139
+ }
140
+ if (record && event.name === 'test_fn_failure') {
141
+ record.status = 'failed';
142
+ }
143
+ break;
144
+ }
145
+ case 'test_done': {
146
+ const name = this.fullTestName(event.test);
147
+ const record = this.recordsByName.get(name);
148
+ const start = this.testStarts.get(name);
149
+ if (record && start !== undefined) {
150
+ record.totalMs = now - start;
151
+ }
152
+ if (record && event.test?.errors?.length) {
153
+ record.status = 'failed';
154
+ }
155
+ this.collector.current = null;
156
+ break;
157
+ }
158
+ case 'teardown': {
159
+ this.finalizeAndFlush();
160
+ break;
161
+ }
162
+ default:
163
+ break;
164
+ }
165
+ }
166
+
167
+ /** The record for the test currently running, if any. */
168
+ currentRecord() {
169
+ return this.collector.current ? this.recordsByName.get(this.collector.current) : undefined;
170
+ }
171
+
172
+ /** Adds `ms` to a hook bucket on the current per-test record, or the suite record during beforeAll/afterAll. */
173
+ addToCurrent(field, ms) {
174
+ const record = this.currentRecord();
175
+ if (record) {
176
+ record[field] += ms;
177
+ }
178
+ }
179
+
180
+ /** Builds the full test name by walking up the describe blocks, matching jest's currentTestName. */
181
+ fullTestName(test) {
182
+ if (!test) {
183
+ return null;
184
+ }
185
+ const parts = [];
186
+ let node = test;
187
+ while (node && node.name && node.name !== 'ROOT_DESCRIBE_BLOCK') {
188
+ parts.unshift(node.name);
189
+ node = node.parent;
190
+ }
191
+ return parts.join(' ');
192
+ }
193
+
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 = [];
203
+ }
204
+
205
+ /** Folds spans into records, finalizes the suite-scoped record, and writes all JSONL. */
206
+ finalizeAndFlush() {
207
+ if (this.flushed || !this.timingFile) {
208
+ return;
209
+ }
210
+ this.flushed = true;
211
+ this.foldSpans();
212
+
213
+ const lines = [];
214
+ for (const record of this.records) {
215
+ lines.push(this.toLine({ ...record }));
216
+ }
217
+ lines.push(
218
+ this.toLine({
219
+ type: 'suite',
220
+ name: null,
221
+ status: 'passed',
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,
228
+ }),
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
+ }
233
+
234
+ const payload = lines.join('\n') + '\n';
235
+ try {
236
+ // One file per worker process, but a worker may run several suites: append so we keep them all.
237
+ appendFileSync(this.timingFile, payload);
238
+ } catch {
239
+ try {
240
+ writeFileSync(this.timingFile, payload);
241
+ } catch {
242
+ // Timing is best-effort; never fail a test because we couldn't write the file.
243
+ }
244
+ }
245
+ }
246
+
247
+ /** Flattens metadata onto a record and serializes to a single JSON line, rounding all Ms fields. */
248
+ toLine(record) {
249
+ const obj = { suite: this.suite, ...record, ...this.meta };
250
+ for (const key of Object.keys(obj)) {
251
+ if (key.endsWith('Ms') && typeof obj[key] === 'number') {
252
+ obj[key] = Math.round(obj[key]);
253
+ }
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
+ }
265
+ return JSON.stringify(obj);
266
+ }
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
  }
@@ -208,7 +208,7 @@ export class LendingSimulator {
208
208
  expect(interestAccumulator).toEqual(this.accumulator);
209
209
  expect(asset['last_updated_ts']).toEqual(BigInt(this.time));
210
210
 
211
- for (const key of [this.account.address, AztecAddress.fromField(await this.account.key())]) {
211
+ for (const key of [this.account.address, AztecAddress.fromFieldUnsafe(await this.account.key())]) {
212
212
  const { result: privatePos } = await this.lendingContract.methods
213
213
  .get_position(key)
214
214
  .simulate({ from: this.account.address });
@@ -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). |