@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,433 @@
1
+ import type { AztecNodeService } from '@aztec/aztec-node';
2
+ import type { Logger } from '@aztec/aztec.js/log';
3
+ import type { RollupCheatCodes } from '@aztec/aztec/testing';
4
+ import type { EpochCacheInterface } from '@aztec/epoch-cache';
5
+ import type { RollupContract, SlashingProposerContract } from '@aztec/ethereum/contracts';
6
+ import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
7
+ import { unique } from '@aztec/foundation/collection';
8
+ import { EthAddress } from '@aztec/foundation/eth-address';
9
+ import { retryUntil } from '@aztec/foundation/retry';
10
+ import { pluralize } from '@aztec/foundation/string';
11
+ import { type OffenseType, getRoundForOffense } from '@aztec/slasher';
12
+ import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
13
+ import type { TxHash } from '@aztec/stdlib/tx';
14
+
15
+ import { jest } from '@jest/globals';
16
+
17
+ import { testSpan } from '../../fixtures/timing.js';
18
+ import { submitTxsTo } from '../../shared/submit-transactions.js';
19
+ import type { TestWallet } from '../../test-wallet/test_wallet.js';
20
+ import type { MultiNodeTestContext } from '../multi_node_test_context.js';
21
+
22
+ const TEST_TIMEOUT = 600_000; // 10 minutes
23
+
24
+ jest.setTimeout(TEST_TIMEOUT);
25
+
26
+ export const NUM_VALIDATORS = 4;
27
+ export const COMMITTEE_SIZE = NUM_VALIDATORS;
28
+ export const ETHEREUM_SLOT_DURATION = 8;
29
+ export const AZTEC_SLOT_DURATION = ETHEREUM_SLOT_DURATION * 3;
30
+ export const BLOCK_DURATION = 4;
31
+
32
+ // Small slashing unit so we don't kick anyone out.
33
+ export const slashingUnit = BigInt(1e14);
34
+ export const slashingQuorum = 3;
35
+ export const slashingRoundSize = 4;
36
+ export const aztecEpochDuration = 2;
37
+
38
+ /**
39
+ * The shared per-test slashing config for the offense-detection suites (`duplicate_proposal`,
40
+ * `duplicate_attestation`). Spread into a {@link MultiNodeTestContext.setup} call alongside
41
+ * {@link SLASHER_ENABLED_MULTI_VALIDATOR_OPTS} and `initialValidators` (from `buildMockGossipValidators`).
42
+ */
43
+ export const baseSlashingOpts = {
44
+ anvilSlotsInAnEpoch: 4,
45
+ listenAddress: '127.0.0.1',
46
+ aztecEpochDuration,
47
+ ethereumSlotDuration: ETHEREUM_SLOT_DURATION,
48
+ aztecSlotDuration: AZTEC_SLOT_DURATION,
49
+ aztecTargetCommitteeSize: COMMITTEE_SIZE,
50
+ aztecProofSubmissionEpochs: 1024, // effectively do not reorg
51
+ slashInactivityConsecutiveEpochThreshold: 32, // effectively do not slash for inactivity
52
+ minTxsPerBlock: 0, // always be building
53
+ slashingQuorum,
54
+ slashingRoundSizeInEpochs: slashingRoundSize / aztecEpochDuration,
55
+ slashAmountSmall: slashingUnit,
56
+ slashAmountMedium: slashingUnit * 2n,
57
+ slashAmountLarge: slashingUnit * 3n,
58
+ blockDurationMs: BLOCK_DURATION * 1000,
59
+ slashDuplicateProposalPenalty: slashingUnit,
60
+ slashingOffsetInRounds: 1,
61
+ };
62
+
63
+ /**
64
+ * The fast slot timing shared by the sentinel-observation suites (`sentinel_status_slash`,
65
+ * `validators_sentinel`, `multiple_validators_sentinel`, `slash_veto_demo`). Slots are 8s (eth 4s ×
66
+ * epoch 2), which fit a checkpoint comfortably at the fast mocked-p2p operational budgets used at
67
+ * eth<8, keeping wall-clock down for tests whose bodies advance through real L2 slots. Spread into a
68
+ * {@link MultiNodeTestContext.setup} call alongside {@link SLASHER_ENABLED_MULTI_VALIDATOR_OPTS},
69
+ * `initialValidators`, and the per-test slash/penalty config. Non-sentinel offense-detection files
70
+ * that only need the same fast timing spread this and override `sentinelEnabled: false`.
71
+ */
72
+ export const SENTINEL_TIMING = {
73
+ anvilSlotsInAnEpoch: 4,
74
+ listenAddress: '127.0.0.1',
75
+ ethereumSlotDuration: 4,
76
+ aztecSlotDuration: 8,
77
+ aztecEpochDuration: 2,
78
+ sentinelEnabled: true,
79
+ } as const;
80
+
81
+ /** A single detected slash offense as returned by {@link AztecNodeService.getSlashOffenses}. */
82
+ export type SlashOffense = Awaited<ReturnType<AztecNodeService['getSlashOffenses']>>[number];
83
+
84
+ /** Looks up the offense recorded for `validator` of `offenseType` at `slot`, if any. */
85
+ export function findSlashOffense(
86
+ offenses: SlashOffense[],
87
+ validator: EthAddress,
88
+ offenseType: OffenseType,
89
+ slot: SlotNumber,
90
+ ): SlashOffense | undefined {
91
+ return offenses.find(
92
+ offense =>
93
+ offense.validator.equals(validator) &&
94
+ offense.offenseType === offenseType &&
95
+ offense.epochOrSlot === BigInt(slot),
96
+ );
97
+ }
98
+
99
+ export function awaitProposalExecution(
100
+ slashingProposer: SlashingProposerContract,
101
+ timeoutSeconds: number,
102
+ logger: Logger,
103
+ ): Promise<bigint> {
104
+ return testSpan(
105
+ 'wait:slash-execution',
106
+ () =>
107
+ new Promise<bigint>((resolve, reject) => {
108
+ const timeout = setTimeout(() => {
109
+ logger.warn(`Timed out waiting for proposal execution`);
110
+ reject(new Error(`Timeout waiting for proposal execution after ${timeoutSeconds}s`));
111
+ }, timeoutSeconds * 1000);
112
+
113
+ const unwatch = slashingProposer.listenToRoundExecuted(args => {
114
+ logger.warn(`Slash from round ${args.round} executed`);
115
+ clearTimeout(timeout);
116
+ unwatch();
117
+ resolve(args.round);
118
+ });
119
+ }),
120
+ );
121
+ }
122
+
123
+ export async function awaitCommitteeExists({
124
+ rollup,
125
+ logger,
126
+ }: {
127
+ rollup: RollupContract;
128
+ logger: Logger;
129
+ }): Promise<readonly `0x${string}`[]> {
130
+ logger.info(`Waiting for committee to be set`);
131
+ let committee: EthAddress[] | undefined;
132
+ await testSpan('wait:committee', () =>
133
+ retryUntil(
134
+ async () => {
135
+ committee = await rollup.getCurrentEpochCommittee();
136
+ return committee && committee.length > 0;
137
+ },
138
+ 'non-empty committee',
139
+ 60,
140
+ ),
141
+ );
142
+ logger.warn(`Committee has been formed`, { committee: committee!.map(c => c.toString()) });
143
+ return committee!.map(c => c.toString() as `0x${string}`);
144
+ }
145
+
146
+ /**
147
+ * Scans L2 slots forward from `minLeadSlots` ahead of the current slot, returning the first slot in
148
+ * which `targetProposer` is the proposer.
149
+ *
150
+ * Scanning starts at `currentSlot + minLeadSlots` and only ever moves forward, so every returned slot
151
+ * is at least `minLeadSlots` ahead — a caller can safely warp to `targetSlot - minLeadSlots` for a
152
+ * settle buffer without risking a backwards warp. Stepping by a single slot examines both epoch
153
+ * parities, which matters because the per-slot proposer is a different RANDAO-shuffled committee
154
+ * member: searching only a fixed offset within each epoch can leave a 1-of-N target unexamined when
155
+ * the epoch is short. A candidate in an epoch whose committee isn't sampled yet makes the proposer
156
+ * lookup revert with EpochNotStable; this warps one epoch forward and continues, keeping the
157
+ * candidate at least `minLeadSlots` ahead of the new current slot. Throws after `maxSlotsToScan`.
158
+ *
159
+ * Unlike {@link advanceToEpochBeforeProposer}, this does not stop an epoch early — callers that want
160
+ * to warp close to the target (rather than stage sequencers an epoch ahead) use this and warp the
161
+ * final `minLeadSlots` in themselves.
162
+ */
163
+ export function findUpcomingProposerSlot({
164
+ epochCache,
165
+ cheatCodes,
166
+ targetProposer,
167
+ logger,
168
+ minLeadSlots,
169
+ maxSlotsToScan = 100,
170
+ }: {
171
+ epochCache: EpochCacheInterface;
172
+ cheatCodes: RollupCheatCodes;
173
+ targetProposer: EthAddress;
174
+ logger: Logger;
175
+ minLeadSlots: number;
176
+ maxSlotsToScan?: number;
177
+ }): Promise<SlotNumber> {
178
+ return testSpan('warp:find-proposer', async () => {
179
+ let candidate = Number(await cheatCodes.getSlot()) + minLeadSlots;
180
+
181
+ for (let scanned = 0; scanned < maxSlotsToScan; scanned++) {
182
+ let proposer: EthAddress | undefined;
183
+ try {
184
+ proposer = await epochCache.getProposerAttesterAddressInSlot(SlotNumber(candidate));
185
+ } catch (err) {
186
+ if (!(err instanceof Error) || !err.message.includes('EpochNotStable')) {
187
+ throw err;
188
+ }
189
+ await cheatCodes.advanceToNextEpoch();
190
+ const newCurrentSlot = Number(await cheatCodes.getSlot());
191
+ // Keep the lead after the warp: never return a slot we could no longer warp ahead of.
192
+ candidate = Math.max(candidate, newCurrentSlot + minLeadSlots);
193
+ continue;
194
+ }
195
+
196
+ if (proposer && proposer.equals(targetProposer)) {
197
+ logger.warn(`Found target proposer ${targetProposer} at slot ${candidate}`);
198
+ return SlotNumber(candidate);
199
+ }
200
+ candidate++;
201
+ }
202
+
203
+ throw new Error(`Target proposer ${targetProposer} not found within ${maxSlotsToScan} slots`);
204
+ });
205
+ }
206
+
207
+ /**
208
+ * Advance epochs until we find one where the target proposer is selected for a slot at least
209
+ * `warmupSlots` into the epoch, then stop one epoch before it. This leaves time for the caller to
210
+ * start sequencers before warping to the target epoch, avoiding the race where the target epoch
211
+ * passes before sequencers are ready.
212
+ *
213
+ * The first `warmupSlots` slots of the epoch are skipped on purpose. Callers warp to one slot
214
+ * before the target epoch and, under proposer pipelining, the proposer begins building one slot
215
+ * before its proposal slot. If the proposer were in the first slot of the epoch, that build would
216
+ * begin at the exact instant of the warp, leaving the freshly-started sequencer no warm-up margin;
217
+ * it then serializes its (often AVM-heavy) proposal past the slot boundary and honest receivers
218
+ * reject it as late. Picking a slot at least `warmupSlots` into the epoch guarantees that many full
219
+ * slots of wall-clock between the warp and the start of the proposer's build.
220
+ *
221
+ * Returns the target epoch and the concrete target slot so the caller can warp to it after starting
222
+ * sequencers.
223
+ *
224
+ * The default `maxAttempts` accounts for the worst-case caller: with a 2-slot epoch and
225
+ * `warmupSlots = 1`, each attempt checks a single slot, and with a 4-member committee the target is
226
+ * the proposer with probability 1/4 per attempt (proposer index is keccak(epoch, slot, seed) mod
227
+ * committee size, so attempts are independent). 50 attempts bound the miss probability at
228
+ * (3/4)^50 ≈ 6e-7; each attempt is just a committee query plus an anvil warp, so the extra headroom
229
+ * costs almost nothing.
230
+ */
231
+ export function advanceToEpochBeforeProposer({
232
+ epochCache,
233
+ cheatCodes,
234
+ targetProposer,
235
+ logger,
236
+ maxAttempts = 50,
237
+ warmupSlots = 1,
238
+ }: {
239
+ epochCache: EpochCacheInterface;
240
+ cheatCodes: RollupCheatCodes;
241
+ targetProposer: EthAddress;
242
+ logger: Logger;
243
+ maxAttempts?: number;
244
+ warmupSlots?: number;
245
+ }): Promise<{ targetEpoch: EpochNumber; targetSlot: SlotNumber }> {
246
+ return testSpan('warp:find-proposer', async () => {
247
+ const { epochDuration } = await cheatCodes.getConfig();
248
+
249
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
250
+ const currentEpoch = await cheatCodes.getEpoch();
251
+ // Check the NEXT epoch's slots so we stay one epoch before the target,
252
+ // giving the caller time to start sequencers before the target epoch arrives.
253
+ const nextEpoch = Number(currentEpoch) + 1;
254
+ const epochStartSlot = nextEpoch * Number(epochDuration);
255
+ // Skip the first `warmupSlots` slots so the caller keeps a warm-up margin after warping to one
256
+ // slot before the epoch (see the doc comment above).
257
+ const startSlot = epochStartSlot + warmupSlots;
258
+ const endSlot = epochStartSlot + Number(epochDuration);
259
+
260
+ logger.info(
261
+ `Checking next epoch ${nextEpoch} (slots ${startSlot}-${endSlot - 1}) for proposer ${targetProposer} (current epoch: ${currentEpoch})`,
262
+ );
263
+
264
+ for (let s = startSlot; s < endSlot; s++) {
265
+ const proposer = await epochCache.getProposerAttesterAddressInSlot(SlotNumber(s));
266
+ if (proposer && proposer.equals(targetProposer)) {
267
+ logger.warn(
268
+ `Found target proposer ${targetProposer} in slot ${s} of epoch ${nextEpoch}. Staying at epoch ${currentEpoch} to allow sequencer startup.`,
269
+ );
270
+ return { targetEpoch: EpochNumber(nextEpoch), targetSlot: SlotNumber(s) };
271
+ }
272
+ }
273
+
274
+ logger.info(`Target proposer not found in epoch ${nextEpoch}, advancing to next epoch`);
275
+ await cheatCodes.advanceToNextEpoch();
276
+ }
277
+
278
+ throw new Error(`Target proposer ${targetProposer} not found in any slot after ${maxAttempts} epoch attempts`);
279
+ });
280
+ }
281
+
282
+ export async function awaitOffenseDetected({
283
+ logger,
284
+ nodeAdmin,
285
+ slashingRoundSize,
286
+ epochDuration,
287
+ waitUntilOffenseCount,
288
+ timeoutSeconds = 120,
289
+ }: {
290
+ nodeAdmin: AztecNodeAdmin;
291
+ logger: Logger;
292
+ slashingRoundSize: number;
293
+ epochDuration: number;
294
+ waitUntilOffenseCount?: number;
295
+ timeoutSeconds?: number;
296
+ }) {
297
+ const targetOffenseCount = waitUntilOffenseCount ?? 1;
298
+ logger.warn(`Waiting for ${pluralize('offense', targetOffenseCount)} to be detected`);
299
+ const offenses = await testSpan('wait:offense', () =>
300
+ retryUntil(
301
+ async () => {
302
+ const offenses = await nodeAdmin.getSlashOffenses('all');
303
+ if (offenses.length >= targetOffenseCount) {
304
+ return offenses;
305
+ }
306
+ },
307
+ 'non-empty offenses',
308
+ timeoutSeconds,
309
+ ),
310
+ );
311
+ logger.info(
312
+ `Hit ${offenses.length} offenses on rounds ${unique(offenses.map(o => getRoundForOffense(o, { slashingRoundSize, epochDuration })))}`,
313
+ { offenses },
314
+ );
315
+ return offenses;
316
+ }
317
+
318
+ /**
319
+ * Await the committee to be slashed out of the validator set.
320
+ * Currently assumes that the committee is the same size as the validator set.
321
+ */
322
+ export async function awaitCommitteeKicked({
323
+ rollup,
324
+ cheatCodes,
325
+ committee,
326
+ slashingProposer,
327
+ slashingRoundSize,
328
+ aztecSlotDuration,
329
+ aztecEpochDuration,
330
+ logger,
331
+ offenseEpoch,
332
+ }: {
333
+ rollup: RollupContract;
334
+ cheatCodes: RollupCheatCodes;
335
+ committee: readonly `0x${string}`[];
336
+ slashingProposer: SlashingProposerContract | undefined;
337
+ slashingRoundSize: number;
338
+ aztecSlotDuration: number;
339
+ aztecEpochDuration: number;
340
+ logger: Logger;
341
+ offenseEpoch: number;
342
+ }) {
343
+ if (!slashingProposer) {
344
+ throw new Error('No slashing proposer configured. Cannot test slashing.');
345
+ }
346
+
347
+ await testSpan('wait:committee-kicked', async () => {
348
+ await cheatCodes.debugRollup();
349
+
350
+ // Use the slash offset to ensure we are in the right epoch for tally
351
+ const slashOffsetInRounds = await slashingProposer.getSlashOffsetInRounds();
352
+ const slashingRoundSizeInEpochs = slashingRoundSize / aztecEpochDuration;
353
+ const slashingOffsetInEpochs = Number(slashOffsetInRounds) * slashingRoundSizeInEpochs;
354
+ const firstEpochInOffenseRound = offenseEpoch - (offenseEpoch % slashingRoundSizeInEpochs);
355
+ const targetEpoch = firstEpochInOffenseRound + slashingOffsetInEpochs;
356
+ logger.info(`Advancing to epoch ${targetEpoch} so we start slashing`);
357
+ await cheatCodes.advanceToEpoch(EpochNumber(targetEpoch), { offset: -aztecSlotDuration / 2 });
358
+
359
+ const attestersPre = await rollup.getAttesters();
360
+ expect(attestersPre.length).toBe(committee.length);
361
+
362
+ for (const attester of attestersPre) {
363
+ const attesterInfo = await rollup.getAttesterView(attester);
364
+ expect(attesterInfo.status).toEqual(1); // Validating
365
+ }
366
+
367
+ // Allow up to four round-lengths so that under proposer pipelining, where individual rounds
368
+ // sometimes fail to gather quorum because parts of the committee miss votes due to chain-state
369
+ // races, we still see a later round execute the slash.
370
+ const timeout = slashingRoundSize * 4 * aztecSlotDuration + 30;
371
+ logger.info(`Waiting for slash to be executed (timeout ${timeout}s)`);
372
+ await awaitProposalExecution(slashingProposer, timeout, logger);
373
+
374
+ // The attesters should still form the committee but they should be reduced to the "living" status
375
+ await cheatCodes.debugRollup();
376
+ const committeePostSlashing = await rollup.getCurrentEpochCommittee();
377
+ expect(committeePostSlashing?.length).toBe(attestersPre.length);
378
+
379
+ const attestersPostSlashing = await rollup.getAttesters();
380
+ expect(attestersPostSlashing.length).toBe(0);
381
+
382
+ for (const attester of attestersPre) {
383
+ const attesterInfo = await rollup.getAttesterView(attester);
384
+ expect(attesterInfo.status).toEqual(2); // Living
385
+ }
386
+
387
+ logger.info(`Advancing to check current committee`);
388
+ await cheatCodes.debugRollup();
389
+ await cheatCodes.advanceToEpoch(
390
+ EpochNumber((await cheatCodes.getEpoch()) + (await rollup.getLagInEpochsForValidatorSet()) + 1),
391
+ );
392
+ await cheatCodes.debugRollup();
393
+
394
+ const committeeNextEpoch = await rollup.getCurrentEpochCommittee();
395
+ // The committee should be undefined, since the validator set is empty
396
+ // and the tests currently using this helper always set a target committee size.
397
+ expect(committeeNextEpoch).toBeUndefined();
398
+
399
+ const attestersNextEpoch = await rollup.getAttesters();
400
+ expect(attestersNextEpoch.length).toBe(0);
401
+ });
402
+ }
403
+
404
+ /** Resolves the slot at which `node` includes `txHash`, by reading the tx receipt and block header. */
405
+ export async function getMinedSlot(node: AztecNodeService, txHash: { toString(): string }): Promise<number> {
406
+ const receipt = await node.getTxReceipt(txHash as any);
407
+ if (!receipt.blockNumber) {
408
+ throw new Error(`Tx ${txHash} has no block number on receipt`);
409
+ }
410
+ const block = await node.getBlock(receipt.blockNumber);
411
+ if (!block) {
412
+ throw new Error(`Block ${receipt.blockNumber} not found`);
413
+ }
414
+ return Number(block.header.getSlot());
415
+ }
416
+
417
+ /**
418
+ * Submits `numTxs` account-deployment transactions through `node`, paying with the funded hardcoded
419
+ * account (`context.accounts[0]`). Repoints the context wallet at `node` so the txs land in that node's
420
+ * mempool. The mock-gossip equivalent of the old `submitTransactions(logger, node, numTxs, fundedAccount)`
421
+ * helper, which built a fresh wallet from the funded account.
422
+ */
423
+ export function submitTxsThroughNode(
424
+ test: MultiNodeTestContext,
425
+ node: AztecNodeService,
426
+ numTxs: number,
427
+ ): Promise<TxHash[]> {
428
+ const wallet = test.context.wallet as TestWallet;
429
+ wallet.updateNode(node);
430
+ return submitTxsTo(wallet, test.context.accounts[0], numTxs, test.logger);
431
+ }
432
+
433
+ export { jest };
@@ -0,0 +1,78 @@
1
+ # `p2p` e2e test category
2
+
3
+ P2P tests run a network of validator nodes over **real libp2p** — a real bootstrap node, discv5
4
+ discovery, the GossipSub mesh, the req/resp protocol, and real peer authentication and transport. This
5
+ is the category for any test whose subject is the networking layer itself: peer discovery and
6
+ rediscovery, gossip mesh formation and propagation, req/resp fetching, preferred-peer / supernode
7
+ topologies, and peer auth gating.
8
+
9
+ Tests whose subject — proposals, attestations, checkpointing, pruning/recovery, offense detection,
10
+ sentinel observability — is faithfully reproduced by the in-memory `MockGossipSubNetwork` bus belong in
11
+ the `multi-node` category instead, which is far cheaper to run. Only reach for `p2p` when the behavior
12
+ under test genuinely cannot be reproduced without real networking.
13
+
14
+ ## Entrypoint
15
+
16
+ `P2PNetworkTest` (`p2p_network.ts`) is the env-builder for this category. Unlike `MultiNodeTestContext`,
17
+ it does **not** extend `SingleNodeTestContext`; it is a parallel, self-contained builder that calls the
18
+ root `setup()` directly, then spawns real-libp2p nodes via the factories in
19
+ `../fixtures/setup_p2p_test.ts`. Its distinguishing traits:
20
+
21
+ - A real bootstrap node (`addBootstrapNode`) with a fixed private key, so nodes discover each other via
22
+ discv5 and data directories can be reused across a restart.
23
+ - Two validator-registration paths: `applyBaseSetup()` registers the committee post-genesis via the
24
+ on-chain `MultiAdder` cheat (validators are added at `aztecTargetCommitteeSize: 0`, then activated by
25
+ warping past the validator-set lag), while tests that exercise the real onboarding flow call
26
+ `addBootstrapNode()` and register each validator through the CLI `addL1Validator` path instead.
27
+ - `waitForP2PMeshConnectivity(nodes, …)` — waits for peer connections and for the GossipSub mesh to
28
+ form on the requested topics; callers that need a proposal to reach the whole committee within a slot
29
+ raise `minMeshPeerCount` for a full mesh.
30
+ - Data-directory management: `setup()` creates one root temp dir; `dataDirFor(label)` hands out a nested
31
+ per-role path (`createNodes` appends `-<index>`, single-node factories use it verbatim); `teardown()`
32
+ removes the whole tree in one recursive delete. Test files never `mkdtemp`/`rmSync` themselves.
33
+ - One named timing preset: `SHORTENED_BLOCK_TIME_CONFIG_NO_PRUNES` (ethSlot 4s, aztecSlot 12s,
34
+ `aztecProofSubmissionEpochs: 640` so the chain effectively never prunes), used by every file with
35
+ per-file slot/epoch overrides. `WAIT_FOR_TX_TIMEOUT` derives from the env slot duration.
36
+
37
+ ## Shared skeleton and helpers
38
+
39
+ `shared.ts` holds the common scenario skeleton and the reusable building blocks, so test bodies read
40
+ declaratively rather than re-deriving the same ~40 lines of node-creation / mesh-wait / signer-check
41
+ boilerplate:
42
+
43
+ - `runGossipScenario(opts)` — the shared bootstrap→createNodes→mesh→account→(submit)→verify skeleton.
44
+ Each varying part is a callback/flag: validator registration (`beforeCreateNodes`), extra prover /
45
+ monitor nodes (`createExtraNodes`), pre-submit waits (`beforeSubmit`), mesh parameters (`mesh`),
46
+ whether/how many txs to submit (`txsPerNode`, `submitSequentially`), which published checkpoint to
47
+ read signers from (`checkpointSource`), and scenario-specific verification (`afterVerify`).
48
+ - `verifyAttestationSigners(t, nodes, checkpoint)` — recovers the attestation signers from a published
49
+ checkpoint and asserts each belongs to the validator set; returns the signers for extra assertions.
50
+ - `getPublishedCheckpointForTx(node, txHash)` / `waitForFirstPublishedCheckpoint(t, nodes)` — resolve
51
+ the published checkpoint to read signers from, either from a mined tx's block or by polling for the
52
+ first one indexed by the archiver.
53
+ - `waitForNodesToSync(t, nodes)` — wait for every node to catch up to the initial node's tip.
54
+ - `maybeCheckQosAlerts(logger)` — run the QoS Grafana alert check when `CHECK_ALERTS=true`, else a no-op.
55
+ - `submitTransactions` / `submitComplexTxsTo` / `prepareTransactions` — build a throwaway wallet on a
56
+ node and submit (or pre-prove) N txs through it.
57
+
58
+ Node factories live in `../fixtures/setup_p2p_test.ts` (`createNodes`, `createNode`,
59
+ `createNonValidatorNode`, `createProverNode`, `createValidatorConfig`, `generatePrivateKeys`), shared
60
+ with `P2PNetworkTest`.
61
+
62
+ ## Organizing principle
63
+
64
+ Each file is one real-libp2p scenario the mock-gossip bus cannot reproduce, with a single top-level
65
+ `describe` named `e2e_p2p_*`. Files are plain `*.test.ts` (no `.parallel` suffix): each is one CI
66
+ container running the whole file. Because the nodes bind **fixed UDP/TCP ports**, two p2p test files
67
+ must never run at the same time — run them one at a time locally.
68
+
69
+ ## Files
70
+
71
+ | File | Scenario |
72
+ |---|---|
73
+ | `gossip_network.test.ts` | The baseline gossip test, two describes on the shared skeleton: `cheat-registered validators` (4 validators + a p2p-only prover + a re-execution monitor; txs mine from every node, attestation signers match the committee, and the prover produces a proven block by collecting txs over p2p) and `on-chain-registered validators (no cheats)` (validators registered via the real `addL1Validator` CLI path with a ZkPassport mock proof, then the same propagation/signer checks). |
74
+ | `fee_asset_price_oracle_gossip.test.ts` | A fee-asset price set on a mock L1 `StateView` contract gossips through the validator network and the rollup's on-chain price converges on it across two adjustments. Runs on the shared skeleton with `txsPerNode: 0` — no txs are submitted; empty blocks carry the price. |
75
+ | `late_prover_tx_collection.test.ts` | A prover that joins after a block was already mined learns the block from its archiver (via L1 sync) but is missing the txs, and must fetch them from peers over the req/resp `BLOCK_TXS` path — the same path `ProverNode.gatherTxs` takes when preparing an epoch proof. |
76
+ | `preferred_gossip_network.test.ts` | A preferred-node (supernode) topology: preferred nodes accept only validator connections, a no-discovery validator reaches the network exclusively through them, and gossip monitors assert traffic flows only through the expected peers. Verifies exact per-role peer counts, tx mining, and attestation signers. |
77
+ | `rediscovery.test.ts` | Nodes form a mesh, then the bootstrap node and all validators are stopped and restarted from their data directories with no bootstrap ENR — they rejoin purely from the discv5 peer tables they persisted to disk. |
78
+ | `reqresp/reqresp.test.ts` | Tx gossip is disabled on the upcoming proposer nodes, so they must request the missing tx data over req/resp before they can attest; also asserts a multiple-blocks-per-slot checkpoint is produced with correctly ordered blocks. The scenario body lives in `reqresp/utils.ts`. |
@@ -25,7 +25,10 @@ import type { GenesisData } from '@aztec/stdlib/world-state';
25
25
  import { ZkPassportProofParams } from '@aztec/stdlib/zkpassport';
