@aztec/end-to-end 4.0.0-nightly.20260113 → 4.0.0-nightly.20260115

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 (80) hide show
  1. package/dest/bench/client_flows/client_flows_benchmark.d.ts +12 -13
  2. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  3. package/dest/bench/client_flows/client_flows_benchmark.js +104 -134
  4. package/dest/bench/utils.d.ts +1 -1
  5. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +6 -7
  6. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  7. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +98 -113
  8. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +6 -7
  9. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  10. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +65 -62
  11. package/dest/e2e_deploy_contract/deploy_test.d.ts +4 -3
  12. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  13. package/dest/e2e_deploy_contract/deploy_test.js +18 -13
  14. package/dest/e2e_epochs/epochs_test.js +1 -1
  15. package/dest/e2e_fees/bridging_race.notest.js +2 -4
  16. package/dest/e2e_fees/fees_test.d.ts +13 -13
  17. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  18. package/dest/e2e_fees/fees_test.js +122 -140
  19. package/dest/e2e_l1_publisher/write_json.d.ts +1 -1
  20. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -1
  21. package/dest/e2e_l1_publisher/write_json.js +1 -0
  22. package/dest/e2e_nested_contract/nested_contract_test.d.ts +6 -9
  23. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  24. package/dest/e2e_nested_contract/nested_contract_test.js +32 -40
  25. package/dest/e2e_p2p/inactivity_slash_test.d.ts +3 -3
  26. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -1
  27. package/dest/e2e_p2p/inactivity_slash_test.js +3 -3
  28. package/dest/e2e_p2p/p2p_network.d.ts +7 -6
  29. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  30. package/dest/e2e_p2p/p2p_network.js +106 -103
  31. package/dest/e2e_token_contract/token_contract_test.d.ts +16 -9
  32. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  33. package/dest/e2e_token_contract/token_contract_test.js +90 -92
  34. package/dest/fixtures/e2e_prover_test.d.ts +8 -14
  35. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  36. package/dest/fixtures/e2e_prover_test.js +82 -93
  37. package/dest/fixtures/setup.d.ts +216 -0
  38. package/dest/fixtures/setup.d.ts.map +1 -0
  39. package/dest/fixtures/setup.js +683 -0
  40. package/dest/fixtures/utils.d.ts +5 -191
  41. package/dest/fixtures/utils.d.ts.map +1 -1
  42. package/dest/fixtures/utils.js +4 -615
  43. package/dest/quality_of_service/prometheus_client.d.ts +38 -0
  44. package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
  45. package/dest/quality_of_service/prometheus_client.js +67 -0
  46. package/dest/shared/cross_chain_test_harness.d.ts +12 -1
  47. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  48. package/dest/shared/gas_portal_test_harness.d.ts +11 -1
  49. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  50. package/dest/simulators/lending_simulator.d.ts +5 -1
  51. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  52. package/dest/spartan/tx_metrics.d.ts +4 -1
  53. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  54. package/dest/spartan/tx_metrics.js +21 -1
  55. package/dest/spartan/utils.d.ts +5 -1
  56. package/dest/spartan/utils.d.ts.map +1 -1
  57. package/dest/spartan/utils.js +25 -8
  58. package/package.json +39 -39
  59. package/src/bench/client_flows/client_flows_benchmark.ts +142 -195
  60. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +107 -142
  61. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +99 -106
  62. package/src/e2e_deploy_contract/deploy_test.ts +21 -14
  63. package/src/e2e_epochs/epochs_test.ts +1 -1
  64. package/src/e2e_fees/bridging_race.notest.ts +2 -5
  65. package/src/e2e_fees/fees_test.ts +171 -213
  66. package/src/e2e_l1_publisher/write_json.ts +1 -0
  67. package/src/e2e_nested_contract/nested_contract_test.ts +35 -56
  68. package/src/e2e_p2p/inactivity_slash_test.ts +5 -5
  69. package/src/e2e_p2p/p2p_network.ts +165 -167
  70. package/src/e2e_token_contract/token_contract_test.ts +105 -118
  71. package/src/fixtures/e2e_prover_test.ts +107 -136
  72. package/src/fixtures/setup.ts +1009 -0
  73. package/src/fixtures/utils.ts +27 -901
  74. package/src/quality_of_service/prometheus_client.ts +113 -0
  75. package/src/spartan/tx_metrics.ts +21 -1
  76. package/src/spartan/utils.ts +26 -8
  77. package/dest/fixtures/snapshot_manager.d.ts +0 -93
  78. package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
  79. package/dest/fixtures/snapshot_manager.js +0 -488
  80. package/src/fixtures/snapshot_manager.ts +0 -646
