@walletmesh/aztec-rpc-wallet 0.3.0 → 0.4.0
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/CHANGELOG.md +26 -0
- package/README.md +290 -228
- package/dist/.tsbuildinfo +1 -1
- package/dist/client/aztec-dapp-wallet.d.ts +401 -0
- package/dist/client/aztec-dapp-wallet.d.ts.map +1 -0
- package/dist/client/aztec-dapp-wallet.js +705 -0
- package/dist/client/aztec-router-provider.d.ts +58 -0
- package/dist/client/aztec-router-provider.d.ts.map +1 -0
- package/dist/client/aztec-router-provider.js +62 -0
- package/dist/client/helpers.d.ts +44 -0
- package/dist/client/helpers.d.ts.map +1 -0
- package/dist/client/helpers.js +79 -0
- package/dist/client/register-serializers.d.ts +41 -0
- package/dist/client/register-serializers.d.ts.map +1 -0
- package/dist/client/register-serializers.js +97 -0
- package/dist/contractArtifactCache.d.ts +49 -32
- package/dist/contractArtifactCache.d.ts.map +1 -1
- package/dist/contractArtifactCache.js +47 -34
- package/dist/errors.d.ts +50 -8
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +50 -10
- package/dist/index.d.ts +53 -40
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -17
- package/dist/types.d.ts +345 -268
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +10 -8
- package/dist/wallet/create-node.d.ts +73 -0
- package/dist/wallet/create-node.d.ts.map +1 -0
- package/dist/wallet/create-node.js +99 -0
- package/dist/wallet/handlers/account.d.ts +67 -0
- package/dist/wallet/handlers/account.d.ts.map +1 -0
- package/dist/wallet/handlers/account.js +85 -0
- package/dist/wallet/handlers/contract-interaction.d.ts +77 -0
- package/dist/wallet/handlers/contract-interaction.d.ts.map +1 -0
- package/dist/wallet/handlers/contract-interaction.js +219 -0
- package/dist/wallet/handlers/contract.d.ts +96 -0
- package/dist/wallet/handlers/contract.d.ts.map +1 -0
- package/dist/wallet/handlers/contract.js +146 -0
- package/dist/wallet/handlers/event.d.ts +62 -0
- package/dist/wallet/handlers/event.d.ts.map +1 -0
- package/dist/wallet/handlers/event.js +85 -0
- package/dist/wallet/handlers/index.d.ts +88 -0
- package/dist/wallet/handlers/index.d.ts.map +1 -0
- package/dist/wallet/handlers/index.js +47 -0
- package/dist/wallet/handlers/node.d.ts +117 -0
- package/dist/wallet/handlers/node.d.ts.map +1 -0
- package/dist/wallet/handlers/node.js +196 -0
- package/dist/wallet/handlers/senders.d.ts +70 -0
- package/dist/wallet/handlers/senders.d.ts.map +1 -0
- package/dist/wallet/handlers/senders.js +92 -0
- package/dist/wallet/handlers/transaction.d.ts +123 -0
- package/dist/wallet/handlers/transaction.d.ts.map +1 -0
- package/dist/wallet/handlers/transaction.js +191 -0
- package/dist/wallet/serializers.d.ts +75 -0
- package/dist/wallet/serializers.d.ts.map +1 -0
- package/dist/wallet/serializers.js +501 -0
- package/docs/README.md +290 -229
- package/docs/classes/AztecDappWallet.md +1304 -0
- package/docs/classes/AztecRouterProvider.md +1058 -0
- package/docs/classes/AztecWalletError.md +124 -47
- package/docs/classes/ContractArtifactCache.md +48 -31
- package/docs/functions/connectAztec.md +62 -0
- package/docs/functions/createAztecWallet.md +46 -0
- package/docs/functions/createAztecWalletNode.md +96 -0
- package/docs/functions/registerAztecSerializers.md +61 -0
- package/docs/functions/registerWalletAztecSerializers.md +39 -0
- package/docs/globals.md +16 -14
- package/docs/interfaces/AztecHandlerContext.md +54 -0
- package/docs/interfaces/AztecWalletContext.md +50 -0
- package/docs/interfaces/AztecWalletMethodMap.md +471 -470
- package/docs/type-aliases/AztecChainId.md +16 -3
- package/docs/variables/ALL_AZTEC_METHODS.md +20 -0
- package/docs/variables/AztecWalletErrorMap.md +9 -4
- package/docs/variables/AztecWalletSerializer.md +45 -0
- package/package.json +9 -9
- package/src/client/aztec-dapp-wallet.test.ts +628 -0
- package/src/client/aztec-dapp-wallet.ts +879 -0
- package/src/client/aztec-router-provider.test.ts +235 -0
- package/src/client/aztec-router-provider.ts +64 -0
- package/src/client/helpers.test.ts +187 -0
- package/src/client/helpers.ts +91 -0
- package/src/client/register-serializers.ts +108 -0
- package/src/contractArtifactCache.test.ts +21 -10
- package/src/contractArtifactCache.ts +54 -35
- package/src/errors.ts +58 -10
- package/src/index.test.ts +2 -6
- package/src/index.ts +73 -37
- package/src/types.ts +379 -217
- package/src/wallet/create-node.test.ts +332 -0
- package/src/wallet/create-node.ts +120 -0
- package/src/wallet/handlers/account.test.ts +172 -0
- package/src/wallet/handlers/account.ts +99 -0
- package/src/wallet/handlers/contract-interaction.test.ts +248 -0
- package/src/wallet/handlers/contract-interaction.ts +269 -0
- package/src/wallet/handlers/contract.test.ts +245 -0
- package/src/wallet/handlers/contract.ts +174 -0
- package/src/wallet/handlers/event.test.ts +216 -0
- package/src/wallet/handlers/event.ts +99 -0
- package/src/wallet/handlers/index.ts +84 -0
- package/src/wallet/handlers/node.test.ts +304 -0
- package/src/wallet/handlers/node.ts +230 -0
- package/src/wallet/handlers/senders.test.ts +172 -0
- package/src/wallet/handlers/senders.ts +106 -0
- package/src/wallet/handlers/transaction.test.ts +371 -0
- package/src/wallet/handlers/transaction.ts +239 -0
- package/src/wallet/serializers.test.ts +253 -0
- package/src/wallet/serializers.ts +586 -0
- package/typedoc.json +23 -1
- package/dist/aztecRemoteWallet.d.ts +0 -70
- package/dist/aztecRemoteWallet.d.ts.map +0 -1
- package/dist/aztecRemoteWallet.js +0 -335
- package/dist/chainProvider.d.ts +0 -56
- package/dist/chainProvider.d.ts.map +0 -1
- package/dist/chainProvider.js +0 -98
- package/dist/handlers/aztecAccountWallet.d.ts +0 -4
- package/dist/handlers/aztecAccountWallet.d.ts.map +0 -1
- package/dist/handlers/aztecAccountWallet.js +0 -296
- package/dist/handlers/transactions.d.ts +0 -21
- package/dist/handlers/transactions.d.ts.map +0 -1
- package/dist/handlers/transactions.js +0 -98
- package/dist/handlers.d.ts +0 -27
- package/dist/handlers.d.ts.map +0 -1
- package/dist/handlers.js +0 -55
- package/dist/provider.d.ts +0 -105
- package/dist/provider.d.ts.map +0 -1
- package/dist/provider.js +0 -160
- package/dist/serializers/account.d.ts +0 -164
- package/dist/serializers/account.d.ts.map +0 -1
- package/dist/serializers/account.js +0 -244
- package/dist/serializers/contract.d.ts +0 -62
- package/dist/serializers/contract.d.ts.map +0 -1
- package/dist/serializers/contract.js +0 -130
- package/dist/serializers/index.d.ts +0 -21
- package/dist/serializers/index.d.ts.map +0 -1
- package/dist/serializers/index.js +0 -154
- package/dist/serializers/log.d.ts +0 -66
- package/dist/serializers/log.d.ts.map +0 -1
- package/dist/serializers/log.js +0 -222
- package/dist/serializers/note.d.ts +0 -124
- package/dist/serializers/note.d.ts.map +0 -1
- package/dist/serializers/note.js +0 -208
- package/dist/serializers/transaction.d.ts +0 -99
- package/dist/serializers/transaction.d.ts.map +0 -1
- package/dist/serializers/transaction.js +0 -275
- package/dist/wallet.d.ts +0 -62
- package/dist/wallet.d.ts.map +0 -1
- package/dist/wallet.js +0 -77
- package/docs/classes/AztecChainProvider.md +0 -553
- package/docs/classes/AztecChainWallet.md +0 -409
- package/docs/classes/AztecProvider.md +0 -1112
- package/docs/interfaces/AztecWalletBaseMethodMap.md +0 -135
- package/docs/interfaces/AztecWalletEventMap.md +0 -17
- package/docs/type-aliases/AztecChainWalletMiddleware.md +0 -13
- package/docs/type-aliases/AztecWalletContext.md +0 -29
- package/docs/type-aliases/AztecWalletMethodHandler.md +0 -37
- package/docs/type-aliases/AztecWalletMiddleware.md +0 -13
- package/docs/type-aliases/AztecWalletRouterClient.md +0 -13
- package/docs/type-aliases/TransactionFunctionCall.md +0 -33
- package/docs/type-aliases/TransactionParams.md +0 -27
- package/src/aztecRemoteWallet.test.ts +0 -504
- package/src/aztecRemoteWallet.ts +0 -467
- package/src/chainProvider.test.ts +0 -401
- package/src/chainProvider.ts +0 -116
- package/src/handlers/aztecAccountWallet.test.ts +0 -649
- package/src/handlers/aztecAccountWallet.ts +0 -532
- package/src/handlers/transactions.ts +0 -124
- package/src/handlers.test.ts +0 -270
- package/src/handlers.ts +0 -70
- package/src/provider.test.ts +0 -274
- package/src/provider.ts +0 -189
- package/src/serializers/account.test.ts +0 -125
- package/src/serializers/account.ts +0 -301
- package/src/serializers/contract.test.ts +0 -24
- package/src/serializers/contract.ts +0 -183
- package/src/serializers/index.test.ts +0 -136
- package/src/serializers/index.ts +0 -191
- package/src/serializers/log.test.ts +0 -286
- package/src/serializers/log.ts +0 -292
- package/src/serializers/note.test.ts +0 -125
- package/src/serializers/note.ts +0 -250
- package/src/serializers/transaction.test.ts +0 -320
- package/src/serializers/transaction.ts +0 -409
- package/src/wallet.test.ts +0 -275
- package/src/wallet.ts +0 -94
@@ -0,0 +1,628 @@
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, beforeAll, type Mock } from 'vitest';
|
2
|
+
import { AztecDappWallet, createAztecWallet } from './aztec-dapp-wallet.js';
|
3
|
+
import { AztecAddress, TxHash, CompleteAddress, Fr } from '@aztec/aztec.js';
|
4
|
+
import type { ContractArtifact, ContractInstanceWithAddress, Tx, TxExecutionRequest } from '@aztec/aztec.js';
|
5
|
+
import type { ExecutionPayload } from '@aztec/entrypoints/payload';
|
6
|
+
import type { FeeOptions, TxExecutionOptions } from '@aztec/entrypoints/interfaces';
|
7
|
+
import type { WalletRouterProvider } from '@walletmesh/router';
|
8
|
+
|
9
|
+
// Mock provider
|
10
|
+
const createMockProvider = () => {
|
11
|
+
const call = vi.fn() as Mock;
|
12
|
+
const on = vi.fn();
|
13
|
+
const off = vi.fn();
|
14
|
+
return {
|
15
|
+
call,
|
16
|
+
on,
|
17
|
+
off,
|
18
|
+
} as unknown as WalletRouterProvider & { call: Mock };
|
19
|
+
};
|
20
|
+
|
21
|
+
// Mock Aztec objects - we'll create these asynchronously in tests or beforeEach hooks
|
22
|
+
let mockAddress: AztecAddress;
|
23
|
+
let mockCompleteAddress: CompleteAddress;
|
24
|
+
let mockTxHash: TxHash;
|
25
|
+
const testChainId = 'aztec:test';
|
26
|
+
|
27
|
+
// Helper to create mock objects
|
28
|
+
async function createMockObjects() {
|
29
|
+
// Create a CompleteAddress first, then extract its address
|
30
|
+
mockCompleteAddress = await CompleteAddress.random();
|
31
|
+
mockAddress = mockCompleteAddress.address;
|
32
|
+
mockTxHash = await TxHash.random();
|
33
|
+
}
|
34
|
+
|
35
|
+
describe('AztecDappWallet', () => {
|
36
|
+
let provider: ReturnType<typeof createMockProvider>;
|
37
|
+
let wallet: AztecDappWallet;
|
38
|
+
|
39
|
+
beforeAll(async () => {
|
40
|
+
await createMockObjects();
|
41
|
+
});
|
42
|
+
|
43
|
+
beforeEach(() => {
|
44
|
+
provider = createMockProvider();
|
45
|
+
wallet = new AztecDappWallet(provider, testChainId);
|
46
|
+
});
|
47
|
+
|
48
|
+
describe('Cached properties', () => {
|
49
|
+
it('should throw when accessing address before initialization', () => {
|
50
|
+
expect(() => wallet.getAddress()).toThrow(
|
51
|
+
'Wallet not initialized. Call createAztecWallet() to properly initialize the wallet.',
|
52
|
+
);
|
53
|
+
});
|
54
|
+
|
55
|
+
it('should throw when accessing completeAddress before initialization', () => {
|
56
|
+
expect(() => wallet.getCompleteAddress()).toThrow(
|
57
|
+
'Wallet not initialized. Call createAztecWallet() to properly initialize the wallet.',
|
58
|
+
);
|
59
|
+
});
|
60
|
+
|
61
|
+
it('should throw when accessing chainId before initialization', () => {
|
62
|
+
expect(() => wallet.getChainId()).toThrow(
|
63
|
+
'Chain ID not initialized. Call createAztecWallet() to properly initialize the wallet.',
|
64
|
+
);
|
65
|
+
});
|
66
|
+
|
67
|
+
it('should throw when accessing version before initialization', () => {
|
68
|
+
expect(() => wallet.getVersion()).toThrow(
|
69
|
+
'Wallet version not initialized. Call createAztecWallet() to properly initialize the wallet.',
|
70
|
+
);
|
71
|
+
});
|
72
|
+
|
73
|
+
it('should return cached values after initialization', async () => {
|
74
|
+
const mockChainIdFr = new Fr(31337n);
|
75
|
+
const mockVersionFr = new Fr(1n);
|
76
|
+
|
77
|
+
provider.call.mockImplementation(async (_chainId: string, { method }: { method: string }) => {
|
78
|
+
switch (method) {
|
79
|
+
case 'aztec_getCompleteAddress':
|
80
|
+
return mockCompleteAddress;
|
81
|
+
case 'aztec_getChainId':
|
82
|
+
return mockChainIdFr;
|
83
|
+
case 'aztec_getVersion':
|
84
|
+
return mockVersionFr;
|
85
|
+
default:
|
86
|
+
throw new Error(`Unexpected method: ${method}`);
|
87
|
+
}
|
88
|
+
});
|
89
|
+
|
90
|
+
await wallet.initialize();
|
91
|
+
|
92
|
+
expect(wallet.getAddress()).toEqual(mockAddress);
|
93
|
+
expect(wallet.getCompleteAddress()).toEqual(mockCompleteAddress);
|
94
|
+
expect(wallet.getChainId()).toEqual(mockChainIdFr);
|
95
|
+
expect(wallet.getVersion()).toEqual(mockVersionFr);
|
96
|
+
});
|
97
|
+
});
|
98
|
+
|
99
|
+
describe('initialize', () => {
|
100
|
+
it('should fetch all cached values', async () => {
|
101
|
+
const mockChainIdFr = new Fr(31337n);
|
102
|
+
const mockVersionFr = new Fr(1n);
|
103
|
+
|
104
|
+
provider.call.mockImplementation(async (_chainId: string, { method }: { method: string }) => {
|
105
|
+
switch (method) {
|
106
|
+
case 'aztec_getCompleteAddress':
|
107
|
+
return mockCompleteAddress;
|
108
|
+
case 'aztec_getChainId':
|
109
|
+
return mockChainIdFr;
|
110
|
+
case 'aztec_getVersion':
|
111
|
+
return mockVersionFr;
|
112
|
+
default:
|
113
|
+
throw new Error(`Unexpected method: ${method}`);
|
114
|
+
}
|
115
|
+
});
|
116
|
+
|
117
|
+
await wallet.initialize();
|
118
|
+
|
119
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, { method: 'aztec_getCompleteAddress' });
|
120
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, { method: 'aztec_getChainId' });
|
121
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, { method: 'aztec_getVersion' });
|
122
|
+
});
|
123
|
+
|
124
|
+
it('should handle initialization errors', async () => {
|
125
|
+
provider.call.mockRejectedValue(new Error('Provider error'));
|
126
|
+
|
127
|
+
await expect(wallet.initialize()).rejects.toThrow('Provider error');
|
128
|
+
});
|
129
|
+
});
|
130
|
+
|
131
|
+
describe('Account methods', () => {
|
132
|
+
beforeEach(async () => {
|
133
|
+
// Initialize wallet with default chain ID for testing
|
134
|
+
const mockChainIdFr = new Fr(31337n);
|
135
|
+
const mockVersionFr = new Fr(1n);
|
136
|
+
|
137
|
+
provider.call.mockImplementation(async (_chainId: string, { method }: { method: string }) => {
|
138
|
+
switch (method) {
|
139
|
+
case 'aztec_getCompleteAddress':
|
140
|
+
return mockCompleteAddress;
|
141
|
+
case 'aztec_getChainId':
|
142
|
+
return mockChainIdFr;
|
143
|
+
case 'aztec_getVersion':
|
144
|
+
return mockVersionFr;
|
145
|
+
default:
|
146
|
+
return null;
|
147
|
+
}
|
148
|
+
});
|
149
|
+
await wallet.initialize();
|
150
|
+
provider.call.mockClear();
|
151
|
+
});
|
152
|
+
|
153
|
+
it('should call aztec_getAddress', async () => {
|
154
|
+
provider.call.mockResolvedValue(mockAddress);
|
155
|
+
|
156
|
+
const result = await wallet.getAddressAsync();
|
157
|
+
|
158
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, { method: 'aztec_getAddress' });
|
159
|
+
expect(result).toEqual(mockAddress);
|
160
|
+
});
|
161
|
+
|
162
|
+
it('should call aztec_getCompleteAddress', async () => {
|
163
|
+
provider.call.mockResolvedValue(mockCompleteAddress);
|
164
|
+
|
165
|
+
const result = await wallet.getCompleteAddressAsync();
|
166
|
+
|
167
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, { method: 'aztec_getCompleteAddress' });
|
168
|
+
expect(result).toEqual(mockCompleteAddress);
|
169
|
+
});
|
170
|
+
|
171
|
+
it('should call aztec_createAuthWit with Fr', async () => {
|
172
|
+
const messageHash = await Fr.random();
|
173
|
+
const authWitness = { messageHash };
|
174
|
+
provider.call.mockResolvedValue(authWitness);
|
175
|
+
|
176
|
+
const result = await wallet.createAuthWit(messageHash);
|
177
|
+
|
178
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
179
|
+
method: 'aztec_createAuthWit',
|
180
|
+
params: { intent: messageHash },
|
181
|
+
});
|
182
|
+
expect(result).toEqual(authWitness);
|
183
|
+
});
|
184
|
+
|
185
|
+
it('should call aztec_createAuthWit with Buffer', async () => {
|
186
|
+
const buffer = Buffer.from('test');
|
187
|
+
const authWitness = { messageHash: await Fr.random() };
|
188
|
+
provider.call.mockResolvedValue(authWitness);
|
189
|
+
|
190
|
+
const result = await wallet.createAuthWit(buffer);
|
191
|
+
|
192
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
193
|
+
method: 'aztec_createAuthWit',
|
194
|
+
params: { intent: buffer },
|
195
|
+
});
|
196
|
+
expect(result).toEqual(authWitness);
|
197
|
+
});
|
198
|
+
});
|
199
|
+
|
200
|
+
describe('Transaction methods', () => {
|
201
|
+
beforeEach(async () => {
|
202
|
+
const mockChainIdFr = new Fr(31337n);
|
203
|
+
const mockVersionFr = new Fr(1n);
|
204
|
+
|
205
|
+
provider.call.mockImplementation(async (_chainId: string, { method }: { method: string }) => {
|
206
|
+
switch (method) {
|
207
|
+
case 'aztec_getCompleteAddress':
|
208
|
+
return mockCompleteAddress;
|
209
|
+
case 'aztec_getChainId':
|
210
|
+
return mockChainIdFr;
|
211
|
+
case 'aztec_getVersion':
|
212
|
+
return mockVersionFr;
|
213
|
+
default:
|
214
|
+
return null;
|
215
|
+
}
|
216
|
+
});
|
217
|
+
await wallet.initialize();
|
218
|
+
provider.call.mockClear();
|
219
|
+
});
|
220
|
+
|
221
|
+
it('should create transaction execution request locally', async () => {
|
222
|
+
// The createTxExecutionRequest method now uses the local DefaultAccountEntrypoint
|
223
|
+
// instead of making an RPC call. Since we can't easily mock the entrypoint,
|
224
|
+
// we'll just verify it doesn't make an RPC call for this method.
|
225
|
+
const executionPayload = {
|
226
|
+
calls: [],
|
227
|
+
authWitnesses: [],
|
228
|
+
capsules: [],
|
229
|
+
extraHashedArgs: [],
|
230
|
+
} as ExecutionPayload;
|
231
|
+
const feeOptions = {} as FeeOptions;
|
232
|
+
const txOptions = {} as TxExecutionOptions;
|
233
|
+
|
234
|
+
// This will throw because we haven't mocked all the internal dependencies
|
235
|
+
// but that's okay - we just want to verify no RPC call is made
|
236
|
+
await expect(
|
237
|
+
wallet.createTxExecutionRequest(executionPayload, feeOptions, txOptions),
|
238
|
+
).rejects.toThrow();
|
239
|
+
|
240
|
+
// Verify no RPC call was made for createTxExecutionRequest
|
241
|
+
expect(provider.call).not.toHaveBeenCalledWith(
|
242
|
+
expect.any(String),
|
243
|
+
expect.objectContaining({ method: 'aztec_createTxExecutionRequest' }),
|
244
|
+
);
|
245
|
+
});
|
246
|
+
|
247
|
+
it('should call aztec_sendTx', async () => {
|
248
|
+
const tx = { request: {} } as unknown as Tx;
|
249
|
+
provider.call.mockResolvedValue(mockTxHash);
|
250
|
+
|
251
|
+
const result = await wallet.sendTx(tx);
|
252
|
+
|
253
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
254
|
+
method: 'aztec_sendTx',
|
255
|
+
params: { tx },
|
256
|
+
});
|
257
|
+
expect(result).toEqual(mockTxHash);
|
258
|
+
});
|
259
|
+
|
260
|
+
it('should call aztec_getTxReceipt', async () => {
|
261
|
+
const receipt = { txHash: mockTxHash };
|
262
|
+
provider.call.mockResolvedValue(receipt);
|
263
|
+
|
264
|
+
const result = await wallet.getTxReceipt(mockTxHash);
|
265
|
+
|
266
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
267
|
+
method: 'aztec_getTxReceipt',
|
268
|
+
params: { txHash: mockTxHash },
|
269
|
+
});
|
270
|
+
expect(result).toEqual(receipt);
|
271
|
+
});
|
272
|
+
|
273
|
+
it('should call aztec_getCurrentBaseFees', async () => {
|
274
|
+
const fees = { gasPrice: 100n };
|
275
|
+
provider.call.mockResolvedValue(fees);
|
276
|
+
|
277
|
+
const result = await wallet.getCurrentBaseFees();
|
278
|
+
|
279
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
280
|
+
method: 'aztec_getCurrentBaseFees',
|
281
|
+
});
|
282
|
+
expect(result).toEqual(fees);
|
283
|
+
});
|
284
|
+
});
|
285
|
+
|
286
|
+
describe('Block methods', () => {
|
287
|
+
beforeEach(async () => {
|
288
|
+
const mockChainIdFr = new Fr(31337n);
|
289
|
+
const mockVersionFr = new Fr(1n);
|
290
|
+
|
291
|
+
provider.call.mockImplementation(async (_chainId: string, { method }: { method: string }) => {
|
292
|
+
switch (method) {
|
293
|
+
case 'aztec_getCompleteAddress':
|
294
|
+
return mockCompleteAddress;
|
295
|
+
case 'aztec_getChainId':
|
296
|
+
return mockChainIdFr;
|
297
|
+
case 'aztec_getVersion':
|
298
|
+
return mockVersionFr;
|
299
|
+
default:
|
300
|
+
return null;
|
301
|
+
}
|
302
|
+
});
|
303
|
+
await wallet.initialize();
|
304
|
+
provider.call.mockClear();
|
305
|
+
});
|
306
|
+
|
307
|
+
it('should call aztec_getBlock', async () => {
|
308
|
+
const block = { blockNumber: 1 };
|
309
|
+
provider.call.mockResolvedValue(block);
|
310
|
+
|
311
|
+
const result = await wallet.getBlock(1);
|
312
|
+
|
313
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
314
|
+
method: 'aztec_getBlock',
|
315
|
+
params: { number: 1 },
|
316
|
+
});
|
317
|
+
expect(result).toEqual(block);
|
318
|
+
});
|
319
|
+
|
320
|
+
it('should call aztec_getBlockNumber', async () => {
|
321
|
+
provider.call.mockResolvedValue(100);
|
322
|
+
|
323
|
+
const result = await wallet.getBlockNumber();
|
324
|
+
|
325
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
326
|
+
method: 'aztec_getBlockNumber',
|
327
|
+
});
|
328
|
+
expect(result).toBe(100);
|
329
|
+
});
|
330
|
+
});
|
331
|
+
|
332
|
+
describe('Contract methods', () => {
|
333
|
+
beforeEach(async () => {
|
334
|
+
const mockChainIdFr = new Fr(31337n);
|
335
|
+
const mockVersionFr = new Fr(1n);
|
336
|
+
|
337
|
+
provider.call.mockImplementation(async (_chainId: string, { method }: { method: string }) => {
|
338
|
+
switch (method) {
|
339
|
+
case 'aztec_getCompleteAddress':
|
340
|
+
return mockCompleteAddress;
|
341
|
+
case 'aztec_getChainId':
|
342
|
+
return mockChainIdFr;
|
343
|
+
case 'aztec_getVersion':
|
344
|
+
return mockVersionFr;
|
345
|
+
default:
|
346
|
+
return null;
|
347
|
+
}
|
348
|
+
});
|
349
|
+
await wallet.initialize();
|
350
|
+
provider.call.mockClear();
|
351
|
+
});
|
352
|
+
|
353
|
+
it('should call aztec_registerContract', async () => {
|
354
|
+
const contract = { instance: { address: mockAddress } } as { instance: ContractInstanceWithAddress };
|
355
|
+
provider.call.mockResolvedValue(undefined);
|
356
|
+
|
357
|
+
await wallet.registerContract(contract);
|
358
|
+
|
359
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
360
|
+
method: 'aztec_registerContract',
|
361
|
+
params: { instance: contract.instance },
|
362
|
+
});
|
363
|
+
});
|
364
|
+
|
365
|
+
it('should call aztec_registerContractClass', async () => {
|
366
|
+
const artifact = { name: 'TestContract' } as ContractArtifact;
|
367
|
+
provider.call.mockResolvedValue(undefined);
|
368
|
+
|
369
|
+
await wallet.registerContractClass(artifact);
|
370
|
+
|
371
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
372
|
+
method: 'aztec_registerContractClass',
|
373
|
+
params: { artifact },
|
374
|
+
});
|
375
|
+
});
|
376
|
+
|
377
|
+
it('should call aztec_getContracts', async () => {
|
378
|
+
const contracts: unknown[] = [];
|
379
|
+
provider.call.mockResolvedValue(contracts);
|
380
|
+
|
381
|
+
const result = await wallet.getContracts();
|
382
|
+
|
383
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
384
|
+
method: 'aztec_getContracts',
|
385
|
+
});
|
386
|
+
expect(result).toEqual(contracts);
|
387
|
+
});
|
388
|
+
});
|
389
|
+
|
390
|
+
describe('Node info methods', () => {
|
391
|
+
beforeEach(async () => {
|
392
|
+
const mockChainIdFr = new Fr(31337n);
|
393
|
+
const mockVersionFr = new Fr(1n);
|
394
|
+
|
395
|
+
provider.call.mockImplementation(async (_chainId: string, { method }: { method: string }) => {
|
396
|
+
switch (method) {
|
397
|
+
case 'aztec_getCompleteAddress':
|
398
|
+
return mockCompleteAddress;
|
399
|
+
case 'aztec_getChainId':
|
400
|
+
return mockChainIdFr;
|
401
|
+
case 'aztec_getVersion':
|
402
|
+
return mockVersionFr;
|
403
|
+
default:
|
404
|
+
return null;
|
405
|
+
}
|
406
|
+
});
|
407
|
+
await wallet.initialize();
|
408
|
+
provider.call.mockClear();
|
409
|
+
});
|
410
|
+
|
411
|
+
it('should call aztec_getNodeInfo', async () => {
|
412
|
+
const nodeInfo = { version: '1.0.0' };
|
413
|
+
provider.call.mockResolvedValue(nodeInfo);
|
414
|
+
|
415
|
+
const result = await wallet.getNodeInfo();
|
416
|
+
|
417
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
418
|
+
method: 'aztec_getNodeInfo',
|
419
|
+
});
|
420
|
+
expect(result).toEqual(nodeInfo);
|
421
|
+
});
|
422
|
+
|
423
|
+
it('should return cached chainId', () => {
|
424
|
+
// chainId should already be cached from initialization
|
425
|
+
const result = wallet.getChainId();
|
426
|
+
expect(result.toBigInt()).toBe(31337n);
|
427
|
+
});
|
428
|
+
|
429
|
+
it('should call aztec_getChainId async', async () => {
|
430
|
+
const mockChainIdFr = new Fr(31337n);
|
431
|
+
provider.call.mockResolvedValue(mockChainIdFr);
|
432
|
+
|
433
|
+
const result = await wallet.getChainIdAsync();
|
434
|
+
|
435
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
436
|
+
method: 'aztec_getChainId',
|
437
|
+
});
|
438
|
+
expect(result).toEqual(mockChainIdFr);
|
439
|
+
});
|
440
|
+
|
441
|
+
it('should return cached version', () => {
|
442
|
+
// version should already be cached from initialization
|
443
|
+
const result = wallet.getVersion();
|
444
|
+
expect(result.toBigInt()).toBe(1n);
|
445
|
+
});
|
446
|
+
|
447
|
+
it('should call aztec_getVersion async', async () => {
|
448
|
+
const mockVersionFr = new Fr(1n);
|
449
|
+
provider.call.mockResolvedValue(mockVersionFr);
|
450
|
+
|
451
|
+
const result = await wallet.getVersionAsync();
|
452
|
+
|
453
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
454
|
+
method: 'aztec_getVersion',
|
455
|
+
});
|
456
|
+
expect(result).toEqual(mockVersionFr);
|
457
|
+
});
|
458
|
+
});
|
459
|
+
|
460
|
+
describe('Sender methods', () => {
|
461
|
+
beforeEach(async () => {
|
462
|
+
const mockChainIdFr = new Fr(31337n);
|
463
|
+
const mockVersionFr = new Fr(1n);
|
464
|
+
|
465
|
+
provider.call.mockImplementation(async (_chainId: string, { method }: { method: string }) => {
|
466
|
+
switch (method) {
|
467
|
+
case 'aztec_getCompleteAddress':
|
468
|
+
return mockCompleteAddress;
|
469
|
+
case 'aztec_getChainId':
|
470
|
+
return mockChainIdFr;
|
471
|
+
case 'aztec_getVersion':
|
472
|
+
return mockVersionFr;
|
473
|
+
default:
|
474
|
+
return null;
|
475
|
+
}
|
476
|
+
});
|
477
|
+
await wallet.initialize();
|
478
|
+
provider.call.mockClear();
|
479
|
+
});
|
480
|
+
|
481
|
+
it('should call aztec_registerSender', async () => {
|
482
|
+
const senderAddress = await AztecAddress.random();
|
483
|
+
// registerSender returns the passed address after registration
|
484
|
+
provider.call.mockResolvedValue(undefined);
|
485
|
+
|
486
|
+
const result = await wallet.registerSender(senderAddress);
|
487
|
+
|
488
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
489
|
+
method: 'aztec_registerSender',
|
490
|
+
params: { sender: senderAddress },
|
491
|
+
});
|
492
|
+
expect(result).toEqual(senderAddress);
|
493
|
+
});
|
494
|
+
|
495
|
+
it('should call aztec_getSenders', async () => {
|
496
|
+
const senders = [mockAddress];
|
497
|
+
provider.call.mockResolvedValue(senders);
|
498
|
+
|
499
|
+
const result = await wallet.getSenders();
|
500
|
+
|
501
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
502
|
+
method: 'aztec_getSenders',
|
503
|
+
});
|
504
|
+
expect(result).toEqual(senders);
|
505
|
+
});
|
506
|
+
|
507
|
+
it('should call aztec_removeSender', async () => {
|
508
|
+
provider.call.mockResolvedValue(undefined);
|
509
|
+
|
510
|
+
await wallet.removeSender(mockAddress);
|
511
|
+
|
512
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
513
|
+
method: 'aztec_removeSender',
|
514
|
+
params: { sender: mockAddress },
|
515
|
+
});
|
516
|
+
});
|
517
|
+
});
|
518
|
+
|
519
|
+
describe('Additional methods', () => {
|
520
|
+
beforeEach(async () => {
|
521
|
+
const mockChainIdFr = new Fr(31337n);
|
522
|
+
const mockVersionFr = new Fr(1n);
|
523
|
+
|
524
|
+
provider.call.mockImplementation(async (_chainId: string, { method }: { method: string }) => {
|
525
|
+
switch (method) {
|
526
|
+
case 'aztec_getCompleteAddress':
|
527
|
+
return mockCompleteAddress;
|
528
|
+
case 'aztec_getChainId':
|
529
|
+
return mockChainIdFr;
|
530
|
+
case 'aztec_getVersion':
|
531
|
+
return mockVersionFr;
|
532
|
+
default:
|
533
|
+
return null;
|
534
|
+
}
|
535
|
+
});
|
536
|
+
await wallet.initialize();
|
537
|
+
provider.call.mockClear();
|
538
|
+
});
|
539
|
+
|
540
|
+
it('should call aztec_simulateTx', async () => {
|
541
|
+
const txRequest = { request: {} } as unknown as TxExecutionRequest;
|
542
|
+
const simulatedTx = { tx: txRequest, privateReturnValues: [] };
|
543
|
+
const msgSender = await AztecAddress.random();
|
544
|
+
provider.call.mockResolvedValue(simulatedTx);
|
545
|
+
|
546
|
+
const result = await wallet.simulateTx(txRequest, true, msgSender);
|
547
|
+
|
548
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
549
|
+
method: 'aztec_simulateTx',
|
550
|
+
params: {
|
551
|
+
txRequest,
|
552
|
+
simulatePublic: true,
|
553
|
+
msgSender,
|
554
|
+
},
|
555
|
+
});
|
556
|
+
expect(result).toEqual(simulatedTx);
|
557
|
+
});
|
558
|
+
|
559
|
+
it('should call aztec_getPXEInfo', async () => {
|
560
|
+
const pxeInfo = { version: '1.0.0' };
|
561
|
+
provider.call.mockResolvedValue(pxeInfo);
|
562
|
+
|
563
|
+
const result = await wallet.getPXEInfo();
|
564
|
+
|
565
|
+
expect(provider.call).toHaveBeenCalledWith(testChainId, {
|
566
|
+
method: 'aztec_getPXEInfo',
|
567
|
+
});
|
568
|
+
expect(result).toEqual(pxeInfo);
|
569
|
+
});
|
570
|
+
});
|
571
|
+
|
572
|
+
describe('createAztecWallet', () => {
|
573
|
+
it('should create and initialize a wallet with default chainId', async () => {
|
574
|
+
const mockChainIdFr = new Fr(31337n);
|
575
|
+
const mockVersionFr = new Fr(1n);
|
576
|
+
|
577
|
+
provider.call.mockImplementation(async (chainId: string, { method }: { method: string }) => {
|
578
|
+
expect(chainId).toBe('aztec:mainnet'); // default chainId
|
579
|
+
switch (method) {
|
580
|
+
case 'aztec_getCompleteAddress':
|
581
|
+
return mockCompleteAddress;
|
582
|
+
case 'aztec_getChainId':
|
583
|
+
return mockChainIdFr;
|
584
|
+
case 'aztec_getVersion':
|
585
|
+
return mockVersionFr;
|
586
|
+
default:
|
587
|
+
throw new Error(`Unexpected method: ${method}`);
|
588
|
+
}
|
589
|
+
});
|
590
|
+
|
591
|
+
const wallet = await createAztecWallet(provider);
|
592
|
+
|
593
|
+
expect(wallet).toBeInstanceOf(AztecDappWallet);
|
594
|
+
expect(wallet.getAddress()).toEqual(mockAddress);
|
595
|
+
expect(wallet.getCompleteAddress()).toEqual(mockCompleteAddress);
|
596
|
+
expect(wallet.getChainId()).toEqual(mockChainIdFr);
|
597
|
+
expect(wallet.getVersion()).toEqual(mockVersionFr);
|
598
|
+
});
|
599
|
+
|
600
|
+
it('should create and initialize a wallet with custom chainId', async () => {
|
601
|
+
const mockChainIdFr = new Fr(31337n);
|
602
|
+
const mockVersionFr = new Fr(1n);
|
603
|
+
const customChainId = 'aztec:custom';
|
604
|
+
|
605
|
+
provider.call.mockImplementation(async (chainId: string, { method }: { method: string }) => {
|
606
|
+
expect(chainId).toBe(customChainId);
|
607
|
+
switch (method) {
|
608
|
+
case 'aztec_getCompleteAddress':
|
609
|
+
return mockCompleteAddress;
|
610
|
+
case 'aztec_getChainId':
|
611
|
+
return mockChainIdFr;
|
612
|
+
case 'aztec_getVersion':
|
613
|
+
return mockVersionFr;
|
614
|
+
default:
|
615
|
+
throw new Error(`Unexpected method: ${method}`);
|
616
|
+
}
|
617
|
+
});
|
618
|
+
|
619
|
+
const wallet = await createAztecWallet(provider, customChainId);
|
620
|
+
|
621
|
+
expect(wallet).toBeInstanceOf(AztecDappWallet);
|
622
|
+
expect(wallet.getAddress()).toEqual(mockAddress);
|
623
|
+
expect(wallet.getCompleteAddress()).toEqual(mockCompleteAddress);
|
624
|
+
expect(wallet.getChainId()).toEqual(mockChainIdFr);
|
625
|
+
expect(wallet.getVersion()).toEqual(mockVersionFr);
|
626
|
+
});
|
627
|
+
});
|
628
|
+
});
|