@aztec/end-to-end 3.0.0-canary.a9708bd → 3.0.0-manual.20251030

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 (139) hide show
  1. package/dest/bench/client_flows/benchmark.d.ts +3 -2
  2. package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
  3. package/dest/bench/client_flows/benchmark.js +2 -2
  4. package/dest/bench/client_flows/client_flows_benchmark.d.ts +16 -12
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  6. package/dest/bench/client_flows/client_flows_benchmark.js +54 -58
  7. package/dest/bench/client_flows/data_extractor.js +3 -3
  8. package/dest/bench/utils.d.ts +2 -11
  9. package/dest/bench/utils.d.ts.map +1 -1
  10. package/dest/bench/utils.js +10 -34
  11. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +7 -7
  12. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  13. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +42 -42
  14. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +10 -8
  15. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  16. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +31 -33
  17. package/dest/e2e_deploy_contract/deploy_test.d.ts +10 -4
  18. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  19. package/dest/e2e_deploy_contract/deploy_test.js +9 -18
  20. package/dest/e2e_epochs/epochs_test.d.ts +9 -3
  21. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  22. package/dest/e2e_epochs/epochs_test.js +19 -13
  23. package/dest/e2e_fees/bridging_race.notest.js +12 -9
  24. package/dest/e2e_fees/fees_test.d.ts +5 -5
  25. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  26. package/dest/e2e_fees/fees_test.js +26 -33
  27. package/dest/e2e_l1_publisher/write_json.d.ts +3 -1
  28. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -1
  29. package/dest/e2e_l1_publisher/write_json.js +5 -5
  30. package/dest/e2e_multi_validator/utils.d.ts +1 -1
  31. package/dest/e2e_multi_validator/utils.d.ts.map +1 -1
  32. package/dest/e2e_multi_validator/utils.js +3 -9
  33. package/dest/e2e_nested_contract/nested_contract_test.d.ts +6 -3
  34. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  35. package/dest/e2e_nested_contract/nested_contract_test.js +7 -9
  36. package/dest/e2e_p2p/inactivity_slash_test.d.ts +31 -0
  37. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -0
  38. package/dest/e2e_p2p/inactivity_slash_test.js +135 -0
  39. package/dest/e2e_p2p/p2p_network.d.ts +22 -8
  40. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  41. package/dest/e2e_p2p/p2p_network.js +36 -15
  42. package/dest/e2e_p2p/shared.d.ts +12 -13
  43. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  44. package/dest/e2e_p2p/shared.js +54 -54
  45. package/dest/e2e_token_contract/token_contract_test.d.ts +5 -4
  46. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  47. package/dest/e2e_token_contract/token_contract_test.js +14 -17
  48. package/dest/fixtures/e2e_prover_test.d.ts +8 -6
  49. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  50. package/dest/fixtures/e2e_prover_test.js +42 -51
  51. package/dest/fixtures/get_acvm_config.d.ts +1 -1
  52. package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
  53. package/dest/fixtures/get_bb_config.d.ts +1 -1
  54. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  55. package/dest/fixtures/get_bb_config.js +2 -2
  56. package/dest/fixtures/setup_l1_contracts.d.ts +1 -1
  57. package/dest/fixtures/setup_l1_contracts.d.ts.map +1 -1
  58. package/dest/fixtures/setup_l1_contracts.js +2 -2
  59. package/dest/fixtures/setup_p2p_test.d.ts +10 -9
  60. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  61. package/dest/fixtures/setup_p2p_test.js +38 -20
  62. package/dest/fixtures/snapshot_manager.d.ts +10 -7
  63. package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
  64. package/dest/fixtures/snapshot_manager.js +60 -47
  65. package/dest/fixtures/token_utils.d.ts +6 -4
  66. package/dest/fixtures/token_utils.d.ts.map +1 -1
  67. package/dest/fixtures/token_utils.js +11 -15
  68. package/dest/fixtures/utils.d.ts +26 -28
  69. package/dest/fixtures/utils.d.ts.map +1 -1
  70. package/dest/fixtures/utils.js +83 -109
  71. package/dest/fixtures/web3signer.d.ts +5 -0
  72. package/dest/fixtures/web3signer.d.ts.map +1 -0
  73. package/dest/fixtures/web3signer.js +53 -0
  74. package/dest/quality_of_service/alert_checker.d.ts +1 -1
  75. package/dest/quality_of_service/alert_checker.d.ts.map +1 -1
  76. package/dest/shared/cross_chain_test_harness.d.ts +16 -10
  77. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  78. package/dest/shared/cross_chain_test_harness.js +13 -15
  79. package/dest/shared/gas_portal_test_harness.d.ts +9 -6
  80. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  81. package/dest/shared/gas_portal_test_harness.js +10 -7
  82. package/dest/shared/jest_setup.js +1 -1
  83. package/dest/shared/submit-transactions.d.ts +5 -3
  84. package/dest/shared/submit-transactions.d.ts.map +1 -1
  85. package/dest/shared/submit-transactions.js +8 -7
  86. package/dest/shared/uniswap_l1_l2.d.ts +9 -6
  87. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  88. package/dest/shared/uniswap_l1_l2.js +29 -45
  89. package/dest/simulators/lending_simulator.d.ts +2 -1
  90. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  91. package/dest/simulators/lending_simulator.js +3 -2
  92. package/dest/simulators/token_simulator.d.ts +3 -1
  93. package/dest/simulators/token_simulator.d.ts.map +1 -1
  94. package/dest/simulators/token_simulator.js +2 -2
  95. package/dest/spartan/setup_test_wallets.d.ts +19 -13
  96. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  97. package/dest/spartan/setup_test_wallets.js +108 -85
  98. package/dest/spartan/utils.d.ts +68 -3
  99. package/dest/spartan/utils.d.ts.map +1 -1
  100. package/dest/spartan/utils.js +312 -49
  101. package/package.json +39 -38
  102. package/src/bench/client_flows/benchmark.ts +8 -8
  103. package/src/bench/client_flows/client_flows_benchmark.ts +62 -82
  104. package/src/bench/client_flows/data_extractor.ts +4 -4
  105. package/src/bench/utils.ts +9 -37
  106. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +46 -63
  107. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +33 -47
  108. package/src/e2e_deploy_contract/deploy_test.ts +17 -35
  109. package/src/e2e_epochs/epochs_test.ts +22 -19
  110. package/src/e2e_fees/bridging_race.notest.ts +14 -9
  111. package/src/e2e_fees/fees_test.ts +29 -40
  112. package/src/e2e_l1_publisher/write_json.ts +8 -6
  113. package/src/e2e_multi_validator/utils.ts +4 -10
  114. package/src/e2e_nested_contract/nested_contract_test.ts +11 -10
  115. package/src/e2e_p2p/inactivity_slash_test.ts +178 -0
  116. package/src/e2e_p2p/p2p_network.ts +110 -71
  117. package/src/e2e_p2p/shared.ts +57 -56
  118. package/src/e2e_token_contract/token_contract_test.ts +17 -17
  119. package/src/fixtures/e2e_prover_test.ts +52 -88
  120. package/src/fixtures/get_acvm_config.ts +1 -1
  121. package/src/fixtures/get_bb_config.ts +3 -2
  122. package/src/fixtures/setup_l1_contracts.ts +3 -3
  123. package/src/fixtures/setup_p2p_test.ts +60 -27
  124. package/src/fixtures/snapshot_manager.ts +80 -72
  125. package/src/fixtures/token_utils.ts +13 -21
  126. package/src/fixtures/utils.ts +95 -145
  127. package/src/fixtures/web3signer.ts +63 -0
  128. package/src/guides/up_quick_start.sh +2 -10
  129. package/src/quality_of_service/alert_checker.ts +1 -1
  130. package/src/shared/cross_chain_test_harness.ts +18 -29
  131. package/src/shared/gas_portal_test_harness.ts +12 -19
  132. package/src/shared/jest_setup.ts +1 -1
  133. package/src/shared/submit-transactions.ts +12 -8
  134. package/src/shared/uniswap_l1_l2.ts +61 -67
  135. package/src/simulators/lending_simulator.ts +3 -2
  136. package/src/simulators/token_simulator.ts +5 -2
  137. package/src/spartan/DEVELOP.md +8 -3
  138. package/src/spartan/setup_test_wallets.ts +133 -126
  139. package/src/spartan/utils.ts +373 -48
