@aztec/end-to-end 0.0.1-commit.e3c1de76 → 0.0.1-commit.e57c76e

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 (230) hide show
  1. package/README.md +27 -0
  2. package/dest/bench/client_flows/benchmark.d.ts +15 -1
  3. package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
  4. package/dest/bench/client_flows/benchmark.js +17 -0
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts +3 -3
  6. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  7. package/dest/bench/client_flows/client_flows_benchmark.js +36 -39
  8. package/dest/bench/client_flows/config.d.ts +2 -2
  9. package/dest/bench/client_flows/config.d.ts.map +1 -1
  10. package/dest/bench/client_flows/config.js +18 -0
  11. package/dest/bench/utils.d.ts +1 -1
  12. package/dest/bench/utils.d.ts.map +1 -1
  13. package/dest/bench/utils.js +8 -3
  14. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +8 -5
  15. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  16. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +36 -17
  17. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +16 -5
  18. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  19. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +42 -9
  20. package/dest/e2e_deploy_contract/deploy_test.d.ts +4 -4
  21. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  22. package/dest/e2e_deploy_contract/deploy_test.js +2 -1
  23. package/dest/e2e_epochs/epochs_test.d.ts +33 -8
  24. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  25. package/dest/e2e_epochs/epochs_test.js +143 -44
  26. package/dest/e2e_fees/fees_test.d.ts +6 -3
  27. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  28. package/dest/e2e_fees/fees_test.js +50 -17
  29. package/dest/e2e_nested_contract/nested_contract_test.d.ts +3 -3
  30. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  31. package/dest/e2e_nested_contract/nested_contract_test.js +6 -7
  32. package/dest/e2e_p2p/inactivity_slash_test.d.ts +1 -1
  33. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -1
  34. package/dest/e2e_p2p/inactivity_slash_test.js +4 -3
  35. package/dest/e2e_p2p/p2p_network.d.ts +14 -12
  36. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  37. package/dest/e2e_p2p/p2p_network.js +70 -34
  38. package/dest/e2e_p2p/reqresp/utils.d.ts +3 -3
  39. package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -1
  40. package/dest/e2e_p2p/reqresp/utils.js +67 -14
  41. package/dest/e2e_p2p/shared.d.ts +37 -8
  42. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  43. package/dest/e2e_p2p/shared.js +91 -51
  44. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +2 -0
  45. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +1 -0
  46. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.js +184 -0
  47. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts +18 -0
  48. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +1 -0
  49. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.js +120 -0
  50. package/dest/e2e_token_contract/token_contract_test.d.ts +6 -4
  51. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  52. package/dest/e2e_token_contract/token_contract_test.js +23 -11
  53. package/dest/fixtures/authwit_proxy.d.ts +15 -0
  54. package/dest/fixtures/authwit_proxy.d.ts.map +1 -0
  55. package/dest/fixtures/authwit_proxy.js +34 -0
  56. package/dest/fixtures/e2e_prover_test.d.ts +9 -8
  57. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  58. package/dest/fixtures/e2e_prover_test.js +39 -50
  59. package/dest/fixtures/elu_monitor.d.ts +21 -0
  60. package/dest/fixtures/elu_monitor.d.ts.map +1 -0
  61. package/dest/fixtures/elu_monitor.js +102 -0
  62. package/dest/fixtures/fixtures.d.ts +74 -1
  63. package/dest/fixtures/fixtures.d.ts.map +1 -1
  64. package/dest/fixtures/fixtures.js +71 -0
  65. package/dest/fixtures/get_bb_config.d.ts +1 -1
  66. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  67. package/dest/fixtures/get_bb_config.js +5 -5
  68. package/dest/fixtures/ha_setup.d.ts +71 -0
  69. package/dest/fixtures/ha_setup.d.ts.map +1 -0
  70. package/dest/fixtures/ha_setup.js +116 -0
  71. package/dest/fixtures/index.d.ts +2 -1
  72. package/dest/fixtures/index.d.ts.map +1 -1
  73. package/dest/fixtures/index.js +1 -0
  74. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts +25 -0
  75. package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts.map +1 -0
  76. package/dest/fixtures/schnorr_hardcoded_account_contract.js +37 -0
  77. package/dest/fixtures/setup.d.ts +86 -32
  78. package/dest/fixtures/setup.d.ts.map +1 -1
  79. package/dest/fixtures/setup.js +209 -169
  80. package/dest/fixtures/setup_p2p_test.d.ts +22 -10
  81. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  82. package/dest/fixtures/setup_p2p_test.js +23 -17
  83. package/dest/fixtures/token_utils.d.ts +2 -2
  84. package/dest/fixtures/token_utils.d.ts.map +1 -1
  85. package/dest/fixtures/token_utils.js +5 -7
  86. package/dest/fixtures/utils.d.ts +2 -2
  87. package/dest/fixtures/utils.d.ts.map +1 -1
  88. package/dest/fixtures/utils.js +1 -1
  89. package/dest/forward-compatibility/wallet_rpc_client.d.ts +7 -0
  90. package/dest/forward-compatibility/wallet_rpc_client.d.ts.map +1 -0
  91. package/dest/forward-compatibility/wallet_rpc_client.js +15 -0
  92. package/dest/forward-compatibility/wallet_service.d.ts +3 -0
  93. package/dest/forward-compatibility/wallet_service.d.ts.map +1 -0
  94. package/dest/forward-compatibility/wallet_service.js +109 -0
  95. package/dest/install_legacy_contracts.d.cts +10 -0
  96. package/dest/install_legacy_contracts.d.cts.map +1 -0
  97. package/dest/legacy-jest-resolver.d.cts +3 -0
  98. package/dest/legacy-jest-resolver.d.cts.map +1 -0
  99. package/dest/shared/cross_chain_test_harness.d.ts +4 -2
  100. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  101. package/dest/shared/cross_chain_test_harness.js +22 -18
  102. package/dest/shared/gas_portal_test_harness.d.ts +8 -5
  103. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  104. package/dest/shared/gas_portal_test_harness.js +19 -10
  105. package/dest/shared/index.d.ts +2 -1
  106. package/dest/shared/index.d.ts.map +1 -1
  107. package/dest/shared/index.js +1 -0
  108. package/dest/shared/jest_setup.js +41 -1
  109. package/dest/shared/mock_state_view.d.ts +86 -0
  110. package/dest/shared/mock_state_view.d.ts.map +1 -0
  111. package/dest/shared/mock_state_view.js +186 -0
  112. package/dest/shared/submit-transactions.d.ts +2 -2
  113. package/dest/shared/submit-transactions.d.ts.map +1 -1
  114. package/dest/shared/submit-transactions.js +1 -1
  115. package/dest/shared/uniswap_l1_l2.d.ts +1 -1
  116. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  117. package/dest/shared/uniswap_l1_l2.js +57 -40
  118. package/dest/shared/wait_for_l1_to_l2_message.d.ts +13 -0
  119. package/dest/shared/wait_for_l1_to_l2_message.d.ts.map +1 -0
  120. package/dest/shared/wait_for_l1_to_l2_message.js +10 -0
  121. package/dest/simulators/lending_simulator.d.ts +10 -3
  122. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  123. package/dest/simulators/lending_simulator.js +26 -14
  124. package/dest/simulators/token_simulator.d.ts +1 -1
  125. package/dest/simulators/token_simulator.d.ts.map +1 -1
  126. package/dest/simulators/token_simulator.js +3 -24
  127. package/dest/spartan/setup_test_wallets.d.ts +12 -3
  128. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  129. package/dest/spartan/setup_test_wallets.js +108 -41
  130. package/dest/spartan/tx_metrics.d.ts +18 -4
  131. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  132. package/dest/spartan/tx_metrics.js +74 -21
  133. package/dest/spartan/utils/bot.d.ts +3 -2
  134. package/dest/spartan/utils/bot.d.ts.map +1 -1
  135. package/dest/spartan/utils/bot.js +2 -1
  136. package/dest/spartan/utils/config.d.ts +11 -28
  137. package/dest/spartan/utils/config.d.ts.map +1 -1
  138. package/dest/spartan/utils/config.js +4 -1
  139. package/dest/spartan/utils/index.d.ts +5 -3
  140. package/dest/spartan/utils/index.d.ts.map +1 -1
  141. package/dest/spartan/utils/index.js +5 -1
  142. package/dest/spartan/utils/k8s.d.ts +3 -1
  143. package/dest/spartan/utils/k8s.d.ts.map +1 -1
  144. package/dest/spartan/utils/k8s.js +6 -0
  145. package/dest/spartan/utils/nodes.d.ts +4 -5
  146. package/dest/spartan/utils/nodes.d.ts.map +1 -1
  147. package/dest/spartan/utils/nodes.js +11 -11
  148. package/dest/spartan/utils/pod_logs.d.ts +25 -0
  149. package/dest/spartan/utils/pod_logs.d.ts.map +1 -0
  150. package/dest/spartan/utils/pod_logs.js +74 -0
  151. package/dest/spartan/utils/scripts.d.ts +18 -4
  152. package/dest/spartan/utils/scripts.d.ts.map +1 -1
  153. package/dest/spartan/utils/scripts.js +19 -4
  154. package/dest/test-wallet/test_wallet.d.ts +85 -0
  155. package/dest/test-wallet/test_wallet.d.ts.map +1 -0
  156. package/dest/test-wallet/test_wallet.js +273 -0
  157. package/dest/test-wallet/utils.d.ts +41 -0
  158. package/dest/test-wallet/utils.d.ts.map +1 -0
  159. package/dest/test-wallet/utils.js +66 -0
  160. package/dest/test-wallet/wallet_worker_script.d.ts +2 -0
  161. package/dest/test-wallet/wallet_worker_script.d.ts.map +1 -0
  162. package/dest/test-wallet/wallet_worker_script.js +53 -0
  163. package/dest/test-wallet/worker_wallet.d.ts +53 -0
  164. package/dest/test-wallet/worker_wallet.d.ts.map +1 -0
  165. package/dest/test-wallet/worker_wallet.js +155 -0
  166. package/dest/test-wallet/worker_wallet_schema.d.ts +160 -0
  167. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -0
  168. package/dest/test-wallet/worker_wallet_schema.js +22 -0
  169. package/package.json +52 -45
  170. package/src/bench/client_flows/benchmark.ts +19 -0
  171. package/src/bench/client_flows/client_flows_benchmark.ts +64 -49
  172. package/src/bench/client_flows/config.ts +9 -1
  173. package/src/bench/utils.ts +10 -4
  174. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +52 -25
  175. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +56 -19
  176. package/src/e2e_deploy_contract/deploy_test.ts +6 -5
  177. package/src/e2e_epochs/epochs_test.ts +166 -68
  178. package/src/e2e_fees/bridging_race.notest.ts +1 -1
  179. package/src/e2e_fees/fees_test.ts +57 -32
  180. package/src/e2e_nested_contract/nested_contract_test.ts +10 -6
  181. package/src/e2e_p2p/inactivity_slash_test.ts +8 -7
  182. package/src/e2e_p2p/p2p_network.ts +93 -49
  183. package/src/e2e_p2p/reqresp/utils.ts +84 -17
  184. package/src/e2e_p2p/shared.ts +109 -65
  185. package/src/e2e_storage_proof/fixtures/storage_proof.json +915 -0
  186. package/src/e2e_storage_proof/fixtures/storage_proof_fetcher.ts +190 -0
  187. package/src/e2e_storage_proof/fixtures/storage_proof_fixture.ts +173 -0
  188. package/src/e2e_token_contract/token_contract_test.ts +38 -11
  189. package/src/fixtures/authwit_proxy.ts +54 -0
  190. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  191. package/src/fixtures/e2e_prover_test.ts +49 -56
  192. package/src/fixtures/elu_monitor.ts +126 -0
  193. package/src/fixtures/fixtures.ts +93 -0
  194. package/src/fixtures/get_bb_config.ts +7 -6
  195. package/src/fixtures/ha_setup.ts +188 -0
  196. package/src/fixtures/index.ts +1 -0
  197. package/src/fixtures/schnorr_hardcoded_account_contract.ts +49 -0
  198. package/src/fixtures/setup.ts +272 -233
  199. package/src/fixtures/setup_p2p_test.ts +37 -32
  200. package/src/fixtures/token_utils.ts +3 -3
  201. package/src/fixtures/utils.ts +2 -0
  202. package/src/forward-compatibility/wallet_rpc_client.ts +14 -0
  203. package/src/forward-compatibility/wallet_service.ts +104 -0
  204. package/src/guides/up_quick_start.sh +3 -5
  205. package/src/install_legacy_contracts.cjs +75 -0
  206. package/src/legacy-jest-resolver.cjs +112 -0
  207. package/src/shared/cross_chain_test_harness.ts +27 -13
  208. package/src/shared/gas_portal_test_harness.ts +21 -11
  209. package/src/shared/index.ts +1 -0
  210. package/src/shared/jest_setup.ts +51 -1
  211. package/src/shared/mock_state_view.ts +188 -0
  212. package/src/shared/submit-transactions.ts +3 -2
  213. package/src/shared/uniswap_l1_l2.ts +103 -54
  214. package/src/shared/wait_for_l1_to_l2_message.ts +23 -0
  215. package/src/simulators/lending_simulator.ts +32 -14
  216. package/src/simulators/token_simulator.ts +6 -30
  217. package/src/spartan/setup_test_wallets.ts +146 -35
  218. package/src/spartan/tx_metrics.ts +82 -24
  219. package/src/spartan/utils/bot.ts +4 -1
  220. package/src/spartan/utils/config.ts +3 -0
  221. package/src/spartan/utils/index.ts +8 -1
  222. package/src/spartan/utils/k8s.ts +8 -0
  223. package/src/spartan/utils/nodes.ts +17 -12
  224. package/src/spartan/utils/pod_logs.ts +99 -0
  225. package/src/spartan/utils/scripts.ts +43 -7
  226. package/src/test-wallet/test_wallet.ts +376 -0
  227. package/src/test-wallet/utils.ts +108 -0
  228. package/src/test-wallet/wallet_worker_script.ts +63 -0
  229. package/src/test-wallet/worker_wallet.ts +218 -0
  230. package/src/test-wallet/worker_wallet_schema.ts +13 -0
