@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.
- package/dest/bench/client_flows/client_flows_benchmark.d.ts +12 -13
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
- package/dest/bench/client_flows/client_flows_benchmark.js +104 -134
- package/dest/bench/utils.d.ts +1 -1
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +6 -7
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +98 -113
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +6 -7
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +65 -62
- package/dest/e2e_deploy_contract/deploy_test.d.ts +4 -3
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
- package/dest/e2e_deploy_contract/deploy_test.js +18 -13
- package/dest/e2e_epochs/epochs_test.js +1 -1
- package/dest/e2e_fees/bridging_race.notest.js +2 -4
- package/dest/e2e_fees/fees_test.d.ts +13 -13
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +122 -140
- package/dest/e2e_l1_publisher/write_json.d.ts +1 -1
- package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -1
- package/dest/e2e_l1_publisher/write_json.js +1 -0
- package/dest/e2e_nested_contract/nested_contract_test.d.ts +6 -9
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +32 -40
- package/dest/e2e_p2p/inactivity_slash_test.d.ts +3 -3
- package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -1
- package/dest/e2e_p2p/inactivity_slash_test.js +3 -3
- package/dest/e2e_p2p/p2p_network.d.ts +7 -6
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +106 -103
- package/dest/e2e_token_contract/token_contract_test.d.ts +16 -9
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +90 -92
- package/dest/fixtures/e2e_prover_test.d.ts +8 -14
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
- package/dest/fixtures/e2e_prover_test.js +82 -93
- package/dest/fixtures/setup.d.ts +216 -0
- package/dest/fixtures/setup.d.ts.map +1 -0
- package/dest/fixtures/setup.js +683 -0
- package/dest/fixtures/utils.d.ts +5 -191
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +4 -615
- package/dest/quality_of_service/prometheus_client.d.ts +38 -0
- package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
- package/dest/quality_of_service/prometheus_client.js +67 -0
- package/dest/shared/cross_chain_test_harness.d.ts +12 -1
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.d.ts +11 -1
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.d.ts +5 -1
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/spartan/tx_metrics.d.ts +4 -1
- package/dest/spartan/tx_metrics.d.ts.map +1 -1
- package/dest/spartan/tx_metrics.js +21 -1
- package/dest/spartan/utils.d.ts +5 -1
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +25 -8
- package/package.json +39 -39
- package/src/bench/client_flows/client_flows_benchmark.ts +142 -195
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +107 -142
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +99 -106
- package/src/e2e_deploy_contract/deploy_test.ts +21 -14
- package/src/e2e_epochs/epochs_test.ts +1 -1
- package/src/e2e_fees/bridging_race.notest.ts +2 -5
- package/src/e2e_fees/fees_test.ts +171 -213
- package/src/e2e_l1_publisher/write_json.ts +1 -0
- package/src/e2e_nested_contract/nested_contract_test.ts +35 -56
- package/src/e2e_p2p/inactivity_slash_test.ts +5 -5
- package/src/e2e_p2p/p2p_network.ts +165 -167
- package/src/e2e_token_contract/token_contract_test.ts +105 -118
- package/src/fixtures/e2e_prover_test.ts +107 -136
- package/src/fixtures/setup.ts +1009 -0
- package/src/fixtures/utils.ts +27 -901
- package/src/quality_of_service/prometheus_client.ts +113 -0
- package/src/spartan/tx_metrics.ts +21 -1
- package/src/spartan/utils.ts +26 -8
- package/dest/fixtures/snapshot_manager.d.ts +0 -93
- package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
- package/dest/fixtures/snapshot_manager.js +0 -488
- package/src/fixtures/snapshot_manager.ts +0 -646
package/src/fixtures/utils.ts
CHANGED
|
@@ -1,904 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
import {
|
|
26
|
-
DelayedTxUtils,
|
|
27
|
-
EthCheatCodes,
|
|
28
|
-
EthCheatCodesWithState,
|
|
29
|
-
createDelayedL1TxUtilsFromViemWallet,
|
|
1
|
+
/**
|
|
2
|
+
* Re-exports from the unified setup module for backward compatibility.
|
|
3
|
+
* Tests that previously used utils.ts should continue to work.
|
|
4
|
+
*/
|
|
5
|
+
export {
|
|
6
|
+
type BalancesFn,
|
|
7
|
+
type EndToEndContext,
|
|
8
|
+
type SetupOptions,
|
|
9
|
+
createAndSyncProverNode,
|
|
10
|
+
deployAccounts,
|
|
11
|
+
ensureAccountContractsPublished,
|
|
12
|
+
expectMapping,
|
|
13
|
+
expectMappingDelta,
|
|
14
|
+
getBalancesFn,
|
|
15
|
+
getLogger,
|
|
16
|
+
getPrivateKeyFromIndex,
|
|
17
|
+
getSponsoredFPCAddress,
|
|
18
|
+
getSponsoredFPCInstance,
|
|
19
|
+
publicDeployAccounts,
|
|
20
|
+
registerSponsoredFPC,
|
|
21
|
+
setup,
|
|
22
|
+
setupPXEAndGetWallet,
|
|
23
|
+
setupSharedBlobStorage,
|
|
24
|
+
setupSponsoredFPC,
|
|
30
25
|
startAnvil,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
35
|
-
import { tryRmDir } from '@aztec/foundation/fs';
|
|
36
|
-
import { withLogNameSuffix } from '@aztec/foundation/log';
|
|
37
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
38
|
-
import { sleep } from '@aztec/foundation/sleep';
|
|
39
|
-
import { DateProvider, TestDateProvider } from '@aztec/foundation/timer';
|
|
40
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
41
|
-
import { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC';
|
|
42
|
-
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
43
|
-
import type { P2PClientDeps } from '@aztec/p2p';
|
|
44
|
-
import { MockGossipSubNetwork, getMockPubSubP2PServiceFactory } from '@aztec/p2p/test-helpers';
|
|
45
|
-
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
46
|
-
import { type ProverNode, type ProverNodeConfig, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
|
|
47
|
-
import { type PXEConfig, getPXEConfig } from '@aztec/pxe/server';
|
|
48
|
-
import type { SequencerClient } from '@aztec/sequencer-client';
|
|
49
|
-
import type { TestSequencerClient } from '@aztec/sequencer-client/test';
|
|
50
|
-
import {
|
|
51
|
-
type ContractInstanceWithAddress,
|
|
52
|
-
getContractClassFromArtifact,
|
|
53
|
-
getContractInstanceFromInstantiationParams,
|
|
54
|
-
} from '@aztec/stdlib/contract';
|
|
55
|
-
import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
56
|
-
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
57
|
-
import type { P2PClientType } from '@aztec/stdlib/p2p';
|
|
58
|
-
import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
59
|
-
import {
|
|
60
|
-
type TelemetryClient,
|
|
61
|
-
type TelemetryClientConfig,
|
|
62
|
-
getConfigEnvVars as getTelemetryConfig,
|
|
63
|
-
initTelemetryClient,
|
|
64
|
-
} from '@aztec/telemetry-client';
|
|
65
|
-
import { BenchmarkTelemetryClient } from '@aztec/telemetry-client/bench';
|
|
66
|
-
import { TestWallet, deployFundedSchnorrAccounts } from '@aztec/test-wallet/server';
|
|
67
|
-
import { getGenesisValues } from '@aztec/world-state/testing';
|
|
68
|
-
|
|
69
|
-
import type { Anvil } from '@viem/anvil';
|
|
70
|
-
import { randomBytes } from 'crypto';
|
|
71
|
-
import fs from 'fs/promises';
|
|
72
|
-
import { tmpdir } from 'os';
|
|
73
|
-
import * as path from 'path';
|
|
74
|
-
import type { Hex } from 'viem';
|
|
75
|
-
import {
|
|
76
|
-
type HDAccount,
|
|
77
|
-
type PrivateKeyAccount,
|
|
78
|
-
generatePrivateKey,
|
|
79
|
-
mnemonicToAccount,
|
|
80
|
-
privateKeyToAccount,
|
|
81
|
-
} from 'viem/accounts';
|
|
82
|
-
import { type Chain, foundry } from 'viem/chains';
|
|
83
|
-
|
|
84
|
-
import { MNEMONIC, TEST_PEER_CHECK_INTERVAL_MS } from './fixtures.js';
|
|
85
|
-
import { getACVMConfig } from './get_acvm_config.js';
|
|
86
|
-
import { getBBConfig } from './get_bb_config.js';
|
|
87
|
-
import { isMetricsLoggingRequested, setupMetricsLogger } from './logging.js';
|
|
26
|
+
teardown,
|
|
27
|
+
waitForProvenChain,
|
|
28
|
+
} from './setup.js';
|
|
88
29
|
|
|
89
30
|
export { deployAndInitializeTokenAndBridgeContracts } from '../shared/cross_chain_test_harness.js';
|
|
90
|
-
export { startAnvil };
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Sets up shared blob storage using FileStore in the data directory.
|
|
94
|
-
*/
|
|
95
|
-
export async function setupSharedBlobStorage(config: { dataDirectory?: string } & Record<string, any>): Promise<void> {
|
|
96
|
-
const sharedBlobPath = path.join(config.dataDirectory!, 'shared-blobs');
|
|
97
|
-
await fs.mkdir(sharedBlobPath, { recursive: true });
|
|
98
|
-
config.blobFileStoreUrls = [`file://${sharedBlobPath}`];
|
|
99
|
-
config.blobFileStoreUploadUrl = `file://${sharedBlobPath}`;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const { AZTEC_NODE_URL = '' } = process.env;
|
|
103
|
-
const getAztecUrl = () => AZTEC_NODE_URL;
|
|
104
|
-
|
|
105
|
-
let telemetry: TelemetryClient | undefined = undefined;
|
|
106
|
-
async function getTelemetryClient(partialConfig: Partial<TelemetryClientConfig> & { benchmark?: boolean } = {}) {
|
|
107
|
-
if (!telemetry) {
|
|
108
|
-
const config = { ...getTelemetryConfig(), ...partialConfig };
|
|
109
|
-
telemetry = config.benchmark ? new BenchmarkTelemetryClient() : await initTelemetryClient(config);
|
|
110
|
-
}
|
|
111
|
-
return telemetry;
|
|
112
|
-
}
|
|
113
|
-
if (typeof afterAll === 'function') {
|
|
114
|
-
afterAll(async () => {
|
|
115
|
-
await telemetry?.stop();
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export const getPrivateKeyFromIndex = (index: number): Buffer | null => {
|
|
120
|
-
const hdAccount = mnemonicToAccount(MNEMONIC, { addressIndex: index });
|
|
121
|
-
const privKeyRaw = hdAccount.getHdKey().privateKey;
|
|
122
|
-
return privKeyRaw === null ? null : Buffer.from(privKeyRaw);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Sets up Private eXecution Environment (PXE) and returns the corresponding test wallet.
|
|
127
|
-
* @param aztecNode - An instance of Aztec Node.
|
|
128
|
-
* @param opts - Partial configuration for the PXE.
|
|
129
|
-
* @param logger - The logger to be used.
|
|
130
|
-
* @param useLogSuffix - Whether to add a randomly generated suffix to the PXE debug logs.
|
|
131
|
-
* @returns A test wallet, logger and teardown function.
|
|
132
|
-
*/
|
|
133
|
-
export async function setupPXEAndGetWallet(
|
|
134
|
-
aztecNode: AztecNode,
|
|
135
|
-
opts: Partial<PXEConfig> = {},
|
|
136
|
-
logger = getLogger(),
|
|
137
|
-
useLogSuffix = false,
|
|
138
|
-
): Promise<{
|
|
139
|
-
/**
|
|
140
|
-
* The wallet instance.
|
|
141
|
-
*/
|
|
142
|
-
wallet: TestWallet;
|
|
143
|
-
/**
|
|
144
|
-
* Logger instance named as the current test.
|
|
145
|
-
*/
|
|
146
|
-
logger: Logger;
|
|
147
|
-
/**
|
|
148
|
-
* Teardown function
|
|
149
|
-
*/
|
|
150
|
-
teardown: () => Promise<void>;
|
|
151
|
-
}> {
|
|
152
|
-
const PXEConfig = { ...getPXEConfig(), ...opts };
|
|
153
|
-
// For tests we only want proving enabled if specifically requested
|
|
154
|
-
PXEConfig.proverEnabled = !!opts.proverEnabled;
|
|
155
|
-
|
|
156
|
-
// If no data directory provided, create a temp directory and clean up afterwards
|
|
157
|
-
const configuredDataDirectory = PXEConfig.dataDirectory;
|
|
158
|
-
if (!configuredDataDirectory) {
|
|
159
|
-
PXEConfig.dataDirectory = path.join(tmpdir(), randomBytes(8).toString('hex'));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const teardown = configuredDataDirectory ? () => Promise.resolve() : () => tryRmDir(PXEConfig.dataDirectory!);
|
|
163
|
-
|
|
164
|
-
const wallet = await TestWallet.create(aztecNode, PXEConfig, {
|
|
165
|
-
useLogSuffix,
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
return {
|
|
169
|
-
wallet,
|
|
170
|
-
logger,
|
|
171
|
-
teardown,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Function to setup the test against a remote deployment. It is assumed that L1 contract are already deployed
|
|
177
|
-
* @param account - The account for use in create viem wallets.
|
|
178
|
-
* @param config - The aztec Node Configuration
|
|
179
|
-
* @param logger - The logger to be used
|
|
180
|
-
* @param numberOfAccounts - The number of new accounts to be created once the PXE is initiated.
|
|
181
|
-
* (will create extra accounts if the environment doesn't already have enough accounts)
|
|
182
|
-
* @returns Private eXecution Environment (PXE) client, viem wallets, contract addresses etc.
|
|
183
|
-
*/
|
|
184
|
-
async function setupWithRemoteEnvironment(
|
|
185
|
-
account: HDAccount | PrivateKeyAccount,
|
|
186
|
-
config: AztecNodeConfig,
|
|
187
|
-
logger: Logger,
|
|
188
|
-
numberOfAccounts: number,
|
|
189
|
-
): Promise<EndToEndContext> {
|
|
190
|
-
// we are setting up against a remote environment, l1 contracts are already deployed
|
|
191
|
-
const aztecNodeUrl = getAztecUrl();
|
|
192
|
-
logger.verbose(`Creating Aztec Node client to remote host ${aztecNodeUrl}`);
|
|
193
|
-
const aztecNode = createAztecNodeClient(aztecNodeUrl);
|
|
194
|
-
await waitForNode(aztecNode, logger);
|
|
195
|
-
logger.verbose('JSON RPC client connected to Aztec Node');
|
|
196
|
-
logger.verbose(`Retrieving contract addresses from ${aztecNodeUrl}`);
|
|
197
|
-
const { l1ContractAddresses, rollupVersion } = await aztecNode.getNodeInfo();
|
|
198
|
-
|
|
199
|
-
const l1Client = createExtendedL1Client(config.l1RpcUrls, account, foundry);
|
|
200
|
-
|
|
201
|
-
const deployL1ContractsValues: DeployAztecL1ContractsReturnType = {
|
|
202
|
-
l1ContractAddresses,
|
|
203
|
-
l1Client,
|
|
204
|
-
rollupVersion,
|
|
205
|
-
};
|
|
206
|
-
const ethCheatCodes = new EthCheatCodes(config.l1RpcUrls, new DateProvider());
|
|
207
|
-
const wallet = await TestWallet.create(aztecNode);
|
|
208
|
-
const cheatCodes = await CheatCodes.create(config.l1RpcUrls, aztecNode, new DateProvider());
|
|
209
|
-
const teardown = () => Promise.resolve();
|
|
210
|
-
|
|
211
|
-
logger.verbose('Populating wallet from already registered accounts...');
|
|
212
|
-
const initialFundedAccounts = await getInitialTestAccountsData();
|
|
213
|
-
|
|
214
|
-
if (initialFundedAccounts.length < numberOfAccounts) {
|
|
215
|
-
throw new Error(`Required ${numberOfAccounts} accounts. Found ${initialFundedAccounts.length}.`);
|
|
216
|
-
// Deploy new accounts if there's a test that requires more funded accounts in the remote environment.
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const testAccounts = await Promise.all(
|
|
220
|
-
initialFundedAccounts.slice(0, numberOfAccounts).map(async account => {
|
|
221
|
-
const accountManager = await wallet.createSchnorrAccount(account.secret, account.salt, account.signingKey);
|
|
222
|
-
return accountManager.address;
|
|
223
|
-
}),
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
return {
|
|
227
|
-
aztecNode,
|
|
228
|
-
aztecNodeAdmin: undefined,
|
|
229
|
-
sequencer: undefined,
|
|
230
|
-
proverNode: undefined,
|
|
231
|
-
deployL1ContractsValues,
|
|
232
|
-
config,
|
|
233
|
-
initialFundedAccounts,
|
|
234
|
-
wallet,
|
|
235
|
-
accounts: testAccounts,
|
|
236
|
-
logger,
|
|
237
|
-
cheatCodes,
|
|
238
|
-
ethCheatCodes,
|
|
239
|
-
prefilledPublicData: undefined,
|
|
240
|
-
mockGossipSubNetwork: undefined,
|
|
241
|
-
watcher: undefined,
|
|
242
|
-
dateProvider: undefined,
|
|
243
|
-
telemetryClient: undefined,
|
|
244
|
-
teardown,
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/** Options for the e2e tests setup */
|
|
249
|
-
export type SetupOptions = {
|
|
250
|
-
/** State load */
|
|
251
|
-
stateLoad?: string;
|
|
252
|
-
/** Whether to enable metrics collection, if undefined, metrics collection is disabled */
|
|
253
|
-
metricsPort?: number | undefined;
|
|
254
|
-
/** Previously deployed contracts on L1 */
|
|
255
|
-
deployL1ContractsValues?: DeployAztecL1ContractsReturnType;
|
|
256
|
-
/** Initial fee juice for default accounts */
|
|
257
|
-
initialAccountFeeJuice?: Fr;
|
|
258
|
-
/** Number of initial accounts funded with fee juice */
|
|
259
|
-
numberOfInitialFundedAccounts?: number;
|
|
260
|
-
/** Data of the initial funded accounts */
|
|
261
|
-
initialFundedAccounts?: InitialAccountData[];
|
|
262
|
-
/** An initial set of validators */
|
|
263
|
-
initialValidators?: (Operator & { privateKey: `0x${string}` })[];
|
|
264
|
-
/** Anvil Start time */
|
|
265
|
-
l1StartTime?: number;
|
|
266
|
-
/** The anvil time where we should at the earliest be seeing L2 blocks */
|
|
267
|
-
l2StartTime?: number;
|
|
268
|
-
/** Whether to start a prover node */
|
|
269
|
-
startProverNode?: boolean;
|
|
270
|
-
/** Manual config for the telemetry client */
|
|
271
|
-
telemetryConfig?: Partial<TelemetryClientConfig> & { benchmark?: boolean };
|
|
272
|
-
/** Public data that will be inserted in the tree in genesis */
|
|
273
|
-
genesisPublicData?: PublicDataTreeLeaf[];
|
|
274
|
-
/** Specific config for the prover node, if set. */
|
|
275
|
-
proverNodeConfig?: Partial<ProverNodeConfig>;
|
|
276
|
-
/** Whether to use a mock gossip sub network for p2p clients. */
|
|
277
|
-
mockGossipSubNetwork?: boolean;
|
|
278
|
-
/** Whether to disable the anvil test watcher (can still be manually started) */
|
|
279
|
-
disableAnvilTestWatcher?: boolean;
|
|
280
|
-
/** Whether to enable anvil automine during deployment of L1 contracts (consider defaulting this to true). */
|
|
281
|
-
automineL1Setup?: boolean;
|
|
282
|
-
/** How many accounts to seed and unlock in anvil. */
|
|
283
|
-
anvilAccounts?: number;
|
|
284
|
-
/** Port to start anvil (defaults to 8545) */
|
|
285
|
-
anvilPort?: number;
|
|
286
|
-
/** Key to use for publishing L1 contracts */
|
|
287
|
-
l1PublisherKey?: SecretValue<`0x${string}`>;
|
|
288
|
-
/** ZkPassport configuration (domain, scope, mock verifier) */
|
|
289
|
-
zkPassportArgs?: ZKPassportArgs;
|
|
290
|
-
} & Partial<AztecNodeConfig>;
|
|
291
|
-
|
|
292
|
-
/** Context for an end-to-end test as returned by the `setup` function */
|
|
293
|
-
export type EndToEndContext = {
|
|
294
|
-
/** The Aztec Node service or client a connected to it. */
|
|
295
|
-
aztecNode: AztecNode;
|
|
296
|
-
/** Client to the Aztec Node admin interface (undefined if connected to remote environment) */
|
|
297
|
-
aztecNodeAdmin?: AztecNodeAdmin;
|
|
298
|
-
/** The prover node service (only set if startProverNode is true) */
|
|
299
|
-
proverNode: ProverNode | undefined;
|
|
300
|
-
/** A client to the sequencer service (undefined if connected to remote environment) */
|
|
301
|
-
sequencer: SequencerClient | undefined;
|
|
302
|
-
/** Return values from deployAztecL1Contracts function. */
|
|
303
|
-
deployL1ContractsValues: DeployAztecL1ContractsReturnType;
|
|
304
|
-
/** The Aztec Node configuration. */
|
|
305
|
-
config: AztecNodeConfig;
|
|
306
|
-
/** The data for the initial funded accounts. */
|
|
307
|
-
initialFundedAccounts: InitialAccountData[];
|
|
308
|
-
/** The wallet to be used. */
|
|
309
|
-
wallet: TestWallet;
|
|
310
|
-
/** The wallets to be used. */
|
|
311
|
-
accounts: AztecAddress[];
|
|
312
|
-
/** Logger instance named as the current test. */
|
|
313
|
-
logger: Logger;
|
|
314
|
-
/** The cheat codes. */
|
|
315
|
-
cheatCodes: CheatCodes;
|
|
316
|
-
/** The cheat codes for L1 */
|
|
317
|
-
ethCheatCodes: EthCheatCodes;
|
|
318
|
-
/** The anvil test watcher (undefined if connected to remote environment) */
|
|
319
|
-
watcher: AnvilTestWatcher | undefined;
|
|
320
|
-
/** Allows tweaking current system time, used by the epoch cache only (undefined if connected to remote environment) */
|
|
321
|
-
dateProvider: TestDateProvider | undefined;
|
|
322
|
-
/** Telemetry client */
|
|
323
|
-
telemetryClient: TelemetryClient | undefined;
|
|
324
|
-
/** Mock gossip sub network used for gossipping messages (only if mockGossipSubNetwork was set to true in opts) */
|
|
325
|
-
mockGossipSubNetwork: MockGossipSubNetwork | undefined;
|
|
326
|
-
/** Prefilled public data used for setting up nodes. */
|
|
327
|
-
prefilledPublicData: PublicDataTreeLeaf[] | undefined;
|
|
328
|
-
/** Function to stop the started services. */
|
|
329
|
-
teardown: () => Promise<void>;
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Sets up the environment for the end-to-end tests.
|
|
334
|
-
* @param numberOfAccounts - The number of new accounts to be created once the PXE is initiated.
|
|
335
|
-
* @param opts - Options to pass to the node initialization and to the setup script.
|
|
336
|
-
* @param pxeOpts - Options to pass to the PXE initialization.
|
|
337
|
-
*/
|
|
338
|
-
export async function setup(
|
|
339
|
-
numberOfAccounts = 1,
|
|
340
|
-
opts: SetupOptions = {},
|
|
341
|
-
pxeOpts: Partial<PXEConfig> = {},
|
|
342
|
-
chain: Chain = foundry,
|
|
343
|
-
): Promise<EndToEndContext> {
|
|
344
|
-
let anvil: Anvil | undefined;
|
|
345
|
-
try {
|
|
346
|
-
opts.aztecTargetCommitteeSize ??= 0;
|
|
347
|
-
opts.slasherFlavor ??= 'none';
|
|
348
|
-
|
|
349
|
-
const config: AztecNodeConfig & SetupOptions = { ...getConfigEnvVars(), ...opts };
|
|
350
|
-
// use initialValidators for the node config
|
|
351
|
-
config.validatorPrivateKeys = new SecretValue(opts.initialValidators?.map(v => v.privateKey) ?? []);
|
|
352
|
-
|
|
353
|
-
config.peerCheckIntervalMS = TEST_PEER_CHECK_INTERVAL_MS;
|
|
354
|
-
// For tests we only want proving enabled if specifically requested
|
|
355
|
-
config.realProofs = !!opts.realProofs;
|
|
356
|
-
// Only enforce the time table if requested
|
|
357
|
-
config.enforceTimeTable = !!opts.enforceTimeTable;
|
|
358
|
-
|
|
359
|
-
const logger = getLogger();
|
|
360
|
-
|
|
361
|
-
// Create a temp directory for any services that need it and cleanup later
|
|
362
|
-
const directoryToCleanup = path.join(tmpdir(), randomBytes(8).toString('hex'));
|
|
363
|
-
await fs.mkdir(directoryToCleanup, { recursive: true });
|
|
364
|
-
if (!config.dataDirectory) {
|
|
365
|
-
config.dataDirectory = directoryToCleanup;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
if (!config.l1RpcUrls?.length) {
|
|
369
|
-
if (!isAnvilTestChain(chain.id)) {
|
|
370
|
-
throw new Error(`No ETHEREUM_HOSTS set but non anvil chain requested`);
|
|
371
|
-
}
|
|
372
|
-
if (AZTEC_NODE_URL) {
|
|
373
|
-
throw new Error(
|
|
374
|
-
`AZTEC_NODE_URL provided but no ETHEREUM_HOSTS set. Refusing to run, please set both variables so tests can deploy L1 contracts to the same Anvil instance`,
|
|
375
|
-
);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
const res = await startAnvil({
|
|
379
|
-
l1BlockTime: opts.ethereumSlotDuration,
|
|
380
|
-
accounts: opts.anvilAccounts,
|
|
381
|
-
port: opts.anvilPort,
|
|
382
|
-
});
|
|
383
|
-
anvil = res.anvil;
|
|
384
|
-
config.l1RpcUrls = [res.rpcUrl];
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// Enable logging metrics to a local file named after the test suite
|
|
388
|
-
if (isMetricsLoggingRequested()) {
|
|
389
|
-
const filename = path.join('log', getJobName() + '.jsonl');
|
|
390
|
-
logger.info(`Logging metrics to ${filename}`);
|
|
391
|
-
setupMetricsLogger(filename);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
const dateProvider = new TestDateProvider();
|
|
395
|
-
const ethCheatCodes = new EthCheatCodesWithState(config.l1RpcUrls, dateProvider);
|
|
396
|
-
|
|
397
|
-
if (opts.stateLoad) {
|
|
398
|
-
await ethCheatCodes.loadChainState(opts.stateLoad);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
if (opts.l1StartTime) {
|
|
402
|
-
await ethCheatCodes.warp(opts.l1StartTime, { resetBlockInterval: true });
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
let publisherPrivKeyHex: `0x${string}` | undefined = undefined;
|
|
406
|
-
let publisherHdAccount: HDAccount | PrivateKeyAccount | undefined = undefined;
|
|
407
|
-
|
|
408
|
-
if (opts.l1PublisherKey && opts.l1PublisherKey.getValue() && opts.l1PublisherKey.getValue() != NULL_KEY) {
|
|
409
|
-
publisherPrivKeyHex = opts.l1PublisherKey.getValue();
|
|
410
|
-
publisherHdAccount = privateKeyToAccount(publisherPrivKeyHex);
|
|
411
|
-
} else if (
|
|
412
|
-
config.publisherPrivateKeys &&
|
|
413
|
-
config.publisherPrivateKeys.length > 0 &&
|
|
414
|
-
config.publisherPrivateKeys[0].getValue() != NULL_KEY
|
|
415
|
-
) {
|
|
416
|
-
publisherPrivKeyHex = config.publisherPrivateKeys[0].getValue();
|
|
417
|
-
publisherHdAccount = privateKeyToAccount(publisherPrivKeyHex);
|
|
418
|
-
} else if (!MNEMONIC) {
|
|
419
|
-
throw new Error(`Mnemonic not provided and no publisher private key`);
|
|
420
|
-
} else {
|
|
421
|
-
publisherHdAccount = mnemonicToAccount(MNEMONIC, { addressIndex: 0 });
|
|
422
|
-
const publisherPrivKeyRaw = publisherHdAccount.getHdKey().privateKey;
|
|
423
|
-
const publisherPrivKey = publisherPrivKeyRaw === null ? null : Buffer.from(publisherPrivKeyRaw);
|
|
424
|
-
publisherPrivKeyHex = `0x${publisherPrivKey!.toString('hex')}` as const;
|
|
425
|
-
config.publisherPrivateKeys = [new SecretValue(publisherPrivKeyHex)];
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
if (config.coinbase === undefined) {
|
|
429
|
-
config.coinbase = EthAddress.fromString(publisherHdAccount.address);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
if (AZTEC_NODE_URL) {
|
|
433
|
-
// we are setting up against a remote environment, l1 contracts are assumed to already be deployed
|
|
434
|
-
return await setupWithRemoteEnvironment(publisherHdAccount!, config, logger, numberOfAccounts);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
const initialFundedAccounts =
|
|
438
|
-
opts.initialFundedAccounts ??
|
|
439
|
-
(await generateSchnorrAccounts(opts.numberOfInitialFundedAccounts ?? numberOfAccounts));
|
|
440
|
-
const { genesisArchiveRoot, prefilledPublicData, fundingNeeded } = await getGenesisValues(
|
|
441
|
-
initialFundedAccounts.map(a => a.address),
|
|
442
|
-
opts.initialAccountFeeJuice,
|
|
443
|
-
opts.genesisPublicData,
|
|
444
|
-
);
|
|
445
|
-
|
|
446
|
-
const wasAutomining = await ethCheatCodes.isAutoMining();
|
|
447
|
-
const enableAutomine = opts.automineL1Setup && !wasAutomining && isAnvilTestChain(chain.id);
|
|
448
|
-
if (enableAutomine) {
|
|
449
|
-
await ethCheatCodes.setAutomine(true);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
const l1Client = createExtendedL1Client(config.l1RpcUrls, publisherHdAccount!, chain);
|
|
453
|
-
|
|
454
|
-
const deployL1ContractsValues: DeployAztecL1ContractsReturnType = await deployAztecL1Contracts(
|
|
455
|
-
config.l1RpcUrls[0],
|
|
456
|
-
publisherPrivKeyHex!,
|
|
457
|
-
chain.id,
|
|
458
|
-
{
|
|
459
|
-
...getL1ContractsConfigEnvVars(),
|
|
460
|
-
...opts,
|
|
461
|
-
vkTreeRoot: getVKTreeRoot(),
|
|
462
|
-
protocolContractsHash,
|
|
463
|
-
genesisArchiveRoot,
|
|
464
|
-
initialValidators: opts.initialValidators,
|
|
465
|
-
feeJuicePortalInitialBalance: fundingNeeded,
|
|
466
|
-
realVerifier: false,
|
|
467
|
-
},
|
|
468
|
-
);
|
|
469
|
-
|
|
470
|
-
config.l1Contracts = deployL1ContractsValues.l1ContractAddresses;
|
|
471
|
-
config.rollupVersion = deployL1ContractsValues.rollupVersion;
|
|
472
|
-
|
|
473
|
-
if (enableAutomine) {
|
|
474
|
-
await ethCheatCodes.setAutomine(false);
|
|
475
|
-
await ethCheatCodes.setIntervalMining(config.ethereumSlotDuration);
|
|
476
|
-
dateProvider.setTime((await ethCheatCodes.timestamp()) * 1000);
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
if (opts.l2StartTime) {
|
|
480
|
-
// This should only be used in synching test or when you need to have a stable
|
|
481
|
-
// timestamp for the first l2 block.
|
|
482
|
-
await ethCheatCodes.warp(opts.l2StartTime, { resetBlockInterval: true });
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
const watcher = new AnvilTestWatcher(
|
|
486
|
-
new EthCheatCodesWithState(config.l1RpcUrls, dateProvider),
|
|
487
|
-
deployL1ContractsValues.l1ContractAddresses.rollupAddress,
|
|
488
|
-
deployL1ContractsValues.l1Client,
|
|
489
|
-
dateProvider,
|
|
490
|
-
);
|
|
491
|
-
if (!opts.disableAnvilTestWatcher) {
|
|
492
|
-
await watcher.start();
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
const telemetry = await getTelemetryClient(opts.telemetryConfig);
|
|
496
|
-
|
|
497
|
-
await setupSharedBlobStorage(config);
|
|
498
|
-
|
|
499
|
-
logger.verbose('Creating and synching an aztec node', config);
|
|
500
|
-
|
|
501
|
-
const acvmConfig = await getACVMConfig(logger);
|
|
502
|
-
if (acvmConfig) {
|
|
503
|
-
config.acvmWorkingDirectory = acvmConfig.acvmWorkingDirectory;
|
|
504
|
-
config.acvmBinaryPath = acvmConfig.acvmBinaryPath;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
const bbConfig = await getBBConfig(logger);
|
|
508
|
-
if (bbConfig) {
|
|
509
|
-
config.bbBinaryPath = bbConfig.bbBinaryPath;
|
|
510
|
-
config.bbWorkingDirectory = bbConfig.bbWorkingDirectory;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
let mockGossipSubNetwork: MockGossipSubNetwork | undefined;
|
|
514
|
-
let p2pClientDeps: P2PClientDeps<P2PClientType.Full> | undefined = undefined;
|
|
515
|
-
|
|
516
|
-
if (opts.mockGossipSubNetwork) {
|
|
517
|
-
mockGossipSubNetwork = new MockGossipSubNetwork();
|
|
518
|
-
p2pClientDeps = { p2pServiceFactory: getMockPubSubP2PServiceFactory(mockGossipSubNetwork) };
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
// Transactions built against the genesis state must be included in block 1, otherwise they are dropped.
|
|
522
|
-
// To avoid test failures from dropped transactions, we ensure progression beyond genesis before proceeding.
|
|
523
|
-
// For account deployments, we set minTxsPerBlock=1 and deploy accounts sequentially for guaranteed success.
|
|
524
|
-
// If no accounts need deployment, we await an empty block to confirm network progression. After either path
|
|
525
|
-
// completes, we restore the original minTxsPerBlock setting. The deployment and waiting for empty block is
|
|
526
|
-
// handled by the if-else branches on line 632.
|
|
527
|
-
// For more details on why the tx would be dropped see `validate_include_by_timestamp` function in
|
|
528
|
-
// `noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/validation_requests.nr`.
|
|
529
|
-
//
|
|
530
|
-
// Note: If the following seems too convoluted or if it starts making problems, we could drop the "progressing
|
|
531
|
-
// past genesis via an account contract deployment" optimization and just call flush() on the sequencer and wait
|
|
532
|
-
// for an empty block to be mined. This would simplify it all quite a bit but the setup would be slower for tests
|
|
533
|
-
// deploying accounts.
|
|
534
|
-
const originalMinTxsPerBlock = config.minTxsPerBlock;
|
|
535
|
-
if (originalMinTxsPerBlock === undefined) {
|
|
536
|
-
throw new Error('minTxsPerBlock is undefined in e2e test setup');
|
|
537
|
-
}
|
|
538
|
-
config.minTxsPerBlock = numberOfAccounts === 0 ? 0 : 1;
|
|
539
|
-
|
|
540
|
-
config.p2pEnabled = opts.mockGossipSubNetwork || config.p2pEnabled;
|
|
541
|
-
config.p2pIp = opts.p2pIp ?? config.p2pIp ?? '127.0.0.1';
|
|
542
|
-
|
|
543
|
-
if (!config.disableValidator) {
|
|
544
|
-
if ((config.validatorPrivateKeys?.getValue().length ?? 0) === 0) {
|
|
545
|
-
config.validatorPrivateKeys = new SecretValue([generatePrivateKey()]);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
const aztecNode = await AztecNodeService.createAndSync(
|
|
550
|
-
config, // REFACTOR: createAndSync mutates this config
|
|
551
|
-
{ dateProvider, telemetry, p2pClientDeps, logger: createLogger('node:MAIN-aztec-node') },
|
|
552
|
-
{ prefilledPublicData },
|
|
553
|
-
);
|
|
554
|
-
const sequencerClient = aztecNode.getSequencer();
|
|
555
|
-
|
|
556
|
-
if (sequencerClient) {
|
|
557
|
-
const publisher = (sequencerClient as TestSequencerClient).sequencer.publisher;
|
|
558
|
-
publisher.l1TxUtils = DelayedTxUtils.fromL1TxUtils(publisher.l1TxUtils, config.ethereumSlotDuration, l1Client);
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
let proverNode: ProverNode | undefined = undefined;
|
|
562
|
-
if (opts.startProverNode) {
|
|
563
|
-
logger.verbose('Creating and syncing a simulated prover node...');
|
|
564
|
-
const proverNodePrivateKey = getPrivateKeyFromIndex(2);
|
|
565
|
-
const proverNodePrivateKeyHex: Hex = `0x${proverNodePrivateKey!.toString('hex')}`;
|
|
566
|
-
const proverNodeDataDirectory = path.join(directoryToCleanup, randomBytes(8).toString('hex'));
|
|
567
|
-
const proverNodeConfig = { ...config.proverNodeConfig, dataDirectory: proverNodeDataDirectory };
|
|
568
|
-
proverNode = await createAndSyncProverNode(
|
|
569
|
-
proverNodePrivateKeyHex,
|
|
570
|
-
config,
|
|
571
|
-
proverNodeConfig,
|
|
572
|
-
aztecNode,
|
|
573
|
-
prefilledPublicData,
|
|
574
|
-
);
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
logger.verbose('Creating a pxe...');
|
|
578
|
-
const { wallet, teardown: pxeTeardown } = await setupPXEAndGetWallet(aztecNode!, pxeOpts, logger);
|
|
579
|
-
|
|
580
|
-
const cheatCodes = await CheatCodes.create(config.l1RpcUrls, aztecNode, dateProvider);
|
|
581
|
-
|
|
582
|
-
if (
|
|
583
|
-
(opts.aztecTargetCommitteeSize && opts.aztecTargetCommitteeSize > 0) ||
|
|
584
|
-
(opts.initialValidators && opts.initialValidators.length > 0)
|
|
585
|
-
) {
|
|
586
|
-
// We need to advance such that the committee is set up.
|
|
587
|
-
await cheatCodes.rollup.advanceToEpoch(
|
|
588
|
-
EpochNumber.fromBigInt(
|
|
589
|
-
BigInt(await cheatCodes.rollup.getEpoch()) + BigInt(config.lagInEpochsForValidatorSet + 1),
|
|
590
|
-
),
|
|
591
|
-
);
|
|
592
|
-
await cheatCodes.rollup.setupEpoch();
|
|
593
|
-
await cheatCodes.rollup.debugRollup();
|
|
594
|
-
}
|
|
595
|
-
let accounts: AztecAddress[] = [];
|
|
596
|
-
// Below we continue with what we described in the long comment on line 571.
|
|
597
|
-
if (numberOfAccounts === 0) {
|
|
598
|
-
logger.info('No accounts are being deployed, waiting for an empty block 1 to be mined');
|
|
599
|
-
while ((await aztecNode.getBlockNumber()) === 0) {
|
|
600
|
-
await sleep(2000);
|
|
601
|
-
}
|
|
602
|
-
} else {
|
|
603
|
-
logger.info(
|
|
604
|
-
`${numberOfAccounts} accounts are being deployed. Reliably progressing past genesis by setting minTxsPerBlock to 1 and waiting for the accounts to be deployed`,
|
|
605
|
-
);
|
|
606
|
-
const accountsData = initialFundedAccounts.slice(0, numberOfAccounts);
|
|
607
|
-
const accountManagers = await deployFundedSchnorrAccounts(wallet, aztecNode, accountsData);
|
|
608
|
-
accounts = accountManagers.map(accountManager => accountManager.address);
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
// Now we restore the original minTxsPerBlock setting.
|
|
612
|
-
sequencerClient!.getSequencer().updateConfig({ minTxsPerBlock: originalMinTxsPerBlock });
|
|
613
|
-
|
|
614
|
-
if (initialFundedAccounts.length < numberOfAccounts) {
|
|
615
|
-
// TODO: Create (numberOfAccounts - initialFundedAccounts.length) wallets without funds.
|
|
616
|
-
throw new Error(
|
|
617
|
-
`Unable to deploy ${numberOfAccounts} accounts. Only ${initialFundedAccounts.length} accounts were funded.`,
|
|
618
|
-
);
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
const teardown = async () => {
|
|
622
|
-
try {
|
|
623
|
-
await pxeTeardown();
|
|
624
|
-
|
|
625
|
-
await tryStop(aztecNode, logger);
|
|
626
|
-
await tryStop(proverNode, logger);
|
|
627
|
-
|
|
628
|
-
if (acvmConfig?.cleanup) {
|
|
629
|
-
await acvmConfig.cleanup();
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
if (bbConfig?.cleanup) {
|
|
633
|
-
await bbConfig.cleanup();
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
await tryStop(watcher, logger);
|
|
637
|
-
await tryStop(anvil, logger);
|
|
638
|
-
|
|
639
|
-
await tryRmDir(directoryToCleanup, logger);
|
|
640
|
-
} catch (err) {
|
|
641
|
-
logger.error(`Error during e2e test teardown`, err);
|
|
642
|
-
}
|
|
643
|
-
};
|
|
644
|
-
|
|
645
|
-
return {
|
|
646
|
-
aztecNode,
|
|
647
|
-
aztecNodeAdmin: aztecNode,
|
|
648
|
-
cheatCodes,
|
|
649
|
-
ethCheatCodes,
|
|
650
|
-
config,
|
|
651
|
-
dateProvider,
|
|
652
|
-
deployL1ContractsValues,
|
|
653
|
-
initialFundedAccounts,
|
|
654
|
-
logger,
|
|
655
|
-
mockGossipSubNetwork,
|
|
656
|
-
prefilledPublicData,
|
|
657
|
-
proverNode,
|
|
658
|
-
sequencer: sequencerClient,
|
|
659
|
-
teardown,
|
|
660
|
-
telemetryClient: telemetry,
|
|
661
|
-
wallet,
|
|
662
|
-
accounts,
|
|
663
|
-
watcher,
|
|
664
|
-
};
|
|
665
|
-
} catch (err) {
|
|
666
|
-
// TODO: Just hoisted anvil for now to ensure cleanup. Prob need to hoist the rest.
|
|
667
|
-
await anvil?.stop();
|
|
668
|
-
throw err;
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
/**
|
|
673
|
-
* Registers the contract class used for test accounts and publicly deploys the instances requested.
|
|
674
|
-
* Use this when you need to make a public call to an account contract, such as for requesting a public authwit.
|
|
675
|
-
* @param sender - Wallet to send the deployment tx.
|
|
676
|
-
* @param accountsToDeploy - Which accounts to publicly deploy.
|
|
677
|
-
*/
|
|
678
|
-
|
|
679
|
-
export async function ensureAccountContractsPublished(wallet: Wallet, accountsToDeploy: AztecAddress[]) {
|
|
680
|
-
// We have to check whether the accounts are already deployed. This can happen if the test runs against
|
|
681
|
-
// the local network and the test accounts exist
|
|
682
|
-
const accountsAndAddresses = await Promise.all(
|
|
683
|
-
accountsToDeploy.map(async address => {
|
|
684
|
-
return {
|
|
685
|
-
address,
|
|
686
|
-
deployed: (await wallet.getContractMetadata(address)).isContractPublished,
|
|
687
|
-
};
|
|
688
|
-
}),
|
|
689
|
-
);
|
|
690
|
-
const instances = (
|
|
691
|
-
await Promise.all(
|
|
692
|
-
accountsAndAddresses
|
|
693
|
-
.filter(({ deployed }) => !deployed)
|
|
694
|
-
.map(({ address }) => wallet.getContractMetadata(address)),
|
|
695
|
-
)
|
|
696
|
-
).map(contractMetadata => contractMetadata.contractInstance);
|
|
697
|
-
const contractClass = await getContractClassFromArtifact(SchnorrAccountContractArtifact);
|
|
698
|
-
if (!(await wallet.getContractClassMetadata(contractClass.id, true)).isContractClassPubliclyRegistered) {
|
|
699
|
-
await (await publishContractClass(wallet, SchnorrAccountContractArtifact))
|
|
700
|
-
.send({ from: accountsToDeploy[0] })
|
|
701
|
-
.wait();
|
|
702
|
-
}
|
|
703
|
-
const requests = await Promise.all(instances.map(async instance => await publishInstance(wallet, instance!)));
|
|
704
|
-
const batch = new BatchCall(wallet, requests);
|
|
705
|
-
await batch.send({ from: accountsToDeploy[0] }).wait();
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
/** Returns the job name for the current test. */
|
|
709
|
-
function getJobName() {
|
|
710
|
-
return process.env.JOB_NAME ?? expect.getState().currentTestName?.split(' ')[0].replaceAll('/', '_') ?? 'unknown';
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* Returns a logger instance for the current test.
|
|
715
|
-
* @returns a logger instance for the current test.
|
|
716
|
-
*/
|
|
717
|
-
export function getLogger() {
|
|
718
|
-
const describeBlockName = expect.getState().currentTestName?.split(' ')[0].replaceAll('/', ':');
|
|
719
|
-
if (!describeBlockName) {
|
|
720
|
-
const name = expect.getState().testPath?.split('/').pop()?.split('.')[0] ?? 'unknown';
|
|
721
|
-
return createLogger('e2e:' + name);
|
|
722
|
-
}
|
|
723
|
-
return createLogger('e2e:' + describeBlockName);
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
export type BalancesFn = ReturnType<typeof getBalancesFn>;
|
|
727
|
-
export function getBalancesFn(
|
|
728
|
-
symbol: string,
|
|
729
|
-
method: ContractMethod,
|
|
730
|
-
from: AztecAddress,
|
|
731
|
-
logger: any,
|
|
732
|
-
): (...addresses: (AztecAddress | { address: AztecAddress })[]) => Promise<bigint[]> {
|
|
733
|
-
const balances = async (...addressLikes: (AztecAddress | { address: AztecAddress })[]) => {
|
|
734
|
-
const addresses = addressLikes.map(addressLike => ('address' in addressLike ? addressLike.address : addressLike));
|
|
735
|
-
const b = await Promise.all(addresses.map(address => method(address).simulate({ from })));
|
|
736
|
-
const debugString = `${symbol} balances: ${addresses.map((address, i) => `${address}: ${b[i]}`).join(', ')}`;
|
|
737
|
-
logger.verbose(debugString);
|
|
738
|
-
return b;
|
|
739
|
-
};
|
|
740
|
-
|
|
741
|
-
return balances;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
export async function expectMapping<K, V>(
|
|
745
|
-
fn: (...k: K[]) => Promise<V[]>,
|
|
746
|
-
inputs: K[],
|
|
747
|
-
expectedOutputs: V[],
|
|
748
|
-
): Promise<void> {
|
|
749
|
-
expect(inputs.length).toBe(expectedOutputs.length);
|
|
750
|
-
|
|
751
|
-
const outputs = await fn(...inputs);
|
|
752
|
-
|
|
753
|
-
expect(outputs).toEqual(expectedOutputs);
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
export async function expectMappingDelta<K, V extends number | bigint>(
|
|
757
|
-
initialValues: V[],
|
|
758
|
-
fn: (...k: K[]) => Promise<V[]>,
|
|
759
|
-
inputs: K[],
|
|
760
|
-
expectedDiffs: V[],
|
|
761
|
-
): Promise<void> {
|
|
762
|
-
expect(inputs.length).toBe(expectedDiffs.length);
|
|
763
|
-
|
|
764
|
-
const outputs = await fn(...inputs);
|
|
765
|
-
const diffs = outputs.map((output, i) => output - initialValues[i]);
|
|
766
|
-
|
|
767
|
-
expect(diffs).toEqual(expectedDiffs);
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
/**
|
|
771
|
-
* Computes the address of the "canonical" SponsoredFPCContract. This is not a protocol contract
|
|
772
|
-
* but by conventions its address is computed with a salt of 0.
|
|
773
|
-
* @returns The address of the sponsored FPC contract
|
|
774
|
-
*/
|
|
775
|
-
export function getSponsoredFPCInstance(): Promise<ContractInstanceWithAddress> {
|
|
776
|
-
return Promise.resolve(
|
|
777
|
-
getContractInstanceFromInstantiationParams(SponsoredFPCContract.artifact, {
|
|
778
|
-
salt: new Fr(SPONSORED_FPC_SALT),
|
|
779
|
-
}),
|
|
780
|
-
);
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
/**
|
|
784
|
-
* Computes the address of the "canonical" SponsoredFPCContract. This is not a protocol contract
|
|
785
|
-
* but by conventions its address is computed with a salt of 0.
|
|
786
|
-
* @returns The address of the sponsored FPC contract
|
|
787
|
-
*/
|
|
788
|
-
export async function getSponsoredFPCAddress() {
|
|
789
|
-
const sponsoredFPCInstance = await getSponsoredFPCInstance();
|
|
790
|
-
return sponsoredFPCInstance.address;
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
/**
|
|
794
|
-
* Deploy a sponsored FPC contract to a running instance.
|
|
795
|
-
*/
|
|
796
|
-
export async function setupSponsoredFPC(wallet: Wallet) {
|
|
797
|
-
const instance = await getContractInstanceFromInstantiationParams(SponsoredFPCContract.artifact, {
|
|
798
|
-
salt: new Fr(SPONSORED_FPC_SALT),
|
|
799
|
-
});
|
|
800
|
-
|
|
801
|
-
await wallet.registerContract(instance, SponsoredFPCContract.artifact);
|
|
802
|
-
getLogger().info(`SponsoredFPC: ${instance.address}`);
|
|
803
|
-
return instance;
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* Registers the SponsoredFPC in this PXE instance
|
|
808
|
-
* @param wallet - The wallet
|
|
809
|
-
*/
|
|
810
|
-
export async function registerSponsoredFPC(wallet: Wallet): Promise<void> {
|
|
811
|
-
await wallet.registerContract(await getSponsoredFPCInstance(), SponsoredFPCContract.artifact);
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
export async function waitForProvenChain(node: AztecNode, targetBlock?: BlockNumber, timeoutSec = 60, intervalSec = 1) {
|
|
815
|
-
targetBlock ??= await node.getBlockNumber();
|
|
816
|
-
|
|
817
|
-
await retryUntil(
|
|
818
|
-
async () => (await node.getProvenBlockNumber()) >= targetBlock,
|
|
819
|
-
'proven chain status',
|
|
820
|
-
timeoutSec,
|
|
821
|
-
intervalSec,
|
|
822
|
-
);
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
export function createAndSyncProverNode(
|
|
826
|
-
proverNodePrivateKey: `0x${string}`,
|
|
827
|
-
aztecNodeConfig: AztecNodeConfig,
|
|
828
|
-
proverNodeConfig: Partial<ProverNodeConfig> & Pick<DataStoreConfig, 'dataDirectory'> & { dontStart?: boolean },
|
|
829
|
-
aztecNode: AztecNode | undefined,
|
|
830
|
-
prefilledPublicData: PublicDataTreeLeaf[] = [],
|
|
831
|
-
proverNodeDeps: ProverNodeDeps = {},
|
|
832
|
-
) {
|
|
833
|
-
return withLogNameSuffix('prover-node', async () => {
|
|
834
|
-
// Disable stopping the aztec node as the prover coordination test will kill it otherwise
|
|
835
|
-
// This is only required when stopping the prover node for testing
|
|
836
|
-
const aztecNodeTxProvider = aztecNode && {
|
|
837
|
-
getTxByHash: aztecNode.getTxByHash.bind(aztecNode),
|
|
838
|
-
getTxsByHash: aztecNode.getTxsByHash.bind(aztecNode),
|
|
839
|
-
stop: () => Promise.resolve(),
|
|
840
|
-
};
|
|
841
|
-
|
|
842
|
-
const blobClient = await createBlobClientWithFileStores(aztecNodeConfig, createLogger('blob-client:prover-node'));
|
|
843
|
-
|
|
844
|
-
// Creating temp store and archiver for simulated prover node
|
|
845
|
-
const archiverConfig = { ...aztecNodeConfig, dataDirectory: proverNodeConfig.dataDirectory };
|
|
846
|
-
const archiver = await createArchiver(
|
|
847
|
-
archiverConfig,
|
|
848
|
-
{ blobClient, dateProvider: proverNodeDeps.dateProvider },
|
|
849
|
-
{ blockUntilSync: true },
|
|
850
|
-
);
|
|
851
|
-
|
|
852
|
-
// Prover node config is for simulated proofs
|
|
853
|
-
const proverConfig: ProverNodeConfig = {
|
|
854
|
-
...aztecNodeConfig,
|
|
855
|
-
txCollectionNodeRpcUrls: [],
|
|
856
|
-
realProofs: false,
|
|
857
|
-
proverAgentCount: 2,
|
|
858
|
-
publisherPrivateKeys: [new SecretValue(proverNodePrivateKey)],
|
|
859
|
-
proverNodeMaxPendingJobs: 10,
|
|
860
|
-
proverNodeMaxParallelBlocksPerEpoch: 32,
|
|
861
|
-
proverNodePollingIntervalMs: 200,
|
|
862
|
-
txGatheringIntervalMs: 1000,
|
|
863
|
-
txGatheringBatchSize: 10,
|
|
864
|
-
txGatheringMaxParallelRequestsPerNode: 10,
|
|
865
|
-
txGatheringTimeoutMs: 24_000,
|
|
866
|
-
proverNodeFailedEpochStore: undefined,
|
|
867
|
-
proverId: EthAddress.fromNumber(1),
|
|
868
|
-
proverNodeEpochProvingDelayMs: undefined,
|
|
869
|
-
...proverNodeConfig,
|
|
870
|
-
};
|
|
871
|
-
|
|
872
|
-
const l1TxUtils = createDelayedL1TxUtils(
|
|
873
|
-
aztecNodeConfig,
|
|
874
|
-
proverNodePrivateKey,
|
|
875
|
-
'prover-node',
|
|
876
|
-
proverNodeDeps.dateProvider,
|
|
877
|
-
);
|
|
878
|
-
|
|
879
|
-
const proverNode = await createProverNode(
|
|
880
|
-
proverConfig,
|
|
881
|
-
{ ...proverNodeDeps, aztecNodeTxProvider, archiver: archiver as Archiver, l1TxUtils },
|
|
882
|
-
{ prefilledPublicData },
|
|
883
|
-
);
|
|
884
|
-
getLogger().info(`Created and synced prover node`, { publisherAddress: l1TxUtils.client.account!.address });
|
|
885
|
-
if (!proverNodeConfig.dontStart) {
|
|
886
|
-
await proverNode.start();
|
|
887
|
-
}
|
|
888
|
-
return proverNode;
|
|
889
|
-
});
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
function createDelayedL1TxUtils(
|
|
893
|
-
aztecNodeConfig: AztecNodeConfig,
|
|
894
|
-
privateKey: `0x${string}`,
|
|
895
|
-
logName: string,
|
|
896
|
-
dateProvider?: DateProvider,
|
|
897
|
-
) {
|
|
898
|
-
const l1Client = createExtendedL1Client(aztecNodeConfig.l1RpcUrls, privateKey, foundry);
|
|
899
|
-
|
|
900
|
-
const log = createLogger(logName);
|
|
901
|
-
const l1TxUtils = createDelayedL1TxUtilsFromViemWallet(l1Client, log, dateProvider, aztecNodeConfig);
|
|
902
|
-
l1TxUtils.enableDelayer(aztecNodeConfig.ethereumSlotDuration);
|
|
903
|
-
return l1TxUtils;
|
|
904
|
-
}
|