@aztec/end-to-end 0.0.1-commit.f295ac2 → 0.0.1-commit.f8ca9b2f3

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 (169) hide show
  1. package/dest/bench/client_flows/client_flows_benchmark.d.ts +2 -2
  2. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  3. package/dest/bench/client_flows/client_flows_benchmark.js +29 -14
  4. package/dest/bench/client_flows/config.d.ts +2 -2
  5. package/dest/bench/client_flows/config.d.ts.map +1 -1
  6. package/dest/bench/client_flows/config.js +18 -0
  7. package/dest/bench/utils.d.ts +5 -4
  8. package/dest/bench/utils.d.ts.map +1 -1
  9. package/dest/bench/utils.js +9 -7
  10. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +2 -2
  11. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  12. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +7 -8
  13. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +2 -2
  14. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  15. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +3 -2
  16. package/dest/e2e_deploy_contract/deploy_test.d.ts +2 -2
  17. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  18. package/dest/e2e_epochs/epochs_test.d.ts +7 -1
  19. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  20. package/dest/e2e_epochs/epochs_test.js +38 -10
  21. package/dest/e2e_fees/bridging_race.notest.js +1 -1
  22. package/dest/e2e_fees/fees_test.d.ts +2 -2
  23. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  24. package/dest/e2e_fees/fees_test.js +6 -6
  25. package/dest/e2e_l1_publisher/write_json.d.ts +4 -3
  26. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -1
  27. package/dest/e2e_l1_publisher/write_json.js +1 -7
  28. package/dest/e2e_nested_contract/nested_contract_test.d.ts +1 -1
  29. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  30. package/dest/e2e_nested_contract/nested_contract_test.js +2 -2
  31. package/dest/e2e_p2p/p2p_network.d.ts +2 -2
  32. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  33. package/dest/e2e_p2p/p2p_network.js +6 -2
  34. package/dest/e2e_p2p/reqresp/utils.d.ts +22 -0
  35. package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -0
  36. package/dest/e2e_p2p/reqresp/utils.js +153 -0
  37. package/dest/e2e_p2p/shared.d.ts +6 -6
  38. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  39. package/dest/e2e_p2p/shared.js +14 -17
  40. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +2 -0
  41. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +1 -0
  42. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.js +184 -0
  43. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts +18 -0
  44. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +1 -0
  45. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.js +120 -0
  46. package/dest/e2e_token_contract/token_contract_test.d.ts +2 -2
  47. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  48. package/dest/e2e_token_contract/token_contract_test.js +3 -3
  49. package/dest/fixtures/e2e_prover_test.d.ts +2 -2
  50. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  51. package/dest/fixtures/e2e_prover_test.js +8 -5
  52. package/dest/fixtures/ha_setup.d.ts +71 -0
  53. package/dest/fixtures/ha_setup.d.ts.map +1 -0
  54. package/dest/fixtures/ha_setup.js +114 -0
  55. package/dest/fixtures/index.d.ts +2 -1
  56. package/dest/fixtures/index.d.ts.map +1 -1
  57. package/dest/fixtures/index.js +1 -0
  58. package/dest/fixtures/setup.d.ts +18 -16
  59. package/dest/fixtures/setup.d.ts.map +1 -1
  60. package/dest/fixtures/setup.js +40 -93
  61. package/dest/fixtures/setup_p2p_test.d.ts +12 -8
  62. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  63. package/dest/fixtures/setup_p2p_test.js +29 -21
  64. package/dest/fixtures/token_utils.d.ts +1 -1
  65. package/dest/fixtures/token_utils.d.ts.map +1 -1
  66. package/dest/fixtures/token_utils.js +7 -4
  67. package/dest/shared/cross_chain_test_harness.d.ts +3 -4
  68. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  69. package/dest/shared/cross_chain_test_harness.js +11 -11
  70. package/dest/shared/gas_portal_test_harness.js +1 -1
  71. package/dest/shared/submit-transactions.d.ts +4 -4
  72. package/dest/shared/submit-transactions.d.ts.map +1 -1
  73. package/dest/shared/submit-transactions.js +9 -11
  74. package/dest/shared/uniswap_l1_l2.d.ts +1 -1
  75. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  76. package/dest/shared/uniswap_l1_l2.js +20 -18
  77. package/dest/simulators/lending_simulator.js +2 -2
  78. package/dest/spartan/setup_test_wallets.d.ts +2 -2
  79. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  80. package/dest/spartan/setup_test_wallets.js +64 -35
  81. package/dest/spartan/tx_metrics.d.ts +48 -2
  82. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  83. package/dest/spartan/tx_metrics.js +309 -5
  84. package/dest/spartan/utils/bot.d.ts +27 -0
  85. package/dest/spartan/utils/bot.d.ts.map +1 -0
  86. package/dest/spartan/utils/bot.js +141 -0
  87. package/dest/spartan/utils/chaos.d.ts +79 -0
  88. package/dest/spartan/utils/chaos.d.ts.map +1 -0
  89. package/dest/spartan/utils/chaos.js +142 -0
  90. package/dest/spartan/utils/clients.d.ts +39 -0
  91. package/dest/spartan/utils/clients.d.ts.map +1 -0
  92. package/dest/spartan/utils/clients.js +90 -0
  93. package/dest/spartan/utils/config.d.ts +39 -0
  94. package/dest/spartan/utils/config.d.ts.map +1 -0
  95. package/dest/spartan/utils/config.js +21 -0
  96. package/dest/spartan/utils/health.d.ts +63 -0
  97. package/dest/spartan/utils/health.d.ts.map +1 -0
  98. package/dest/spartan/utils/health.js +202 -0
  99. package/dest/spartan/utils/helm.d.ts +15 -0
  100. package/dest/spartan/utils/helm.d.ts.map +1 -0
  101. package/dest/spartan/utils/helm.js +47 -0
  102. package/dest/spartan/utils/index.d.ts +9 -0
  103. package/dest/spartan/utils/index.d.ts.map +1 -0
  104. package/dest/spartan/utils/index.js +18 -0
  105. package/dest/spartan/utils/k8s.d.ts +126 -0
  106. package/dest/spartan/utils/k8s.d.ts.map +1 -0
  107. package/dest/spartan/utils/k8s.js +375 -0
  108. package/dest/spartan/utils/nodes.d.ts +41 -0
  109. package/dest/spartan/utils/nodes.d.ts.map +1 -0
  110. package/dest/spartan/utils/nodes.js +461 -0
  111. package/dest/spartan/utils/scripts.d.ts +30 -0
  112. package/dest/spartan/utils/scripts.d.ts.map +1 -0
  113. package/dest/spartan/utils/scripts.js +81 -0
  114. package/dest/spartan/utils.d.ts +2 -260
  115. package/dest/spartan/utils.d.ts.map +1 -1
  116. package/dest/spartan/utils.js +1 -942
  117. package/dest/test-wallet/test_wallet.d.ts +82 -0
  118. package/dest/test-wallet/test_wallet.d.ts.map +1 -0
  119. package/dest/test-wallet/test_wallet.js +213 -0
  120. package/dest/test-wallet/utils.d.ts +41 -0
  121. package/dest/test-wallet/utils.d.ts.map +1 -0
  122. package/dest/test-wallet/utils.js +71 -0
  123. package/package.json +43 -39
  124. package/src/bench/client_flows/client_flows_benchmark.ts +17 -30
  125. package/src/bench/client_flows/config.ts +9 -1
  126. package/src/bench/utils.ts +10 -8
  127. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +11 -14
  128. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +7 -8
  129. package/src/e2e_deploy_contract/deploy_test.ts +3 -3
  130. package/src/e2e_epochs/epochs_test.ts +71 -35
  131. package/src/e2e_fees/bridging_race.notest.ts +2 -5
  132. package/src/e2e_fees/fees_test.ts +17 -21
  133. package/src/e2e_l1_publisher/write_json.ts +3 -8
  134. package/src/e2e_nested_contract/nested_contract_test.ts +3 -5
  135. package/src/e2e_p2p/inactivity_slash_test.ts +4 -4
  136. package/src/e2e_p2p/p2p_network.ts +20 -14
  137. package/src/e2e_p2p/reqresp/utils.ts +207 -0
  138. package/src/e2e_p2p/shared.ts +22 -22
  139. package/src/e2e_storage_proof/fixtures/storage_proof.json +915 -0
  140. package/src/e2e_storage_proof/fixtures/storage_proof_fetcher.ts +190 -0
  141. package/src/e2e_storage_proof/fixtures/storage_proof_fixture.ts +173 -0
  142. package/src/e2e_token_contract/token_contract_test.ts +5 -7
  143. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  144. package/src/fixtures/e2e_prover_test.ts +8 -13
  145. package/src/fixtures/ha_setup.ts +184 -0
  146. package/src/fixtures/index.ts +1 -0
  147. package/src/fixtures/setup.ts +49 -126
  148. package/src/fixtures/setup_p2p_test.ts +31 -27
  149. package/src/fixtures/token_utils.ts +6 -5
  150. package/src/shared/cross_chain_test_harness.ts +13 -27
  151. package/src/shared/gas_portal_test_harness.ts +1 -1
  152. package/src/shared/submit-transactions.ts +11 -16
  153. package/src/shared/uniswap_l1_l2.ts +21 -30
  154. package/src/simulators/lending_simulator.ts +2 -2
  155. package/src/spartan/setup_test_wallets.ts +75 -25
  156. package/src/spartan/tx_metrics.ts +231 -8
  157. package/src/spartan/utils/bot.ts +185 -0
  158. package/src/spartan/utils/chaos.ts +253 -0
  159. package/src/spartan/utils/clients.ts +100 -0
  160. package/src/spartan/utils/config.ts +27 -0
  161. package/src/spartan/utils/health.ts +255 -0
  162. package/src/spartan/utils/helm.ts +84 -0
  163. package/src/spartan/utils/index.ts +64 -0
  164. package/src/spartan/utils/k8s.ts +527 -0
  165. package/src/spartan/utils/nodes.ts +538 -0
  166. package/src/spartan/utils/scripts.ts +99 -0
  167. package/src/spartan/utils.ts +1 -1246
  168. package/src/test-wallet/test_wallet.ts +296 -0
  169. package/src/test-wallet/utils.ts +112 -0