@@ -0,0 +1,376 @@
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 { type Account, type AccountContract, NO_FROM } from '@aztec/aztec.js/account';
6
+ import type { CompleteAddress } from '@aztec/aztec.js/addresses';
7
+ import {
8
+ type CallIntent,
9
+ type ContractFunctionInteractionCallIntent,
10
+ type IntentInnerHash,
11
+ SetPublicAuthwitContractInteraction,
12
+ computeInnerAuthWitHashFromAction,
13
+ isContractFunctionInteractionCallIntent,
14
+ lookupValidity,
15
+ } from '@aztec/aztec.js/authorization';
16
+ import type { AztecNode } from '@aztec/aztec.js/node';
17
+ import { AccountManager, type SendOptions } from '@aztec/aztec.js/wallet';
18
+ import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
19
+ import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
20
+ import { DefaultEntrypoint } from '@aztec/entrypoints/default';
21
+ import { Fq, Fr } from '@aztec/foundation/curves/bn254';
22
+ import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
23
+ import type { NotesFilter } from '@aztec/pxe/client/lazy';
24
+ import { type PXEConfig, getPXEConfig } from '@aztec/pxe/config';
25
+ import { PXE, type PXECreationOptions, createPXE } from '@aztec/pxe/server';
26
+ import { AuthWitness } from '@aztec/stdlib/auth-witness';
27
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
28
+ import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
29
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
30
+ import type { NoteDao } from '@aztec/stdlib/note';
31
+ import {
32
+ type BlockHeader,
33
+ type ContractOverrides,
34
+ SimulationOverrides,
35
+ type TxExecutionRequest,
36
+ type TxHash,
37
+ type TxReceipt,
38
+ } from '@aztec/stdlib/tx';
39
+ import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
40
+ import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
41
+ import type { AccountType } from '@aztec/wallets/embedded';
42
+
43
+ import { DEFAULT_MIN_FEE_PADDING } from '../fixtures/fixtures.js';
44
+ import { AztecNodeProxy, ProvenTx } from './utils.js';
45
+
46
+ /**
47
+ * Data for generating an account.
48
+ */
49
+ export interface AccountData {
50
+ secret: Fr;
51
+ salt: Fr;
52
+ type?: AccountType;
53
+ contract: AccountContract;
54
+ }
55
+
56
+ /**
57
+ * Wallet implementation that stores accounts in memory and provides extra debugging
58
+ * utilities
59
+ * It is intended to be used in e2e tests.
60
+ */
61
+ export class TestWallet extends BaseWallet {
62
+ constructor(
63
+ pxe: PXE,
64
+ private readonly nodeRef: AztecNodeProxy,
65
+ ) {
66
+ super(pxe, nodeRef);
67
+ this.minFeePadding = DEFAULT_MIN_FEE_PADDING;
68
+ }
69
+
70
+ static async create(
71
+ node: AztecNode,
72
+ overridePXEConfig?: Partial<PXEConfig>,
73
+ options: PXECreationOptions = { loggers: {} },
74
+ ): Promise<TestWallet> {
75
+ const nodeRef = new AztecNodeProxy(node);
76
+ const pxeConfig = Object.assign(getPXEConfig(), {
77
+ proverEnabled: overridePXEConfig?.proverEnabled ?? false,
78
+ ...overridePXEConfig,
79
+ });
80
+ const pxe = await createPXE(nodeRef, pxeConfig, options);
81
+ const wallet = new TestWallet(pxe, nodeRef);
82
+ await wallet.initStubClasses();
83
+ return wallet;
84
+ }
85
+
86
+ /**
87
+ * Updates the underlying node that this wallet and its PXE communicate with.
88
+ * @param node - The new AztecNode to forward all calls to.
89
+ */
90
+ updateNode(node: AztecNode): void {
91
+ this.nodeRef.updateTargetNode(node);
92
+ }
93
+
94
+ createSchnorrAccount(secret: Fr, salt: Fr, signingKey?: Fq): Promise<AccountManager> {
95
+ signingKey = signingKey ?? deriveSigningKey(secret);
96
+ return this.createAccount({ secret, salt, type: 'schnorr', contract: new SchnorrAccountContract(signingKey) });
97
+ }
98
+
99
+ createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager> {
100
+ return this.createAccount({
101
+ secret,
102
+ salt,
103
+ type: 'ecdsasecp256r1',
104
+ contract: new EcdsaRAccountContract(signingKey),
105
+ });
106
+ }
107
+
108
+ createECDSAKAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager> {
109
+ return this.createAccount({
110
+ secret,
111
+ salt,
112
+ type: 'ecdsasecp256k1',
113
+ contract: new EcdsaKAccountContract(signingKey),
114
+ });
115
+ }
116
+
117
+ // Stub class ids, populated on wallet startup
118
+ // to avoid redundant work per simulation
119
+ private stubClassIds = new Map<AccountType, Fr>();
120
+
121
+ /**
122
+ * Hashes and registers the stub class for every supported account type with PXE, populating
123
+ * stubClassIds. Called on wallet initialization.
124
+ */
125
+ private async initStubClasses(): Promise<void> {
126
+ const { id: schnorrClassId } = await getContractClassFromArtifact(StubSchnorrAccountContractArtifact);
127
+ await this.pxe.registerContractClass(StubSchnorrAccountContractArtifact);
128
+
129
+ // ecdsa stubs share the same class id
130
+ const { id: ecdsaClassId } = await getContractClassFromArtifact(StubEcdsaAccountContractArtifact);
131
+ await this.pxe.registerContractClass(StubEcdsaAccountContractArtifact);
132
+
133
+ this.stubClassIds.set('schnorr', schnorrClassId);
134
+ this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
135
+ this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
136
+ }
137
+
138
+ /**
139
+ * Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
140
+ */
141
+ protected async buildAccountOverrides(addresses: AztecAddress[]): Promise<ContractOverrides> {
142
+ const accounts = await this.getAccounts();
143
+ const contracts: ContractOverrides = {};
144
+
145
+ const filtered = accounts.filter(acc => addresses.some(addr => addr.equals(acc.item)));
146
+
147
+ for (const account of filtered) {
148
+ const address = account.item;
149
+ const originalAccount = await this.getAccountFromAddress(address);
150
+ const completeAddress = originalAccount.getCompleteAddress();
151
+ const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
152
+ if (!contractInstance) {
153
+ throw new Error(
154
+ `No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`,
155
+ );
156
+ }
157
+
158
+ const type = this.getTypeFor(address);
159
+ const stubClassId = this.stubClassIds.get(type);
160
+ if (!stubClassId) {
161
+ throw new Error(
162
+ `Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`,
163
+ );
164
+ }
165
+
166
+ contracts[address.toString()] = {
167
+ instance: { ...contractInstance, currentContractClassId: stubClassId },
168
+ };
169
+ }
170
+
171
+ return contracts;
172
+ }
173
+
174
+ protected accounts: Map<string, { account: Account; type: AccountType }> = new Map();
175
+
176
+ private getTypeFor(address: AztecAddress): AccountType {
177
+ return this.accounts.get(address.toString())?.type ?? 'schnorr';
178
+ }
179
+
180
+ private getStubAccountFor(address: AztecAddress, completeAddress: CompleteAddress) {
181
+ return this.getTypeFor(address) === 'schnorr'
182
+ ? createStubSchnorrAccount(completeAddress)
183
+ : createStubEcdsaAccount(completeAddress);
184
+ }
185
+
186
+ /**
187
+ * Controls how the test wallet simulates transactions:
188
+ * - `kernelless`: Skips kernel circuits but uses the real account contract. Default.
189
+ * - `kernelless-override`: Skips kernels and replaces the account with a stub that doesn't do authwit validation.
190
+ * - `full`: Uses real kernel circuits and real account contracts. Slow!
191
+ */
192
+ private simulationMode: 'kernelless' | 'kernelless-override' | 'full' = 'kernelless';
193
+
194
+ setSimulationMode(mode: 'kernelless' | 'kernelless-override' | 'full') {
195
+ this.simulationMode = mode;
196
+ }
197
+
198
+ setMinFeePadding(value?: number) {
199
+ this.minFeePadding = value ?? DEFAULT_MIN_FEE_PADDING;
200
+ }
201
+
202
+ protected getAccountFromAddress(address: AztecAddress): Promise<Account> {
203
+ const entry = this.accounts.get(address?.toString() ?? '');
204
+
205
+ if (!entry) {
206
+ throw new Error(`Account not found in wallet for address: ${address}`);
207
+ }
208
+
209
+ return Promise.resolve(entry.account);
210
+ }
211
+
212
+ getAccounts() {
213
+ return Promise.resolve(
214
+ Array.from(this.accounts.values()).map(entry => ({ alias: '', item: entry.account.getAddress() })),
215
+ );
216
+ }
217
+
218
+ async createAccount(accountData?: AccountData): Promise<AccountManager> {
219
+ const secret = accountData?.secret ?? Fr.random();
220
+ const salt = accountData?.salt ?? Fr.random();
221
+ const type = accountData?.type ?? 'schnorr';
222
+ const contract = accountData?.contract ?? new SchnorrAccountContract(GrumpkinScalar.random());
223
+
224
+ const accountManager = await AccountManager.create(this, secret, contract, { salt });
225
+
226
+ const instance = accountManager.getInstance();
227
+ const artifact = await contract.getContractArtifact();
228
+
229
+ await this.registerContract(instance, artifact, secret);
230
+
231
+ const address = accountManager.address.toString();
232
+ this.accounts.set(address, { account: await accountManager.getAccount(), type });
233
+
234
+ return accountManager;
235
+ }
236
+
237
+ lookupValidity(
238
+ onBehalfOf: AztecAddress,
239
+ intent: IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
240
+ witness: AuthWitness,
241
+ ): Promise<{
242
+ isValidInPrivate: boolean;
243
+ isValidInPublic: boolean;
244
+ }> {
245
+ return lookupValidity(this, onBehalfOf, intent, witness);
246
+ }
247
+
248
+ public setPublicAuthWit(
249
+ from: AztecAddress,
250
+ messageHashOrIntent: Fr | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
251
+ authorized: boolean,
252
+ ): Promise<SetPublicAuthwitContractInteraction> {
253
+ return SetPublicAuthwitContractInteraction.create(this, from, messageHashOrIntent, authorized);
254
+ }
255
+
256
+ public override async createAuthWit(
257
+ from: AztecAddress,
258
+ intent: IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
259
+ ): Promise<AuthWitness> {
260
+ const account = await this.getAccountFromAddress(from);
261
+ const chainInfo = await this.getChainInfo();
262
+ let intentInnerHash: IntentInnerHash;
263
+ if ('caller' in intent) {
264
+ const call = isContractFunctionInteractionCallIntent(intent)
265
+ ? await intent.action.getFunctionCall()
266
+ : intent.call;
267
+ const innerHash = await computeInnerAuthWitHashFromAction(intent.caller, call);
268
+ intentInnerHash = { innerHash, consumer: call.to };
269
+ } else {
270
+ intentInnerHash = intent;
271
+ }
272
+ return account.createAuthWit(intentInnerHash, chainInfo);
273
+ }
274
+
275
+ protected override async simulateViaEntrypoint(
276
+ executionPayload: ExecutionPayload,
277
+ opts: SimulateViaEntrypointOptions,
278
+ ): Promise<TxSimulationResultWithAppOffset> {
279
+ const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement, sendMessagesAs } = opts;
280
+ const scopes = this.scopesFrom(from, additionalScopes);
281
+ const skipKernels = this.simulationMode !== 'full';
282
+ const useOverride = this.simulationMode === 'kernelless-override';
283
+
284
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
285
+ const finalExecutionPayload = feeExecutionPayload
286
+ ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
287
+ : executionPayload;
288
+ const chainInfo = await this.getChainInfo();
289
+
290
+ let overrides = opts.overrides;
291
+ let txRequest: TxExecutionRequest;
292
+ if (useOverride) {
293
+ const accountOverrides = await this.buildAccountOverrides(scopes);
294
+ overrides = new SimulationOverrides({
295
+ publicStorage: overrides?.publicStorage,
296
+ contracts: { ...overrides?.contracts, ...accountOverrides },
297
+ });
298
+ }
299
+
300
+ if (from === NO_FROM) {
301
+ const entrypoint = new DefaultEntrypoint();
302
+ txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
303
+ } else {
304
+ let fromAccount: Account;
305
+ if (useOverride) {
306
+ const originalAccount = await this.getAccountFromAddress(from);
307
+ fromAccount = this.getStubAccountFor(from, originalAccount.getCompleteAddress());
308
+ } else {
309
+ fromAccount = await this.getAccountFromAddress(from);
310
+ }
311
+ const executionOptions: DefaultAccountEntrypointOptions = {
312
+ txNonce: Fr.random(),
313
+ cancellable: this.cancellableTransactions,
314
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
315
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
316
+ };
317
+ txRequest = await fromAccount.createTxExecutionRequest(
318
+ finalExecutionPayload,
319
+ feeOptions.gasSettings,
320
+ chainInfo,
321
+ executionOptions,
322
+ );
323
+ }
324
+
325
+ const result = await this.pxe.simulateTx(txRequest, {
326
+ simulatePublic: true,
327
+ skipKernels,
328
+ skipFeeEnforcement,
329
+ skipTxValidation,
330
+ overrides,
331
+ scopes,
332
+ senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
333
+ });
334
+ const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
335
+ return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
336
+ }
337
+
338
+ async proveTx(exec: ExecutionPayload, opts: Omit<SendOptions, 'wait'>): Promise<ProvenTx> {
339
+ const fee = await this.completeFeeOptions({
340
+ from: opts.from,
341
+ feePayer: exec.feePayer,
342
+ gasSettings: opts.fee?.gasSettings,
343
+ });
344
+ const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(exec, opts.from, fee);
345
+ const txProvingResult = await this.pxe.proveTx(txRequest, {
346
+ scopes: this.scopesFrom(opts.from, opts.additionalScopes),
347
+ senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
348
+ });
349
+ return new ProvenTx(
350
+ this.aztecNode,
351
+ await txProvingResult.toTx(),
352
+ txProvingResult.getOffchainEffects(),
353
+ txProvingResult.stats,
354
+ );
355
+ }
356
+
357
+ getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
358
+ return this.aztecNode.getTxReceipt(txHash);
359
+ }
360
+
361
+ getNotes(filter: NotesFilter): Promise<NoteDao[]> {
362
+ return this.pxe.debug.getNotes(filter);
363
+ }
364
+
365
+ getSyncedBlockHeader(): Promise<BlockHeader> {
366
+ return this.pxe.getSyncedBlockHeader();
367
+ }
368
+
369
+ sync(): Promise<void> {
370
+ return this.pxe.sync();
371
+ }
372
+
373
+ stop(): Promise<void> {
374
+ return this.pxe.stop();
375
+ }
376
+ }
@@ -0,0 +1,108 @@
1
+ import {
2
+ BatchCall,
3
+ ContractFunctionInteraction,
4
+ DeployMethod,
5
+ type DeployOptions,
6
+ NO_WAIT,
7
+ type NoWait,
8
+ type SendInteractionOptions,
9
+ type WaitOpts,
10
+ toSendOptions,
11
+ } from '@aztec/aztec.js/contracts';
12
+ import { type AztecNode, waitForTx } from '@aztec/aztec.js/node';
13
+ import { SimulationError } from '@aztec/stdlib/errors';
14
+ import { type OffchainEffect, type ProvingStats, Tx, TxHash, type TxReceipt } from '@aztec/stdlib/tx';
15
+
16
+ import { inspect } from 'util';
17
+
18
+ import type { TestWallet } from './test_wallet.js';
19
+
20
+ export type ProvenTxSendOpts = {
21
+ wait?: NoWait | WaitOpts;
22
+ };
23
+
24
+ export type ProvenTxSendReturn<T extends NoWait | WaitOpts | undefined> = T extends NoWait ? TxHash : TxReceipt;
25
+
26
+ export class ProvenTx extends Tx {
27
+ constructor(
28
+ private node: AztecNode,
29
+ tx: Tx,
30
+ public offchainEffects: OffchainEffect[],
31
+ public stats?: ProvingStats,
32
+ ) {
33
+ super(tx.getTxHash(), tx.data, tx.chonkProof, tx.contractClassLogFields, tx.publicFunctionCalldata);
34
+ }
35
+
36
+ send(options?: Omit<ProvenTxSendOpts, 'wait'>): Promise<TxReceipt>;
37
+ send<W extends ProvenTxSendOpts['wait']>(options: ProvenTxSendOpts & { wait: W }): Promise<ProvenTxSendReturn<W>>;
38
+ async send(options?: ProvenTxSendOpts): Promise<TxHash | TxReceipt> {
39
+ const txHash = this.getTxHash();
40
+ await this.node.sendTx(this).catch(err => {
41
+ throw this.contextualizeError(err, inspect(this));
42
+ });
43
+
44
+ if (options?.wait === NO_WAIT) {
45
+ return txHash;
46
+ }
47
+
48
+ const waitOpts = typeof options?.wait === 'object' ? options.wait : undefined;
49
+ return await waitForTx(this.node, txHash, waitOpts);
50
+ }
51
+
52
+ private contextualizeError(err: Error, ...context: string[]): Error {
53
+ let contextStr = '';
54
+ if (context.length > 0) {
55
+ contextStr = `\nContext:\n${context.join('\n')}`;
56
+ }
57
+ if (err instanceof SimulationError) {
58
+ err.setAztecContext(contextStr);
59
+ }
60
+ return err;
61
+ }
62
+ }
63
+
64
+ export async function proveInteraction(
65
+ wallet: TestWallet,
66
+ interaction: ContractFunctionInteraction | DeployMethod | BatchCall,
67
+ options: SendInteractionOptions | DeployOptions,
68
+ ) {
69
+ const execPayload = await interaction.request(options);
70
+ return wallet.proveTx(execPayload, toSendOptions(options));
71
+ }
72
+
73
+ /**
74
+ * Extends AztecNode via declaration merging so instances can be used wherever AztecNode is expected.
75
+ * The actual method forwarding is handled by a Proxy in the class constructor.
76
+ */
77
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
78
+ export interface AztecNodeProxy extends AztecNode {}
79
+
80
+ /**
81
+ * Mutable wrapper around an AztecNode that forwards all calls to the current target.
82
+ * Allows swapping the underlying node at runtime via updateTargetNode, which is useful
83
+ * for tests that need to redirect a wallet from one node to another without recreating it.
84
+ */
85
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
86
+ export class AztecNodeProxy {
87
+ constructor(private target: AztecNode) {
88
+ return new Proxy(this, {
89
+ get: (obj, prop, receiver) => {
90
+ // Own properties and methods (updateTargetNode, target) are served directly.
91
+ if (Reflect.has(obj, prop)) {
92
+ return Reflect.get(obj, prop, receiver);
93
+ }
94
+ // Everything else is forwarded to the current target node.
95
+ const val = (obj.target as unknown as Record<string | symbol, unknown>)[prop];
96
+ return typeof val === 'function' ? val.bind(obj.target) : val;
97
+ },
98
+ });
99
+ }
100
+
101
+ /**
102
+ * Updates the underlying node that this reference points to.
103
+ * @param node - The new node to forward calls to.
104
+ */
105
+ updateTargetNode(node: AztecNode): void {
106
+ this.target = node;
107
+ }
108
+ }
@@ -0,0 +1,63 @@
1
+ import { createAztecNodeClient } from '@aztec/aztec.js/node';
2
+ import type { SendOptions } from '@aztec/aztec.js/wallet';
3
+ import { BackendType, BarretenbergSync } from '@aztec/bb.js';
4
+ import { jsonStringify } from '@aztec/foundation/json-rpc';
5
+ import { createLogger } from '@aztec/foundation/log';
6
+ import type { ApiSchema, Fr } from '@aztec/foundation/schemas';
7
+ import { getSchemaParameters, parseWithOptionals, schemaHasMethod } from '@aztec/foundation/schemas';
8
+ import { NodeListener, TransportServer } from '@aztec/foundation/transport';
9
+ import { ExecutionPayload, Tx } from '@aztec/stdlib/tx';
10
+
11
+ import { workerData } from 'worker_threads';
12
+
13
+ import { TestWallet } from './test_wallet.js';
14
+ import { WorkerWalletSchema } from './worker_wallet_schema.js';
15
+
16
+ const logger = createLogger('e2e:test-wallet:worker');
17
+
18
+ try {
19
+ const { nodeUrl, pxeConfig } = workerData as { nodeUrl: string; pxeConfig?: Record<string, unknown> };
20
+
21
+ logger.info('Initializing worker wallet', { nodeUrl });
22
+ const node = createAztecNodeClient(nodeUrl);
23
+ // Worker sync bb use is limited to crypto and proof serialization helpers.
24
+ await BarretenbergSync.initSingleton({ backend: BackendType.Wasm });
25
+ const wallet = await TestWallet.create(node, pxeConfig);
26
+ logger.info('Worker wallet initialized');
27
+
28
+ const customMethods = {
29
+ proveTx: async (exec: ExecutionPayload, opts: Omit<SendOptions, 'wait'>) => {
30
+ const provenTx = await wallet.proveTx(exec, opts);
31
+ return new Tx(
32
+ provenTx.getTxHash(),
33
+ provenTx.data,
34
+ provenTx.chonkProof,
35
+ provenTx.contractClassLogFields,
36
+ provenTx.publicFunctionCalldata,
37
+ );
38
+ },
39
+ registerAccount: async (secret: Fr, salt: Fr) => {
40
+ const manager = await wallet.createSchnorrAccount(secret, salt);
41
+ return manager.address;
42
+ },
43
+ };
44
+
45
+ const schema = WorkerWalletSchema as ApiSchema;
46
+ const listener = new NodeListener();
47
+ const server = new TransportServer<{ fn: string; args: string }>(listener, async msg => {
48
+ if (!schemaHasMethod(schema, msg.fn)) {
49
+ throw new Error(`Unknown method: ${msg.fn}`);
50
+ }
51
+ const jsonParams = JSON.parse(msg.args) as unknown[];
52
+ const args: any[] = await parseWithOptionals(jsonParams, getSchemaParameters(schema[msg.fn]));
53
+ // we have to erase the fn type in order to be able to spread ...args
54
+ const handler: ((...args: any[]) => Promise<any>) | undefined =
55
+ msg.fn in customMethods ? customMethods[msg.fn as keyof typeof customMethods] : undefined;
56
+ const result = handler ? await handler(...args) : await (wallet as any)[msg.fn](...args);
57
+ return jsonStringify(result);
58
+ });
59
+ server.start();
60
+ } catch (err: unknown) {
61
+ logger.error('Worker wallet initialization failed', { error: err instanceof Error ? err.stack : String(err) });
62
+ process.exit(1);
63
+ }