@aztec/end-to-end 4.0.0-devnet.1-patch.0 → 4.0.0-devnet.1-patch.1

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 (53) 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 +1 -1
  4. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +2 -2
  5. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  6. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +2 -2
  7. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  8. package/dest/e2e_deploy_contract/deploy_test.d.ts +2 -2
  9. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  10. package/dest/e2e_fees/fees_test.d.ts +2 -2
  11. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  12. package/dest/e2e_p2p/p2p_network.d.ts +2 -2
  13. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  14. package/dest/e2e_p2p/shared.d.ts +2 -2
  15. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  16. package/dest/e2e_p2p/shared.js +2 -1
  17. package/dest/e2e_token_contract/token_contract_test.d.ts +2 -2
  18. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  19. package/dest/fixtures/e2e_prover_test.d.ts +2 -2
  20. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  21. package/dest/fixtures/setup.d.ts +2 -2
  22. package/dest/fixtures/setup.d.ts.map +1 -1
  23. package/dest/fixtures/setup.js +2 -1
  24. package/dest/shared/submit-transactions.d.ts +2 -2
  25. package/dest/shared/submit-transactions.d.ts.map +1 -1
  26. package/dest/shared/uniswap_l1_l2.d.ts +1 -1
  27. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  28. package/dest/spartan/setup_test_wallets.d.ts +2 -2
  29. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  30. package/dest/spartan/setup_test_wallets.js +3 -1
  31. package/dest/test-wallet/test_wallet.d.ts +82 -0
  32. package/dest/test-wallet/test_wallet.d.ts.map +1 -0
  33. package/dest/test-wallet/test_wallet.js +213 -0
  34. package/dest/test-wallet/utils.d.ts +41 -0
  35. package/dest/test-wallet/utils.d.ts.map +1 -0
  36. package/dest/test-wallet/utils.js +71 -0
  37. package/package.json +40 -39
  38. package/src/bench/client_flows/client_flows_benchmark.ts +1 -1
  39. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +1 -1
  40. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +1 -1
  41. package/src/e2e_deploy_contract/deploy_test.ts +1 -1
  42. package/src/e2e_fees/bridging_race.notest.ts +1 -1
  43. package/src/e2e_fees/fees_test.ts +1 -1
  44. package/src/e2e_p2p/p2p_network.ts +1 -1
  45. package/src/e2e_p2p/shared.ts +2 -1
  46. package/src/e2e_token_contract/token_contract_test.ts +1 -1
  47. package/src/fixtures/e2e_prover_test.ts +1 -1
  48. package/src/fixtures/setup.ts +2 -1
  49. package/src/shared/submit-transactions.ts +2 -1
  50. package/src/shared/uniswap_l1_l2.ts +1 -1
  51. package/src/spartan/setup_test_wallets.ts +3 -1
  52. package/src/test-wallet/test_wallet.ts +296 -0
  53. package/src/test-wallet/utils.ts +112 -0