@@ -1,488 +0,0 @@
1
- import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';
2
- import { generateSchnorrAccounts } from '@aztec/accounts/testing';
3
- import { AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node';
4
- import { AztecAddress, EthAddress } from '@aztec/aztec.js/addresses';
5
- import { getContractClassFromArtifact } from '@aztec/aztec.js/contracts';
6
- import { BatchCall, waitForProven } from '@aztec/aztec.js/contracts';
7
- import { publishContractClass, publishInstance } from '@aztec/aztec.js/deployment';
8
- import { AnvilTestWatcher, CheatCodes } from '@aztec/aztec/testing';
9
- import { createExtendedL1Client } from '@aztec/ethereum/client';
10
- import { getL1ContractsConfigEnvVars } from '@aztec/ethereum/config';
11
- import { deployMulticall3 } from '@aztec/ethereum/contracts';
12
- import { deployAztecL1Contracts } from '@aztec/ethereum/deploy-aztec-l1-contracts';
13
- import { EthCheatCodesWithState, startAnvil } from '@aztec/ethereum/test';
14
- import { asyncMap } from '@aztec/foundation/async-map';
15
- import { SecretValue } from '@aztec/foundation/config';
16
- import { randomBytes } from '@aztec/foundation/crypto/random';
17
- import { tryRmDir } from '@aztec/foundation/fs';
18
- import { createLogger } from '@aztec/foundation/log';
19
- import { resolver, reviver } from '@aztec/foundation/serialize';
20
- import { TestDateProvider } from '@aztec/foundation/timer';
21
- import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
22
- import { protocolContractsHash } from '@aztec/protocol-contracts';
23
- import { getPXEConfig } from '@aztec/pxe/server';
24
- import { tryStop } from '@aztec/stdlib/interfaces/server';
25
- import { getConfigEnvVars as getTelemetryConfig, initTelemetryClient } from '@aztec/telemetry-client';
26
- import { TestWallet } from '@aztec/test-wallet/server';
27
- import { getGenesisValues } from '@aztec/world-state/testing';
28
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
29
- import { copySync, removeSync } from 'fs-extra/esm';
30
- import fs from 'fs/promises';
31
- import { tmpdir } from 'os';
32
- import path, { join } from 'path';
33
- import { mnemonicToAccount } from 'viem/accounts';
34
- import { foundry } from 'viem/chains';
35
- import { MNEMONIC, TEST_MAX_PENDING_TX_POOL_COUNT, TEST_PEER_CHECK_INTERVAL_MS } from './fixtures.js';
36
- import { getACVMConfig } from './get_acvm_config.js';
37
- import { getBBConfig } from './get_bb_config.js';
38
- import { createAndSyncProverNode, getLogger, getPrivateKeyFromIndex, getSponsoredFPCAddress, setupSharedBlobStorage } from './utils.js';
39
- import { getEndToEndTestTelemetryClient } from './with_telemetry_utils.js';
40
- export function createSnapshotManager(testName, dataPath, config = {}, deployL1ContractsArgs = {
41
- initialValidators: []
42
- }) {
43
- return dataPath ? new SnapshotManager(testName, dataPath, config, deployL1ContractsArgs) : new MockSnapshotManager(testName, config, deployL1ContractsArgs);
44
- }
45
- /** Snapshot manager that does not perform snapshotting, it just applies transition and restoration functions as it receives them. */ class MockSnapshotManager {
46
- config;
47
- deployL1ContractsArgs;
48
- context;
49
- logger;
50
- constructor(testName, config = {}, deployL1ContractsArgs = {}){
51
- this.config = config;
52
- this.deployL1ContractsArgs = deployL1ContractsArgs;
53
- this.logger = createLogger(`e2e:snapshot_manager:${testName}`);
54
- this.logger.warn(`No data path given, will not persist any snapshots.`);
55
- }
56
- async snapshot(name, apply, restore = ()=>Promise.resolve()) {
57
- // We are running in disabled mode. Just apply the state.
58
- const context = await this.setup();
59
- this.logger.verbose(`Applying state transition for ${name}...`);
60
- const snapshotData = await apply(context);
61
- this.logger.verbose(`State transition for ${name} complete.`);
62
- // Execute the restoration function.
63
- await restore(snapshotData, context);
64
- return;
65
- }
66
- async setup() {
67
- if (!this.context) {
68
- this.context = await setupFromFresh(undefined, this.logger, this.config, this.deployL1ContractsArgs);
69
- }
70
- return this.context;
71
- }
72
- async teardown() {
73
- await teardown(this.context);
74
- this.context = undefined;
75
- }
76
- }
77
- /**
78
- * Snapshot engine for local e2e tests. Read more:
79
- * https://github.com/AztecProtocol/aztec-packages/pull/5526
80
- */ class SnapshotManager {
81
- dataPath;
82
- config;
83
- deployL1ContractsArgs;
84
- snapshotStack;
85
- context;
86
- livePath;
87
- logger;
88
- constructor(testName, dataPath, config = {}, deployL1ContractsArgs = {}){
89
- this.dataPath = dataPath;
90
- this.config = config;
91
- this.deployL1ContractsArgs = deployL1ContractsArgs;
92
- this.snapshotStack = [];
93
- this.livePath = join(this.dataPath, 'live', testName);
94
- this.logger = createLogger(`e2e:snapshot_manager:${testName}`);
95
- }
96
- async snapshot(name, apply, restore = ()=>Promise.resolve()) {
97
- const snapshotPath = join(this.dataPath, 'snapshots', ...this.snapshotStack.map((e)=>e.name), name, 'snapshot');
98
- if (existsSync(snapshotPath)) {
99
- // Snapshot exists. Record entry on stack but do nothing else as we're probably still descending the tree.
100
- // It's the tests responsibility to call setup() before a test to ensure subsystems get created.
101
- this.logger.verbose(`Snapshot exists at ${snapshotPath}. Continuing...`);
102
- this.snapshotStack.push({
103
- name,
104
- apply,
105
- restore,
106
- snapshotPath
107
- });
108
- return;
109
- }
110
- // Snapshot didn't exist at snapshotPath, and by definition none of the child snapshots can exist.
111
- // If we have no subsystem context yet, create it from the top of the snapshot stack (if it exists).
112
- const context = await this.setup();
113
- this.snapshotStack.push({
114
- name,
115
- apply,
116
- restore,
117
- snapshotPath
118
- });
119
- // Apply current state transition.
120
- this.logger.verbose(`Applying state transition for ${name}...`);
121
- const snapshotData = await apply(context);
122
- this.logger.verbose(`State transition for ${name} complete.`);
123
- // Execute the restoration function.
124
- await restore(snapshotData, context);
125
- // Save the snapshot data.
126
- const ethCheatCodes = new EthCheatCodesWithState(context.aztecNodeConfig.l1RpcUrls, context.dateProvider);
127
- const anvilStateFile = `${this.livePath}/anvil.dat`;
128
- await ethCheatCodes.dumpChainState(anvilStateFile);
129
- writeFileSync(`${this.livePath}/${name}.json`, JSON.stringify(snapshotData || {}, resolver));
130
- // Copy everything to snapshot path.
131
- // We want it to be atomic, in case multiple processes are racing to create the snapshot.
132
- this.logger.verbose(`Saving snapshot to ${snapshotPath}...`);
133
- if (mkdirSync(snapshotPath, {
134
- recursive: true
135
- })) {
136
- copySync(this.livePath, snapshotPath);
137
- this.logger.verbose(`Snapshot copied to ${snapshotPath}.`);
138
- } else {
139
- this.logger.verbose(`Snapshot already exists at ${snapshotPath}. Discarding our version.`);
140
- await this.teardown();
141
- }
142
- }
143
- /**
144
- * Creates and returns the subsystem context based on the current snapshot stack.
145
- * If the subsystem context already exists, just return it.
146
- * If you want to be sure to get a clean snapshot, be sure to call teardown() before calling setup().
147
- */ async setup() {
148
- // We have no subsystem context yet.
149
- // If one exists on the snapshot stack, create one from that snapshot.
150
- // Otherwise create a fresh one.
151
- if (!this.context) {
152
- removeSync(this.livePath);
153
- mkdirSync(this.livePath, {
154
- recursive: true
155
- });
156
- const previousSnapshotPath = this.snapshotStack[this.snapshotStack.length - 1]?.snapshotPath;
157
- if (previousSnapshotPath) {
158
- this.logger.verbose(`Copying snapshot from ${previousSnapshotPath} to ${this.livePath}...`);
159
- copySync(previousSnapshotPath, this.livePath);
160
- this.context = await setupFromState(this.livePath, this.logger);
161
- // Execute each of the previous snapshots restoration functions in turn.
162
- await asyncMap(this.snapshotStack, async (e)=>{
163
- const snapshotData = JSON.parse(readFileSync(`${e.snapshotPath}/${e.name}.json`, 'utf-8'), reviver);
164
- this.logger.verbose(`Executing restoration function for ${e.name}...`);
165
- await e.restore(snapshotData, this.context);
166
- this.logger.verbose(`Restoration of ${e.name} complete.`);
167
- });
168
- } else {
169
- this.context = await setupFromFresh(this.livePath, this.logger, this.config, this.deployL1ContractsArgs);
170
- }
171
- }
172
- return this.context;
173
- }
174
- /**
175
- * Destroys the current subsystem context.
176
- */ async teardown() {
177
- await teardown(this.context);
178
- this.context = undefined;
179
- removeSync(this.livePath);
180
- }
181
- }
182
- /**
183
- * Destroys the current subsystem context.
184
- */ async function teardown(context) {
185
- if (!context) {
186
- return;
187
- }
188
- const logger = getLogger();
189
- try {
190
- logger.info('Tearing down subsystems');
191
- await tryStop(context.proverNode);
192
- await tryStop(context.aztecNode);
193
- await context.acvmConfig?.cleanup();
194
- await context.bbConfig?.cleanup();
195
- await tryStop(context.anvil);
196
- await tryStop(context.watcher);
197
- await tryRmDir(context.directoryToCleanup, logger);
198
- } catch (err) {
199
- logger.error('Error during teardown', err);
200
- }
201
- }
202
- /**
203
- * Initializes a fresh set of subsystems.
204
- * If given a statePath, the state will be written to the path.
205
- * If there is no statePath, in-memory and temporary state locations will be used.
206
- */ async function setupFromFresh(statePath, logger, { numberOfInitialFundedAccounts = 10, ...opts } = {}, deployL1ContractsArgs = {
207
- initialValidators: []
208
- }) {
209
- logger.verbose(`Initializing state...`);
210
- // Default to no slashing
211
- opts.slasherFlavor ??= 'none';
212
- deployL1ContractsArgs.slasherFlavor ??= opts.slasherFlavor;
213
- // Fetch the AztecNode config.
214
- // TODO: For some reason this is currently the union of a bunch of subsystems. That needs fixing.
215
- const aztecNodeConfig = {
216
- ...getConfigEnvVars(),
217
- ...opts
218
- };
219
- aztecNodeConfig.peerCheckIntervalMS = TEST_PEER_CHECK_INTERVAL_MS;
220
- aztecNodeConfig.maxPendingTxCount = opts.maxPendingTxCount ?? TEST_MAX_PENDING_TX_POOL_COUNT;
221
- // Only enable proving if specifically requested.
222
- aztecNodeConfig.realProofs = !!opts.realProofs;
223
- // Only enforce the time table if requested
224
- aztecNodeConfig.enforceTimeTable = !!opts.enforceTimeTable;
225
- // Only set the target committee size if it is explicitly set
226
- aztecNodeConfig.aztecTargetCommitteeSize = opts.aztecTargetCommitteeSize ?? 0;
227
- aztecNodeConfig.listenAddress = '127.0.0.1';
228
- deployL1ContractsArgs.aztecTargetCommitteeSize ??= aztecNodeConfig.aztecTargetCommitteeSize;
229
- // Create a temp directory for all ephemeral state and cleanup afterwards
230
- const directoryToCleanup = path.join(tmpdir(), randomBytes(8).toString('hex'));
231
- await fs.mkdir(directoryToCleanup, {
232
- recursive: true
233
- });
234
- if (statePath === undefined) {
235
- aztecNodeConfig.dataDirectory = directoryToCleanup;
236
- } else {
237
- aztecNodeConfig.dataDirectory = statePath;
238
- }
239
- await setupSharedBlobStorage(aztecNodeConfig);
240
- const hdAccount = mnemonicToAccount(MNEMONIC, {
241
- addressIndex: 0
242
- });
243
- const publisherPrivKeyRaw = hdAccount.getHdKey().privateKey;
244
- const publisherPrivKey = publisherPrivKeyRaw === null ? null : Buffer.from(publisherPrivKeyRaw);
245
- const publisherPrivKeyHex = `0x${publisherPrivKey.toString('hex')}`;
246
- const l1Client = createExtendedL1Client([
247
- aztecNodeConfig.l1RpcUrls[0]
248
- ], hdAccount, foundry);
249
- const validatorPrivKey = getPrivateKeyFromIndex(0);
250
- const proverNodePrivateKey = getPrivateKeyFromIndex(0);
251
- aztecNodeConfig.publisherPrivateKeys = [
252
- new SecretValue(publisherPrivKeyHex)
253
- ];
254
- aztecNodeConfig.validatorPrivateKeys = new SecretValue([
255
- `0x${validatorPrivKey.toString('hex')}`
256
- ]);
257
- aztecNodeConfig.coinbase = opts.coinbase ?? EthAddress.fromString(`${hdAccount.address}`);
258
- logger.info(`Setting up environment with config`, aztecNodeConfig);
259
- // Start anvil. We go via a wrapper script to ensure if the parent dies, anvil dies.
260
- logger.verbose('Starting anvil...');
261
- const res = await startAnvil({
262
- l1BlockTime: opts.ethereumSlotDuration
263
- });
264
- const anvil = res.anvil;
265
- aztecNodeConfig.l1RpcUrls = [
266
- res.rpcUrl
267
- ];
268
- const dateProvider = new TestDateProvider();
269
- const ethCheatCodes = new EthCheatCodesWithState(aztecNodeConfig.l1RpcUrls, dateProvider);
270
- // Deploy our L1 contracts.
271
- logger.verbose('Deploying Aztec L1 contracts...');
272
- if (opts.l1StartTime) {
273
- await ethCheatCodes.warp(opts.l1StartTime, {
274
- resetBlockInterval: true
275
- });
276
- }
277
- const initialFundedAccounts = await generateSchnorrAccounts(numberOfInitialFundedAccounts);
278
- const sponsoredFPCAddress = await getSponsoredFPCAddress();
279
- const { genesisArchiveRoot, prefilledPublicData, fundingNeeded } = await getGenesisValues(initialFundedAccounts.map((a)=>a.address).concat(sponsoredFPCAddress), opts.initialAccountFeeJuice);
280
- const vkTreeRoot = getVKTreeRoot();
281
- await deployMulticall3(l1Client, logger);
282
- // Define args, defaulted to our environment variables.
283
- const args = {
284
- ...getL1ContractsConfigEnvVars(),
285
- ...deployL1ContractsArgs,
286
- vkTreeRoot,
287
- genesisArchiveRoot,
288
- protocolContractsHash,
289
- initialValidators: opts.initialValidators,
290
- feeJuicePortalInitialBalance: fundingNeeded,
291
- realVerifier: false
292
- };
293
- const deployL1ContractsValues = await deployAztecL1Contracts(aztecNodeConfig.l1RpcUrls[0], publisherPrivKeyHex, foundry.id, args);
294
- aztecNodeConfig.l1Contracts = deployL1ContractsValues.l1ContractAddresses;
295
- aztecNodeConfig.rollupVersion = deployL1ContractsValues.rollupVersion;
296
- const watcher = new AnvilTestWatcher(new EthCheatCodesWithState(aztecNodeConfig.l1RpcUrls, dateProvider), deployL1ContractsValues.l1ContractAddresses.rollupAddress, deployL1ContractsValues.l1Client, dateProvider);
297
- await watcher.start();
298
- const acvmConfig = await getACVMConfig(logger);
299
- if (acvmConfig) {
300
- aztecNodeConfig.acvmWorkingDirectory = acvmConfig.acvmWorkingDirectory;
301
- aztecNodeConfig.acvmBinaryPath = acvmConfig.acvmBinaryPath;
302
- }
303
- const bbConfig = await getBBConfig(logger);
304
- if (bbConfig) {
305
- aztecNodeConfig.bbBinaryPath = bbConfig.bbBinaryPath;
306
- aztecNodeConfig.bbWorkingDirectory = bbConfig.bbWorkingDirectory;
307
- }
308
- const telemetry = await getEndToEndTestTelemetryClient(opts.metricsPort);
309
- logger.info('Creating and synching an aztec node...');
310
- const aztecNode = await AztecNodeService.createAndSync(aztecNodeConfig, {
311
- telemetry,
312
- dateProvider
313
- }, {
314
- prefilledPublicData
315
- });
316
- let proverNode = undefined;
317
- if (opts.startProverNode) {
318
- logger.verbose('Creating and syncing a simulated prover node with p2p disabled...');
319
- proverNode = await createAndSyncProverNode(`0x${proverNodePrivateKey.toString('hex')}`, aztecNodeConfig, {
320
- ...aztecNodeConfig.proverNodeConfig,
321
- dataDirectory: path.join(directoryToCleanup, randomBytes(8).toString('hex')),
322
- p2pEnabled: false
323
- }, aztecNode, prefilledPublicData);
324
- }
325
- logger.verbose('Creating pxe...');
326
- const pxeConfig = getPXEConfig();
327
- pxeConfig.dataDirectory = statePath ?? path.join(directoryToCleanup, randomBytes(8).toString('hex'));
328
- // Only enable proving if specifically requested.
329
- pxeConfig.proverEnabled = !!opts.realProofs;
330
- const wallet = await TestWallet.create(aztecNode, pxeConfig);
331
- const cheatCodes = await CheatCodes.create(aztecNodeConfig.l1RpcUrls, aztecNode, dateProvider);
332
- if (statePath) {
333
- writeFileSync(`${statePath}/aztec_node_config.json`, JSON.stringify(aztecNodeConfig, resolver));
334
- writeFileSync(`${statePath}/accounts.json`, JSON.stringify(initialFundedAccounts, resolver));
335
- }
336
- return {
337
- aztecNodeConfig,
338
- anvil,
339
- aztecNode,
340
- wallet,
341
- sequencer: aztecNode.getSequencer(),
342
- acvmConfig,
343
- bbConfig,
344
- deployL1ContractsValues,
345
- proverNode,
346
- watcher,
347
- cheatCodes,
348
- dateProvider,
349
- initialFundedAccounts,
350
- directoryToCleanup
351
- };
352
- }
353
- /**
354
- * Given a statePath, setup the system starting from that state.
355
- */ async function setupFromState(statePath, logger) {
356
- logger.verbose(`Initializing with saved state at ${statePath}...`);
357
- const directoryToCleanup = path.join(tmpdir(), randomBytes(8).toString('hex'));
358
- await fs.mkdir(directoryToCleanup, {
359
- recursive: true
360
- });
361
- // TODO: For some reason this is currently the union of a bunch of subsystems. That needs fixing.
362
- const aztecNodeConfig = JSON.parse(readFileSync(`${statePath}/aztec_node_config.json`, 'utf-8'), reviver);
363
- aztecNodeConfig.dataDirectory = statePath;
364
- aztecNodeConfig.listenAddress = '127.0.0.1';
365
- await setupSharedBlobStorage(aztecNodeConfig);
366
- const initialFundedAccounts = JSON.parse(readFileSync(`${statePath}/accounts.json`, 'utf-8'), reviver) || [];
367
- const { prefilledPublicData } = await getGenesisValues(initialFundedAccounts.map((a)=>a.address));
368
- // Start anvil. We go via a wrapper script to ensure if the parent dies, anvil dies.
369
- const { anvil, rpcUrl } = await startAnvil();
370
- aztecNodeConfig.l1RpcUrls = [
371
- rpcUrl
372
- ];
373
- // Load anvil state.
374
- const anvilStateFile = `${statePath}/anvil.dat`;
375
- const dateProvider = new TestDateProvider();
376
- const ethCheatCodes = new EthCheatCodesWithState(aztecNodeConfig.l1RpcUrls, dateProvider);
377
- await ethCheatCodes.loadChainState(anvilStateFile);
378
- // TODO: Encapsulate this in a NativeAcvm impl.
379
- const acvmConfig = await getACVMConfig(logger);
380
- if (acvmConfig) {
381
- aztecNodeConfig.acvmWorkingDirectory = acvmConfig.acvmWorkingDirectory;
382
- aztecNodeConfig.acvmBinaryPath = acvmConfig.acvmBinaryPath;
383
- }
384
- const bbConfig = await getBBConfig(logger);
385
- if (bbConfig) {
386
- aztecNodeConfig.bbBinaryPath = bbConfig.bbBinaryPath;
387
- aztecNodeConfig.bbWorkingDirectory = bbConfig.bbWorkingDirectory;
388
- }
389
- logger.verbose('Creating ETH clients...');
390
- const l1Client = createExtendedL1Client(aztecNodeConfig.l1RpcUrls, mnemonicToAccount(MNEMONIC));
391
- const watcher = new AnvilTestWatcher(ethCheatCodes, aztecNodeConfig.l1Contracts.rollupAddress, l1Client, dateProvider);
392
- await watcher.start();
393
- const telemetry = await initTelemetryClient(getTelemetryConfig());
394
- logger.verbose('Creating aztec node...');
395
- const aztecNode = await AztecNodeService.createAndSync(aztecNodeConfig, {
396
- telemetry,
397
- dateProvider
398
- }, {
399
- prefilledPublicData
400
- });
401
- let proverNode = undefined;
402
- if (aztecNodeConfig.startProverNode) {
403
- logger.verbose('Creating and syncing a simulated prover node...');
404
- const proverNodePrivateKey = getPrivateKeyFromIndex(2);
405
- const proverNodePrivateKeyHex = `0x${proverNodePrivateKey.toString('hex')}`;
406
- proverNode = await createAndSyncProverNode(proverNodePrivateKeyHex, aztecNodeConfig, {
407
- ...aztecNodeConfig.proverNodeConfig,
408
- dataDirectory: path.join(directoryToCleanup, randomBytes(8).toString('hex')),
409
- p2pEnabled: false
410
- }, aztecNode, prefilledPublicData);
411
- }
412
- logger.verbose('Creating pxe...');
413
- const pxeConfig = getPXEConfig();
414
- pxeConfig.dataDirectory = statePath;
415
- const wallet = await TestWallet.create(aztecNode, pxeConfig);
416
- const cheatCodes = await CheatCodes.create(aztecNodeConfig.l1RpcUrls, aztecNode, dateProvider);
417
- return {
418
- aztecNodeConfig,
419
- anvil,
420
- aztecNode,
421
- wallet,
422
- sequencer: aztecNode.getSequencer(),
423
- acvmConfig,
424
- bbConfig,
425
- proverNode,
426
- deployL1ContractsValues: {
427
- l1Client,
428
- l1ContractAddresses: aztecNodeConfig.l1Contracts,
429
- rollupVersion: aztecNodeConfig.rollupVersion
430
- },
431
- watcher,
432
- cheatCodes,
433
- dateProvider,
434
- initialFundedAccounts,
435
- directoryToCleanup
436
- };
437
- }
438
- /**
439
- * Snapshot 'apply' helper function to add accounts.
440
- * The 'restore' function is not provided, as it must be a closure within the test context to capture the results.
441
- */ export const deployAccounts = (numberOfAccounts, logger)=>async ({ wallet, initialFundedAccounts })=>{
442
- if (initialFundedAccounts.length < numberOfAccounts) {
443
- throw new Error(`Cannot deploy more than ${initialFundedAccounts.length} initial accounts.`);
444
- }
445
- logger.verbose('Deploying accounts funded with fee juice...');
446
- const deployedAccounts = initialFundedAccounts.slice(0, numberOfAccounts);
447
- // Serial due to https://github.com/AztecProtocol/aztec-packages/issues/12045
448
- for(let i = 0; i < deployedAccounts.length; i++){
449
- const accountManager = await wallet.createSchnorrAccount(deployedAccounts[i].secret, deployedAccounts[i].salt, deployedAccounts[i].signingKey);
450
- const deployMethod = await accountManager.getDeployMethod();
451
- await deployMethod.send({
452
- from: AztecAddress.ZERO,
453
- skipClassPublication: i !== 0
454
- }).wait();
455
- }
456
- return {
457
- deployedAccounts
458
- };
459
- };
460
- /**
461
- * Registers the contract class used for test accounts and publicly deploys the instances requested.
462
- * Use this when you need to make a public call to an account contract, such as for requesting a public authwit.
463
- * @param sender - Wallet to send the deployment tx.
464
- * @param accountsToDeploy - Which accounts to publicly deploy.
465
- * @param waitUntilProven - Whether to wait for the tx to be proven.
466
- * @param node - AztecNode used to wait for proven tx.
467
- */ export async function publicDeployAccounts(wallet, accountsToDeploy, waitUntilProven = false, node) {
468
- const instances = (await Promise.all(accountsToDeploy.map((account)=>wallet.getContractMetadata(account)))).map((metadata)=>metadata.contractInstance);
469
- const contractClass = await getContractClassFromArtifact(SchnorrAccountContractArtifact);
470
- const alreadyRegistered = (await wallet.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered;
471
- const calls = await Promise.all([
472
- ...!alreadyRegistered ? [
473
- publishContractClass(wallet, SchnorrAccountContractArtifact)
474
- ] : [],
475
- ...instances.map((instance)=>publishInstance(wallet, instance))
476
- ]);
477
- const batch = new BatchCall(wallet, calls);
478
- const txReceipt = await batch.send({
479
- from: accountsToDeploy[0]
480
- }).wait();
481
- if (waitUntilProven) {
482
- if (!node) {
483
- throw new Error('Need to provide an AztecNode to wait for proven.');
484
- } else {
485
- await waitForProven(node, txReceipt);
486
- }
487
- }
488
- }