@aztec/end-to-end 0.0.1-commit.ff7989d6c → 0.0.1-commit.ffe5b04ea
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/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 +16 -8
- 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 +1 -1
- 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 +14 -14
- 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 +13 -6
- 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/p2p_network.d.ts +4 -3
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +19 -16
- package/dest/e2e_p2p/shared.d.ts +15 -1
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +25 -2
- package/dest/e2e_token_contract/token_contract_test.d.ts +1 -1
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +11 -11
- package/dest/fixtures/authwit_proxy.d.ts +3 -3
- package/dest/fixtures/authwit_proxy.d.ts.map +1 -1
- package/dest/fixtures/e2e_prover_test.d.ts +1 -1
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
- package/dest/fixtures/e2e_prover_test.js +6 -6
- 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/setup.d.ts +3 -4
- package/dest/fixtures/setup.d.ts.map +1 -1
- package/dest/fixtures/setup.js +3 -3
- package/dest/fixtures/token_utils.d.ts +1 -1
- package/dest/fixtures/token_utils.d.ts.map +1 -1
- package/dest/fixtures/token_utils.js +2 -2
- 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/jest_setup.js +41 -1
- package/dest/shared/submit-transactions.d.ts +1 -1
- package/dest/shared/submit-transactions.d.ts.map +1 -1
- 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 +5 -5
- 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 +2 -2
- 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 +1 -1
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +4 -3
- package/dest/spartan/tx_metrics.js +1 -1
- package/dest/spartan/utils/config.d.ts +4 -1
- package/dest/spartan/utils/config.d.ts.map +1 -1
- package/dest/spartan/utils/config.js +2 -1
- package/dest/spartan/utils/index.d.ts +2 -1
- package/dest/spartan/utils/index.d.ts.map +1 -1
- package/dest/spartan/utils/index.js +2 -0
- package/dest/spartan/utils/nodes.d.ts +1 -1
- package/dest/spartan/utils/nodes.d.ts.map +1 -1
- package/dest/spartan/utils/nodes.js +5 -4
- package/dest/test-wallet/wallet_worker_script.js +41 -33
- package/dest/test-wallet/worker_wallet.d.ts +1 -1
- package/dest/test-wallet/worker_wallet.d.ts.map +1 -1
- package/dest/test-wallet/worker_wallet.js +51 -3
- package/dest/test-wallet/worker_wallet_schema.d.ts +1 -1
- package/package.json +43 -44
- package/src/bench/client_flows/client_flows_benchmark.ts +38 -30
- package/src/bench/utils.ts +7 -2
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +18 -14
- package/src/e2e_fees/fees_test.ts +13 -6
- package/src/e2e_nested_contract/nested_contract_test.ts +6 -4
- package/src/e2e_p2p/p2p_network.ts +25 -21
- package/src/e2e_p2p/shared.ts +45 -2
- package/src/e2e_token_contract/token_contract_test.ts +16 -8
- package/src/fixtures/e2e_prover_test.ts +11 -5
- package/src/fixtures/elu_monitor.ts +126 -0
- package/src/fixtures/setup.ts +8 -7
- package/src/fixtures/token_utils.ts +4 -2
- package/src/shared/cross_chain_test_harness.ts +13 -9
- package/src/shared/gas_portal_test_harness.ts +1 -1
- package/src/shared/jest_setup.ts +51 -1
- package/src/shared/submit-transactions.ts +1 -4
- package/src/shared/uniswap_l1_l2.ts +6 -4
- package/src/simulators/lending_simulator.ts +4 -2
- package/src/simulators/token_simulator.ts +6 -2
- package/src/spartan/setup_test_wallets.ts +6 -13
- package/src/spartan/tx_metrics.ts +1 -1
- package/src/spartan/utils/config.ts +1 -0
- package/src/spartan/utils/index.ts +3 -0
- package/src/spartan/utils/nodes.ts +12 -4
- package/src/test-wallet/wallet_worker_script.ts +47 -30
- package/src/test-wallet/worker_wallet.ts +51 -3
package/src/shared/jest_setup.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/aztec.js/log';
|
|
2
2
|
|
|
3
|
-
import { beforeEach, expect } from '@jest/globals';
|
|
3
|
+
import { afterAll, afterEach, beforeEach, expect } from '@jest/globals';
|
|
4
|
+
import { readlinkSync } from 'fs';
|
|
4
5
|
import { basename } from 'path';
|
|
5
6
|
|
|
7
|
+
import { EluMonitor } from '../fixtures/elu_monitor.js';
|
|
8
|
+
|
|
9
|
+
const eluMonitor = process.env.ELU_MONITOR_FILE
|
|
10
|
+
? new EluMonitor(process.env.ELU_MONITOR_FILE, Number(process.env.ELU_MONITOR_INTERVAL_MS) || undefined)
|
|
11
|
+
: undefined;
|
|
12
|
+
|
|
13
|
+
if (eluMonitor) {
|
|
14
|
+
process.on('exit', () => eluMonitor.stop());
|
|
15
|
+
}
|
|
16
|
+
|
|
6
17
|
beforeEach(() => {
|
|
7
18
|
const { testPath, currentTestName } = expect.getState();
|
|
8
19
|
if (!testPath || !currentTestName) {
|
|
@@ -10,4 +21,43 @@ beforeEach(() => {
|
|
|
10
21
|
}
|
|
11
22
|
const logger = createLogger(`e2e:${basename(testPath).replace('.test.ts', '')}`);
|
|
12
23
|
logger.info(`Running test: ${currentTestName}`);
|
|
24
|
+
eluMonitor?.startTest(currentTestName);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
eluMonitor?.stopTest();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Log leaked handles after all tests complete. This runs after test-level afterAll hooks,
|
|
32
|
+
// so any handles still alive at this point were not properly cleaned up during teardown.
|
|
33
|
+
// This diagnostic helps identify the source of exit hangs without masking them.
|
|
34
|
+
afterAll(() => {
|
|
35
|
+
const handles = (process as any)._getActiveHandles();
|
|
36
|
+
if (handles.length > 0) {
|
|
37
|
+
const details = handles.map((h: any) => {
|
|
38
|
+
const type = h?.constructor?.name ?? typeof h;
|
|
39
|
+
const fd = h?.fd ?? h?._handle?.fd ?? '?';
|
|
40
|
+
const destroyed = h?.destroyed ?? '?';
|
|
41
|
+
const hasRef = typeof h?.hasRef === 'function' ? h.hasRef() : '?';
|
|
42
|
+
const localAddr = h?.localAddress ?? '';
|
|
43
|
+
const remoteAddr = h?.remoteAddress ?? '';
|
|
44
|
+
const localPort = h?.localPort ?? '';
|
|
45
|
+
const remotePort = h?.remotePort ?? '';
|
|
46
|
+
const proto = Object.getPrototypeOf(h)?.constructor?.name ?? '?';
|
|
47
|
+
const keys = Object.keys(h).slice(0, 10).join(',');
|
|
48
|
+
let fdTarget = '';
|
|
49
|
+
if (typeof fd === 'number') {
|
|
50
|
+
try {
|
|
51
|
+
fdTarget = ` -> ${readlinkSync(`/proc/self/fd/${fd}`)}`;
|
|
52
|
+
} catch {
|
|
53
|
+
// ignore
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return ` ${type}(fd=${fd}, destroyed=${destroyed}, hasRef=${hasRef}${fdTarget}) proto=${proto} addr=${localAddr}:${localPort}->${remoteAddr}:${remotePort} keys=[${keys}]`;
|
|
57
|
+
});
|
|
58
|
+
process.stderr.write(
|
|
59
|
+
`\n[jest_setup] WARNING: ${handles.length} handle(s) still active after teardown:\n${details.join('\n')}\n` +
|
|
60
|
+
`These may prevent Jest from exiting. Investigate and fix the leak.\n\n`,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
13
63
|
});
|
|
@@ -19,10 +19,7 @@ export const submitTxsTo = async (
|
|
|
19
19
|
times(numTxs, async () => {
|
|
20
20
|
const accountManager = await wallet.createSchnorrAccount(Fr.random(), Fr.random(), GrumpkinScalar.random());
|
|
21
21
|
const deployMethod = await accountManager.getDeployMethod();
|
|
22
|
-
const txHash = await deployMethod.send({
|
|
23
|
-
from: submitter,
|
|
24
|
-
wait: NO_WAIT,
|
|
25
|
-
});
|
|
22
|
+
const { txHash } = await deployMethod.send({ from: submitter, wait: NO_WAIT });
|
|
26
23
|
|
|
27
24
|
logger.info(`Tx sent with hash ${txHash}`);
|
|
28
25
|
const receipt: TxReceipt = await wallet.getTxReceipt(txHash);
|
|
@@ -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({
|
|
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,
|
|
@@ -787,7 +789,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
787
789
|
logger.info('Withdrawing weth to L1 and sending message to swap to dai');
|
|
788
790
|
|
|
789
791
|
const [, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
790
|
-
const withdrawReceipt = await uniswapL2Contract.methods
|
|
792
|
+
const { receipt: withdrawReceipt } = await uniswapL2Contract.methods
|
|
791
793
|
.swap_private(
|
|
792
794
|
wethCrossChainHarness.l2Token.address,
|
|
793
795
|
wethCrossChainHarness.l2Bridge.address,
|
|
@@ -915,7 +917,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
915
917
|
|
|
916
918
|
// Call swap_public on L2
|
|
917
919
|
const secretHashForDepositingSwappedDai = Fr.random();
|
|
918
|
-
const withdrawReceipt = await uniswapL2Contract.methods
|
|
920
|
+
const { receipt: withdrawReceipt } = await uniswapL2Contract.methods
|
|
919
921
|
.swap_public(
|
|
920
922
|
ownerAddress,
|
|
921
923
|
wethCrossChainHarness.l2Bridge.address,
|
|
@@ -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
|
|
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
|
-
)
|
|
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
|
|
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
|
}
|
|
@@ -138,11 +138,8 @@ async function deployAccountWithDiagnostics(
|
|
|
138
138
|
const deployMethod = await account.getDeployMethod();
|
|
139
139
|
let txHash;
|
|
140
140
|
try {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
fee: { paymentMethod },
|
|
144
|
-
wait: NO_WAIT,
|
|
145
|
-
});
|
|
141
|
+
const deployResult = await deployMethod.send({ from: AztecAddress.ZERO, fee: { paymentMethod }, wait: NO_WAIT });
|
|
142
|
+
txHash = deployResult.txHash;
|
|
146
143
|
await waitForTx(aztecNode, txHash, { timeout: 2400 });
|
|
147
144
|
logger.info(`${accountLabel} deployed at ${account.address}`);
|
|
148
145
|
} catch (error) {
|
|
@@ -278,7 +275,7 @@ async function bridgeL1FeeJuice(
|
|
|
278
275
|
const claim = await portal.bridgeTokensPublic(recipient, amount, true /* mint */);
|
|
279
276
|
|
|
280
277
|
const isSynced = async () =>
|
|
281
|
-
(await aztecNode.
|
|
278
|
+
(await aztecNode.getL1ToL2MessageCheckpoint(Fr.fromHexString(claim.messageHash))) !== undefined;
|
|
282
279
|
await retryUntil(isSynced, `message ${claim.messageHash} sync`, 24, 0.5);
|
|
283
280
|
|
|
284
281
|
log.info(`Created a claim for ${amount} L1 fee juice to ${recipient}.`, claim);
|
|
@@ -310,13 +307,9 @@ async function deployTokenAndMint(
|
|
|
310
307
|
logger: Logger,
|
|
311
308
|
) {
|
|
312
309
|
logger.verbose(`Deploying TokenContract...`);
|
|
313
|
-
const {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
TOKEN_NAME,
|
|
317
|
-
TOKEN_SYMBOL,
|
|
318
|
-
TOKEN_DECIMALS,
|
|
319
|
-
).send({
|
|
310
|
+
const {
|
|
311
|
+
receipt: { contract: tokenContract },
|
|
312
|
+
} = await TokenContract.deploy(wallet, admin, TOKEN_NAME, TOKEN_SYMBOL, TOKEN_DECIMALS).send({
|
|
320
313
|
from: admin,
|
|
321
314
|
fee: {
|
|
322
315
|
paymentMethod,
|
|
@@ -16,6 +16,7 @@ const testConfigSchema = z.object({
|
|
|
16
16
|
AZTEC_PROOF_SUBMISSION_WINDOW: z.coerce.number().optional().default(5),
|
|
17
17
|
AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET: z.coerce.number().optional().default(2),
|
|
18
18
|
FUNDING_PRIVATE_KEY: z.string().optional(),
|
|
19
|
+
AZTEC_ADMIN_API_KEY: z.string().optional(),
|
|
19
20
|
});
|
|
20
21
|
|
|
21
22
|
export type TestConfig = z.infer<typeof testConfigSchema>;
|
|
@@ -173,7 +173,7 @@ export async function withSequencersAdmin<T>(env: TestConfig, fn: (node: AztecNo
|
|
|
173
173
|
if (statusRes.status !== 200) {
|
|
174
174
|
throw new Error(`Admin endpoint returned status ${statusRes.status}`);
|
|
175
175
|
}
|
|
176
|
-
const client = createAztecNodeAdminClient(url);
|
|
176
|
+
const client = createAztecNodeAdminClient(url, {}, undefined, env.AZTEC_ADMIN_API_KEY);
|
|
177
177
|
return { result: await fn(client), process };
|
|
178
178
|
} catch (err) {
|
|
179
179
|
// Kill the port-forward before retrying
|
|
@@ -363,16 +363,24 @@ export async function enableValidatorDynamicBootNode(
|
|
|
363
363
|
*/
|
|
364
364
|
export async function rollAztecPods(namespace: string, clearState: boolean = false) {
|
|
365
365
|
// Pod components use 'validator', but StatefulSets and PVCs use 'sequencer-node' for validators
|
|
366
|
+
// RPC nodes have nodeType='rpc-node' in Helm values, so their component label is 'rpc-node' (not 'rpc')
|
|
366
367
|
const podComponents = [
|
|
367
368
|
'p2p-bootstrap',
|
|
368
369
|
'prover-node',
|
|
369
370
|
'prover-broker',
|
|
370
371
|
'prover-agent',
|
|
371
372
|
'sequencer-node',
|
|
372
|
-
'rpc',
|
|
373
|
+
'rpc-node',
|
|
374
|
+
'validator-ha-db',
|
|
375
|
+
];
|
|
376
|
+
const pvcComponents = [
|
|
377
|
+
'p2p-bootstrap',
|
|
378
|
+
'prover-node',
|
|
379
|
+
'prover-broker',
|
|
380
|
+
'sequencer-node',
|
|
381
|
+
'rpc-node',
|
|
373
382
|
'validator-ha-db',
|
|
374
383
|
];
|
|
375
|
-
const pvcComponents = ['p2p-bootstrap', 'prover-node', 'prover-broker', 'sequencer-node', 'rpc', 'validator-ha-db'];
|
|
376
384
|
// StatefulSet components that need to be scaled down before PVC deletion
|
|
377
385
|
// Note: validators use 'sequencer-node' as component label, not 'validator'
|
|
378
386
|
const statefulSetComponents = [
|
|
@@ -380,7 +388,7 @@ export async function rollAztecPods(namespace: string, clearState: boolean = fal
|
|
|
380
388
|
'prover-node',
|
|
381
389
|
'prover-broker',
|
|
382
390
|
'sequencer-node',
|
|
383
|
-
'rpc',
|
|
391
|
+
'rpc-node',
|
|
384
392
|
'validator-ha-db',
|
|
385
393
|
];
|
|
386
394
|
|
|
@@ -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
|
|
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
|
|
15
|
+
const logger = createLogger('e2e:test-wallet:worker');
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
const
|
|
17
|
+
try {
|
|
18
|
+
const { nodeUrl, pxeConfig } = workerData as { nodeUrl: string; pxeConfig?: Record<string, unknown> };
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
66
|
-
|
|
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
|
|