@@ -27,7 +27,6 @@ import { tryStop } from '@aztec/stdlib/interfaces/server';
27
27
  import { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
28
28
  import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
29
29
  import { ZkPassportProofParams } from '@aztec/stdlib/zkpassport';
30
- import type { TestWallet } from '@aztec/test-wallet/server';
31
30
  import { getGenesisValues } from '@aztec/world-state/testing';
32
31
 
33
32
  import getPort from 'get-port';
@@ -49,6 +48,7 @@ import {
49
48
  generatePrivateKeys,
50
49
  } from '../fixtures/setup_p2p_test.js';
51
50
  import { getEndToEndTestTelemetryClient } from '../fixtures/with_telemetry_utils.js';
51
+ import type { TestWallet } from '../test-wallet/test_wallet.js';
52
52
 
53
53
  // Use a fixed bootstrap node private key so that we can re-use the same snapshot and the nodes can find each other
54
54
  const BOOTSTRAP_NODE_PRIVATE_KEY = '080212208f988fc0899e4a73a5aee4d271a5f20670603a756ad8d84f2c94263a6427c591';
@@ -22,9 +22,10 @@ import { getPXEConfig, getPXEConfig as getRpcConfig } from '@aztec/pxe/server';
22
22
  import { getRoundForOffense } from '@aztec/slasher';
23
23
  import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
24
24
  import type { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
25
- import { type ProvenTx, TestWallet, proveInteraction } from '@aztec/test-wallet/server';
26
25
 
27
26
  import { submitTxsTo } from '../shared/submit-transactions.js';
27
+ import { TestWallet } from '../test-wallet/test_wallet.js';
28
+ import { type ProvenTx, proveInteraction } from '../test-wallet/utils.js';
28
29
 
29
30
  // submits a set of transactions to the provided Private eXecution Environment (PXE)
30
31
  export const submitComplexTxsTo = async (
@@ -3,13 +3,13 @@ import { type Logger, createLogger } from '@aztec/aztec.js/log';
3
3
  import type { AztecNode } from '@aztec/aztec.js/node';
4
4
  import { TokenContract } from '@aztec/noir-contracts.js/Token';
5
5
  import { InvalidAccountContract } from '@aztec/noir-test-contracts.js/InvalidAccount';
6
- import type { TestWallet } from '@aztec/test-wallet/server';
7
6
 
8
7
  import { jest } from '@jest/globals';
9
8
 
10
9
  import { type EndToEndContext, deployAccounts, publicDeployAccounts, setup, teardown } from '../fixtures/setup.js';
11
10
  import { mintTokensToPrivate } from '../fixtures/token_utils.js';
12
11
  import { TokenSimulator } from '../simulators/token_simulator.js';
12
+ import type { TestWallet } from '../test-wallet/test_wallet.js';
13
13
 
14
14
  const { METRICS_PORT: metricsPort } = process.env;
15
15
 
@@ -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 {
@@ -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';
@@ -4,7 +4,8 @@ import { Fr, GrumpkinScalar } from '@aztec/aztec.js/fields';
4
4
  import type { Logger } from '@aztec/aztec.js/log';
5
5
  import { TxHash, type TxReceipt, TxStatus } from '@aztec/aztec.js/tx';
6
6
  import { times } from '@aztec/foundation/collection';
7
- import type { TestWallet } from '@aztec/test-wallet/server';
7
+
8
+ import type { TestWallet } from '../test-wallet/test_wallet.js';
8
9
 
9
10
  // submits a set of transactions to the provided Wallet
10
11
  export const submitTxsTo = async (
@@ -17,12 +17,12 @@ import { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-art
17
17
  import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
18
18
  import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
19
19
  import { computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
20
- import type { TestWallet } from '@aztec/test-wallet/server';
21
20
 
22
21
  import { jest } from '@jest/globals';
23
22
  import { type GetContractReturnType, getContract, parseEther, toFunctionSelector } from 'viem';
24
23
 
25
24
  import { type EndToEndContext, ensureAccountContractsPublished } from '../fixtures/utils.js';
25
+ import type { TestWallet } from '../test-wallet/test_wallet.js';
26
26
  import { CrossChainTestHarness } from './cross_chain_test_harness.js';
27
27
 
28
28
  // PSA: This tests works on forked mainnet. There is a dump of the data in `dumpedState` such that we
@@ -13,11 +13,13 @@ import type { Logger } from '@aztec/foundation/log';
13
13
  import { retryUntil } from '@aztec/foundation/retry';
14
14
  import { TokenContract } from '@aztec/noir-contracts.js/Token';
15
15
  import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
16
- import { TestWallet, proveInteraction, registerInitialLocalNetworkAccountsInWallet } from '@aztec/test-wallet/server';
16
+ import { registerInitialLocalNetworkAccountsInWallet } from '@aztec/wallets/testing';
17
17
 
18
18
  import { getACVMConfig } from '../fixtures/get_acvm_config.js';
19
19
  import { getBBConfig } from '../fixtures/get_bb_config.js';
20
20
  import { getSponsoredFPCAddress, registerSponsoredFPC } from '../fixtures/utils.js';
21
+ import { TestWallet } from '../test-wallet/test_wallet.js';
22
+ import { proveInteraction } from '../test-wallet/utils.js';
21
23
 
22
24
  export interface TestAccounts {
23
25
  aztecNode: AztecNode;
@@ -0,0 +1,296 @@
1
+ import { EcdsaKAccountContract, EcdsaRAccountContract } from '@aztec/accounts/ecdsa';
2
+ import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
3
+ import { StubAccountContractArtifact, createStubAccount } from '@aztec/accounts/stub';
4
+ import { type Account, type AccountContract, SignerlessAccount } from '@aztec/aztec.js/account';
5
+ import {
6
+ type CallIntent,
7
+ type ContractFunctionInteractionCallIntent,
8
+ type IntentInnerHash,
9
+ SetPublicAuthwitContractInteraction,
10
+ computeInnerAuthWitHashFromAction,
11
+ isContractFunctionInteractionCallIntent,
12
+ lookupValidity,
13
+ } from '@aztec/aztec.js/authorization';
14
+ import type { AztecNode } from '@aztec/aztec.js/node';
15
+ import { AccountManager, type SendOptions } from '@aztec/aztec.js/wallet';
16
+ import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
17
+ import { Fq, Fr } from '@aztec/foundation/curves/bn254';
18
+ import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
19
+ import { type PXEConfig, getPXEConfig } from '@aztec/pxe/config';
20
+ import { PXE, type PXECreationOptions, createPXE } from '@aztec/pxe/server';
21
+ import { AuthWitness } from '@aztec/stdlib/auth-witness';
22
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
23
+ import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
24
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
25
+ import type { NoteDao, NotesFilter } from '@aztec/stdlib/note';
26
+ import type { BlockHeader, TxHash, TxReceipt, TxSimulationResult } from '@aztec/stdlib/tx';
27
+ import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
28
+ import { BaseWallet, type FeeOptions } from '@aztec/wallet-sdk/base-wallet';
29
+
30
+ import { AztecNodeProxy, ProvenTx } from './utils.js';
31
+
32
+ /**
33
+ * Data for generating an account.
34
+ */
35
+ export interface AccountData {
36
+ secret: Fr;
37
+ salt: Fr;
38
+ contract: AccountContract;
39
+ }
40
+
41
+ /**
42
+ * Wallet implementation that stores accounts in memory and provides extra debugging
43
+ * utilities
44
+ * It is intended to be used in e2e tests.
45
+ */
46
+ export class TestWallet extends BaseWallet {
47
+ constructor(
48
+ pxe: PXE,
49
+ private readonly nodeRef: AztecNodeProxy,
50
+ ) {
51
+ super(pxe, nodeRef);
52
+ }
53
+
54
+ static async create(
55
+ node: AztecNode,
56
+ overridePXEConfig?: Partial<PXEConfig>,
57
+ options: PXECreationOptions = { loggers: {} },
58
+ ): Promise<TestWallet> {
59
+ const nodeRef = new AztecNodeProxy(node);
60
+ const pxeConfig = Object.assign(getPXEConfig(), {
61
+ proverEnabled: overridePXEConfig?.proverEnabled ?? false,
62
+ ...overridePXEConfig,
63
+ });
64
+ const pxe = await createPXE(nodeRef, pxeConfig, options);
65
+ return new TestWallet(pxe, nodeRef);
66
+ }
67
+
68
+ /**
69
+ * Updates the underlying node that this wallet and its PXE communicate with.
70
+ * @param node - The new AztecNode to forward all calls to.
71
+ */
72
+ updateNode(node: AztecNode): void {
73
+ this.nodeRef.updateTargetNode(node);
74
+ }
75
+
76
+ createSchnorrAccount(secret: Fr, salt: Fr, signingKey?: Fq): Promise<AccountManager> {
77
+ signingKey = signingKey ?? deriveSigningKey(secret);
78
+ const accountData = {
79
+ secret,
80
+ salt,
81
+ contract: new SchnorrAccountContract(signingKey),
82
+ };
83
+ return this.createAccount(accountData);
84
+ }
85
+
86
+ createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager> {
87
+ const accountData = {
88
+ secret,
89
+ salt,
90
+ contract: new EcdsaRAccountContract(signingKey),
91
+ };
92
+ return this.createAccount(accountData);
93
+ }
94
+
95
+ createECDSAKAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager> {
96
+ const accountData = {
97
+ secret,
98
+ salt,
99
+ contract: new EcdsaKAccountContract(signingKey),
100
+ };
101
+ return this.createAccount(accountData);
102
+ }
103
+
104
+ async getFakeAccountDataFor(address: AztecAddress) {
105
+ const originalAccount = await this.getAccountFromAddress(address);
106
+ if (originalAccount instanceof SignerlessAccount) {
107
+ throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
108
+ }
109
+ const originalAddress = (originalAccount as Account).getCompleteAddress();
110
+ const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
111
+ if (!contractInstance) {
112
+ throw new Error(`No contract instance found for address: ${originalAddress.address}`);
113
+ }
114
+ const stubAccount = createStubAccount(originalAddress);
115
+ const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
116
+ salt: Fr.random(),
117
+ });
118
+ return {
119
+ account: stubAccount,
120
+ instance,
121
+ artifact: StubAccountContractArtifact,
122
+ };
123
+ }
124
+ protected accounts: Map<string, Account> = new Map();
125
+
126
+ /**
127
+ * Toggle for running "simulated simulations" when calling simulateTx.
128
+ *
129
+ * When this flag is true, simulateViaEntrypoint constructs a request using a fake account
130
+ * (and accepts contract overrides on the input) and the PXE emulates kernel effects without
131
+ * generating kernel witnesses. When false, simulateViaEntrypoint defers to the standard
132
+ * simulation path via the real account entrypoint.
133
+ */
134
+ private simulatedSimulations = false;
135
+
136
+ enableSimulatedSimulations() {
137
+ this.simulatedSimulations = true;
138
+ }
139
+
140
+ disableSimulatedSimulations() {
141
+ this.simulatedSimulations = false;
142
+ }
143
+
144
+ setMinFeePadding(value?: number) {
145
+ this.minFeePadding = value ?? 0.5;
146
+ }
147
+
148
+ protected getAccountFromAddress(address: AztecAddress): Promise<Account> {
149
+ let account: Account | undefined;
150
+ if (address.equals(AztecAddress.ZERO)) {
151
+ account = new SignerlessAccount();
152
+ } else {
153
+ account = this.accounts.get(address?.toString() ?? '');
154
+ }
155
+
156
+ if (!account) {
157
+ throw new Error(`Account not found in wallet for address: ${address}`);
158
+ }
159
+
160
+ return Promise.resolve(account);
161
+ }
162
+
163
+ getAccounts() {
164
+ return Promise.resolve(Array.from(this.accounts.values()).map(acc => ({ alias: '', item: acc.getAddress() })));
165
+ }
166
+
167
+ async createAccount(accountData?: AccountData): Promise<AccountManager> {
168
+ const secret = accountData?.secret ?? Fr.random();
169
+ const salt = accountData?.salt ?? Fr.random();
170
+ const contract = accountData?.contract ?? new SchnorrAccountContract(GrumpkinScalar.random());
171
+
172
+ const accountManager = await AccountManager.create(this, secret, contract, salt);
173
+
174
+ const instance = accountManager.getInstance();
175
+ const artifact = await contract.getContractArtifact();
176
+
177
+ await this.registerContract(instance, artifact, secret);
178
+
179
+ this.accounts.set(accountManager.address.toString(), await accountManager.getAccount());
180
+
181
+ return accountManager;
182
+ }
183
+
184
+ lookupValidity(
185
+ onBehalfOf: AztecAddress,
186
+ intent: IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
187
+ witness: AuthWitness,
188
+ ): Promise<{
189
+ isValidInPrivate: boolean;
190
+ isValidInPublic: boolean;
191
+ }> {
192
+ return lookupValidity(this, onBehalfOf, intent, witness);
193
+ }
194
+
195
+ public setPublicAuthWit(
196
+ from: AztecAddress,
197
+ messageHashOrIntent: Fr | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
198
+ authorized: boolean,
199
+ ): Promise<SetPublicAuthwitContractInteraction> {
200
+ return SetPublicAuthwitContractInteraction.create(this, from, messageHashOrIntent, authorized);
201
+ }
202
+
203
+ public override async createAuthWit(
204
+ from: AztecAddress,
205
+ intent: IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
206
+ ): Promise<AuthWitness> {
207
+ const account = await this.getAccountFromAddress(from);
208
+ const chainInfo = await this.getChainInfo();
209
+ let intentInnerHash: IntentInnerHash;
210
+ if ('caller' in intent) {
211
+ const call = isContractFunctionInteractionCallIntent(intent)
212
+ ? await intent.action.getFunctionCall()
213
+ : intent.call;
214
+ const innerHash = await computeInnerAuthWitHashFromAction(intent.caller, call);
215
+ intentInnerHash = { innerHash, consumer: call.to };
216
+ } else {
217
+ intentInnerHash = intent;
218
+ }
219
+ return account.createAuthWit(intentInnerHash, chainInfo);
220
+ }
221
+
222
+ /**
223
+ * Override simulateViaEntrypoint to use fake accounts for kernelless simulation
224
+ * when simulatedSimulations is enabled. Otherwise falls through to the real entrypoint path.
225
+ */
226
+ protected override async simulateViaEntrypoint(
227
+ executionPayload: ExecutionPayload,
228
+ from: AztecAddress,
229
+ feeOptions: FeeOptions,
230
+ skipTxValidation?: boolean,
231
+ skipFeeEnforcement?: boolean,
232
+ ): Promise<TxSimulationResult> {
233
+ if (!this.simulatedSimulations) {
234
+ return super.simulateViaEntrypoint(executionPayload, from, feeOptions, skipTxValidation, skipFeeEnforcement);
235
+ }
236
+
237
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
238
+ const executionOptions: DefaultAccountEntrypointOptions = {
239
+ txNonce: Fr.random(),
240
+ cancellable: this.cancellableTransactions,
241
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
242
+ };
243
+ const finalExecutionPayload = feeExecutionPayload
244
+ ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
245
+ : executionPayload;
246
+ const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(from);
247
+ const chainInfo = await this.getChainInfo();
248
+ const txRequest = await fromAccount.createTxExecutionRequest(
249
+ finalExecutionPayload,
250
+ feeOptions.gasSettings,
251
+ chainInfo,
252
+ executionOptions,
253
+ );
254
+ const contractOverrides = {
255
+ [from.toString()]: { instance, artifact },
256
+ };
257
+ return this.pxe.simulateTx(txRequest, {
258
+ simulatePublic: true,
259
+ skipFeeEnforcement: true,
260
+ skipTxValidation: true,
261
+ overrides: { contracts: contractOverrides },
262
+ });
263
+ }
264
+
265
+ async proveTx(exec: ExecutionPayload, opts: Omit<SendOptions, 'wait'>): Promise<ProvenTx> {
266
+ const fee = await this.completeFeeOptions(opts.from, exec.feePayer, opts.fee?.gasSettings);
267
+ const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(exec, opts.from, fee);
268
+ const txProvingResult = await this.pxe.proveTx(txRequest);
269
+ return new ProvenTx(
270
+ this.aztecNode,
271
+ await txProvingResult.toTx(),
272
+ txProvingResult.getOffchainEffects(),
273
+ txProvingResult.stats,
274
+ );
275
+ }
276
+
277
+ getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
278
+ return this.aztecNode.getTxReceipt(txHash);
279
+ }
280
+
281
+ getNotes(filter: NotesFilter): Promise<NoteDao[]> {
282
+ return this.pxe.debug.getNotes(filter);
283
+ }
284
+
285
+ getSyncedBlockHeader(): Promise<BlockHeader> {
286
+ return this.pxe.getSyncedBlockHeader();
287
+ }
288
+
289
+ sync(): Promise<void> {
290
+ return this.pxe.debug.sync();
291
+ }
292
+
293
+ stop(): Promise<void> {
294
+ return this.pxe.stop();
295
+ }
296
+ }
@@ -0,0 +1,112 @@
1
+ import {
2
+ ContractFunctionInteraction,
3
+ DeployMethod,
4
+ type DeployOptions,
5
+ NO_WAIT,
6
+ type NoWait,
7
+ type SendInteractionOptions,
8
+ type WaitOpts,
9
+ toSendOptions,
10
+ } from '@aztec/aztec.js/contracts';
11
+ import { type AztecNode, waitForTx } from '@aztec/aztec.js/node';
12
+ import { SimulationError } from '@aztec/stdlib/errors';
13
+ import { type OffchainEffect, type ProvingStats, Tx, TxHash, type TxReceipt } from '@aztec/stdlib/tx';
14
+
15
+ import { inspect } from 'util';
16
+
17
+ import type { TestWallet } from './test_wallet.js';
18
+
19
+ export type ProvenTxSendOpts = {
20
+ wait?: NoWait | WaitOpts;
21
+ };
22
+
23
+ export type ProvenTxSendReturn<T extends NoWait | WaitOpts | undefined> = T extends NoWait ? TxHash : TxReceipt;
24
+
25
+ export class ProvenTx extends Tx {
26
+ constructor(
27
+ private node: AztecNode,
28
+ tx: Tx,
29
+ public offchainEffects: OffchainEffect[],
30
+ public stats?: ProvingStats,
31
+ ) {
32
+ super(tx.getTxHash(), tx.data, tx.chonkProof, tx.contractClassLogFields, tx.publicFunctionCalldata);
33
+ }
34
+
35
+ send(options?: Omit<ProvenTxSendOpts, 'wait'>): Promise<TxReceipt>;
36
+ send<W extends ProvenTxSendOpts['wait']>(options: ProvenTxSendOpts & { wait: W }): Promise<ProvenTxSendReturn<W>>;
37
+ async send(options?: ProvenTxSendOpts): Promise<TxHash | TxReceipt> {
38
+ const txHash = this.getTxHash();
39
+ await this.node.sendTx(this).catch(err => {
40
+ throw this.contextualizeError(err, inspect(this));
41
+ });
42
+
43
+ if (options?.wait === NO_WAIT) {
44
+ return txHash;
45
+ }
46
+
47
+ const waitOpts = typeof options?.wait === 'object' ? options.wait : undefined;
48
+ return await waitForTx(this.node, txHash, waitOpts);
49
+ }
50
+
51
+ private contextualizeError(err: Error, ...context: string[]): Error {
52
+ let contextStr = '';
53
+ if (context.length > 0) {
54
+ contextStr = `\nContext:\n${context.join('\n')}`;
55
+ }
56
+ if (err instanceof SimulationError) {
57
+ err.setAztecContext(contextStr);
58
+ }
59
+ return err;
60
+ }
61
+ }
62
+
63
+ export async function proveInteraction(
64
+ wallet: TestWallet,
65
+ interaction: ContractFunctionInteraction | DeployMethod,
66
+ options: SendInteractionOptions | DeployOptions,
67
+ ) {
68
+ let execPayload;
69
+ if (interaction instanceof DeployMethod) {
70
+ execPayload = await interaction.request(interaction.convertDeployOptionsToRequestOptions(options));
71
+ } else {
72
+ execPayload = await interaction.request(options);
73
+ }
74
+ return wallet.proveTx(execPayload, toSendOptions(options));
75
+ }
76
+
77
+ /**
78
+ * Extends AztecNode via declaration merging so instances can be used wherever AztecNode is expected.
79
+ * The actual method forwarding is handled by a Proxy in the class constructor.
80
+ */
81
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
82
+ export interface AztecNodeProxy extends AztecNode {}
83
+
84
+ /**
85
+ * Mutable wrapper around an AztecNode that forwards all calls to the current target.
86
+ * Allows swapping the underlying node at runtime via updateTargetNode, which is useful
87
+ * for tests that need to redirect a wallet from one node to another without recreating it.
88
+ */
89
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
90
+ export class AztecNodeProxy {
91
+ constructor(private target: AztecNode) {
92
+ return new Proxy(this, {
93
+ get: (obj, prop, receiver) => {
94
+ // Own properties and methods (updateTargetNode, target) are served directly.
95
+ if (Reflect.has(obj, prop)) {
96
+ return Reflect.get(obj, prop, receiver);
97
+ }
98
+ // Everything else is forwarded to the current target node.
99
+ const val = (obj.target as unknown as Record<string | symbol, unknown>)[prop];
100
+ return typeof val === 'function' ? val.bind(obj.target) : val;
101
+ },
102
+ });
103
+ }
104
+
105
+ /**
106
+ * Updates the underlying node that this reference points to.
107
+ * @param node - The new node to forward calls to.
108
+ */
109
+ updateTargetNode(node: AztecNode): void {
110
+ this.target = node;
111
+ }
112
+ }