@aztec/end-to-end 4.0.0-nightly.20260112 → 4.0.0-nightly.20260114

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 (74) hide show
  1. package/dest/bench/client_flows/client_flows_benchmark.d.ts +10 -10
  2. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  3. package/dest/bench/client_flows/client_flows_benchmark.js +98 -133
  4. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +5 -6
  5. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  6. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +94 -112
  7. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +5 -5
  8. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  9. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +60 -62
  10. package/dest/e2e_deploy_contract/deploy_test.d.ts +4 -3
  11. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  12. package/dest/e2e_deploy_contract/deploy_test.js +15 -13
  13. package/dest/e2e_epochs/epochs_test.js +1 -1
  14. package/dest/e2e_fees/bridging_race.notest.js +2 -4
  15. package/dest/e2e_fees/fees_test.d.ts +11 -11
  16. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  17. package/dest/e2e_fees/fees_test.js +118 -139
  18. package/dest/e2e_l1_publisher/write_json.d.ts +1 -1
  19. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -1
  20. package/dest/e2e_l1_publisher/write_json.js +1 -0
  21. package/dest/e2e_nested_contract/nested_contract_test.d.ts +5 -8
  22. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  23. package/dest/e2e_nested_contract/nested_contract_test.js +29 -40
  24. package/dest/e2e_p2p/inactivity_slash_test.js +1 -1
  25. package/dest/e2e_p2p/p2p_network.d.ts +5 -3
  26. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  27. package/dest/e2e_p2p/p2p_network.js +99 -102
  28. package/dest/e2e_token_contract/token_contract_test.d.ts +15 -8
  29. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  30. package/dest/e2e_token_contract/token_contract_test.js +88 -92
  31. package/dest/fixtures/e2e_prover_test.d.ts +7 -13
  32. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  33. package/dest/fixtures/e2e_prover_test.js +78 -91
  34. package/dest/fixtures/snapshot_manager.d.ts +10 -44
  35. package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
  36. package/dest/fixtures/snapshot_manager.js +12 -255
  37. package/dest/fixtures/utils.js +3 -3
  38. package/dest/quality_of_service/grafana_client.d.ts +41 -0
  39. package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
  40. package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
  41. package/dest/quality_of_service/prometheus_client.d.ts +38 -0
  42. package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
  43. package/dest/quality_of_service/prometheus_client.js +67 -0
  44. package/dest/spartan/setup_test_wallets.d.ts +4 -3
  45. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  46. package/dest/spartan/tx_metrics.d.ts +4 -1
  47. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  48. package/dest/spartan/tx_metrics.js +21 -1
  49. package/dest/spartan/utils.d.ts +5 -1
  50. package/dest/spartan/utils.d.ts.map +1 -1
  51. package/dest/spartan/utils.js +25 -8
  52. package/package.json +38 -38
  53. package/src/bench/client_flows/client_flows_benchmark.ts +134 -192
  54. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +104 -136
  55. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +91 -103
  56. package/src/e2e_deploy_contract/deploy_test.ts +18 -14
  57. package/src/e2e_epochs/epochs_test.ts +1 -1
  58. package/src/e2e_fees/bridging_race.notest.ts +2 -5
  59. package/src/e2e_fees/fees_test.ts +165 -210
  60. package/src/e2e_l1_publisher/write_json.ts +1 -0
  61. package/src/e2e_nested_contract/nested_contract_test.ts +30 -54
  62. package/src/e2e_p2p/inactivity_slash_test.ts +1 -1
  63. package/src/e2e_p2p/p2p_network.ts +149 -165
  64. package/src/e2e_token_contract/token_contract_test.ts +104 -113
  65. package/src/fixtures/e2e_prover_test.ts +97 -130
  66. package/src/fixtures/snapshot_manager.ts +12 -325
  67. package/src/fixtures/utils.ts +3 -3
  68. package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +1 -1
  69. package/src/quality_of_service/prometheus_client.ts +113 -0
  70. package/src/spartan/setup_test_wallets.ts +7 -1
  71. package/src/spartan/tx_metrics.ts +21 -1
  72. package/src/spartan/utils.ts +26 -8
  73. package/dest/quality_of_service/alert_checker.d.ts +0 -41
  74. package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
@@ -39,12 +39,7 @@ import {
39
39
  createValidatorConfig,
40
40
  generatePrivateKeys,
41
41
  } from '../fixtures/setup_p2p_test.js';
42
- import {
43
- type ISnapshotManager,
44
- type SubsystemsContext,
45
- createSnapshotManager,
46
- deployAccounts,
47
- } from '../fixtures/snapshot_manager.js';
42
+ import { type SubsystemsContext, deployAccounts, setupFromFresh, teardown } from '../fixtures/snapshot_manager.js';
48
43
  import { type SetupOptions, getPrivateKeyFromIndex, getSponsoredFPCAddress } from '../fixtures/utils.js';