@@ -1,4 +1,4 @@
1
- import type { AztecAddress } from '@aztec/aztec.js';
1
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
2
2
  import { getAddressFromPrivateKey } from '@aztec/ethereum';
3
3
  import { EthAddress } from '@aztec/foundation/eth-address';
4
4
  import type { EthPrivateKey } from '@aztec/node-keystore';
@@ -157,9 +157,7 @@ export async function createKeyFile3(
157
157
  schemaVersion: 1,
158
158
  validators: [
159
159
  {
160
- attester: {
161
- address: validatorAddress.toChecksumString(),
162
- },
160
+ attester: validatorAddress.toChecksumString(),
163
161
  coinbase: coinbase.toChecksumString(),
164
162
  publisher: [publisher1Key, publisher2Key],
165
163
  feeRecipient: feeRecipient.toString(),
@@ -193,9 +191,7 @@ export async function createKeyFile4(
193
191
  },
194
192
  validators: [
195
193
  {
196
- attester: {
197
- address: validator1Address.toChecksumString(),
198
- },
194
+ attester: validator1Address.toChecksumString(),
199
195
  coinbase: coinbase1.toChecksumString(),
200
196
  publisher: {
201
197
  mnemonic: mnemonic,
@@ -206,9 +202,7 @@ export async function createKeyFile4(
206
202
  feeRecipient: feeRecipient1.toString(),
207
203
  },
208
204
  {
209
- attester: {
210
- address: validator2Address.toChecksumString(),
211
- },
205
+ attester: validator2Address.toChecksumString(),
212
206
  coinbase: coinbase2.toChecksumString(),
213
207
  publisher: [publisher2Key, publisher3Key],
214
208
  feeRecipient: feeRecipient2.toString(),
@@ -1,5 +1,7 @@
1
- import { getSchnorrWallet } from '@aztec/accounts/schnorr';
2
- import { type AccountWallet, AztecAddress, type Logger, type PXE, createLogger } from '@aztec/aztec.js';
1
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { type Logger, createLogger } from '@aztec/aztec.js/log';
3
+ import type { AztecNode } from '@aztec/aztec.js/node';
4
+ import type { Wallet } from '@aztec/aztec.js/wallet';
3
5
  import { ChildContract } from '@aztec/noir-test-contracts.js/Child';
4
6
  import { ParentContract } from '@aztec/noir-test-contracts.js/Parent';
5
7
 
@@ -16,9 +18,9 @@ const { E2E_DATA_PATH: dataPath } = process.env;
16
18
  export class NestedContractTest {
17
19
  private snapshotManager: ISnapshotManager;
18
20
  logger: Logger;
19
- wallet!: AccountWallet;
21
+ wallet!: Wallet;
20
22
  defaultAccountAddress!: AztecAddress;
21
- pxe!: PXE;
23
+ aztecNode!: AztecNode;
22
24
 
23
25
  parentContract!: ParentContract;
24
26
  childContract!: ChildContract;
@@ -40,12 +42,11 @@ export class NestedContractTest {
40
42
  await this.snapshotManager.snapshot(
41
43
  'accounts',
42
44
  deployAccounts(this.numberOfAccounts, this.logger),
43
- async ({ deployedAccounts }, { pxe }) => {
44
- const wallets = await Promise.all(deployedAccounts.map(a => getSchnorrWallet(pxe, a.address, a.signingKey)));
45
- wallets.forEach((w, i) => this.logger.verbose(`Wallet ${i} address: ${w.getAddress()}`));
46
- [this.wallet] = wallets;
47
- this.defaultAccountAddress = this.wallet.getAddress();
48
- this.pxe = pxe;
45
+ ({ deployedAccounts }, { wallet, aztecNode }) => {
46
+ this.wallet = wallet;
47
+ [{ address: this.defaultAccountAddress }] = deployedAccounts;
48
+ this.aztecNode = aztecNode;
49
+ return Promise.resolve();
49
50
  },
50
51
  );
51
52
 
@@ -0,0 +1,178 @@
1
+ import type { AztecNodeService } from '@aztec/aztec-node';
2
+ import { EthAddress } from '@aztec/aztec.js/addresses';
3
+ import { RollupContract } from '@aztec/ethereum';
4
+
5
+ import fs from 'fs';
6
+ import 'jest-extended';
7
+ import os from 'os';
8
+ import path from 'path';
9
+
10
+ import { createNodes } from '../fixtures/setup_p2p_test.js';
11
+ import { P2PNetworkTest } from './p2p_network.js';
12
+
13
+ const NUM_NODES = 6;
14
+ const NUM_VALIDATORS = NUM_NODES;
15
+ const COMMITTEE_SIZE = NUM_VALIDATORS;
16
+ const SLASHING_QUORUM = 3;
17
+ const EPOCH_DURATION = 2;
18
+ const SLASHING_ROUND_SIZE_IN_EPOCHS = 2;
19
+ const BOOT_NODE_UDP_PORT = 4500;
20
+ const ETHEREUM_SLOT_DURATION = process.env.CI ? 8 : 4;
21
+ const AZTEC_SLOT_DURATION = ETHEREUM_SLOT_DURATION * 2;
22
+ const SLASHING_UNIT = BigInt(1e18);
23
+ const SLASHING_AMOUNT = SLASHING_UNIT * 3n;
24
+
25
+ // How many epochs it may take to set everything up, so we dont slash during this period
26
+ const SETUP_EPOCH_DURATION = 5;
27
+
28
+ export class P2PInactivityTest {
29
+ public nodes!: AztecNodeService[];
30
+ public activeNodes!: AztecNodeService[];
31
+ public inactiveNodes!: AztecNodeService[];
32
+
33
+ public rollup!: RollupContract;
34
+ public offlineValidators!: EthAddress[];
35
+
36
+ private dataDir: string;
37
+ private inactiveNodeCount: number;
38
+ private keepInitialNode: boolean;
39
+
40
+ constructor(
41
+ public readonly test: P2PNetworkTest,
42
+ opts: { inactiveNodeCount: number; keepInitialNode?: boolean },
43
+ ) {
44
+ this.dataDir = fs.mkdtempSync(path.join(os.tmpdir(), test.testName));
45
+ this.inactiveNodeCount = opts.inactiveNodeCount;
46
+ this.keepInitialNode = opts.keepInitialNode ?? false;
47
+ }
48
+
49
+ static async create(
50
+ testName: string,
51
+ opts: { slashInactivityConsecutiveEpochThreshold: number; inactiveNodeCount: number; keepInitialNode?: boolean },
52
+ ) {
53
+ const test = await P2PNetworkTest.create({
54
+ testName,
55
+ numberOfNodes: 0,
56
+ numberOfValidators: NUM_VALIDATORS,
57
+ basePort: BOOT_NODE_UDP_PORT,
58
+ startProverNode: true,
59
+ initialConfig: {
60
+ proverNodeConfig: { proverNodeEpochProvingDelayMs: AZTEC_SLOT_DURATION * 1000 },
61
+ aztecTargetCommitteeSize: COMMITTEE_SIZE,
62
+ aztecSlotDuration: AZTEC_SLOT_DURATION,
63
+ ethereumSlotDuration: ETHEREUM_SLOT_DURATION,
64
+ aztecProofSubmissionEpochs: 1024, // effectively do not reorg
65
+ listenAddress: '127.0.0.1',
66
+ minTxsPerBlock: 0,
67
+ aztecEpochDuration: EPOCH_DURATION,
68
+ validatorReexecute: false,
69
+ sentinelEnabled: true,
70
+ slashingQuorum: SLASHING_QUORUM,
71
+ slashingRoundSizeInEpochs: SLASHING_ROUND_SIZE_IN_EPOCHS,
72
+ slashInactivityTargetPercentage: 0.8,
73
+ slashGracePeriodL2Slots: SETUP_EPOCH_DURATION * EPOCH_DURATION, // do not slash during setup
74
+ slashAmountSmall: SLASHING_UNIT,
75
+ slashAmountMedium: SLASHING_UNIT * 2n,
76
+ slashAmountLarge: SLASHING_UNIT * 3n,
77
+ ...opts,
78
+ },
79
+ });
80
+ return new P2PInactivityTest(test, opts);
81
+ }
82
+
83
+ public async setup() {
84
+ await this.test.applyBaseSnapshots();
85
+ await this.test.setup();
86
+
87
+ // Set slashing penalties for inactivity
88
+ const { rollup } = await this.test.getContracts();
89
+ const [activationThreshold, ejectionThreshold, localEjectionThreshold] = await Promise.all([
90
+ rollup.getActivationThreshold(),
91
+ rollup.getEjectionThreshold(),
92
+ rollup.getLocalEjectionThreshold(),
93
+ ]);
94
+ const biggestEjection = ejectionThreshold > localEjectionThreshold ? ejectionThreshold : localEjectionThreshold;
95
+ expect(activationThreshold - SLASHING_AMOUNT).toBeLessThan(biggestEjection);
96
+ this.test.ctx.aztecNodeConfig.slashInactivityPenalty = SLASHING_AMOUNT;
97
+ this.rollup = rollup;
98
+
99
+ if (!this.keepInitialNode) {
100
+ await this.test.ctx.aztecNode.stop();
101
+ }
102
+
103
+ // Create all active nodes
104
+ this.activeNodes = await createNodes(
105
+ this.test.ctx.aztecNodeConfig,
106
+ this.test.ctx.dateProvider,
107
+ this.test.bootstrapNodeEnr,
108
+ NUM_NODES - this.inactiveNodeCount - Number(this.keepInitialNode),
109
+ BOOT_NODE_UDP_PORT,
110
+ this.test.prefilledPublicData,
111
+ this.dataDir,
112
+ undefined,
113
+ Number(this.keepInitialNode),
114
+ );
115
+
116
+ // And the ones with an initially disabled sequencer
117
+ const inactiveConfig = { ...this.test.ctx.aztecNodeConfig, dontStartSequencer: true };
118
+ this.inactiveNodes = await createNodes(
119
+ inactiveConfig,
120
+ this.test.ctx.dateProvider,
121
+ this.test.bootstrapNodeEnr,
122
+ this.inactiveNodeCount,
123
+ BOOT_NODE_UDP_PORT,
124
+ this.test.prefilledPublicData,
125
+ this.dataDir,
126
+ undefined,
127
+ NUM_NODES - this.inactiveNodeCount,
128
+ );
129
+
130
+ this.nodes = [
131
+ ...(this.keepInitialNode ? [this.test.ctx.aztecNode] : []),
132
+ ...this.activeNodes,
133
+ ...this.inactiveNodes,
134
+ ];
135
+
136
+ if (this.nodes.length !== NUM_NODES) {
137
+ throw new Error(`Expected ${NUM_NODES} nodes but got ${this.nodes.length}`);
138
+ }
139
+
140
+ this.offlineValidators = this.test.validators
141
+ .slice(this.test.validators.length - this.inactiveNodeCount)
142
+ .map(a => a.attester);
143
+
144
+ this.test.logger.warn(`Setup complete. Offline validators are ${this.offlineValidators.join(', ')}.`, {
145
+ validators: this.test.validators,
146
+ offlineValidators: this.offlineValidators,
147
+ });
148
+
149
+ // Wait for P2P mesh to be fully formed before starting slashing period
150
+ // This prevents race conditions where validators propose blocks before the network is ready
151
+ await this.test.waitForP2PMeshConnectivity(this.nodes, NUM_NODES);
152
+
153
+ this.test.logger.warn(`Advancing to epoch ${SETUP_EPOCH_DURATION + 1} to start slashing`);
154
+ await this.test.ctx.cheatCodes.rollup.advanceToEpoch(SETUP_EPOCH_DURATION + 1);
155
+
156
+ return this;
157
+ }
158
+
159
+ public async teardown() {
160
+ await this.test.stopNodes(this.nodes);
161
+ await this.test.teardown();
162
+ for (let i = 0; i < NUM_NODES; i++) {
163
+ fs.rmSync(`${this.dataDir}-${i}`, { recursive: true, force: true, maxRetries: 3 });
164
+ }
165
+ }
166
+
167
+ public get ctx() {
168
+ return this.test.ctx;
169
+ }
170
+
171
+ public get logger() {
172
+ return this.test.logger;
173
+ }
174
+
175
+ public get slashingAmount() {
176
+ return SLASHING_AMOUNT;
177
+ }
178
+ }
@@ -1,7 +1,7 @@
1
- import { getSchnorrWalletWithSecretKey } from '@aztec/accounts/schnorr';
2
1
  import type { InitialAccountData } from '@aztec/accounts/testing';
3
2
  import type { AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
4
- import { type AccountWalletWithSecretKey, AztecAddress, EthAddress, Fr } from '@aztec/aztec.js';
3
+ import { AztecAddress, EthAddress } from '@aztec/aztec.js/addresses';
4
+ import { Fr } from '@aztec/aztec.js/fields';
5
5
  import {
6
6
  type EmpireSlashingProposerContract,
7
7
  type ExtendedViemWalletClient,
@@ -18,6 +18,7 @@ import {
18
18
  import { ChainMonitor } from '@aztec/ethereum/test';
19
19
  import { SecretValue } from '@aztec/foundation/config';
20
20
  import { type Logger, createLogger } from '@aztec/foundation/log';
21
+ import { retryUntil } from '@aztec/foundation/retry';
21
22
  import { RollupAbi, SlasherAbi, TestERC20Abi } from '@aztec/l1-artifacts';
22
23
  import { SpamContract } from '@aztec/noir-test-contracts.js/Spam';
23
24
  import type { BootstrapNode } from '@aztec/p2p/bootstrap';
@@ -26,6 +27,7 @@ import { tryStop } from '@aztec/stdlib/interfaces/server';
26
27
  import { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
27
28
  import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
28
29
  import { ZkPassportProofParams } from '@aztec/stdlib/zkpassport';
30
+ import type { TestWallet } from '@aztec/test-wallet/server';
29
31
  import { getGenesisValues } from '@aztec/world-state/testing';
30
32
 
31
33
  import getPort from 'get-port';
@@ -43,7 +45,7 @@ import {
43
45
  createSnapshotManager,
44
46
  deployAccounts,
45
47
  } from '../fixtures/snapshot_manager.js';
46
- import { getPrivateKeyFromIndex, getSponsoredFPCAddress } from '../fixtures/utils.js';
48
+ import { type SetupOptions, getPrivateKeyFromIndex, getSponsoredFPCAddress } from '../fixtures/utils.js';
47
49
  import { getEndToEndTestTelemetryClient } from '../fixtures/with_telemetry_utils.js';
48
50
 
49
51
  // Use a fixed bootstrap node private key so that we can re-use the same snapshot and the nodes can find each other
@@ -75,18 +77,18 @@ export class P2PNetworkTest {
75
77
  public prefilledPublicData: PublicDataTreeLeaf[] = [];
76
78
 
77
79
  // The re-execution test needs a wallet and a spam contract
78
- public wallet?: AccountWalletWithSecretKey;
80
+ public wallet?: TestWallet;
79
81
  public defaultAccountAddress?: AztecAddress;
80
82
  public spamContract?: SpamContract;
81
83
 
82
84
  public bootstrapNode?: BootstrapNode;
83
85
 
84
86
  constructor(
85
- testName: string,
87
+ public readonly testName: string,
86
88
  public bootstrapNodeEnr: string,
87
89
  public bootNodePort: number,
88
90
  public numberOfValidators: number,
89
- initialValidatorConfig: AztecNodeConfig,
91
+ initialValidatorConfig: SetupOptions,
90
92
  public numberOfNodes = 0,
91
93
  // If set enable metrics collection
92
94
  private metricsPort?: number,
@@ -162,7 +164,7 @@ export class P2PNetworkTest {
162
164
  numberOfValidators: number;
163
165
  basePort?: number;
164
166
  metricsPort?: number;
165
- initialConfig?: Partial<AztecNodeConfig>;
167
+ initialConfig?: SetupOptions;
166
168
  startProverNode?: boolean;
167
169
  mockZkPassportVerifier?: boolean;
168
170
  }) {
@@ -230,88 +232,83 @@ export class P2PNetworkTest {
230
232
 
231
233
  async applyBaseSnapshots() {
232
234
  await this.addBootstrapNode();
233
- await this.snapshotManager.snapshot(
234
- 'add-validators',
235
- async ({ deployL1ContractsValues, dateProvider, cheatCodes }) => {
236
- const rollup = getContract({
237
- address: deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(),
238
- abi: RollupAbi,
239
- client: deployL1ContractsValues.l1Client,
240
- });
235
+ await this.snapshotManager.snapshot('add-validators', async ({ deployL1ContractsValues, cheatCodes }) => {
236
+ const rollup = getContract({
237
+ address: deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(),
238
+ abi: RollupAbi,
239
+ client: deployL1ContractsValues.l1Client,
240
+ });
241
241
 
242
- this.logger.info(`Adding ${this.numberOfValidators} validators`);
242
+ this.logger.info(`Adding ${this.numberOfValidators} validators`);
243
243
 
244
- const stakingAsset = getContract({
245
- address: deployL1ContractsValues.l1ContractAddresses.stakingAssetAddress.toString(),
246
- abi: TestERC20Abi,
247
- client: deployL1ContractsValues.l1Client,
248
- });
244
+ const stakingAsset = getContract({
245
+ address: deployL1ContractsValues.l1ContractAddresses.stakingAssetAddress.toString(),
246
+ abi: TestERC20Abi,
247
+ client: deployL1ContractsValues.l1Client,
248
+ });
249
249
 
250
- const { address: multiAdderAddress } = await deployL1Contract(
251
- deployL1ContractsValues.l1Client,
252
- MultiAdderArtifact.contractAbi,
253
- MultiAdderArtifact.contractBytecode,
254
- [rollup.address, deployL1ContractsValues.l1Client.account.address],
255
- );
250
+ const { address: multiAdderAddress } = await deployL1Contract(
251
+ deployL1ContractsValues.l1Client,
252
+ MultiAdderArtifact.contractAbi,
253
+ MultiAdderArtifact.contractBytecode,
254
+ [rollup.address, deployL1ContractsValues.l1Client.account.address],
255
+ );
256
256
 
257
- const multiAdder = getContract({
258
- address: multiAdderAddress.toString(),
259
- abi: MultiAdderArtifact.contractAbi,
260
- client: deployL1ContractsValues.l1Client,
261
- });
257
+ const multiAdder = getContract({
258
+ address: multiAdderAddress.toString(),
259
+ abi: MultiAdderArtifact.contractAbi,
260
+ client: deployL1ContractsValues.l1Client,
261
+ });
262
262
 
263
- const stakeNeeded = l1ContractsConfig.activationThreshold * BigInt(this.numberOfValidators);
264
- await Promise.all(
265
- [await stakingAsset.write.mint([multiAdder.address, stakeNeeded], {} as any)].map(txHash =>
266
- deployL1ContractsValues.l1Client.waitForTransactionReceipt({ hash: txHash }),
267
- ),
268
- );
263
+ const stakeNeeded = (await rollup.read.getActivationThreshold()) * BigInt(this.numberOfValidators);
264
+ await Promise.all(
265
+ [await stakingAsset.write.mint([multiAdder.address, stakeNeeded], {} as any)].map(txHash =>
266
+ deployL1ContractsValues.l1Client.waitForTransactionReceipt({ hash: txHash }),
267
+ ),
268
+ );
269
269
 
270
- const { validators } = this.getValidators();
271
- this.validators = validators;
270
+ const { validators } = this.getValidators();
271
+ this.validators = validators;
272
272
 
273
- const gseAddress = deployL1ContractsValues.l1ContractAddresses.gseAddress!;
274
- if (!gseAddress) {
275
- throw new Error('GSE contract not deployed');
276
- }
273
+ const gseAddress = deployL1ContractsValues.l1ContractAddresses.gseAddress!;
274
+ if (!gseAddress) {
275
+ throw new Error('GSE contract not deployed');
276
+ }
277
277
 
278
- const gseContract = new GSEContract(deployL1ContractsValues.l1Client, gseAddress.toString());
278
+ const gseContract = new GSEContract(deployL1ContractsValues.l1Client, gseAddress.toString());
279
279
 
280
- const makeValidatorTuples = async (validator: Operator) => {
281
- const registrationTuple = await gseContract.makeRegistrationTuple(validator.bn254SecretKey.getValue());
282
- return {
283
- attester: validator.attester.toString() as `0x${string}`,
284
- withdrawer: validator.withdrawer.toString() as `0x${string}`,
285
- ...registrationTuple,
286
- };
280
+ const makeValidatorTuples = async (validator: Operator) => {
281
+ const registrationTuple = await gseContract.makeRegistrationTuple(validator.bn254SecretKey.getValue());
282
+ return {
283
+ attester: validator.attester.toString() as `0x${string}`,
284
+ withdrawer: validator.withdrawer.toString() as `0x${string}`,
285
+ ...registrationTuple,
287
286
  };
288
- const validatorTuples = await Promise.all(validators.map(makeValidatorTuples));
287
+ };
288
+ const validatorTuples = await Promise.all(validators.map(makeValidatorTuples));
289
289
 
290
- await deployL1ContractsValues.l1Client.waitForTransactionReceipt({
291
- hash: await multiAdder.write.addValidators([validatorTuples]),
292
- });
293
-
294
- const timestamp = await cheatCodes.rollup.advanceToEpoch(2n, { updateDateProvider: dateProvider });
290
+ await deployL1ContractsValues.l1Client.waitForTransactionReceipt({
291
+ hash: await multiAdder.write.addValidators([validatorTuples]),
292
+ });
295
293
 
296
- // Send and await a tx to make sure we mine a block for the warp to correctly progress.
297
- await this._sendDummyTx(deployL1ContractsValues.l1Client);
294
+ await cheatCodes.rollup.advanceToEpoch(
295
+ (await cheatCodes.rollup.getEpoch()) + (await rollup.read.getLagInEpochs()) + 1n,
296
+ );
298
297
 
299
- // Set the system time in the node, only after we have warped the time and waited for a block
300
- // Time is only set in the NEXT block
301
- dateProvider.setTime(Number(timestamp) * 1000);
302
- },
303
- );
298
+ // Send and await a tx to make sure we mine a block for the warp to correctly progress.
299
+ await this._sendDummyTx(deployL1ContractsValues.l1Client);
300
+ });
304
301
  }
305
302
 
306
303
  async setupAccount() {
307
304
  await this.snapshotManager.snapshot(
308
305
  'setup-account',
309
- deployAccounts(1, this.logger, false),
310
- async ({ deployedAccounts }, { pxe }) => {
306
+ deployAccounts(1, this.logger),
307
+ ({ deployedAccounts }, { wallet }) => {
311
308
  this.deployedAccounts = deployedAccounts;
312
- const [account] = deployedAccounts;
313
- this.wallet = await getSchnorrWalletWithSecretKey(pxe, account.secret, account.signingKey, account.salt);
314
- this.defaultAccountAddress = this.wallet.getAddress();
309
+ [{ address: this.defaultAccountAddress }] = deployedAccounts;
310
+ this.wallet = wallet;
311
+ return Promise.resolve();
315
312
  },
316
313
  );
317
314
  }
@@ -393,6 +390,48 @@ export class P2PNetworkTest {
393
390
  this.logger.info('Nodes stopped');
394
391
  }
395
392
 
393
+ /**
394
+ * Wait for P2P mesh to be fully formed across all nodes.
395
+ * This ensures that all nodes are connected to each other before proceeding,
396
+ * preventing race conditions where validators propose blocks before the network is ready.
397
+ *
398
+ * @param nodes - Array of nodes to check for P2P connectivity
399
+ * @param expectedNodeCount - Expected number of nodes in the network (defaults to nodes.length)
400
+ * @param timeoutSeconds - Maximum time to wait for connections (default: 30 seconds)
401
+ * @param checkIntervalSeconds - How often to check connectivity (default: 0.1 seconds)
402
+ */
403
+ async waitForP2PMeshConnectivity(
404
+ nodes: AztecNodeService[],
405
+ expectedNodeCount?: number,
406
+ timeoutSeconds = 30,
407
+ checkIntervalSeconds = 0.1,
408
+ ) {
409
+ const nodeCount = expectedNodeCount ?? nodes.length;
410
+ const minPeerCount = nodeCount - 1;
411
+
412
+ this.logger.warn(
413
+ `Waiting for all ${nodeCount} nodes to connect to P2P mesh (at least ${minPeerCount} peers each)...`,
414
+ );
415
+
416
+ await Promise.all(
417
+ nodes.map(async (node, index) => {
418
+ const p2p = node.getP2P();
419
+ await retryUntil(
420
+ async () => {
421
+ const peers = await p2p.getPeers();
422
+ // Each node should be connected to at least N-1 other nodes
423
+ return peers.length >= minPeerCount ? true : undefined;
424
+ },
425
+ `Node ${index} to connect to at least ${minPeerCount} peers`,
426
+ timeoutSeconds,
427
+ checkIntervalSeconds,
428
+ );
429
+ }),
430
+ );
431
+
432
+ this.logger.warn('All nodes connected to P2P mesh');
433
+ }
434
+
396
435
  async teardown() {
397
436
  await this.monitor.stop();
398
437
  await tryStop(this.bootstrapNode, this.logger);
@@ -415,7 +454,7 @@ export class P2PNetworkTest {
415
454
  );
416
455
 
417
456
  const slasherContract = getContract({
418
- address: getAddress(await rollup.getSlasher()),
457
+ address: getAddress(await rollup.getSlasherAddress()),
419
458
  abi: SlasherAbi,
420
459
  client: this.ctx.deployL1ContractsValues.l1Client,
421
460
  });