@aztec/end-to-end 0.0.0-test.0 → 0.0.1-commit.023c3e5
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/benchmark.d.ts +62 -0
- package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/benchmark.js +281 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts +79 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/client_flows_benchmark.js +321 -0
- package/dest/bench/client_flows/config.d.ts +14 -0
- package/dest/bench/client_flows/config.d.ts.map +1 -0
- package/dest/bench/client_flows/config.js +106 -0
- package/dest/bench/client_flows/data_extractor.d.ts +2 -0
- package/dest/bench/client_flows/data_extractor.d.ts.map +1 -0
- package/dest/bench/client_flows/data_extractor.js +79 -0
- package/dest/bench/utils.d.ts +16 -41
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/bench/utils.js +41 -72
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +26 -19
- 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 +114 -102
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +32 -32
- 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 +104 -104
- package/dest/e2e_deploy_contract/deploy_test.d.ts +19 -10
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
- package/dest/e2e_deploy_contract/deploy_test.js +26 -27
- package/dest/e2e_epochs/epochs_test.d.ts +71 -22
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +260 -54
- package/dest/e2e_fees/bridging_race.notest.d.ts +2 -0
- package/dest/e2e_fees/bridging_race.notest.d.ts.map +1 -0
- package/dest/e2e_fees/bridging_race.notest.js +61 -0
- package/dest/e2e_fees/fees_test.d.ts +38 -23
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +162 -183
- package/dest/e2e_l1_publisher/write_json.d.ts +11 -0
- package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
- package/dest/e2e_l1_publisher/write_json.js +56 -0
- package/dest/e2e_multi_validator/utils.d.ts +12 -0
- package/dest/e2e_multi_validator/utils.d.ts.map +1 -0
- package/dest/e2e_multi_validator/utils.js +214 -0
- package/dest/e2e_nested_contract/nested_contract_test.d.ts +15 -15
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +37 -41
- package/dest/e2e_p2p/inactivity_slash_test.d.ts +31 -0
- package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -0
- package/dest/e2e_p2p/inactivity_slash_test.js +136 -0
- package/dest/e2e_p2p/p2p_network.d.ts +281 -27
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +237 -175
- package/dest/e2e_p2p/reqresp/utils.d.ts +22 -0
- package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -0
- package/dest/e2e_p2p/reqresp/utils.js +153 -0
- package/dest/e2e_p2p/shared.d.ts +44 -8
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +165 -27
- package/dest/e2e_token_contract/token_contract_test.d.ts +27 -14
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +96 -74
- package/dest/fixtures/e2e_prover_test.d.ts +55 -0
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
- package/dest/fixtures/e2e_prover_test.js +278 -0
- package/dest/fixtures/fixtures.d.ts +6 -8
- package/dest/fixtures/fixtures.d.ts.map +1 -1
- package/dest/fixtures/fixtures.js +5 -5
- package/dest/fixtures/get_acvm_config.d.ts +2 -2
- package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
- package/dest/fixtures/get_acvm_config.js +3 -15
- package/dest/fixtures/get_bb_config.d.ts +2 -2
- package/dest/fixtures/get_bb_config.d.ts.map +1 -1
- package/dest/fixtures/get_bb_config.js +10 -17
- package/dest/fixtures/index.d.ts +1 -1
- package/dest/fixtures/l1_to_l2_messaging.d.ts +11 -7
- package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
- package/dest/fixtures/l1_to_l2_messaging.js +45 -19
- package/dest/fixtures/logging.d.ts +1 -1
- package/dest/fixtures/setup.d.ts +218 -0
- package/dest/fixtures/setup.d.ts.map +1 -0
- package/dest/fixtures/setup.js +695 -0
- package/dest/fixtures/setup_p2p_test.d.ts +15 -15
- package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
- package/dest/fixtures/setup_p2p_test.js +96 -31
- package/dest/fixtures/token_utils.d.ts +10 -4
- package/dest/fixtures/token_utils.d.ts.map +1 -1
- package/dest/fixtures/token_utils.js +31 -12
- package/dest/fixtures/utils.d.ts +5 -153
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +4 -552
- package/dest/fixtures/web3signer.d.ts +5 -0
- package/dest/fixtures/web3signer.d.ts.map +1 -0
- package/dest/fixtures/web3signer.js +53 -0
- package/dest/fixtures/with_telemetry_utils.d.ts +2 -2
- package/dest/fixtures/with_telemetry_utils.d.ts.map +1 -1
- package/dest/fixtures/with_telemetry_utils.js +2 -2
- package/dest/index.d.ts +1 -1
- package/dest/quality_of_service/grafana_client.d.ts +41 -0
- package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
- package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
- 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 +44 -27
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +105 -51
- package/dest/shared/gas_portal_test_harness.d.ts +33 -25
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.js +51 -30
- package/dest/shared/index.d.ts +2 -2
- package/dest/shared/index.d.ts.map +1 -1
- package/dest/shared/jest_setup.d.ts +1 -1
- package/dest/shared/jest_setup.js +1 -1
- package/dest/shared/submit-transactions.d.ts +6 -4
- package/dest/shared/submit-transactions.d.ts.map +1 -1
- package/dest/shared/submit-transactions.js +15 -16
- package/dest/shared/uniswap_l1_l2.d.ts +3 -25
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.js +176 -126
- package/dest/simulators/index.d.ts +1 -1
- package/dest/simulators/lending_simulator.d.ts +7 -7
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +17 -18
- package/dest/simulators/token_simulator.d.ts +6 -3
- package/dest/simulators/token_simulator.d.ts.map +1 -1
- package/dest/simulators/token_simulator.js +16 -13
- package/dest/spartan/setup_test_wallets.d.ts +27 -11
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +233 -62
- package/dest/spartan/tx_metrics.d.ts +88 -0
- package/dest/spartan/tx_metrics.d.ts.map +1 -0
- package/dest/spartan/tx_metrics.js +422 -0
- package/dest/spartan/utils/bot.d.ts +27 -0
- package/dest/spartan/utils/bot.d.ts.map +1 -0
- package/dest/spartan/utils/bot.js +141 -0
- package/dest/spartan/utils/chaos.d.ts +79 -0
- package/dest/spartan/utils/chaos.d.ts.map +1 -0
- package/dest/spartan/utils/chaos.js +142 -0
- package/dest/spartan/utils/clients.d.ts +39 -0
- package/dest/spartan/utils/clients.d.ts.map +1 -0
- package/dest/spartan/utils/clients.js +90 -0
- package/dest/spartan/utils/config.d.ts +36 -0
- package/dest/spartan/utils/config.d.ts.map +1 -0
- package/dest/spartan/utils/config.js +20 -0
- package/dest/spartan/utils/health.d.ts +63 -0
- package/dest/spartan/utils/health.d.ts.map +1 -0
- package/dest/spartan/utils/health.js +202 -0
- package/dest/spartan/utils/helm.d.ts +15 -0
- package/dest/spartan/utils/helm.d.ts.map +1 -0
- package/dest/spartan/utils/helm.js +47 -0
- package/dest/spartan/utils/index.d.ts +9 -0
- package/dest/spartan/utils/index.d.ts.map +1 -0
- package/dest/spartan/utils/index.js +18 -0
- package/dest/spartan/utils/k8s.d.ts +126 -0
- package/dest/spartan/utils/k8s.d.ts.map +1 -0
- package/dest/spartan/utils/k8s.js +375 -0
- package/dest/spartan/utils/nodes.d.ts +41 -0
- package/dest/spartan/utils/nodes.d.ts.map +1 -0
- package/dest/spartan/utils/nodes.js +461 -0
- package/dest/spartan/utils/scripts.d.ts +16 -0
- package/dest/spartan/utils/scripts.d.ts.map +1 -0
- package/dest/spartan/utils/scripts.js +66 -0
- package/dest/spartan/utils.d.ts +2 -415
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +1 -445
- package/package.json +66 -58
- package/src/bench/client_flows/benchmark.ts +363 -0
- package/src/bench/client_flows/client_flows_benchmark.ts +384 -0
- package/src/bench/client_flows/config.ts +61 -0
- package/src/bench/client_flows/data_extractor.ts +89 -0
- package/src/bench/utils.ts +41 -85
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +134 -169
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +156 -182
- package/src/e2e_deploy_contract/deploy_test.ts +40 -48
- package/src/e2e_epochs/epochs_test.ts +341 -81
- package/src/e2e_fees/bridging_race.notest.ts +74 -0
- package/src/e2e_fees/fees_test.ts +220 -258
- package/src/e2e_l1_publisher/write_json.ts +77 -0
- package/src/e2e_multi_validator/utils.ts +258 -0
- package/src/e2e_nested_contract/nested_contract_test.ts +46 -59
- package/src/e2e_p2p/inactivity_slash_test.ts +179 -0
- package/src/e2e_p2p/p2p_network.ts +341 -234
- package/src/e2e_p2p/reqresp/utils.ts +207 -0
- package/src/e2e_p2p/shared.ts +260 -39
- package/src/e2e_token_contract/token_contract_test.ts +115 -126
- package/src/fixtures/dumps/epoch_proof_result.json +1 -1
- package/src/fixtures/e2e_prover_test.ts +336 -0
- package/src/fixtures/fixtures.ts +5 -7
- package/src/fixtures/get_acvm_config.ts +4 -12
- package/src/fixtures/get_bb_config.ts +18 -13
- package/src/fixtures/l1_to_l2_messaging.ts +56 -24
- package/src/fixtures/setup.ts +1017 -0
- package/src/fixtures/setup_p2p_test.ts +133 -50
- package/src/fixtures/token_utils.ts +33 -15
- package/src/fixtures/utils.ts +27 -820
- package/src/fixtures/web3signer.ts +63 -0
- package/src/fixtures/with_telemetry_utils.ts +2 -2
- package/src/guides/up_quick_start.sh +7 -15
- package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +2 -2
- package/src/quality_of_service/prometheus_client.ts +113 -0
- package/src/shared/cross_chain_test_harness.ts +103 -91
- package/src/shared/gas_portal_test_harness.ts +59 -50
- package/src/shared/index.ts +1 -1
- package/src/shared/jest_setup.ts +1 -1
- package/src/shared/submit-transactions.ts +18 -20
- package/src/shared/uniswap_l1_l2.ts +197 -221
- package/src/simulators/lending_simulator.ts +16 -17
- package/src/simulators/token_simulator.ts +21 -13
- package/src/spartan/DEVELOP.md +128 -0
- package/src/spartan/setup_test_wallets.ts +308 -95
- package/src/spartan/tx_metrics.ts +376 -0
- package/src/spartan/utils/bot.ts +185 -0
- package/src/spartan/utils/chaos.ts +253 -0
- package/src/spartan/utils/clients.ts +100 -0
- package/src/spartan/utils/config.ts +26 -0
- package/src/spartan/utils/health.ts +255 -0
- package/src/spartan/utils/helm.ts +84 -0
- package/src/spartan/utils/index.ts +64 -0
- package/src/spartan/utils/k8s.ts +527 -0
- package/src/spartan/utils/nodes.ts +538 -0
- package/src/spartan/utils/scripts.ts +63 -0
- package/src/spartan/utils.ts +1 -582
- package/dest/e2e_prover/e2e_prover_test.d.ts +0 -56
- package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
- package/dest/e2e_prover/e2e_prover_test.js +0 -291
- package/dest/fixtures/setup_l1_contracts.d.ts +0 -6
- package/dest/fixtures/setup_l1_contracts.d.ts.map +0 -1
- package/dest/fixtures/setup_l1_contracts.js +0 -17
- package/dest/fixtures/snapshot_manager.d.ts +0 -87
- package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
- package/dest/fixtures/snapshot_manager.js +0 -479
- package/dest/quality_of_service/alert_checker.d.ts +0 -41
- package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
- package/dest/sample-dapp/connect.js +0 -12
- package/dest/sample-dapp/contracts.js +0 -10
- package/dest/sample-dapp/deploy.js +0 -35
- package/dest/sample-dapp/index.js +0 -98
- package/src/e2e_prover/e2e_prover_test.ts +0 -418
- package/src/fixtures/setup_l1_contracts.ts +0 -27
- package/src/fixtures/snapshot_manager.ts +0 -617
- package/src/sample-dapp/connect.mjs +0 -16
- package/src/sample-dapp/contracts.mjs +0 -14
- package/src/sample-dapp/deploy.mjs +0 -40
- package/src/sample-dapp/index.mjs +0 -128
|
@@ -1,617 +0,0 @@
|
|
|
1
|
-
import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';
|
|
2
|
-
import { type InitialAccountData, deployFundedSchnorrAccounts, generateSchnorrAccounts } from '@aztec/accounts/testing';
|
|
3
|
-
import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node';
|
|
4
|
-
import {
|
|
5
|
-
AnvilTestWatcher,
|
|
6
|
-
type AztecAddress,
|
|
7
|
-
BatchCall,
|
|
8
|
-
type Capsule,
|
|
9
|
-
CheatCodes,
|
|
10
|
-
type CompleteAddress,
|
|
11
|
-
type ContractFunctionInteraction,
|
|
12
|
-
type DeployL1ContractsReturnType,
|
|
13
|
-
type FunctionCall,
|
|
14
|
-
type Logger,
|
|
15
|
-
type PXE,
|
|
16
|
-
type Wallet,
|
|
17
|
-
getContractClassFromArtifact,
|
|
18
|
-
} from '@aztec/aztec.js';
|
|
19
|
-
import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment';
|
|
20
|
-
import { type BlobSinkServer, createBlobSinkServer } from '@aztec/blob-sink/server';
|
|
21
|
-
import { type DeployL1ContractsArgs, createL1Clients, getL1ContractsConfigEnvVars, l1Artifacts } from '@aztec/ethereum';
|
|
22
|
-
import { EthCheatCodesWithState, startAnvil } from '@aztec/ethereum/test';
|
|
23
|
-
import { asyncMap } from '@aztec/foundation/async-map';
|
|
24
|
-
import { randomBytes } from '@aztec/foundation/crypto';
|
|
25
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
26
|
-
import { resolver, reviver } from '@aztec/foundation/serialize';
|
|
27
|
-
import { TestDateProvider } from '@aztec/foundation/timer';
|
|
28
|
-
import type { ProverNode } from '@aztec/prover-node';
|
|
29
|
-
import { type PXEService, createPXEService, getPXEServiceConfig } from '@aztec/pxe/server';
|
|
30
|
-
import { getConfigEnvVars as getTelemetryConfig, initTelemetryClient } from '@aztec/telemetry-client';
|
|
31
|
-
import { getGenesisValues } from '@aztec/world-state/testing';
|
|
32
|
-
|
|
33
|
-
import type { Anvil } from '@viem/anvil';
|
|
34
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
35
|
-
import { copySync, removeSync } from 'fs-extra/esm';
|
|
36
|
-
import fs from 'fs/promises';
|
|
37
|
-
import getPort from 'get-port';
|
|
38
|
-
import { tmpdir } from 'os';
|
|
39
|
-
import path, { join } from 'path';
|
|
40
|
-
import { type Hex, getContract } from 'viem';
|
|
41
|
-
import { mnemonicToAccount } from 'viem/accounts';
|
|
42
|
-
|
|
43
|
-
import { MNEMONIC, TEST_PEER_CHECK_INTERVAL_MS } from './fixtures.js';
|
|
44
|
-
import { getACVMConfig } from './get_acvm_config.js';
|
|
45
|
-
import { getBBConfig } from './get_bb_config.js';
|
|
46
|
-
import { setupL1Contracts } from './setup_l1_contracts.js';
|
|
47
|
-
import { type SetupOptions, createAndSyncProverNode, getLogger, getPrivateKeyFromIndex } from './utils.js';
|
|
48
|
-
import { getEndToEndTestTelemetryClient } from './with_telemetry_utils.js';
|
|
49
|
-
|
|
50
|
-
export type SubsystemsContext = {
|
|
51
|
-
anvil: Anvil;
|
|
52
|
-
acvmConfig: any;
|
|
53
|
-
bbConfig: any;
|
|
54
|
-
aztecNode: AztecNodeService;
|
|
55
|
-
aztecNodeConfig: AztecNodeConfig;
|
|
56
|
-
pxe: PXEService;
|
|
57
|
-
deployL1ContractsValues: DeployL1ContractsReturnType;
|
|
58
|
-
proverNode?: ProverNode;
|
|
59
|
-
watcher: AnvilTestWatcher;
|
|
60
|
-
cheatCodes: CheatCodes;
|
|
61
|
-
dateProvider: TestDateProvider;
|
|
62
|
-
blobSink: BlobSinkServer;
|
|
63
|
-
initialFundedAccounts: InitialAccountData[];
|
|
64
|
-
directoryToCleanup?: string;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
type SnapshotEntry = {
|
|
68
|
-
name: string;
|
|
69
|
-
apply: (context: SubsystemsContext) => Promise<any>;
|
|
70
|
-
restore: (snapshotData: any, context: SubsystemsContext) => Promise<any>;
|
|
71
|
-
snapshotPath: string;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export function createSnapshotManager(
|
|
75
|
-
testName: string,
|
|
76
|
-
dataPath?: string,
|
|
77
|
-
config: Partial<SetupOptions> = {},
|
|
78
|
-
deployL1ContractsArgs: Partial<DeployL1ContractsArgs> = {
|
|
79
|
-
initialValidators: [],
|
|
80
|
-
},
|
|
81
|
-
) {
|
|
82
|
-
return dataPath
|
|
83
|
-
? new SnapshotManager(testName, dataPath, config, deployL1ContractsArgs)
|
|
84
|
-
: new MockSnapshotManager(testName, config, deployL1ContractsArgs);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export interface ISnapshotManager {
|
|
88
|
-
snapshot<T>(
|
|
89
|
-
name: string,
|
|
90
|
-
apply: (context: SubsystemsContext) => Promise<T>,
|
|
91
|
-
restore?: (snapshotData: T, context: SubsystemsContext) => Promise<void>,
|
|
92
|
-
): Promise<void>;
|
|
93
|
-
|
|
94
|
-
setup(): Promise<SubsystemsContext>;
|
|
95
|
-
|
|
96
|
-
teardown(): Promise<void>;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** Snapshot manager that does not perform snapshotting, it just applies transition and restoration functions as it receives them. */
|
|
100
|
-
class MockSnapshotManager implements ISnapshotManager {
|
|
101
|
-
private context?: SubsystemsContext;
|
|
102
|
-
private logger: Logger;
|
|
103
|
-
|
|
104
|
-
constructor(
|
|
105
|
-
testName: string,
|
|
106
|
-
private config: Partial<AztecNodeConfig> = {},
|
|
107
|
-
private deployL1ContractsArgs: Partial<DeployL1ContractsArgs> = {},
|
|
108
|
-
) {
|
|
109
|
-
this.logger = createLogger(`e2e:snapshot_manager:${testName}`);
|
|
110
|
-
this.logger.warn(`No data path given, will not persist any snapshots.`);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
public async snapshot<T>(
|
|
114
|
-
name: string,
|
|
115
|
-
apply: (context: SubsystemsContext) => Promise<T>,
|
|
116
|
-
restore: (snapshotData: T, context: SubsystemsContext) => Promise<void> = () => Promise.resolve(),
|
|
117
|
-
) {
|
|
118
|
-
// We are running in disabled mode. Just apply the state.
|
|
119
|
-
const context = await this.setup();
|
|
120
|
-
this.logger.verbose(`Applying state transition for ${name}...`);
|
|
121
|
-
const snapshotData = await apply(context);
|
|
122
|
-
this.logger.verbose(`State transition for ${name} complete.`);
|
|
123
|
-
// Execute the restoration function.
|
|
124
|
-
await restore(snapshotData, context);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
public async setup() {
|
|
129
|
-
if (!this.context) {
|
|
130
|
-
this.context = await setupFromFresh(undefined, this.logger, this.config, this.deployL1ContractsArgs);
|
|
131
|
-
}
|
|
132
|
-
return this.context;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
public async teardown() {
|
|
136
|
-
await teardown(this.context);
|
|
137
|
-
this.context = undefined;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Snapshot engine for local e2e tests. Read more:
|
|
143
|
-
* https://github.com/AztecProtocol/aztec-packages/pull/5526
|
|
144
|
-
*/
|
|
145
|
-
class SnapshotManager implements ISnapshotManager {
|
|
146
|
-
private snapshotStack: SnapshotEntry[] = [];
|
|
147
|
-
private context?: SubsystemsContext;
|
|
148
|
-
private livePath: string;
|
|
149
|
-
private logger: Logger;
|
|
150
|
-
|
|
151
|
-
constructor(
|
|
152
|
-
testName: string,
|
|
153
|
-
private dataPath: string,
|
|
154
|
-
private config: Partial<SetupOptions> = {},
|
|
155
|
-
private deployL1ContractsArgs: Partial<DeployL1ContractsArgs> = {},
|
|
156
|
-
) {
|
|
157
|
-
this.livePath = join(this.dataPath, 'live', testName);
|
|
158
|
-
this.logger = createLogger(`e2e:snapshot_manager:${testName}`);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
public async snapshot<T>(
|
|
162
|
-
name: string,
|
|
163
|
-
apply: (context: SubsystemsContext) => Promise<T>,
|
|
164
|
-
restore: (snapshotData: T, context: SubsystemsContext) => Promise<void> = () => Promise.resolve(),
|
|
165
|
-
) {
|
|
166
|
-
const snapshotPath = join(this.dataPath, 'snapshots', ...this.snapshotStack.map(e => e.name), name, 'snapshot');
|
|
167
|
-
|
|
168
|
-
if (existsSync(snapshotPath)) {
|
|
169
|
-
// Snapshot exists. Record entry on stack but do nothing else as we're probably still descending the tree.
|
|
170
|
-
// It's the tests responsibility to call setup() before a test to ensure subsystems get created.
|
|
171
|
-
this.logger.verbose(`Snapshot exists at ${snapshotPath}. Continuing...`);
|
|
172
|
-
this.snapshotStack.push({ name, apply, restore, snapshotPath });
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Snapshot didn't exist at snapshotPath, and by definition none of the child snapshots can exist.
|
|
177
|
-
// If we have no subsystem context yet, create it from the top of the snapshot stack (if it exists).
|
|
178
|
-
const context = await this.setup();
|
|
179
|
-
|
|
180
|
-
this.snapshotStack.push({ name, apply, restore, snapshotPath });
|
|
181
|
-
|
|
182
|
-
// Apply current state transition.
|
|
183
|
-
this.logger.verbose(`Applying state transition for ${name}...`);
|
|
184
|
-
const snapshotData = await apply(context);
|
|
185
|
-
this.logger.verbose(`State transition for ${name} complete.`);
|
|
186
|
-
|
|
187
|
-
// Execute the restoration function.
|
|
188
|
-
await restore(snapshotData, context);
|
|
189
|
-
|
|
190
|
-
// Save the snapshot data.
|
|
191
|
-
const ethCheatCodes = new EthCheatCodesWithState(context.aztecNodeConfig.l1RpcUrls);
|
|
192
|
-
const anvilStateFile = `${this.livePath}/anvil.dat`;
|
|
193
|
-
await ethCheatCodes.dumpChainState(anvilStateFile);
|
|
194
|
-
writeFileSync(`${this.livePath}/${name}.json`, JSON.stringify(snapshotData || {}, resolver));
|
|
195
|
-
|
|
196
|
-
// Copy everything to snapshot path.
|
|
197
|
-
// We want it to be atomic, in case multiple processes are racing to create the snapshot.
|
|
198
|
-
this.logger.verbose(`Saving snapshot to ${snapshotPath}...`);
|
|
199
|
-
if (mkdirSync(snapshotPath, { recursive: true })) {
|
|
200
|
-
copySync(this.livePath, snapshotPath);
|
|
201
|
-
this.logger.verbose(`Snapshot copied to ${snapshotPath}.`);
|
|
202
|
-
} else {
|
|
203
|
-
this.logger.verbose(`Snapshot already exists at ${snapshotPath}. Discarding our version.`);
|
|
204
|
-
await this.teardown();
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Creates and returns the subsystem context based on the current snapshot stack.
|
|
210
|
-
* If the subsystem context already exists, just return it.
|
|
211
|
-
* If you want to be sure to get a clean snapshot, be sure to call teardown() before calling setup().
|
|
212
|
-
*/
|
|
213
|
-
public async setup() {
|
|
214
|
-
// We have no subsystem context yet.
|
|
215
|
-
// If one exists on the snapshot stack, create one from that snapshot.
|
|
216
|
-
// Otherwise create a fresh one.
|
|
217
|
-
if (!this.context) {
|
|
218
|
-
removeSync(this.livePath);
|
|
219
|
-
mkdirSync(this.livePath, { recursive: true });
|
|
220
|
-
const previousSnapshotPath = this.snapshotStack[this.snapshotStack.length - 1]?.snapshotPath;
|
|
221
|
-
if (previousSnapshotPath) {
|
|
222
|
-
this.logger.verbose(`Copying snapshot from ${previousSnapshotPath} to ${this.livePath}...`);
|
|
223
|
-
copySync(previousSnapshotPath, this.livePath);
|
|
224
|
-
this.context = await setupFromState(this.livePath, this.logger);
|
|
225
|
-
// Execute each of the previous snapshots restoration functions in turn.
|
|
226
|
-
await asyncMap(this.snapshotStack, async e => {
|
|
227
|
-
const snapshotData = JSON.parse(readFileSync(`${e.snapshotPath}/${e.name}.json`, 'utf-8'), reviver);
|
|
228
|
-
this.logger.verbose(`Executing restoration function for ${e.name}...`);
|
|
229
|
-
await e.restore(snapshotData, this.context!);
|
|
230
|
-
this.logger.verbose(`Restoration of ${e.name} complete.`);
|
|
231
|
-
});
|
|
232
|
-
} else {
|
|
233
|
-
this.context = await setupFromFresh(this.livePath, this.logger, this.config, this.deployL1ContractsArgs);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return this.context;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Destroys the current subsystem context.
|
|
241
|
-
*/
|
|
242
|
-
public async teardown() {
|
|
243
|
-
await teardown(this.context);
|
|
244
|
-
this.context = undefined;
|
|
245
|
-
removeSync(this.livePath);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Destroys the current subsystem context.
|
|
251
|
-
*/
|
|
252
|
-
async function teardown(context: SubsystemsContext | undefined) {
|
|
253
|
-
if (!context) {
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
try {
|
|
257
|
-
getLogger().info('Tearing down subsystems');
|
|
258
|
-
await context.proverNode?.stop();
|
|
259
|
-
await context.aztecNode.stop();
|
|
260
|
-
await context.acvmConfig?.cleanup();
|
|
261
|
-
await context.bbConfig?.cleanup();
|
|
262
|
-
await context.anvil.stop();
|
|
263
|
-
await context.watcher.stop();
|
|
264
|
-
await context.blobSink.stop();
|
|
265
|
-
if (context.directoryToCleanup) {
|
|
266
|
-
try {
|
|
267
|
-
await fs.rm(context.directoryToCleanup, { recursive: true, force: true, maxRetries: 3 });
|
|
268
|
-
} catch (err) {
|
|
269
|
-
getLogger().warn(`Failed to delete tmp directory ${context.directoryToCleanup}: ${err}`);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
} catch (err) {
|
|
273
|
-
getLogger().error('Error during teardown', err);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Initializes a fresh set of subsystems.
|
|
279
|
-
* If given a statePath, the state will be written to the path.
|
|
280
|
-
* If there is no statePath, in-memory and temporary state locations will be used.
|
|
281
|
-
*/
|
|
282
|
-
async function setupFromFresh(
|
|
283
|
-
statePath: string | undefined,
|
|
284
|
-
logger: Logger,
|
|
285
|
-
{ numberOfInitialFundedAccounts = 10, ...opts }: SetupOptions = {},
|
|
286
|
-
deployL1ContractsArgs: Partial<DeployL1ContractsArgs> = {
|
|
287
|
-
initialValidators: [],
|
|
288
|
-
},
|
|
289
|
-
): Promise<SubsystemsContext> {
|
|
290
|
-
logger.verbose(`Initializing state...`);
|
|
291
|
-
|
|
292
|
-
const blobSinkPort = await getPort();
|
|
293
|
-
|
|
294
|
-
// Fetch the AztecNode config.
|
|
295
|
-
// TODO: For some reason this is currently the union of a bunch of subsystems. That needs fixing.
|
|
296
|
-
const aztecNodeConfig: AztecNodeConfig & SetupOptions = { ...getConfigEnvVars(), ...opts };
|
|
297
|
-
aztecNodeConfig.peerCheckIntervalMS = TEST_PEER_CHECK_INTERVAL_MS;
|
|
298
|
-
|
|
299
|
-
// Create a temp directory for all ephemeral state and cleanup afterwards
|
|
300
|
-
const directoryToCleanup = path.join(tmpdir(), randomBytes(8).toString('hex'));
|
|
301
|
-
await fs.mkdir(directoryToCleanup, { recursive: true });
|
|
302
|
-
if (statePath === undefined) {
|
|
303
|
-
aztecNodeConfig.dataDirectory = directoryToCleanup;
|
|
304
|
-
} else {
|
|
305
|
-
aztecNodeConfig.dataDirectory = statePath;
|
|
306
|
-
}
|
|
307
|
-
aztecNodeConfig.blobSinkUrl = `http://localhost:${blobSinkPort}`;
|
|
308
|
-
|
|
309
|
-
// Setup blob sink service
|
|
310
|
-
const blobSink = await createBlobSinkServer({
|
|
311
|
-
port: blobSinkPort,
|
|
312
|
-
dataStoreConfig: {
|
|
313
|
-
dataDirectory: aztecNodeConfig.dataDirectory,
|
|
314
|
-
dataStoreMapSizeKB: aztecNodeConfig.dataStoreMapSizeKB,
|
|
315
|
-
},
|
|
316
|
-
});
|
|
317
|
-
await blobSink.start();
|
|
318
|
-
|
|
319
|
-
// Start anvil. We go via a wrapper script to ensure if the parent dies, anvil dies.
|
|
320
|
-
logger.verbose('Starting anvil...');
|
|
321
|
-
const res = await startAnvil({ l1BlockTime: opts.ethereumSlotDuration });
|
|
322
|
-
const anvil = res.anvil;
|
|
323
|
-
aztecNodeConfig.l1RpcUrls = [res.rpcUrl];
|
|
324
|
-
|
|
325
|
-
// Deploy our L1 contracts.
|
|
326
|
-
logger.verbose('Deploying L1 contracts...');
|
|
327
|
-
const hdAccount = mnemonicToAccount(MNEMONIC, { accountIndex: 0 });
|
|
328
|
-
const publisherPrivKeyRaw = hdAccount.getHdKey().privateKey;
|
|
329
|
-
const publisherPrivKey = publisherPrivKeyRaw === null ? null : Buffer.from(publisherPrivKeyRaw);
|
|
330
|
-
|
|
331
|
-
const validatorPrivKey = getPrivateKeyFromIndex(0);
|
|
332
|
-
const proverNodePrivateKey = getPrivateKeyFromIndex(0);
|
|
333
|
-
|
|
334
|
-
aztecNodeConfig.publisherPrivateKey = `0x${publisherPrivKey!.toString('hex')}`;
|
|
335
|
-
aztecNodeConfig.validatorPrivateKey = `0x${validatorPrivKey!.toString('hex')}`;
|
|
336
|
-
|
|
337
|
-
const ethCheatCodes = new EthCheatCodesWithState(aztecNodeConfig.l1RpcUrls);
|
|
338
|
-
|
|
339
|
-
if (opts.l1StartTime) {
|
|
340
|
-
await ethCheatCodes.warp(opts.l1StartTime);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
const initialFundedAccounts = await generateSchnorrAccounts(numberOfInitialFundedAccounts);
|
|
344
|
-
const { genesisArchiveRoot, genesisBlockHash, prefilledPublicData } = await getGenesisValues(
|
|
345
|
-
initialFundedAccounts.map(a => a.address),
|
|
346
|
-
opts.initialAccountFeeJuice,
|
|
347
|
-
);
|
|
348
|
-
|
|
349
|
-
const deployL1ContractsValues = await setupL1Contracts(aztecNodeConfig.l1RpcUrls[0], hdAccount, logger, {
|
|
350
|
-
...getL1ContractsConfigEnvVars(),
|
|
351
|
-
genesisArchiveRoot,
|
|
352
|
-
genesisBlockHash,
|
|
353
|
-
salt: opts.salt,
|
|
354
|
-
...deployL1ContractsArgs,
|
|
355
|
-
initialValidators: opts.initialValidators,
|
|
356
|
-
});
|
|
357
|
-
aztecNodeConfig.l1Contracts = deployL1ContractsValues.l1ContractAddresses;
|
|
358
|
-
aztecNodeConfig.l1PublishRetryIntervalMS = 100;
|
|
359
|
-
|
|
360
|
-
if (opts.fundRewardDistributor) {
|
|
361
|
-
// Mints block rewards for 10000 blocks to the rewardDistributor contract
|
|
362
|
-
|
|
363
|
-
const rewardDistributor = getContract({
|
|
364
|
-
address: deployL1ContractsValues.l1ContractAddresses.rewardDistributorAddress.toString(),
|
|
365
|
-
abi: l1Artifacts.rewardDistributor.contractAbi,
|
|
366
|
-
client: deployL1ContractsValues.publicClient,
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
const blockReward = await rewardDistributor.read.BLOCK_REWARD();
|
|
370
|
-
const mintAmount = 10_000n * (blockReward as bigint);
|
|
371
|
-
|
|
372
|
-
const feeJuice = getContract({
|
|
373
|
-
address: deployL1ContractsValues.l1ContractAddresses.feeJuiceAddress.toString(),
|
|
374
|
-
abi: l1Artifacts.feeAsset.contractAbi,
|
|
375
|
-
client: deployL1ContractsValues.walletClient,
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
const rewardDistributorMintTxHash = await feeJuice.write.mint([rewardDistributor.address, mintAmount], {} as any);
|
|
379
|
-
await deployL1ContractsValues.publicClient.waitForTransactionReceipt({ hash: rewardDistributorMintTxHash });
|
|
380
|
-
logger.info(`Funding rewardDistributor in ${rewardDistributorMintTxHash}`);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
const watcher = new AnvilTestWatcher(
|
|
384
|
-
new EthCheatCodesWithState(aztecNodeConfig.l1RpcUrls),
|
|
385
|
-
deployL1ContractsValues.l1ContractAddresses.rollupAddress,
|
|
386
|
-
deployL1ContractsValues.publicClient,
|
|
387
|
-
);
|
|
388
|
-
await watcher.start();
|
|
389
|
-
|
|
390
|
-
const acvmConfig = await getACVMConfig(logger);
|
|
391
|
-
if (acvmConfig) {
|
|
392
|
-
aztecNodeConfig.acvmWorkingDirectory = acvmConfig.acvmWorkingDirectory;
|
|
393
|
-
aztecNodeConfig.acvmBinaryPath = acvmConfig.acvmBinaryPath;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
const bbConfig = await getBBConfig(logger);
|
|
397
|
-
if (bbConfig) {
|
|
398
|
-
aztecNodeConfig.bbBinaryPath = bbConfig.bbBinaryPath;
|
|
399
|
-
aztecNodeConfig.bbWorkingDirectory = bbConfig.bbWorkingDirectory;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
const telemetry = getEndToEndTestTelemetryClient(opts.metricsPort);
|
|
403
|
-
|
|
404
|
-
logger.verbose('Creating and synching an aztec node...');
|
|
405
|
-
const dateProvider = new TestDateProvider();
|
|
406
|
-
const aztecNode = await AztecNodeService.createAndSync(
|
|
407
|
-
aztecNodeConfig,
|
|
408
|
-
{ telemetry, dateProvider },
|
|
409
|
-
{ prefilledPublicData },
|
|
410
|
-
);
|
|
411
|
-
|
|
412
|
-
let proverNode: ProverNode | undefined = undefined;
|
|
413
|
-
if (opts.startProverNode) {
|
|
414
|
-
logger.verbose('Creating and syncing a simulated prover node...');
|
|
415
|
-
proverNode = await createAndSyncProverNode(
|
|
416
|
-
`0x${proverNodePrivateKey!.toString('hex')}`,
|
|
417
|
-
aztecNodeConfig,
|
|
418
|
-
aztecNode,
|
|
419
|
-
path.join(directoryToCleanup, randomBytes(8).toString('hex')),
|
|
420
|
-
prefilledPublicData,
|
|
421
|
-
);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
logger.verbose('Creating pxe...');
|
|
425
|
-
const pxeConfig = getPXEServiceConfig();
|
|
426
|
-
pxeConfig.dataDirectory = statePath ?? path.join(directoryToCleanup, randomBytes(8).toString('hex'));
|
|
427
|
-
const pxe = await createPXEService(aztecNode, pxeConfig);
|
|
428
|
-
|
|
429
|
-
const cheatCodes = await CheatCodes.create(aztecNodeConfig.l1RpcUrls, pxe);
|
|
430
|
-
|
|
431
|
-
if (statePath) {
|
|
432
|
-
writeFileSync(`${statePath}/aztec_node_config.json`, JSON.stringify(aztecNodeConfig, resolver));
|
|
433
|
-
writeFileSync(`${statePath}/accounts.json`, JSON.stringify(initialFundedAccounts, resolver));
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
return {
|
|
437
|
-
aztecNodeConfig,
|
|
438
|
-
anvil,
|
|
439
|
-
aztecNode,
|
|
440
|
-
pxe,
|
|
441
|
-
acvmConfig,
|
|
442
|
-
bbConfig,
|
|
443
|
-
deployL1ContractsValues,
|
|
444
|
-
proverNode,
|
|
445
|
-
watcher,
|
|
446
|
-
cheatCodes,
|
|
447
|
-
dateProvider,
|
|
448
|
-
blobSink,
|
|
449
|
-
initialFundedAccounts,
|
|
450
|
-
directoryToCleanup,
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* Given a statePath, setup the system starting from that state.
|
|
456
|
-
*/
|
|
457
|
-
async function setupFromState(statePath: string, logger: Logger): Promise<SubsystemsContext> {
|
|
458
|
-
logger.verbose(`Initializing with saved state at ${statePath}...`);
|
|
459
|
-
|
|
460
|
-
const directoryToCleanup = path.join(tmpdir(), randomBytes(8).toString('hex'));
|
|
461
|
-
await fs.mkdir(directoryToCleanup, { recursive: true });
|
|
462
|
-
|
|
463
|
-
// Run the blob sink on a random port
|
|
464
|
-
const blobSinkPort = await getPort();
|
|
465
|
-
|
|
466
|
-
// TODO: For some reason this is currently the union of a bunch of subsystems. That needs fixing.
|
|
467
|
-
const aztecNodeConfig: AztecNodeConfig & SetupOptions = JSON.parse(
|
|
468
|
-
readFileSync(`${statePath}/aztec_node_config.json`, 'utf-8'),
|
|
469
|
-
reviver,
|
|
470
|
-
);
|
|
471
|
-
aztecNodeConfig.dataDirectory = statePath;
|
|
472
|
-
aztecNodeConfig.blobSinkUrl = `http://127.0.0.1:${blobSinkPort}`;
|
|
473
|
-
|
|
474
|
-
const initialFundedAccounts: InitialAccountData[] =
|
|
475
|
-
JSON.parse(readFileSync(`${statePath}/accounts.json`, 'utf-8'), reviver) || [];
|
|
476
|
-
const { prefilledPublicData } = await getGenesisValues(initialFundedAccounts.map(a => a.address));
|
|
477
|
-
|
|
478
|
-
const blobSink = await createBlobSinkServer({
|
|
479
|
-
port: blobSinkPort,
|
|
480
|
-
dataStoreConfig: {
|
|
481
|
-
dataDirectory: statePath,
|
|
482
|
-
dataStoreMapSizeKB: aztecNodeConfig.dataStoreMapSizeKB,
|
|
483
|
-
},
|
|
484
|
-
});
|
|
485
|
-
await blobSink.start();
|
|
486
|
-
|
|
487
|
-
// Start anvil. We go via a wrapper script to ensure if the parent dies, anvil dies.
|
|
488
|
-
const { anvil, rpcUrl } = await startAnvil();
|
|
489
|
-
aztecNodeConfig.l1RpcUrls = [rpcUrl];
|
|
490
|
-
// Load anvil state.
|
|
491
|
-
const anvilStateFile = `${statePath}/anvil.dat`;
|
|
492
|
-
const ethCheatCodes = new EthCheatCodesWithState(aztecNodeConfig.l1RpcUrls);
|
|
493
|
-
await ethCheatCodes.loadChainState(anvilStateFile);
|
|
494
|
-
|
|
495
|
-
// TODO: Encapsulate this in a NativeAcvm impl.
|
|
496
|
-
const acvmConfig = await getACVMConfig(logger);
|
|
497
|
-
if (acvmConfig) {
|
|
498
|
-
aztecNodeConfig.acvmWorkingDirectory = acvmConfig.acvmWorkingDirectory;
|
|
499
|
-
aztecNodeConfig.acvmBinaryPath = acvmConfig.acvmBinaryPath;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
const bbConfig = await getBBConfig(logger);
|
|
503
|
-
if (bbConfig) {
|
|
504
|
-
aztecNodeConfig.bbBinaryPath = bbConfig.bbBinaryPath;
|
|
505
|
-
aztecNodeConfig.bbWorkingDirectory = bbConfig.bbWorkingDirectory;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
logger.verbose('Creating ETH clients...');
|
|
509
|
-
const { publicClient, walletClient } = createL1Clients(aztecNodeConfig.l1RpcUrls, mnemonicToAccount(MNEMONIC));
|
|
510
|
-
|
|
511
|
-
const watcher = new AnvilTestWatcher(
|
|
512
|
-
new EthCheatCodesWithState(aztecNodeConfig.l1RpcUrls),
|
|
513
|
-
aztecNodeConfig.l1Contracts.rollupAddress,
|
|
514
|
-
publicClient,
|
|
515
|
-
);
|
|
516
|
-
await watcher.start();
|
|
517
|
-
|
|
518
|
-
logger.verbose('Creating aztec node...');
|
|
519
|
-
const telemetry = initTelemetryClient(getTelemetryConfig());
|
|
520
|
-
const dateProvider = new TestDateProvider();
|
|
521
|
-
const aztecNode = await AztecNodeService.createAndSync(
|
|
522
|
-
aztecNodeConfig,
|
|
523
|
-
{ telemetry, dateProvider },
|
|
524
|
-
{ prefilledPublicData },
|
|
525
|
-
);
|
|
526
|
-
|
|
527
|
-
let proverNode: ProverNode | undefined = undefined;
|
|
528
|
-
if (aztecNodeConfig.startProverNode) {
|
|
529
|
-
logger.verbose('Creating and syncing a simulated prover node...');
|
|
530
|
-
const proverNodePrivateKey = getPrivateKeyFromIndex(2);
|
|
531
|
-
const proverNodePrivateKeyHex: Hex = `0x${proverNodePrivateKey!.toString('hex')}`;
|
|
532
|
-
proverNode = await createAndSyncProverNode(
|
|
533
|
-
proverNodePrivateKeyHex,
|
|
534
|
-
aztecNodeConfig,
|
|
535
|
-
aztecNode,
|
|
536
|
-
path.join(directoryToCleanup, randomBytes(8).toString('hex')),
|
|
537
|
-
prefilledPublicData,
|
|
538
|
-
);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
logger.verbose('Creating pxe...');
|
|
542
|
-
const pxeConfig = getPXEServiceConfig();
|
|
543
|
-
pxeConfig.dataDirectory = statePath;
|
|
544
|
-
const pxe = await createPXEService(aztecNode, pxeConfig);
|
|
545
|
-
|
|
546
|
-
const cheatCodes = await CheatCodes.create(aztecNodeConfig.l1RpcUrls, pxe);
|
|
547
|
-
|
|
548
|
-
return {
|
|
549
|
-
aztecNodeConfig,
|
|
550
|
-
anvil,
|
|
551
|
-
aztecNode,
|
|
552
|
-
pxe,
|
|
553
|
-
acvmConfig,
|
|
554
|
-
bbConfig,
|
|
555
|
-
proverNode,
|
|
556
|
-
deployL1ContractsValues: {
|
|
557
|
-
walletClient,
|
|
558
|
-
publicClient,
|
|
559
|
-
l1ContractAddresses: aztecNodeConfig.l1Contracts,
|
|
560
|
-
},
|
|
561
|
-
watcher,
|
|
562
|
-
cheatCodes,
|
|
563
|
-
dateProvider,
|
|
564
|
-
blobSink,
|
|
565
|
-
initialFundedAccounts,
|
|
566
|
-
directoryToCleanup,
|
|
567
|
-
};
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* Snapshot 'apply' helper function to add accounts.
|
|
572
|
-
* The 'restore' function is not provided, as it must be a closure within the test context to capture the results.
|
|
573
|
-
*/
|
|
574
|
-
export const deployAccounts =
|
|
575
|
-
(numberOfAccounts: number, logger: Logger, waitUntilProven = false) =>
|
|
576
|
-
async ({ pxe, initialFundedAccounts }: { pxe: PXE; initialFundedAccounts: InitialAccountData[] }) => {
|
|
577
|
-
if (initialFundedAccounts.length < numberOfAccounts) {
|
|
578
|
-
throw new Error(`Cannot deploy more than ${initialFundedAccounts.length} initial accounts.`);
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
logger.verbose('Deploying accounts funded with fee juice...');
|
|
582
|
-
const deployedAccounts = initialFundedAccounts.slice(0, numberOfAccounts);
|
|
583
|
-
await deployFundedSchnorrAccounts(pxe, deployedAccounts, { proven: waitUntilProven });
|
|
584
|
-
|
|
585
|
-
return { deployedAccounts };
|
|
586
|
-
};
|
|
587
|
-
|
|
588
|
-
/**
|
|
589
|
-
* Registers the contract class used for test accounts and publicly deploys the instances requested.
|
|
590
|
-
* Use this when you need to make a public call to an account contract, such as for requesting a public authwit.
|
|
591
|
-
* @param sender - Wallet to send the deployment tx.
|
|
592
|
-
* @param accountsToDeploy - Which accounts to publicly deploy.
|
|
593
|
-
*/
|
|
594
|
-
export async function publicDeployAccounts(
|
|
595
|
-
sender: Wallet,
|
|
596
|
-
accountsToDeploy: (CompleteAddress | AztecAddress)[],
|
|
597
|
-
waitUntilProven = false,
|
|
598
|
-
) {
|
|
599
|
-
const accountAddressesToDeploy = accountsToDeploy.map(a => ('address' in a ? a.address : a));
|
|
600
|
-
const instances = (
|
|
601
|
-
await Promise.all(accountAddressesToDeploy.map(account => sender.getContractMetadata(account)))
|
|
602
|
-
).map(metadata => metadata.contractInstance);
|
|
603
|
-
|
|
604
|
-
const contractClass = await getContractClassFromArtifact(SchnorrAccountContractArtifact);
|
|
605
|
-
const alreadyRegistered = (await sender.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered;
|
|
606
|
-
|
|
607
|
-
const fns: ContractFunctionInteraction[] = await Promise.all([
|
|
608
|
-
...(!alreadyRegistered ? [registerContractClass(sender, SchnorrAccountContractArtifact)] : []),
|
|
609
|
-
...instances.map(instance => deployInstance(sender, instance!)),
|
|
610
|
-
]);
|
|
611
|
-
const calls: FunctionCall[] = await Promise.all(fns.map(fn => fn.request()));
|
|
612
|
-
const capsules: Capsule[] = fns.map(fn => fn.getCapsules()).flat();
|
|
613
|
-
|
|
614
|
-
const batch = new BatchCall(sender, calls);
|
|
615
|
-
batch.addCapsules(capsules);
|
|
616
|
-
await batch.send().wait({ proven: waitUntilProven });
|
|
617
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// docs:start:all
|
|
2
|
-
import { createPXEClient } from '@aztec/aztec.js';
|
|
3
|
-
|
|
4
|
-
const { PXE_URL = 'http://localhost:8080' } = process.env;
|
|
5
|
-
|
|
6
|
-
async function main() {
|
|
7
|
-
const pxe = await createPXEClient(PXE_URL);
|
|
8
|
-
const { l1ChainId } = await pxe.getNodeInfo();
|
|
9
|
-
console.log(`Connected to chain ${l1ChainId}`);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
main().catch(err => {
|
|
13
|
-
console.error(`Error in app: ${err}`);
|
|
14
|
-
process.exit(1);
|
|
15
|
-
});
|
|
16
|
-
// docs:end:all
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// docs:start:imports
|
|
2
|
-
import { AztecAddress } from '@aztec/aztec.js';
|
|
3
|
-
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
4
|
-
|
|
5
|
-
import { readFileSync } from 'fs';
|
|
6
|
-
|
|
7
|
-
// docs:end:imports
|
|
8
|
-
|
|
9
|
-
// docs:start:get-tokens
|
|
10
|
-
export async function getToken(wallet) {
|
|
11
|
-
const addresses = JSON.parse(readFileSync('addresses.json'));
|
|
12
|
-
return TokenContract.at(AztecAddress.fromString(addresses.token), wallet);
|
|
13
|
-
}
|
|
14
|
-
// docs:end:get-tokens
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// docs:start:deploy-imports
|
|
2
|
-
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing';
|
|
3
|
-
import { Contract, createPXEClient, loadContractArtifact, waitForPXE } from '@aztec/aztec.js';
|
|
4
|
-
// docs:end:deploy-imports
|
|
5
|
-
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
|
|
6
|
-
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
7
|
-
|
|
8
|
-
import { writeFileSync } from 'fs';
|
|
9
|
-
import { fileURLToPath } from 'url';
|
|
10
|
-
|
|
11
|
-
// docs:start:dapp-deploy
|
|
12
|
-
const { PXE_URL = 'http://localhost:8080' } = process.env;
|
|
13
|
-
|
|
14
|
-
async function main() {
|
|
15
|
-
const pxe = createPXEClient(PXE_URL);
|
|
16
|
-
await waitForPXE(pxe);
|
|
17
|
-
|
|
18
|
-
const [ownerWallet] = await getInitialTestAccountsWallets(pxe);
|
|
19
|
-
const ownerAddress = ownerWallet.getAddress();
|
|
20
|
-
|
|
21
|
-
const token = await Contract.deploy(ownerWallet, TokenContractArtifact, [ownerAddress, 'TokenName', 'TKN', 18])
|
|
22
|
-
.send()
|
|
23
|
-
.deployed();
|
|
24
|
-
|
|
25
|
-
console.log(`Token deployed at ${token.address.toString()}`);
|
|
26
|
-
|
|
27
|
-
const addresses = { token: token.address.toString() };
|
|
28
|
-
writeFileSync('addresses.json', JSON.stringify(addresses, null, 2));
|
|
29
|
-
}
|
|
30
|
-
// docs:end:dapp-deploy
|
|
31
|
-
|
|
32
|
-
// Execute main only if run directly
|
|
33
|
-
if (process.argv[1].replace(/\/index\.m?js$/, '') === fileURLToPath(import.meta.url).replace(/\/index\.m?js$/, '')) {
|
|
34
|
-
main().catch(err => {
|
|
35
|
-
console.error(`Error in deployment script: ${err}`);
|
|
36
|
-
process.exit(1);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export { main as deploy };
|