@aztec/aztec 0.0.1-commit.993d240 → 0.0.1-commit.9a89641
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/bin/index.js +2 -0
- package/dest/cli/aztec_start_action.d.ts +1 -1
- package/dest/cli/aztec_start_action.d.ts.map +1 -1
- package/dest/cli/aztec_start_action.js +10 -26
- package/dest/cli/aztec_start_options.js +1 -1
- package/dest/cli/cmds/compile.d.ts +1 -1
- package/dest/cli/cmds/compile.d.ts.map +1 -1
- package/dest/cli/cmds/compile.js +25 -17
- package/dest/cli/cmds/prover.d.ts +4 -0
- package/dest/cli/cmds/prover.d.ts.map +1 -0
- package/dest/cli/cmds/prover.js +24 -0
- package/dest/cli/cmds/standby.d.ts +28 -2
- package/dest/cli/cmds/standby.d.ts.map +1 -1
- package/dest/cli/cmds/standby.js +45 -2
- package/dest/cli/cmds/start_bot.d.ts +1 -1
- package/dest/cli/cmds/start_bot.d.ts.map +1 -1
- package/dest/cli/cmds/start_bot.js +5 -1
- package/dest/cli/cmds/start_node.d.ts +1 -1
- package/dest/cli/cmds/start_node.d.ts.map +1 -1
- package/dest/cli/cmds/start_node.js +14 -23
- package/dest/cli/cmds/utils/artifacts.d.ts +6 -1
- package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -1
- package/dest/cli/util.d.ts +10 -5
- package/dest/cli/util.d.ts.map +1 -1
- package/dest/cli/util.js +20 -49
- package/dest/examples/token.js +3 -3
- package/dest/local-network/auth_registry.d.ts +3 -2
- package/dest/local-network/auth_registry.d.ts.map +1 -1
- package/dest/local-network/auth_registry.js +5 -3
- package/dest/local-network/banana_fpc.d.ts +3 -2
- package/dest/local-network/banana_fpc.d.ts.map +1 -1
- package/dest/local-network/banana_fpc.js +5 -3
- package/dest/local-network/local-network.d.ts +6 -5
- package/dest/local-network/local-network.d.ts.map +1 -1
- package/dest/local-network/local-network.js +43 -78
- package/dest/testing/cheat_codes.d.ts +16 -23
- package/dest/testing/cheat_codes.d.ts.map +1 -1
- package/dest/testing/cheat_codes.js +20 -82
- package/dest/testing/epoch_test_settler.d.ts +2 -2
- package/dest/testing/epoch_test_settler.d.ts.map +1 -1
- package/dest/testing/epoch_test_settler.js +5 -26
- package/dest/testing/index.d.ts +2 -2
- package/dest/testing/index.d.ts.map +1 -1
- package/dest/testing/index.js +1 -1
- package/dest/testing/local-network.d.ts +51 -0
- package/dest/testing/local-network.d.ts.map +1 -0
- package/dest/testing/local-network.js +60 -0
- package/dest/testing/token_allowed_setup.d.ts +9 -4
- package/dest/testing/token_allowed_setup.d.ts.map +1 -1
- package/dest/testing/token_allowed_setup.js +12 -8
- package/package.json +34 -34
- package/scripts/templates/counter/contract/src/main.nr +4 -4
- package/src/bin/index.ts +2 -0
- package/src/cli/aztec_start_action.ts +8 -13
- package/src/cli/aztec_start_options.ts +1 -1
- package/src/cli/cmds/compile.ts +29 -16
- package/src/cli/cmds/prover.ts +42 -0
- package/src/cli/cmds/standby.ts +55 -3
- package/src/cli/cmds/start_bot.ts +6 -1
- package/src/cli/cmds/start_node.ts +17 -23
- package/src/cli/cmds/utils/artifacts.ts +5 -0
- package/src/cli/util.ts +21 -62
- package/src/examples/token.ts +11 -3
- package/src/local-network/auth_registry.ts +8 -3
- package/src/local-network/banana_fpc.ts +9 -2
- package/src/local-network/local-network.ts +48 -89
- package/src/testing/cheat_codes.ts +19 -103
- package/src/testing/epoch_test_settler.ts +8 -30
- package/src/testing/index.ts +1 -1
- package/src/testing/local-network.ts +97 -0
- package/src/testing/token_allowed_setup.ts +15 -8
- package/dest/testing/anvil_test_watcher.d.ts +0 -54
- package/dest/testing/anvil_test_watcher.d.ts.map +0 -1
- package/dest/testing/anvil_test_watcher.js +0 -235
- package/src/testing/anvil_test_watcher.ts +0 -273
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env -S node --no-warnings
|
|
2
2
|
import { getInitialTestAccountsData } from '@aztec/accounts/testing';
|
|
3
|
-
import {
|
|
3
|
+
import { createAztecNodeService } from '@aztec/aztec-node';
|
|
4
4
|
import { type AztecNodeConfig, getConfigEnvVars } from '@aztec/aztec-node/config';
|
|
5
5
|
import { Fr } from '@aztec/aztec.js/fields';
|
|
6
6
|
import { createLogger } from '@aztec/aztec.js/log';
|
|
7
7
|
import { type BlobClientInterface, createBlobClient } from '@aztec/blob-client/client';
|
|
8
8
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
9
|
-
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
10
9
|
import { waitForPublicClient } from '@aztec/ethereum/client';
|
|
11
10
|
import { getL1ContractsConfigEnvVars } from '@aztec/ethereum/config';
|
|
12
11
|
import { NULL_KEY } from '@aztec/ethereum/constants';
|
|
13
12
|
import { deployAztecL1Contracts } from '@aztec/ethereum/deploy-aztec-l1-contracts';
|
|
14
13
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
15
|
-
import { EthCheatCodes } from '@aztec/ethereum/test';
|
|
16
14
|
import { SecretValue } from '@aztec/foundation/config';
|
|
17
15
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
18
16
|
import type { LogFn } from '@aztec/foundation/log';
|
|
19
17
|
import { DateProvider, TestDateProvider } from '@aztec/foundation/timer';
|
|
20
18
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
21
19
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
22
|
-
import { SequencerState } from '@aztec/sequencer-client';
|
|
23
20
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
24
21
|
import type { ProvingJobBroker } from '@aztec/stdlib/interfaces/server';
|
|
22
|
+
import { TxStatus } from '@aztec/stdlib/tx';
|
|
25
23
|
import type { GenesisData } from '@aztec/stdlib/world-state';
|
|
26
24
|
import {
|
|
27
25
|
type TelemetryClient,
|
|
@@ -29,17 +27,15 @@ import {
|
|
|
29
27
|
initTelemetryClient,
|
|
30
28
|
} from '@aztec/telemetry-client';
|
|
31
29
|
import { EmbeddedWallet } from '@aztec/wallets/embedded';
|
|
32
|
-
import {
|
|
30
|
+
import { createFundedInitializerlessAccounts } from '@aztec/wallets/testing';
|
|
33
31
|
import { getGenesisValues } from '@aztec/world-state/testing';
|
|
34
32
|
|
|
35
|
-
import {
|
|
33
|
+
import type { Hex } from 'viem';
|
|
36
34
|
import { mnemonicToAccount, privateKeyToAddress } from 'viem/accounts';
|
|
37
35
|
import { foundry } from 'viem/chains';
|
|
38
36
|
|
|
39
37
|
import { createAccountLogs } from '../cli/util.js';
|
|
40
38
|
import { DefaultMnemonic } from '../mnemonic.js';
|
|
41
|
-
import { AnvilTestWatcher } from '../testing/anvil_test_watcher.js';
|
|
42
|
-
import { EpochTestSettler } from '../testing/epoch_test_settler.js';
|
|
43
39
|
import { getTokenAllowedSetupFunctions } from '../testing/token_allowed_setup.js';
|
|
44
40
|
import { publishStandardAuthRegistry } from './auth_registry.js';
|
|
45
41
|
import { getBananaFPCAddress, setupBananaFPC } from './banana_fpc.js';
|
|
@@ -47,7 +43,11 @@ import { getSponsoredFPCAddress } from './sponsored_fpc.js';
|
|
|
47
43
|
|
|
48
44
|
const logger = createLogger('local-network');
|
|
49
45
|
|
|
50
|
-
|
|
46
|
+
// The embedded wallet defaults to waiting for PROPOSED, which returns as soon as a tx lands in a
|
|
47
|
+
// proposed L2 block. That is flaky for the serial sandbox setup below: a proposed block can be
|
|
48
|
+
// pruned before its checkpoint is published, dropping a tx we already moved on from ("Tx dropped by
|
|
49
|
+
// P2P node"). Wait for the checkpoint so each setup tx is durably included before the next is sent.
|
|
50
|
+
const setupWaitOpts = { waitForStatus: TxStatus.CHECKPOINTED };
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Function to deploy our L1 contracts to the local network L1
|
|
@@ -88,6 +88,8 @@ export type LocalNetworkConfig = AztecNodeConfig & {
|
|
|
88
88
|
l1Mnemonic: string;
|
|
89
89
|
/** Whether to deploy test accounts on local network start.*/
|
|
90
90
|
testAccounts: boolean;
|
|
91
|
+
/** Override the default per-address fee juice granted at genesis to funded addresses. */
|
|
92
|
+
initialAccountFeeJuice?: Fr;
|
|
91
93
|
};
|
|
92
94
|
|
|
93
95
|
/**
|
|
@@ -109,10 +111,33 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
|
|
|
109
111
|
// in the setup allowlist so FPC-based fee payments work out of the box.
|
|
110
112
|
const tokenAllowList = await getTokenAllowedSetupFunctions();
|
|
111
113
|
|
|
114
|
+
const envConfig = getConfigEnvVars();
|
|
112
115
|
const aztecNodeConfig: AztecNodeConfig = {
|
|
113
|
-
...
|
|
116
|
+
...envConfig,
|
|
114
117
|
...config,
|
|
118
|
+
skipOrphanProposedBlockPruning: true,
|
|
119
|
+
// The local network builds node config from env without a DATA_DIRECTORY, so the validator's
|
|
120
|
+
// local signing protection runs against an ephemeral store. That is acceptable for this dev
|
|
121
|
+
// network; production validators must persist it and fail-fast when the data directory is unset.
|
|
122
|
+
allowEphemeralSigningProtection: config.allowEphemeralSigningProtection ?? true,
|
|
115
123
|
txPublicSetupAllowListExtend: [...tokenAllowList, ...(config.txPublicSetupAllowListExtend ?? [])],
|
|
124
|
+
// The local network runs against anvil with no committee, so it defaults to the deterministic
|
|
125
|
+
// AutomineSequencer, which owns L1 time control (warps the dateProvider and L1 timestamps to slot
|
|
126
|
+
// boundaries as it builds), replacing the deleted AnvilTestWatcher. This remains true when p2p is
|
|
127
|
+
// enabled for local peer testing; local-network is not a mode for connecting to an existing network.
|
|
128
|
+
useAutomineSequencer: config.useAutomineSequencer ?? true,
|
|
129
|
+
// The AutomineSequencer owns epoch proving in the local network — it writes epoch out hashes to
|
|
130
|
+
// the L1 Outbox and advances the proven tip as checkpoints land, through the same serial queue as
|
|
131
|
+
// its builds — replacing the standalone EpochTestSettler that used to race the build loop.
|
|
132
|
+
automineEnableProveEpoch: config.automineEnableProveEpoch ?? true,
|
|
133
|
+
// Defaults for the local network / sandbox; callers (e.g. the CLI) may override. No real proving
|
|
134
|
+
// happens here — the AutomineSequencer synthetically settles epochs. Short epochs let it write out
|
|
135
|
+
// hashes quickly (so users can consume L2-to-L1 messages without a long wait), with a wider
|
|
136
|
+
// proof-submission window so the synthetic settler has headroom before the rollup would prune an
|
|
137
|
+
// unproven checkpoint.
|
|
138
|
+
realProofs: config.realProofs ?? false,
|
|
139
|
+
aztecEpochDuration: config.aztecEpochDuration ?? 4,
|
|
140
|
+
aztecProofSubmissionEpochs: config.aztecProofSubmissionEpochs ?? 2,
|
|
116
141
|
};
|
|
117
142
|
const hdAccount = mnemonicToAccount(config.l1Mnemonic || DefaultMnemonic);
|
|
118
143
|
if (
|
|
@@ -136,7 +161,7 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
|
|
|
136
161
|
const initialAccounts = await (async () => {
|
|
137
162
|
if (config.testAccounts === true || config.testAccounts === undefined) {
|
|
138
163
|
if (aztecNodeConfig.p2pEnabled) {
|
|
139
|
-
userLog(`Not setting up test accounts
|
|
164
|
+
userLog(`Not setting up test accounts when p2p is enabled`);
|
|
140
165
|
} else {
|
|
141
166
|
userLog(`Setting up test accounts`);
|
|
142
167
|
return await getInitialTestAccountsData();
|
|
@@ -147,46 +172,24 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
|
|
|
147
172
|
|
|
148
173
|
const bananaFPC = await getBananaFPCAddress(initialAccounts);
|
|
149
174
|
const sponsoredFPC = await getSponsoredFPCAddress();
|
|
150
|
-
const prefundAddresses = (aztecNodeConfig.prefundAddresses ?? []).map(a => AztecAddress.
|
|
175
|
+
const prefundAddresses = (aztecNodeConfig.prefundAddresses ?? []).map(a => AztecAddress.fromStringUnsafe(a));
|
|
151
176
|
const fundedAddresses = [
|
|
152
177
|
...initialAccounts.map(a => a.address),
|
|
153
178
|
...(initialAccounts.length ? [bananaFPC, sponsoredFPC] : []),
|
|
154
179
|
...prefundAddresses,
|
|
155
180
|
];
|
|
156
|
-
const { genesisArchiveRoot, genesis, fundingNeeded } = await getGenesisValues(
|
|
181
|
+
const { genesisArchiveRoot, genesis, fundingNeeded } = await getGenesisValues(
|
|
182
|
+
fundedAddresses,
|
|
183
|
+
config.initialAccountFeeJuice,
|
|
184
|
+
);
|
|
157
185
|
|
|
158
186
|
const dateProvider = new TestDateProvider();
|
|
159
187
|
|
|
160
|
-
let cheatcodes: EthCheatCodes | undefined;
|
|
161
|
-
let rollupAddress: EthAddress | undefined;
|
|
162
|
-
let watcher: AnvilTestWatcher | undefined;
|
|
163
188
|
if (!aztecNodeConfig.p2pEnabled) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
{
|
|
168
|
-
genesisArchiveRoot,
|
|
169
|
-
feeJuicePortalInitialBalance: fundingNeeded,
|
|
170
|
-
},
|
|
171
|
-
));
|
|
172
|
-
|
|
173
|
-
const chain =
|
|
174
|
-
aztecNodeConfig.l1RpcUrls.length > 0
|
|
175
|
-
? createEthereumChain([l1RpcUrl], aztecNodeConfig.l1ChainId)
|
|
176
|
-
: { chainInfo: localAnvil };
|
|
177
|
-
|
|
178
|
-
const publicClient = createPublicClient({
|
|
179
|
-
chain: chain.chainInfo,
|
|
180
|
-
transport: fallback([httpViemTransport(l1RpcUrl)]) as any,
|
|
189
|
+
await deployContractsToL1(aztecNodeConfig, aztecNodeConfig.validatorPrivateKeys.getValue()[0], {
|
|
190
|
+
genesisArchiveRoot,
|
|
191
|
+
feeJuicePortalInitialBalance: fundingNeeded,
|
|
181
192
|
});
|
|
182
|
-
|
|
183
|
-
cheatcodes = new EthCheatCodes([l1RpcUrl], dateProvider);
|
|
184
|
-
|
|
185
|
-
watcher = new AnvilTestWatcher(cheatcodes, rollupAddress, publicClient, dateProvider);
|
|
186
|
-
watcher.setisLocalNetwork(true);
|
|
187
|
-
watcher.setIsMarkingAsProven(false); // Do not mark as proven in the watcher. It's marked in the epochTestSettler after the out hash is set.
|
|
188
|
-
|
|
189
|
-
await watcher.start();
|
|
190
193
|
}
|
|
191
194
|
|
|
192
195
|
const telemetry = await initTelemetryClient(getTelemetryClientConfig());
|
|
@@ -194,48 +197,6 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
|
|
|
194
197
|
const blobClient = createBlobClient();
|
|
195
198
|
const node = await createAztecNode(aztecNodeConfig, { telemetry, blobClient, dateProvider }, { genesis });
|
|
196
199
|
|
|
197
|
-
// Now that the node is up, let the watcher check for pending txs so it can skip unfilled slots faster when
|
|
198
|
-
// transactions are waiting in the mempool. Also let it check if the sequencer is actively building, to avoid
|
|
199
|
-
// warping time out from under an in-progress block.
|
|
200
|
-
watcher?.setGetPendingTxCount(() => node.getPendingTxCount());
|
|
201
|
-
const sequencer = node.getSequencer()?.getSequencer();
|
|
202
|
-
if (sequencer) {
|
|
203
|
-
const idleStates: Set<string> = new Set([
|
|
204
|
-
SequencerState.STOPPED,
|
|
205
|
-
SequencerState.STOPPING,
|
|
206
|
-
SequencerState.IDLE,
|
|
207
|
-
SequencerState.SYNCHRONIZING,
|
|
208
|
-
]);
|
|
209
|
-
watcher?.setIsSequencerBuilding(() => !idleStates.has(sequencer.getState()));
|
|
210
|
-
// Under proposer pipelining the L1 publish for slot N happens during wall-clock slot N,
|
|
211
|
-
// but the proposer for slot N has already built the checkpoint during slot N-1 and is
|
|
212
|
-
// waiting for L1 to advance. We need to fast-forward L1 to wake that wait — and the wait
|
|
213
|
-
// we have to break first is `waitForValidParentCheckpointOnL1`, which blocks the
|
|
214
|
-
// checkpoint_proposal_job's background submission task until the archiver has synced past
|
|
215
|
-
// the build slot. That wait happens *before* `PUBLISHING_CHECKPOINT` is set, so a hook on
|
|
216
|
-
// that state transition would be circular (L1 has to advance before the state we'd use to
|
|
217
|
-
// advance L1 fires). The earliest pre-wait signal is `block-proposed`, which the sequencer
|
|
218
|
-
// emits once each block is built. In sandbox single-block-per-slot mode this is
|
|
219
|
-
// effectively "checkpoint built", and the watcher warp is harmless if a subsequent
|
|
220
|
-
// assembly/validation/parent-wait step aborts: L1 just sits one slot ahead, which the
|
|
221
|
-
// cascade absorbs.
|
|
222
|
-
if (watcher) {
|
|
223
|
-
sequencer.on('block-proposed', ({ slot }) => watcher!.setProposedTargetSlot(Number(slot)));
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
let epochTestSettler: EpochTestSettler | undefined;
|
|
228
|
-
if (!aztecNodeConfig.p2pEnabled) {
|
|
229
|
-
epochTestSettler = new EpochTestSettler(
|
|
230
|
-
cheatcodes!,
|
|
231
|
-
rollupAddress!,
|
|
232
|
-
node.getBlockSource(),
|
|
233
|
-
logger.createChild('epoch-settler'),
|
|
234
|
-
{ pollingIntervalMs: 200 },
|
|
235
|
-
);
|
|
236
|
-
await epochTestSettler.start();
|
|
237
|
-
}
|
|
238
|
-
|
|
239
200
|
if (initialAccounts.length) {
|
|
240
201
|
const wallet = await EmbeddedWallet.create(node, {
|
|
241
202
|
pxeConfig: { proverEnabled: aztecNodeConfig.realProofs },
|
|
@@ -243,14 +204,14 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
|
|
|
243
204
|
});
|
|
244
205
|
|
|
245
206
|
userLog('Setting up funded test accounts...');
|
|
246
|
-
const accountManagers = await
|
|
207
|
+
const accountManagers = await createFundedInitializerlessAccounts(wallet, initialAccounts);
|
|
247
208
|
const accLogs = await createAccountLogs(accountManagers, wallet);
|
|
248
209
|
userLog(accLogs.join(''));
|
|
249
210
|
|
|
250
211
|
userLog('Publishing standard AuthRegistry contract...');
|
|
251
|
-
await publishStandardAuthRegistry(wallet, initialAccounts[0].address);
|
|
212
|
+
await publishStandardAuthRegistry(wallet, initialAccounts[0].address, setupWaitOpts);
|
|
252
213
|
|
|
253
|
-
await setupBananaFPC(initialAccounts, wallet, userLog);
|
|
214
|
+
await setupBananaFPC(initialAccounts, wallet, userLog, setupWaitOpts);
|
|
254
215
|
|
|
255
216
|
userLog(`SponsoredFPC: ${await getSponsoredFPCAddress()}`);
|
|
256
217
|
|
|
@@ -260,8 +221,6 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
|
|
|
260
221
|
|
|
261
222
|
const stop = async () => {
|
|
262
223
|
await node.stop();
|
|
263
|
-
await watcher?.stop();
|
|
264
|
-
await epochTestSettler?.stop();
|
|
265
224
|
};
|
|
266
225
|
|
|
267
226
|
return { node, stop };
|
|
@@ -287,7 +246,7 @@ export async function createAztecNode(
|
|
|
287
246
|
...getConfigEnvVars(),
|
|
288
247
|
...config,
|
|
289
248
|
};
|
|
290
|
-
const node = await
|
|
249
|
+
const node = await createAztecNodeService(
|
|
291
250
|
aztecNodeConfig,
|
|
292
251
|
{ ...deps, proverNodeDeps: { broker: deps.proverBroker } },
|
|
293
252
|
options,
|
|
@@ -1,132 +1,48 @@
|
|
|
1
1
|
import { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
|
|
2
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
4
2
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
-
import type { AutomineSequencer } from '@aztec/sequencer-client';
|
|
6
3
|
import type { AztecNode, AztecNodeDebug } from '@aztec/stdlib/interfaces/client';
|
|
7
4
|
|
|
8
5
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @deprecated
|
|
11
|
-
* they became unused (we now have better testing tools). If you are introducing a new functionality to the cheat
|
|
12
|
-
* codes, please consider whether it makes sense to just introduce new utils in your tests instead.
|
|
6
|
+
* Wrapper for Aztec Debug API.
|
|
7
|
+
* @deprecated use the AztecNode debug API directly.
|
|
13
8
|
*/
|
|
14
9
|
export class CheatCodes {
|
|
15
|
-
private logger = createLogger('aztecjs:cheat_codes');
|
|
16
|
-
|
|
17
10
|
constructor(
|
|
18
11
|
/** Cheat codes for L1.*/
|
|
19
12
|
public eth: EthCheatCodes,
|
|
20
13
|
/** Cheat codes for the Aztec Rollup contract on L1. */
|
|
21
14
|
public rollup: RollupCheatCodes,
|
|
22
|
-
/** When wired, redirects time-warps through the AutomineSequencer queue (test-only). */
|
|
23
|
-
private automine?: AutomineSequencer,
|
|
24
15
|
) {}
|
|
25
16
|
|
|
26
|
-
static async create(
|
|
27
|
-
rpcUrls: string[],
|
|
28
|
-
node: AztecNode,
|
|
29
|
-
dateProvider: DateProvider,
|
|
30
|
-
automine?: AutomineSequencer,
|
|
31
|
-
): Promise<CheatCodes> {
|
|
17
|
+
static async create(rpcUrls: string[], node: AztecNode, dateProvider: DateProvider): Promise<CheatCodes> {
|
|
32
18
|
const ethCheatCodes = new EthCheatCodes(rpcUrls, dateProvider);
|
|
33
19
|
const rollupCheatCodes = new RollupCheatCodes(
|
|
34
20
|
ethCheatCodes,
|
|
35
21
|
await node.getNodeInfo().then(n => n.l1ContractAddresses),
|
|
36
22
|
);
|
|
37
|
-
return new CheatCodes(ethCheatCodes, rollupCheatCodes
|
|
23
|
+
return new CheatCodes(ethCheatCodes, rollupCheatCodes);
|
|
38
24
|
}
|
|
39
25
|
|
|
40
26
|
/**
|
|
41
|
-
* Warps the L1 timestamp to
|
|
42
|
-
* the target
|
|
43
|
-
*
|
|
44
|
-
* @param
|
|
45
|
-
* @
|
|
27
|
+
* Warps the L1 timestamp to at least `targetTimestamp` and mines an L2 block advancing the L2 timestamp to at least
|
|
28
|
+
* the target. Forwards to the node's debug API, which serializes the warp through the automine sequencer queue.
|
|
29
|
+
* @param node - The Aztec node whose debug API performs the warp. Must run an automine sequencer.
|
|
30
|
+
* @param targetTimestamp - The target timestamp to warp to (in seconds).
|
|
31
|
+
* @deprecated Call `node.warpL2TimeAtLeastTo(targetTimestamp)` on the node debug API directly.
|
|
46
32
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const currentTimestamp = BigInt(await this.eth.lastBlockTimestamp());
|
|
50
|
-
|
|
51
|
-
if (targetBigInt <= currentTimestamp) {
|
|
52
|
-
throw new Error(
|
|
53
|
-
`warpL2TimeAtLeastTo: target timestamp ${targetBigInt} is not in the future (current L1 timestamp is ${currentTimestamp}).`,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// AutomineSequencer owns time control through its serial queue — delegate to keep warps atomic
|
|
58
|
-
// with respect to any in-flight build, and avoid the mineBlock-loop hack below.
|
|
59
|
-
// `warpTo` internally builds an empty L2 checkpoint, which auto-mines exactly one L1 block at
|
|
60
|
-
// the target slot boundary, so no separate `node.mineBlock()` is needed here.
|
|
61
|
-
if (this.automine) {
|
|
62
|
-
await this.automine.warpTo(Number(targetBigInt));
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const currentSlot = await this.rollup.getSlot();
|
|
67
|
-
const targetSlot = await this.rollup.getSlotAt(targetBigInt);
|
|
68
|
-
|
|
69
|
-
let effectiveTimestamp = targetBigInt;
|
|
70
|
-
let effectiveTargetSlot = targetSlot;
|
|
71
|
-
|
|
72
|
-
if (targetSlot <= currentSlot) {
|
|
73
|
-
// Target lands in the same (or earlier) slot — auto-adjust to the next slot's start.
|
|
74
|
-
const nextSlot = SlotNumber(currentSlot + 1);
|
|
75
|
-
const nextSlotTimestamp = await this.rollup.getTimestampForSlot(nextSlot);
|
|
76
|
-
this.logger.warn(
|
|
77
|
-
`warpL2TimeAtLeastTo: target timestamp ${targetBigInt} falls in current slot ${currentSlot}. ` +
|
|
78
|
-
`Auto-adjusting to start of slot ${nextSlot} at timestamp ${nextSlotTimestamp}.`,
|
|
79
|
-
);
|
|
80
|
-
effectiveTimestamp = nextSlotTimestamp;
|
|
81
|
-
effectiveTargetSlot = nextSlot;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
await this.eth.warp(effectiveTimestamp, { resetBlockInterval: true });
|
|
85
|
-
|
|
86
|
-
// The sequencer's polling loop may have a `work()` cycle in flight that captured pre-warp slot/timestamp values
|
|
87
|
-
// just before our warp landed. That cycle would mine an L2 block at the stale slot — the L1 sync prunes such a
|
|
88
|
-
// block from the canonical chain, but it lingers in local world state and the PXE will use it as the anchor for
|
|
89
|
-
// subsequent txs, leading to `expiration_timestamp` values that are already in the past relative to L1. Mine
|
|
90
|
-
// until we observe an L2 block at (or past) the post-warp slot, ensuring the next tx anchors to a fresh block.
|
|
91
|
-
const maxAttempts = 5;
|
|
92
|
-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
93
|
-
await node.mineBlock();
|
|
94
|
-
const blockData = await node.getBlockData('latest');
|
|
95
|
-
const blockSlot = blockData?.header.globalVariables.slotNumber;
|
|
96
|
-
if (blockSlot !== undefined && BigInt(blockSlot) >= BigInt(effectiveTargetSlot)) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
this.logger.warn(
|
|
100
|
-
`warpL2TimeAtLeastTo: mined L2 block at slot ${blockSlot}, expected at least ${effectiveTargetSlot}. ` +
|
|
101
|
-
`Retrying mineBlock (attempt ${attempt}/${maxAttempts}).`,
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
throw new Error(
|
|
105
|
-
`warpL2TimeAtLeastTo: failed to mine an L2 block at or past slot ${effectiveTargetSlot} after ${maxAttempts} attempts.`,
|
|
106
|
-
);
|
|
33
|
+
warpL2TimeAtLeastTo(node: AztecNode & AztecNodeDebug, targetTimestamp: bigint | number): Promise<void> {
|
|
34
|
+
return node.warpL2TimeAtLeastTo(Number(targetTimestamp));
|
|
107
35
|
}
|
|
108
36
|
|
|
109
37
|
/**
|
|
110
|
-
* Warps the L1 timestamp forward by
|
|
111
|
-
* least by the duration.
|
|
112
|
-
*
|
|
113
|
-
* @param node - The Aztec node
|
|
114
|
-
* @param duration - The duration to advance time by (in seconds)
|
|
38
|
+
* Warps the L1 timestamp forward by at least `duration` seconds and mines an L2 block advancing the L2 timestamp at
|
|
39
|
+
* least by the duration. Forwards to the node's debug API, which serializes the warp through the automine sequencer
|
|
40
|
+
* queue.
|
|
41
|
+
* @param node - The Aztec node whose debug API performs the warp. Must run an automine sequencer.
|
|
42
|
+
* @param duration - The duration to advance time by (in seconds).
|
|
43
|
+
* @deprecated Call `node.warpL2TimeAtLeastBy(duration)` on the node debug API directly.
|
|
115
44
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
throw new Error(`warpL2TimeAtLeastBy: duration must be positive, got ${duration} seconds.`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Advance relative to whichever clock leads. A live sequencer mines L2 blocks at slot boundaries that can run
|
|
122
|
-
// ahead of anvil's L1 timestamp, so basing the target on L1 alone would advance the L2 timestamp by less than
|
|
123
|
-
// `duration`. Anchoring to the latest L2 block timestamp when it leads guarantees the post-warp L2 block is at
|
|
124
|
-
// least `duration` ahead of the current one.
|
|
125
|
-
const currentL1Timestamp = BigInt(await this.eth.lastBlockTimestamp());
|
|
126
|
-
const latestBlockData = await node.getBlockData('latest');
|
|
127
|
-
const latestL2Timestamp = latestBlockData ? BigInt(latestBlockData.header.globalVariables.timestamp) : 0n;
|
|
128
|
-
const baseTimestamp = latestL2Timestamp > currentL1Timestamp ? latestL2Timestamp : currentL1Timestamp;
|
|
129
|
-
const targetTimestamp = baseTimestamp + BigInt(duration);
|
|
130
|
-
await this.warpL2TimeAtLeastTo(node, targetTimestamp);
|
|
45
|
+
warpL2TimeAtLeastBy(node: AztecNode & AztecNodeDebug, duration: bigint | number): Promise<void> {
|
|
46
|
+
return node.warpL2TimeAtLeastBy(Number(duration));
|
|
131
47
|
}
|
|
132
48
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Fr } from '@aztec/aztec.js/fields';
|
|
2
1
|
import { type EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
|
|
3
|
-
import {
|
|
2
|
+
import type { EpochNumber } from '@aztec/foundation/branded-types';
|
|
4
3
|
import type { Logger } from '@aztec/foundation/log';
|
|
4
|
+
import { settleEpochOutbox } from '@aztec/prover-client/test';
|
|
5
5
|
import { EpochMonitor } from '@aztec/prover-node';
|
|
6
6
|
import type { EthAddress, L2BlockSource } from '@aztec/stdlib/block';
|
|
7
|
-
import { computeEpochOutHash } from '@aztec/stdlib/messaging';
|
|
8
7
|
|
|
9
8
|
export class EpochTestSettler {
|
|
10
9
|
private rollupCheatCodes: RollupCheatCodes;
|
|
@@ -31,33 +30,12 @@ export class EpochTestSettler {
|
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
async handleEpochReadyToProve(epoch: EpochNumber): Promise<boolean> {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
let previousSlotNumber = SlotNumber.ZERO;
|
|
41
|
-
let checkpointIndex = -1;
|
|
42
|
-
|
|
43
|
-
for (const block of blocks) {
|
|
44
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
45
|
-
if (slotNumber !== previousSlotNumber) {
|
|
46
|
-
checkpointIndex++;
|
|
47
|
-
messagesInEpoch[checkpointIndex] = [];
|
|
48
|
-
previousSlotNumber = slotNumber;
|
|
49
|
-
}
|
|
50
|
-
messagesInEpoch[checkpointIndex].push(block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const outHash = computeEpochOutHash(messagesInEpoch);
|
|
54
|
-
if (!outHash.isZero()) {
|
|
55
|
-
await this.rollupCheatCodes.insertOutbox(epoch, messagesInEpoch.length, outHash.toBigInt());
|
|
56
|
-
} else {
|
|
57
|
-
this.log.info(`No L2 to L1 messages in epoch ${epoch}`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const lastCheckpoint = blocks.at(-1)?.checkpointNumber;
|
|
33
|
+
const lastCheckpoint = await settleEpochOutbox({
|
|
34
|
+
rollupCheatCodes: this.rollupCheatCodes,
|
|
35
|
+
l2BlockSource: this.l2BlockSource,
|
|
36
|
+
epoch,
|
|
37
|
+
log: this.log,
|
|
38
|
+
});
|
|
61
39
|
if (lastCheckpoint !== undefined) {
|
|
62
40
|
await this.rollupCheatCodes.markAsProven(lastCheckpoint);
|
|
63
41
|
} else {
|
package/src/testing/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { AnvilTestWatcher, type AnvilTestWatcherOpts } from './anvil_test_watcher.js';
|
|
2
1
|
export { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
|
|
3
2
|
export { CheatCodes } from './cheat_codes.js';
|
|
4
3
|
export { EpochTestSettler } from './epoch_test_settler.js';
|
|
4
|
+
export { setupLocalNetwork, TEST_FEE_PADDING, type LocalNetwork, type LocalNetworkOptions } from './local-network.js';
|
|
5
5
|
export { getTokenAllowedSetupFunctions } from './token_allowed_setup.js';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { AztecNodeService } from '@aztec/aztec-node';
|
|
2
|
+
import type { AztecNodeConfig } from '@aztec/aztec-node/config';
|
|
3
|
+
import type { Fr } from '@aztec/aztec.js/fields';
|
|
4
|
+
import { startAnvil } from '@aztec/ethereum/test';
|
|
5
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
+
|
|
7
|
+
import { foundry } from 'viem/chains';
|
|
8
|
+
|
|
9
|
+
import { createLocalNetwork } from '../local-network/local-network.js';
|
|
10
|
+
|
|
11
|
+
/** A running in-process local network: an inline Aztec node backed by its own anvil L1. */
|
|
12
|
+
export interface LocalNetwork extends AsyncDisposable {
|
|
13
|
+
/** Fully-synced Aztec node, ready to serve client requests. */
|
|
14
|
+
node: AztecNodeService;
|
|
15
|
+
/** RPC URL of the spawned anvil instance. */
|
|
16
|
+
l1RpcUrl: string;
|
|
17
|
+
/** Chain id used on L1 (foundry's default 31337). */
|
|
18
|
+
l1ChainId: number;
|
|
19
|
+
/** Stops every process started by the fixture: node and anvil. Also invoked by `await using`. */
|
|
20
|
+
stop: () => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Options for {@link setupLocalNetwork}. */
|
|
24
|
+
export interface LocalNetworkOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Addresses that should hold fee juice at genesis. Saves each of these the round-trip of bridging
|
|
27
|
+
* + claiming fee juice before they can pay for gas.
|
|
28
|
+
*/
|
|
29
|
+
fundedAddresses?: AztecAddress[];
|
|
30
|
+
/** Override the default per-address genesis fee juice granted to {@link fundedAddresses}. */
|
|
31
|
+
initialAccountFeeJuice?: Fr;
|
|
32
|
+
/** Node config overrides, e.g. `realProofs`, `aztecEpochDuration`, `p2pEnabled`. */
|
|
33
|
+
config?: Partial<AztecNodeConfig>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Spin up an in-process local network with the given addresses pre-funded.
|
|
38
|
+
*
|
|
39
|
+
* Each call spawns its own anvil on an OS-assigned random port and runs the Aztec node inline via
|
|
40
|
+
* the same {@link createLocalNetwork} codepath that backs `aztec start --local-network` (with the
|
|
41
|
+
* sandbox account/FPC/token setup skipped). Distinct ports let independent suites run in parallel.
|
|
42
|
+
* The caller must `await result.stop()` in its teardown (or hold the result with `await using`).
|
|
43
|
+
*
|
|
44
|
+
* Requires a Foundry toolchain (`anvil`/`forge`), installed via `aztec-up` or `foundryup`. Binaries
|
|
45
|
+
* are located in the standard install directories or on `PATH`; set `$ANVIL_BIN` / `$FORGE_BIN` to
|
|
46
|
+
* pin specific ones.
|
|
47
|
+
*/
|
|
48
|
+
export async function setupLocalNetwork(opts: LocalNetworkOptions = {}): Promise<LocalNetwork> {
|
|
49
|
+
// `--port 0` → anvil binds an ephemeral port that `startAnvil` reads back, so parallel suites
|
|
50
|
+
// never collide on a fixed port.
|
|
51
|
+
const { rpcUrl, stop: stopAnvil } = await startAnvil({ port: 0 });
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const { node, stop: stopNode } = await createLocalNetwork(
|
|
55
|
+
{
|
|
56
|
+
...opts.config,
|
|
57
|
+
l1RpcUrls: [rpcUrl],
|
|
58
|
+
testAccounts: false,
|
|
59
|
+
prefundAddresses: (opts.fundedAddresses ?? []).map(a => a.toString()),
|
|
60
|
+
initialAccountFeeJuice: opts.initialAccountFeeJuice,
|
|
61
|
+
},
|
|
62
|
+
() => {},
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
// Stop the node before anvil (its teardown still talks to L1); the finally guarantees anvil is
|
|
66
|
+
// reaped even if node shutdown throws.
|
|
67
|
+
const stop = async () => {
|
|
68
|
+
try {
|
|
69
|
+
await stopNode();
|
|
70
|
+
} finally {
|
|
71
|
+
await stopAnvil();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
node,
|
|
77
|
+
l1RpcUrl: rpcUrl,
|
|
78
|
+
l1ChainId: foundry.id,
|
|
79
|
+
stop,
|
|
80
|
+
[Symbol.asyncDispose]: stop,
|
|
81
|
+
};
|
|
82
|
+
} catch (err) {
|
|
83
|
+
await stopAnvil();
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Min-fee padding multiplier for test wallets whose txs may mine well after their fee estimate.
|
|
90
|
+
* The automine sequencer builds one block per tx and advances L1 time in big jumps, and proposer
|
|
91
|
+
* pipelining evolves the fee-asset price across the build/publish gap (~20x observed in CI), so the
|
|
92
|
+
* network's congestion base fee can swing sharply between the wallet's fee estimate and the block
|
|
93
|
+
* the tx actually lands in. The default wallet padding isn't enough and trips
|
|
94
|
+
* `maxFeesPerGas.feePerL2Gas must be >= gasFees.feePerL2Gas`. Apply via
|
|
95
|
+
* `wallet.setMinFeePadding(TEST_FEE_PADDING)` on every test wallet that sends txs.
|
|
96
|
+
*/
|
|
97
|
+
export const TEST_FEE_PADDING = 30;
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
|
|
2
2
|
import { buildAllowedElement } from '@aztec/p2p/msg_validators';
|
|
3
|
+
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
3
4
|
import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
4
5
|
import type { AllowedElement } from '@aztec/stdlib/interfaces/server';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
* Returns
|
|
8
|
-
*
|
|
8
|
+
* Returns the allowlist entries needed for FPC-based fee payments, keyed by the contract class of
|
|
9
|
+
* the `artifact` actually deployed as the fee token (defaults to canonical Token). The setup-phase
|
|
10
|
+
* validator matches these entries by class id, so a test deploying the codegen'd TestToken as its
|
|
11
|
+
* fee vehicle must pass `TestTokenContract.artifact` here -- otherwise the FPC fee calls are matched
|
|
12
|
+
* against the wrong class and rejected. Test-only: FPC fee payment with custom tokens won't work on
|
|
13
|
+
* mainnet alpha.
|
|
9
14
|
*/
|
|
10
|
-
export async function getTokenAllowedSetupFunctions(
|
|
11
|
-
|
|
15
|
+
export async function getTokenAllowedSetupFunctions(
|
|
16
|
+
artifact: ContractArtifact = TokenContractArtifact,
|
|
17
|
+
): Promise<AllowedElement[]> {
|
|
18
|
+
const tokenClassId = (await getContractClassFromArtifact(artifact)).id;
|
|
12
19
|
const target = { classId: tokenClassId };
|
|
13
20
|
return Promise.all([
|
|
14
|
-
//
|
|
15
|
-
buildAllowedElement(
|
|
16
|
-
//
|
|
17
|
-
buildAllowedElement(
|
|
21
|
+
// needed for private transfers via FPC (transfer_to_public enqueues this)
|
|
22
|
+
buildAllowedElement(artifact, target, '_increase_public_balance', { onlySelf: true }),
|
|
23
|
+
// needed for public transfers via FPC (fee_entrypoint_public enqueues this)
|
|
24
|
+
buildAllowedElement(artifact, target, 'transfer_in_public'),
|
|
18
25
|
]);
|
|
19
26
|
}
|