@@ -20,13 +20,13 @@ import { TokenContract } from '@aztec/noir-contracts.js/Token';
20
20
  import { type ProverNode, type ProverNodeConfig, createProverNode } from '@aztec/prover-node';
21
21
  import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
22
22
  import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
23
- import { TestWallet } from '@aztec/test-wallet/server';
24
23
  import { getGenesisValues } from '@aztec/world-state/testing';
25
24
 
26
25
  import { type Hex, getContract } from 'viem';
27
26
  import { privateKeyToAddress } from 'viem/accounts';
28
27
 
29
28
  import { TokenSimulator } from '../simulators/token_simulator.js';
29
+ import { TestWallet } from '../test-wallet/test_wallet.js';
30
30
  import { getACVMConfig } from './get_acvm_config.js';
31
31
  import { getBBConfig } from './get_bb_config.js';
32
32
  import {
@@ -114,9 +114,7 @@ export class FullProverTest {
114
114
  FullProverTest.TOKEN_NAME,
115
115
  FullProverTest.TOKEN_SYMBOL,
116
116
  FullProverTest.TOKEN_DECIMALS,
117
- )
118
- .send({ from: this.accounts[0] })
119
- .wait();
117
+ ).send({ from: this.accounts[0], wait: { returnReceipt: true } });
120
118
  this.logger.verbose(`Token deployed to ${asset.address}`);
