@aztec/end-to-end 0.0.0-test.1 → 0.0.1-commit.1142ef1

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.
Files changed (186) hide show
  1. package/dest/bench/client_flows/benchmark.d.ts +61 -0
  2. package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
  3. package/dest/bench/client_flows/benchmark.js +261 -0
  4. package/dest/bench/client_flows/client_flows_benchmark.d.ts +80 -0
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
  6. package/dest/bench/client_flows/client_flows_benchmark.js +336 -0
  7. package/dest/bench/client_flows/config.d.ts +14 -0
  8. package/dest/bench/client_flows/config.d.ts.map +1 -0
  9. package/dest/bench/client_flows/config.js +106 -0
  10. package/dest/bench/client_flows/data_extractor.d.ts +2 -0
  11. package/dest/bench/client_flows/data_extractor.d.ts.map +1 -0
  12. package/dest/bench/client_flows/data_extractor.js +79 -0
  13. package/dest/bench/utils.d.ts +14 -40
  14. package/dest/bench/utils.d.ts.map +1 -1
  15. package/dest/bench/utils.js +37 -70
  16. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +21 -13
  17. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  18. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +85 -57
  19. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +29 -28
  20. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  21. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +79 -82
  22. package/dest/e2e_deploy_contract/deploy_test.d.ts +16 -8
  23. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  24. package/dest/e2e_deploy_contract/deploy_test.js +13 -19
  25. package/dest/e2e_epochs/epochs_test.d.ts +65 -22
  26. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  27. package/dest/e2e_epochs/epochs_test.js +233 -49
  28. package/dest/e2e_fees/bridging_race.notest.d.ts +2 -0
  29. package/dest/e2e_fees/bridging_race.notest.d.ts.map +1 -0
  30. package/dest/e2e_fees/bridging_race.notest.js +63 -0
  31. package/dest/e2e_fees/fees_test.d.ts +27 -12
  32. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  33. package/dest/e2e_fees/fees_test.js +107 -110
  34. package/dest/e2e_l1_publisher/write_json.d.ts +10 -0
  35. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
  36. package/dest/e2e_l1_publisher/write_json.js +55 -0
  37. package/dest/e2e_multi_validator/utils.d.ts +12 -0
  38. package/dest/e2e_multi_validator/utils.d.ts.map +1 -0
  39. package/dest/e2e_multi_validator/utils.js +214 -0
  40. package/dest/e2e_nested_contract/nested_contract_test.d.ts +10 -7
  41. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  42. package/dest/e2e_nested_contract/nested_contract_test.js +24 -20
  43. package/dest/e2e_p2p/inactivity_slash_test.d.ts +31 -0
  44. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -0
  45. package/dest/e2e_p2p/inactivity_slash_test.js +136 -0
  46. package/dest/e2e_p2p/p2p_network.d.ts +276 -23
  47. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  48. package/dest/e2e_p2p/p2p_network.js +188 -133
  49. package/dest/e2e_p2p/shared.d.ts +43 -7
  50. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  51. package/dest/e2e_p2p/shared.js +164 -19
  52. package/dest/e2e_token_contract/token_contract_test.d.ts +12 -6
  53. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  54. package/dest/e2e_token_contract/token_contract_test.js +50 -26
  55. package/dest/fixtures/e2e_prover_test.d.ts +61 -0
  56. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
  57. package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +108 -113
  58. package/dest/fixtures/fixtures.d.ts +6 -8
  59. package/dest/fixtures/fixtures.d.ts.map +1 -1
  60. package/dest/fixtures/fixtures.js +5 -5
  61. package/dest/fixtures/get_acvm_config.d.ts +2 -2
  62. package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
  63. package/dest/fixtures/get_acvm_config.js +3 -15
  64. package/dest/fixtures/get_bb_config.d.ts +2 -2
  65. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  66. package/dest/fixtures/get_bb_config.js +10 -17
  67. package/dest/fixtures/index.d.ts +1 -1
  68. package/dest/fixtures/l1_to_l2_messaging.d.ts +11 -7
  69. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  70. package/dest/fixtures/l1_to_l2_messaging.js +45 -19
  71. package/dest/fixtures/logging.d.ts +1 -1
  72. package/dest/fixtures/setup_p2p_test.d.ts +15 -14
  73. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  74. package/dest/fixtures/setup_p2p_test.js +82 -22
  75. package/dest/fixtures/snapshot_manager.d.ts +20 -14
  76. package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
  77. package/dest/fixtures/snapshot_manager.js +147 -138
  78. package/dest/fixtures/token_utils.d.ts +10 -4
  79. package/dest/fixtures/token_utils.d.ts.map +1 -1
  80. package/dest/fixtures/token_utils.js +28 -12
  81. package/dest/fixtures/utils.d.ts +92 -54
  82. package/dest/fixtures/utils.d.ts.map +1 -1
  83. package/dest/fixtures/utils.js +452 -389
  84. package/dest/fixtures/web3signer.d.ts +5 -0
  85. package/dest/fixtures/web3signer.d.ts.map +1 -0
  86. package/dest/fixtures/web3signer.js +53 -0
  87. package/dest/fixtures/with_telemetry_utils.d.ts +2 -2
  88. package/dest/fixtures/with_telemetry_utils.d.ts.map +1 -1
  89. package/dest/fixtures/with_telemetry_utils.js +2 -2
  90. package/dest/index.d.ts +1 -1
  91. package/dest/quality_of_service/grafana_client.d.ts +41 -0
  92. package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
  93. package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
  94. package/dest/shared/cross_chain_test_harness.d.ts +42 -35
  95. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  96. package/dest/shared/cross_chain_test_harness.js +106 -52
  97. package/dest/shared/gas_portal_test_harness.d.ts +29 -31
  98. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  99. package/dest/shared/gas_portal_test_harness.js +51 -30
  100. package/dest/shared/index.d.ts +2 -2
  101. package/dest/shared/index.d.ts.map +1 -1
  102. package/dest/shared/jest_setup.d.ts +1 -1
  103. package/dest/shared/jest_setup.js +1 -1
  104. package/dest/shared/submit-transactions.d.ts +6 -4
  105. package/dest/shared/submit-transactions.d.ts.map +1 -1
  106. package/dest/shared/submit-transactions.js +8 -7
  107. package/dest/shared/uniswap_l1_l2.d.ts +3 -25
  108. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  109. package/dest/shared/uniswap_l1_l2.js +170 -120
  110. package/dest/simulators/index.d.ts +1 -1
  111. package/dest/simulators/lending_simulator.d.ts +7 -11
  112. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  113. package/dest/simulators/lending_simulator.js +16 -17
  114. package/dest/simulators/token_simulator.d.ts +6 -3
  115. package/dest/simulators/token_simulator.d.ts.map +1 -1
  116. package/dest/simulators/token_simulator.js +16 -13
  117. package/dest/spartan/setup_test_wallets.d.ts +27 -11
  118. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  119. package/dest/spartan/setup_test_wallets.js +202 -58
  120. package/dest/spartan/tx_metrics.d.ts +39 -0
  121. package/dest/spartan/tx_metrics.d.ts.map +1 -0
  122. package/dest/spartan/tx_metrics.js +95 -0
  123. package/dest/spartan/utils.d.ts +151 -313
  124. package/dest/spartan/utils.d.ts.map +1 -1
  125. package/dest/spartan/utils.js +598 -151
  126. package/package.json +65 -58
  127. package/src/bench/client_flows/benchmark.ts +341 -0
  128. package/src/bench/client_flows/client_flows_benchmark.ts +450 -0
  129. package/src/bench/client_flows/config.ts +61 -0
  130. package/src/bench/client_flows/data_extractor.ts +89 -0
  131. package/src/bench/utils.ts +35 -81
  132. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +80 -77
  133. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +103 -122
  134. package/src/e2e_deploy_contract/deploy_test.ts +24 -39
  135. package/src/e2e_epochs/epochs_test.ts +299 -65
  136. package/src/e2e_fees/bridging_race.notest.ts +80 -0
  137. package/src/e2e_fees/fees_test.ts +150 -142
  138. package/src/e2e_l1_publisher/write_json.ts +74 -0
  139. package/src/e2e_multi_validator/utils.ts +258 -0
  140. package/src/e2e_nested_contract/nested_contract_test.ts +29 -19
  141. package/src/e2e_p2p/inactivity_slash_test.ts +179 -0
  142. package/src/e2e_p2p/p2p_network.ts +274 -171
  143. package/src/e2e_p2p/shared.ts +252 -29
  144. package/src/e2e_token_contract/token_contract_test.ts +43 -39
  145. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  146. package/src/{e2e_prover → fixtures}/e2e_prover_test.ts +112 -160
  147. package/src/fixtures/fixtures.ts +5 -7
  148. package/src/fixtures/get_acvm_config.ts +4 -12
  149. package/src/fixtures/get_bb_config.ts +18 -13
  150. package/src/fixtures/l1_to_l2_messaging.ts +56 -24
  151. package/src/fixtures/setup_p2p_test.ts +127 -39
  152. package/src/fixtures/snapshot_manager.ts +189 -160
  153. package/src/fixtures/token_utils.ts +32 -15
  154. package/src/fixtures/utils.ts +556 -475
  155. package/src/fixtures/web3signer.ts +63 -0
  156. package/src/fixtures/with_telemetry_utils.ts +2 -2
  157. package/src/guides/up_quick_start.sh +7 -15
  158. package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +2 -2
  159. package/src/shared/cross_chain_test_harness.ts +113 -87
  160. package/src/shared/gas_portal_test_harness.ts +59 -50
  161. package/src/shared/index.ts +1 -1
  162. package/src/shared/jest_setup.ts +1 -1
  163. package/src/shared/submit-transactions.ts +12 -8
  164. package/src/shared/uniswap_l1_l2.ts +194 -211
  165. package/src/simulators/lending_simulator.ts +15 -16
  166. package/src/simulators/token_simulator.ts +21 -13
  167. package/src/spartan/DEVELOP.md +128 -0
  168. package/src/spartan/setup_test_wallets.ts +258 -93
  169. package/src/spartan/tx_metrics.ts +130 -0
  170. package/src/spartan/utils.ts +722 -146
  171. package/dest/e2e_prover/e2e_prover_test.d.ts +0 -56
  172. package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
  173. package/dest/fixtures/setup_l1_contracts.d.ts +0 -6
  174. package/dest/fixtures/setup_l1_contracts.d.ts.map +0 -1
  175. package/dest/fixtures/setup_l1_contracts.js +0 -17
  176. package/dest/quality_of_service/alert_checker.d.ts +0 -41
  177. package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
  178. package/dest/sample-dapp/connect.js +0 -12
  179. package/dest/sample-dapp/contracts.js +0 -10
  180. package/dest/sample-dapp/deploy.js +0 -35
  181. package/dest/sample-dapp/index.js +0 -98
  182. package/src/fixtures/setup_l1_contracts.ts +0 -27
  183. package/src/sample-dapp/connect.mjs +0 -16
  184. package/src/sample-dapp/contracts.mjs +0 -14
  185. package/src/sample-dapp/deploy.mjs +0 -40
  186. package/src/sample-dapp/index.mjs +0 -128
