@aztec/end-to-end 0.0.0-test.1 → 0.0.1-fake-ceab37513c

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 (156) hide show
  1. package/dest/bench/client_flows/benchmark.d.ts +60 -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 +69 -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 +315 -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 +99 -0
  13. package/dest/bench/utils.d.ts +10 -27
  14. package/dest/bench/utils.d.ts.map +1 -1
  15. package/dest/bench/utils.js +27 -43
  16. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +15 -7
  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 +66 -38
  19. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +10 -18
  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 +34 -53
  22. package/dest/e2e_deploy_contract/deploy_test.d.ts +4 -2
  23. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  24. package/dest/e2e_deploy_contract/deploy_test.js +9 -6
  25. package/dest/e2e_epochs/epochs_test.d.ts +56 -17
  26. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  27. package/dest/e2e_epochs/epochs_test.js +222 -42
  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 +60 -0
  31. package/dest/e2e_fees/fees_test.d.ts +16 -5
  32. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  33. package/dest/e2e_fees/fees_test.js +87 -88
  34. package/dest/e2e_l1_publisher/write_json.d.ts +8 -0
  35. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
  36. package/dest/e2e_l1_publisher/write_json.js +57 -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 +5 -5
  41. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  42. package/dest/e2e_nested_contract/nested_contract_test.js +19 -14
  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 +132 -0
  46. package/dest/e2e_p2p/p2p_network.d.ts +56 -21
  47. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  48. package/dest/e2e_p2p/p2p_network.js +154 -125
  49. package/dest/e2e_p2p/shared.d.ts +41 -3
  50. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  51. package/dest/e2e_p2p/shared.js +146 -6
  52. package/dest/e2e_token_contract/token_contract_test.d.ts +10 -5
  53. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  54. package/dest/e2e_token_contract/token_contract_test.js +51 -24
  55. package/dest/{e2e_prover → fixtures}/e2e_prover_test.d.ts +7 -4
  56. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
  57. package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +67 -62
  58. package/dest/fixtures/fixtures.d.ts +5 -6
  59. package/dest/fixtures/fixtures.d.ts.map +1 -1
  60. package/dest/fixtures/fixtures.js +4 -3
  61. package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
  62. package/dest/fixtures/get_acvm_config.js +2 -14
  63. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  64. package/dest/fixtures/get_bb_config.js +8 -15
  65. package/dest/fixtures/l1_to_l2_messaging.d.ts +8 -5
  66. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  67. package/dest/fixtures/l1_to_l2_messaging.js +44 -18
  68. package/dest/fixtures/setup_l1_contracts.d.ts +3 -3
  69. package/dest/fixtures/setup_l1_contracts.d.ts.map +1 -1
  70. package/dest/fixtures/setup_l1_contracts.js +3 -3
  71. package/dest/fixtures/setup_p2p_test.d.ts +14 -6
  72. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  73. package/dest/fixtures/setup_p2p_test.js +73 -21
  74. package/dest/fixtures/snapshot_manager.d.ts +8 -3
  75. package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
  76. package/dest/fixtures/snapshot_manager.js +120 -104
  77. package/dest/fixtures/token_utils.d.ts +4 -3
  78. package/dest/fixtures/token_utils.d.ts.map +1 -1
  79. package/dest/fixtures/token_utils.js +24 -7
  80. package/dest/fixtures/utils.d.ts +65 -22
  81. package/dest/fixtures/utils.d.ts.map +1 -1
  82. package/dest/fixtures/utils.js +439 -318
  83. package/dest/fixtures/web3signer.d.ts +5 -0
  84. package/dest/fixtures/web3signer.d.ts.map +1 -0
  85. package/dest/fixtures/web3signer.js +42 -0
  86. package/dest/shared/cross_chain_test_harness.d.ts +28 -18
  87. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  88. package/dest/shared/cross_chain_test_harness.js +97 -41
  89. package/dest/shared/gas_portal_test_harness.d.ts +23 -18
  90. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  91. package/dest/shared/gas_portal_test_harness.js +43 -25
  92. package/dest/shared/submit-transactions.d.ts.map +1 -1
  93. package/dest/shared/uniswap_l1_l2.d.ts +5 -6
  94. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  95. package/dest/shared/uniswap_l1_l2.js +136 -90
  96. package/dest/simulators/lending_simulator.d.ts +5 -6
  97. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  98. package/dest/simulators/lending_simulator.js +11 -15
  99. package/dest/simulators/token_simulator.d.ts +2 -1
  100. package/dest/simulators/token_simulator.d.ts.map +1 -1
  101. package/dest/simulators/token_simulator.js +16 -13
  102. package/dest/spartan/setup_test_wallets.d.ts +8 -1
  103. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  104. package/dest/spartan/setup_test_wallets.js +108 -22
  105. package/dest/spartan/utils.d.ts +60 -307
  106. package/dest/spartan/utils.d.ts.map +1 -1
  107. package/dest/spartan/utils.js +200 -115
  108. package/package.json +60 -56
  109. package/src/bench/client_flows/benchmark.ts +341 -0
  110. package/src/bench/client_flows/client_flows_benchmark.ts +422 -0
  111. package/src/bench/client_flows/config.ts +61 -0
  112. package/src/bench/client_flows/data_extractor.ts +111 -0
  113. package/src/bench/utils.ts +26 -52
  114. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +60 -40
  115. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +47 -75
  116. package/src/e2e_deploy_contract/deploy_test.ts +11 -8
  117. package/src/e2e_epochs/epochs_test.ts +276 -54
  118. package/src/e2e_fees/bridging_race.notest.ts +75 -0
  119. package/src/e2e_fees/fees_test.ts +121 -108
  120. package/src/e2e_l1_publisher/write_json.ts +74 -0
  121. package/src/e2e_multi_validator/utils.ts +258 -0
  122. package/src/e2e_nested_contract/nested_contract_test.ts +22 -14
  123. package/src/e2e_p2p/inactivity_slash_test.ts +174 -0
  124. package/src/e2e_p2p/p2p_network.ts +212 -144
  125. package/src/e2e_p2p/shared.ts +234 -14
  126. package/src/e2e_token_contract/token_contract_test.ts +42 -38
  127. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  128. package/src/{e2e_prover → fixtures}/e2e_prover_test.ts +62 -69
  129. package/src/fixtures/fixtures.ts +4 -3
  130. package/src/fixtures/get_acvm_config.ts +2 -10
  131. package/src/fixtures/get_bb_config.ts +15 -11
  132. package/src/fixtures/l1_to_l2_messaging.ts +53 -23
  133. package/src/fixtures/setup_l1_contracts.ts +5 -6
  134. package/src/fixtures/setup_p2p_test.ts +112 -30
  135. package/src/fixtures/snapshot_manager.ts +150 -102
  136. package/src/fixtures/token_utils.ts +33 -8
  137. package/src/fixtures/utils.ts +530 -352
  138. package/src/fixtures/web3signer.ts +46 -0
  139. package/src/guides/up_quick_start.sh +4 -4
  140. package/src/shared/cross_chain_test_harness.ts +92 -52
  141. package/src/shared/gas_portal_test_harness.ts +47 -31
  142. package/src/shared/uniswap_l1_l2.ts +127 -124
  143. package/src/simulators/lending_simulator.ts +11 -15
  144. package/src/simulators/token_simulator.ts +17 -12
  145. package/src/spartan/DEVELOP.md +116 -0
  146. package/src/spartan/setup_test_wallets.ts +144 -29
  147. package/src/spartan/utils.ts +194 -116
  148. package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
  149. package/dest/sample-dapp/connect.js +0 -12
  150. package/dest/sample-dapp/contracts.js +0 -10
  151. package/dest/sample-dapp/deploy.js +0 -35
  152. package/dest/sample-dapp/index.js +0 -98
  153. package/src/sample-dapp/connect.mjs +0 -16
  154. package/src/sample-dapp/contracts.mjs +0 -14
  155. package/src/sample-dapp/deploy.mjs +0 -40
  156. package/src/sample-dapp/index.mjs +0 -128
