@aztec/end-to-end 0.0.1-commit.ee80a48 → 0.0.1-commit.f103f88

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 (188) hide show
  1. package/README.md +27 -0
  2. package/dest/bench/client_flows/client_flows_benchmark.d.ts +2 -2
  3. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  4. package/dest/bench/client_flows/client_flows_benchmark.js +22 -29
  5. package/dest/bench/client_flows/config.d.ts +2 -2
  6. package/dest/bench/client_flows/config.d.ts.map +1 -1
  7. package/dest/bench/client_flows/config.js +18 -0
  8. package/dest/bench/utils.d.ts +1 -1
  9. package/dest/bench/utils.d.ts.map +1 -1
  10. package/dest/bench/utils.js +6 -3
  11. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +6 -3
  12. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  13. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +23 -13
  14. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +2 -2
  15. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  16. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +3 -2
  17. package/dest/e2e_deploy_contract/deploy_test.d.ts +2 -2
  18. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  19. package/dest/e2e_epochs/epochs_test.d.ts +11 -7
  20. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  21. package/dest/e2e_epochs/epochs_test.js +64 -36
  22. package/dest/e2e_fees/fees_test.d.ts +2 -2
  23. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  24. package/dest/e2e_fees/fees_test.js +19 -12
  25. package/dest/e2e_nested_contract/nested_contract_test.d.ts +1 -1
  26. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  27. package/dest/e2e_nested_contract/nested_contract_test.js +4 -6
  28. package/dest/e2e_p2p/inactivity_slash_test.js +3 -3
  29. package/dest/e2e_p2p/p2p_network.d.ts +9 -10
  30. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  31. package/dest/e2e_p2p/p2p_network.js +38 -20
  32. package/dest/e2e_p2p/reqresp/utils.d.ts +3 -3
  33. package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -1
  34. package/dest/e2e_p2p/reqresp/utils.js +46 -9
  35. package/dest/e2e_p2p/shared.d.ts +26 -8
  36. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  37. package/dest/e2e_p2p/shared.js +54 -45
  38. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +2 -0
  39. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +1 -0
  40. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.js +184 -0
  41. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts +18 -0
  42. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +1 -0
  43. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.js +120 -0
  44. package/dest/e2e_token_contract/token_contract_test.d.ts +4 -2
  45. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  46. package/dest/e2e_token_contract/token_contract_test.js +19 -9
  47. package/dest/fixtures/authwit_proxy.d.ts +15 -0
  48. package/dest/fixtures/authwit_proxy.d.ts.map +1 -0
  49. package/dest/fixtures/authwit_proxy.js +34 -0
  50. package/dest/fixtures/e2e_prover_test.d.ts +7 -6
  51. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  52. package/dest/fixtures/e2e_prover_test.js +37 -49
  53. package/dest/fixtures/elu_monitor.d.ts +21 -0
  54. package/dest/fixtures/elu_monitor.d.ts.map +1 -0
  55. package/dest/fixtures/elu_monitor.js +102 -0
  56. package/dest/fixtures/fixtures.d.ts +5 -1
  57. package/dest/fixtures/fixtures.d.ts.map +1 -1
  58. package/dest/fixtures/fixtures.js +6 -0
  59. package/dest/fixtures/get_bb_config.d.ts +1 -1
  60. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  61. package/dest/fixtures/get_bb_config.js +5 -5
  62. package/dest/fixtures/ha_setup.d.ts +1 -1
  63. package/dest/fixtures/ha_setup.d.ts.map +1 -1
  64. package/dest/fixtures/ha_setup.js +3 -1
  65. package/dest/fixtures/setup.d.ts +53 -29
  66. package/dest/fixtures/setup.d.ts.map +1 -1
  67. package/dest/fixtures/setup.js +79 -163
  68. package/dest/fixtures/setup_p2p_test.d.ts +18 -10
  69. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  70. package/dest/fixtures/setup_p2p_test.js +23 -17
  71. package/dest/fixtures/token_utils.d.ts +2 -2
  72. package/dest/fixtures/token_utils.d.ts.map +1 -1
  73. package/dest/fixtures/token_utils.js +5 -7
  74. package/dest/legacy-jest-resolver.d.cts +3 -0
  75. package/dest/legacy-jest-resolver.d.cts.map +1 -0
  76. package/dest/shared/cross_chain_test_harness.d.ts +1 -1
  77. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  78. package/dest/shared/cross_chain_test_harness.js +13 -13
  79. package/dest/shared/gas_portal_test_harness.js +2 -2
  80. package/dest/shared/index.d.ts +2 -1
  81. package/dest/shared/index.d.ts.map +1 -1
  82. package/dest/shared/index.js +1 -0
  83. package/dest/shared/jest_setup.js +41 -1
  84. package/dest/shared/mock_state_view.d.ts +86 -0
  85. package/dest/shared/mock_state_view.d.ts.map +1 -0
  86. package/dest/shared/mock_state_view.js +186 -0
  87. package/dest/shared/submit-transactions.d.ts +2 -2
  88. package/dest/shared/submit-transactions.d.ts.map +1 -1
  89. package/dest/shared/submit-transactions.js +1 -1
  90. package/dest/shared/uniswap_l1_l2.d.ts +1 -1
  91. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  92. package/dest/shared/uniswap_l1_l2.js +16 -17
  93. package/dest/simulators/lending_simulator.d.ts +1 -1
  94. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  95. package/dest/simulators/lending_simulator.js +4 -4
  96. package/dest/simulators/token_simulator.d.ts +1 -1
  97. package/dest/simulators/token_simulator.d.ts.map +1 -1
  98. package/dest/simulators/token_simulator.js +3 -24
  99. package/dest/spartan/setup_test_wallets.d.ts +12 -3
  100. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  101. package/dest/spartan/setup_test_wallets.js +100 -39
  102. package/dest/spartan/tx_metrics.js +1 -1
  103. package/dest/spartan/utils/bot.d.ts +3 -2
  104. package/dest/spartan/utils/bot.d.ts.map +1 -1
  105. package/dest/spartan/utils/bot.js +2 -1
  106. package/dest/spartan/utils/config.d.ts +7 -1
  107. package/dest/spartan/utils/config.d.ts.map +1 -1
  108. package/dest/spartan/utils/config.js +3 -1
  109. package/dest/spartan/utils/index.d.ts +4 -2
  110. package/dest/spartan/utils/index.d.ts.map +1 -1
  111. package/dest/spartan/utils/index.js +5 -1
  112. package/dest/spartan/utils/k8s.d.ts +3 -1
  113. package/dest/spartan/utils/k8s.d.ts.map +1 -1
  114. package/dest/spartan/utils/k8s.js +6 -0
  115. package/dest/spartan/utils/nodes.d.ts +4 -5
  116. package/dest/spartan/utils/nodes.d.ts.map +1 -1
  117. package/dest/spartan/utils/nodes.js +9 -9
  118. package/dest/spartan/utils/pod_logs.d.ts +25 -0
  119. package/dest/spartan/utils/pod_logs.d.ts.map +1 -0
  120. package/dest/spartan/utils/pod_logs.js +74 -0
  121. package/dest/test-wallet/test_wallet.d.ts +84 -0
  122. package/dest/test-wallet/test_wallet.d.ts.map +1 -0
  123. package/dest/test-wallet/test_wallet.js +249 -0
  124. package/dest/test-wallet/utils.d.ts +41 -0
  125. package/dest/test-wallet/utils.d.ts.map +1 -0
  126. package/dest/test-wallet/utils.js +71 -0
  127. package/dest/test-wallet/wallet_worker_script.d.ts +2 -0
  128. package/dest/test-wallet/wallet_worker_script.d.ts.map +1 -0
  129. package/dest/test-wallet/wallet_worker_script.js +48 -0
  130. package/dest/test-wallet/worker_wallet.d.ts +52 -0
  131. package/dest/test-wallet/worker_wallet.d.ts.map +1 -0
  132. package/dest/test-wallet/worker_wallet.js +151 -0
  133. package/dest/test-wallet/worker_wallet_schema.d.ts +279 -0
  134. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -0
  135. package/dest/test-wallet/worker_wallet_schema.js +10 -0
  136. package/package.json +43 -43
  137. package/src/bench/client_flows/client_flows_benchmark.ts +31 -18
  138. package/src/bench/client_flows/config.ts +9 -1
  139. package/src/bench/utils.ts +8 -3
  140. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +31 -21
  141. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +7 -8
  142. package/src/e2e_deploy_contract/deploy_test.ts +3 -3
  143. package/src/e2e_epochs/epochs_test.ts +85 -63
  144. package/src/e2e_fees/bridging_race.notest.ts +1 -1
  145. package/src/e2e_fees/fees_test.ts +21 -29
  146. package/src/e2e_nested_contract/nested_contract_test.ts +7 -5
  147. package/src/e2e_p2p/inactivity_slash_test.ts +7 -7
  148. package/src/e2e_p2p/p2p_network.ts +58 -37
  149. package/src/e2e_p2p/reqresp/utils.ts +62 -13
  150. package/src/e2e_p2p/shared.ts +74 -60
  151. package/src/e2e_storage_proof/fixtures/storage_proof.json +915 -0
  152. package/src/e2e_storage_proof/fixtures/storage_proof_fetcher.ts +190 -0
  153. package/src/e2e_storage_proof/fixtures/storage_proof_fixture.ts +173 -0
  154. package/src/e2e_token_contract/token_contract_test.ts +26 -9
  155. package/src/fixtures/authwit_proxy.ts +54 -0
  156. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  157. package/src/fixtures/e2e_prover_test.ts +46 -55
  158. package/src/fixtures/elu_monitor.ts +126 -0
  159. package/src/fixtures/fixtures.ts +10 -0
  160. package/src/fixtures/get_bb_config.ts +7 -6
  161. package/src/fixtures/ha_setup.ts +3 -1
  162. package/src/fixtures/setup.ts +124 -231
  163. package/src/fixtures/setup_p2p_test.ts +33 -32
  164. package/src/fixtures/token_utils.ts +3 -3
  165. package/src/guides/up_quick_start.sh +3 -3
  166. package/src/legacy-jest-resolver.cjs +135 -0
  167. package/src/shared/cross_chain_test_harness.ts +13 -9
  168. package/src/shared/gas_portal_test_harness.ts +1 -1
  169. package/src/shared/index.ts +1 -0
  170. package/src/shared/jest_setup.ts +51 -1
  171. package/src/shared/mock_state_view.ts +188 -0
  172. package/src/shared/submit-transactions.ts +3 -2
  173. package/src/shared/uniswap_l1_l2.ts +38 -33
  174. package/src/simulators/lending_simulator.ts +8 -4
  175. package/src/simulators/token_simulator.ts +6 -30
  176. package/src/spartan/setup_test_wallets.ts +141 -32
  177. package/src/spartan/tx_metrics.ts +1 -1
  178. package/src/spartan/utils/bot.ts +4 -1
  179. package/src/spartan/utils/config.ts +2 -0
  180. package/src/spartan/utils/index.ts +7 -0
  181. package/src/spartan/utils/k8s.ts +8 -0
  182. package/src/spartan/utils/nodes.ts +15 -10
  183. package/src/spartan/utils/pod_logs.ts +99 -0
  184. package/src/test-wallet/test_wallet.ts +351 -0
  185. package/src/test-wallet/utils.ts +112 -0
  186. package/src/test-wallet/wallet_worker_script.ts +60 -0
  187. package/src/test-wallet/worker_wallet.ts +214 -0
  188. package/src/test-wallet/worker_wallet_schema.ts +13 -0
