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