@@ -3,8 +3,11 @@
3
3
  */
4
4
  import { type AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
5
5
  import type { SentTx } from '@aztec/aztec.js';
6
+ import { SecretValue } from '@aztec/foundation/config';
6
7
  import { addLogNameHandler, removeLogNameHandler } from '@aztec/foundation/log';
8
+ import { bufferToHex } from '@aztec/foundation/string';
7
9
  import type { DateProvider } from '@aztec/foundation/timer';
10
+ import type { ProverNodeConfig, ProverNodeDeps } from '@aztec/prover-node';
8
11
  import type { PXEService } from '@aztec/pxe/server';
9
12
  import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
10
13
 
@@ -12,13 +15,13 @@ import getPort from 'get-port';
12
15
  import { AsyncLocalStorage } from 'node:async_hooks';
13
16
 
14
17
  import { TEST_PEER_CHECK_INTERVAL_MS } from './fixtures.js';
15
- import { getPrivateKeyFromIndex } from './utils.js';
18
+ import { createAndSyncProverNode, getPrivateKeyFromIndex } from './utils.js';
16
19
  import { getEndToEndTestTelemetryClient } from './with_telemetry_utils.js';
17
20
 
18
- // Setup snapshots will create a node with index 0, so all of our loops here
19
- // need to start from 1 to avoid running validators with the same key
20
- export const PROPOSER_PRIVATE_KEYS_START_INDEX = 1;
21
- export const ATTESTER_PRIVATE_KEYS_START_INDEX = 1001;
21
+ // Setup snapshots will create a node with index 0, and run extra bootstrap with
22
+ // index 1, and prover node with index 2, so all of our loops here need to start from 3
23
+ // to avoid running validators with the same key
24
+ export const ATTESTER_PRIVATE_KEYS_START_INDEX = 3;
22
25
 
23
26
  export interface NodeContext {
24
27
  node: AztecNodeService;
@@ -36,7 +39,7 @@ export function generatePrivateKeys(startIndex: number, numberOfKeys: number): `
36
39
  }
37
40
 
38
41
  export async function createNodes(
39
- config: AztecNodeConfig,
42
+ config: AztecNodeConfig & { dontStartSequencer?: boolean },
40
43
  dateProvider: DateProvider,
41
44
  bootstrapNodeEnr: string,
42
45
  numNodes: number,
@@ -44,6 +47,7 @@ export async function createNodes(
44
47
  prefilledPublicData?: PublicDataTreeLeaf[],
45
48
  dataDirectory?: string,
46
49
  metricsPort?: number,
50
+ indexOffset = 0,
47
51
  ): Promise<AztecNodeService[]> {
48
52
  const nodePromises: Promise<AztecNodeService>[] = [];
49
53
  const loggerIdStorage = new AsyncLocalStorage<string>();
@@ -52,16 +56,17 @@ export async function createNodes(
52
56
  addLogNameHandler(logNameHandler);
53
57
 
54
58
  for (let i = 0; i < numNodes; i++) {
59
+ const index = indexOffset + i;
55
60
  // We run on ports from the bootnode upwards
56
- const port = bootNodePort + i + 1;
61
+ const port = bootNodePort + 1 + index;
57
62
 
58
- const dataDir = dataDirectory ? `${dataDirectory}-${i}` : undefined;
63
+ const dataDir = dataDirectory ? `${dataDirectory}-${index}` : undefined;
59
64
  const nodePromise = createNode(
60
65
  config,
61
66
  dateProvider,
62
67
  port,
63
68
  bootstrapNodeEnr,
64
- i,
69
+ index,
65
70
  prefilledPublicData,
66
71
  dataDir,
67
72
  metricsPort,
@@ -70,55 +75,113 @@ export async function createNodes(
70
75
  nodePromises.push(nodePromise);
71
76
  }
72
77
  const nodes = await Promise.all(nodePromises);
78
+
79
+ // Sanity check that we have a sequencer if required
80
+ const seqClient = nodes[0].getSequencer();
81
+ if (!seqClient && config.disableValidator === false) {
82
+ throw new Error('Sequencer not found');
83
+ }
84
+
73
85
  removeLogNameHandler(logNameHandler);
74
86
  return nodes;
75
87
  }
76
88
 
77
- // creates a P2P enabled instance of Aztec Node Service
89
+ /** Creates a P2P enabled instance of Aztec Node Service with a validator */
78
90
  export async function createNode(
79
- config: AztecNodeConfig,
91
+ config: AztecNodeConfig & { dontStartSequencer?: boolean },
80
92
  dateProvider: DateProvider,
81
93
  tcpPort: number,
82
94
  bootstrapNode: string | undefined,
83
- accountIndex: number,
95
+ addressIndex: number,
84
96
  prefilledPublicData?: PublicDataTreeLeaf[],
85
97
  dataDirectory?: string,
86
98
  metricsPort?: number,
87
99
  loggerIdStorage?: AsyncLocalStorage<string>,
88
100
  ) {
89
101
  const createNode = async () => {
90
- const validatorConfig = await createValidatorConfig(config, bootstrapNode, tcpPort, accountIndex, dataDirectory);
102
+ const validatorConfig = await createValidatorConfig(config, bootstrapNode, tcpPort, addressIndex, dataDirectory);
91
103
  const telemetry = getEndToEndTestTelemetryClient(metricsPort);
92
- return await AztecNodeService.createAndSync(validatorConfig, { telemetry, dateProvider }, { prefilledPublicData });
104
+ return await AztecNodeService.createAndSync(
105
+ validatorConfig,
106
+ { telemetry, dateProvider },
107
+ { prefilledPublicData, dontStartSequencer: config.dontStartSequencer },
108
+ );
93
109
  };
94
110
  return loggerIdStorage ? await loggerIdStorage.run(tcpPort.toString(), createNode) : createNode();
95
111
  }
96
112
 
97
- export async function createValidatorConfig(
113
+ /** Creates a P2P enabled instance of Aztec Node Service without a validator */
114
+ export async function createNonValidatorNode(
115
+ baseConfig: AztecNodeConfig,
116
+ dateProvider: DateProvider,
117
+ tcpPort: number,
118
+ bootstrapNode: string | undefined,
119
+ prefilledPublicData?: PublicDataTreeLeaf[],
120
+ dataDirectory?: string,
121
+ metricsPort?: number,
122
+ loggerIdStorage?: AsyncLocalStorage<string>,
123
+ ) {
124
+ const createNode = async () => {
125
+ const p2pConfig = await createP2PConfig(baseConfig, bootstrapNode, tcpPort, dataDirectory);
126
+ const config: AztecNodeConfig = {
127
+ ...p2pConfig,
128
+ disableValidator: true,
129
+ validatorPrivateKeys: undefined,
130
+ publisherPrivateKeys: [],
131
+ };
132
+ const telemetry = getEndToEndTestTelemetryClient(metricsPort);
133
+ return await AztecNodeService.createAndSync(config, { telemetry, dateProvider }, { prefilledPublicData });
134
+ };
135
+ return loggerIdStorage ? await loggerIdStorage.run(tcpPort.toString(), createNode) : createNode();
136
+ }
137
+
138
+ export async function createProverNode(
139
+ config: AztecNodeConfig,
140
+ tcpPort: number,
141
+ bootstrapNode: string | undefined,
142
+ addressIndex: number,
143
+ proverNodeDeps: ProverNodeDeps & Required<Pick<ProverNodeDeps, 'dateProvider'>>,
144
+ prefilledPublicData?: PublicDataTreeLeaf[],
145
+ dataDirectory?: string,
146
+ metricsPort?: number,
147
+ loggerIdStorage?: AsyncLocalStorage<string>,
148
+ ) {
149
+ const createProverNode = async () => {
150
+ const proverNodePrivateKey = getPrivateKeyFromIndex(ATTESTER_PRIVATE_KEYS_START_INDEX + addressIndex)!;
151
+ const telemetry = getEndToEndTestTelemetryClient(metricsPort);
152
+
153
+ const proverConfig: Partial<ProverNodeConfig> = await createP2PConfig(
154
+ config,
155
+ bootstrapNode,
156
+ tcpPort,
157
+ dataDirectory,
158
+ );
159
+
160
+ const aztecNodeRpcTxProvider = undefined;
161
+ return await createAndSyncProverNode(
162
+ bufferToHex(proverNodePrivateKey),
163
+ config,
164
+ { ...proverConfig, dataDirectory },
165
+ aztecNodeRpcTxProvider,
166
+ prefilledPublicData,
167
+ { ...proverNodeDeps, telemetry },
168
+ );
169
+ };
170
+ return loggerIdStorage ? await loggerIdStorage.run(tcpPort.toString(), createProverNode) : createProverNode();
171
+ }
172
+
173
+ export async function createP2PConfig(
98
174
  config: AztecNodeConfig,
99
175
  bootstrapNodeEnr?: string,
100
176
  port?: number,
101
- accountIndex: number = 1,
102
177
  dataDirectory?: string,
103
178
  ) {
104
179
  port = port ?? (await getPort());
105
180
 
106
- const attesterPrivateKey: `0x${string}` = `0x${getPrivateKeyFromIndex(
107
- ATTESTER_PRIVATE_KEYS_START_INDEX + accountIndex,
108
- )!.toString('hex')}`;
109
- const proposerPrivateKey: `0x${string}` = `0x${getPrivateKeyFromIndex(
110
- PROPOSER_PRIVATE_KEYS_START_INDEX + accountIndex,
111
- )!.toString('hex')}`;
112
-
113
- config.validatorPrivateKey = attesterPrivateKey;
114
- config.publisherPrivateKey = proposerPrivateKey;
115
-
116
181
  const nodeConfig: AztecNodeConfig = {
117
182
  ...config,
118
- udpListenAddress: `0.0.0.0:${port}`,
119
- tcpListenAddress: `0.0.0.0:${port}`,
120
- tcpAnnounceAddress: `127.0.0.1:${port}`,
121
- udpAnnounceAddress: `127.0.0.1:${port}`,
183
+ p2pIp: `127.0.0.1`,
184
+ p2pPort: port,
122
185
  p2pEnabled: true,
123
186
  peerCheckIntervalMS: TEST_PEER_CHECK_INTERVAL_MS,
124
187
  blockCheckIntervalMS: 1000,
@@ -128,3 +191,22 @@ export async function createValidatorConfig(
128
191
 
129
192
  return nodeConfig;
130
193
  }
194
+
195
+ export async function createValidatorConfig(
196
+ config: AztecNodeConfig,
197
+ bootstrapNodeEnr?: string,
198
+ port?: number,
199
+ addressIndex: number = 1,
200
+ dataDirectory?: string,
201
+ ) {
202
+ const attesterPrivateKey = bufferToHex(getPrivateKeyFromIndex(ATTESTER_PRIVATE_KEYS_START_INDEX + addressIndex)!);
203
+ const p2pConfig = await createP2PConfig(config, bootstrapNodeEnr, port, dataDirectory);
204
+ const nodeConfig: AztecNodeConfig = {
205
+ ...config,
206
+ ...p2pConfig,
207
+ validatorPrivateKeys: new SecretValue([attesterPrivateKey]),
208
+ publisherPrivateKeys: [new SecretValue(attesterPrivateKey)],
209
+ };
210
+
211
+ return nodeConfig;
212
+ }
@@ -2,31 +2,41 @@ import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';
2
2
  import { type InitialAccountData, deployFundedSchnorrAccounts, generateSchnorrAccounts } from '@aztec/accounts/testing';
3
3
  import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node';
4
4
  import {
5
- AnvilTestWatcher,
6
5
  type AztecAddress,
6
+ type AztecNode,
7
7
  BatchCall,
8
- type Capsule,
9
- CheatCodes,
10
8
  type CompleteAddress,
11
9
  type ContractFunctionInteraction,
12
- type DeployL1ContractsReturnType,
13
- type FunctionCall,
10
+ DefaultWaitForProvenOpts,
11
+ EthAddress,
14
12
  type Logger,
15
13
  type PXE,
16
14
  type Wallet,
17
15
  getContractClassFromArtifact,
16
+ waitForProven,
18
17
  } from '@aztec/aztec.js';
19
- import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment';
18
+ import { publishContractClass, publishInstance } from '@aztec/aztec.js/deployment';
19
+ import { AnvilTestWatcher, CheatCodes } from '@aztec/aztec/testing';
20
20
  import { type BlobSinkServer, createBlobSinkServer } from '@aztec/blob-sink/server';
21
- import { type DeployL1ContractsArgs, createL1Clients, getL1ContractsConfigEnvVars, l1Artifacts } from '@aztec/ethereum';
21
+ import {
22
+ type DeployL1ContractsArgs,
23
+ type DeployL1ContractsReturnType,
24
+ createExtendedL1Client,
25
+ deployMulticall3,
26
+ getL1ContractsConfigEnvVars,
27
+ } from '@aztec/ethereum';
22
28
  import { EthCheatCodesWithState, startAnvil } from '@aztec/ethereum/test';
23
29
  import { asyncMap } from '@aztec/foundation/async-map';
30
+ import { SecretValue } from '@aztec/foundation/config';
24
31
  import { randomBytes } from '@aztec/foundation/crypto';
32
+ import { tryRmDir } from '@aztec/foundation/fs';
25
33
  import { createLogger } from '@aztec/foundation/log';
26
34
  import { resolver, reviver } from '@aztec/foundation/serialize';
27
35
  import { TestDateProvider } from '@aztec/foundation/timer';
28
36
  import type { ProverNode } from '@aztec/prover-node';
29
37
  import { type PXEService, createPXEService, getPXEServiceConfig } from '@aztec/pxe/server';
38
+ import type { SequencerClient } from '@aztec/sequencer-client';
39
+ import { tryStop } from '@aztec/stdlib/interfaces/server';
30
40
  import { getConfigEnvVars as getTelemetryConfig, initTelemetryClient } from '@aztec/telemetry-client';
31
41
  import { getGenesisValues } from '@aztec/world-state/testing';
32
42
 
@@ -37,14 +47,21 @@ import fs from 'fs/promises';
37
47
  import getPort from 'get-port';
38
48
  import { tmpdir } from 'os';
39
49
  import path, { join } from 'path';
40
- import { type Hex, getContract } from 'viem';
50
+ import type { Hex } from 'viem';
41
51
  import { mnemonicToAccount } from 'viem/accounts';
52
+ import { foundry } from 'viem/chains';
42
53
 
43
- import { MNEMONIC, TEST_PEER_CHECK_INTERVAL_MS } from './fixtures.js';
54
+ import { MNEMONIC, TEST_MAX_TX_POOL_SIZE, TEST_PEER_CHECK_INTERVAL_MS } from './fixtures.js';
44
55
  import { getACVMConfig } from './get_acvm_config.js';
45
56
  import { getBBConfig } from './get_bb_config.js';
46
57
  import { setupL1Contracts } from './setup_l1_contracts.js';
47
- import { type SetupOptions, createAndSyncProverNode, getLogger, getPrivateKeyFromIndex } from './utils.js';
58
+ import {
59
+ type SetupOptions,
60
+ createAndSyncProverNode,
61
+ getLogger,
62
+ getPrivateKeyFromIndex,
63
+ getSponsoredFPCAddress,
64
+ } from './utils.js';
48
65
  import { getEndToEndTestTelemetryClient } from './with_telemetry_utils.js';
49
66
 
50
67
  export type SubsystemsContext = {
@@ -58,6 +75,7 @@ export type SubsystemsContext = {
58
75
  proverNode?: ProverNode;
59
76
  watcher: AnvilTestWatcher;
60
77
  cheatCodes: CheatCodes;
78
+ sequencer: SequencerClient;
61
79
  dateProvider: TestDateProvider;
62
80
  blobSink: BlobSinkServer;
63
81
  initialFundedAccounts: InitialAccountData[];
@@ -253,24 +271,19 @@ async function teardown(context: SubsystemsContext | undefined) {
253
271
  if (!context) {
254
272
  return;
255
273
  }
274
+ const logger = getLogger();
256
275
  try {
257
- getLogger().info('Tearing down subsystems');
258
- await context.proverNode?.stop();
259
- await context.aztecNode.stop();
276
+ logger.info('Tearing down subsystems');
277
+ await tryStop(context.proverNode);
278
+ await tryStop(context.aztecNode);
260
279
  await context.acvmConfig?.cleanup();
261
280
  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
- }
281
+ await tryStop(context.anvil);
282
+ await tryStop(context.watcher);
283
+ await tryStop(context.blobSink);
284
+ await tryRmDir(context.directoryToCleanup, logger);
272
285
  } catch (err) {
273
- getLogger().error('Error during teardown', err);
286
+ logger.error('Error during teardown', err);
274
287
  }
275
288
  }
276
289
 
@@ -291,10 +304,24 @@ async function setupFromFresh(
291
304
 
292
305
  const blobSinkPort = await getPort();
293
306
 
307
+ // Default to no slashing
308
+ opts.slasherFlavor ??= 'none';
309
+ deployL1ContractsArgs.slasherFlavor ??= opts.slasherFlavor;
310
+
294
311
  // Fetch the AztecNode config.
295
312
  // TODO: For some reason this is currently the union of a bunch of subsystems. That needs fixing.
296
313
  const aztecNodeConfig: AztecNodeConfig & SetupOptions = { ...getConfigEnvVars(), ...opts };
297
314
  aztecNodeConfig.peerCheckIntervalMS = TEST_PEER_CHECK_INTERVAL_MS;
315
+ aztecNodeConfig.maxTxPoolSize = opts.maxTxPoolSize ?? TEST_MAX_TX_POOL_SIZE;
316
+ // Only enable proving if specifically requested.
317
+ aztecNodeConfig.realProofs = !!opts.realProofs;
318
+ // Only enforce the time table if requested
319
+ aztecNodeConfig.enforceTimeTable = !!opts.enforceTimeTable;
320
+ // Only set the target committee size if it is explicitly set
321
+ aztecNodeConfig.aztecTargetCommitteeSize = opts.aztecTargetCommitteeSize ?? 0;
322
+ aztecNodeConfig.listenAddress = '127.0.0.1';
323
+
324
+ deployL1ContractsArgs.aztecTargetCommitteeSize ??= aztecNodeConfig.aztecTargetCommitteeSize;
298
325
 
299
326
  // Create a temp directory for all ephemeral state and cleanup afterwards
300
327
  const directoryToCleanup = path.join(tmpdir(), randomBytes(8).toString('hex'));
@@ -304,86 +331,63 @@ async function setupFromFresh(
304
331
  } else {
305
332
  aztecNodeConfig.dataDirectory = statePath;
306
333
  }
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];
334
+ aztecNodeConfig.blobSinkUrl = `http://127.0.0.1:${blobSinkPort}`;
324
335
 
325
- // Deploy our L1 contracts.
326
- logger.verbose('Deploying L1 contracts...');
327
- const hdAccount = mnemonicToAccount(MNEMONIC, { accountIndex: 0 });
336
+ const hdAccount = mnemonicToAccount(MNEMONIC, { addressIndex: 0 });
328
337
  const publisherPrivKeyRaw = hdAccount.getHdKey().privateKey;
329
338
  const publisherPrivKey = publisherPrivKeyRaw === null ? null : Buffer.from(publisherPrivKeyRaw);
330
339
 
340
+ const l1Client = createExtendedL1Client([aztecNodeConfig.l1RpcUrls[0]], hdAccount, foundry);
341
+
331
342
  const validatorPrivKey = getPrivateKeyFromIndex(0);
332
343
  const proverNodePrivateKey = getPrivateKeyFromIndex(0);
333
344
 
334
- aztecNodeConfig.publisherPrivateKey = `0x${publisherPrivKey!.toString('hex')}`;
335
- aztecNodeConfig.validatorPrivateKey = `0x${validatorPrivKey!.toString('hex')}`;
345
+ aztecNodeConfig.publisherPrivateKeys = [new SecretValue<`0x${string}`>(`0x${publisherPrivKey!.toString('hex')}`)];
346
+ aztecNodeConfig.validatorPrivateKeys = new SecretValue([`0x${validatorPrivKey!.toString('hex')}`]);
347
+ aztecNodeConfig.coinbase = opts.coinbase ?? EthAddress.fromString(`${hdAccount.address}`);
336
348
 
349
+ logger.info(`Setting up environment with config`, aztecNodeConfig);
350
+
351
+ // Start anvil. We go via a wrapper script to ensure if the parent dies, anvil dies.
352
+ logger.verbose('Starting anvil...');
353
+ const res = await startAnvil({ l1BlockTime: opts.ethereumSlotDuration });
354
+ const anvil = res.anvil;
355
+ aztecNodeConfig.l1RpcUrls = [res.rpcUrl];
337
356
  const ethCheatCodes = new EthCheatCodesWithState(aztecNodeConfig.l1RpcUrls);
338
357
 
358
+ // Deploy our L1 contracts.
359
+ logger.verbose('Deploying L1 contracts...');
339
360
  if (opts.l1StartTime) {
340
- await ethCheatCodes.warp(opts.l1StartTime);
361
+ await ethCheatCodes.warp(opts.l1StartTime, { resetBlockInterval: true });
341
362
  }
342
363
 
343
364
  const initialFundedAccounts = await generateSchnorrAccounts(numberOfInitialFundedAccounts);
344
- const { genesisArchiveRoot, genesisBlockHash, prefilledPublicData } = await getGenesisValues(
345
- initialFundedAccounts.map(a => a.address),
365
+ const sponsoredFPCAddress = await getSponsoredFPCAddress();
366
+ const { genesisArchiveRoot, prefilledPublicData, fundingNeeded } = await getGenesisValues(
367
+ initialFundedAccounts.map(a => a.address).concat(sponsoredFPCAddress),
346
368
  opts.initialAccountFeeJuice,
347
369
  );
348
370
 
371
+ await deployMulticall3(l1Client, logger);
372
+
349
373
  const deployL1ContractsValues = await setupL1Contracts(aztecNodeConfig.l1RpcUrls[0], hdAccount, logger, {
350
374
  ...getL1ContractsConfigEnvVars(),
351
375
  genesisArchiveRoot,
352
- genesisBlockHash,
376
+ feeJuicePortalInitialBalance: fundingNeeded,
353
377
  salt: opts.salt,
354
378
  ...deployL1ContractsArgs,
355
379
  initialValidators: opts.initialValidators,
356
380
  });
357
381
  aztecNodeConfig.l1Contracts = deployL1ContractsValues.l1ContractAddresses;
358
- aztecNodeConfig.l1PublishRetryIntervalMS = 100;
359
-
360
- if (opts.fundRewardDistributor) {
361
- // Mints block rewards for 10000 blocks to the rewardDistributor contract
382
+ aztecNodeConfig.rollupVersion = deployL1ContractsValues.rollupVersion;
362
383
 
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
- }
384
+ const dateProvider = new TestDateProvider();
382
385
 
383
386
  const watcher = new AnvilTestWatcher(
384
387
  new EthCheatCodesWithState(aztecNodeConfig.l1RpcUrls),
385
388
  deployL1ContractsValues.l1ContractAddresses.rollupAddress,
386
- deployL1ContractsValues.publicClient,
389
+ deployL1ContractsValues.l1Client,
390
+ dateProvider,
387
391
  );
388
392
  await watcher.start();
389
393
 
@@ -401,8 +405,21 @@ async function setupFromFresh(
401
405
 
402
406
  const telemetry = getEndToEndTestTelemetryClient(opts.metricsPort);
403
407
 
404
- logger.verbose('Creating and synching an aztec node...');
405
- const dateProvider = new TestDateProvider();
408
+ // Setup blob sink service
409
+ const blobSink = await createBlobSinkServer(
410
+ {
411
+ l1ChainId: aztecNodeConfig.l1ChainId,
412
+ l1RpcUrls: aztecNodeConfig.l1RpcUrls,
413
+ l1Contracts: aztecNodeConfig.l1Contracts,
414
+ port: blobSinkPort,
415
+ dataDirectory: aztecNodeConfig.dataDirectory,
416
+ dataStoreMapSizeKb: aztecNodeConfig.dataStoreMapSizeKb,
417
+ },
418
+ telemetry,
419
+ );
420
+ await blobSink.start();
421
+
422
+ logger.info('Creating and synching an aztec node...');
406
423
  const aztecNode = await AztecNodeService.createAndSync(
407
424
  aztecNodeConfig,
408
425
  { telemetry, dateProvider },
@@ -411,12 +428,16 @@ async function setupFromFresh(
411
428
 
412
429
  let proverNode: ProverNode | undefined = undefined;
413
430
  if (opts.startProverNode) {
414
- logger.verbose('Creating and syncing a simulated prover node...');
431
+ logger.verbose('Creating and syncing a simulated prover node with p2p disabled...');
415
432
  proverNode = await createAndSyncProverNode(
416
433
  `0x${proverNodePrivateKey!.toString('hex')}`,
417
434
  aztecNodeConfig,
435
+ {
436
+ ...aztecNodeConfig.proverNodeConfig,
437
+ dataDirectory: path.join(directoryToCleanup, randomBytes(8).toString('hex')),
438
+ p2pEnabled: false,
439
+ },
418
440
  aztecNode,
419
- path.join(directoryToCleanup, randomBytes(8).toString('hex')),
420
441
  prefilledPublicData,
421
442
  );
422
443
  }
@@ -424,6 +445,8 @@ async function setupFromFresh(
424
445
  logger.verbose('Creating pxe...');
425
446
  const pxeConfig = getPXEServiceConfig();
426
447
  pxeConfig.dataDirectory = statePath ?? path.join(directoryToCleanup, randomBytes(8).toString('hex'));
448
+ // Only enable proving if specifically requested.
449
+ pxeConfig.proverEnabled = !!opts.realProofs;
427
450
  const pxe = await createPXEService(aztecNode, pxeConfig);
428
451
 
429
452
  const cheatCodes = await CheatCodes.create(aztecNodeConfig.l1RpcUrls, pxe);
@@ -438,6 +461,7 @@ async function setupFromFresh(
438
461
  anvil,
439
462
  aztecNode,
440
463
  pxe,
464
+ sequencer: aztecNode.getSequencer()!,
441
465
  acvmConfig,
442
466
  bbConfig,
443
467
  deployL1ContractsValues,
@@ -470,20 +494,12 @@ async function setupFromState(statePath: string, logger: Logger): Promise<Subsys
470
494
  );
471
495
  aztecNodeConfig.dataDirectory = statePath;
472
496
  aztecNodeConfig.blobSinkUrl = `http://127.0.0.1:${blobSinkPort}`;
497
+ aztecNodeConfig.listenAddress = '127.0.0.1';
473
498
 
474
499
  const initialFundedAccounts: InitialAccountData[] =
475
500
  JSON.parse(readFileSync(`${statePath}/accounts.json`, 'utf-8'), reviver) || [];
476
501
  const { prefilledPublicData } = await getGenesisValues(initialFundedAccounts.map(a => a.address));
477
502
 
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
503
  // Start anvil. We go via a wrapper script to ensure if the parent dies, anvil dies.
488
504
  const { anvil, rpcUrl } = await startAnvil();
489
505
  aztecNodeConfig.l1RpcUrls = [rpcUrl];
@@ -506,18 +522,32 @@ async function setupFromState(statePath: string, logger: Logger): Promise<Subsys
506
522
  }
507
523
 
508
524
  logger.verbose('Creating ETH clients...');
509
- const { publicClient, walletClient } = createL1Clients(aztecNodeConfig.l1RpcUrls, mnemonicToAccount(MNEMONIC));
525
+ const l1Client = createExtendedL1Client(aztecNodeConfig.l1RpcUrls, mnemonicToAccount(MNEMONIC));
510
526
 
527
+ const dateProvider = new TestDateProvider();
511
528
  const watcher = new AnvilTestWatcher(
512
529
  new EthCheatCodesWithState(aztecNodeConfig.l1RpcUrls),
513
530
  aztecNodeConfig.l1Contracts.rollupAddress,
514
- publicClient,
531
+ l1Client,
532
+ dateProvider,
515
533
  );
516
534
  await watcher.start();
517
535
 
518
- logger.verbose('Creating aztec node...');
519
536
  const telemetry = initTelemetryClient(getTelemetryConfig());
520
- const dateProvider = new TestDateProvider();
537
+ const blobSink = await createBlobSinkServer(
538
+ {
539
+ l1ChainId: aztecNodeConfig.l1ChainId,
540
+ l1RpcUrls: aztecNodeConfig.l1RpcUrls,
541
+ l1Contracts: aztecNodeConfig.l1Contracts,
542
+ port: blobSinkPort,
543
+ dataDirectory: statePath,
544
+ dataStoreMapSizeKb: aztecNodeConfig.dataStoreMapSizeKb,
545
+ },
546
+ telemetry,
547
+ );
548
+ await blobSink.start();
549
+
550
+ logger.verbose('Creating aztec node...');
521
551
  const aztecNode = await AztecNodeService.createAndSync(
522
552
  aztecNodeConfig,
523
553
  { telemetry, dateProvider },
@@ -532,8 +562,12 @@ async function setupFromState(statePath: string, logger: Logger): Promise<Subsys
532
562
  proverNode = await createAndSyncProverNode(
533
563
  proverNodePrivateKeyHex,
534
564
  aztecNodeConfig,
565
+ {
566
+ ...aztecNodeConfig.proverNodeConfig,
567
+ dataDirectory: path.join(directoryToCleanup, randomBytes(8).toString('hex')),
568
+ p2pEnabled: false,
569
+ },
535
570
  aztecNode,
536
- path.join(directoryToCleanup, randomBytes(8).toString('hex')),
537
571
  prefilledPublicData,
538
572
  );
539
573
  }
@@ -550,13 +584,14 @@ async function setupFromState(statePath: string, logger: Logger): Promise<Subsys
550
584
  anvil,
551
585
  aztecNode,
552
586
  pxe,
587
+ sequencer: aztecNode.getSequencer()!,
553
588
  acvmConfig,
554
589
  bbConfig,
555
590
  proverNode,
556
591
  deployL1ContractsValues: {
557
- walletClient,
558
- publicClient,
592
+ l1Client,
559
593
  l1ContractAddresses: aztecNodeConfig.l1Contracts,
594
+ rollupVersion: aztecNodeConfig.rollupVersion,
560
595
  },
561
596
  watcher,
562
597
  cheatCodes,
@@ -580,7 +615,12 @@ export const deployAccounts =
580
615
 
581
616
  logger.verbose('Deploying accounts funded with fee juice...');
582
617
  const deployedAccounts = initialFundedAccounts.slice(0, numberOfAccounts);
583
- await deployFundedSchnorrAccounts(pxe, deployedAccounts, { proven: waitUntilProven });
618
+ await deployFundedSchnorrAccounts(
619
+ pxe,
620
+ deployedAccounts,
621
+ undefined,
622
+ waitUntilProven ? DefaultWaitForProvenOpts : undefined,
623
+ );
584
624
 
585
625
  return { deployedAccounts };
586
626
  };
@@ -590,11 +630,14 @@ export const deployAccounts =
590
630
  * Use this when you need to make a public call to an account contract, such as for requesting a public authwit.
591
631
  * @param sender - Wallet to send the deployment tx.
592
632
  * @param accountsToDeploy - Which accounts to publicly deploy.
633
+ * @param waitUntilProven - Whether to wait for the tx to be proven.
634
+ * @param pxeOrNode - PXE or AztecNode to wait for proven.
593
635
  */
594
636
  export async function publicDeployAccounts(
595
637
  sender: Wallet,
596
638
  accountsToDeploy: (CompleteAddress | AztecAddress)[],
597
639
  waitUntilProven = false,
640
+ pxeOrNode?: PXE | AztecNode,
598
641
  ) {
599
642
  const accountAddressesToDeploy = accountsToDeploy.map(a => ('address' in a ? a.address : a));
600
643
  const instances = (
@@ -604,14 +647,19 @@ export async function publicDeployAccounts(
604
647
  const contractClass = await getContractClassFromArtifact(SchnorrAccountContractArtifact);
605
648
  const alreadyRegistered = (await sender.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered;
606
649
 
607
- const fns: ContractFunctionInteraction[] = await Promise.all([
608
- ...(!alreadyRegistered ? [registerContractClass(sender, SchnorrAccountContractArtifact)] : []),
609
- ...instances.map(instance => deployInstance(sender, instance!)),
650
+ const calls: ContractFunctionInteraction[] = await Promise.all([
651
+ ...(!alreadyRegistered ? [publishContractClass(sender, SchnorrAccountContractArtifact)] : []),
652
+ ...instances.map(instance => publishInstance(sender, instance!)),
610
653
  ]);
611
- const calls: FunctionCall[] = await Promise.all(fns.map(fn => fn.request()));
612
- const capsules: Capsule[] = fns.map(fn => fn.getCapsules()).flat();
613
654
 
614
655
  const batch = new BatchCall(sender, calls);
615
- batch.addCapsules(capsules);
616
- await batch.send().wait({ proven: waitUntilProven });
656
+
657
+ const txReceipt = await batch.send({ from: accountAddressesToDeploy[0] }).wait();
658
+ if (waitUntilProven) {
659
+ if (!pxeOrNode) {
660
+ throw new Error('Need to provide a PXE or AztecNode to wait for proven.');
661
+ } else {
662
+ await waitForProven(pxeOrNode, txReceipt);
663
+ }
664
+ }
617
665
  }