@@ -1,36 +1,46 @@
1
1
  import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';
2
- import { deployFundedSchnorrAccounts, generateSchnorrAccounts, getDeployedTestAccounts, getDeployedTestAccountsWallets } from '@aztec/accounts/testing';
2
+ import { generateSchnorrAccounts, getInitialTestAccountsData } from '@aztec/accounts/testing';
3
3
  import { createArchiver } from '@aztec/archiver';
4
4
  import { AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node';
5
- import { AnvilTestWatcher, BatchCall, CheatCodes, FeeJuicePaymentMethod, SignerlessWallet, createAztecNodeClient, createLogger, createPXEClient, deployL1Contracts, makeFetch, waitForPXE } from '@aztec/aztec.js';
6
- import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment';
7
- import { createBlobSinkClient } from '@aztec/blob-sink/client';
8
- import { createBlobSinkServer } from '@aztec/blob-sink/server';
9
- import { FEE_JUICE_INITIAL_MINT, GENESIS_ARCHIVE_ROOT, GENESIS_BLOCK_HASH } from '@aztec/constants';
10
- import { ForwarderContract, NULL_KEY, createL1Clients, getL1ContractsConfigEnvVars, isAnvilTestChain, l1Artifacts } from '@aztec/ethereum';
11
- import { DelayedTxUtils, EthCheatCodesWithState, startAnvil } from '@aztec/ethereum/test';
12
- import { randomBytes } from '@aztec/foundation/crypto';
5
+ import { BatchCall } from '@aztec/aztec.js/contracts';
6
+ import { publishContractClass, publishInstance } from '@aztec/aztec.js/deployment';
7
+ import { Fr } from '@aztec/aztec.js/fields';
8
+ import { createLogger } from '@aztec/aztec.js/log';
9
+ import { createAztecNodeClient, waitForNode } from '@aztec/aztec.js/node';
10
+ import { AnvilTestWatcher, CheatCodes } from '@aztec/aztec/testing';
11
+ import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
12
+ import { SPONSORED_FPC_SALT } from '@aztec/constants';
13
+ import { isAnvilTestChain } from '@aztec/ethereum/chain';
14
+ import { createExtendedL1Client } from '@aztec/ethereum/client';
15
+ import { getL1ContractsConfigEnvVars } from '@aztec/ethereum/config';
16
+ import { NULL_KEY } from '@aztec/ethereum/constants';
17
+ import { deployAztecL1Contracts } from '@aztec/ethereum/deploy-aztec-l1-contracts';
18
+ import { DelayedTxUtils, EthCheatCodes, EthCheatCodesWithState, createDelayedL1TxUtilsFromViemWallet, startAnvil } from '@aztec/ethereum/test';
19
+ import { EpochNumber } from '@aztec/foundation/branded-types';
20
+ import { SecretValue } from '@aztec/foundation/config';
13
21
  import { EthAddress } from '@aztec/foundation/eth-address';
14
- import { Fr } from '@aztec/foundation/fields';
22
+ import { tryRmDir } from '@aztec/foundation/fs';
23
+ import { withLogNameSuffix } from '@aztec/foundation/log';
15
24
  import { retryUntil } from '@aztec/foundation/retry';
16
- import { TestDateProvider } from '@aztec/foundation/timer';
17
- import { FeeJuiceContract } from '@aztec/noir-contracts.js/FeeJuice';
25
+ import { sleep } from '@aztec/foundation/sleep';
26
+ import { DateProvider, TestDateProvider } from '@aztec/foundation/timer';
27
+ import { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC';
18
28
  import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
19
- import { ProtocolContractAddress, protocolContractTreeRoot } from '@aztec/protocol-contracts';
29
+ import { MockGossipSubNetwork, getMockPubSubP2PServiceFactory } from '@aztec/p2p/test-helpers';
30
+ import { protocolContractsHash } from '@aztec/protocol-contracts';
20
31
  import { createProverNode } from '@aztec/prover-node';
21
- import { createPXEService, getPXEServiceConfig } from '@aztec/pxe/server';
22
- import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
23
- import { Gas } from '@aztec/stdlib/gas';
32
+ import { getPXEConfig } from '@aztec/pxe/server';
33
+ import { getContractClassFromArtifact, getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
34
+ import { tryStop } from '@aztec/stdlib/interfaces/server';
24
35
  import { getConfigEnvVars as getTelemetryConfig, initTelemetryClient } from '@aztec/telemetry-client';
25
36
  import { BenchmarkTelemetryClient } from '@aztec/telemetry-client/bench';
37
+ import { TestWallet, deployFundedSchnorrAccounts } from '@aztec/test-wallet/server';
26
38
  import { getGenesisValues } from '@aztec/world-state/testing';
39
+ import { randomBytes } from 'crypto';
27
40
  import fs from 'fs/promises';
28
- import getPort from 'get-port';
29
41
  import { tmpdir } from 'os';
30
42
  import * as path from 'path';
31
- import { inspect } from 'util';
32
- import { getContract } from 'viem';
33
- import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
43
+ import { generatePrivateKey, mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
34
44
  import { foundry } from 'viem/chains';
35
45
  import { MNEMONIC, TEST_PEER_CHECK_INTERVAL_MS } from './fixtures.js';
36
46
  import { getACVMConfig } from './get_acvm_config.js';
@@ -38,16 +48,28 @@ import { getBBConfig } from './get_bb_config.js';
38
48
  import { isMetricsLoggingRequested, setupMetricsLogger } from './logging.js';
39
49
  export { deployAndInitializeTokenAndBridgeContracts } from '../shared/cross_chain_test_harness.js';
40
50
  export { startAnvil };
41
- const { PXE_URL = '' } = process.env;
42
- const getAztecUrl = ()=>PXE_URL;
51
+ /**
52
+ * Sets up shared blob storage using FileStore in the data directory.
53
+ */ export async function setupSharedBlobStorage(config) {
54
+ const sharedBlobPath = path.join(config.dataDirectory, 'shared-blobs');
55
+ await fs.mkdir(sharedBlobPath, {
56
+ recursive: true
57
+ });
58
+ config.blobFileStoreUrls = [
59
+ `file://${sharedBlobPath}`
60
+ ];
61
+ config.blobFileStoreUploadUrl = `file://${sharedBlobPath}`;
62
+ }
63
+ const { AZTEC_NODE_URL = '' } = process.env;
64
+ const getAztecUrl = ()=>AZTEC_NODE_URL;
43
65
  let telemetry = undefined;
44
- function getTelemetryClient(partialConfig = {}) {
66
+ async function getTelemetryClient(partialConfig = {}) {
45
67
  if (!telemetry) {
46
68
  const config = {
47
69
  ...getTelemetryConfig(),
48
70
  ...partialConfig
49
71
  };
50
- telemetry = config.benchmark ? new BenchmarkTelemetryClient() : initTelemetryClient(config);
72
+ telemetry = config.benchmark ? new BenchmarkTelemetryClient() : await initTelemetryClient(config);
51
73
  }
52
74
  return telemetry;
53
75
  }
@@ -63,55 +85,31 @@ export const getPrivateKeyFromIndex = (index)=>{
63
85
  const privKeyRaw = hdAccount.getHdKey().privateKey;
64
86
  return privKeyRaw === null ? null : Buffer.from(privKeyRaw);
65
87
  };
66
- export const setupL1Contracts = async (l1RpcUrls, account, logger, args = {}, chain = foundry)=>{
67
- const l1Data = await deployL1Contracts(l1RpcUrls, account, chain, logger, {
68
- l2FeeJuiceAddress: ProtocolContractAddress.FeeJuice.toField(),
69
- vkTreeRoot: getVKTreeRoot(),
70
- protocolContractTreeRoot,
71
- genesisArchiveRoot: args.genesisArchiveRoot ?? new Fr(GENESIS_ARCHIVE_ROOT),
72
- genesisBlockHash: args.genesisBlockHash ?? new Fr(GENESIS_BLOCK_HASH),
73
- salt: args.salt,
74
- initialValidators: args.initialValidators,
75
- ...getL1ContractsConfigEnvVars(),
76
- ...args
77
- });
78
- return l1Data;
79
- };
80
88
  /**
81
- * Sets up Private eXecution Environment (PXE).
89
+ * Sets up Private eXecution Environment (PXE) and returns the corresponding test wallet.
82
90
  * @param aztecNode - An instance of Aztec Node.
83
- * @param opts - Partial configuration for the PXE service.
84
- * @param firstPrivKey - The private key of the first account to be created.
91
+ * @param opts - Partial configuration for the PXE.
85
92
  * @param logger - The logger to be used.
86
93
  * @param useLogSuffix - Whether to add a randomly generated suffix to the PXE debug logs.
87
- * @param proofCreator - An optional proof creator to use
88
- * @returns Private eXecution Environment (PXE), accounts, wallets and logger.
89
- */ export async function setupPXEService(aztecNode, opts = {}, logger = getLogger(), useLogSuffix = false, proofCreator) {
90
- const pxeServiceConfig = {
91
- ...getPXEServiceConfig(),
94
+ * @returns A test wallet, logger and teardown function.
95
+ */ export async function setupPXEAndGetWallet(aztecNode, opts = {}, logger = getLogger(), useLogSuffix = false) {
96
+ const PXEConfig = {
97
+ ...getPXEConfig(),
92
98
  ...opts
93
99
  };
100
+ // For tests we only want proving enabled if specifically requested
101
+ PXEConfig.proverEnabled = !!opts.proverEnabled;
94
102
  // If no data directory provided, create a temp directory and clean up afterwards
95
- const configuredDataDirectory = pxeServiceConfig.dataDirectory;
103
+ const configuredDataDirectory = PXEConfig.dataDirectory;
96
104
  if (!configuredDataDirectory) {
97
- pxeServiceConfig.dataDirectory = path.join(tmpdir(), randomBytes(8).toString('hex'));
105
+ PXEConfig.dataDirectory = path.join(tmpdir(), randomBytes(8).toString('hex'));
98
106
  }
99
- const pxe = await createPXEService(aztecNode, pxeServiceConfig, useLogSuffix, proofCreator);
100
- const teardown = async ()=>{
101
- if (!configuredDataDirectory) {
102
- try {
103
- await fs.rm(pxeServiceConfig.dataDirectory, {
104
- recursive: true,
105
- force: true,
106
- maxRetries: 3
107
- });
108
- } catch (err) {
109
- logger.warn(`Failed to delete tmp PXE data directory ${pxeServiceConfig.dataDirectory}: ${err}`);
110
- }
111
- }
112
- };
107
+ const teardown = configuredDataDirectory ? ()=>Promise.resolve() : ()=>tryRmDir(PXEConfig.dataDirectory);
108
+ const wallet = await TestWallet.create(aztecNode, PXEConfig, {
109
+ useLogSuffix
110
+ });
113
111
  return {
114
- pxe,
112
+ wallet,
115
113
  logger,
116
114
  teardown
117
115
  };
@@ -129,48 +127,47 @@ export const setupL1Contracts = async (l1RpcUrls, account, logger, args = {}, ch
129
127
  const aztecNodeUrl = getAztecUrl();
130
128
  logger.verbose(`Creating Aztec Node client to remote host ${aztecNodeUrl}`);
131
129
  const aztecNode = createAztecNodeClient(aztecNodeUrl);
132
- logger.verbose(`Creating PXE client to remote host ${PXE_URL}`);
133
- const pxeClient = createPXEClient(PXE_URL, {}, makeFetch([
134
- 1,
135
- 2,
136
- 3
137
- ], true));
138
- await waitForPXE(pxeClient, logger);
139
- logger.verbose('JSON RPC client connected to PXE');
140
- logger.verbose(`Retrieving contract addresses from ${PXE_URL}`);
141
- const l1Contracts = (await pxeClient.getNodeInfo()).l1ContractAddresses;
142
- const { walletClient, publicClient } = createL1Clients(config.l1RpcUrls, account, foundry);
130
+ await waitForNode(aztecNode, logger);
131
+ logger.verbose('JSON RPC client connected to Aztec Node');
132
+ logger.verbose(`Retrieving contract addresses from ${aztecNodeUrl}`);
133
+ const { l1ContractAddresses, rollupVersion } = await aztecNode.getNodeInfo();
134
+ const l1Client = createExtendedL1Client(config.l1RpcUrls, account, foundry);
143
135
  const deployL1ContractsValues = {
144
- l1ContractAddresses: l1Contracts,
145
- walletClient,
146
- publicClient
136
+ l1ContractAddresses,
137
+ l1Client,
138
+ rollupVersion
147
139
  };
148
- const cheatCodes = await CheatCodes.create(config.l1RpcUrls, pxeClient);
140
+ const ethCheatCodes = new EthCheatCodes(config.l1RpcUrls, new DateProvider());
141
+ const wallet = await TestWallet.create(aztecNode);
142
+ const cheatCodes = await CheatCodes.create(config.l1RpcUrls, aztecNode, new DateProvider());
149
143
  const teardown = ()=>Promise.resolve();
150
- await setupCanonicalFeeJuice(pxeClient);
151
- logger.verbose('Constructing available wallets from already registered accounts...');
152
- const initialFundedAccounts = await getDeployedTestAccounts(pxeClient);
153
- const wallets = await getDeployedTestAccountsWallets(pxeClient);
154
- if (wallets.length < numberOfAccounts) {
155
- throw new Error(`Required ${numberOfAccounts} accounts. Found ${wallets.length}.`);
144
+ logger.verbose('Populating wallet from already registered accounts...');
145
+ const initialFundedAccounts = await getInitialTestAccountsData();
146
+ if (initialFundedAccounts.length < numberOfAccounts) {
147
+ throw new Error(`Required ${numberOfAccounts} accounts. Found ${initialFundedAccounts.length}.`);
156
148
  // Deploy new accounts if there's a test that requires more funded accounts in the remote environment.
157
149
  }
150
+ const testAccounts = await Promise.all(initialFundedAccounts.slice(0, numberOfAccounts).map(async (account)=>{
151
+ const accountManager = await wallet.createSchnorrAccount(account.secret, account.salt, account.signingKey);
152
+ return accountManager.address;
153
+ }));
158
154
  return {
159
155
  aztecNode,
156
+ aztecNodeAdmin: undefined,
160
157
  sequencer: undefined,
161
158
  proverNode: undefined,
162
- pxe: pxeClient,
163
159
  deployL1ContractsValues,
164
- accounts: await pxeClient.getRegisteredAccounts(),
165
160
  config,
166
161
  initialFundedAccounts,
167
- wallet: wallets[0],
168
- wallets: wallets.slice(0, numberOfAccounts),
162
+ wallet,
163
+ accounts: testAccounts,
169
164
  logger,
170
165
  cheatCodes,
166
+ ethCheatCodes,
167
+ prefilledPublicData: undefined,
168
+ mockGossipSubNetwork: undefined,
171
169
  watcher: undefined,
172
170
  dateProvider: undefined,
173
- blobSink: undefined,
174
171
  telemetryClient: undefined,
175
172
  teardown
176
173
  };
@@ -180,257 +177,301 @@ export const setupL1Contracts = async (l1RpcUrls, account, logger, args = {}, ch
180
177
  * @param numberOfAccounts - The number of new accounts to be created once the PXE is initiated.
181
178
  * @param opts - Options to pass to the node initialization and to the setup script.
182
179
  * @param pxeOpts - Options to pass to the PXE initialization.
183
- */ export async function setup(numberOfAccounts = 1, opts = {
184
- customForwarderContractAddress: EthAddress.ZERO
185
- }, pxeOpts = {}, chain = foundry) {
186
- const config = {
187
- ...getConfigEnvVars(),
188
- ...opts
189
- };
190
- config.peerCheckIntervalMS = TEST_PEER_CHECK_INTERVAL_MS;
191
- const logger = getLogger();
192
- // Create a temp directory for any services that need it and cleanup later
193
- const directoryToCleanup = path.join(tmpdir(), randomBytes(8).toString('hex'));
194
- await fs.mkdir(directoryToCleanup, {
195
- recursive: true
196
- });
197
- if (!config.dataDirectory) {
198
- config.dataDirectory = directoryToCleanup;
199
- }
180
+ */ export async function setup(numberOfAccounts = 1, opts = {}, pxeOpts = {}, chain = foundry) {
200
181
  let anvil;
201
- if (!config.l1RpcUrls?.length) {
202
- if (!isAnvilTestChain(chain.id)) {
203
- throw new Error(`No ETHEREUM_HOSTS set but non anvil chain requested`);
182
+ try {
183
+ opts.aztecTargetCommitteeSize ??= 0;
184
+ opts.slasherFlavor ??= 'none';
185
+ const config = {
186
+ ...getConfigEnvVars(),
187
+ ...opts
188
+ };
189
+ // use initialValidators for the node config
190
+ config.validatorPrivateKeys = new SecretValue(opts.initialValidators?.map((v)=>v.privateKey) ?? []);
191
+ config.peerCheckIntervalMS = TEST_PEER_CHECK_INTERVAL_MS;
192
+ // For tests we only want proving enabled if specifically requested
193
+ config.realProofs = !!opts.realProofs;
194
+ // Only enforce the time table if requested
195
+ config.enforceTimeTable = !!opts.enforceTimeTable;
196
+ const logger = getLogger();
197
+ // Create a temp directory for any services that need it and cleanup later
198
+ const directoryToCleanup = path.join(tmpdir(), randomBytes(8).toString('hex'));
199
+ await fs.mkdir(directoryToCleanup, {
200
+ recursive: true
201
+ });
202
+ if (!config.dataDirectory) {
203
+ config.dataDirectory = directoryToCleanup;
204
204
  }
205
- if (PXE_URL) {
206
- throw new Error(`PXE_URL provided but no ETHEREUM_HOSTS set. Refusing to run, please set both variables so tests can deploy L1 contracts to the same Anvil instance`);
205
+ if (!config.l1RpcUrls?.length) {
206
+ if (!isAnvilTestChain(chain.id)) {
207
+ throw new Error(`No ETHEREUM_HOSTS set but non anvil chain requested`);
208
+ }
209
+ if (AZTEC_NODE_URL) {
210
+ throw new Error(`AZTEC_NODE_URL provided but no ETHEREUM_HOSTS set. Refusing to run, please set both variables so tests can deploy L1 contracts to the same Anvil instance`);
211
+ }
212
+ const res = await startAnvil({
213
+ l1BlockTime: opts.ethereumSlotDuration,
214
+ accounts: opts.anvilAccounts,
215
+ port: opts.anvilPort
216
+ });
217
+ anvil = res.anvil;
218
+ config.l1RpcUrls = [
219
+ res.rpcUrl
220
+ ];
207
221
  }
208
- const res = await startAnvil({
209
- l1BlockTime: opts.ethereumSlotDuration
210
- });
211
- anvil = res.anvil;
212
- config.l1RpcUrls = [
213
- res.rpcUrl
214
- ];
215
- }
216
- // Enable logging metrics to a local file named after the test suite
217
- if (isMetricsLoggingRequested()) {
218
- const filename = path.join('log', getJobName() + '.jsonl');
219
- logger.info(`Logging metrics to ${filename}`);
220
- setupMetricsLogger(filename);
221
- }
222
- const ethCheatCodes = new EthCheatCodesWithState(config.l1RpcUrls);
223
- if (opts.stateLoad) {
224
- await ethCheatCodes.loadChainState(opts.stateLoad);
225
- }
226
- if (opts.l1StartTime) {
227
- await ethCheatCodes.warp(opts.l1StartTime);
228
- }
229
- let publisherPrivKey = undefined;
230
- let publisherHdAccount = undefined;
231
- if (config.publisherPrivateKey && config.publisherPrivateKey != NULL_KEY) {
232
- publisherHdAccount = privateKeyToAccount(config.publisherPrivateKey);
233
- } else if (!MNEMONIC) {
234
- throw new Error(`Mnemonic not provided and no publisher private key`);
235
- } else {
236
- publisherHdAccount = mnemonicToAccount(MNEMONIC, {
237
- addressIndex: 0
238
- });
239
- const publisherPrivKeyRaw = publisherHdAccount.getHdKey().privateKey;
240
- publisherPrivKey = publisherPrivKeyRaw === null ? null : Buffer.from(publisherPrivKeyRaw);
241
- config.publisherPrivateKey = `0x${publisherPrivKey.toString('hex')}`;
242
- }
243
- // Made as separate values such that keys can change, but for test they will be the same.
244
- config.validatorPrivateKey = config.publisherPrivateKey;
245
- if (PXE_URL) {
246
- // we are setting up against a remote environment, l1 contracts are assumed to already be deployed
247
- return await setupWithRemoteEnvironment(publisherHdAccount, config, logger, numberOfAccounts);
248
- }
249
- // Blob sink service - blobs get posted here and served from here
250
- const blobSinkPort = await getPort();
251
- const blobSink = await createBlobSinkServer({
252
- port: blobSinkPort
253
- });
254
- await blobSink.start();
255
- config.blobSinkUrl = `http://localhost:${blobSinkPort}`;
256
- const initialFundedAccounts = opts.initialFundedAccounts ?? await generateSchnorrAccounts(opts.numberOfInitialFundedAccounts ?? numberOfAccounts);
257
- const { genesisBlockHash, genesisArchiveRoot, prefilledPublicData } = await getGenesisValues(initialFundedAccounts.map((a)=>a.address), opts.initialAccountFeeJuice, opts.genesisPublicData);
258
- const deployL1ContractsValues = opts.deployL1ContractsValues ?? await setupL1Contracts(config.l1RpcUrls, publisherHdAccount, logger, {
259
- ...opts,
260
- genesisArchiveRoot,
261
- genesisBlockHash
262
- }, chain);
263
- config.l1Contracts = deployL1ContractsValues.l1ContractAddresses;
264
- if (opts.fundRewardDistributor) {
265
- // Mints block rewards for 10000 blocks to the rewardDistributor contract
266
- const rewardDistributor = getContract({
267
- address: deployL1ContractsValues.l1ContractAddresses.rewardDistributorAddress.toString(),
268
- abi: l1Artifacts.rewardDistributor.contractAbi,
269
- client: deployL1ContractsValues.publicClient
270
- });
271
- const blockReward = await rewardDistributor.read.BLOCK_REWARD();
272
- const mintAmount = 10_000n * blockReward;
273
- const feeJuice = getContract({
274
- address: deployL1ContractsValues.l1ContractAddresses.feeJuiceAddress.toString(),
275
- abi: l1Artifacts.feeAsset.contractAbi,
276
- client: deployL1ContractsValues.walletClient
222
+ // Enable logging metrics to a local file named after the test suite
223
+ if (isMetricsLoggingRequested()) {
224
+ const filename = path.join('log', getJobName() + '.jsonl');
225
+ logger.info(`Logging metrics to ${filename}`);
226
+ setupMetricsLogger(filename);
227
+ }
228
+ const dateProvider = new TestDateProvider();
229
+ const ethCheatCodes = new EthCheatCodesWithState(config.l1RpcUrls, dateProvider);
230
+ if (opts.stateLoad) {
231
+ await ethCheatCodes.loadChainState(opts.stateLoad);
232
+ }
233
+ if (opts.l1StartTime) {
234
+ await ethCheatCodes.warp(opts.l1StartTime, {
235
+ resetBlockInterval: true
236
+ });
237
+ }
238
+ let publisherPrivKeyHex = undefined;
239
+ let publisherHdAccount = undefined;
240
+ if (opts.l1PublisherKey && opts.l1PublisherKey.getValue() && opts.l1PublisherKey.getValue() != NULL_KEY) {
241
+ publisherPrivKeyHex = opts.l1PublisherKey.getValue();
242
+ publisherHdAccount = privateKeyToAccount(publisherPrivKeyHex);
243
+ } else if (config.publisherPrivateKeys && config.publisherPrivateKeys.length > 0 && config.publisherPrivateKeys[0].getValue() != NULL_KEY) {
244
+ publisherPrivKeyHex = config.publisherPrivateKeys[0].getValue();
245
+ publisherHdAccount = privateKeyToAccount(publisherPrivKeyHex);
246
+ } else if (!MNEMONIC) {
247
+ throw new Error(`Mnemonic not provided and no publisher private key`);
248
+ } else {
249
+ publisherHdAccount = mnemonicToAccount(MNEMONIC, {
250
+ addressIndex: 0
251
+ });
252
+ const publisherPrivKeyRaw = publisherHdAccount.getHdKey().privateKey;
253
+ const publisherPrivKey = publisherPrivKeyRaw === null ? null : Buffer.from(publisherPrivKeyRaw);
254
+ publisherPrivKeyHex = `0x${publisherPrivKey.toString('hex')}`;
255
+ config.publisherPrivateKeys = [
256
+ new SecretValue(publisherPrivKeyHex)
257
+ ];
258
+ }
259
+ if (config.coinbase === undefined) {
260
+ config.coinbase = EthAddress.fromString(publisherHdAccount.address);
261
+ }
262
+ if (AZTEC_NODE_URL) {
263
+ // we are setting up against a remote environment, l1 contracts are assumed to already be deployed
264
+ return await setupWithRemoteEnvironment(publisherHdAccount, config, logger, numberOfAccounts);
265
+ }
266
+ const initialFundedAccounts = opts.initialFundedAccounts ?? await generateSchnorrAccounts(opts.numberOfInitialFundedAccounts ?? numberOfAccounts);
267
+ const { genesisArchiveRoot, prefilledPublicData, fundingNeeded } = await getGenesisValues(initialFundedAccounts.map((a)=>a.address), opts.initialAccountFeeJuice, opts.genesisPublicData);
268
+ const wasAutomining = await ethCheatCodes.isAutoMining();
269
+ const enableAutomine = opts.automineL1Setup && !wasAutomining && isAnvilTestChain(chain.id);
270
+ if (enableAutomine) {
271
+ await ethCheatCodes.setAutomine(true);
272
+ }
273
+ const l1Client = createExtendedL1Client(config.l1RpcUrls, publisherHdAccount, chain);
274
+ const deployL1ContractsValues = await deployAztecL1Contracts(config.l1RpcUrls[0], publisherPrivKeyHex, chain.id, {
275
+ ...getL1ContractsConfigEnvVars(),
276
+ ...opts,
277
+ vkTreeRoot: getVKTreeRoot(),
278
+ protocolContractsHash,
279
+ genesisArchiveRoot,
280
+ initialValidators: opts.initialValidators,
281
+ feeJuicePortalInitialBalance: fundingNeeded,
282
+ realVerifier: false
277
283
  });
278
- const rewardDistributorMintTxHash = await feeJuice.write.mint([
279
- rewardDistributor.address,
280
- mintAmount
281
- ], {});
282
- await deployL1ContractsValues.publicClient.waitForTransactionReceipt({
283
- hash: rewardDistributorMintTxHash
284
+ config.l1Contracts = deployL1ContractsValues.l1ContractAddresses;
285
+ config.rollupVersion = deployL1ContractsValues.rollupVersion;
286
+ if (enableAutomine) {
287
+ await ethCheatCodes.setAutomine(false);
288
+ await ethCheatCodes.setIntervalMining(config.ethereumSlotDuration);
289
+ dateProvider.setTime(await ethCheatCodes.timestamp() * 1000);
290
+ }
291
+ if (opts.l2StartTime) {
292
+ // This should only be used in synching test or when you need to have a stable
293
+ // timestamp for the first l2 block.
294
+ await ethCheatCodes.warp(opts.l2StartTime, {
295
+ resetBlockInterval: true
296
+ });
297
+ }
298
+ const watcher = new AnvilTestWatcher(new EthCheatCodesWithState(config.l1RpcUrls, dateProvider), deployL1ContractsValues.l1ContractAddresses.rollupAddress, deployL1ContractsValues.l1Client, dateProvider);
299
+ if (!opts.disableAnvilTestWatcher) {
300
+ await watcher.start();
301
+ }
302
+ const telemetry = await getTelemetryClient(opts.telemetryConfig);
303
+ await setupSharedBlobStorage(config);
304
+ logger.verbose('Creating and synching an aztec node', config);
305
+ const acvmConfig = await getACVMConfig(logger);
306
+ if (acvmConfig) {
307
+ config.acvmWorkingDirectory = acvmConfig.acvmWorkingDirectory;
308
+ config.acvmBinaryPath = acvmConfig.acvmBinaryPath;
309
+ }
310
+ const bbConfig = await getBBConfig(logger);
311
+ if (bbConfig) {
312
+ config.bbBinaryPath = bbConfig.bbBinaryPath;
313
+ config.bbWorkingDirectory = bbConfig.bbWorkingDirectory;
314
+ }
315
+ let mockGossipSubNetwork;
316
+ let p2pClientDeps = undefined;
317
+ if (opts.mockGossipSubNetwork) {
318
+ mockGossipSubNetwork = new MockGossipSubNetwork();
319
+ p2pClientDeps = {
320
+ p2pServiceFactory: getMockPubSubP2PServiceFactory(mockGossipSubNetwork)
321
+ };
322
+ }
323
+ // Transactions built against the genesis state must be included in block 1, otherwise they are dropped.
324
+ // To avoid test failures from dropped transactions, we ensure progression beyond genesis before proceeding.
325
+ // For account deployments, we set minTxsPerBlock=1 and deploy accounts sequentially for guaranteed success.
326
+ // If no accounts need deployment, we await an empty block to confirm network progression. After either path
327
+ // completes, we restore the original minTxsPerBlock setting. The deployment and waiting for empty block is
328
+ // handled by the if-else branches on line 632.
329
+ // For more details on why the tx would be dropped see `validate_include_by_timestamp` function in
330
+ // `noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/validation_requests.nr`.
331
+ //
332
+ // Note: If the following seems too convoluted or if it starts making problems, we could drop the "progressing
333
+ // past genesis via an account contract deployment" optimization and just call flush() on the sequencer and wait
334
+ // for an empty block to be mined. This would simplify it all quite a bit but the setup would be slower for tests
335
+ // deploying accounts.
336
+ const originalMinTxsPerBlock = config.minTxsPerBlock;
337
+ if (originalMinTxsPerBlock === undefined) {
338
+ throw new Error('minTxsPerBlock is undefined in e2e test setup');
339
+ }
340
+ config.minTxsPerBlock = numberOfAccounts === 0 ? 0 : 1;
341
+ config.p2pEnabled = opts.mockGossipSubNetwork || config.p2pEnabled;
342
+ config.p2pIp = opts.p2pIp ?? config.p2pIp ?? '127.0.0.1';
343
+ if (!config.disableValidator) {
344
+ if ((config.validatorPrivateKeys?.getValue().length ?? 0) === 0) {
345
+ config.validatorPrivateKeys = new SecretValue([
346
+ generatePrivateKey()
347
+ ]);
348
+ }
349
+ }
350
+ const aztecNode = await AztecNodeService.createAndSync(config, {
351
+ dateProvider,
352
+ telemetry,
353
+ p2pClientDeps,
354
+ logger: createLogger('node:MAIN-aztec-node')
355
+ }, {
356
+ prefilledPublicData
284
357
  });
285
- logger.info(`Funding rewardDistributor in ${rewardDistributorMintTxHash}`);
286
- }
287
- if (opts.l2StartTime) {
288
- // This should only be used in synching test or when you need to have a stable
289
- // timestamp for the first l2 block.
290
- await ethCheatCodes.warp(opts.l2StartTime);
291
- }
292
- const dateProvider = new TestDateProvider();
293
- const watcher = new AnvilTestWatcher(new EthCheatCodesWithState(config.l1RpcUrls), deployL1ContractsValues.l1ContractAddresses.rollupAddress, deployL1ContractsValues.publicClient, dateProvider);
294
- await watcher.start();
295
- logger.verbose('Creating and synching an aztec node...');
296
- const acvmConfig = await getACVMConfig(logger);
297
- if (acvmConfig) {
298
- config.acvmWorkingDirectory = acvmConfig.acvmWorkingDirectory;
299
- config.acvmBinaryPath = acvmConfig.acvmBinaryPath;
300
- }
301
- const bbConfig = await getBBConfig(logger);
302
- if (bbConfig) {
303
- config.bbBinaryPath = bbConfig.bbBinaryPath;
304
- config.bbWorkingDirectory = bbConfig.bbWorkingDirectory;
305
- }
306
- config.l1PublishRetryIntervalMS = 100;
307
- const telemetry = getTelemetryClient(opts.telemetryConfig);
308
- const blobSinkClient = createBlobSinkClient(config);
309
- const aztecNode = await AztecNodeService.createAndSync(config, {
310
- dateProvider,
311
- blobSinkClient
312
- }, {
313
- prefilledPublicData
314
- });
315
- const sequencer = aztecNode.getSequencer();
316
- if (sequencer) {
317
- const publisher = sequencer.sequencer.publisher;
318
- publisher.l1TxUtils = DelayedTxUtils.fromL1TxUtils(publisher.l1TxUtils, config.ethereumSlotDuration);
319
- }
320
- let proverNode = undefined;
321
- if (opts.startProverNode) {
322
- logger.verbose('Creating and syncing a simulated prover node...');
323
- const proverNodePrivateKey = getPrivateKeyFromIndex(2);
324
- const proverNodePrivateKeyHex = `0x${proverNodePrivateKey.toString('hex')}`;
325
- proverNode = await createAndSyncProverNode(proverNodePrivateKeyHex, config, aztecNode, path.join(directoryToCleanup, randomBytes(8).toString('hex')));
326
- }
327
- logger.verbose('Creating a pxe...');
328
- const { pxe, teardown: pxeTeardown } = await setupPXEService(aztecNode, pxeOpts, logger);
329
- if (!config.skipProtocolContracts) {
330
- logger.verbose('Setting up Fee Juice...');
331
- await setupCanonicalFeeJuice(pxe);
332
- }
333
- const accountManagers = await deployFundedSchnorrAccounts(pxe, initialFundedAccounts.slice(0, numberOfAccounts));
334
- const wallets = await Promise.all(accountManagers.map((account)=>account.getWallet()));
335
- if (initialFundedAccounts.length < numberOfAccounts) {
336
- // TODO: Create (numberOfAccounts - initialFundedAccounts.length) wallets without funds.
337
- throw new Error(`Unable to deploy ${numberOfAccounts} accounts. Only ${initialFundedAccounts.length} accounts were funded.`);
338
- }
339
- const cheatCodes = await CheatCodes.create(config.l1RpcUrls, pxe);
340
- const teardown = async ()=>{
341
- await pxeTeardown();
342
- if (aztecNode instanceof AztecNodeService) {
343
- await aztecNode?.stop();
358
+ const sequencerClient = aztecNode.getSequencer();
359
+ if (sequencerClient) {
360
+ const publisher = sequencerClient.sequencer.publisher;
361
+ publisher.l1TxUtils = DelayedTxUtils.fromL1TxUtils(publisher.l1TxUtils, config.ethereumSlotDuration, l1Client);
362
+ }
363
+ let proverNode = undefined;
364
+ if (opts.startProverNode) {
365
+ logger.verbose('Creating and syncing a simulated prover node...');
366
+ const proverNodePrivateKey = getPrivateKeyFromIndex(2);
367
+ const proverNodePrivateKeyHex = `0x${proverNodePrivateKey.toString('hex')}`;
368
+ const proverNodeDataDirectory = path.join(directoryToCleanup, randomBytes(8).toString('hex'));
369
+ const proverNodeConfig = {
370
+ ...config.proverNodeConfig,
371
+ dataDirectory: proverNodeDataDirectory
372
+ };
373
+ proverNode = await createAndSyncProverNode(proverNodePrivateKeyHex, config, proverNodeConfig, aztecNode, prefilledPublicData);
344
374
  }
345
- if (proverNode) {
346
- await proverNode.stop();
375
+ logger.verbose('Creating a pxe...');
376
+ const { wallet, teardown: pxeTeardown } = await setupPXEAndGetWallet(aztecNode, pxeOpts, logger);
377
+ const cheatCodes = await CheatCodes.create(config.l1RpcUrls, aztecNode, dateProvider);
378
+ if (opts.aztecTargetCommitteeSize && opts.aztecTargetCommitteeSize > 0 || opts.initialValidators && opts.initialValidators.length > 0) {
379
+ // We need to advance such that the committee is set up.
380
+ await cheatCodes.rollup.advanceToEpoch(EpochNumber.fromBigInt(BigInt(await cheatCodes.rollup.getEpoch()) + BigInt(config.lagInEpochsForValidatorSet + 1)));
381
+ await cheatCodes.rollup.setupEpoch();
382
+ await cheatCodes.rollup.debugRollup();
347
383
  }
348
- if (acvmConfig?.cleanup) {
349
- // remove the temp directory created for the acvm
350
- logger.verbose(`Cleaning up ACVM state`);
351
- await acvmConfig.cleanup();
384
+ let accounts = [];
385
+ // Below we continue with what we described in the long comment on line 571.
386
+ if (numberOfAccounts === 0) {
387
+ logger.info('No accounts are being deployed, waiting for an empty block 1 to be mined');
388
+ while(await aztecNode.getBlockNumber() === 0){
389
+ await sleep(2000);
390
+ }
391
+ } else {
392
+ logger.info(`${numberOfAccounts} accounts are being deployed. Reliably progressing past genesis by setting minTxsPerBlock to 1 and waiting for the accounts to be deployed`);
393
+ const accountsData = initialFundedAccounts.slice(0, numberOfAccounts);
394
+ const accountManagers = await deployFundedSchnorrAccounts(wallet, aztecNode, accountsData);
395
+ accounts = accountManagers.map((accountManager)=>accountManager.address);
352
396
  }
353
- if (bbConfig?.cleanup) {
354
- // remove the temp directory created for the acvm
355
- logger.verbose(`Cleaning up BB state`);
356
- await bbConfig.cleanup();
397
+ // Now we restore the original minTxsPerBlock setting.
398
+ sequencerClient.getSequencer().updateConfig({
399
+ minTxsPerBlock: originalMinTxsPerBlock
400
+ });
401
+ if (initialFundedAccounts.length < numberOfAccounts) {
402
+ // TODO: Create (numberOfAccounts - initialFundedAccounts.length) wallets without funds.
403
+ throw new Error(`Unable to deploy ${numberOfAccounts} accounts. Only ${initialFundedAccounts.length} accounts were funded.`);
357
404
  }
358
- await anvil?.stop().catch((err)=>getLogger().error(err));
359
- await watcher.stop();
360
- await blobSink?.stop();
361
- if (directoryToCleanup) {
405
+ const teardown = async ()=>{
362
406
  try {
363
- logger.verbose(`Cleaning up data directory at ${directoryToCleanup}`);
364
- await fs.rm(directoryToCleanup, {
365
- recursive: true,
366
- force: true,
367
- maxRetries: 3
368
- });
407
+ await pxeTeardown();
408
+ await tryStop(aztecNode, logger);
409
+ await tryStop(proverNode, logger);
410
+ if (acvmConfig?.cleanup) {
411
+ await acvmConfig.cleanup();
412
+ }
413
+ if (bbConfig?.cleanup) {
414
+ await bbConfig.cleanup();
415
+ }
416
+ await tryStop(watcher, logger);
417
+ await tryStop(anvil, logger);
418
+ await tryRmDir(directoryToCleanup, logger);
369
419
  } catch (err) {
370
- logger.warn(`Failed to delete data directory at ${directoryToCleanup}: ${err}`);
420
+ logger.error(`Error during e2e test teardown`, err);
371
421
  }
372
- }
373
- };
374
- return {
375
- aztecNode,
376
- blobSink,
377
- cheatCodes,
378
- config,
379
- dateProvider,
380
- deployL1ContractsValues,
381
- initialFundedAccounts,
382
- logger,
383
- proverNode,
384
- pxe,
385
- sequencer,
386
- teardown,
387
- telemetryClient: telemetry,
388
- wallet: wallets[0],
389
- wallets,
390
- watcher
391
- };
422
+ };
423
+ return {
424
+ aztecNode,
425
+ aztecNodeAdmin: aztecNode,
426
+ cheatCodes,
427
+ ethCheatCodes,
428
+ config,
429
+ dateProvider,
430
+ deployL1ContractsValues,
431
+ initialFundedAccounts,
432
+ logger,
433
+ mockGossipSubNetwork,
434
+ prefilledPublicData,
435
+ proverNode,
436
+ sequencer: sequencerClient,
437
+ teardown,
438
+ telemetryClient: telemetry,
439
+ wallet,
440
+ accounts,
441
+ watcher
442
+ };
443
+ } catch (err) {
444
+ // TODO: Just hoisted anvil for now to ensure cleanup. Prob need to hoist the rest.
445
+ await anvil?.stop();
446
+ throw err;
447
+ }
392
448
  }
393
449
  /**
394
450
  * Registers the contract class used for test accounts and publicly deploys the instances requested.
395
451
  * Use this when you need to make a public call to an account contract, such as for requesting a public authwit.
396
452
  * @param sender - Wallet to send the deployment tx.
397
453
  * @param accountsToDeploy - Which accounts to publicly deploy.
398
- */ // docs:start:public_deploy_accounts
399
- export async function ensureAccountsPubliclyDeployed(sender, accountsToDeploy) {
454
+ */ export async function ensureAccountContractsPublished(wallet, accountsToDeploy) {
400
455
  // We have to check whether the accounts are already deployed. This can happen if the test runs against
401
- // the sandbox and the test accounts exist
402
- const accountsAndAddresses = await Promise.all(accountsToDeploy.map(async (account)=>{
403
- const address = account.getAddress();
456
+ // the local network and the test accounts exist
457
+ const accountsAndAddresses = await Promise.all(accountsToDeploy.map(async (address)=>{
404
458
  return {
405
459
  address,
406
- deployed: (await sender.getContractMetadata(address)).isContractPubliclyDeployed
460
+ deployed: (await wallet.getContractMetadata(address)).isContractPublished
407
461
  };
408
462
  }));
409
- const instances = (await Promise.all(accountsAndAddresses.filter(({ deployed })=>!deployed).map(({ address })=>sender.getContractMetadata(address)))).map((contractMetadata)=>contractMetadata.contractInstance);
463
+ const instances = (await Promise.all(accountsAndAddresses.filter(({ deployed })=>!deployed).map(({ address })=>wallet.getContractMetadata(address)))).map((contractMetadata)=>contractMetadata.contractInstance);
410
464
  const contractClass = await getContractClassFromArtifact(SchnorrAccountContractArtifact);
411
- if (!(await sender.getContractClassMetadata(contractClass.id, true)).isContractClassPubliclyRegistered) {
412
- await (await registerContractClass(sender, SchnorrAccountContractArtifact)).send().wait();
465
+ if (!(await wallet.getContractClassMetadata(contractClass.id, true)).isContractClassPubliclyRegistered) {
466
+ await (await publishContractClass(wallet, SchnorrAccountContractArtifact)).send({
467
+ from: accountsToDeploy[0]
468
+ }).wait();
413
469
  }
414
- const requests = await Promise.all(instances.map(async (instance)=>(await deployInstance(sender, instance)).request()));
415
- const batch = new BatchCall(sender, [
416
- ...requests
417
- ]);
418
- await batch.send().wait();
419
- }
420
- // docs:end:public_deploy_accounts
421
- /**
422
- * Sets the timestamp of the next block.
423
- * @param rpcUrl - rpc url of the blockchain instance to connect to
424
- * @param timestamp - the timestamp for the next block
425
- */ export async function setNextBlockTimestamp(rpcUrl, timestamp) {
426
- const params = `[${timestamp}]`;
427
- await fetch(rpcUrl, {
428
- body: `{"jsonrpc":"2.0", "method": "evm_setNextBlockTimestamp", "params": ${params}, "id": 1}`,
429
- method: 'POST',
430
- headers: {
431
- 'Content-Type': 'application/json'
432
- }
433
- });
470
+ const requests = await Promise.all(instances.map(async (instance)=>await publishInstance(wallet, instance)));
471
+ const batch = new BatchCall(wallet, requests);
472
+ await batch.send({
473
+ from: accountsToDeploy[0]
474
+ }).wait();
434
475
  }
435
476
  /** Returns the job name for the current test. */ function getJobName() {
436
477
  return process.env.JOB_NAME ?? expect.getState().currentTestName?.split(' ')[0].replaceAll('/', '_') ?? 'unknown';
@@ -446,10 +487,12 @@ export async function ensureAccountsPubliclyDeployed(sender, accountsToDeploy) {
446
487
  }
447
488
  return createLogger('e2e:' + describeBlockName);
448
489
  }
449
- export function getBalancesFn(symbol, method, logger) {
490
+ export function getBalancesFn(symbol, method, from, logger) {
450
491
  const balances = async (...addressLikes)=>{
451
492
  const addresses = addressLikes.map((addressLike)=>'address' in addressLike ? addressLike.address : addressLike);
452
- const b = await Promise.all(addresses.map((address)=>method(address).simulate()));
493
+ const b = await Promise.all(addresses.map((address)=>method(address).simulate({
494
+ from
495
+ })));
453
496
  const debugString = `${symbol} balances: ${addresses.map((address, i)=>`${address}: ${b[i]}`).join(', ')}`;
454
497
  logger.verbose(debugString);
455
498
  return b;
@@ -468,86 +511,106 @@ export async function expectMappingDelta(initialValues, fn, inputs, expectedDiff
468
511
  expect(diffs).toEqual(expectedDiffs);
469
512
  }
470
513
  /**
471
- * Deploy the protocol contracts to a running instance.
472
- */ export async function setupCanonicalFeeJuice(pxe) {
473
- // "deploy" the Fee Juice as it contains public functions
474
- const feeJuicePortalAddress = (await pxe.getNodeInfo()).l1ContractAddresses.feeJuicePortalAddress;
475
- const wallet = new SignerlessWallet(pxe);
476
- const feeJuice = await FeeJuiceContract.at(ProtocolContractAddress.FeeJuice, wallet);
477
- try {
478
- const paymentMethod = new FeeJuicePaymentMethod(ProtocolContractAddress.FeeJuice);
479
- await feeJuice.methods.initialize(feeJuicePortalAddress, FEE_JUICE_INITIAL_MINT).send({
480
- fee: {
481
- paymentMethod,
482
- gasSettings: {
483
- teardownGasLimits: Gas.empty()
484
- }
485
- }
486
- }).wait();
487
- getLogger().info(`Fee Juice successfully setup. Portal address: ${feeJuicePortalAddress}`);
488
- } catch (error) {
489
- getLogger().warn(`Fee Juice might have already been setup. Got error: ${inspect(error)}.`);
490
- }
514
+ * Computes the address of the "canonical" SponsoredFPCContract. This is not a protocol contract
515
+ * but by conventions its address is computed with a salt of 0.
516
+ * @returns The address of the sponsored FPC contract
517
+ */ export function getSponsoredFPCInstance() {
518
+ return Promise.resolve(getContractInstanceFromInstantiationParams(SponsoredFPCContract.artifact, {
519
+ salt: new Fr(SPONSORED_FPC_SALT)
520
+ }));
521
+ }
522
+ /**
523
+ * Computes the address of the "canonical" SponsoredFPCContract. This is not a protocol contract
524
+ * but by conventions its address is computed with a salt of 0.
525
+ * @returns The address of the sponsored FPC contract
526
+ */ export async function getSponsoredFPCAddress() {
527
+ const sponsoredFPCInstance = await getSponsoredFPCInstance();
528
+ return sponsoredFPCInstance.address;
529
+ }
530
+ /**
531
+ * Deploy a sponsored FPC contract to a running instance.
532
+ */ export async function setupSponsoredFPC(wallet) {
533
+ const instance = await getContractInstanceFromInstantiationParams(SponsoredFPCContract.artifact, {
534
+ salt: new Fr(SPONSORED_FPC_SALT)
535
+ });
536
+ await wallet.registerContract(instance, SponsoredFPCContract.artifact);
537
+ getLogger().info(`SponsoredFPC: ${instance.address}`);
538
+ return instance;
539
+ }
540
+ /**
541
+ * Registers the SponsoredFPC in this PXE instance
542
+ * @param wallet - The wallet
543
+ */ export async function registerSponsoredFPC(wallet) {
544
+ await wallet.registerContract(await getSponsoredFPCInstance(), SponsoredFPCContract.artifact);
491
545
  }
492
546
  export async function waitForProvenChain(node, targetBlock, timeoutSec = 60, intervalSec = 1) {
493
547
  targetBlock ??= await node.getBlockNumber();
494
548
  await retryUntil(async ()=>await node.getProvenBlockNumber() >= targetBlock, 'proven chain status', timeoutSec, intervalSec);
495
549
  }
496
- export async function createAndSyncProverNode(proverNodePrivateKey, aztecNodeConfig, aztecNode, dataDirectory, prefilledPublicData = []) {
497
- // Disable stopping the aztec node as the prover coordination test will kill it otherwise
498
- // This is only required when stopping the prover node for testing
499
- const aztecNodeWithoutStop = {
500
- getTxByHash: aztecNode.getTxByHash.bind(aztecNode),
501
- getTxsByHash: aztecNode.getTxsByHash.bind(aztecNode),
502
- stop: ()=>Promise.resolve()
503
- };
504
- const blobSinkClient = createBlobSinkClient(aztecNodeConfig);
505
- // Creating temp store and archiver for simulated prover node
506
- const archiverConfig = {
507
- ...aztecNodeConfig,
508
- dataDirectory
509
- };
510
- const archiver = await createArchiver(archiverConfig, blobSinkClient, {
511
- blockUntilSync: true
512
- });
513
- // Prover node config is for simulated proofs
514
- const proverConfig = {
515
- ...aztecNodeConfig,
516
- proverCoordinationNodeUrl: undefined,
517
- dataDirectory: undefined,
518
- realProofs: false,
519
- proverAgentCount: 2,
520
- publisherPrivateKey: proverNodePrivateKey,
521
- proverNodeMaxPendingJobs: 10,
522
- proverNodeMaxParallelBlocksPerEpoch: 32,
523
- proverNodePollingIntervalMs: 200,
524
- txGatheringTimeoutMs: 60000,
525
- txGatheringIntervalMs: 1000,
526
- txGatheringMaxParallelRequests: 100
527
- };
528
- const l1TxUtils = createDelayedL1TxUtils(aztecNodeConfig, proverNodePrivateKey, 'prover-node');
529
- const proverNode = await createProverNode(proverConfig, {
530
- aztecNodeTxProvider: aztecNodeWithoutStop,
531
- archiver: archiver,
532
- l1TxUtils
533
- }, {
534
- prefilledPublicData
535
- });
536
- getLogger().info(`Created and synced prover node`, {
537
- publisherAddress: l1TxUtils.walletClient.account.address
550
+ export function createAndSyncProverNode(proverNodePrivateKey, aztecNodeConfig, proverNodeConfig, aztecNode, prefilledPublicData = [], proverNodeDeps = {}) {
551
+ return withLogNameSuffix('prover-node', async ()=>{
552
+ // Disable stopping the aztec node as the prover coordination test will kill it otherwise
553
+ // This is only required when stopping the prover node for testing
554
+ const aztecNodeTxProvider = aztecNode && {
555
+ getTxByHash: aztecNode.getTxByHash.bind(aztecNode),
556
+ getTxsByHash: aztecNode.getTxsByHash.bind(aztecNode),
557
+ stop: ()=>Promise.resolve()
558
+ };
559
+ const blobClient = await createBlobClientWithFileStores(aztecNodeConfig, createLogger('blob-client:prover-node'));
560
+ // Creating temp store and archiver for simulated prover node
561
+ const archiverConfig = {
562
+ ...aztecNodeConfig,
563
+ dataDirectory: proverNodeConfig.dataDirectory
564
+ };
565
+ const archiver = await createArchiver(archiverConfig, {
566
+ blobClient,
567
+ dateProvider: proverNodeDeps.dateProvider
568
+ }, {
569
+ blockUntilSync: true
570
+ });
571
+ // Prover node config is for simulated proofs
572
+ const proverConfig = {
573
+ ...aztecNodeConfig,
574
+ txCollectionNodeRpcUrls: [],
575
+ realProofs: false,
576
+ proverAgentCount: 2,
577
+ publisherPrivateKeys: [
578
+ new SecretValue(proverNodePrivateKey)
579
+ ],
580
+ proverNodeMaxPendingJobs: 10,
581
+ proverNodeMaxParallelBlocksPerEpoch: 32,
582
+ proverNodePollingIntervalMs: 200,
583
+ txGatheringIntervalMs: 1000,
584
+ txGatheringBatchSize: 10,
585
+ txGatheringMaxParallelRequestsPerNode: 10,
586
+ txGatheringTimeoutMs: 24_000,
587
+ proverNodeFailedEpochStore: undefined,
588
+ proverId: EthAddress.fromNumber(1),
589
+ proverNodeEpochProvingDelayMs: undefined,
590
+ ...proverNodeConfig
591
+ };
592
+ const l1TxUtils = createDelayedL1TxUtils(aztecNodeConfig, proverNodePrivateKey, 'prover-node', proverNodeDeps.dateProvider);
593
+ const proverNode = await createProverNode(proverConfig, {
594
+ ...proverNodeDeps,
595
+ aztecNodeTxProvider,
596
+ archiver: archiver,
597
+ l1TxUtils
598
+ }, {
599
+ prefilledPublicData
600
+ });
601
+ getLogger().info(`Created and synced prover node`, {
602
+ publisherAddress: l1TxUtils.client.account.address
603
+ });
604
+ if (!proverNodeConfig.dontStart) {
605
+ await proverNode.start();
606
+ }
607
+ return proverNode;
538
608
  });
539
- proverNode.start();
540
- return proverNode;
541
609
  }
542
- function createDelayedL1TxUtils(aztecNodeConfig, privateKey, logName) {
543
- const { publicClient, walletClient } = createL1Clients(aztecNodeConfig.l1RpcUrls, privateKey, foundry);
610
+ function createDelayedL1TxUtils(aztecNodeConfig, privateKey, logName, dateProvider) {
611
+ const l1Client = createExtendedL1Client(aztecNodeConfig.l1RpcUrls, privateKey, foundry);
544
612
  const log = createLogger(logName);
545
- const l1TxUtils = new DelayedTxUtils(publicClient, walletClient, log, aztecNodeConfig);
613
+ const l1TxUtils = createDelayedL1TxUtilsFromViemWallet(l1Client, log, dateProvider, aztecNodeConfig);
546
614
  l1TxUtils.enableDelayer(aztecNodeConfig.ethereumSlotDuration);
547
615
  return l1TxUtils;
548
616
  }
549
- export async function createForwarderContract(aztecNodeConfig, privateKey, rollupAddress) {
550
- const { walletClient, publicClient } = createL1Clients(aztecNodeConfig.l1RpcUrls, privateKey, foundry);
551
- const forwarderContract = await ForwarderContract.create(walletClient.account.address, walletClient, publicClient, createLogger('forwarder'), rollupAddress);
552
- return forwarderContract;
553
- }