@aztec/end-to-end 0.0.1-commit.cd76b27 → 0.0.1-commit.d0fcfb7f

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 (85) hide show
  1. package/dest/bench/client_flows/client_flows_benchmark.d.ts +1 -1
  2. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  3. package/dest/bench/client_flows/client_flows_benchmark.js +15 -8
  4. package/dest/bench/utils.d.ts +1 -1
  5. package/dest/bench/utils.d.ts.map +1 -1
  6. package/dest/bench/utils.js +6 -3
  7. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +1 -1
  8. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  9. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +14 -14
  10. package/dest/e2e_epochs/epochs_test.d.ts +1 -1
  11. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  12. package/dest/e2e_epochs/epochs_test.js +2 -1
  13. package/dest/e2e_fees/fees_test.d.ts +1 -1
  14. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  15. package/dest/e2e_fees/fees_test.js +13 -6
  16. package/dest/e2e_nested_contract/nested_contract_test.d.ts +1 -1
  17. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  18. package/dest/e2e_nested_contract/nested_contract_test.js +4 -6
  19. package/dest/e2e_p2p/p2p_network.d.ts +1 -1
  20. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  21. package/dest/e2e_p2p/p2p_network.js +2 -3
  22. package/dest/e2e_p2p/shared.js +1 -1
  23. package/dest/e2e_token_contract/token_contract_test.d.ts +1 -1
  24. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  25. package/dest/e2e_token_contract/token_contract_test.js +11 -11
  26. package/dest/fixtures/authwit_proxy.d.ts +3 -3
  27. package/dest/fixtures/authwit_proxy.d.ts.map +1 -1
  28. package/dest/fixtures/e2e_prover_test.d.ts +1 -1
  29. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  30. package/dest/fixtures/e2e_prover_test.js +6 -6
  31. package/dest/fixtures/setup.d.ts +2 -3
  32. package/dest/fixtures/setup.d.ts.map +1 -1
  33. package/dest/fixtures/setup.js +3 -3
  34. package/dest/fixtures/token_utils.d.ts +1 -1
  35. package/dest/fixtures/token_utils.d.ts.map +1 -1
  36. package/dest/fixtures/token_utils.js +2 -2
  37. package/dest/shared/cross_chain_test_harness.d.ts +1 -1
  38. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  39. package/dest/shared/cross_chain_test_harness.js +13 -13
  40. package/dest/shared/gas_portal_test_harness.js +2 -2
  41. package/dest/shared/submit-transactions.js +1 -1
  42. package/dest/shared/uniswap_l1_l2.d.ts +1 -1
  43. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  44. package/dest/shared/uniswap_l1_l2.js +14 -17
  45. package/dest/simulators/lending_simulator.d.ts +1 -1
  46. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  47. package/dest/simulators/lending_simulator.js +2 -2
  48. package/dest/simulators/token_simulator.d.ts +1 -1
  49. package/dest/simulators/token_simulator.d.ts.map +1 -1
  50. package/dest/simulators/token_simulator.js +2 -2
  51. package/dest/spartan/setup_test_wallets.d.ts +4 -2
  52. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  53. package/dest/spartan/setup_test_wallets.js +23 -10
  54. package/dest/spartan/utils/index.d.ts +2 -1
  55. package/dest/spartan/utils/index.d.ts.map +1 -1
  56. package/dest/spartan/utils/index.js +2 -0
  57. package/dest/test-wallet/wallet_worker_script.js +41 -33
  58. package/dest/test-wallet/worker_wallet.d.ts +1 -1
  59. package/dest/test-wallet/worker_wallet.d.ts.map +1 -1
  60. package/dest/test-wallet/worker_wallet.js +51 -3
  61. package/dest/test-wallet/worker_wallet_schema.d.ts +5 -2
  62. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -1
  63. package/package.json +40 -40
  64. package/src/bench/client_flows/client_flows_benchmark.ts +37 -30
  65. package/src/bench/utils.ts +7 -2
  66. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +18 -14
  67. package/src/e2e_epochs/epochs_test.ts +1 -0
  68. package/src/e2e_fees/fees_test.ts +13 -6
  69. package/src/e2e_nested_contract/nested_contract_test.ts +6 -4
  70. package/src/e2e_p2p/p2p_network.ts +3 -2
  71. package/src/e2e_p2p/shared.ts +1 -1
  72. package/src/e2e_token_contract/token_contract_test.ts +16 -8
  73. package/src/fixtures/e2e_prover_test.ts +11 -5
  74. package/src/fixtures/setup.ts +7 -6
  75. package/src/fixtures/token_utils.ts +4 -2
  76. package/src/shared/cross_chain_test_harness.ts +13 -9
  77. package/src/shared/gas_portal_test_harness.ts +1 -1
  78. package/src/shared/submit-transactions.ts +1 -1
  79. package/src/shared/uniswap_l1_l2.ts +35 -28
  80. package/src/simulators/lending_simulator.ts +4 -2
  81. package/src/simulators/token_simulator.ts +6 -2
  82. package/src/spartan/setup_test_wallets.ts +49 -14
  83. package/src/spartan/utils/index.ts +3 -0
  84. package/src/test-wallet/wallet_worker_script.ts +47 -30
  85. package/src/test-wallet/worker_wallet.ts +51 -3