121
119
 
122
120
  this.fakeProofsAsset = asset;
@@ -146,7 +144,7 @@ export class FullProverTest {
146
144
  this.logger.info(`Enabling proving`, { realProofs: this.realProofs });
147
145
 
148
146
  // We don't wish to mark as proven automatically, so we set the flag to false
149
- this.context.watcher!.setIsMarkingAsProven(false);
147
+ this.context.watcher.setIsMarkingAsProven(false);
150
148
 
151
149
  this.simulatedProverNode = this.context.proverNode!;
152
150
  ({
@@ -154,7 +152,7 @@ export class FullProverTest {
154
152
  deployL1ContractsValues: this.l1Contracts,
155
153
  cheatCodes: this.cheatCodes,
156
154
  } = this.context);
157
- this.aztecNodeAdmin = this.context.aztecNodeService!;
155
+ this.aztecNodeAdmin = this.context.aztecNodeService;
158
156
 
159
157
  const config = this.context.aztecNodeConfig;
160
158
  const blobClient = await createBlobClientWithFileStores(config, this.logger);
@@ -200,7 +198,7 @@ export class FullProverTest {
200
198
  this.aztecNode,
201
199
  { proverEnabled: this.realProofs },
202
200
  undefined,
203
- true,
201
+ 'pxe-proven',
204
202
  );
205
203
  this.logger.debug(`Contract address ${this.fakeProofsAsset.address}`);
206
204
  await provenWallet.registerContract(this.fakeProofsAssetInstance, TokenContract.artifact);
@@ -227,7 +225,7 @@ export class FullProverTest {
227
225
  this.logger.verbose('Starting archiver for new prover node');
228
226
  const archiver = await createArchiver(
229
227
  { ...this.context.aztecNodeConfig, dataDirectory: undefined },
230
- { blobClient, dateProvider: this.context.dateProvider! },
228
+ { blobClient, dateProvider: this.context.dateProvider },
231
229
  { blockUntilSync: true },
232
230
  );
233
231
 
@@ -308,13 +306,10 @@ export class FullProverTest {
308
306
  const publicAmount = 10000n;
309
307
 
310
308
  this.logger.verbose(`Minting ${privateAmount + publicAmount} publicly...`);
311
- await asset.methods
312
- .mint_to_public(accounts[0], privateAmount + publicAmount)
313
- .send({ from: accounts[0] })
314
- .wait();
309
+ await asset.methods.mint_to_public(accounts[0], privateAmount + publicAmount).send({ from: accounts[0] });
315
310
 
316
311
  this.logger.verbose(`Transferring ${privateAmount} to private...`);
317
- await asset.methods.transfer_to_private(accounts[0], privateAmount).send({ from: accounts[0] }).wait();
312
+ await asset.methods.transfer_to_private(accounts[0], privateAmount).send({ from: accounts[0] });
318
313
 
319
314
  this.logger.info(`Minting complete`);
320
315
 
@@ -0,0 +1,184 @@
1
+ import { EthAddress } from '@aztec/aztec.js/addresses';
2
+ import { Fr } from '@aztec/aztec.js/fields';
3
+ import type { Logger } from '@aztec/aztec.js/log';
4
+ import { SecretValue } from '@aztec/foundation/config';
5
+
6
+ import { Pool } from 'pg';
7
+ import { privateKeyToAccount } from 'viem/accounts';
8
+
9
+ /**
10
+ * Configuration for HA database connection
11
+ */
12
+ export interface HADatabaseConfig {
13
+ /** PostgreSQL connection URL */
14
+ databaseUrl: string;
15
+ /** Node ID for HA coordination */
16
+ nodeId: string;
17
+ /** Enable HA signing */
18
+ haSigningEnabled: boolean;
19
+ /** Polling interval in ms */
20
+ pollingIntervalMs: number;
21
+ /** Signing timeout in ms */
22
+ signingTimeoutMs: number;
23
+ /** Max stuck duties age in ms */
24
+ maxStuckDutiesAgeMs: number;
25
+ }
26
+
27
+ /**
28
+ * Get database configuration from environment variables
29
+ */
30
+ export function createHADatabaseConfig(nodeId: string): HADatabaseConfig {
31
+ const databaseUrl = process.env.DATABASE_URL || 'postgresql://aztec:aztec@localhost:5432/aztec_ha_test';
32
+
33
+ return {
34
+ databaseUrl,
35
+ nodeId,
36
+ haSigningEnabled: true,
37
+ pollingIntervalMs: 100,
38
+ signingTimeoutMs: 3000,
39
+ maxStuckDutiesAgeMs: 72000,
40
+ };
41
+ }
42
+
43
+ /**
44
+ * Setup PostgreSQL database connection pool for HA tests
45
+ *
46
+ * Note: Database migrations should be run separately before starting tests,
47
+ * either via docker-compose entrypoint or manually with: aztec migrate-ha-db up
48
+ */
49
+ export function setupHADatabase(databaseUrl: string, logger?: Logger): Pool {
50
+ try {
51
+ // Create connection pool for test usage
52
+ // Migrations are already run by docker-compose entrypoint before tests start
53
+ const pool = new Pool({ connectionString: databaseUrl });
54
+
55
+ logger?.info('Connected to HA database (migrations should already be applied)');
56
+
57
+ return pool;
58
+ } catch (error) {
59
+ logger?.error(`Failed to connect to HA database: ${error}`);
60
+ throw error;
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Clean up HA database - drop all tables
66
+ * Use this between tests to ensure clean state
67
+ */
68
+ export async function cleanupHADatabase(pool: Pool, logger?: Logger): Promise<void> {
69
+ try {
70
+ // Drop all HA tables
71
+ await pool.query('DROP TABLE IF EXISTS validator_duties CASCADE');
72
+ await pool.query('DROP TABLE IF EXISTS slashing_protection CASCADE');
73
+ await pool.query('DROP TABLE IF EXISTS schema_version CASCADE');
74
+
75
+ logger?.info('HA database cleaned up successfully');
76
+ } catch (error) {
77
+ logger?.error(`Failed to cleanup HA database: ${error}`);
78
+ throw error;
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Query validator duties from the database
84
+ */
85
+ export async function getValidatorDuties(
86
+ pool: Pool,
87
+ slot: bigint,
88
+ dutyType?: 'ATTESTATION' | 'BLOCK_PROPOSAL' | 'GOVERNANCE_VOTE' | 'SLASHING_VOTE',
89
+ ): Promise<
90
+ Array<{
91
+ slot: string;
92
+ dutyType: string;
93
+ validatorAddress: string;
94
+ nodeId: string;
95
+ startedAt: Date;
96
+ completedAt: Date | undefined;
97
+ }>
98
+ > {
99
+ const query = dutyType
100
+ ? 'SELECT slot, duty_type, validator_address, node_id, started_at, completed_at FROM validator_duties WHERE slot = $1 AND duty_type = $2 ORDER BY started_at'
101
+ : 'SELECT slot, duty_type, validator_address, node_id, started_at, completed_at FROM validator_duties WHERE slot = $1 ORDER BY started_at';
102
+
103
+ const params = dutyType ? [slot.toString(), dutyType] : [slot.toString()];
104
+
105
+ const result = await pool.query<{
106
+ slot: string;
107
+ duty_type: string;
108
+ validator_address: string;
109
+ node_id: string;
110
+ started_at: Date;
111
+ completed_at: Date | undefined;
112
+ }>(query, params);
113
+
114
+ return result.rows.map(row => ({
115
+ slot: row.slot,
116
+ dutyType: row.duty_type,
117
+ validatorAddress: row.validator_address,
118
+ nodeId: row.node_id,
119
+ startedAt: row.started_at,
120
+ completedAt: row.completed_at,
121
+ }));
122
+ }
123
+
124
+ /**
125
+ * Convert private keys to Ethereum addresses
126
+ */
127
+ export function getAddressesFromPrivateKeys(privateKeys: `0x${string}`[]): string[] {
128
+ return privateKeys.map(pk => {
129
+ const account = privateKeyToAccount(pk);
130
+ return account.address;
131
+ });
132
+ }
133
+
134
+ /**
135
+ * Create initial validators from private keys for L1 contract deployment
136
+ */
137
+ export function createInitialValidatorsFromPrivateKeys(attesterPrivateKeys: `0x${string}`[]): Array<{
138
+ attester: EthAddress;
139
+ withdrawer: EthAddress;
140
+ privateKey: `0x${string}`;
141
+ bn254SecretKey: SecretValue<bigint>;
142
+ }> {
143
+ return attesterPrivateKeys.map(pk => {
144
+ const account = privateKeyToAccount(pk);
145
+ return {
146
+ attester: EthAddress.fromString(account.address),
147
+ withdrawer: EthAddress.fromString(account.address),
148
+ privateKey: pk,
149
+ bn254SecretKey: new SecretValue(Fr.random().toBigInt()),
150
+ };
151
+ });
152
+ }
153
+
154
+ /**
155
+ * Verify no duplicate attestations per validator (HA coordination check)
156
+ * Groups duties by validator address and verifies each validator attested exactly once
157
+ */
158
+ export function verifyNoDuplicateAttestations(
159
+ attestationDuties: Array<{
160
+ validatorAddress: string;
161
+ nodeId: string;
162
+ completedAt: Date | undefined;
163
+ }>,
164
+ logger?: Logger,
165
+ ): Map<string, typeof attestationDuties> {
166
+ const dutiesByValidator = new Map<string, typeof attestationDuties>();
167
+ for (const duty of attestationDuties) {
168
+ const existing = dutiesByValidator.get(duty.validatorAddress) || [];
169
+ existing.push(duty);
170
+ dutiesByValidator.set(duty.validatorAddress, existing);
171
+ }
172
+
173
+ for (const [validatorAddress, validatorDuties] of dutiesByValidator.entries()) {
174
+ if (validatorDuties.length !== 1) {
175
+ throw new Error(`Validator ${validatorAddress} attested ${validatorDuties.length} times (expected exactly once)`);
176
+ }
177
+ if (!validatorDuties[0].completedAt) {
178
+ throw new Error(`Validator ${validatorAddress} attestation duty not completed`);
179
+ }
180
+ logger?.info(`Validator ${validatorAddress} attested once via node ${validatorDuties[0].nodeId}`);
181
+ }
182
+
183
+ return dutiesByValidator;
184
+ }
@@ -1,4 +1,5 @@
1
1
  export * from './fixtures.js';
2
+ export * from './ha_setup.js';
2
3
  export * from './logging.js';
3
4
  export * from './utils.js';
4
5
  export * from './token_utils.js';
@@ -1,5 +1,5 @@
1
1
  import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';
2
- import { type InitialAccountData, generateSchnorrAccounts, getInitialTestAccountsData } from '@aztec/accounts/testing';
2
+ import { type InitialAccountData, generateSchnorrAccounts } from '@aztec/accounts/testing';
3
3
  import { type Archiver, createArchiver } from '@aztec/archiver';
4
4
  import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node';
5
5
  import { AztecAddress, EthAddress } from '@aztec/aztec.js/addresses';
@@ -13,7 +13,7 @@ import {
13
13
  import { publishContractClass, publishInstance } from '@aztec/aztec.js/deployment';
14
14
  import { Fr } from '@aztec/aztec.js/fields';
15
15
  import { type Logger, createLogger } from '@aztec/aztec.js/log';
16
- import { type AztecNode, createAztecNodeClient, waitForNode } from '@aztec/aztec.js/node';
16
+ import type { AztecNode } from '@aztec/aztec.js/node';
17
17
  import type { Wallet } from '@aztec/aztec.js/wallet';
18
18
  import { AnvilTestWatcher, CheatCodes } from '@aztec/aztec/testing';
19
19
  import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
@@ -41,7 +41,7 @@ import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
41
41
  import { SecretValue } from '@aztec/foundation/config';
42
42
  import { randomBytes } from '@aztec/foundation/crypto/random';
43
43
  import { tryRmDir } from '@aztec/foundation/fs';
44
- import { withLogNameSuffix } from '@aztec/foundation/log';
44
+ import { withLoggerBindings } from '@aztec/foundation/log/server';
45
45
  import { retryUntil } from '@aztec/foundation/retry';
46
46
  import { sleep } from '@aztec/foundation/sleep';
47
47
  import { DateProvider, TestDateProvider } from '@aztec/foundation/timer';
@@ -67,7 +67,7 @@ import {
67
67
  initTelemetryClient,
68
68
  } from '@aztec/telemetry-client';
69
69
  import { BenchmarkTelemetryClient } from '@aztec/telemetry-client/bench';
70
- import { TestWallet, deployFundedSchnorrAccounts } from '@aztec/test-wallet/server';
70
+ import { deployFundedSchnorrAccounts } from '@aztec/wallets/testing';
71
71
  import { getGenesisValues } from '@aztec/world-state/testing';
72
72
 
73
73
  import type { Anvil } from '@viem/anvil';
@@ -84,6 +84,7 @@ import {
84
84
  } from 'viem/accounts';
85
85
  import { type Chain, foundry } from 'viem/chains';
86
86
 
87
+ import { TestWallet } from '../test-wallet/test_wallet.js';
87
88
  import { MNEMONIC, TEST_MAX_PENDING_TX_POOL_COUNT, TEST_PEER_CHECK_INTERVAL_MS } from './fixtures.js';
88
89
  import { getACVMConfig } from './get_acvm_config.js';
89
90
  import { getBBConfig } from './get_bb_config.js';
@@ -92,9 +93,6 @@ import { getEndToEndTestTelemetryClient } from './with_telemetry_utils.js';
92
93
 
93
94
  export { startAnvil };
94
95
 
95
- const { AZTEC_NODE_URL = '' } = process.env;
96
- const getAztecUrl = () => AZTEC_NODE_URL;
97
-
98
96
  let telemetry: TelemetryClient | undefined = undefined;
99
97
  async function getTelemetryClient(partialConfig: Partial<TelemetryClientConfig> & { benchmark?: boolean } = {}) {
100
98
  if (!telemetry) {
@@ -125,14 +123,14 @@ export async function setupSharedBlobStorage(config: { dataDirectory?: string }
125
123
  * @param aztecNode - An instance of Aztec Node.
126
124
  * @param opts - Partial configuration for the PXE.
127
125
  * @param logger - The logger to be used.
128
- * @param useLogSuffix - Whether to add a randomly generated suffix to the PXE debug logs.
126
+ * @param actor - Actor label to include in log output (e.g., 'pxe-test').
129
127
  * @returns A test wallet, logger and teardown function.
130
128
  */
131
129
  export async function setupPXEAndGetWallet(
132
130
  aztecNode: AztecNode,
133
131
  opts: Partial<PXEConfig> = {},
134
132
  logger = getLogger(),
135
- useLogSuffix = false,
133
+ actor?: string,
136
134
  ): Promise<{
137
135
  wallet: TestWallet;
138
136
  logger: Logger;
@@ -150,9 +148,7 @@ export async function setupPXEAndGetWallet(
150
148
 
151
149
  const teardown = configuredDataDirectory ? () => Promise.resolve() : () => tryRmDir(PXEConfig.dataDirectory!);
152
150
 
153
- const wallet = await TestWallet.create(aztecNode, PXEConfig, {
154
- useLogSuffix,
155
- });
151
+ const wallet = await TestWallet.create(aztecNode, PXEConfig, { loggerActorLabel: actor });
156
152
 
157
153
  return {
158
154
  wallet,
@@ -209,6 +205,8 @@ export type SetupOptions = {
209
205
  skipAccountDeployment?: boolean;
210
206
  /** L1 contracts deployment arguments. */
211
207
  l1ContractsArgs?: Partial<DeployAztecL1ContractsArgs>;
208
+ /** Wallet minimum fee padding multiplier (defaults to 0.5, which is 50% padding). */
209
+ walletMinFeePadding?: number;
212
210
  } & Partial<AztecNodeConfig>;
213
211
 
214
212
  /** Context for an end-to-end test as returned by the `setup` function */
@@ -217,13 +215,13 @@ export type EndToEndContext = {
217
215
  anvil: Anvil | undefined;
218
216
  /** The Aztec Node service or client a connected to it. */
219
217
  aztecNode: AztecNode;
220
- /** The Aztec Node as a service (only set if running locally). */
221
- aztecNodeService: AztecNodeService | undefined;
222
- /** Client to the Aztec Node admin interface (undefined if connected to remote environment) */
223
- aztecNodeAdmin: AztecNodeAdmin | undefined;
218
+ /** The Aztec Node as a service. */
219
+ aztecNodeService: AztecNodeService;
220
+ /** Client to the Aztec Node admin interface. */
221
+ aztecNodeAdmin: AztecNodeAdmin;
224
222
  /** The prover node service (only set if startProverNode is true) */
225
223
  proverNode: ProverNode | undefined;
226
- /** A client to the sequencer service (undefined if connected to remote environment) */
224
+ /** A client to the sequencer service. */
227
225
  sequencer: SequencerClient | undefined;
228
226
  /** Return values from deployAztecL1Contracts function. */
229
227
  deployL1ContractsValues: DeployAztecL1ContractsReturnType;
@@ -243,12 +241,12 @@ export type EndToEndContext = {
243
241
  cheatCodes: CheatCodes;
244
242
  /** The cheat codes for L1 */
245
243
  ethCheatCodes: EthCheatCodes;
246
- /** The anvil test watcher (undefined if connected to remote environment) */
247
- watcher: AnvilTestWatcher | undefined;
248
- /** Allows tweaking current system time, used by the epoch cache only (undefined if connected to remote environment) */
249
- dateProvider: TestDateProvider | undefined;
244
+ /** The anvil test watcher. */
245
+ watcher: AnvilTestWatcher;
246
+ /** Allows tweaking current system time, used by the epoch cache only. */
247
+ dateProvider: TestDateProvider;
250
248
  /** Telemetry client */
251
- telemetryClient: TelemetryClient | undefined;
249
+ telemetryClient: TelemetryClient;
252
250
  /** Mock gossip sub network used for gossipping messages (only if mockGossipSubNetwork was set to true in opts) */
253
251
  mockGossipSubNetwork: MockGossipSubNetwork | undefined;
254
252
  /** Prefilled public data used for setting up nodes. */
@@ -258,82 +256,11 @@ export type EndToEndContext = {
258
256
  /** BB config (only set if running locally). */
259
257
  bbConfig: Awaited<ReturnType<typeof getBBConfig>>;
260
258
  /** Directory to cleanup on teardown. */
261
- directoryToCleanup: string | undefined;
259
+ directoryToCleanup: string;
262
260
  /** Function to stop the started services. */
263
261
  teardown: () => Promise<void>;
264
262
  };
265
263
 
266
- /**
267
- * Function to setup the test against a remote deployment. It is assumed that L1 contract are already deployed
268
- */
269
- async function setupWithRemoteEnvironment(
270
- account: HDAccount | PrivateKeyAccount,
271
- config: AztecNodeConfig,
272
- logger: Logger,
273
- numberOfAccounts: number,
274
- ): Promise<EndToEndContext> {
275
- const aztecNodeUrl = getAztecUrl();
276
- logger.verbose(`Creating Aztec Node client to remote host ${aztecNodeUrl}`);
277
- const aztecNode = createAztecNodeClient(aztecNodeUrl);
278
- await waitForNode(aztecNode, logger);
279
- logger.verbose('JSON RPC client connected to Aztec Node');
280
- logger.verbose(`Retrieving contract addresses from ${aztecNodeUrl}`);
281
- const { l1ContractAddresses, rollupVersion } = await aztecNode.getNodeInfo();
282
-
283
- const l1Client = createExtendedL1Client(config.l1RpcUrls, account, foundry);
284
-
285
- const deployL1ContractsValues: DeployAztecL1ContractsReturnType = {
286
- l1ContractAddresses,
287
- l1Client,
288
- rollupVersion,
289
- };
290
- const ethCheatCodes = new EthCheatCodes(config.l1RpcUrls, new DateProvider());
291
- const wallet = await TestWallet.create(aztecNode);
292
- const cheatCodes = await CheatCodes.create(config.l1RpcUrls, aztecNode, new DateProvider());
293
- const teardown = () => Promise.resolve();
294
-
295
- logger.verbose('Populating wallet from already registered accounts...');
296
- const initialFundedAccounts = await getInitialTestAccountsData();
297
-
298
- if (initialFundedAccounts.length < numberOfAccounts) {
299
- throw new Error(`Required ${numberOfAccounts} accounts. Found ${initialFundedAccounts.length}.`);
300
- }
301
-
302
- const testAccounts = await Promise.all(
303
- initialFundedAccounts.slice(0, numberOfAccounts).map(async account => {
304
- const accountManager = await wallet.createSchnorrAccount(account.secret, account.salt, account.signingKey);
305
- return accountManager.address;
306
- }),
307
- );
308
-
309
- return {
310
- anvil: undefined,
311
- aztecNode,
312
- aztecNodeService: undefined,
313
- aztecNodeAdmin: undefined,
314
- sequencer: undefined,
315
- proverNode: undefined,
316
- deployL1ContractsValues,
317
- config,
318
- aztecNodeConfig: config,
319
- initialFundedAccounts,
320
- wallet,
321
- accounts: testAccounts,
322
- logger,
323
- cheatCodes,
324
- ethCheatCodes,
325
- prefilledPublicData: undefined,
326
- mockGossipSubNetwork: undefined,
327
- watcher: undefined,
328
- dateProvider: undefined,
329
- telemetryClient: undefined,
330
- acvmConfig: undefined,
331
- bbConfig: undefined,
332
- directoryToCleanup: undefined,
333
- teardown,
334
- };
335
- }
336
-
337
264
  /**
338
265
  * Sets up the environment for the end-to-end tests.
339
266
  * @param numberOfAccounts - The number of new accounts to be created once the PXE is initiated.
@@ -376,16 +303,10 @@ export async function setup(
376
303
  if (!isAnvilTestChain(chain.id)) {
377
304
  throw new Error(`No ETHEREUM_HOSTS set but non anvil chain requested`);
378
305
  }
379
- if (AZTEC_NODE_URL) {
380
- throw new Error(
381
- `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`,
382
- );
383
- }
384
-
385
306
  const res = await startAnvil({
386
307
  l1BlockTime: opts.ethereumSlotDuration,
387
308
  accounts: opts.anvilAccounts,
388
- port: opts.anvilPort,
309
+ port: opts.anvilPort ?? (process.env.ANVIL_PORT ? parseInt(process.env.ANVIL_PORT) : undefined),
389
310
  });
390
311
  anvil = res.anvil;
391
312
  config.l1RpcUrls = [res.rpcUrl];
@@ -436,11 +357,6 @@ export async function setup(
436
357
  config.coinbase = EthAddress.fromString(publisherHdAccount.address);
437
358
  }
438
359
 
439
- if (AZTEC_NODE_URL) {
440
- // we are setting up against a remote environment, l1 contracts are assumed to already be deployed
441
- return await setupWithRemoteEnvironment(publisherHdAccount!, config, logger, numberOfAccounts);
442
- }
443
-
444
360
  // Determine which addresses to fund in genesis
445
361
  const initialFundedAccounts =
446
362
  opts.initialFundedAccounts ??
@@ -567,10 +483,12 @@ export async function setup(
567
483
  }
568
484
  }
569
485
 
570
- const aztecNodeService = await AztecNodeService.createAndSync(
571
- config,
572
- { dateProvider, telemetry: telemetryClient, p2pClientDeps, logger: createLogger('node:MAIN-aztec-node') },
573
- { prefilledPublicData },
486
+ const aztecNodeService = await withLoggerBindings({ actor: 'node-0' }, () =>
487
+ AztecNodeService.createAndSync(
488
+ config,
489
+ { dateProvider, telemetry: telemetryClient, p2pClientDeps },
490
+ { prefilledPublicData },
491
+ ),
574
492
  );
575
493
  const sequencerClient = aztecNodeService.getSequencer();
576
494
 
@@ -588,7 +506,7 @@ export async function setup(
588
506
  const proverNodeConfig = {
589
507
  ...config.proverNodeConfig,
590
508
  dataDirectory: proverNodeDataDirectory,
591
- p2pEnabled: false,
509
+ p2pEnabled: !!mockGossipSubNetwork,
592
510
  };
593
511
  proverNode = await createAndSyncProverNode(
594
512
  proverNodePrivateKeyHex,
@@ -596,6 +514,11 @@ export async function setup(
596
514
  proverNodeConfig,
597
515
  aztecNodeService,
598
516
  prefilledPublicData,
517
+ {
518
+ p2pClientDeps: mockGossipSubNetwork
519
+ ? { p2pServiceFactory: getMockPubSubP2PServiceFactory(mockGossipSubNetwork) }
520
+ : undefined,
521
+ },
599
522
  );
600
523
  }
601
524
 
@@ -604,7 +527,11 @@ export async function setup(
604
527
  pxeConfig.dataDirectory = path.join(directoryToCleanup, randomBytes(8).toString('hex'));
605
528
  // For tests we only want proving enabled if specifically requested
606
529
  pxeConfig.proverEnabled = !!pxeOpts.proverEnabled;
607
- const wallet = await TestWallet.create(aztecNodeService, pxeConfig);
530
+ const wallet = await TestWallet.create(aztecNodeService, pxeConfig, { loggerActorLabel: 'pxe-0' });
531
+
532
+ if (opts.walletMinFeePadding !== undefined) {
533
+ wallet.setMinFeePadding(opts.walletMinFeePadding);
534
+ }
608
535
 
609
536
  const cheatCodes = await CheatCodes.create(config.l1RpcUrls, aztecNodeService, dateProvider);
610
537
 
@@ -629,7 +556,7 @@ export async function setup(
629
556
  `${numberOfAccounts} accounts are being deployed. Reliably progressing past genesis by setting minTxsPerBlock to 1 and waiting for the accounts to be deployed`,
630
557
  );
631
558
  const accountsData = initialFundedAccounts.slice(0, numberOfAccounts);
632
- const accountManagers = await deployFundedSchnorrAccounts(wallet, aztecNodeService, accountsData);
559
+ const accountManagers = await deployFundedSchnorrAccounts(wallet, accountsData);
633
560
  accounts = accountManagers.map(accountManager => accountManager.address);
634
561
  } else if (needsEmptyBlock) {
635
562
  logger.info('No accounts are being deployed, waiting for an empty block 1 to be mined');
@@ -672,7 +599,7 @@ export async function setup(
672
599
  logger.error(`Error during e2e test teardown`, err);
673
600
  } finally {
674
601
  try {
675
- await telemetryClient?.stop();
602
+ await telemetryClient.stop();
676
603
  } catch (err) {
677
604
  logger.error(`Error during telemetry client stop`, err);
678
605
  }
@@ -786,7 +713,7 @@ export function createAndSyncProverNode(
786
713
  prefilledPublicData: PublicDataTreeLeaf[] = [],
787
714
  proverNodeDeps: ProverNodeDeps = {},
788
715
  ) {
789
- return withLogNameSuffix('prover-node', async () => {
716
+ return withLoggerBindings({ actor: 'prover-0' }, async () => {
790
717
  const aztecNodeTxProvider = aztecNode && {
791
718
  getTxByHash: aztecNode.getTxByHash.bind(aztecNode),
792
719
  getTxsByHash: aztecNode.getTxsByHash.bind(aztecNode),
@@ -921,13 +848,11 @@ export async function ensureAccountContractsPublished(wallet: Wallet, accountsTo
921
848
  ).map(contractMetadata => contractMetadata.instance);
922
849
  const contractClass = await getContractClassFromArtifact(SchnorrAccountContractArtifact);
923
850
  if (!(await wallet.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered) {
924
- await (await publishContractClass(wallet, SchnorrAccountContractArtifact))
925
- .send({ from: accountsToDeploy[0] })
926
- .wait();
851
+ await (await publishContractClass(wallet, SchnorrAccountContractArtifact)).send({ from: accountsToDeploy[0] });
927
852
  }
928
853
  const requests = instances.map(instance => publishInstance(wallet, instance!));
929
854
  const batch = new BatchCall(wallet, requests);
930
- await batch.send({ from: accountsToDeploy[0] }).wait();
855
+ await batch.send({ from: accountsToDeploy[0] });
931
856
  }
932
857
 
933
858
  /**
@@ -951,12 +876,10 @@ export const deployAccounts =
951
876
  deployedAccounts[i].signingKey,
952
877
  );
953
878
  const deployMethod = await accountManager.getDeployMethod();
954
- await deployMethod
955
- .send({
956
- from: AztecAddress.ZERO,
957
- skipClassPublication: i !== 0, // Publish the contract class at most once.
958
- })
959
- .wait();
879
+ await deployMethod.send({
880
+ from: AztecAddress.ZERO,
881
+ skipClassPublication: i !== 0, // Publish the contract class at most once.
882
+ });
960
883
  }
961
884
 
962
885
  return { deployedAccounts };
@@ -986,7 +909,7 @@ export async function publicDeployAccounts(
986
909
 
987
910
  const batch = new BatchCall(wallet, calls);
988
911
 
989
- const txReceipt = await batch.send({ from: accountsToDeploy[0] }).wait();
912
+ const txReceipt = await batch.send({ from: accountsToDeploy[0] });
990
913
  if (waitUntilProven) {
991
914
  if (!node) {
992
915
  throw new Error('Need to provide an AztecNode to wait for proven.');