49
44
  import { getEndToEndTestTelemetryClient } from '../fixtures/with_telemetry_utils.js';
50
45
 
@@ -60,7 +55,7 @@ export const SHORTENED_BLOCK_TIME_CONFIG_NO_PRUNES = {
60
55
  };
61
56
 
62
57
  export class P2PNetworkTest {
63
- private snapshotManager: ISnapshotManager;
58
+ public context!: SubsystemsContext;
64
59
  public baseAccountPrivateKey: `0x${string}`;
65
60
  public baseAccount;
66
61
 
@@ -83,6 +78,10 @@ export class P2PNetworkTest {
83
78
 
84
79
  public bootstrapNode?: BootstrapNode;
85
80
 
81
+ // Store setup options for use in setup()
82
+ private setupOptions: SetupOptions;
83
+ private deployL1ContractsArgs: any;
84
+
86
85
  constructor(
87
86
  public readonly testName: string,
88
87
  public bootstrapNodeEnr: string,
@@ -107,43 +106,41 @@ export class P2PNetworkTest {
107
106
 
108
107
  const zkPassportParams = ZkPassportProofParams.random();
109
108
 
110
- this.snapshotManager = createSnapshotManager(
111
- `e2e_p2p_network/${testName}`,
112
- process.env.E2E_DATA_PATH,
113
- {
114
- ...initialValidatorConfig,
115
- ethereumSlotDuration: initialValidatorConfig.ethereumSlotDuration ?? l1ContractsConfig.ethereumSlotDuration,
116
- aztecEpochDuration: initialValidatorConfig.aztecEpochDuration ?? l1ContractsConfig.aztecEpochDuration,
117
- aztecSlotDuration: initialValidatorConfig.aztecSlotDuration ?? l1ContractsConfig.aztecSlotDuration,
118
- aztecProofSubmissionEpochs:
119
- initialValidatorConfig.aztecProofSubmissionEpochs ?? l1ContractsConfig.aztecProofSubmissionEpochs,
120
- slashingRoundSizeInEpochs:
121
- initialValidatorConfig.slashingRoundSizeInEpochs ?? l1ContractsConfig.slashingRoundSizeInEpochs,
122
- slasherFlavor: initialValidatorConfig.slasherFlavor ?? 'tally',
123
- aztecTargetCommitteeSize: numberOfValidators,
124
- metricsPort: metricsPort,
125
- numberOfInitialFundedAccounts: 2,
126
- startProverNode,
127
- },
128
- {
129
- ...initialValidatorConfig,
130
- aztecEpochDuration: initialValidatorConfig.aztecEpochDuration ?? l1ContractsConfig.aztecEpochDuration,
131
- slashingRoundSizeInEpochs:
132
- initialValidatorConfig.slashingRoundSizeInEpochs ?? l1ContractsConfig.slashingRoundSizeInEpochs,
133
- slasherFlavor: initialValidatorConfig.slasherFlavor ?? 'tally',
134
-
135
- ethereumSlotDuration: initialValidatorConfig.ethereumSlotDuration ?? l1ContractsConfig.ethereumSlotDuration,
136
- aztecSlotDuration: initialValidatorConfig.aztecSlotDuration ?? l1ContractsConfig.aztecSlotDuration,
137
- aztecProofSubmissionEpochs:
138
- initialValidatorConfig.aztecProofSubmissionEpochs ?? l1ContractsConfig.aztecProofSubmissionEpochs,
139
- aztecTargetCommitteeSize: numberOfValidators,
140
- initialValidators: [],
141
- zkPassportArgs: {
142
- zkPassportDomain: zkPassportParams.domain,
143
- zkPassportScope: zkPassportParams.scope,
144
- },
109
+ // Store setup options for later use
110
+ this.setupOptions = {
111
+ ...initialValidatorConfig,
112
+ ethereumSlotDuration: initialValidatorConfig.ethereumSlotDuration ?? l1ContractsConfig.ethereumSlotDuration,
113
+ aztecEpochDuration: initialValidatorConfig.aztecEpochDuration ?? l1ContractsConfig.aztecEpochDuration,
114
+ aztecSlotDuration: initialValidatorConfig.aztecSlotDuration ?? l1ContractsConfig.aztecSlotDuration,
115
+ aztecProofSubmissionEpochs:
116
+ initialValidatorConfig.aztecProofSubmissionEpochs ?? l1ContractsConfig.aztecProofSubmissionEpochs,
117
+ slashingRoundSizeInEpochs:
118
+ initialValidatorConfig.slashingRoundSizeInEpochs ?? l1ContractsConfig.slashingRoundSizeInEpochs,
119
+ slasherFlavor: initialValidatorConfig.slasherFlavor ?? 'tally',
120
+ aztecTargetCommitteeSize: numberOfValidators,
121
+ metricsPort: metricsPort,
122
+ numberOfInitialFundedAccounts: 2,
123
+ startProverNode,
124
+ };
125
+
126
+ this.deployL1ContractsArgs = {
127
+ ...initialValidatorConfig,
128
+ aztecEpochDuration: initialValidatorConfig.aztecEpochDuration ?? l1ContractsConfig.aztecEpochDuration,
129
+ slashingRoundSizeInEpochs:
130
+ initialValidatorConfig.slashingRoundSizeInEpochs ?? l1ContractsConfig.slashingRoundSizeInEpochs,
131
+ slasherFlavor: initialValidatorConfig.slasherFlavor ?? 'tally',
132
+
133
+ ethereumSlotDuration: initialValidatorConfig.ethereumSlotDuration ?? l1ContractsConfig.ethereumSlotDuration,
134
+ aztecSlotDuration: initialValidatorConfig.aztecSlotDuration ?? l1ContractsConfig.aztecSlotDuration,
135
+ aztecProofSubmissionEpochs:
136
+ initialValidatorConfig.aztecProofSubmissionEpochs ?? l1ContractsConfig.aztecProofSubmissionEpochs,
137
+ aztecTargetCommitteeSize: numberOfValidators,
138
+ initialValidators: [],
139
+ zkPassportArgs: {
140
+ zkPassportDomain: zkPassportParams.domain,
141
+ zkPassportScope: zkPassportParams.scope,
145
142
  },
146
- );
143
+ };
147
144
  }
148
145
 
149
146
  static async create({
@@ -187,23 +184,22 @@ export class P2PNetworkTest {
187
184
 
188
185
  get fundedAccount() {
189
186
  if (!this.deployedAccounts[0]) {
190
- throw new Error('Call snapshot t.setupAccount to create a funded account.');
187
+ throw new Error('Call setupAccount to create a funded account.');
191
188
  }
192
189
  return this.deployedAccounts[0];
193
190
  }
194
191
 
195
192
  async addBootstrapNode() {
196
- await this.snapshotManager.snapshot('add-bootstrap-node', async ({ aztecNodeConfig }) => {
197
- const telemetry = await getEndToEndTestTelemetryClient(this.metricsPort);
198
- this.bootstrapNode = await createBootstrapNodeFromPrivateKey(
199
- BOOTSTRAP_NODE_PRIVATE_KEY,
200
- this.bootNodePort,
201
- telemetry,
202
- aztecNodeConfig,
203
- );
204
- // Overwrite enr with updated info
205
- this.bootstrapNodeEnr = this.bootstrapNode.getENR().encodeTxt();
206
- });
193
+ this.logger.info('Adding bootstrap node');
194
+ const telemetry = await getEndToEndTestTelemetryClient(this.metricsPort);
195
+ this.bootstrapNode = await createBootstrapNodeFromPrivateKey(
196
+ BOOTSTRAP_NODE_PRIVATE_KEY,
197
+ this.bootNodePort,
198
+ telemetry,
199
+ this.context.aztecNodeConfig,
200
+ );
201
+ // Overwrite enr with updated info
202
+ this.bootstrapNodeEnr = this.bootstrapNode.getENR().encodeTxt();
207
203
  }
208
204
 
209
205
  getValidators() {
@@ -224,128 +220,114 @@ export class P2PNetworkTest {
224
220
  return { validators };
225
221
  }
226
222
 
227
- async applyBaseSnapshots() {
223
+ async applyBaseSetup() {
228
224
  await this.addBootstrapNode();
229
- await this.snapshotManager.snapshot('add-validators', async ({ deployL1ContractsValues, cheatCodes }) => {
230
- const rollup = getContract({
231
- address: deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(),
232
- abi: RollupAbi,
233
- client: deployL1ContractsValues.l1Client,
234
- });
235
225
 
236
- this.logger.info(`Adding ${this.numberOfValidators} validators`);
226
+ this.logger.info('Adding validators');
227
+ const rollup = getContract({
228
+ address: this.context.deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(),
229
+ abi: RollupAbi,
230
+ client: this.context.deployL1ContractsValues.l1Client,
231
+ });
237
232
 
238
- const stakingAsset = getContract({
239
- address: deployL1ContractsValues.l1ContractAddresses.stakingAssetAddress.toString(),
240
- abi: TestERC20Abi,
241
- client: deployL1ContractsValues.l1Client,
242
- });
233
+ this.logger.info(`Adding ${this.numberOfValidators} validators`);
243
234
 
244
- const { address: multiAdderAddress } = await deployL1Contract(
245
- deployL1ContractsValues.l1Client,
246
- MultiAdderArtifact.contractAbi,
247
- MultiAdderArtifact.contractBytecode,
248
- [rollup.address, deployL1ContractsValues.l1Client.account.address],
249
- );
250
-
251
- const multiAdder = getContract({
252
- address: multiAdderAddress.toString(),
253
- abi: MultiAdderArtifact.contractAbi,
254
- client: deployL1ContractsValues.l1Client,
255
- });
235
+ const stakingAsset = getContract({
236
+ address: this.context.deployL1ContractsValues.l1ContractAddresses.stakingAssetAddress.toString(),
237
+ abi: TestERC20Abi,
238
+ client: this.context.deployL1ContractsValues.l1Client,
239
+ });
256
240
 
257
- const stakeNeeded = (await rollup.read.getActivationThreshold()) * BigInt(this.numberOfValidators);
258
- await Promise.all(
259
- [await stakingAsset.write.mint([multiAdder.address, stakeNeeded], {} as any)].map(txHash =>
260
- deployL1ContractsValues.l1Client.waitForTransactionReceipt({ hash: txHash }),
261
- ),
262
- );
263
-
264
- const { validators } = this.getValidators();
265
- this.validators = validators;
266
-
267
- const gseAddress = deployL1ContractsValues.l1ContractAddresses.gseAddress!;
268
- if (!gseAddress) {
269
- throw new Error('GSE contract not deployed');
270
- }
271
-
272
- const gseContract = new GSEContract(deployL1ContractsValues.l1Client, gseAddress.toString());
273
-
274
- const makeValidatorTuples = async (validator: Operator) => {
275
- const registrationTuple = await gseContract.makeRegistrationTuple(validator.bn254SecretKey.getValue());
276
- return {
277
- attester: validator.attester.toString() as `0x${string}`,
278
- withdrawer: validator.withdrawer.toString() as `0x${string}`,
279
- ...registrationTuple,
280
- };
281
- };
282
- const validatorTuples = await Promise.all(validators.map(makeValidatorTuples));
241
+ const { address: multiAdderAddress } = await deployL1Contract(
242
+ this.context.deployL1ContractsValues.l1Client,
243
+ MultiAdderArtifact.contractAbi,
244
+ MultiAdderArtifact.contractBytecode,
245
+ [rollup.address, this.context.deployL1ContractsValues.l1Client.account.address],
246
+ );
283
247
 
284
- await deployL1ContractsValues.l1Client.waitForTransactionReceipt({
285
- hash: await multiAdder.write.addValidators([validatorTuples]),
286
- });
248
+ const multiAdder = getContract({
249
+ address: multiAdderAddress.toString(),
250
+ abi: MultiAdderArtifact.contractAbi,
251
+ client: this.context.deployL1ContractsValues.l1Client,
252
+ });
287
253
 
288
- await cheatCodes.rollup.advanceToEpoch(
289
- EpochNumber.fromBigInt(
290
- BigInt(await cheatCodes.rollup.getEpoch()) + (await rollup.read.getLagInEpochsForValidatorSet()) + 1n,
291
- ),
292
- );
254
+ const stakeNeeded = (await rollup.read.getActivationThreshold()) * BigInt(this.numberOfValidators);
255
+ await Promise.all(
256
+ [await stakingAsset.write.mint([multiAdder.address, stakeNeeded], {} as any)].map(txHash =>
257
+ this.context.deployL1ContractsValues.l1Client.waitForTransactionReceipt({ hash: txHash }),
258
+ ),
259
+ );
293
260
 
294
- // Send and await a tx to make sure we mine a block for the warp to correctly progress.
295
- await this._sendDummyTx(deployL1ContractsValues.l1Client);
261
+ const { validators } = this.getValidators();
262
+ this.validators = validators;
263
+
264
+ const gseAddress = this.context.deployL1ContractsValues.l1ContractAddresses.gseAddress!;
265
+ if (!gseAddress) {
266
+ throw new Error('GSE contract not deployed');
267
+ }
268
+
269
+ const gseContract = new GSEContract(this.context.deployL1ContractsValues.l1Client, gseAddress.toString());
270
+
271
+ const makeValidatorTuples = async (validator: Operator) => {
272
+ const registrationTuple = await gseContract.makeRegistrationTuple(validator.bn254SecretKey.getValue());
273
+ return {
274
+ attester: validator.attester.toString() as `0x${string}`,
275
+ withdrawer: validator.withdrawer.toString() as `0x${string}`,
276
+ ...registrationTuple,
277
+ };
278
+ };
279
+ const validatorTuples = await Promise.all(validators.map(makeValidatorTuples));
280
+
281
+ await this.context.deployL1ContractsValues.l1Client.waitForTransactionReceipt({
282
+ hash: await multiAdder.write.addValidators([validatorTuples]),
296
283
  });
284
+
285
+ await this.context.cheatCodes.rollup.advanceToEpoch(
286
+ EpochNumber.fromBigInt(
287
+ BigInt(await this.context.cheatCodes.rollup.getEpoch()) +
288
+ (await rollup.read.getLagInEpochsForValidatorSet()) +
289
+ 1n,
290
+ ),
291
+ );
292
+
293
+ // Send and await a tx to make sure we mine a block for the warp to correctly progress.
294
+ await this._sendDummyTx(this.context.deployL1ContractsValues.l1Client);
297
295
  }
298
296
 
299
297
  async setupAccount() {
300
- await this.snapshotManager.snapshot(
301
- 'setup-account',
302
- deployAccounts(1, this.logger),
303
- ({ deployedAccounts }, { wallet }) => {
304
- this.deployedAccounts = deployedAccounts;
305
- [{ address: this.defaultAccountAddress }] = deployedAccounts;
306
- this.wallet = wallet;
307
- return Promise.resolve();
308
- },
309
- );
298
+ this.logger.info('Setting up account');
299
+ const { deployedAccounts } = await deployAccounts(
300
+ 1,
301
+ this.logger,
302
+ )({
303
+ wallet: this.context.wallet,
304
+ initialFundedAccounts: this.context.initialFundedAccounts,
305
+ });
306
+ this.deployedAccounts = deployedAccounts;
307
+ [{ address: this.defaultAccountAddress }] = deployedAccounts;
308
+ this.wallet = this.context.wallet;
310
309
  }
311
310
 
312
311
  async deploySpamContract() {
313
- await this.snapshotManager.snapshot(
314
- 'add-spam-contract',
315
- async () => {
316
- if (!this.wallet) {
317
- throw new Error('Call snapshot t.setupAccount before deploying account contract');
318
- }
319
-
320
- const spamContract = await SpamContract.deploy(this.wallet)
321
- .send({ from: this.defaultAccountAddress! })
322
- .deployed();
323
- return { contractAddress: spamContract.address };
324
- },
325
- ({ contractAddress }) => {
326
- if (!this.wallet) {
327
- throw new Error('Call snapshot t.setupAccount before deploying account contract');
328
- }
329
- this.spamContract = SpamContract.at(contractAddress, this.wallet);
330
- return Promise.resolve();
331
- },
332
- );
312
+ this.logger.info('Deploying spam contract');
313
+ if (!this.wallet) {
314
+ throw new Error('Call setupAccount before deploying spam contract');
315
+ }
316
+
317
+ const spamContract = await SpamContract.deploy(this.wallet).send({ from: this.defaultAccountAddress! }).deployed();
318
+ this.spamContract = spamContract;
333
319
  }
334
320
 
335
321
  async removeInitialNode() {
336
- await this.snapshotManager.snapshot(
337
- 'remove-initial-validator',
338
- async ({ deployL1ContractsValues, aztecNode, dateProvider }) => {
339
- // Send and await a tx to make sure we mine a block for the warp to correctly progress.
340
- const { receipt } = await this._sendDummyTx(deployL1ContractsValues.l1Client);
341
- const block = await deployL1ContractsValues.l1Client.getBlock({
342
- blockNumber: receipt.blockNumber,
343
- });
344
- dateProvider.setTime(Number(block.timestamp) * 1000);
345
-
346
- await aztecNode.stop();
347
- },
348
- );
322
+ this.logger.info('Removing initial node');
323
+ // Send and await a tx to make sure we mine a block for the warp to correctly progress.
324
+ const { receipt } = await this._sendDummyTx(this.context.deployL1ContractsValues.l1Client);
325
+ const block = await this.context.deployL1ContractsValues.l1Client.getBlock({
326
+ blockNumber: receipt.blockNumber,
327
+ });
328
+ this.context.dateProvider.setTime(Number(block.timestamp) * 1000);
329
+
330
+ await this.context.aztecNode.stop();
349
331
  }
350
332
 
351
333
  async sendDummyTx() {
@@ -361,17 +343,19 @@ export class P2PNetworkTest {
361
343
  }
362
344
 
363
345
  async setup() {
364
- this.ctx = await this.snapshotManager.setup();
346
+ this.logger.info('Setting up subsystems from fresh');
347
+ this.context = await setupFromFresh(this.logger, this.setupOptions, this.deployL1ContractsArgs);
348
+ this.ctx = this.context;
365
349
 
366
350
  const sponsoredFPCAddress = await getSponsoredFPCAddress();
367
- const initialFundedAccounts = [...this.ctx.initialFundedAccounts.map(a => a.address), sponsoredFPCAddress];
351
+ const initialFundedAccounts = [...this.context.initialFundedAccounts.map(a => a.address), sponsoredFPCAddress];
368
352
 
369
353
  const { prefilledPublicData } = await getGenesisValues(initialFundedAccounts);
370
354
  this.prefilledPublicData = prefilledPublicData;
371
355
 
372
- const rollupContract = RollupContract.getFromL1ContractsValues(this.ctx.deployL1ContractsValues);
373
- this.monitor = new ChainMonitor(rollupContract, this.ctx.dateProvider).start();
374
- this.monitor.on('l1-block', ({ timestamp }) => this.ctx.dateProvider.setTime(Number(timestamp) * 1000));
356
+ const rollupContract = RollupContract.getFromL1ContractsValues(this.context.deployL1ContractsValues);
357
+ this.monitor = new ChainMonitor(rollupContract, this.context.dateProvider).start();
358
+ this.monitor.on('l1-block', ({ timestamp }) => this.context.dateProvider.setTime(Number(timestamp) * 1000));
375
359
  }
376
360
 
377
361
  async stopNodes(nodes: AztecNodeService[]) {
@@ -432,7 +416,7 @@ export class P2PNetworkTest {
432
416
  async teardown() {
433
417
  await this.monitor.stop();
434
418
  await tryStop(this.bootstrapNode, this.logger);
435
- await this.snapshotManager.teardown();
419
+ await teardown(this.context);
436
420
  }
437
421
 
438
422
  async getContracts(): Promise<{
@@ -8,23 +8,24 @@ import type { TestWallet } from '@aztec/test-wallet/server';
8
8
  import { jest } from '@jest/globals';
9
9
 
10
10
  import {
11
- type ISnapshotManager,
12
11
  type SubsystemsContext,
13
- createSnapshotManager,
14
12
  deployAccounts,
15
13
  publicDeployAccounts,
14
+ setupFromFresh,
15
+ teardown,
16
16
  } from '../fixtures/snapshot_manager.js';
17
17
  import { mintTokensToPrivate } from '../fixtures/token_utils.js';
18
18
  import { TokenSimulator } from '../simulators/token_simulator.js';
19
19
 
20
- const { E2E_DATA_PATH: dataPath, METRICS_PORT: metricsPort } = process.env;
20
+ const { METRICS_PORT: metricsPort } = process.env;
21
21
 
22
22
  export class TokenContractTest {
23
23
  static TOKEN_NAME = 'USDC';
24
24
  static TOKEN_SYMBOL = 'USD';
25
25
  static TOKEN_DECIMALS = 18n;
26
- private snapshotManager: ISnapshotManager;
26
+ context!: SubsystemsContext;
27
27
  logger: Logger;
28
+ metricsPort?: number;
28
29
  asset!: TokenContract;
29
30
  tokenSim!: TokenSimulator;
30
31
  node!: AztecNode;
@@ -35,133 +36,123 @@ export class TokenContractTest {
35
36
  account1Address!: AztecAddress;
36
37
  account2Address!: AztecAddress;
37
38
 
39
+ private shouldApplyBaseSetup = false;
40
+ private shouldApplyMint = false;
41
+
38
42
  constructor(testName: string) {
39
43
  this.logger = createLogger(`e2e:e2e_token_contract:${testName}`);
40
- this.snapshotManager = createSnapshotManager(`e2e_token_contract/${testName}`, dataPath, {
41
- metricsPort: metricsPort ? parseInt(metricsPort) : undefined,
42
- });
44
+ this.metricsPort = metricsPort ? parseInt(metricsPort) : undefined;
45
+ }
46
+
47
+ /**
48
+ * Registers that base setup should be applied during setup().
49
+ * Call this before setup() to deploy 3 accounts, publicly deploy accounts, token contract and a "bad account".
50
+ */
51
+ applyBaseSnapshots() {
52
+ this.shouldApplyBaseSetup = true;
43
53
  }
44
54
 
45
55
  /**
46
- * Adds two state shifts to snapshot manager.
47
- * 1. Add 3 accounts.
48
- * 2. Publicly deploy accounts, deploy token contract and a "bad account".
56
+ * Registers that mint should be applied during setup().
57
+ * Call this before setup() to mint tokens to the admin account.
49
58
  */
50
- async applyBaseSnapshots() {
59
+ applyMintSnapshot() {
60
+ this.shouldApplyMint = true;
61
+ }
62
+
63
+ /**
64
+ * Applies base setup: deploys 3 accounts, publicly deploys accounts, token contract and a "bad account".
65
+ */
66
+ private async applyBaseSetup() {
51
67
  // Adding a timeout of 2 minutes in here such that it is propagated to the underlying tests
52
68
  jest.setTimeout(120_000);
53
69
 
54
- await this.snapshotManager.snapshot(
55
- '3_accounts',
56
- deployAccounts(3, this.logger),
57
- ({ deployedAccounts }, { wallet, aztecNode }) => {
58
- this.node = aztecNode;
59
- this.wallet = wallet;
60
- [this.adminAddress, this.account1Address, this.account2Address] = deployedAccounts.map(acc => acc.address);
61
- return Promise.resolve();
62
- },
63
- );
70
+ this.logger.info('Applying base setup - deploying 3 accounts');
71
+ const { deployedAccounts } = await deployAccounts(
72
+ 3,
73
+ this.logger,
74
+ )({
75
+ wallet: this.context.wallet,
76
+ initialFundedAccounts: this.context.initialFundedAccounts,
77
+ });
64
78
 
65
- await this.snapshotManager.snapshot(
66
- 'e2e_token_contract',
67
- async () => {
68
- // Create the token contract state.
69
- // Move this account thing to addAccounts above?
70
- this.logger.verbose(`Public deploy accounts...`);
71
- await publicDeployAccounts(this.wallet, [this.adminAddress, this.account1Address]);
72
-
73
- this.logger.verbose(`Deploying TokenContract...`);
74
- const asset = await TokenContract.deploy(
75
- this.wallet,
76
- this.adminAddress,
77
- TokenContractTest.TOKEN_NAME,
78
- TokenContractTest.TOKEN_SYMBOL,
79
- TokenContractTest.TOKEN_DECIMALS,
80
- )
81
- .send({ from: this.adminAddress })
82
- .deployed();
83
- this.logger.verbose(`Token deployed to ${asset.address}`);
84
-
85
- this.logger.verbose(`Deploying bad account...`);
86
- this.badAccount = await InvalidAccountContract.deploy(this.wallet).send({ from: this.adminAddress }).deployed();
87
- this.logger.verbose(`Deployed to ${this.badAccount.address}.`);
88
-
89
- return { tokenContractAddress: asset.address, badAccountAddress: this.badAccount.address };
90
- },
91
- async ({ tokenContractAddress, badAccountAddress }) => {
92
- // Restore the token contract state.
93
- this.asset = TokenContract.at(tokenContractAddress, this.wallet);
94
- this.logger.verbose(`Token contract address: ${this.asset.address}`);
95
-
96
- this.tokenSim = new TokenSimulator(this.asset, this.wallet, this.adminAddress, this.logger, [
97
- this.adminAddress,
98
- this.account1Address,
99
- ]);
100
-
101
- this.badAccount = InvalidAccountContract.at(badAccountAddress, this.wallet);
102
- this.logger.verbose(`Bad account address: ${this.badAccount.address}`);
103
-
104
- expect(await this.asset.methods.get_admin().simulate({ from: this.adminAddress })).toBe(
105
- this.adminAddress.toBigInt(),
106
- );
107
- },
79
+ this.node = this.context.aztecNode;
80
+ this.wallet = this.context.wallet;
81
+ [this.adminAddress, this.account1Address, this.account2Address] = deployedAccounts.map(acc => acc.address);
82
+
83
+ this.logger.info('Applying base setup - deploying token contract');
84
+ this.logger.verbose(`Public deploy accounts...`);
85
+ await publicDeployAccounts(this.wallet, [this.adminAddress, this.account1Address]);
86
+
87
+ this.logger.verbose(`Deploying TokenContract...`);
88
+ this.asset = await TokenContract.deploy(
89
+ this.wallet,
90
+ this.adminAddress,
91
+ TokenContractTest.TOKEN_NAME,
92
+ TokenContractTest.TOKEN_SYMBOL,
93
+ TokenContractTest.TOKEN_DECIMALS,
94
+ )
95
+ .send({ from: this.adminAddress })
96
+ .deployed();
97
+ this.logger.verbose(`Token deployed to ${this.asset.address}`);
98
+
99
+ this.logger.verbose(`Deploying bad account...`);
100
+ this.badAccount = await InvalidAccountContract.deploy(this.wallet).send({ from: this.adminAddress }).deployed();
101
+ this.logger.verbose(`Deployed to ${this.badAccount.address}.`);
102
+
103
+ this.tokenSim = new TokenSimulator(this.asset, this.wallet, this.adminAddress, this.logger, [
104
+ this.adminAddress,
105
+ this.account1Address,
106
+ ]);
107
+
108
+ expect(await this.asset.methods.get_admin().simulate({ from: this.adminAddress })).toBe(
109
+ this.adminAddress.toBigInt(),
108
110
  );
109
-
110
- // TokenContract.artifact.functions.forEach(fn => {
111
- // const sig = decodeFunctionSignature(fn.name, fn.parameters);
112
- // logger.verbose(`Function ${sig} and the selector: ${FunctionSelector.fromNameAndParameters(fn.name, fn.parameters)}`);
113
- // });
114
111
  }
115
112
 
116
113
  async setup() {
117
- await this.snapshotManager.setup();
118
- }
114
+ this.context = await setupFromFresh(this.logger, {
115
+ metricsPort: this.metricsPort,
116
+ });
119
117
 
120
- snapshot = <T>(
121
- name: string,
122
- apply: (context: SubsystemsContext) => Promise<T>,
123
- restore: (snapshotData: T, context: SubsystemsContext) => Promise<void> = () => Promise.resolve(),
124
- ): Promise<void> => this.snapshotManager.snapshot(name, apply, restore);
118
+ if (this.shouldApplyBaseSetup) {
119
+ await this.applyBaseSetup();
120
+ }
121
+
122
+ if (this.shouldApplyMint) {
123
+ await this.applyMint();
124
+ }
125
+ }
125
126
 
126
127
  async teardown() {
127
- await this.snapshotManager.teardown();
128
+ await teardown(this.context);
128
129
  }
129
130
 
130
- async applyMintSnapshot() {
131
- await this.snapshotManager.snapshot(
132
- 'mint',
133
- async () => {
134
- const { asset, adminAddress } = this;
135
- const amount = 10000n;
136
-
137
- this.logger.verbose(`Minting ${amount} publicly...`);
138
- await asset.methods.mint_to_public(adminAddress, amount).send({ from: adminAddress }).wait();
139
-
140
- this.logger.verbose(`Minting ${amount} privately...`);
141
- await mintTokensToPrivate(asset, adminAddress, adminAddress, amount);
142
- this.logger.verbose(`Minting complete.`);
143
-
144
- return { amount };
145
- },
146
- async ({ amount }) => {
147
- const { asset, adminAddress, tokenSim } = this;
148
- tokenSim.mintPublic(adminAddress, amount);
149
-
150
- const publicBalance = await asset.methods.balance_of_public(adminAddress).simulate({ from: adminAddress });
151
- this.logger.verbose(`Public balance of wallet 0: ${publicBalance}`);
152
- expect(publicBalance).toEqual(this.tokenSim.balanceOfPublic(adminAddress));
153
-
154
- tokenSim.mintPrivate(adminAddress, amount);
155
- const privateBalance = await asset.methods.balance_of_private(adminAddress).simulate({ from: adminAddress });
156
- this.logger.verbose(`Private balance of wallet 0: ${privateBalance}`);
157
- expect(privateBalance).toEqual(tokenSim.balanceOfPrivate(adminAddress));
158
-
159
- const totalSupply = await asset.methods.total_supply().simulate({ from: adminAddress });
160
- this.logger.verbose(`Total supply: ${totalSupply}`);
161
- expect(totalSupply).toEqual(tokenSim.totalSupply);
162
-
163
- return Promise.resolve();
164
- },
165
- );
131
+ private async applyMint() {
132
+ this.logger.info('Applying mint setup');
133
+ const { asset, adminAddress, tokenSim } = this;
134
+ const amount = 10000n;
135
+
136
+ this.logger.verbose(`Minting ${amount} publicly...`);
137
+ await asset.methods.mint_to_public(adminAddress, amount).send({ from: adminAddress }).wait();
138
+ tokenSim.mintPublic(adminAddress, amount);
139
+
140
+ const publicBalance = await asset.methods.balance_of_public(adminAddress).simulate({ from: adminAddress });
141
+ this.logger.verbose(`Public balance of wallet 0: ${publicBalance}`);
142
+ expect(publicBalance).toEqual(this.tokenSim.balanceOfPublic(adminAddress));
143
+
144
+ this.logger.verbose(`Minting ${amount} privately...`);
145
+ await mintTokensToPrivate(asset, adminAddress, adminAddress, amount);
146
+ tokenSim.mintPrivate(adminAddress, amount);
147
+
148
+ const privateBalance = await asset.methods.balance_of_private(adminAddress).simulate({ from: adminAddress });
149
+ this.logger.verbose(`Private balance of wallet 0: ${privateBalance}`);
150
+ expect(privateBalance).toEqual(tokenSim.balanceOfPrivate(adminAddress));
151
+
152
+ const totalSupply = await asset.methods.total_supply().simulate({ from: adminAddress });
153
+ this.logger.verbose(`Total supply: ${totalSupply}`);
154
+ expect(totalSupply).toEqual(tokenSim.totalSupply);
155
+
156
+ this.logger.verbose(`Minting complete.`);
166
157
  }
167
158
  }