26
26
  import { getGenesisValues } from '@aztec/world-state/testing';
27
27
 
28
+ import fs from 'fs';
28
29
  import getPort from 'get-port';
30
+ import os from 'os';
31
+ import path from 'path';
29
32
  import { type GetContractReturnType, getAddress, getContract } from 'viem';
30
33
  import { privateKeyToAccount } from 'viem/accounts';
31
34
 
@@ -46,6 +49,7 @@ import {
46
49
  createValidatorConfig,
47
50
  generatePrivateKeys,
48
51
  } from '../fixtures/setup_p2p_test.js';
52
+ import { getStandardContractGenesisNullifiers } from '../fixtures/standard_contracts_genesis.js';
49
53
  import { getEndToEndTestTelemetryClient } from '../fixtures/with_telemetry_utils.js';
50
54
  import type { TestWallet } from '../test-wallet/test_wallet.js';
51
55
 
@@ -84,6 +88,9 @@ export class P2PNetworkTest {
84
88
 
85
89
  public bootstrapNode?: BootstrapNode;
86
90
 
91
+ // Root temp directory holding every node's data dir. Created in setup(), removed in teardown().
92
+ public dataDir!: string;
93
+
87
94
  // Store setup options for use in setup()
88
95
  private setupOptions: SetupOptions;
89
96
  private deployL1ContractsArgs: any;
@@ -194,6 +201,19 @@ export class P2PNetworkTest {
194
201
  return this.hardcodedAccountData;
195
202
  }
196
203
 
204
+ /**
205
+ * Returns a per-role data directory nested under this test's root data dir. The multi-node factories
206
+ * (`createNodes`) append `-<index>` to this base for each node they spawn; single-node factories
207
+ * (`createProverNode`, `createNonValidatorNode`, `createNode`) use it verbatim. Everything lives under
208
+ * `this.dataDir`, so a single recursive remove in teardown() cleans up all of it.
209
+ */
210
+ dataDirFor(label: string): string {
211
+ if (!this.dataDir) {
212
+ throw new Error('Call setup to initialize the data directory.');
213
+ }
214
+ return path.join(this.dataDir, label);
215
+ }
216
+
197
217
  async addBootstrapNode() {
198
218
  this.logger.info('Adding bootstrap node');
199
219
  const telemetry = await getEndToEndTestTelemetryClient(this.metricsPort);
@@ -356,6 +376,8 @@ export class P2PNetworkTest {
356
376
  async setup() {
357
377
  this.logger.info('Setting up subsystems from fresh');
358
378
 
379
+ this.dataDir = fs.mkdtempSync(path.join(os.tmpdir(), `${this.testName}-`));
380
+
359
381
  // Pre-compute hardcoded account data so it gets funded in genesis.
360
382
  const contract = new SchnorrHardcodedKeyAccountContract();
361
383
  const secret = Fr.random();
@@ -394,6 +416,7 @@ export class P2PNetworkTest {
394
416
  undefined,
395
417
  undefined,
396
418
  this.context.genesis!.genesisTimestamp,
419
+ await getStandardContractGenesisNullifiers(),
397
420
  );
398
421
  this.genesis = genesis;
399
422
 
@@ -431,6 +454,7 @@ export class P2PNetworkTest {
431
454
  timeoutSeconds = 30,
432
455
  checkIntervalSeconds = 0.1,
433
456
  topics: TopicType[] = [TopicType.tx],
457
+ minMeshPeerCount = 1,
434
458
  ) {
435
459
  const nodeCount = expectedNodeCount ?? nodes.length;
436
460
  const minPeerCount = nodeCount - 1;
@@ -457,11 +481,13 @@ export class P2PNetworkTest {
457
481
 
458
482
  this.logger.warn('All nodes connected to P2P mesh');
459
483
 
460
- // Wait for GossipSub mesh to form for all specified topics.
461
- // We only require at least 1 mesh peer per node because GossipSub
462
- // stops grafting once it reaches Dlo peers and won't fill the mesh to all available peers.
484
+ // Wait for the GossipSub mesh to form for all specified topics. By default we only require at
485
+ // least 1 mesh peer per node, since GossipSub stops grafting once it reaches Dlo peers and won't
486
+ // fill the mesh to every available peer. Callers that need a proposal to reach the whole
487
+ // committee within a slot (e.g. quorum-from-genesis tests) raise `minMeshPeerCount` so the mesh
488
+ // is fully formed — a single mesh peer can leave some committee members unreached at first.
463
489
  for (const topic of topics) {
464
- this.logger.warn(`Waiting for GossipSub mesh to form for ${topic} topic...`);
490
+ this.logger.warn(`Waiting for GossipSub mesh (>= ${minMeshPeerCount} peers per node) for ${topic} topic...`);
465
491
  await Promise.all(
466
492
  nodes.map(async (node, index) => {
467
493
  const p2p = node.getP2P();
@@ -469,15 +495,15 @@ export class P2PNetworkTest {
469
495
  async () => {
470
496
  const meshPeers = await p2p.getGossipMeshPeerCount(topic);
471
497
  this.logger.debug(`Node ${index} has ${meshPeers} gossip mesh peers for ${topic} topic`);
472
- return meshPeers >= 1 ? true : undefined;
498
+ return meshPeers >= minMeshPeerCount ? true : undefined;
473
499
  },
474
- `Node ${index} to have gossip mesh peers for ${topic} topic`,
500
+ `Node ${index} to have >= ${minMeshPeerCount} gossip mesh peers for ${topic} topic`,
475
501
  timeoutSeconds,
476
502
  checkIntervalSeconds,
477
503
  );
478
504
  }),
479
505
  );
480
- this.logger.warn(`All nodes have gossip mesh peers for ${topic} topic`);
506
+ this.logger.warn(`All nodes have >= ${minMeshPeerCount} gossip mesh peers for ${topic} topic`);
481
507
  }
482
508
  }
483
509
 
@@ -485,6 +511,9 @@ export class P2PNetworkTest {
485
511
  await this.monitor.stop();
486
512
  await tryStop(this.bootstrapNode, this.logger);
487
513
  await teardown(this.context);
514
+ if (this.dataDir) {
515
+ fs.rmSync(this.dataDir, { recursive: true, force: true, maxRetries: 3 });
516
+ }
488
517
  }
489
518
 
490
519
  async getContracts(): Promise<{