@@ -130,7 +130,9 @@ export const uniswapL1L2TestSuite = (
130
130
  client: l1Client,
131
131
  });
132
132
  // deploy l2 uniswap contract and attach to portal
133
- uniswapL2Contract = await UniswapContract.deploy(wallet, uniswapPortalAddress).send({ from: ownerAddress });
133
+ ({ contract: uniswapL2Contract } = await UniswapContract.deploy(wallet, uniswapPortalAddress).send({
134
+ from: ownerAddress,
135
+ }));
134
136
 
135
137
  const registryAddress = (await aztecNode.getNodeInfo()).l1ContractAddresses.registryAddress;
136
138
 
@@ -195,7 +197,7 @@ export const uniswapL1L2TestSuite = (
195
197
  logger.info('Withdrawing weth to L1 and sending message to swap to dai');
196
198
  const [secretForDepositingSwappedDai, secretHashForDepositingSwappedDai] = await generateClaimSecret();
197
199
 
198
- const l2UniswapInteractionReceipt = await uniswapL2Contract.methods
200
+ const { receipt: l2UniswapInteractionReceipt } = await uniswapL2Contract.methods
199
201
  .swap_private(
200
202
  wethCrossChainHarness.l2Token.address,
201
203
  wethCrossChainHarness.l2Bridge.address,
@@ -250,8 +252,12 @@ export const uniswapL1L2TestSuite = (
250
252
  await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n);
251
253
 
252
254
  // Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
253
- const block = await aztecNode.getBlock(l2UniswapInteractionReceipt.blockNumber!);
254
- const epoch = await rollup.getEpochNumberForCheckpoint(block!.checkpointNumber);
255
+ const swapResult = (await computeL2ToL1MembershipWitness(
256
+ aztecNode,
257
+ swapPrivateLeaf,
258
+ l2UniswapInteractionReceipt.txHash,
259
+ ))!;
260
+ const { epochNumber: epoch } = swapResult;
255
261
  await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
256
262
  await waitForProven(aztecNode, l2UniswapInteractionReceipt, { provenTimeout: 300 });
257
263
 
@@ -260,14 +266,17 @@ export const uniswapL1L2TestSuite = (
260
266
  const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf(
261
267
  daiCrossChainHarness.tokenPortalAddress,
262
268
  );
263
- const swapResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, swapPrivateLeaf);
264
- const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, withdrawLeaf);
269
+ const withdrawResult = (await computeL2ToL1MembershipWitness(
270
+ aztecNode,
271
+ withdrawLeaf,
272
+ l2UniswapInteractionReceipt.txHash,
273
+ ))!;
265
274
 
266
- const swapPrivateL2MessageIndex = swapResult!.leafIndex;
267
- const swapPrivateSiblingPath = swapResult!.siblingPath;
275
+ const swapPrivateL2MessageIndex = swapResult.leafIndex;
276
+ const swapPrivateSiblingPath = swapResult.siblingPath;
268
277
 
269
- const withdrawL2MessageIndex = withdrawResult!.leafIndex;
270
- const withdrawSiblingPath = withdrawResult!.siblingPath;
278
+ const withdrawL2MessageIndex = withdrawResult.leafIndex;
279
+ const withdrawSiblingPath = withdrawResult.siblingPath;
271
280
 
272
281
  const withdrawMessageMetadata = {
273
282
  _epoch: BigInt(epoch),
@@ -787,7 +796,7 @@ export const uniswapL1L2TestSuite = (
787
796
  logger.info('Withdrawing weth to L1 and sending message to swap to dai');
788
797
 
789
798
  const [, secretHashForDepositingSwappedDai] = await generateClaimSecret();
790
- const withdrawReceipt = await uniswapL2Contract.methods
799
+ const { receipt: withdrawReceipt } = await uniswapL2Contract.methods
791
800
  .swap_private(
792
801
  wethCrossChainHarness.l2Token.address,
793
802
  wethCrossChainHarness.l2Bridge.address,
@@ -838,16 +847,15 @@ export const uniswapL1L2TestSuite = (
838
847
  chainId: new Fr(l1Client.chain.id),
839
848
  });
840
849
 
841
- const block = await aztecNode.getBlock(withdrawReceipt.blockNumber!);
842
- const epoch = await rollup.getEpochNumberForCheckpoint(block!.checkpointNumber);
843
- const swapResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, swapPrivateLeaf);
844
- const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, withdrawLeaf);
850
+ const swapResult = (await computeL2ToL1MembershipWitness(aztecNode, swapPrivateLeaf, withdrawReceipt.txHash))!;
851
+ const { epochNumber: epoch } = swapResult;
852
+ const withdrawResult = (await computeL2ToL1MembershipWitness(aztecNode, withdrawLeaf, withdrawReceipt.txHash))!;
845
853
 
846
- const swapPrivateL2MessageIndex = swapResult!.leafIndex;
847
- const swapPrivateSiblingPath = swapResult!.siblingPath;
854
+ const swapPrivateL2MessageIndex = swapResult.leafIndex;
855
+ const swapPrivateSiblingPath = swapResult.siblingPath;
848
856
 
849
- const withdrawL2MessageIndex = withdrawResult!.leafIndex;
850
- const withdrawSiblingPath = withdrawResult!.siblingPath;
857
+ const withdrawL2MessageIndex = withdrawResult.leafIndex;
858
+ const withdrawSiblingPath = withdrawResult.siblingPath;
851
859
 
852
860
  const withdrawMessageMetadata = {
853
861
  _epoch: BigInt(epoch),
@@ -915,7 +923,7 @@ export const uniswapL1L2TestSuite = (
915
923
 
916
924
  // Call swap_public on L2
917
925
  const secretHashForDepositingSwappedDai = Fr.random();
918
- const withdrawReceipt = await uniswapL2Contract.methods
926
+ const { receipt: withdrawReceipt } = await uniswapL2Contract.methods
919
927
  .swap_public(
920
928
  ownerAddress,
921
929
  wethCrossChainHarness.l2Bridge.address,
@@ -971,16 +979,15 @@ export const uniswapL1L2TestSuite = (
971
979
  chainId: new Fr(l1Client.chain.id),
972
980
  });
973
981
 
974
- const block = await aztecNode.getBlock(withdrawReceipt.blockNumber!);
975
- const epoch = await rollup.getEpochNumberForCheckpoint(block!.checkpointNumber);
976
- const swapResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, swapPublicLeaf);
977
- const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, withdrawLeaf);
982
+ const swapResult = (await computeL2ToL1MembershipWitness(aztecNode, swapPublicLeaf, withdrawReceipt.txHash))!;
983
+ const { epochNumber: epoch } = swapResult;
984
+ const withdrawResult = (await computeL2ToL1MembershipWitness(aztecNode, withdrawLeaf, withdrawReceipt.txHash))!;
978
985
 
979
- const swapPublicL2MessageIndex = swapResult!.leafIndex;
980
- const swapPublicSiblingPath = swapResult!.siblingPath;
986
+ const swapPublicL2MessageIndex = swapResult.leafIndex;
987
+ const swapPublicSiblingPath = swapResult.siblingPath;
981
988
 
982
- const withdrawL2MessageIndex = withdrawResult!.leafIndex;
983
- const withdrawSiblingPath = withdrawResult!.siblingPath;
989
+ const withdrawL2MessageIndex = withdrawResult.leafIndex;
990
+ const withdrawSiblingPath = withdrawResult.siblingPath;
984
991
 
985
992
  const withdrawMessageMetadata = {
986
993
  _epoch: BigInt(epoch),
@@ -186,14 +186,16 @@ export class LendingSimulator {
186
186
 
187
187
  expect(this.borrowed).toEqual(this.stableCoin.totalSupply - this.mintedOutside);
188
188
 
189
- const asset = await this.lendingContract.methods.get_asset(0).simulate({ from: this.account.address });
189
+ const { result: asset } = await this.lendingContract.methods.get_asset(0).simulate({ from: this.account.address });
190
190
 
191
191
  const interestAccumulator = asset['interest_accumulator'];
192
192
  expect(interestAccumulator).toEqual(this.accumulator);
193
193
  expect(asset['last_updated_ts']).toEqual(BigInt(this.time));
194
194
 
195
195
  for (const key of [this.account.address, AztecAddress.fromField(await this.account.key())]) {
196
- const privatePos = await this.lendingContract.methods.get_position(key).simulate({ from: this.account.address });
196
+ const { result: privatePos } = await this.lendingContract.methods
197
+ .get_position(key)
198
+ .simulate({ from: this.account.address });
197
199
  expect(new Fr(privatePos['collateral'])).toEqual(this.collateral[key.toString()] ?? Fr.ZERO);
198
200
  expect(new Fr(privatePos['static_debt'])).toEqual(this.staticDebt[key.toString()] ?? Fr.ZERO);
199
201
  expect(privatePos['debt']).toEqual(
@@ -109,7 +109,9 @@ export class TokenSimulator {
109
109
  await Promise.all(
110
110
  chunk(calls, 5).map(batch => new BatchCall(this.defaultWallet, batch).simulate({ from: this.defaultAddress })),
111
111
  )
112
- ).flat();
112
+ )
113
+ .flat()
114
+ .map(r => r.result);
113
115
  expect(results[0]).toEqual(this.totalSupply);
114
116
 
115
117
  // Check that all our balances match
@@ -123,7 +125,9 @@ export class TokenSimulator {
123
125
  const wallet = this.lookupProvider.get(address.toString());
124
126
  const asset = wallet ? this.token.withWallet(wallet) : this.token;
125
127
 
126
- const actualPrivateBalance = await asset.methods.balance_of_private(address).simulate({ from: address });
128
+ const { result: actualPrivateBalance } = await asset.methods
129
+ .balance_of_private(address)
130
+ .simulate({ from: address });
127
131
  expect(actualPrivateBalance).toEqual(this.balanceOfPrivate(address));
128
132
  }
129
133
  }
@@ -121,16 +121,28 @@ export async function deploySponsoredTestAccountsWithTokens(
121
121
  }
122
122
 
123
123
  async function deployAccountWithDiagnostics(
124
- account: { getDeployMethod: () => Promise<{ send: (opts: any) => any }>; address: any },
124
+ account: { getDeployMethod: () => Promise<{ simulate: (opts: any) => any; send: (opts: any) => any }>; address: any },
125
125
  paymentMethod: SponsoredFeePaymentMethod,
126
126
  aztecNode: AztecNode,
127
127
  logger: Logger,
128
128
  accountLabel: string,
129
+ estimateGas?: boolean,
129
130
  ): Promise<void> {
130
131
  const deployMethod = await account.getDeployMethod();
131
132
  let txHash;
132
133
  try {
133
- txHash = await deployMethod.send({ from: AztecAddress.ZERO, fee: { paymentMethod }, wait: NO_WAIT });
134
+ let gasSettings;
135
+ if (estimateGas) {
136
+ const sim = await deployMethod.simulate({ from: AztecAddress.ZERO, fee: { paymentMethod } });
137
+ gasSettings = sim.estimatedGas;
138
+ logger.info(`${accountLabel} estimated gas: DA=${gasSettings.gasLimits.daGas} L2=${gasSettings.gasLimits.l2Gas}`);
139
+ }
140
+ const deployResult = await deployMethod.send({
141
+ from: AztecAddress.ZERO,
142
+ fee: { paymentMethod, gasSettings },
143
+ wait: NO_WAIT,
144
+ });
145
+ txHash = deployResult.txHash;
134
146
  await waitForTx(aztecNode, txHash, { timeout: 2400 });
135
147
  logger.info(`${accountLabel} deployed at ${account.address}`);
136
148
  } catch (error) {
@@ -152,18 +164,29 @@ async function deployAccountWithDiagnostics(
152
164
  }
153
165
 
154
166
  async function deployAccountsInBatches(
155
- accounts: { getDeployMethod: () => Promise<{ send: (opts: any) => any }>; address: any }[],
167
+ accounts: {
168
+ getDeployMethod: () => Promise<{ simulate: (opts: any) => any; send: (opts: any) => any }>;
169
+ address: any;
170
+ }[],
156
171
  paymentMethod: SponsoredFeePaymentMethod,
157
172
  aztecNode: AztecNode,
158
173
  logger: Logger,
159
174
  labelPrefix: string,
160
175
  batchSize = 2,
176
+ estimateGas?: boolean,
161
177
  ): Promise<void> {
162
178
  for (let i = 0; i < accounts.length; i += batchSize) {
163
179
  const batch = accounts.slice(i, i + batchSize);
164
180
  await Promise.all(
165
181
  batch.map((account, idx) =>
166
- deployAccountWithDiagnostics(account, paymentMethod, aztecNode, logger, `${labelPrefix}${i + idx + 1}`),
182
+ deployAccountWithDiagnostics(
183
+ account,
184
+ paymentMethod,
185
+ aztecNode,
186
+ logger,
187
+ `${labelPrefix}${i + idx + 1}`,
188
+ estimateGas,
189
+ ),
167
190
  ),
168
191
  );
169
192
  }
@@ -174,6 +197,7 @@ export async function deploySponsoredTestAccounts(
174
197
  aztecNode: AztecNode,
175
198
  logger: Logger,
176
199
  numberOfFundedWallets = 1,
200
+ opts?: { estimateGas?: boolean },
177
201
  ): Promise<TestAccountsWithoutTokens> {
178
202
  const [recipient, ...funded] = await generateSchnorrAccounts(numberOfFundedWallets + 1);
179
203
  const recipientAccount = await wallet.createSchnorrAccount(recipient.secret, recipient.salt);
@@ -183,8 +207,23 @@ export async function deploySponsoredTestAccounts(
183
207
 
184
208
  const paymentMethod = new SponsoredFeePaymentMethod(await getSponsoredFPCAddress());
185
209
 
186
- await deployAccountWithDiagnostics(recipientAccount, paymentMethod, aztecNode, logger, 'Recipient account');
187
- await deployAccountsInBatches(fundedAccounts, paymentMethod, aztecNode, logger, 'Funded account ', 2);
210
+ await deployAccountWithDiagnostics(
211
+ recipientAccount,
212
+ paymentMethod,
213
+ aztecNode,
214
+ logger,
215
+ 'Recipient account',
216
+ opts?.estimateGas,
217
+ );
218
+ await deployAccountsInBatches(
219
+ fundedAccounts,
220
+ paymentMethod,
221
+ aztecNode,
222
+ logger,
223
+ 'Funded account ',
224
+ 2,
225
+ opts?.estimateGas,
226
+ );
188
227
 
189
228
  return {
190
229
  aztecNode,
@@ -266,7 +305,7 @@ async function bridgeL1FeeJuice(
266
305
  const claim = await portal.bridgeTokensPublic(recipient, amount, true /* mint */);
267
306
 
268
307
  const isSynced = async () =>
269
- (await aztecNode.getL1ToL2MessageBlock(Fr.fromHexString(claim.messageHash))) !== undefined;
308
+ (await aztecNode.getL1ToL2MessageCheckpoint(Fr.fromHexString(claim.messageHash))) !== undefined;
270
309
  await retryUntil(isSynced, `message ${claim.messageHash} sync`, 24, 0.5);
271
310
 
272
311
  log.info(`Created a claim for ${amount} L1 fee juice to ${recipient}.`, claim);
@@ -298,13 +337,9 @@ async function deployTokenAndMint(
298
337
  logger: Logger,
299
338
  ) {
300
339
  logger.verbose(`Deploying TokenContract...`);
301
- const { contract: tokenContract } = await TokenContract.deploy(
302
- wallet,
303
- admin,
304
- TOKEN_NAME,
305
- TOKEN_SYMBOL,
306
- TOKEN_DECIMALS,
307
- ).send({
340
+ const {
341
+ receipt: { contract: tokenContract },
342
+ } = await TokenContract.deploy(wallet, admin, TOKEN_NAME, TOKEN_SYMBOL, TOKEN_DECIMALS).send({
308
343
  from: admin,
309
344
  fee: {
310
345
  paymentMethod,
@@ -41,6 +41,9 @@ export {
41
41
  applyNetworkShaping,
42
42
  } from './chaos.js';
43
43
 
44
+ // Helm
45
+ export { hasDeployedHelmRelease } from './helm.js';
46
+
44
47
  // Bot management
45
48
  export { restartBot, installTransferBot, uninstallTransferBot } from './bot.js';
46
49
 
@@ -1,43 +1,60 @@
1
1
  import { createAztecNodeClient } from '@aztec/aztec.js/node';
2
+ import type { SendOptions } from '@aztec/aztec.js/wallet';
2
3
  import { jsonStringify } from '@aztec/foundation/json-rpc';
3
- import type { ApiSchema } from '@aztec/foundation/schemas';
4
+ import { createLogger } from '@aztec/foundation/log';
5
+ import type { ApiSchema, Fr } from '@aztec/foundation/schemas';
4
6
  import { parseWithOptionals, schemaHasMethod } from '@aztec/foundation/schemas';
5
7
  import { NodeListener, TransportServer } from '@aztec/foundation/transport';
8
+ import { ExecutionPayload, Tx } from '@aztec/stdlib/tx';
6
9
 
7
10
  import { workerData } from 'worker_threads';
8
11
 
9
12
  import { TestWallet } from './test_wallet.js';
10
13
  import { WorkerWalletSchema } from './worker_wallet_schema.js';
11
14
 
12
- const { nodeUrl, pxeConfig } = workerData as { nodeUrl: string; pxeConfig?: Record<string, unknown> };
15
+ const logger = createLogger('e2e:test-wallet:worker');
13
16
 
14
- const node = createAztecNodeClient(nodeUrl);
15
- const wallet = await TestWallet.create(node, pxeConfig);
17
+ try {
18
+ const { nodeUrl, pxeConfig } = workerData as { nodeUrl: string; pxeConfig?: Record<string, unknown> };
16
19
 
17
- /** Handlers for methods that need custom implementation (not direct wallet passthrough). */
18
- const handlers: Record<string, (...args: any[]) => Promise<any>> = {
19
- proveTx: async (exec, opts) => {
20
- const provenTx = await wallet.proveTx(exec, opts);
21
- // ProvenTx has non-serializable fields (node proxy, etc.) — extract only Tx-compatible fields
22
- const { data, chonkProof, contractClassLogFields, publicFunctionCalldata } = provenTx;
23
- return { data, chonkProof, contractClassLogFields, publicFunctionCalldata };
24
- },
25
- registerAccount: async (secret, salt) => {
26
- const manager = await wallet.createSchnorrAccount(secret, salt);
27
- return manager.address;
28
- },
29
- };
20
+ logger.info('Initializing worker wallet', { nodeUrl });
21
+ const node = createAztecNodeClient(nodeUrl);
22
+ const wallet = await TestWallet.create(node, pxeConfig);
23
+ logger.info('Worker wallet initialized');
30
24
 
31
- const schema = WorkerWalletSchema as ApiSchema;
32
- const listener = new NodeListener();
33
- const server = new TransportServer<{ fn: string; args: string }>(listener, async msg => {
34
- if (!schemaHasMethod(schema, msg.fn)) {
35
- throw new Error(`Unknown method: ${msg.fn}`);
36
- }
37
- const jsonParams = JSON.parse(msg.args) as unknown[];
38
- const args = await parseWithOptionals(jsonParams, schema[msg.fn].parameters());
39
- const handler = handlers[msg.fn];
40
- const result = handler ? await handler(...args) : await (wallet as any)[msg.fn](...args);
41
- return jsonStringify(result);
42
- });
43
- server.start();
25
+ const customMethods = {
26
+ proveTx: async (exec: ExecutionPayload, opts: Omit<SendOptions, 'wait'>) => {
27
+ const provenTx = await wallet.proveTx(exec, opts);
28
+ return new Tx(
29
+ provenTx.getTxHash(),
30
+ provenTx.data,
31
+ provenTx.chonkProof,
32
+ provenTx.contractClassLogFields,
33
+ provenTx.publicFunctionCalldata,
34
+ );
35
+ },
36
+ registerAccount: async (secret: Fr, salt: Fr) => {
37
+ const manager = await wallet.createSchnorrAccount(secret, salt);
38
+ return manager.address;
39
+ },
40
+ };
41
+
42
+ const schema = WorkerWalletSchema as ApiSchema;
43
+ const listener = new NodeListener();
44
+ const server = new TransportServer<{ fn: string; args: string }>(listener, async msg => {
45
+ if (!schemaHasMethod(schema, msg.fn)) {
46
+ throw new Error(`Unknown method: ${msg.fn}`);
47
+ }
48
+ const jsonParams = JSON.parse(msg.args) as unknown[];
49
+ const args: any[] = await parseWithOptionals(jsonParams, schema[msg.fn].parameters());
50
+ // we have to erase the fn type in order to be able to spread ...args
51
+ const handler: ((...args: any[]) => Promise<any>) | undefined =
52
+ msg.fn in customMethods ? customMethods[msg.fn as keyof typeof customMethods] : undefined;
53
+ const result = handler ? await handler(...args) : await (wallet as any)[msg.fn](...args);
54
+ return jsonStringify(result);
55
+ });
56
+ server.start();
57
+ } catch (err: unknown) {
58
+ logger.error('Worker wallet initialization failed', { error: err instanceof Error ? err.stack : String(err) });
59
+ process.exit(1);
60
+ }
@@ -19,7 +19,10 @@ import type {
19
19
  import type { ChainInfo } from '@aztec/entrypoints/interfaces';
20
20
  import type { Fr } from '@aztec/foundation/curves/bn254';
21
21
  import { jsonStringify } from '@aztec/foundation/json-rpc';
22
+ import { createLogger } from '@aztec/foundation/log';
23
+ import { promiseWithResolvers } from '@aztec/foundation/promise';
22
24
  import type { ApiSchema } from '@aztec/foundation/schemas';
25
+ import { sleep } from '@aztec/foundation/sleep';
23
26
  import { NodeConnector, TransportClient } from '@aztec/foundation/transport';
24
27
  import type { PXEConfig } from '@aztec/pxe/config';
25
28
  import type { ContractArtifact, EventMetadataDefinition, FunctionCall } from '@aztec/stdlib/abi';
@@ -35,6 +38,10 @@ import { WorkerWalletSchema } from './worker_wallet_schema.js';
35
38
 
36
39
  type WorkerMsg = { fn: string; args: string };
37
40
 
41
+ const log = createLogger('e2e:test-wallet:worker-wallet');
42
+
43
+ const WORKER_READY_TIMEOUT_MS = 120_000;
44
+
38
45
  /**
39
46
  * Wallet implementation that offloads all work to a worker thread.
40
47
  * Implements the Wallet interface by proxying calls over a transport layer
@@ -53,8 +60,18 @@ export class WorkerWallet implements Wallet {
53
60
  * @returns A WorkerWallet ready to use.
54
61
  */
55
62
  static async create(nodeUrl: string, pxeConfig?: Partial<PXEConfig>): Promise<WorkerWallet> {
56
- const worker = new Worker(new URL('./wallet_worker_script.js', import.meta.url), {
63
+ // replace stc/ with dest/ so the wallet works in Jest tests
64
+ const workerUrl = new URL('./wallet_worker_script.js', import.meta.url);
65
+ workerUrl.pathname = workerUrl.pathname.replace('/src/', '/dest/');
66
+ // remove JEST_WORKER_ID so the worker uses pino-pretty transport instead of Jest's raw output.
67
+ const { JEST_WORKER_ID: _, ...parentEnv } = process.env;
68
+ const worker = new Worker(workerUrl, {
57
69
  workerData: { nodeUrl, pxeConfig },
70
+ env: {
71
+ ...parentEnv,
72
+ ...(process.stderr.isTTY || process.env.FORCE_COLOR ? { FORCE_COLOR: '1' } : {}),
73
+ LOG_LEVEL: process.env.WORKER_LOG_LEVEL ?? 'warn',
74
+ },
58
75
  });
59
76
 
60
77
  const connector = new NodeConnector(worker);
@@ -62,8 +79,39 @@ export class WorkerWallet implements Wallet {
62
79
  await client.open();
63
80
 
64
81
  const wallet = new WorkerWallet(worker, client);
65
- // Warmup / readiness check — blocks until the worker has finished creating the TestWallet.
66
- await wallet.getChainInfo();
82
+
83
+ const { promise: workerDied, reject: rejectWorkerDied } = promiseWithResolvers<void>();
84
+ // reject if the worker exits or errors before the warmup completes.
85
+ const onError = (err: Error): void => {
86
+ worker.off('exit', onExit!);
87
+ rejectWorkerDied(new Error(`Worker wallet thread error: ${err.message}`));
88
+ };
89
+
90
+ const onExit = (code: number): void => {
91
+ worker.off('error', onError!);
92
+ rejectWorkerDied(new Error(`Worker wallet thread exited with code ${code} before becoming ready`));
93
+ };
94
+
95
+ worker.once('error', onError);
96
+ worker.once('exit', onExit);
97
+
98
+ const timeout = sleep(WORKER_READY_TIMEOUT_MS).then(() => {
99
+ throw new Error(`Worker wallet creation timed out after ${WORKER_READY_TIMEOUT_MS / 1000}s`);
100
+ });
101
+
102
+ try {
103
+ // wait for worker wallet to start
104
+ await Promise.race([wallet.getChainInfo(), workerDied, timeout]);
105
+ } catch (err) {
106
+ log.error('Worker wallet creation failed, cleaning up', { error: String(err) });
107
+ client.close();
108
+ await worker.terminate();
109
+ throw err;
110
+ } finally {
111
+ worker.off('error', onError);
112
+ worker.off('exit', onExit);
113
+ }
114
+
67
115
  return wallet;
68
116
  }
69
117