@walletmesh/aztec-rpc-wallet 0.2.0 → 0.3.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 +12 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/aztecRemoteWallet.d.ts +4 -8
- package/dist/aztecRemoteWallet.d.ts.map +1 -1
- package/dist/aztecRemoteWallet.js +5 -29
- package/dist/contractArtifactCache.d.ts.map +1 -1
- package/dist/contractArtifactCache.js +20 -9
- package/dist/handlers/aztecAccountWallet.d.ts.map +1 -1
- package/dist/handlers/aztecAccountWallet.js +11 -44
- package/dist/serializers/account.d.ts +16 -16
- package/dist/serializers/account.d.ts.map +1 -1
- package/dist/serializers/account.js +43 -43
- package/dist/serializers/contract.d.ts +22 -76
- package/dist/serializers/contract.d.ts.map +1 -1
- package/dist/serializers/contract.js +68 -120
- package/dist/serializers/index.d.ts +0 -4
- package/dist/serializers/index.d.ts.map +1 -1
- package/dist/serializers/index.js +15 -20
- package/dist/serializers/log.d.ts +16 -16
- package/dist/serializers/log.d.ts.map +1 -1
- package/dist/serializers/log.js +43 -43
- package/dist/serializers/note.d.ts +12 -12
- package/dist/serializers/note.d.ts.map +1 -1
- package/dist/serializers/note.js +32 -32
- package/dist/serializers/transaction.d.ts +25 -26
- package/dist/serializers/transaction.d.ts.map +1 -1
- package/dist/serializers/transaction.js +92 -44
- package/dist/types.d.ts +7 -30
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/docs/README.md +264 -0
- package/docs/classes/AztecChainProvider.md +553 -0
- package/docs/classes/AztecChainWallet.md +409 -0
- package/docs/classes/AztecProvider.md +1112 -0
- package/docs/classes/AztecWalletError.md +213 -0
- package/docs/classes/ContractArtifactCache.md +81 -0
- package/docs/globals.md +34 -0
- package/docs/interfaces/AztecWalletBaseMethodMap.md +135 -0
- package/docs/interfaces/AztecWalletEventMap.md +17 -0
- package/docs/interfaces/AztecWalletMethodMap.md +1012 -0
- package/docs/type-aliases/AztecChainId.md +11 -0
- package/docs/type-aliases/AztecChainWalletMiddleware.md +13 -0
- package/docs/type-aliases/AztecWalletContext.md +29 -0
- package/docs/type-aliases/AztecWalletMethodHandler.md +37 -0
- package/docs/type-aliases/AztecWalletMiddleware.md +13 -0
- package/docs/type-aliases/AztecWalletRouterClient.md +13 -0
- package/docs/type-aliases/TransactionFunctionCall.md +33 -0
- package/docs/type-aliases/TransactionParams.md +27 -0
- package/docs/variables/AztecWalletErrorMap.md +13 -0
- package/package.json +9 -9
- package/src/aztecRemoteWallet.test.ts +22 -61
- package/src/aztecRemoteWallet.ts +8 -35
- package/src/chainProvider.test.ts +117 -38
- package/src/contractArtifactCache.test.ts +28 -45
- package/src/contractArtifactCache.ts +20 -10
- package/src/handlers/aztecAccountWallet.test.ts +12 -86
- package/src/handlers/aztecAccountWallet.ts +19 -77
- package/src/provider.test.ts +0 -2
- package/src/serializers/account.test.ts +19 -20
- package/src/serializers/account.ts +52 -52
- package/src/serializers/contract.test.ts +4 -140
- package/src/serializers/contract.ts +93 -166
- package/src/serializers/index.test.ts +30 -28
- package/src/serializers/index.ts +15 -21
- package/src/serializers/log.test.ts +42 -48
- package/src/serializers/log.ts +54 -54
- package/src/serializers/note.test.ts +43 -16
- package/src/serializers/note.ts +39 -39
- package/src/serializers/transaction.test.ts +48 -41
- package/src/serializers/transaction.ts +146 -58
- package/src/types.ts +7 -7
- package/src/wallet.test.ts +3 -3
- package/dist/serializers/transaction-utils.d.ts +0 -51
- package/dist/serializers/transaction-utils.d.ts.map +0 -1
- package/dist/serializers/transaction-utils.js +0 -103
- package/src/serializers/transaction-utils.ts +0 -174
@@ -1,12 +1,19 @@
|
|
1
1
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
2
|
-
import type {
|
2
|
+
import type { JSONRPCRequest } from '@walletmesh/jsonrpc';
|
3
3
|
import { AztecChainProvider } from './chainProvider.js';
|
4
4
|
import { AztecWalletError } from './errors.js';
|
5
5
|
import type { ContractInstanceWithAddress, ContractArtifact, AztecAddress } from '@aztec/aztec.js';
|
6
6
|
import type { AztecWalletMethodMap } from './types.js';
|
7
7
|
|
8
8
|
const createMockTransport = () => ({
|
9
|
-
send: vi
|
9
|
+
send: vi
|
10
|
+
.fn()
|
11
|
+
.mockImplementation(
|
12
|
+
async (_request: JSONRPCRequest<AztecWalletMethodMap, keyof AztecWalletMethodMap>) => {
|
13
|
+
// Default mock implementation that records the call but returns undefined
|
14
|
+
return undefined;
|
15
|
+
},
|
16
|
+
),
|
10
17
|
});
|
11
18
|
|
12
19
|
describe('AztecChainProvider', () => {
|
@@ -27,10 +34,16 @@ describe('AztecChainProvider', () => {
|
|
27
34
|
const expectedAddress = '0x1234567890abcdef';
|
28
35
|
const promise = provider.getAccount();
|
29
36
|
|
37
|
+
// Wait for the async operation to complete
|
38
|
+
await Promise.resolve();
|
39
|
+
|
30
40
|
// Get the request ID from the sent message
|
31
|
-
|
32
|
-
|
33
|
-
|
41
|
+
expect(mockTransport.send).toHaveBeenCalledTimes(1);
|
42
|
+
const firstCall = mockTransport.send.mock.calls[0];
|
43
|
+
if (!firstCall) throw new Error('Expected mock to be called');
|
44
|
+
const request = firstCall[0];
|
45
|
+
if (!request) throw new Error('Expected request to be defined');
|
46
|
+
const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_getAccount'>;
|
34
47
|
expect(sentRequest).toEqual({
|
35
48
|
jsonrpc: '2.0',
|
36
49
|
id: expect.any(String),
|
@@ -51,10 +64,16 @@ describe('AztecChainProvider', () => {
|
|
51
64
|
it('throws on invalid response', async () => {
|
52
65
|
const promise = provider.getAccount();
|
53
66
|
|
67
|
+
// Wait for the async operation to complete
|
68
|
+
await Promise.resolve();
|
69
|
+
|
54
70
|
// Get the request ID
|
55
|
-
|
56
|
-
|
57
|
-
|
71
|
+
expect(mockTransport.send).toHaveBeenCalledTimes(1);
|
72
|
+
const firstCall = mockTransport.send.mock.calls[0];
|
73
|
+
if (!firstCall) throw new Error('Expected mock to be called');
|
74
|
+
const request = firstCall[0];
|
75
|
+
if (!request) throw new Error('Expected request to be defined');
|
76
|
+
const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_getAccount'>;
|
58
77
|
|
59
78
|
// Simulate error response
|
60
79
|
await provider.receiveMessage({
|
@@ -82,10 +101,16 @@ describe('AztecChainProvider', () => {
|
|
82
101
|
const expectedHash = '0xabcd';
|
83
102
|
const promise = provider.sendTransaction(txParams);
|
84
103
|
|
104
|
+
// Wait for the async operation to complete
|
105
|
+
await Promise.resolve();
|
106
|
+
|
85
107
|
// Get the request ID
|
86
|
-
|
87
|
-
|
88
|
-
|
108
|
+
expect(mockTransport.send).toHaveBeenCalledTimes(1);
|
109
|
+
const firstCall = mockTransport.send.mock.calls[0];
|
110
|
+
if (!firstCall) throw new Error('Expected mock to be called');
|
111
|
+
const request = firstCall[0];
|
112
|
+
if (!request) throw new Error('Expected request to be defined');
|
113
|
+
const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_sendTransaction'>;
|
89
114
|
expect(sentRequest).toEqual({
|
90
115
|
jsonrpc: '2.0',
|
91
116
|
id: expect.any(String),
|
@@ -107,10 +132,16 @@ describe('AztecChainProvider', () => {
|
|
107
132
|
it('throws on invalid response', async () => {
|
108
133
|
const promise = provider.sendTransaction(txParams);
|
109
134
|
|
135
|
+
// Wait for the async operation to complete
|
136
|
+
await Promise.resolve();
|
137
|
+
|
110
138
|
// Get the request ID
|
111
|
-
|
112
|
-
|
113
|
-
|
139
|
+
expect(mockTransport.send).toHaveBeenCalledTimes(1);
|
140
|
+
const firstCall = mockTransport.send.mock.calls[0];
|
141
|
+
if (!firstCall) throw new Error('Expected mock to be called');
|
142
|
+
const request = firstCall[0];
|
143
|
+
if (!request) throw new Error('Expected request to be defined');
|
144
|
+
const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_sendTransaction'>;
|
114
145
|
|
115
146
|
// Simulate error response
|
116
147
|
await provider.receiveMessage({
|
@@ -134,10 +165,16 @@ describe('AztecChainProvider', () => {
|
|
134
165
|
const expectedResult = { success: true, data: 'test' };
|
135
166
|
const promise = provider.simulateTransaction(txParams);
|
136
167
|
|
168
|
+
// Wait for the async operation to complete
|
169
|
+
await Promise.resolve();
|
170
|
+
|
137
171
|
// Get the request ID
|
138
|
-
|
139
|
-
|
140
|
-
|
172
|
+
expect(mockTransport.send).toHaveBeenCalledTimes(1);
|
173
|
+
const firstCall = mockTransport.send.mock.calls[0];
|
174
|
+
if (!firstCall) throw new Error('Expected mock to be called');
|
175
|
+
const request = firstCall[0];
|
176
|
+
if (!request) throw new Error('Expected request to be defined');
|
177
|
+
const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_simulateTransaction'>;
|
141
178
|
expect(sentRequest).toEqual({
|
142
179
|
jsonrpc: '2.0',
|
143
180
|
id: expect.any(String),
|
@@ -159,10 +196,16 @@ describe('AztecChainProvider', () => {
|
|
159
196
|
it('throws on invalid response', async () => {
|
160
197
|
const promise = provider.simulateTransaction(txParams);
|
161
198
|
|
199
|
+
// Wait for the async operation to complete
|
200
|
+
await Promise.resolve();
|
201
|
+
|
162
202
|
// Get the request ID
|
163
|
-
|
164
|
-
|
165
|
-
|
203
|
+
expect(mockTransport.send).toHaveBeenCalledTimes(1);
|
204
|
+
const firstCall = mockTransport.send.mock.calls[0];
|
205
|
+
if (!firstCall) throw new Error('Expected mock to be called');
|
206
|
+
const request = firstCall[0];
|
207
|
+
if (!request) throw new Error('Expected request to be defined');
|
208
|
+
const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_simulateTransaction'>;
|
166
209
|
|
167
210
|
// Simulate error response
|
168
211
|
await provider.receiveMessage({
|
@@ -184,10 +227,16 @@ describe('AztecChainProvider', () => {
|
|
184
227
|
it('succeeds on valid response', async () => {
|
185
228
|
const promise = provider.registerContract(contractParams);
|
186
229
|
|
230
|
+
// Wait for the async operation to complete
|
231
|
+
await Promise.resolve();
|
232
|
+
|
187
233
|
// Get the request ID
|
188
|
-
|
189
|
-
|
190
|
-
|
234
|
+
expect(mockTransport.send).toHaveBeenCalledTimes(1);
|
235
|
+
const firstCall = mockTransport.send.mock.calls[0];
|
236
|
+
if (!firstCall) throw new Error('Expected mock to be called');
|
237
|
+
const request = firstCall[0];
|
238
|
+
if (!request) throw new Error('Expected request to be defined');
|
239
|
+
const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerContract'>;
|
191
240
|
expect(sentRequest).toEqual({
|
192
241
|
jsonrpc: '2.0',
|
193
242
|
id: expect.any(String),
|
@@ -208,10 +257,16 @@ describe('AztecChainProvider', () => {
|
|
208
257
|
it('throws on invalid response', async () => {
|
209
258
|
const promise = provider.registerContract(contractParams);
|
210
259
|
|
260
|
+
// Wait for the async operation to complete
|
261
|
+
await Promise.resolve();
|
262
|
+
|
211
263
|
// Get the request ID
|
212
|
-
|
213
|
-
|
214
|
-
|
264
|
+
expect(mockTransport.send).toHaveBeenCalledTimes(1);
|
265
|
+
const firstCall = mockTransport.send.mock.calls[0];
|
266
|
+
if (!firstCall) throw new Error('Expected mock to be called');
|
267
|
+
const request = firstCall[0];
|
268
|
+
if (!request) throw new Error('Expected request to be defined');
|
269
|
+
const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerContract'>;
|
215
270
|
|
216
271
|
// Simulate error response
|
217
272
|
await provider.receiveMessage({
|
@@ -232,10 +287,16 @@ describe('AztecChainProvider', () => {
|
|
232
287
|
it('succeeds on valid response', async () => {
|
233
288
|
const promise = provider.registerContractClass(classParams);
|
234
289
|
|
290
|
+
// Wait for the async operation to complete
|
291
|
+
await Promise.resolve();
|
292
|
+
|
235
293
|
// Get the request ID
|
236
|
-
|
237
|
-
|
238
|
-
|
294
|
+
expect(mockTransport.send).toHaveBeenCalledTimes(1);
|
295
|
+
const firstCall = mockTransport.send.mock.calls[0];
|
296
|
+
if (!firstCall) throw new Error('Expected mock to be called');
|
297
|
+
const request = firstCall[0];
|
298
|
+
if (!request) throw new Error('Expected request to be defined');
|
299
|
+
const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerContractClass'>;
|
239
300
|
expect(sentRequest).toEqual({
|
240
301
|
jsonrpc: '2.0',
|
241
302
|
id: expect.any(String),
|
@@ -256,10 +317,16 @@ describe('AztecChainProvider', () => {
|
|
256
317
|
it('throws on invalid response', async () => {
|
257
318
|
const promise = provider.registerContractClass(classParams);
|
258
319
|
|
320
|
+
// Wait for the async operation to complete
|
321
|
+
await Promise.resolve();
|
322
|
+
|
259
323
|
// Get the request ID
|
260
|
-
|
261
|
-
|
262
|
-
|
324
|
+
expect(mockTransport.send).toHaveBeenCalledTimes(1);
|
325
|
+
const firstCall = mockTransport.send.mock.calls[0];
|
326
|
+
if (!firstCall) throw new Error('Expected mock to be called');
|
327
|
+
const request = firstCall[0];
|
328
|
+
if (!request) throw new Error('Expected request to be defined');
|
329
|
+
const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerContractClass'>;
|
263
330
|
|
264
331
|
// Simulate error response
|
265
332
|
await provider.receiveMessage({
|
@@ -280,10 +347,16 @@ describe('AztecChainProvider', () => {
|
|
280
347
|
it('succeeds on valid response', async () => {
|
281
348
|
const promise = provider.registerSender(senderParams);
|
282
349
|
|
350
|
+
// Wait for the async operation to complete
|
351
|
+
await Promise.resolve();
|
352
|
+
|
283
353
|
// Get the request ID
|
284
|
-
|
285
|
-
|
286
|
-
|
354
|
+
expect(mockTransport.send).toHaveBeenCalledTimes(1);
|
355
|
+
const firstCall = mockTransport.send.mock.calls[0];
|
356
|
+
if (!firstCall) throw new Error('Expected mock to be called');
|
357
|
+
const request = firstCall[0];
|
358
|
+
if (!request) throw new Error('Expected request to be defined');
|
359
|
+
const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerSender'>;
|
287
360
|
expect(sentRequest).toEqual({
|
288
361
|
jsonrpc: '2.0',
|
289
362
|
id: expect.any(String),
|
@@ -304,10 +377,16 @@ describe('AztecChainProvider', () => {
|
|
304
377
|
it('throws on invalid response', async () => {
|
305
378
|
const promise = provider.registerSender(senderParams);
|
306
379
|
|
380
|
+
// Wait for the async operation to complete
|
381
|
+
await Promise.resolve();
|
382
|
+
|
307
383
|
// Get the request ID
|
308
|
-
|
309
|
-
|
310
|
-
|
384
|
+
expect(mockTransport.send).toHaveBeenCalledTimes(1);
|
385
|
+
const firstCall = mockTransport.send.mock.calls[0];
|
386
|
+
if (!firstCall) throw new Error('Expected mock to be called');
|
387
|
+
const request = firstCall[0];
|
388
|
+
if (!request) throw new Error('Expected request to be defined');
|
389
|
+
const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerSender'>;
|
311
390
|
|
312
391
|
// Simulate error response
|
313
392
|
await provider.receiveMessage({
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { describe, expect, it, vi, beforeEach, type Mock } from 'vitest';
|
2
|
-
import type { AztecAddress, ContractArtifact,
|
2
|
+
import type { AztecAddress, ContractArtifact, Fr, Wallet } from '@aztec/aztec.js';
|
3
|
+
import { randomDeployedContract } from '@aztec/circuit-types';
|
3
4
|
import { ContractArtifactCache } from './contractArtifactCache.js';
|
4
5
|
import { AztecWalletError } from './errors.js';
|
5
6
|
|
@@ -7,45 +8,23 @@ describe('ContractArtifactCache', () => {
|
|
7
8
|
let wallet: Wallet;
|
8
9
|
let cache: ContractArtifactCache;
|
9
10
|
let mockContractAddress: AztecAddress;
|
10
|
-
let mockContractClassId:
|
11
|
+
let mockContractClassId: Fr;
|
11
12
|
let mockArtifact: ContractArtifact;
|
12
13
|
|
13
|
-
beforeEach(() => {
|
14
|
+
beforeEach(async () => {
|
14
15
|
// Mock contract address and class ID
|
15
16
|
// Create a complete mock of AztecAddress
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
toBuffer: () => Buffer.from([]),
|
23
|
-
toFields: () => [],
|
24
|
-
toField: () => BigInt(0),
|
25
|
-
toBigInt: () => BigInt(0),
|
26
|
-
isZero: () => false,
|
27
|
-
isValid: () => true,
|
28
|
-
toAddressPoint: () => ({ x: BigInt(0) }),
|
29
|
-
toJSON: () => ({ x: '0' }),
|
30
|
-
[Symbol.for('nodejs.util.inspect.custom')]: () => 'AztecAddress',
|
31
|
-
} as unknown as AztecAddress;
|
32
|
-
|
33
|
-
// Create a complete mock of ContractClassWithId
|
34
|
-
mockContractClassId = {
|
35
|
-
toString: () => '456',
|
36
|
-
id: BigInt(456),
|
37
|
-
version: 1,
|
38
|
-
artifactHash: BigInt(0),
|
39
|
-
privateFunctions: new Map(),
|
40
|
-
publicFunctions: new Map(),
|
41
|
-
packedBytecode: new Uint8Array(),
|
42
|
-
} as unknown as ContractClassWithId;
|
43
|
-
mockArtifact = { name: 'TestContract' } as ContractArtifact;
|
17
|
+
|
18
|
+
const { instance, artifact } = await randomDeployedContract();
|
19
|
+
|
20
|
+
mockContractAddress = instance.address;
|
21
|
+
mockContractClassId = instance.contractClassId;
|
22
|
+
mockArtifact = artifact;
|
44
23
|
|
45
24
|
// Create mock wallet
|
46
25
|
wallet = {
|
47
|
-
|
48
|
-
|
26
|
+
getContractMetadata: vi.fn(),
|
27
|
+
getContractClassMetadata: vi.fn(),
|
49
28
|
} as unknown as Wallet;
|
50
29
|
|
51
30
|
// Initialize cache with mock wallet
|
@@ -64,21 +43,23 @@ describe('ContractArtifactCache', () => {
|
|
64
43
|
|
65
44
|
// Verify: Result is from cache, wallet methods not called
|
66
45
|
expect(result).toBe(mockArtifact);
|
67
|
-
expect(wallet.
|
68
|
-
expect(wallet.
|
46
|
+
expect(wallet.getContractMetadata).not.toHaveBeenCalled();
|
47
|
+
expect(wallet.getContractClassMetadata).not.toHaveBeenCalled();
|
69
48
|
});
|
70
49
|
|
71
50
|
it('fetches and caches artifact on cache miss', async () => {
|
72
51
|
// Setup: Configure wallet mocks
|
73
|
-
(wallet.
|
74
|
-
|
52
|
+
(wallet.getContractMetadata as Mock).mockResolvedValue({
|
53
|
+
contractInstance: { contractClassId: mockContractClassId },
|
54
|
+
});
|
55
|
+
(wallet.getContractClassMetadata as Mock).mockResolvedValue({ artifact: mockArtifact });
|
75
56
|
|
76
57
|
// Test: Get artifact
|
77
58
|
const result = await cache.getContractArtifact(mockContractAddress);
|
78
59
|
|
79
60
|
// Verify: Correct methods called and result cached
|
80
|
-
expect(wallet.
|
81
|
-
expect(wallet.
|
61
|
+
expect(wallet.getContractMetadata).toHaveBeenCalledWith(mockContractAddress);
|
62
|
+
expect(wallet.getContractClassMetadata).toHaveBeenCalledWith(mockContractClassId);
|
82
63
|
expect(result).toBe(mockArtifact);
|
83
64
|
|
84
65
|
// Verify: Result was cached
|
@@ -89,9 +70,9 @@ describe('ContractArtifactCache', () => {
|
|
89
70
|
).toBe(mockArtifact);
|
90
71
|
});
|
91
72
|
|
92
|
-
it('throws error if contract
|
73
|
+
it('throws error if contract metadata not found', async () => {
|
93
74
|
// Setup: Mock contract instance not found
|
94
|
-
(wallet.
|
75
|
+
(wallet.getContractMetadata as Mock).mockResolvedValue({ contractInstance: undefined });
|
95
76
|
|
96
77
|
// Test & Verify: Expect error
|
97
78
|
await expect(cache.getContractArtifact(mockContractAddress)).rejects.toThrow(
|
@@ -106,10 +87,12 @@ describe('ContractArtifactCache', () => {
|
|
106
87
|
).toBeUndefined();
|
107
88
|
});
|
108
89
|
|
109
|
-
it('throws error if contract
|
110
|
-
// Setup: Mock contract
|
111
|
-
(wallet.
|
112
|
-
|
90
|
+
it('throws error if contract class metadata not found', async () => {
|
91
|
+
// Setup: Mock contract metadata found but class metadata missing
|
92
|
+
(wallet.getContractMetadata as Mock).mockResolvedValue({
|
93
|
+
contractInstance: { contractClassId: mockContractClassId },
|
94
|
+
});
|
95
|
+
(wallet.getContractClassMetadata as Mock).mockResolvedValue({ artifact: undefined });
|
113
96
|
|
114
97
|
// Test & Verify: Expect error
|
115
98
|
await expect(cache.getContractArtifact(mockContractAddress)).rejects.toThrow(
|
@@ -60,16 +60,26 @@ export class ContractArtifactCache {
|
|
60
60
|
return cached;
|
61
61
|
}
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
throw new AztecWalletError('contractClassNotRegistered', contract.contractClassId.toString());
|
70
|
-
}
|
63
|
+
try {
|
64
|
+
const contractMetadata = await this.wallet.getContractMetadata(contractAddress);
|
65
|
+
const contract = contractMetadata.contractInstance;
|
66
|
+
if (!contract) {
|
67
|
+
throw new AztecWalletError('contractInstanceNotRegistered', addressStr);
|
68
|
+
}
|
71
69
|
|
72
|
-
|
73
|
-
|
70
|
+
const contractClassMetadata = await this.wallet.getContractClassMetadata(contract.contractClassId);
|
71
|
+
const artifact = contractClassMetadata.artifact;
|
72
|
+
if (!artifact) {
|
73
|
+
throw new AztecWalletError('contractClassNotRegistered', contract.contractClassId.toString());
|
74
|
+
}
|
75
|
+
this.cache.set(addressStr, artifact);
|
76
|
+
return artifact;
|
77
|
+
} catch (error) {
|
78
|
+
if (error instanceof AztecWalletError) {
|
79
|
+
throw error;
|
80
|
+
}
|
81
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
82
|
+
throw new AztecWalletError('contractInstanceNotRegistered', `${addressStr}: ${errorMessage}`);
|
83
|
+
}
|
74
84
|
}
|
75
85
|
}
|
@@ -6,7 +6,6 @@ import type {
|
|
6
6
|
ContractInstanceWithAddress,
|
7
7
|
ContractArtifact,
|
8
8
|
PublicKeys,
|
9
|
-
Note,
|
10
9
|
AuthWitness,
|
11
10
|
Tx,
|
12
11
|
} from '@aztec/aztec.js';
|
@@ -46,12 +45,8 @@ describe('Aztec Account Wallet Handler', () => {
|
|
46
45
|
createAuthWit: vi.fn(),
|
47
46
|
isL1ToL2MessageSynced: vi.fn(),
|
48
47
|
getContracts: vi.fn(),
|
49
|
-
|
50
|
-
|
51
|
-
getContractArtifact: vi.fn(),
|
52
|
-
isContractClassPubliclyRegistered: vi.fn(),
|
53
|
-
isContractPubliclyDeployed: vi.fn(),
|
54
|
-
isContractInitialized: vi.fn(),
|
48
|
+
getContractMetadata: vi.fn(),
|
49
|
+
getContractClassMetadata: vi.fn(),
|
55
50
|
registerContract: vi.fn(),
|
56
51
|
registerContractClass: vi.fn(),
|
57
52
|
getPublicStorageAt: vi.fn(),
|
@@ -255,91 +250,22 @@ describe('Aztec Account Wallet Handler', () => {
|
|
255
250
|
});
|
256
251
|
|
257
252
|
describe('Contract Methods', () => {
|
258
|
-
it('handles
|
253
|
+
it('handles aztec_getContractMetadata', async () => {
|
259
254
|
const mockAddress = await AztecAddress.random();
|
260
|
-
const
|
261
|
-
|
262
|
-
toString: () => mockAddress.toString(),
|
263
|
-
} as unknown as ContractInstanceWithAddress;
|
264
|
-
wallet.getContractInstance = vi.fn().mockResolvedValue(mockInstance);
|
265
|
-
|
266
|
-
const result = await aztecWalletHandler(context, 'aztec_getContractInstance', { address: mockAddress });
|
267
|
-
expect(result).toBe(mockInstance);
|
268
|
-
});
|
269
|
-
|
270
|
-
it('throws error when contract instance not found', async () => {
|
271
|
-
wallet.getContractInstance = vi.fn().mockResolvedValue(null);
|
272
|
-
|
273
|
-
const testAddress = await AztecAddress.random();
|
274
|
-
await expect(
|
275
|
-
aztecWalletHandler(context, 'aztec_getContractInstance', { address: testAddress }),
|
276
|
-
).rejects.toThrow(AztecWalletError);
|
277
|
-
});
|
278
|
-
|
279
|
-
it('handles aztec_getContractClass', async () => {
|
280
|
-
const mockId = await Fr.random();
|
281
|
-
const mockContractClass = { id: mockId };
|
282
|
-
wallet.getContractClass = vi.fn().mockResolvedValue(mockContractClass);
|
283
|
-
|
284
|
-
const result = await aztecWalletHandler(context, 'aztec_getContractClass', { id: mockId });
|
285
|
-
expect(result).toBe(mockContractClass);
|
286
|
-
});
|
287
|
-
|
288
|
-
it('throws error when contract class not found', async () => {
|
289
|
-
wallet.getContractClass = vi.fn().mockResolvedValue(null);
|
290
|
-
const mockId = await Fr.random();
|
291
|
-
|
292
|
-
await expect(aztecWalletHandler(context, 'aztec_getContractClass', { id: mockId })).rejects.toThrow(
|
293
|
-
AztecWalletError,
|
294
|
-
);
|
295
|
-
});
|
296
|
-
|
297
|
-
it('handles aztec_getContractArtifact', async () => {
|
298
|
-
const mockId = await Fr.random();
|
299
|
-
const mockArtifact = { id: mockId, name: 'TestContract' };
|
300
|
-
wallet.getContractArtifact = vi.fn().mockResolvedValue(mockArtifact);
|
255
|
+
const mockMetadata = { address: mockAddress };
|
256
|
+
wallet.getContractMetadata = vi.fn().mockResolvedValue(mockMetadata);
|
301
257
|
|
302
|
-
const result = await aztecWalletHandler(context, '
|
303
|
-
expect(result).toBe(
|
258
|
+
const result = await aztecWalletHandler(context, 'aztec_getContractMetadata', { address: mockAddress });
|
259
|
+
expect(result).toBe(mockMetadata);
|
304
260
|
});
|
305
261
|
|
306
|
-
it('
|
307
|
-
wallet.getContractArtifact = vi.fn().mockResolvedValue(null);
|
262
|
+
it('handles aztec_getContractClassMetadata', async () => {
|
308
263
|
const mockId = await Fr.random();
|
264
|
+
const mockMetadata = { id: mockId };
|
265
|
+
wallet.getContractClassMetadata = vi.fn().mockResolvedValue(mockMetadata);
|
309
266
|
|
310
|
-
await
|
311
|
-
|
312
|
-
);
|
313
|
-
});
|
314
|
-
|
315
|
-
it('handles aztec_isContractClassPubliclyRegistered', async () => {
|
316
|
-
const mockId = await Fr.random();
|
317
|
-
wallet.isContractClassPubliclyRegistered = vi.fn().mockResolvedValue(true);
|
318
|
-
|
319
|
-
const result = await aztecWalletHandler(context, 'aztec_isContractClassPubliclyRegistered', {
|
320
|
-
id: mockId,
|
321
|
-
});
|
322
|
-
expect(result).toBe(true);
|
323
|
-
});
|
324
|
-
|
325
|
-
it('handles aztec_isContractPubliclyDeployed', async () => {
|
326
|
-
const mockAddress = await AztecAddress.random();
|
327
|
-
wallet.isContractPubliclyDeployed = vi.fn().mockResolvedValue(true);
|
328
|
-
|
329
|
-
const result = await aztecWalletHandler(context, 'aztec_isContractPubliclyDeployed', {
|
330
|
-
address: mockAddress,
|
331
|
-
});
|
332
|
-
expect(result).toBe(true);
|
333
|
-
});
|
334
|
-
|
335
|
-
it('handles aztec_isContractInitialized', async () => {
|
336
|
-
const mockAddress = await AztecAddress.random();
|
337
|
-
wallet.isContractInitialized = vi.fn().mockResolvedValue(true);
|
338
|
-
|
339
|
-
const result = await aztecWalletHandler(context, 'aztec_isContractInitialized', {
|
340
|
-
address: mockAddress,
|
341
|
-
});
|
342
|
-
expect(result).toBe(true);
|
267
|
+
const result = await aztecWalletHandler(context, 'aztec_getContractClassMetadata', { id: mockId });
|
268
|
+
expect(result).toBe(mockMetadata);
|
343
269
|
});
|
344
270
|
|
345
271
|
it('handles aztec_registerContract', async () => {
|