@aztec/end-to-end 0.0.1-commit.e2b2873ed → 0.0.1-commit.e304674f1
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.
- package/README.md +27 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts +1 -1
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
- package/dest/bench/client_flows/client_flows_benchmark.js +19 -26
- package/dest/bench/utils.d.ts +1 -1
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/bench/utils.js +6 -3
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +2 -2
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +16 -16
- package/dest/e2e_epochs/epochs_test.d.ts +11 -7
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +60 -38
- package/dest/e2e_fees/fees_test.d.ts +1 -1
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +14 -7
- package/dest/e2e_nested_contract/nested_contract_test.d.ts +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +4 -6
- package/dest/e2e_p2p/inactivity_slash_test.js +3 -3
- package/dest/e2e_p2p/p2p_network.d.ts +8 -9
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +32 -19
- package/dest/e2e_p2p/reqresp/utils.d.ts +3 -3
- package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -1
- package/dest/e2e_p2p/reqresp/utils.js +46 -9
- package/dest/e2e_p2p/shared.d.ts +25 -7
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +49 -44
- package/dest/e2e_token_contract/token_contract_test.d.ts +2 -2
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +13 -13
- package/dest/fixtures/authwit_proxy.d.ts +15 -0
- package/dest/fixtures/authwit_proxy.d.ts.map +1 -0
- package/dest/fixtures/authwit_proxy.js +34 -0
- package/dest/fixtures/e2e_prover_test.d.ts +6 -5
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
- package/dest/fixtures/e2e_prover_test.js +37 -49
- package/dest/fixtures/elu_monitor.d.ts +21 -0
- package/dest/fixtures/elu_monitor.d.ts.map +1 -0
- package/dest/fixtures/elu_monitor.js +102 -0
- package/dest/fixtures/fixtures.d.ts +5 -1
- package/dest/fixtures/fixtures.d.ts.map +1 -1
- package/dest/fixtures/fixtures.js +6 -0
- package/dest/fixtures/get_bb_config.d.ts +1 -1
- package/dest/fixtures/get_bb_config.d.ts.map +1 -1
- package/dest/fixtures/get_bb_config.js +5 -5
- package/dest/fixtures/ha_setup.d.ts +1 -1
- package/dest/fixtures/ha_setup.d.ts.map +1 -1
- package/dest/fixtures/ha_setup.js +3 -1
- package/dest/fixtures/setup.d.ts +33 -11
- package/dest/fixtures/setup.d.ts.map +1 -1
- package/dest/fixtures/setup.js +68 -89
- package/dest/fixtures/setup_p2p_test.d.ts +10 -7
- package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
- package/dest/fixtures/setup_p2p_test.js +18 -15
- package/dest/fixtures/token_utils.d.ts +2 -2
- package/dest/fixtures/token_utils.d.ts.map +1 -1
- package/dest/fixtures/token_utils.js +5 -7
- package/dest/legacy-jest-resolver.d.cts +3 -0
- package/dest/legacy-jest-resolver.d.cts.map +1 -0
- package/dest/shared/cross_chain_test_harness.d.ts +1 -1
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +13 -13
- package/dest/shared/gas_portal_test_harness.js +2 -2
- package/dest/shared/index.d.ts +2 -1
- package/dest/shared/index.d.ts.map +1 -1
- package/dest/shared/index.js +1 -0
- package/dest/shared/jest_setup.js +41 -1
- package/dest/shared/mock_state_view.d.ts +86 -0
- package/dest/shared/mock_state_view.d.ts.map +1 -0
- package/dest/shared/mock_state_view.js +186 -0
- package/dest/shared/submit-transactions.js +1 -1
- package/dest/shared/uniswap_l1_l2.d.ts +1 -1
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.js +14 -17
- package/dest/simulators/lending_simulator.d.ts +1 -1
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +4 -4
- package/dest/simulators/token_simulator.d.ts +1 -1
- package/dest/simulators/token_simulator.d.ts.map +1 -1
- package/dest/simulators/token_simulator.js +2 -2
- package/dest/spartan/setup_test_wallets.d.ts +11 -2
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +97 -38
- package/dest/spartan/tx_metrics.js +1 -1
- package/dest/spartan/utils/bot.d.ts +3 -2
- package/dest/spartan/utils/bot.d.ts.map +1 -1
- package/dest/spartan/utils/bot.js +2 -1
- package/dest/spartan/utils/config.d.ts +7 -1
- package/dest/spartan/utils/config.d.ts.map +1 -1
- package/dest/spartan/utils/config.js +3 -1
- package/dest/spartan/utils/index.d.ts +4 -2
- package/dest/spartan/utils/index.d.ts.map +1 -1
- package/dest/spartan/utils/index.js +5 -1
- package/dest/spartan/utils/k8s.d.ts +3 -1
- package/dest/spartan/utils/k8s.d.ts.map +1 -1
- package/dest/spartan/utils/k8s.js +6 -0
- package/dest/spartan/utils/nodes.d.ts +4 -5
- package/dest/spartan/utils/nodes.d.ts.map +1 -1
- package/dest/spartan/utils/nodes.js +9 -9
- package/dest/spartan/utils/pod_logs.d.ts +25 -0
- package/dest/spartan/utils/pod_logs.d.ts.map +1 -0
- package/dest/spartan/utils/pod_logs.js +74 -0
- package/dest/test-wallet/test_wallet.d.ts +16 -23
- package/dest/test-wallet/test_wallet.d.ts.map +1 -1
- package/dest/test-wallet/test_wallet.js +73 -65
- package/dest/test-wallet/wallet_worker_script.d.ts +2 -0
- package/dest/test-wallet/wallet_worker_script.d.ts.map +1 -0
- package/dest/test-wallet/wallet_worker_script.js +48 -0
- package/dest/test-wallet/worker_wallet.d.ts +52 -0
- package/dest/test-wallet/worker_wallet.d.ts.map +1 -0
- package/dest/test-wallet/worker_wallet.js +151 -0
- package/dest/test-wallet/worker_wallet_schema.d.ts +274 -0
- package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -0
- package/dest/test-wallet/worker_wallet_schema.js +10 -0
- package/package.json +43 -44
- package/src/bench/client_flows/client_flows_benchmark.ts +27 -10
- package/src/bench/utils.ts +7 -2
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +20 -16
- package/src/e2e_epochs/epochs_test.ts +78 -66
- package/src/e2e_fees/fees_test.ts +14 -7
- package/src/e2e_nested_contract/nested_contract_test.ts +6 -4
- package/src/e2e_p2p/inactivity_slash_test.ts +3 -3
- package/src/e2e_p2p/p2p_network.ts +47 -28
- package/src/e2e_p2p/reqresp/utils.ts +58 -9
- package/src/e2e_p2p/shared.ts +71 -59
- package/src/e2e_token_contract/token_contract_test.ts +18 -10
- package/src/fixtures/authwit_proxy.ts +54 -0
- package/src/fixtures/dumps/epoch_proof_result.json +1 -1
- package/src/fixtures/e2e_prover_test.ts +43 -52
- package/src/fixtures/elu_monitor.ts +126 -0
- package/src/fixtures/fixtures.ts +10 -0
- package/src/fixtures/get_bb_config.ts +7 -6
- package/src/fixtures/ha_setup.ts +3 -1
- package/src/fixtures/setup.ts +97 -124
- package/src/fixtures/setup_p2p_test.ts +17 -25
- package/src/fixtures/token_utils.ts +3 -3
- package/src/legacy-jest-resolver.cjs +135 -0
- package/src/shared/cross_chain_test_harness.ts +13 -9
- package/src/shared/gas_portal_test_harness.ts +1 -1
- package/src/shared/index.ts +1 -0
- package/src/shared/jest_setup.ts +51 -1
- package/src/shared/mock_state_view.ts +188 -0
- package/src/shared/submit-transactions.ts +1 -1
- package/src/shared/uniswap_l1_l2.ts +35 -28
- package/src/simulators/lending_simulator.ts +8 -4
- package/src/simulators/token_simulator.ts +6 -2
- package/src/spartan/setup_test_wallets.ts +138 -31
- package/src/spartan/tx_metrics.ts +1 -1
- package/src/spartan/utils/bot.ts +4 -1
- package/src/spartan/utils/config.ts +2 -0
- package/src/spartan/utils/index.ts +7 -0
- package/src/spartan/utils/k8s.ts +8 -0
- package/src/spartan/utils/nodes.ts +15 -10
- package/src/spartan/utils/pod_logs.ts +99 -0
- package/src/test-wallet/test_wallet.ts +101 -80
- package/src/test-wallet/wallet_worker_script.ts +60 -0
- package/src/test-wallet/worker_wallet.ts +213 -0
- package/src/test-wallet/worker_wallet_schema.ts +13 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EcdsaKAccountContract, EcdsaRAccountContract } from '@aztec/accounts/ecdsa';
|
|
2
2
|
import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
|
|
3
3
|
import { StubAccountContractArtifact, createStubAccount } from '@aztec/accounts/stub';
|
|
4
|
-
import { type Account, type AccountContract,
|
|
4
|
+
import { type Account, type AccountContract, NO_FROM } from '@aztec/aztec.js/account';
|
|
5
5
|
import {
|
|
6
6
|
type CallIntent,
|
|
7
7
|
type ContractFunctionInteractionCallIntent,
|
|
@@ -14,18 +14,28 @@ import {
|
|
|
14
14
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
15
15
|
import { AccountManager, type SendOptions } from '@aztec/aztec.js/wallet';
|
|
16
16
|
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
17
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
17
18
|
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
18
19
|
import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
20
|
+
import type { NotesFilter } from '@aztec/pxe/client/lazy';
|
|
19
21
|
import { type PXEConfig, getPXEConfig } from '@aztec/pxe/config';
|
|
20
22
|
import { PXE, type PXECreationOptions, createPXE } from '@aztec/pxe/server';
|
|
21
23
|
import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
22
24
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
23
25
|
import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
|
|
24
26
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
25
|
-
import type { NoteDao
|
|
26
|
-
import
|
|
27
|
+
import type { NoteDao } from '@aztec/stdlib/note';
|
|
28
|
+
import {
|
|
29
|
+
type BlockHeader,
|
|
30
|
+
type ContractOverrides,
|
|
31
|
+
SimulationOverrides,
|
|
32
|
+
type TxExecutionRequest,
|
|
33
|
+
type TxHash,
|
|
34
|
+
type TxReceipt,
|
|
35
|
+
type TxSimulationResult,
|
|
36
|
+
} from '@aztec/stdlib/tx';
|
|
27
37
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
28
|
-
import { BaseWallet, type
|
|
38
|
+
import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
29
39
|
|
|
30
40
|
import { AztecNodeProxy, ProvenTx } from './utils.js';
|
|
31
41
|
|
|
@@ -101,44 +111,51 @@ export class TestWallet extends BaseWallet {
|
|
|
101
111
|
return this.createAccount(accountData);
|
|
102
112
|
}
|
|
103
113
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
|
|
116
|
+
*/
|
|
117
|
+
protected async buildAccountOverrides(addresses: AztecAddress[]): Promise<ContractOverrides> {
|
|
118
|
+
const accounts = await this.getAccounts();
|
|
119
|
+
const contracts: ContractOverrides = {};
|
|
120
|
+
|
|
121
|
+
const filtered = accounts.filter(acc => addresses.some(addr => addr.equals(acc.item)));
|
|
122
|
+
|
|
123
|
+
for (const account of filtered) {
|
|
124
|
+
const address = account.item;
|
|
125
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
126
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
127
|
+
const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
|
|
128
|
+
if (!contractInstance) {
|
|
129
|
+
throw new Error(
|
|
130
|
+
`No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const stubInstance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
|
|
135
|
+
salt: Fr.random(),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
contracts[address.toString()] = {
|
|
139
|
+
instance: stubInstance,
|
|
140
|
+
artifact: StubAccountContractArtifact,
|
|
141
|
+
};
|
|
113
142
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
salt: Fr.random(),
|
|
117
|
-
});
|
|
118
|
-
return {
|
|
119
|
-
account: stubAccount,
|
|
120
|
-
instance,
|
|
121
|
-
artifact: StubAccountContractArtifact,
|
|
122
|
-
};
|
|
143
|
+
|
|
144
|
+
return contracts;
|
|
123
145
|
}
|
|
146
|
+
|
|
124
147
|
protected accounts: Map<string, Account> = new Map();
|
|
125
148
|
|
|
126
149
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* generating kernel witnesses. When false, simulateViaEntrypoint defers to the standard
|
|
132
|
-
* simulation path via the real account entrypoint.
|
|
150
|
+
* Controls how the test wallet simulates transactions:
|
|
151
|
+
* - `kernelless`: Skips kernel circuits but uses the real account contract. Default.
|
|
152
|
+
* - `kernelless-override`: Skips kernels and replaces the account with a stub that doesn't do authwit validation.
|
|
153
|
+
* - `full`: Uses real kernel circuits and real account contracts. Slow!
|
|
133
154
|
*/
|
|
134
|
-
private
|
|
135
|
-
|
|
136
|
-
enableSimulatedSimulations() {
|
|
137
|
-
this.simulatedSimulations = true;
|
|
138
|
-
}
|
|
155
|
+
private simulationMode: 'kernelless' | 'kernelless-override' | 'full' = 'kernelless';
|
|
139
156
|
|
|
140
|
-
|
|
141
|
-
this.
|
|
157
|
+
setSimulationMode(mode: 'kernelless' | 'kernelless-override' | 'full') {
|
|
158
|
+
this.simulationMode = mode;
|
|
142
159
|
}
|
|
143
160
|
|
|
144
161
|
setMinFeePadding(value?: number) {
|
|
@@ -146,12 +163,7 @@ export class TestWallet extends BaseWallet {
|
|
|
146
163
|
}
|
|
147
164
|
|
|
148
165
|
protected getAccountFromAddress(address: AztecAddress): Promise<Account> {
|
|
149
|
-
|
|
150
|
-
if (address.equals(AztecAddress.ZERO)) {
|
|
151
|
-
account = new SignerlessAccount();
|
|
152
|
-
} else {
|
|
153
|
-
account = this.accounts.get(address?.toString() ?? '');
|
|
154
|
-
}
|
|
166
|
+
const account = this.accounts.get(address?.toString() ?? '');
|
|
155
167
|
|
|
156
168
|
if (!account) {
|
|
157
169
|
throw new Error(`Account not found in wallet for address: ${address}`);
|
|
@@ -219,62 +231,71 @@ export class TestWallet extends BaseWallet {
|
|
|
219
231
|
return account.createAuthWit(intentInnerHash, chainInfo);
|
|
220
232
|
}
|
|
221
233
|
|
|
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
234
|
protected override async simulateViaEntrypoint(
|
|
227
235
|
executionPayload: ExecutionPayload,
|
|
228
|
-
|
|
229
|
-
feeOptions: FeeOptions,
|
|
230
|
-
skipTxValidation?: boolean,
|
|
231
|
-
skipFeeEnforcement?: boolean,
|
|
232
|
-
scopes?: AztecAddress[],
|
|
236
|
+
opts: SimulateViaEntrypointOptions,
|
|
233
237
|
): Promise<TxSimulationResult> {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
from,
|
|
238
|
-
feeOptions,
|
|
239
|
-
skipTxValidation,
|
|
240
|
-
skipFeeEnforcement,
|
|
241
|
-
scopes,
|
|
242
|
-
);
|
|
243
|
-
}
|
|
238
|
+
const { from, feeOptions, scopes, skipTxValidation, skipFeeEnforcement } = opts;
|
|
239
|
+
const skipKernels = this.simulationMode !== 'full';
|
|
240
|
+
const useOverride = this.simulationMode === 'kernelless-override';
|
|
244
241
|
|
|
245
242
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
246
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
247
|
-
txNonce: Fr.random(),
|
|
248
|
-
cancellable: this.cancellableTransactions,
|
|
249
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
250
|
-
};
|
|
251
243
|
const finalExecutionPayload = feeExecutionPayload
|
|
252
244
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
253
245
|
: executionPayload;
|
|
254
|
-
const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(from);
|
|
255
246
|
const chainInfo = await this.getChainInfo();
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
247
|
+
|
|
248
|
+
let overrides: SimulationOverrides | undefined;
|
|
249
|
+
let txRequest: TxExecutionRequest;
|
|
250
|
+
if (useOverride) {
|
|
251
|
+
const accountOverrides = await this.buildAccountOverrides(this.scopesFrom(from, opts.additionalScopes));
|
|
252
|
+
overrides = new SimulationOverrides(accountOverrides);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (from === NO_FROM) {
|
|
256
|
+
const entrypoint = new DefaultEntrypoint();
|
|
257
|
+
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
258
|
+
} else {
|
|
259
|
+
let fromAccount: Account;
|
|
260
|
+
if (useOverride) {
|
|
261
|
+
const originalAccount = await this.getAccountFromAddress(from);
|
|
262
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
263
|
+
fromAccount = createStubAccount(completeAddress);
|
|
264
|
+
} else {
|
|
265
|
+
fromAccount = await this.getAccountFromAddress(from);
|
|
266
|
+
}
|
|
267
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
268
|
+
txNonce: Fr.random(),
|
|
269
|
+
cancellable: this.cancellableTransactions,
|
|
270
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
271
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
272
|
+
};
|
|
273
|
+
txRequest = await fromAccount.createTxExecutionRequest(
|
|
274
|
+
finalExecutionPayload,
|
|
275
|
+
feeOptions.gasSettings,
|
|
276
|
+
chainInfo,
|
|
277
|
+
executionOptions,
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
265
281
|
return this.pxe.simulateTx(txRequest, {
|
|
266
282
|
simulatePublic: true,
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
283
|
+
skipKernels,
|
|
284
|
+
skipFeeEnforcement,
|
|
285
|
+
skipTxValidation,
|
|
286
|
+
overrides,
|
|
270
287
|
scopes,
|
|
271
288
|
});
|
|
272
289
|
}
|
|
273
290
|
|
|
274
291
|
async proveTx(exec: ExecutionPayload, opts: Omit<SendOptions, 'wait'>): Promise<ProvenTx> {
|
|
275
|
-
const fee = await this.completeFeeOptions(
|
|
292
|
+
const fee = await this.completeFeeOptions({
|
|
293
|
+
from: opts.from,
|
|
294
|
+
feePayer: exec.feePayer,
|
|
295
|
+
gasSettings: opts.fee?.gasSettings,
|
|
296
|
+
});
|
|
276
297
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(exec, opts.from, fee);
|
|
277
|
-
const txProvingResult = await this.pxe.proveTx(txRequest, this.
|
|
298
|
+
const txProvingResult = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
|
|
278
299
|
return new ProvenTx(
|
|
279
300
|
this.aztecNode,
|
|
280
301
|
await txProvingResult.toTx(),
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createAztecNodeClient } from '@aztec/aztec.js/node';
|
|
2
|
+
import type { SendOptions } from '@aztec/aztec.js/wallet';
|
|
3
|
+
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
4
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import type { ApiSchema, Fr } from '@aztec/foundation/schemas';
|
|
6
|
+
import { parseWithOptionals, schemaHasMethod } from '@aztec/foundation/schemas';
|
|
7
|
+
import { NodeListener, TransportServer } from '@aztec/foundation/transport';
|
|
8
|
+
import { ExecutionPayload, Tx } from '@aztec/stdlib/tx';
|
|
9
|
+
|
|
10
|
+
import { workerData } from 'worker_threads';
|
|
11
|
+
|
|
12
|
+
import { TestWallet } from './test_wallet.js';
|
|
13
|
+
import { WorkerWalletSchema } from './worker_wallet_schema.js';
|
|
14
|
+
|
|
15
|
+
const logger = createLogger('e2e:test-wallet:worker');
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const { nodeUrl, pxeConfig } = workerData as { nodeUrl: string; pxeConfig?: Record<string, unknown> };
|
|
19
|
+
|
|
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');
|
|
24
|
+
|
|
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
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
2
|
+
import type { InteractionWaitOptions, SendReturn } from '@aztec/aztec.js/contracts';
|
|
3
|
+
import type {
|
|
4
|
+
Aliased,
|
|
5
|
+
AppCapabilities,
|
|
6
|
+
BatchResults,
|
|
7
|
+
BatchedMethod,
|
|
8
|
+
ContractClassMetadata,
|
|
9
|
+
ContractMetadata,
|
|
10
|
+
ExecuteUtilityOptions,
|
|
11
|
+
PrivateEvent,
|
|
12
|
+
PrivateEventFilter,
|
|
13
|
+
ProfileOptions,
|
|
14
|
+
SendOptions,
|
|
15
|
+
SimulateOptions,
|
|
16
|
+
Wallet,
|
|
17
|
+
WalletCapabilities,
|
|
18
|
+
} from '@aztec/aztec.js/wallet';
|
|
19
|
+
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
20
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
21
|
+
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
22
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
23
|
+
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
24
|
+
import type { ApiSchema } from '@aztec/foundation/schemas';
|
|
25
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
26
|
+
import { NodeConnector, TransportClient } from '@aztec/foundation/transport';
|
|
27
|
+
import type { PXEConfig } from '@aztec/pxe/config';
|
|
28
|
+
import type { ContractArtifact, EventMetadataDefinition, FunctionCall } from '@aztec/stdlib/abi';
|
|
29
|
+
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
30
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
31
|
+
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
32
|
+
import type { ExecutionPayload, TxProfileResult, TxSimulationResult, UtilityExecutionResult } from '@aztec/stdlib/tx';
|
|
33
|
+
import { Tx } from '@aztec/stdlib/tx';
|
|
34
|
+
|
|
35
|
+
import { Worker } from 'worker_threads';
|
|
36
|
+
|
|
37
|
+
import { WorkerWalletSchema } from './worker_wallet_schema.js';
|
|
38
|
+
|
|
39
|
+
type WorkerMsg = { fn: string; args: string };
|
|
40
|
+
|
|
41
|
+
const log = createLogger('e2e:test-wallet:worker-wallet');
|
|
42
|
+
|
|
43
|
+
const WORKER_READY_TIMEOUT_MS = 120_000;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Wallet implementation that offloads all work to a worker thread.
|
|
47
|
+
* Implements the Wallet interface by proxying calls over a transport layer
|
|
48
|
+
* using JSON serialization with Zod schema parsing on both ends.
|
|
49
|
+
*/
|
|
50
|
+
export class WorkerWallet implements Wallet {
|
|
51
|
+
private constructor(
|
|
52
|
+
private worker: Worker,
|
|
53
|
+
private client: TransportClient<WorkerMsg>,
|
|
54
|
+
) {}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates a WorkerWallet by spawning a worker thread that creates a TestWallet internally.
|
|
58
|
+
* @param nodeUrl - URL of the Aztec node to connect to.
|
|
59
|
+
* @param pxeConfig - Optional PXE configuration overrides.
|
|
60
|
+
* @returns A WorkerWallet ready to use.
|
|
61
|
+
*/
|
|
62
|
+
static async create(nodeUrl: string, pxeConfig?: Partial<PXEConfig>): Promise<WorkerWallet> {
|
|
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, {
|
|
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
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const connector = new NodeConnector(worker);
|
|
78
|
+
const client = new TransportClient<WorkerMsg>(connector);
|
|
79
|
+
await client.open();
|
|
80
|
+
|
|
81
|
+
const wallet = new WorkerWallet(worker, client);
|
|
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
|
+
|
|
115
|
+
return wallet;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private async callRaw(fn: string, ...args: any[]): Promise<string> {
|
|
119
|
+
const argsJson = jsonStringify(args);
|
|
120
|
+
return (await this.client.request({ fn, args: argsJson })) as string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private async call(fn: string, ...args: any[]): Promise<any> {
|
|
124
|
+
const resultJson = await this.callRaw(fn, ...args);
|
|
125
|
+
const methodSchema = (WorkerWalletSchema as ApiSchema)[fn];
|
|
126
|
+
return methodSchema.returnType().parseAsync(JSON.parse(resultJson));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
getChainInfo(): Promise<ChainInfo> {
|
|
130
|
+
return this.call('getChainInfo');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
getContractMetadata(address: AztecAddress): Promise<ContractMetadata> {
|
|
134
|
+
return this.call('getContractMetadata', address);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
getContractClassMetadata(id: Fr): Promise<ContractClassMetadata> {
|
|
138
|
+
return this.call('getContractClassMetadata', id);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
getPrivateEvents<T>(
|
|
142
|
+
eventMetadata: EventMetadataDefinition,
|
|
143
|
+
eventFilter: PrivateEventFilter,
|
|
144
|
+
): Promise<PrivateEvent<T>[]> {
|
|
145
|
+
return this.call('getPrivateEvents', eventMetadata, eventFilter);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
registerSender(address: AztecAddress, alias?: string): Promise<AztecAddress> {
|
|
149
|
+
return this.call('registerSender', address, alias);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
getAddressBook(): Promise<Aliased<AztecAddress>[]> {
|
|
153
|
+
return this.call('getAddressBook');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
getAccounts(): Promise<Aliased<AztecAddress>[]> {
|
|
157
|
+
return this.call('getAccounts');
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
registerContract(
|
|
161
|
+
instance: ContractInstanceWithAddress,
|
|
162
|
+
artifact?: ContractArtifact,
|
|
163
|
+
secretKey?: Fr,
|
|
164
|
+
): Promise<ContractInstanceWithAddress> {
|
|
165
|
+
return this.call('registerContract', instance, artifact, secretKey);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
simulateTx(exec: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
|
|
169
|
+
return this.call('simulateTx', exec, opts);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult> {
|
|
173
|
+
return this.call('executeUtility', call, opts);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
profileTx(exec: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
177
|
+
return this.call('profileTx', exec, opts);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
sendTx<W extends InteractionWaitOptions = undefined>(
|
|
181
|
+
exec: ExecutionPayload,
|
|
182
|
+
opts: SendOptions<W>,
|
|
183
|
+
): Promise<SendReturn<W>> {
|
|
184
|
+
return this.call('sendTx', exec, opts);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
proveTx(exec: ExecutionPayload, opts: Omit<SendOptions, 'wait'>): Promise<Tx> {
|
|
188
|
+
return this.call('proveTx', exec, opts);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Registers an account inside the worker's TestWallet, populating its accounts map. */
|
|
192
|
+
registerAccount(secret: Fr, salt: Fr): Promise<AztecAddress> {
|
|
193
|
+
return this.call('registerAccount', secret, salt);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness> {
|
|
197
|
+
return this.call('createAuthWit', from, messageHashOrIntent);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
requestCapabilities(manifest: AppCapabilities): Promise<WalletCapabilities> {
|
|
201
|
+
return this.call('requestCapabilities', manifest);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>> {
|
|
205
|
+
return this.call('batch', methods);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Shuts down the worker thread and closes the transport. */
|
|
209
|
+
async stop(): Promise<void> {
|
|
210
|
+
this.client.close();
|
|
211
|
+
await this.worker.terminate();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ExecutionPayloadSchema, SendOptionsSchema, WalletSchema } from '@aztec/aztec.js/wallet';
|
|
2
|
+
import { schemas } from '@aztec/foundation/schemas';
|
|
3
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import { Tx } from '@aztec/stdlib/tx';
|
|
5
|
+
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
|
|
8
|
+
/** Schema for the WorkerWallet API — extends WalletSchema with proveTx and registerAccount. */
|
|
9
|
+
export const WorkerWalletSchema = {
|
|
10
|
+
...WalletSchema,
|
|
11
|
+
proveTx: z.function().args(ExecutionPayloadSchema, SendOptionsSchema).returns(Tx.schema),
|
|
12
|
+
registerAccount: z.function().args(schemas.Fr, schemas.Fr).returns(AztecAddress.schema),
|
|
13
|
+
};
|