@@ -0,0 +1,249 @@
1
+ import { EcdsaKAccountContract, EcdsaRAccountContract } from '@aztec/accounts/ecdsa';
2
+ import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
3
+ import { StubEcdsaAccountContractArtifact, createStubEcdsaAccount } from '@aztec/accounts/stub/ecdsa';
4
+ import { StubSchnorrAccountContractArtifact, createStubSchnorrAccount } from '@aztec/accounts/stub/schnorr';
5
+ import { NO_FROM } from '@aztec/aztec.js/account';
6
+ import { SetPublicAuthwitContractInteraction, computeInnerAuthWitHashFromAction, isContractFunctionInteractionCallIntent, lookupValidity } from '@aztec/aztec.js/authorization';
7
+ import { AccountManager } from '@aztec/aztec.js/wallet';
8
+ import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
9
+ import { DefaultEntrypoint } from '@aztec/entrypoints/default';
10
+ import { Fr } from '@aztec/foundation/curves/bn254';
11
+ import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
12
+ import { getPXEConfig } from '@aztec/pxe/config';
13
+ import { createPXE } from '@aztec/pxe/server';
14
+ import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
15
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
16
+ import { SimulationOverrides } from '@aztec/stdlib/tx';
17
+ import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
18
+ import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
19
+ import { AztecNodeProxy, ProvenTx } from './utils.js';
20
+ /**
21
+ * Wallet implementation that stores accounts in memory and provides extra debugging
22
+ * utilities
23
+ * It is intended to be used in e2e tests.
24
+ */ export class TestWallet extends BaseWallet {
25
+ nodeRef;
26
+ constructor(pxe, nodeRef){
27
+ super(pxe, nodeRef), this.nodeRef = nodeRef, this.accounts = new Map(), this.simulationMode = 'kernelless';
28
+ }
29
+ static async create(node, overridePXEConfig, options = {
30
+ loggers: {}
31
+ }) {
32
+ const nodeRef = new AztecNodeProxy(node);
33
+ const pxeConfig = Object.assign(getPXEConfig(), {
34
+ proverEnabled: overridePXEConfig?.proverEnabled ?? false,
35
+ ...overridePXEConfig
36
+ });
37
+ const pxe = await createPXE(nodeRef, pxeConfig, options);
38
+ return new TestWallet(pxe, nodeRef);
39
+ }
40
+ /**
41
+ * Updates the underlying node that this wallet and its PXE communicate with.
42
+ * @param node - The new AztecNode to forward all calls to.
43
+ */ updateNode(node) {
44
+ this.nodeRef.updateTargetNode(node);
45
+ }
46
+ createSchnorrAccount(secret, salt, signingKey) {
47
+ signingKey = signingKey ?? deriveSigningKey(secret);
48
+ return this.createAccount({
49
+ secret,
50
+ salt,
51
+ type: 'schnorr',
52
+ contract: new SchnorrAccountContract(signingKey)
53
+ });
54
+ }
55
+ createECDSARAccount(secret, salt, signingKey) {
56
+ return this.createAccount({
57
+ secret,
58
+ salt,
59
+ type: 'ecdsasecp256r1',
60
+ contract: new EcdsaRAccountContract(signingKey)
61
+ });
62
+ }
63
+ createECDSAKAccount(secret, salt, signingKey) {
64
+ return this.createAccount({
65
+ secret,
66
+ salt,
67
+ type: 'ecdsasecp256k1',
68
+ contract: new EcdsaKAccountContract(signingKey)
69
+ });
70
+ }
71
+ /**
72
+ * Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
73
+ */ async buildAccountOverrides(addresses) {
74
+ const accounts = await this.getAccounts();
75
+ const contracts = {};
76
+ const filtered = accounts.filter((acc)=>addresses.some((addr)=>addr.equals(acc.item)));
77
+ for (const account of filtered){
78
+ const address = account.item;
79
+ const originalAccount = await this.getAccountFromAddress(address);
80
+ const completeAddress = originalAccount.getCompleteAddress();
81
+ const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
82
+ if (!contractInstance) {
83
+ throw new Error(`No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`);
84
+ }
85
+ const stubArtifact = this.getStubArtifactFor(address);
86
+ const stubConstructorArgs = this.getTypeFor(address) === 'schnorr' ? [
87
+ Fr.ZERO,
88
+ Fr.ZERO
89
+ ] : [
90
+ Buffer.alloc(32),
91
+ Buffer.alloc(32)
92
+ ];
93
+ const stubInstance = await getContractInstanceFromInstantiationParams(stubArtifact, {
94
+ salt: Fr.random(),
95
+ constructorArgs: stubConstructorArgs
96
+ });
97
+ contracts[address.toString()] = {
98
+ instance: stubInstance,
99
+ artifact: stubArtifact
100
+ };
101
+ }
102
+ return contracts;
103
+ }
104
+ accounts;
105
+ getTypeFor(address) {
106
+ return this.accounts.get(address.toString())?.type ?? 'schnorr';
107
+ }
108
+ getStubArtifactFor(address) {
109
+ return this.getTypeFor(address) === 'schnorr' ? StubSchnorrAccountContractArtifact : StubEcdsaAccountContractArtifact;
110
+ }
111
+ getStubAccountFor(address, completeAddress) {
112
+ return this.getTypeFor(address) === 'schnorr' ? createStubSchnorrAccount(completeAddress) : createStubEcdsaAccount(completeAddress);
113
+ }
114
+ /**
115
+ * Controls how the test wallet simulates transactions:
116
+ * - `kernelless`: Skips kernel circuits but uses the real account contract. Default.
117
+ * - `kernelless-override`: Skips kernels and replaces the account with a stub that doesn't do authwit validation.
118
+ * - `full`: Uses real kernel circuits and real account contracts. Slow!
119
+ */ simulationMode;
120
+ setSimulationMode(mode) {
121
+ this.simulationMode = mode;
122
+ }
123
+ setMinFeePadding(value) {
124
+ this.minFeePadding = value ?? 0.5;
125
+ }
126
+ getAccountFromAddress(address) {
127
+ const entry = this.accounts.get(address?.toString() ?? '');
128
+ if (!entry) {
129
+ throw new Error(`Account not found in wallet for address: ${address}`);
130
+ }
131
+ return Promise.resolve(entry.account);
132
+ }
133
+ getAccounts() {
134
+ return Promise.resolve(Array.from(this.accounts.values()).map((entry)=>({
135
+ alias: '',
136
+ item: entry.account.getAddress()
137
+ })));
138
+ }
139
+ async createAccount(accountData) {
140
+ const secret = accountData?.secret ?? Fr.random();
141
+ const salt = accountData?.salt ?? Fr.random();
142
+ const type = accountData?.type ?? 'schnorr';
143
+ const contract = accountData?.contract ?? new SchnorrAccountContract(GrumpkinScalar.random());
144
+ const accountManager = await AccountManager.create(this, secret, contract, salt);
145
+ const instance = accountManager.getInstance();
146
+ const artifact = await contract.getContractArtifact();
147
+ await this.registerContract(instance, artifact, secret);
148
+ const address = accountManager.address.toString();
149
+ this.accounts.set(address, {
150
+ account: await accountManager.getAccount(),
151
+ type
152
+ });
153
+ return accountManager;
154
+ }
155
+ lookupValidity(onBehalfOf, intent, witness) {
156
+ return lookupValidity(this, onBehalfOf, intent, witness);
157
+ }
158
+ setPublicAuthWit(from, messageHashOrIntent, authorized) {
159
+ return SetPublicAuthwitContractInteraction.create(this, from, messageHashOrIntent, authorized);
160
+ }
161
+ async createAuthWit(from, intent) {
162
+ const account = await this.getAccountFromAddress(from);
163
+ const chainInfo = await this.getChainInfo();
164
+ let intentInnerHash;
165
+ if ('caller' in intent) {
166
+ const call = isContractFunctionInteractionCallIntent(intent) ? await intent.action.getFunctionCall() : intent.call;
167
+ const innerHash = await computeInnerAuthWitHashFromAction(intent.caller, call);
168
+ intentInnerHash = {
169
+ innerHash,
170
+ consumer: call.to
171
+ };
172
+ } else {
173
+ intentInnerHash = intent;
174
+ }
175
+ return account.createAuthWit(intentInnerHash, chainInfo);
176
+ }
177
+ async simulateViaEntrypoint(executionPayload, opts) {
178
+ const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement } = opts;
179
+ const scopes = this.scopesFrom(from, additionalScopes);
180
+ const skipKernels = this.simulationMode !== 'full';
181
+ const useOverride = this.simulationMode === 'kernelless-override';
182
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
183
+ const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
184
+ feeExecutionPayload,
185
+ executionPayload
186
+ ]) : executionPayload;
187
+ const chainInfo = await this.getChainInfo();
188
+ let overrides;
189
+ let txRequest;
190
+ if (useOverride) {
191
+ const accountOverrides = await this.buildAccountOverrides(scopes);
192
+ overrides = new SimulationOverrides(accountOverrides);
193
+ }
194
+ if (from === NO_FROM) {
195
+ const entrypoint = new DefaultEntrypoint();
196
+ txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
197
+ } else {
198
+ let fromAccount;
199
+ if (useOverride) {
200
+ const originalAccount = await this.getAccountFromAddress(from);
201
+ fromAccount = this.getStubAccountFor(from, originalAccount.getCompleteAddress());
202
+ } else {
203
+ fromAccount = await this.getAccountFromAddress(from);
204
+ }
205
+ const executionOptions = {
206
+ txNonce: Fr.random(),
207
+ cancellable: this.cancellableTransactions,
208
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
209
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
210
+ };
211
+ txRequest = await fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
212
+ }
213
+ const result = await this.pxe.simulateTx(txRequest, {
214
+ simulatePublic: true,
215
+ skipKernels,
216
+ skipFeeEnforcement,
217
+ skipTxValidation,
218
+ overrides,
219
+ scopes
220
+ });
221
+ const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
222
+ return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
223
+ }
224
+ async proveTx(exec, opts) {
225
+ const fee = await this.completeFeeOptions({
226
+ from: opts.from,
227
+ feePayer: exec.feePayer,
228
+ gasSettings: opts.fee?.gasSettings
229
+ });
230
+ const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(exec, opts.from, fee);
231
+ const txProvingResult = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
232
+ return new ProvenTx(this.aztecNode, await txProvingResult.toTx(), txProvingResult.getOffchainEffects(), txProvingResult.stats);
233
+ }
234
+ getTxReceipt(txHash) {
235
+ return this.aztecNode.getTxReceipt(txHash);
236
+ }
237
+ getNotes(filter) {
238
+ return this.pxe.debug.getNotes(filter);
239
+ }
240
+ getSyncedBlockHeader() {
241
+ return this.pxe.getSyncedBlockHeader();
242
+ }
243
+ sync() {
244
+ return this.pxe.debug.sync();
245
+ }
246
+ stop() {
247
+ return this.pxe.stop();
248
+ }
249
+ }
@@ -0,0 +1,41 @@
1
+ import { ContractFunctionInteraction, DeployMethod, type DeployOptions, type NoWait, type SendInteractionOptions, type WaitOpts } from '@aztec/aztec.js/contracts';
2
+ import { type AztecNode } from '@aztec/aztec.js/node';
3
+ import { type OffchainEffect, type ProvingStats, Tx, TxHash, type TxReceipt } from '@aztec/stdlib/tx';
4
+ import type { TestWallet } from './test_wallet.js';
5
+ export type ProvenTxSendOpts = {
6
+ wait?: NoWait | WaitOpts;
7
+ };
8
+ export type ProvenTxSendReturn<T extends NoWait | WaitOpts | undefined> = T extends NoWait ? TxHash : TxReceipt;
9
+ export declare class ProvenTx extends Tx {
10
+ private node;
11
+ offchainEffects: OffchainEffect[];
12
+ stats?: ProvingStats | undefined;
13
+ constructor(node: AztecNode, tx: Tx, offchainEffects: OffchainEffect[], stats?: ProvingStats | undefined);
14
+ send(options?: Omit<ProvenTxSendOpts, 'wait'>): Promise<TxReceipt>;
15
+ send<W extends ProvenTxSendOpts['wait']>(options: ProvenTxSendOpts & {
16
+ wait: W;
17
+ }): Promise<ProvenTxSendReturn<W>>;
18
+ private contextualizeError;
19
+ }
20
+ export declare function proveInteraction(wallet: TestWallet, interaction: ContractFunctionInteraction | DeployMethod, options: SendInteractionOptions | DeployOptions): Promise<ProvenTx>;
21
+ /**
22
+ * Extends AztecNode via declaration merging so instances can be used wherever AztecNode is expected.
23
+ * The actual method forwarding is handled by a Proxy in the class constructor.
24
+ */
25
+ export interface AztecNodeProxy extends AztecNode {
26
+ }
27
+ /**
28
+ * Mutable wrapper around an AztecNode that forwards all calls to the current target.
29
+ * Allows swapping the underlying node at runtime via updateTargetNode, which is useful
30
+ * for tests that need to redirect a wallet from one node to another without recreating it.
31
+ */
32
+ export declare class AztecNodeProxy {
33
+ private target;
34
+ constructor(target: AztecNode);
35
+ /**
36
+ * Updates the underlying node that this reference points to.
37
+ * @param node - The new node to forward calls to.
38
+ */
39
+ updateTargetNode(node: AztecNode): void;
40
+ }
41
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0LXdhbGxldC91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsMkJBQTJCLEVBQzNCLFlBQVksRUFDWixLQUFLLGFBQWEsRUFFbEIsS0FBSyxNQUFNLEVBQ1gsS0FBSyxzQkFBc0IsRUFDM0IsS0FBSyxRQUFRLEVBRWQsTUFBTSwyQkFBMkIsQ0FBQztBQUNuQyxPQUFPLEVBQUUsS0FBSyxTQUFTLEVBQWEsTUFBTSx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AEhH,qBAAa,QAAS,SAAQ,EAAE;IAE5B,OAAO,CAAC,IAAI;IAEL,eAAe,EAAE,cAAc,EAAE;IACjC,KAAK,CAAC;IAJf,YACU,IAAI,EAAE,SAAS,EACvB,EAAE,EAAE,EAAE,EACC,eAAe,EAAE,cAAc,EAAE,EACjC,KAAK,CAAC,0BAAc,EAG5B;IAED,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACnE,IAAI,CAAC,CAAC,SAAS,gBAAgB,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,gBAAgB,GAAG;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;IAelH,OAAO,CAAC,kBAAkB;CAU3B;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,UAAU,EAClB,WAAW,EAAE,2BAA2B,GAAG,YAAY,EACvD,OAAO,EAAE,sBAAsB,GAAG,aAAa,qBAShD;AAED;;;GAGG;AAEH,MAAM,WAAW,cAAe,SAAQ,SAAS;CAAG;AAEpD;;;;GAIG;AAEH,qBAAa,cAAc;IACb,OAAO,CAAC,MAAM;IAA1B,YAAoB,MAAM,EAAE,SAAS,EAYpC;IAED;;;OAGG;IACH,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAEtC;CACF"}
@@ -0,0 +1,71 @@
1
+ import { DeployMethod, NO_WAIT, toSendOptions } from '@aztec/aztec.js/contracts';
2
+ import { waitForTx } from '@aztec/aztec.js/node';
3
+ import { SimulationError } from '@aztec/stdlib/errors';
4
+ import { Tx } from '@aztec/stdlib/tx';
5
+ import { inspect } from 'util';
6
+ export class ProvenTx extends Tx {
7
+ node;
8
+ offchainEffects;
9
+ stats;
10
+ constructor(node, tx, offchainEffects, stats){
11
+ super(tx.getTxHash(), tx.data, tx.chonkProof, tx.contractClassLogFields, tx.publicFunctionCalldata), this.node = node, this.offchainEffects = offchainEffects, this.stats = stats;
12
+ }
13
+ async send(options) {
14
+ const txHash = this.getTxHash();
15
+ await this.node.sendTx(this).catch((err)=>{
16
+ throw this.contextualizeError(err, inspect(this));
17
+ });
18
+ if (options?.wait === NO_WAIT) {
19
+ return txHash;
20
+ }
21
+ const waitOpts = typeof options?.wait === 'object' ? options.wait : undefined;
22
+ return await waitForTx(this.node, txHash, waitOpts);
23
+ }
24
+ contextualizeError(err, ...context) {
25
+ let contextStr = '';
26
+ if (context.length > 0) {
27
+ contextStr = `\nContext:\n${context.join('\n')}`;
28
+ }
29
+ if (err instanceof SimulationError) {
30
+ err.setAztecContext(contextStr);
31
+ }
32
+ return err;
33
+ }
34
+ }
35
+ export async function proveInteraction(wallet, interaction, options) {
36
+ let execPayload;
37
+ if (interaction instanceof DeployMethod) {
38
+ execPayload = await interaction.request(interaction.convertDeployOptionsToRequestOptions(options));
39
+ } else {
40
+ execPayload = await interaction.request(options);
41
+ }
42
+ return wallet.proveTx(execPayload, toSendOptions(options));
43
+ }
44
+ /**
45
+ * Mutable wrapper around an AztecNode that forwards all calls to the current target.
46
+ * Allows swapping the underlying node at runtime via updateTargetNode, which is useful
47
+ * for tests that need to redirect a wallet from one node to another without recreating it.
48
+ */ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
49
+ export class AztecNodeProxy {
50
+ target;
51
+ constructor(target){
52
+ this.target = target;
53
+ return new Proxy(this, {
54
+ get: (obj, prop, receiver)=>{
55
+ // Own properties and methods (updateTargetNode, target) are served directly.
56
+ if (Reflect.has(obj, prop)) {
57
+ return Reflect.get(obj, prop, receiver);
58
+ }
59
+ // Everything else is forwarded to the current target node.
60
+ const val = obj.target[prop];
61
+ return typeof val === 'function' ? val.bind(obj.target) : val;
62
+ }
63
+ });
64
+ }
65
+ /**
66
+ * Updates the underlying node that this reference points to.
67
+ * @param node - The new node to forward calls to.
68
+ */ updateTargetNode(node) {
69
+ this.target = node;
70
+ }
71
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2FsbGV0X3dvcmtlcl9zY3JpcHQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0LXdhbGxldC93YWxsZXRfd29ya2VyX3NjcmlwdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet_worker_script.d.ts","sourceRoot":"","sources":["../../src/test-wallet/wallet_worker_script.ts"],"names":[],"mappings":""}
@@ -0,0 +1,48 @@
1
+ import { createAztecNodeClient } from '@aztec/aztec.js/node';
2
+ import { jsonStringify } from '@aztec/foundation/json-rpc';
3
+ import { createLogger } from '@aztec/foundation/log';
4
+ import { parseWithOptionals, schemaHasMethod } from '@aztec/foundation/schemas';
5
+ import { NodeListener, TransportServer } from '@aztec/foundation/transport';
6
+ import { Tx } from '@aztec/stdlib/tx';
7
+ import { workerData } from 'worker_threads';
8
+ import { TestWallet } from './test_wallet.js';
9
+ import { WorkerWalletSchema } from './worker_wallet_schema.js';
10
+ const logger = createLogger('e2e:test-wallet:worker');
11
+ try {
12
+ const { nodeUrl, pxeConfig } = workerData;
13
+ logger.info('Initializing worker wallet', {
14
+ nodeUrl
15
+ });
16
+ const node = createAztecNodeClient(nodeUrl);
17
+ const wallet = await TestWallet.create(node, pxeConfig);
18
+ logger.info('Worker wallet initialized');
19
+ const customMethods = {
20
+ proveTx: async (exec, opts)=>{
21
+ const provenTx = await wallet.proveTx(exec, opts);
22
+ return new Tx(provenTx.getTxHash(), provenTx.data, provenTx.chonkProof, provenTx.contractClassLogFields, provenTx.publicFunctionCalldata);
23
+ },
24
+ registerAccount: async (secret, salt)=>{
25
+ const manager = await wallet.createSchnorrAccount(secret, salt);
26
+ return manager.address;
27
+ }
28
+ };
29
+ const schema = WorkerWalletSchema;
30
+ const listener = new NodeListener();
31
+ const server = new TransportServer(listener, async (msg)=>{
32
+ if (!schemaHasMethod(schema, msg.fn)) {
33
+ throw new Error(`Unknown method: ${msg.fn}`);
34
+ }
35
+ const jsonParams = JSON.parse(msg.args);
36
+ const args = await parseWithOptionals(jsonParams, schema[msg.fn].parameters());
37
+ // we have to erase the fn type in order to be able to spread ...args
38
+ const handler = msg.fn in customMethods ? customMethods[msg.fn] : undefined;
39
+ const result = handler ? await handler(...args) : await wallet[msg.fn](...args);
40
+ return jsonStringify(result);
41
+ });
42
+ server.start();
43
+ } catch (err) {
44
+ logger.error('Worker wallet initialization failed', {
45
+ error: err instanceof Error ? err.stack : String(err)
46
+ });
47
+ process.exit(1);
48
+ }
@@ -0,0 +1,52 @@
1
+ import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
2
+ import type { InteractionWaitOptions, SendReturn } from '@aztec/aztec.js/contracts';
3
+ import type { Aliased, AppCapabilities, BatchResults, BatchedMethod, ContractClassMetadata, ContractMetadata, ExecuteUtilityOptions, PrivateEvent, PrivateEventFilter, ProfileOptions, SendOptions, SimulateOptions, TxSimulationResultWithAppOffset, Wallet, WalletCapabilities } from '@aztec/aztec.js/wallet';
4
+ import type { ChainInfo } from '@aztec/entrypoints/interfaces';
5
+ import type { Fr } from '@aztec/foundation/curves/bn254';
6
+ import type { PXEConfig } from '@aztec/pxe/config';
7
+ import type { ContractArtifact, EventMetadataDefinition, FunctionCall } from '@aztec/stdlib/abi';
8
+ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
9
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
+ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
11
+ import type { ExecutionPayload, TxProfileResult, UtilityExecutionResult } from '@aztec/stdlib/tx';
12
+ import { Tx } from '@aztec/stdlib/tx';
13
+ /**
14
+ * Wallet implementation that offloads all work to a worker thread.
15
+ * Implements the Wallet interface by proxying calls over a transport layer
16
+ * using JSON serialization with Zod schema parsing on both ends.
17
+ */
18
+ export declare class WorkerWallet implements Wallet {
19
+ private worker;
20
+ private client;
21
+ private constructor();
22
+ /**
23
+ * Creates a WorkerWallet by spawning a worker thread that creates a TestWallet internally.
24
+ * @param nodeUrl - URL of the Aztec node to connect to.
25
+ * @param pxeConfig - Optional PXE configuration overrides.
26
+ * @returns A WorkerWallet ready to use.
27
+ */
28
+ static create(nodeUrl: string, pxeConfig?: Partial<PXEConfig>): Promise<WorkerWallet>;
29
+ private callRaw;
30
+ private call;
31
+ getChainInfo(): Promise<ChainInfo>;
32
+ getContractMetadata(address: AztecAddress): Promise<ContractMetadata>;
33
+ getContractClassMetadata(id: Fr): Promise<ContractClassMetadata>;
34
+ getPrivateEvents<T>(eventMetadata: EventMetadataDefinition, eventFilter: PrivateEventFilter): Promise<PrivateEvent<T>[]>;
35
+ registerSender(address: AztecAddress, alias?: string): Promise<AztecAddress>;
36
+ getAddressBook(): Promise<Aliased<AztecAddress>[]>;
37
+ getAccounts(): Promise<Aliased<AztecAddress>[]>;
38
+ registerContract(instance: ContractInstanceWithAddress, artifact?: ContractArtifact, secretKey?: Fr): Promise<ContractInstanceWithAddress>;
39
+ simulateTx(exec: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResultWithAppOffset>;
40
+ executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult>;
41
+ profileTx(exec: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
42
+ sendTx<W extends InteractionWaitOptions = undefined>(exec: ExecutionPayload, opts: SendOptions<W>): Promise<SendReturn<W>>;
43
+ proveTx(exec: ExecutionPayload, opts: Omit<SendOptions, 'wait'>): Promise<Tx>;
44
+ /** Registers an account inside the worker's TestWallet, populating its accounts map. */
45
+ registerAccount(secret: Fr, salt: Fr): Promise<AztecAddress>;
46
+ createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
47
+ requestCapabilities(manifest: AppCapabilities): Promise<WalletCapabilities>;
48
+ batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
49
+ /** Shuts down the worker thread and closes the transport. */
50
+ stop(): Promise<void>;
51
+ }
52
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid29ya2VyX3dhbGxldC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3Rlc3Qtd2FsbGV0L3dvcmtlcl93YWxsZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLGVBQWUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBQ2pGLE9BQU8sS0FBSyxFQUFFLHNCQUFzQixFQUFFLFVBQVUsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBQ3BGLE9BQU8sS0FBSyxFQUNWLE9BQU8sRUFDUCxlQUFlLEVBQ2YsWUFBWSxFQUNaLGFBQWEsRUFDYixxQkFBcUIsRUFDckIsZ0JBQWdCLEVBQ2hCLHFCQUFxQixFQUNyQixZQUFZLEVBQ1osa0JBQWtCLEVBQ2xCLGNBQWMsRUFDZCxXQUFXLEVBQ1gsZUFBZSxFQUNmLCtCQUErQixFQUMvQixNQUFNLEVBQ04sa0JBQWtCLEVBQ25CLE1BQU0sd0JBQXdCLENBQUM7QUFDaEMsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDL0QsT0FBTyxLQUFLLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFPekQsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFDbkQsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsdUJBQXVCLEVBQUUsWUFBWSxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFDakcsT0FBTy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,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAE1E;IAED,KAAK,CAAC,KAAK,CAAC,CAAC,SAAS,SAAS,aAAa,EAAE,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAEpF;IAED,6DAA6D;IACvD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAG1B;CACF"}
@@ -0,0 +1,151 @@
1
+ import { jsonStringify } from '@aztec/foundation/json-rpc';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ import { promiseWithResolvers } from '@aztec/foundation/promise';
4
+ import { sleep } from '@aztec/foundation/sleep';
5
+ import { NodeConnector, TransportClient } from '@aztec/foundation/transport';
6
+ import { Worker } from 'worker_threads';
7
+ import { WorkerWalletSchema } from './worker_wallet_schema.js';
8
+ const log = createLogger('e2e:test-wallet:worker-wallet');
9
+ const WORKER_READY_TIMEOUT_MS = 120_000;
10
+ /**
11
+ * Wallet implementation that offloads all work to a worker thread.
12
+ * Implements the Wallet interface by proxying calls over a transport layer
13
+ * using JSON serialization with Zod schema parsing on both ends.
14
+ */ export class WorkerWallet {
15
+ worker;
16
+ client;
17
+ constructor(worker, client){
18
+ this.worker = worker;
19
+ this.client = client;
20
+ }
21
+ /**
22
+ * Creates a WorkerWallet by spawning a worker thread that creates a TestWallet internally.
23
+ * @param nodeUrl - URL of the Aztec node to connect to.
24
+ * @param pxeConfig - Optional PXE configuration overrides.
25
+ * @returns A WorkerWallet ready to use.
26
+ */ static async create(nodeUrl, pxeConfig) {
27
+ // replace stc/ with dest/ so the wallet works in Jest tests
28
+ const workerUrl = new URL('./wallet_worker_script.js', import.meta.url);
29
+ workerUrl.pathname = workerUrl.pathname.replace('/src/', '/dest/');
30
+ // remove JEST_WORKER_ID so the worker uses pino-pretty transport instead of Jest's raw output.
31
+ const { JEST_WORKER_ID: _, ...parentEnv } = process.env;
32
+ const worker = new Worker(workerUrl, {
33
+ workerData: {
34
+ nodeUrl,
35
+ pxeConfig
36
+ },
37
+ env: {
38
+ ...parentEnv,
39
+ ...process.stderr.isTTY || process.env.FORCE_COLOR ? {
40
+ FORCE_COLOR: '1'
41
+ } : {},
42
+ LOG_LEVEL: process.env.WORKER_LOG_LEVEL ?? 'warn'
43
+ }
44
+ });
45
+ const connector = new NodeConnector(worker);
46
+ const client = new TransportClient(connector);
47
+ await client.open();
48
+ const wallet = new WorkerWallet(worker, client);
49
+ const { promise: workerDied, reject: rejectWorkerDied } = promiseWithResolvers();
50
+ // reject if the worker exits or errors before the warmup completes.
51
+ const onError = (err)=>{
52
+ worker.off('exit', onExit);
53
+ rejectWorkerDied(new Error(`Worker wallet thread error: ${err.message}`));
54
+ };
55
+ const onExit = (code)=>{
56
+ worker.off('error', onError);
57
+ rejectWorkerDied(new Error(`Worker wallet thread exited with code ${code} before becoming ready`));
58
+ };
59
+ worker.once('error', onError);
60
+ worker.once('exit', onExit);
61
+ const timeout = sleep(WORKER_READY_TIMEOUT_MS).then(()=>{
62
+ throw new Error(`Worker wallet creation timed out after ${WORKER_READY_TIMEOUT_MS / 1000}s`);
63
+ });
64
+ try {
65
+ // wait for worker wallet to start
66
+ await Promise.race([
67
+ wallet.getChainInfo(),
68
+ workerDied,
69
+ timeout
70
+ ]);
71
+ } catch (err) {
72
+ log.error('Worker wallet creation failed, cleaning up', {
73
+ error: String(err)
74
+ });
75
+ client.close();
76
+ await worker.terminate();
77
+ throw err;
78
+ } finally{
79
+ worker.off('error', onError);
80
+ worker.off('exit', onExit);
81
+ }
82
+ return wallet;
83
+ }
84
+ async callRaw(fn, ...args) {
85
+ const argsJson = jsonStringify(args);
86
+ return await this.client.request({
87
+ fn,
88
+ args: argsJson
89
+ });
90
+ }
91
+ async call(fn, ...args) {
92
+ const resultJson = await this.callRaw(fn, ...args);
93
+ const methodSchema = WorkerWalletSchema[fn];
94
+ return methodSchema.returnType().parseAsync(JSON.parse(resultJson));
95
+ }
96
+ getChainInfo() {
97
+ return this.call('getChainInfo');
98
+ }
99
+ getContractMetadata(address) {
100
+ return this.call('getContractMetadata', address);
101
+ }
102
+ getContractClassMetadata(id) {
103
+ return this.call('getContractClassMetadata', id);
104
+ }
105
+ getPrivateEvents(eventMetadata, eventFilter) {
106
+ return this.call('getPrivateEvents', eventMetadata, eventFilter);
107
+ }
108
+ registerSender(address, alias) {
109
+ return this.call('registerSender', address, alias);
110
+ }
111
+ getAddressBook() {
112
+ return this.call('getAddressBook');
113
+ }
114
+ getAccounts() {
115
+ return this.call('getAccounts');
116
+ }
117
+ registerContract(instance, artifact, secretKey) {
118
+ return this.call('registerContract', instance, artifact, secretKey);
119
+ }
120
+ simulateTx(exec, opts) {
121
+ return this.call('simulateTx', exec, opts);
122
+ }
123
+ executeUtility(call, opts) {
124
+ return this.call('executeUtility', call, opts);
125
+ }
126
+ profileTx(exec, opts) {
127
+ return this.call('profileTx', exec, opts);
128
+ }
129
+ sendTx(exec, opts) {
130
+ return this.call('sendTx', exec, opts);
131
+ }
132
+ proveTx(exec, opts) {
133
+ return this.call('proveTx', exec, opts);
134
+ }
135
+ /** Registers an account inside the worker's TestWallet, populating its accounts map. */ registerAccount(secret, salt) {
136
+ return this.call('registerAccount', secret, salt);
137
+ }
138
+ createAuthWit(from, messageHashOrIntent) {
139
+ return this.call('createAuthWit', from, messageHashOrIntent);
140
+ }
141
+ requestCapabilities(manifest) {
142
+ return this.call('requestCapabilities', manifest);
143
+ }
144
+ batch(methods) {
145
+ return this.call('batch', methods);
146
+ }
147
+ /** Shuts down the worker thread and closes the transport. */ async stop() {
148
+ this.client.close();
149
+ await this.worker.terminate();
150
+ }
151
+ }