@aztec/aztec 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0
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 +14 -5
- package/dest/cli/admin_api_key_store.d.ts +45 -0
- package/dest/cli/admin_api_key_store.d.ts.map +1 -0
- package/dest/cli/admin_api_key_store.js +98 -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 +69 -31
- package/dest/cli/aztec_start_options.d.ts +2 -2
- package/dest/cli/aztec_start_options.d.ts.map +1 -1
- package/dest/cli/aztec_start_options.js +53 -48
- package/dest/cli/cli.d.ts +1 -1
- package/dest/cli/cli.d.ts.map +1 -1
- package/dest/cli/cli.js +4 -37
- package/dest/cli/cmds/compile.d.ts +4 -0
- package/dest/cli/cmds/compile.d.ts.map +1 -0
- package/dest/cli/cmds/compile.js +174 -0
- package/dest/cli/cmds/migrate_ha_db.d.ts +3 -0
- package/dest/cli/cmds/migrate_ha_db.d.ts.map +1 -0
- package/dest/cli/cmds/migrate_ha_db.js +27 -0
- package/dest/cli/cmds/profile.d.ts +4 -0
- package/dest/cli/cmds/profile.d.ts.map +1 -0
- package/dest/cli/cmds/profile.js +8 -0
- package/dest/cli/cmds/profile_flamegraph.d.ts +4 -0
- package/dest/cli/cmds/profile_flamegraph.d.ts.map +1 -0
- package/dest/cli/cmds/profile_flamegraph.js +52 -0
- package/dest/cli/cmds/profile_gates.d.ts +4 -0
- package/dest/cli/cmds/profile_gates.d.ts.map +1 -0
- package/dest/cli/cmds/profile_gates.js +76 -0
- package/dest/cli/cmds/profile_utils.d.ts +18 -0
- package/dest/cli/cmds/profile_utils.d.ts.map +1 -0
- package/dest/cli/cmds/profile_utils.js +50 -0
- 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 +56 -0
- package/dest/cli/cmds/standby.d.ts.map +1 -0
- package/dest/cli/cmds/standby.js +140 -0
- package/dest/cli/cmds/start_bot.d.ts +3 -3
- package/dest/cli/cmds/start_bot.d.ts.map +1 -1
- package/dest/cli/cmds/start_bot.js +18 -10
- package/dest/cli/cmds/start_node.d.ts +3 -2
- package/dest/cli/cmds/start_node.d.ts.map +1 -1
- package/dest/cli/cmds/start_node.js +83 -52
- package/dest/cli/cmds/start_p2p_bootstrap.d.ts +2 -2
- package/dest/cli/cmds/start_p2p_bootstrap.d.ts.map +1 -1
- package/dest/cli/cmds/start_p2p_bootstrap.js +2 -3
- package/dest/cli/cmds/start_prover_agent.d.ts +1 -1
- package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -1
- package/dest/cli/cmds/start_prover_agent.js +8 -20
- package/dest/cli/cmds/start_prover_broker.d.ts +1 -1
- package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
- package/dest/cli/cmds/start_prover_broker.js +25 -16
- package/dest/cli/cmds/start_txe.d.ts +2 -2
- package/dest/cli/cmds/start_txe.d.ts.map +1 -1
- package/dest/cli/cmds/start_txe.js +6 -5
- package/dest/cli/cmds/utils/artifacts.d.ts +26 -0
- package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -0
- package/dest/cli/cmds/utils/artifacts.js +24 -0
- package/dest/cli/cmds/utils/collect_crate_dirs.d.ts +21 -0
- package/dest/cli/cmds/utils/collect_crate_dirs.d.ts.map +1 -0
- package/dest/cli/cmds/utils/collect_crate_dirs.js +114 -0
- package/dest/cli/cmds/utils/needs_recompile.d.ts +10 -0
- package/dest/cli/cmds/utils/needs_recompile.d.ts.map +1 -0
- package/dest/cli/cmds/utils/needs_recompile.js +90 -0
- package/dest/cli/cmds/utils/spawn.d.ts +3 -0
- package/dest/cli/cmds/utils/spawn.d.ts.map +1 -0
- package/dest/cli/cmds/utils/spawn.js +16 -0
- package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts +4 -0
- package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts.map +1 -0
- package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.js +61 -0
- package/dest/cli/util.d.ts +14 -20
- package/dest/cli/util.d.ts.map +1 -1
- package/dest/cli/util.js +38 -101
- package/dest/examples/token.js +12 -12
- package/dest/examples/util.d.ts +2 -2
- package/dest/examples/util.d.ts.map +1 -1
- package/dest/local-network/auth_registry.d.ts +5 -0
- package/dest/local-network/auth_registry.d.ts.map +1 -0
- package/dest/local-network/auth_registry.js +17 -0
- 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 +14 -10
- package/dest/local-network/local-network.d.ts +18 -41
- package/dest/local-network/local-network.d.ts.map +1 -1
- package/dest/local-network/local-network.js +98 -76
- package/dest/testing/cheat_codes.d.ts +19 -23
- package/dest/testing/cheat_codes.d.ts.map +1 -1
- package/dest/testing/cheat_codes.js +17 -43
- package/dest/testing/epoch_test_settler.d.ts +19 -0
- package/dest/testing/epoch_test_settler.d.ts.map +1 -0
- package/dest/testing/epoch_test_settler.js +42 -0
- package/dest/testing/index.d.ts +4 -2
- package/dest/testing/index.d.ts.map +1 -1
- package/dest/testing/index.js +3 -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 +12 -0
- package/dest/testing/token_allowed_setup.d.ts.map +1 -0
- package/dest/testing/token_allowed_setup.js +24 -0
- package/package.json +36 -33
- package/scripts/add_crate.sh +53 -0
- package/scripts/aztec.sh +26 -9
- package/scripts/init.sh +23 -19
- package/scripts/new.sh +48 -24
- package/scripts/setup_workspace.sh +69 -0
- package/scripts/templates/blank/contract/Nargo.toml +6 -0
- package/scripts/templates/blank/contract/src/main.nr +10 -0
- package/scripts/templates/blank/test/Nargo.toml +7 -0
- package/scripts/templates/blank/test/src/lib.nr +11 -0
- package/scripts/templates/counter/contract/Nargo.toml +7 -0
- package/scripts/templates/counter/contract/src/main.nr +48 -0
- package/scripts/templates/counter/test/Nargo.toml +7 -0
- package/scripts/templates/counter/test/src/lib.nr +32 -0
- package/src/bin/index.ts +15 -5
- package/src/cli/admin_api_key_store.ts +128 -0
- package/src/cli/aztec_start_action.ts +69 -23
- package/src/cli/aztec_start_options.ts +61 -55
- package/src/cli/cli.ts +4 -37
- package/src/cli/cmds/compile.ts +205 -0
- package/src/cli/cmds/migrate_ha_db.ts +43 -0
- package/src/cli/cmds/profile.ts +26 -0
- package/src/cli/cmds/profile_flamegraph.ts +64 -0
- package/src/cli/cmds/profile_gates.ts +84 -0
- package/src/cli/cmds/profile_utils.ts +58 -0
- package/src/cli/cmds/prover.ts +42 -0
- package/src/cli/cmds/standby.ts +184 -0
- package/src/cli/cmds/start_bot.ts +18 -12
- package/src/cli/cmds/start_node.ts +93 -53
- package/src/cli/cmds/start_p2p_bootstrap.ts +3 -3
- package/src/cli/cmds/start_prover_agent.ts +9 -20
- package/src/cli/cmds/start_prover_broker.ts +29 -26
- package/src/cli/cmds/start_txe.ts +7 -5
- package/src/cli/cmds/utils/artifacts.ts +49 -0
- package/src/cli/cmds/utils/collect_crate_dirs.ts +118 -0
- package/src/cli/cmds/utils/needs_recompile.ts +98 -0
- package/src/cli/cmds/utils/spawn.ts +16 -0
- package/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +76 -0
- package/src/cli/util.ts +41 -120
- package/src/examples/token.ts +21 -13
- package/src/examples/util.ts +1 -1
- package/src/local-network/auth_registry.ts +19 -0
- package/src/local-network/banana_fpc.ts +17 -9
- package/src/local-network/local-network.ts +124 -111
- package/src/testing/cheat_codes.ts +18 -49
- package/src/testing/epoch_test_settler.ts +47 -0
- package/src/testing/index.ts +3 -1
- package/src/testing/local-network.ts +97 -0
- package/src/testing/token_allowed_setup.ts +26 -0
- package/dest/cli/cmds/start_archiver.d.ts +0 -9
- package/dest/cli/cmds/start_archiver.d.ts.map +0 -1
- package/dest/cli/cmds/start_archiver.js +0 -50
- package/dest/cli/cmds/start_blob_sink.d.ts +0 -3
- package/dest/cli/cmds/start_blob_sink.d.ts.map +0 -1
- package/dest/cli/cmds/start_blob_sink.js +0 -33
- package/dest/cli/cmds/start_prover_node.d.ts +0 -7
- package/dest/cli/cmds/start_prover_node.d.ts.map +0 -1
- package/dest/cli/cmds/start_prover_node.js +0 -108
- package/dest/cli/release_version.d.ts +0 -2
- package/dest/cli/release_version.d.ts.map +0 -1
- package/dest/cli/release_version.js +0 -14
- package/dest/testing/anvil_test_watcher.d.ts +0 -34
- package/dest/testing/anvil_test_watcher.d.ts.map +0 -1
- package/dest/testing/anvil_test_watcher.js +0 -144
- package/scripts/compile.sh +0 -44
- package/scripts/extract_function.js +0 -47
- package/scripts/flamegraph.sh +0 -59
- package/scripts/setup_project.sh +0 -31
- package/src/cli/cmds/start_archiver.ts +0 -61
- package/src/cli/cmds/start_blob_sink.ts +0 -57
- package/src/cli/cmds/start_prover_node.ts +0 -124
- package/src/cli/release_version.ts +0 -21
- package/src/testing/anvil_test_watcher.ts +0 -166
package/src/examples/util.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
-
import type { ExtendedViemWalletClient } from '@aztec/ethereum';
|
|
2
|
+
import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
|
|
3
3
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
4
4
|
|
|
5
5
|
import type { Abi, Narrow } from 'abitype';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { WaitOpts } from '@aztec/aztec.js/contracts';
|
|
2
|
+
import { publishContractClass, publishInstance } from '@aztec/aztec.js/deployment';
|
|
3
|
+
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
4
|
+
import { AuthRegistryArtifact, getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry';
|
|
5
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
+
|
|
7
|
+
export async function publishStandardAuthRegistry(
|
|
8
|
+
wallet: Wallet,
|
|
9
|
+
from: AztecAddress,
|
|
10
|
+
waitOpts?: WaitOpts,
|
|
11
|
+
): Promise<void> {
|
|
12
|
+
const { instance, contractClass } = await getStandardAuthRegistry();
|
|
13
|
+
if (!(await wallet.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered) {
|
|
14
|
+
await (await publishContractClass(wallet, AuthRegistryArtifact)).send({ from, wait: waitOpts });
|
|
15
|
+
}
|
|
16
|
+
if (!(await wallet.getContractMetadata(instance.address)).isContractPublished) {
|
|
17
|
+
await publishInstance(wallet, instance).send({ from, wait: waitOpts });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type InitialAccountData, getInitialTestAccountsData } from '@aztec/accounts/testing';
|
|
2
|
+
import type { WaitOpts } from '@aztec/aztec.js/contracts';
|
|
2
3
|
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
3
|
-
import { Fr } from '@aztec/foundation/
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import type { LogFn } from '@aztec/foundation/log';
|
|
5
6
|
import { FPCContract } from '@aztec/noir-contracts.js/FPC';
|
|
6
7
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
@@ -45,16 +46,23 @@ export async function getBananaFPCAddress(initialAccounts: InitialAccountData[])
|
|
|
45
46
|
return (await getBananaFPCInstance(initialAccounts)).address;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
export async function setupBananaFPC(
|
|
49
|
+
export async function setupBananaFPC(
|
|
50
|
+
initialAccounts: InitialAccountData[],
|
|
51
|
+
wallet: Wallet,
|
|
52
|
+
log: LogFn,
|
|
53
|
+
waitOpts?: WaitOpts,
|
|
54
|
+
) {
|
|
49
55
|
const bananaCoinAddress = await getBananaCoinAddress(initialAccounts);
|
|
50
56
|
const admin = getBananaAdmin(initialAccounts);
|
|
51
|
-
const [bananaCoin, fpc] = await Promise.all([
|
|
52
|
-
TokenContract.deploy(wallet, admin, bananaCoinArgs.name, bananaCoinArgs.symbol, bananaCoinArgs.decimal
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
const [{ contract: bananaCoin }, { contract: fpc }] = await Promise.all([
|
|
58
|
+
TokenContract.deploy(wallet, admin, bananaCoinArgs.name, bananaCoinArgs.symbol, bananaCoinArgs.decimal, {
|
|
59
|
+
salt: BANANA_COIN_SALT,
|
|
60
|
+
universalDeploy: true,
|
|
61
|
+
}).send({ from: admin, wait: waitOpts }),
|
|
62
|
+
FPCContract.deploy(wallet, bananaCoinAddress, admin, { salt: BANANA_FPC_SALT, universalDeploy: true }).send({
|
|
63
|
+
from: admin,
|
|
64
|
+
wait: waitOpts,
|
|
65
|
+
}),
|
|
58
66
|
]);
|
|
59
67
|
|
|
60
68
|
log(`BananaCoin: ${bananaCoin.address}`);
|
|
@@ -1,46 +1,53 @@
|
|
|
1
1
|
#!/usr/bin/env -S node --no-warnings
|
|
2
2
|
import { getInitialTestAccountsData } from '@aztec/accounts/testing';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { createAztecNodeService } from '@aztec/aztec-node';
|
|
4
|
+
import { type AztecNodeConfig, getConfigEnvVars } from '@aztec/aztec-node/config';
|
|
5
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
6
|
+
import { createLogger } from '@aztec/aztec.js/log';
|
|
7
|
+
import { type BlobClientInterface, createBlobClient } from '@aztec/blob-client/client';
|
|
6
8
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
getL1ContractsConfigEnvVars,
|
|
13
|
-
waitForPublicClient,
|
|
14
|
-
} from '@aztec/ethereum';
|
|
15
|
-
import { EthCheatCodes } from '@aztec/ethereum/test';
|
|
9
|
+
import { waitForPublicClient } from '@aztec/ethereum/client';
|
|
10
|
+
import { getL1ContractsConfigEnvVars } from '@aztec/ethereum/config';
|
|
11
|
+
import { NULL_KEY } from '@aztec/ethereum/constants';
|
|
12
|
+
import { deployAztecL1Contracts } from '@aztec/ethereum/deploy-aztec-l1-contracts';
|
|
13
|
+
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
16
14
|
import { SecretValue } from '@aztec/foundation/config';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
15
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
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
|
|
20
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
21
|
+
import type { ProvingJobBroker } from '@aztec/stdlib/interfaces/server';
|
|
22
|
+
import { TxStatus } from '@aztec/stdlib/tx';
|
|
23
|
+
import type { GenesisData } from '@aztec/stdlib/world-state';
|
|
23
24
|
import {
|
|
24
25
|
type TelemetryClient,
|
|
25
26
|
getConfigEnvVars as getTelemetryClientConfig,
|
|
26
27
|
initTelemetryClient,
|
|
27
28
|
} from '@aztec/telemetry-client';
|
|
28
|
-
import {
|
|
29
|
+
import { EmbeddedWallet } from '@aztec/wallets/embedded';
|
|
30
|
+
import { createFundedInitializerlessAccounts } from '@aztec/wallets/testing';
|
|
29
31
|
import { getGenesisValues } from '@aztec/world-state/testing';
|
|
30
32
|
|
|
31
|
-
import
|
|
33
|
+
import type { Hex } from 'viem';
|
|
32
34
|
import { mnemonicToAccount, privateKeyToAddress } from 'viem/accounts';
|
|
33
35
|
import { foundry } from 'viem/chains';
|
|
34
36
|
|
|
35
37
|
import { createAccountLogs } from '../cli/util.js';
|
|
36
38
|
import { DefaultMnemonic } from '../mnemonic.js';
|
|
37
|
-
import {
|
|
39
|
+
import { getTokenAllowedSetupFunctions } from '../testing/token_allowed_setup.js';
|
|
40
|
+
import { publishStandardAuthRegistry } from './auth_registry.js';
|
|
38
41
|
import { getBananaFPCAddress, setupBananaFPC } from './banana_fpc.js';
|
|
39
42
|
import { getSponsoredFPCAddress } from './sponsored_fpc.js';
|
|
40
43
|
|
|
41
44
|
const logger = createLogger('local-network');
|
|
42
45
|
|
|
43
|
-
|
|
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 };
|
|
44
51
|
|
|
45
52
|
/**
|
|
46
53
|
* Function to deploy our L1 contracts to the local network L1
|
|
@@ -49,57 +56,40 @@ const localAnvil = foundry;
|
|
|
49
56
|
*/
|
|
50
57
|
export async function deployContractsToL1(
|
|
51
58
|
aztecNodeConfig: AztecNodeConfig,
|
|
52
|
-
|
|
53
|
-
contractDeployLogger = logger,
|
|
59
|
+
privateKey: Hex,
|
|
54
60
|
opts: {
|
|
55
|
-
assumeProvenThroughBlockNumber?: number;
|
|
56
|
-
salt?: number;
|
|
57
61
|
genesisArchiveRoot?: Fr;
|
|
58
62
|
feeJuicePortalInitialBalance?: bigint;
|
|
59
63
|
} = {},
|
|
60
|
-
) {
|
|
61
|
-
const chain =
|
|
62
|
-
aztecNodeConfig.l1RpcUrls.length > 0
|
|
63
|
-
? createEthereumChain(aztecNodeConfig.l1RpcUrls, aztecNodeConfig.l1ChainId)
|
|
64
|
-
: { chainInfo: localAnvil };
|
|
65
|
-
|
|
64
|
+
): Promise<L1ContractAddresses> {
|
|
66
65
|
await waitForPublicClient(aztecNodeConfig);
|
|
67
66
|
|
|
68
|
-
const l1Contracts = await
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
aztecTargetCommitteeSize: 0, // no committee in local network
|
|
82
|
-
slasherFlavor: 'none', // no slashing in local network
|
|
83
|
-
realVerifier: false,
|
|
84
|
-
},
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
await deployMulticall3(l1Contracts.l1Client, logger);
|
|
88
|
-
|
|
89
|
-
aztecNodeConfig.l1Contracts = l1Contracts.l1ContractAddresses;
|
|
67
|
+
const l1Contracts = await deployAztecL1Contracts(aztecNodeConfig.l1RpcUrls[0], privateKey, foundry.id, {
|
|
68
|
+
...getL1ContractsConfigEnvVars(), // TODO: We should not need to be loading config from env again, caller should handle this
|
|
69
|
+
...aztecNodeConfig,
|
|
70
|
+
vkTreeRoot: getVKTreeRoot(),
|
|
71
|
+
protocolContractsHash,
|
|
72
|
+
genesisArchiveRoot: opts.genesisArchiveRoot ?? new Fr(GENESIS_ARCHIVE_ROOT),
|
|
73
|
+
feeJuicePortalInitialBalance: opts.feeJuicePortalInitialBalance,
|
|
74
|
+
aztecTargetCommitteeSize: 0, // no committee in local network
|
|
75
|
+
slasherEnabled: false, // no slashing in local network
|
|
76
|
+
realVerifier: false,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
Object.assign(aztecNodeConfig, l1Contracts.l1ContractAddresses);
|
|
90
80
|
aztecNodeConfig.rollupVersion = l1Contracts.rollupVersion;
|
|
91
81
|
|
|
92
|
-
return
|
|
82
|
+
return l1Contracts.l1ContractAddresses;
|
|
93
83
|
}
|
|
94
84
|
|
|
95
85
|
/** Local network settings. */
|
|
96
86
|
export type LocalNetworkConfig = AztecNodeConfig & {
|
|
97
87
|
/** Mnemonic used to derive the L1 deployer private key.*/
|
|
98
88
|
l1Mnemonic: string;
|
|
99
|
-
/** Salt used to deploy L1 contracts.*/
|
|
100
|
-
deployAztecContractsSalt: string;
|
|
101
89
|
/** Whether to deploy test accounts on local network start.*/
|
|
102
90
|
testAccounts: boolean;
|
|
91
|
+
/** Override the default per-address fee juice granted at genesis to funded addresses. */
|
|
92
|
+
initialAccountFeeJuice?: Fr;
|
|
103
93
|
};
|
|
104
94
|
|
|
105
95
|
/**
|
|
@@ -116,15 +106,49 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
|
|
|
116
106
|
if ((config.l1RpcUrls?.length || 0) > 1) {
|
|
117
107
|
logger.warn(`Multiple L1 RPC URLs provided. Local networks will only use the first one: ${l1RpcUrl}`);
|
|
118
108
|
}
|
|
119
|
-
|
|
109
|
+
|
|
110
|
+
// The local network deploys a banana FPC with Token contracts, so include Token entries
|
|
111
|
+
// in the setup allowlist so FPC-based fee payments work out of the box.
|
|
112
|
+
const tokenAllowList = await getTokenAllowedSetupFunctions();
|
|
113
|
+
|
|
114
|
+
const envConfig = getConfigEnvVars();
|
|
115
|
+
const aztecNodeConfig: AztecNodeConfig = {
|
|
116
|
+
...envConfig,
|
|
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,
|
|
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,
|
|
141
|
+
};
|
|
120
142
|
const hdAccount = mnemonicToAccount(config.l1Mnemonic || DefaultMnemonic);
|
|
121
143
|
if (
|
|
122
|
-
aztecNodeConfig.
|
|
123
|
-
!aztecNodeConfig.
|
|
124
|
-
aztecNodeConfig.
|
|
144
|
+
aztecNodeConfig.sequencerPublisherPrivateKeys == undefined ||
|
|
145
|
+
!aztecNodeConfig.sequencerPublisherPrivateKeys.length ||
|
|
146
|
+
aztecNodeConfig.sequencerPublisherPrivateKeys[0].getValue() === NULL_KEY
|
|
125
147
|
) {
|
|
126
148
|
const privKey = hdAccount.getHdKey().privateKey;
|
|
127
|
-
aztecNodeConfig.
|
|
149
|
+
aztecNodeConfig.sequencerPublisherPrivateKeys = [
|
|
150
|
+
new SecretValue(`0x${Buffer.from(privKey!).toString('hex')}` as const),
|
|
151
|
+
];
|
|
128
152
|
}
|
|
129
153
|
if (!aztecNodeConfig.validatorPrivateKeys?.getValue().length) {
|
|
130
154
|
const privKey = hdAccount.getHdKey().privateKey;
|
|
@@ -137,7 +161,7 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
|
|
|
137
161
|
const initialAccounts = await (async () => {
|
|
138
162
|
if (config.testAccounts === true || config.testAccounts === undefined) {
|
|
139
163
|
if (aztecNodeConfig.p2pEnabled) {
|
|
140
|
-
userLog(`Not setting up test accounts
|
|
164
|
+
userLog(`Not setting up test accounts when p2p is enabled`);
|
|
141
165
|
} else {
|
|
142
166
|
userLog(`Setting up test accounts`);
|
|
143
167
|
return await getInitialTestAccountsData();
|
|
@@ -148,64 +172,46 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
|
|
|
148
172
|
|
|
149
173
|
const bananaFPC = await getBananaFPCAddress(initialAccounts);
|
|
150
174
|
const sponsoredFPC = await getSponsoredFPCAddress();
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
175
|
+
const prefundAddresses = (aztecNodeConfig.prefundAddresses ?? []).map(a => AztecAddress.fromStringUnsafe(a));
|
|
176
|
+
const fundedAddresses = [
|
|
177
|
+
...initialAccounts.map(a => a.address),
|
|
178
|
+
...(initialAccounts.length ? [bananaFPC, sponsoredFPC] : []),
|
|
179
|
+
...prefundAddresses,
|
|
180
|
+
];
|
|
181
|
+
const { genesisArchiveRoot, genesis, fundingNeeded } = await getGenesisValues(
|
|
182
|
+
fundedAddresses,
|
|
183
|
+
config.initialAccountFeeJuice,
|
|
184
|
+
);
|
|
155
185
|
|
|
156
|
-
let watcher: AnvilTestWatcher | undefined = undefined;
|
|
157
186
|
const dateProvider = new TestDateProvider();
|
|
187
|
+
|
|
158
188
|
if (!aztecNodeConfig.p2pEnabled) {
|
|
159
|
-
|
|
160
|
-
assumeProvenThroughBlockNumber: Number.MAX_SAFE_INTEGER,
|
|
189
|
+
await deployContractsToL1(aztecNodeConfig, aztecNodeConfig.validatorPrivateKeys.getValue()[0], {
|
|
161
190
|
genesisArchiveRoot,
|
|
162
|
-
salt: config.deployAztecContractsSalt ? parseInt(config.deployAztecContractsSalt) : undefined,
|
|
163
191
|
feeJuicePortalInitialBalance: fundingNeeded,
|
|
164
192
|
});
|
|
165
|
-
|
|
166
|
-
const chain =
|
|
167
|
-
aztecNodeConfig.l1RpcUrls.length > 0
|
|
168
|
-
? createEthereumChain([l1RpcUrl], aztecNodeConfig.l1ChainId)
|
|
169
|
-
: { chainInfo: localAnvil };
|
|
170
|
-
|
|
171
|
-
const publicClient = createPublicClient({
|
|
172
|
-
chain: chain.chainInfo,
|
|
173
|
-
transport: fallback([httpViemTransport(l1RpcUrl)]) as any,
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
watcher = new AnvilTestWatcher(
|
|
177
|
-
new EthCheatCodes([l1RpcUrl], dateProvider),
|
|
178
|
-
l1ContractAddresses.rollupAddress,
|
|
179
|
-
publicClient,
|
|
180
|
-
dateProvider,
|
|
181
|
-
);
|
|
182
|
-
watcher.setisLocalNetwork(true);
|
|
183
|
-
await watcher.start();
|
|
184
193
|
}
|
|
185
194
|
|
|
186
|
-
const telemetry = initTelemetryClient(getTelemetryClientConfig());
|
|
187
|
-
// Create a local blob
|
|
188
|
-
const
|
|
189
|
-
const node = await createAztecNode(
|
|
190
|
-
aztecNodeConfig,
|
|
191
|
-
{ telemetry, blobSinkClient, dateProvider },
|
|
192
|
-
{ prefilledPublicData },
|
|
193
|
-
);
|
|
195
|
+
const telemetry = await initTelemetryClient(getTelemetryClientConfig());
|
|
196
|
+
// Create a local blob client client inside the local network, no http connectivity
|
|
197
|
+
const blobClient = createBlobClient();
|
|
198
|
+
const node = await createAztecNode(aztecNodeConfig, { telemetry, blobClient, dateProvider }, { genesis });
|
|
194
199
|
|
|
195
200
|
if (initialAccounts.length) {
|
|
196
|
-
const
|
|
197
|
-
|
|
201
|
+
const wallet = await EmbeddedWallet.create(node, {
|
|
202
|
+
pxeConfig: { proverEnabled: aztecNodeConfig.realProofs },
|
|
203
|
+
ephemeral: true,
|
|
204
|
+
});
|
|
198
205
|
|
|
199
206
|
userLog('Setting up funded test accounts...');
|
|
200
|
-
const accountManagers = await
|
|
201
|
-
const
|
|
202
|
-
account: manager,
|
|
203
|
-
secretKey: initialAccounts[i].secret,
|
|
204
|
-
}));
|
|
205
|
-
const accLogs = await createAccountLogs(accountsWithSecrets, wallet);
|
|
207
|
+
const accountManagers = await createFundedInitializerlessAccounts(wallet, initialAccounts);
|
|
208
|
+
const accLogs = await createAccountLogs(accountManagers, wallet);
|
|
206
209
|
userLog(accLogs.join(''));
|
|
207
210
|
|
|
208
|
-
|
|
211
|
+
userLog('Publishing standard AuthRegistry contract...');
|
|
212
|
+
await publishStandardAuthRegistry(wallet, initialAccounts[0].address, setupWaitOpts);
|
|
213
|
+
|
|
214
|
+
await setupBananaFPC(initialAccounts, wallet, userLog, setupWaitOpts);
|
|
209
215
|
|
|
210
216
|
userLog(`SponsoredFPC: ${await getSponsoredFPCAddress()}`);
|
|
211
217
|
|
|
@@ -215,7 +221,6 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
|
|
|
215
221
|
|
|
216
222
|
const stop = async () => {
|
|
217
223
|
await node.stop();
|
|
218
|
-
await watcher?.stop();
|
|
219
224
|
};
|
|
220
225
|
|
|
221
226
|
return { node, stop };
|
|
@@ -227,16 +232,24 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
|
|
|
227
232
|
*/
|
|
228
233
|
export async function createAztecNode(
|
|
229
234
|
config: Partial<AztecNodeConfig> = {},
|
|
230
|
-
deps: {
|
|
231
|
-
|
|
235
|
+
deps: {
|
|
236
|
+
telemetry?: TelemetryClient;
|
|
237
|
+
blobClient?: BlobClientInterface;
|
|
238
|
+
dateProvider?: DateProvider;
|
|
239
|
+
proverBroker?: ProvingJobBroker;
|
|
240
|
+
} = {},
|
|
241
|
+
options: { genesis?: GenesisData } = {},
|
|
232
242
|
) {
|
|
233
243
|
// TODO(#12272): will clean this up. This is criminal.
|
|
234
|
-
|
|
244
|
+
// Not sure why this was ever done. Will be fixed in A-989, A-991, A-990.
|
|
235
245
|
const aztecNodeConfig: AztecNodeConfig = {
|
|
236
|
-
...
|
|
246
|
+
...getConfigEnvVars(),
|
|
237
247
|
...config,
|
|
238
|
-
l1Contracts: { ...l1Contracts, ...config.l1Contracts },
|
|
239
248
|
};
|
|
240
|
-
const node = await
|
|
249
|
+
const node = await createAztecNodeService(
|
|
250
|
+
aztecNodeConfig,
|
|
251
|
+
{ ...deps, proverNodeDeps: { broker: deps.proverBroker } },
|
|
252
|
+
options,
|
|
253
|
+
);
|
|
241
254
|
return node;
|
|
242
255
|
}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
|
|
2
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
4
2
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
-
import type {
|
|
6
|
-
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
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
10
|
constructor(
|
|
@@ -29,51 +24,25 @@ export class CheatCodes {
|
|
|
29
24
|
}
|
|
30
25
|
|
|
31
26
|
/**
|
|
32
|
-
* Warps the L1 timestamp to
|
|
33
|
-
* the target
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* @
|
|
37
|
-
* @param node - The Aztec node used to query if a new block has been mined.
|
|
38
|
-
* @param targetTimestamp - The target timestamp to warp to (in seconds)
|
|
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.
|
|
39
32
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// We warp the L1 timestamp
|
|
44
|
-
await this.eth.warp(targetTimestamp, { resetBlockInterval: true });
|
|
45
|
-
|
|
46
|
-
// Wait until an L2 block is mined
|
|
47
|
-
const sequencer = sequencerClient.getSequencer();
|
|
48
|
-
const minTxsPerBlock = sequencer.getConfig().minTxsPerBlock;
|
|
49
|
-
sequencer.updateConfig({ minTxsPerBlock: 0 });
|
|
50
|
-
|
|
51
|
-
await retryUntil(
|
|
52
|
-
async () => {
|
|
53
|
-
const newL2BlockNumber: BlockNumber = await node.getBlockNumber();
|
|
54
|
-
return newL2BlockNumber > currentL2BlockNumber;
|
|
55
|
-
},
|
|
56
|
-
'new block after warping L2 time',
|
|
57
|
-
36,
|
|
58
|
-
1,
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
// Restore original minTxsPerBlock
|
|
62
|
-
sequencer.updateConfig({ minTxsPerBlock });
|
|
33
|
+
warpL2TimeAtLeastTo(node: AztecNode & AztecNodeDebug, targetTimestamp: bigint | number): Promise<void> {
|
|
34
|
+
return node.warpL2TimeAtLeastTo(Number(targetTimestamp));
|
|
63
35
|
}
|
|
64
36
|
|
|
65
37
|
/**
|
|
66
|
-
* Warps the L1 timestamp forward by
|
|
67
|
-
* least by the duration.
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* @param
|
|
71
|
-
* @
|
|
72
|
-
* @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.
|
|
73
44
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const targetTimestamp = BigInt(currentTimestamp) + BigInt(duration);
|
|
77
|
-
await this.warpL2TimeAtLeastTo(sequencerClient, node, targetTimestamp);
|
|
45
|
+
warpL2TimeAtLeastBy(node: AztecNode & AztecNodeDebug, duration: bigint | number): Promise<void> {
|
|
46
|
+
return node.warpL2TimeAtLeastBy(Number(duration));
|
|
78
47
|
}
|
|
79
48
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
|
|
2
|
+
import type { EpochNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
4
|
+
import { settleEpochOutbox } from '@aztec/prover-client/test';
|
|
5
|
+
import { EpochMonitor } from '@aztec/prover-node';
|
|
6
|
+
import type { EthAddress, L2BlockSource } from '@aztec/stdlib/block';
|
|
7
|
+
|
|
8
|
+
export class EpochTestSettler {
|
|
9
|
+
private rollupCheatCodes: RollupCheatCodes;
|
|
10
|
+
private epochMonitor?: EpochMonitor;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
cheatcodes: EthCheatCodes,
|
|
14
|
+
rollupAddress: EthAddress,
|
|
15
|
+
private l2BlockSource: L2BlockSource,
|
|
16
|
+
private log: Logger,
|
|
17
|
+
private options: { pollingIntervalMs: number; provingDelayMs?: number },
|
|
18
|
+
) {
|
|
19
|
+
this.rollupCheatCodes = new RollupCheatCodes(cheatcodes, { rollupAddress });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async start() {
|
|
23
|
+
const { epochDuration } = await this.rollupCheatCodes.getConfig();
|
|
24
|
+
this.epochMonitor = new EpochMonitor(this.l2BlockSource, { epochDuration: Number(epochDuration) }, this.options);
|
|
25
|
+
this.epochMonitor.start(this);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async stop() {
|
|
29
|
+
await this.epochMonitor?.stop();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async handleEpochReadyToProve(epoch: EpochNumber): Promise<boolean> {
|
|
33
|
+
const lastCheckpoint = await settleEpochOutbox({
|
|
34
|
+
rollupCheatCodes: this.rollupCheatCodes,
|
|
35
|
+
l2BlockSource: this.l2BlockSource,
|
|
36
|
+
epoch,
|
|
37
|
+
log: this.log,
|
|
38
|
+
});
|
|
39
|
+
if (lastCheckpoint !== undefined) {
|
|
40
|
+
await this.rollupCheatCodes.markAsProven(lastCheckpoint);
|
|
41
|
+
} else {
|
|
42
|
+
this.log.warn(`No checkpoint found for epoch ${epoch}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/testing/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export { AnvilTestWatcher } from './anvil_test_watcher.js';
|
|
2
1
|
export { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
|
|
3
2
|
export { CheatCodes } from './cheat_codes.js';
|
|
3
|
+
export { EpochTestSettler } from './epoch_test_settler.js';
|
|
4
|
+
export { setupLocalNetwork, TEST_FEE_PADDING, type LocalNetwork, type LocalNetworkOptions } from './local-network.js';
|
|
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;
|