@aztec/end-to-end 0.0.1-commit.5daedc8 → 0.0.1-commit.6201a7b05
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/benchmark.d.ts +3 -2
- package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
- package/dest/bench/client_flows/benchmark.js +21 -1
- package/dest/bench/client_flows/client_flows_benchmark.d.ts +15 -16
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
- package/dest/bench/client_flows/client_flows_benchmark.js +125 -145
- package/dest/bench/client_flows/config.d.ts +2 -2
- package/dest/bench/client_flows/config.d.ts.map +1 -1
- package/dest/bench/client_flows/config.js +18 -0
- package/dest/bench/client_flows/data_extractor.js +3 -1
- package/dest/bench/utils.d.ts +9 -8
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/bench/utils.js +31 -19
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +11 -9
- 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 +108 -114
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +20 -14
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +92 -71
- package/dest/e2e_deploy_contract/deploy_test.d.ts +5 -4
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
- package/dest/e2e_deploy_contract/deploy_test.js +18 -13
- package/dest/e2e_epochs/epochs_test.d.ts +42 -15
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +159 -59
- package/dest/e2e_fees/bridging_race.notest.js +4 -6
- package/dest/e2e_fees/fees_test.d.ts +21 -17
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +139 -147
- package/dest/e2e_l1_publisher/write_json.d.ts +4 -3
- package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -1
- package/dest/e2e_l1_publisher/write_json.js +14 -16
- package/dest/e2e_multi_validator/utils.js +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.d.ts +6 -9
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +30 -40
- package/dest/e2e_p2p/inactivity_slash_test.d.ts +4 -4
- package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -1
- package/dest/e2e_p2p/inactivity_slash_test.js +9 -12
- package/dest/e2e_p2p/p2p_network.d.ts +25 -21
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +175 -130
- package/dest/e2e_p2p/reqresp/utils.d.ts +22 -0
- package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -0
- package/dest/e2e_p2p/reqresp/utils.js +193 -0
- package/dest/e2e_p2p/shared.d.ts +30 -12
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +84 -67
- package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +2 -0
- package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +1 -0
- package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.js +184 -0
- package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts +18 -0
- package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +1 -0
- package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.js +120 -0
- package/dest/e2e_token_contract/token_contract_test.d.ts +19 -10
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +100 -92
- 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 +16 -23
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
- package/dest/fixtures/e2e_prover_test.js +115 -139
- 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 +17 -3
- package/dest/fixtures/fixtures.d.ts.map +1 -1
- package/dest/fixtures/fixtures.js +18 -3
- package/dest/fixtures/get_acvm_config.js +1 -1
- 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 +71 -0
- package/dest/fixtures/ha_setup.d.ts.map +1 -0
- package/dest/fixtures/ha_setup.js +116 -0
- package/dest/fixtures/index.d.ts +2 -1
- package/dest/fixtures/index.d.ts.map +1 -1
- package/dest/fixtures/index.js +1 -0
- package/dest/fixtures/l1_to_l2_messaging.d.ts +4 -3
- package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
- package/dest/fixtures/l1_to_l2_messaging.js +2 -2
- package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts +25 -0
- package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts.map +1 -0
- package/dest/fixtures/schnorr_hardcoded_account_contract.js +39 -0
- package/dest/fixtures/setup.d.ts +246 -0
- package/dest/fixtures/setup.d.ts.map +1 -0
- package/dest/fixtures/setup.js +625 -0
- package/dest/fixtures/setup_p2p_test.d.ts +18 -11
- package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
- package/dest/fixtures/setup_p2p_test.js +46 -35
- 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 +7 -6
- package/dest/fixtures/utils.d.ts +5 -637
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +4 -647
- package/dest/fixtures/web3signer.js +1 -1
- package/dest/fixtures/with_telemetry_utils.d.ts +2 -2
- package/dest/fixtures/with_telemetry_utils.d.ts.map +1 -1
- package/dest/fixtures/with_telemetry_utils.js +2 -2
- package/dest/forward-compatibility/wallet_rpc_client.d.ts +7 -0
- package/dest/forward-compatibility/wallet_rpc_client.d.ts.map +1 -0
- package/dest/forward-compatibility/wallet_rpc_client.js +15 -0
- package/dest/forward-compatibility/wallet_service.d.ts +3 -0
- package/dest/forward-compatibility/wallet_service.d.ts.map +1 -0
- package/dest/forward-compatibility/wallet_service.js +109 -0
- package/dest/legacy-jest-resolver.d.cts +3 -0
- package/dest/legacy-jest-resolver.d.cts.map +1 -0
- package/dest/quality_of_service/grafana_client.d.ts +41 -0
- package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
- package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
- package/dest/quality_of_service/prometheus_client.d.ts +38 -0
- package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
- package/dest/quality_of_service/prometheus_client.js +67 -0
- package/dest/shared/cross_chain_test_harness.d.ts +18 -6
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +27 -27
- package/dest/shared/gas_portal_test_harness.d.ts +12 -2
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.js +4 -4
- package/dest/shared/index.d.ts +3 -2
- 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.d.ts +4 -4
- package/dest/shared/submit-transactions.d.ts.map +1 -1
- package/dest/shared/submit-transactions.js +9 -11
- package/dest/shared/uniswap_l1_l2.d.ts +3 -27
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.js +58 -43
- package/dest/simulators/lending_simulator.d.ts +6 -2
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +6 -6
- 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 +3 -24
- package/dest/spartan/setup_test_wallets.d.ts +15 -5
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +132 -43
- package/dest/spartan/tx_metrics.d.ts +88 -0
- package/dest/spartan/tx_metrics.d.ts.map +1 -0
- package/dest/spartan/tx_metrics.js +438 -0
- package/dest/spartan/utils/bot.d.ts +28 -0
- package/dest/spartan/utils/bot.d.ts.map +1 -0
- package/dest/spartan/utils/bot.js +142 -0
- package/dest/spartan/utils/chaos.d.ts +79 -0
- package/dest/spartan/utils/chaos.d.ts.map +1 -0
- package/dest/spartan/utils/chaos.js +142 -0
- package/dest/spartan/utils/clients.d.ts +39 -0
- package/dest/spartan/utils/clients.d.ts.map +1 -0
- package/dest/spartan/utils/clients.js +90 -0
- package/dest/spartan/utils/config.d.ts +45 -0
- package/dest/spartan/utils/config.d.ts.map +1 -0
- package/dest/spartan/utils/config.js +23 -0
- package/dest/spartan/utils/health.d.ts +63 -0
- package/dest/spartan/utils/health.d.ts.map +1 -0
- package/dest/spartan/utils/health.js +202 -0
- package/dest/spartan/utils/helm.d.ts +15 -0
- package/dest/spartan/utils/helm.d.ts.map +1 -0
- package/dest/spartan/utils/helm.js +47 -0
- package/dest/spartan/utils/index.d.ts +11 -0
- package/dest/spartan/utils/index.d.ts.map +1 -0
- package/dest/spartan/utils/index.js +22 -0
- package/dest/spartan/utils/k8s.d.ts +128 -0
- package/dest/spartan/utils/k8s.d.ts.map +1 -0
- package/dest/spartan/utils/k8s.js +381 -0
- package/dest/spartan/utils/nodes.d.ts +40 -0
- package/dest/spartan/utils/nodes.d.ts.map +1 -0
- package/dest/spartan/utils/nodes.js +461 -0
- 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/spartan/utils/scripts.d.ts +30 -0
- package/dest/spartan/utils/scripts.d.ts.map +1 -0
- package/dest/spartan/utils/scripts.js +81 -0
- package/dest/spartan/utils.d.ts +2 -220
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +1 -782
- package/dest/test-wallet/test_wallet.d.ts +84 -0
- package/dest/test-wallet/test_wallet.d.ts.map +1 -0
- package/dest/test-wallet/test_wallet.js +255 -0
- package/dest/test-wallet/utils.d.ts +41 -0
- package/dest/test-wallet/utils.d.ts.map +1 -0
- package/dest/test-wallet/utils.js +71 -0
- 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 +279 -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 +49 -45
- package/src/bench/client_flows/benchmark.ts +24 -2
- package/src/bench/client_flows/client_flows_benchmark.ts +166 -216
- package/src/bench/client_flows/config.ts +9 -1
- package/src/bench/client_flows/data_extractor.ts +1 -1
- package/src/bench/utils.ts +36 -21
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +123 -151
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +140 -126
- package/src/e2e_deploy_contract/deploy_test.ts +22 -15
- package/src/e2e_epochs/epochs_test.ts +222 -112
- package/src/e2e_fees/bridging_race.notest.ts +5 -11
- package/src/e2e_fees/fees_test.ts +182 -230
- package/src/e2e_l1_publisher/write_json.ts +16 -16
- package/src/e2e_multi_validator/utils.ts +1 -1
- package/src/e2e_nested_contract/nested_contract_test.ts +35 -56
- package/src/e2e_p2p/inactivity_slash_test.ts +10 -13
- package/src/e2e_p2p/p2p_network.ts +245 -204
- package/src/e2e_p2p/reqresp/utils.ts +257 -0
- package/src/e2e_p2p/shared.ts +111 -81
- package/src/e2e_storage_proof/fixtures/storage_proof.json +915 -0
- package/src/e2e_storage_proof/fixtures/storage_proof_fetcher.ts +190 -0
- package/src/e2e_storage_proof/fixtures/storage_proof_fixture.ts +173 -0
- package/src/e2e_token_contract/token_contract_test.ts +121 -119
- 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 +143 -189
- package/src/fixtures/elu_monitor.ts +126 -0
- package/src/fixtures/fixtures.ts +34 -5
- package/src/fixtures/get_acvm_config.ts +1 -1
- package/src/fixtures/get_bb_config.ts +7 -6
- package/src/fixtures/ha_setup.ts +188 -0
- package/src/fixtures/index.ts +1 -0
- package/src/fixtures/l1_to_l2_messaging.ts +4 -2
- package/src/fixtures/schnorr_hardcoded_account_contract.ts +49 -0
- package/src/fixtures/setup.ts +932 -0
- package/src/fixtures/setup_p2p_test.ts +51 -55
- package/src/fixtures/token_utils.ts +7 -6
- package/src/fixtures/utils.ts +27 -966
- package/src/fixtures/web3signer.ts +1 -1
- package/src/fixtures/with_telemetry_utils.ts +2 -2
- package/src/forward-compatibility/wallet_rpc_client.ts +14 -0
- package/src/forward-compatibility/wallet_service.ts +104 -0
- package/src/guides/up_quick_start.sh +3 -5
- package/src/legacy-jest-resolver.cjs +135 -0
- package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +1 -1
- package/src/quality_of_service/prometheus_client.ts +113 -0
- package/src/shared/cross_chain_test_harness.ts +30 -43
- package/src/shared/gas_portal_test_harness.ts +3 -4
- package/src/shared/index.ts +2 -1
- package/src/shared/jest_setup.ts +51 -1
- package/src/shared/mock_state_view.ts +188 -0
- package/src/shared/submit-transactions.ts +11 -16
- package/src/shared/uniswap_l1_l2.ts +86 -106
- package/src/simulators/lending_simulator.ts +11 -7
- package/src/simulators/token_simulator.ts +6 -30
- package/src/spartan/DEVELOP.md +7 -0
- package/src/spartan/setup_test_wallets.ts +192 -28
- package/src/spartan/tx_metrics.ts +388 -0
- package/src/spartan/utils/bot.ts +188 -0
- package/src/spartan/utils/chaos.ts +253 -0
- package/src/spartan/utils/clients.ts +100 -0
- package/src/spartan/utils/config.ts +29 -0
- package/src/spartan/utils/health.ts +255 -0
- package/src/spartan/utils/helm.ts +84 -0
- package/src/spartan/utils/index.ts +71 -0
- package/src/spartan/utils/k8s.ts +535 -0
- package/src/spartan/utils/nodes.ts +543 -0
- package/src/spartan/utils/pod_logs.ts +99 -0
- package/src/spartan/utils/scripts.ts +99 -0
- package/src/spartan/utils.ts +1 -982
- package/src/test-wallet/test_wallet.ts +357 -0
- package/src/test-wallet/utils.ts +112 -0
- package/src/test-wallet/wallet_worker_script.ts +60 -0
- package/src/test-wallet/worker_wallet.ts +214 -0
- package/src/test-wallet/worker_wallet_schema.ts +13 -0
- package/dest/fixtures/setup_l1_contracts.d.ts +0 -477
- package/dest/fixtures/setup_l1_contracts.d.ts.map +0 -1
- package/dest/fixtures/setup_l1_contracts.js +0 -17
- package/dest/fixtures/snapshot_manager.d.ts +0 -95
- package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
- package/dest/fixtures/snapshot_manager.js +0 -505
- package/dest/quality_of_service/alert_checker.d.ts +0 -41
- package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
- package/src/fixtures/setup_l1_contracts.ts +0 -26
- package/src/fixtures/snapshot_manager.ts +0 -665
|
@@ -0,0 +1,214 @@
|
|
|
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
|
+
TxSimulationResultWithAppOffset,
|
|
17
|
+
Wallet,
|
|
18
|
+
WalletCapabilities,
|
|
19
|
+
} from '@aztec/aztec.js/wallet';
|
|
20
|
+
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
21
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
22
|
+
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
23
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
24
|
+
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
25
|
+
import type { ApiSchema } from '@aztec/foundation/schemas';
|
|
26
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
27
|
+
import { NodeConnector, TransportClient } from '@aztec/foundation/transport';
|
|
28
|
+
import type { PXEConfig } from '@aztec/pxe/config';
|
|
29
|
+
import type { ContractArtifact, EventMetadataDefinition, FunctionCall } from '@aztec/stdlib/abi';
|
|
30
|
+
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
31
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
32
|
+
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
33
|
+
import type { ExecutionPayload, TxProfileResult, UtilityExecutionResult } from '@aztec/stdlib/tx';
|
|
34
|
+
import { Tx } from '@aztec/stdlib/tx';
|
|
35
|
+
|
|
36
|
+
import { Worker } from 'worker_threads';
|
|
37
|
+
|
|
38
|
+
import { WorkerWalletSchema } from './worker_wallet_schema.js';
|
|
39
|
+
|
|
40
|
+
type WorkerMsg = { fn: string; args: string };
|
|
41
|
+
|
|
42
|
+
const log = createLogger('e2e:test-wallet:worker-wallet');
|
|
43
|
+
|
|
44
|
+
const WORKER_READY_TIMEOUT_MS = 120_000;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Wallet implementation that offloads all work to a worker thread.
|
|
48
|
+
* Implements the Wallet interface by proxying calls over a transport layer
|
|
49
|
+
* using JSON serialization with Zod schema parsing on both ends.
|
|
50
|
+
*/
|
|
51
|
+
export class WorkerWallet implements Wallet {
|
|
52
|
+
private constructor(
|
|
53
|
+
private worker: Worker,
|
|
54
|
+
private client: TransportClient<WorkerMsg>,
|
|
55
|
+
) {}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Creates a WorkerWallet by spawning a worker thread that creates a TestWallet internally.
|
|
59
|
+
* @param nodeUrl - URL of the Aztec node to connect to.
|
|
60
|
+
* @param pxeConfig - Optional PXE configuration overrides.
|
|
61
|
+
* @returns A WorkerWallet ready to use.
|
|
62
|
+
*/
|
|
63
|
+
static async create(nodeUrl: string, pxeConfig?: Partial<PXEConfig>): Promise<WorkerWallet> {
|
|
64
|
+
// replace stc/ with dest/ so the wallet works in Jest tests
|
|
65
|
+
const workerUrl = new URL('./wallet_worker_script.js', import.meta.url);
|
|
66
|
+
workerUrl.pathname = workerUrl.pathname.replace('/src/', '/dest/');
|
|
67
|
+
// remove JEST_WORKER_ID so the worker uses pino-pretty transport instead of Jest's raw output.
|
|
68
|
+
const { JEST_WORKER_ID: _, ...parentEnv } = process.env;
|
|
69
|
+
const worker = new Worker(workerUrl, {
|
|
70
|
+
workerData: { nodeUrl, pxeConfig },
|
|
71
|
+
env: {
|
|
72
|
+
...parentEnv,
|
|
73
|
+
...(process.stderr.isTTY || process.env.FORCE_COLOR ? { FORCE_COLOR: '1' } : {}),
|
|
74
|
+
LOG_LEVEL: process.env.WORKER_LOG_LEVEL ?? 'warn',
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const connector = new NodeConnector(worker);
|
|
79
|
+
const client = new TransportClient<WorkerMsg>(connector);
|
|
80
|
+
await client.open();
|
|
81
|
+
|
|
82
|
+
const wallet = new WorkerWallet(worker, client);
|
|
83
|
+
|
|
84
|
+
const { promise: workerDied, reject: rejectWorkerDied } = promiseWithResolvers<void>();
|
|
85
|
+
// reject if the worker exits or errors before the warmup completes.
|
|
86
|
+
const onError = (err: Error): void => {
|
|
87
|
+
worker.off('exit', onExit!);
|
|
88
|
+
rejectWorkerDied(new Error(`Worker wallet thread error: ${err.message}`));
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const onExit = (code: number): void => {
|
|
92
|
+
worker.off('error', onError!);
|
|
93
|
+
rejectWorkerDied(new Error(`Worker wallet thread exited with code ${code} before becoming ready`));
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
worker.once('error', onError);
|
|
97
|
+
worker.once('exit', onExit);
|
|
98
|
+
|
|
99
|
+
const timeout = sleep(WORKER_READY_TIMEOUT_MS).then(() => {
|
|
100
|
+
throw new Error(`Worker wallet creation timed out after ${WORKER_READY_TIMEOUT_MS / 1000}s`);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
// wait for worker wallet to start
|
|
105
|
+
await Promise.race([wallet.getChainInfo(), workerDied, timeout]);
|
|
106
|
+
} catch (err) {
|
|
107
|
+
log.error('Worker wallet creation failed, cleaning up', { error: String(err) });
|
|
108
|
+
client.close();
|
|
109
|
+
await worker.terminate();
|
|
110
|
+
throw err;
|
|
111
|
+
} finally {
|
|
112
|
+
worker.off('error', onError);
|
|
113
|
+
worker.off('exit', onExit);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return wallet;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private async callRaw(fn: string, ...args: any[]): Promise<string> {
|
|
120
|
+
const argsJson = jsonStringify(args);
|
|
121
|
+
return (await this.client.request({ fn, args: argsJson })) as string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private async call(fn: string, ...args: any[]): Promise<any> {
|
|
125
|
+
const resultJson = await this.callRaw(fn, ...args);
|
|
126
|
+
const methodSchema = (WorkerWalletSchema as ApiSchema)[fn];
|
|
127
|
+
return methodSchema.returnType().parseAsync(JSON.parse(resultJson));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
getChainInfo(): Promise<ChainInfo> {
|
|
131
|
+
return this.call('getChainInfo');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
getContractMetadata(address: AztecAddress): Promise<ContractMetadata> {
|
|
135
|
+
return this.call('getContractMetadata', address);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
getContractClassMetadata(id: Fr): Promise<ContractClassMetadata> {
|
|
139
|
+
return this.call('getContractClassMetadata', id);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
getPrivateEvents<T>(
|
|
143
|
+
eventMetadata: EventMetadataDefinition,
|
|
144
|
+
eventFilter: PrivateEventFilter,
|
|
145
|
+
): Promise<PrivateEvent<T>[]> {
|
|
146
|
+
return this.call('getPrivateEvents', eventMetadata, eventFilter);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
registerSender(address: AztecAddress, alias?: string): Promise<AztecAddress> {
|
|
150
|
+
return this.call('registerSender', address, alias);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
getAddressBook(): Promise<Aliased<AztecAddress>[]> {
|
|
154
|
+
return this.call('getAddressBook');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
getAccounts(): Promise<Aliased<AztecAddress>[]> {
|
|
158
|
+
return this.call('getAccounts');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
registerContract(
|
|
162
|
+
instance: ContractInstanceWithAddress,
|
|
163
|
+
artifact?: ContractArtifact,
|
|
164
|
+
secretKey?: Fr,
|
|
165
|
+
): Promise<ContractInstanceWithAddress> {
|
|
166
|
+
return this.call('registerContract', instance, artifact, secretKey);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
simulateTx(exec: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResultWithAppOffset> {
|
|
170
|
+
return this.call('simulateTx', exec, opts);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult> {
|
|
174
|
+
return this.call('executeUtility', call, opts);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
profileTx(exec: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
178
|
+
return this.call('profileTx', exec, opts);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
sendTx<W extends InteractionWaitOptions = undefined>(
|
|
182
|
+
exec: ExecutionPayload,
|
|
183
|
+
opts: SendOptions<W>,
|
|
184
|
+
): Promise<SendReturn<W>> {
|
|
185
|
+
return this.call('sendTx', exec, opts);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
proveTx(exec: ExecutionPayload, opts: Omit<SendOptions, 'wait'>): Promise<Tx> {
|
|
189
|
+
return this.call('proveTx', exec, opts);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Registers an account inside the worker's TestWallet, populating its accounts map. */
|
|
193
|
+
registerAccount(secret: Fr, salt: Fr): Promise<AztecAddress> {
|
|
194
|
+
return this.call('registerAccount', secret, salt);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness> {
|
|
198
|
+
return this.call('createAuthWit', from, messageHashOrIntent);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
requestCapabilities(manifest: AppCapabilities): Promise<WalletCapabilities> {
|
|
202
|
+
return this.call('requestCapabilities', manifest);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>> {
|
|
206
|
+
return this.call('batch', methods);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Shuts down the worker thread and closes the transport. */
|
|
210
|
+
async stop(): Promise<void> {
|
|
211
|
+
this.client.close();
|
|
212
|
+
await this.worker.terminate();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
@@ -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
|
+
};
|