@rocketh/core 0.17.8 → 0.17.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/account.d.ts +43 -0
- package/dist/account.d.ts.map +1 -0
- package/dist/account.js +61 -0
- package/dist/account.js.map +1 -0
- package/dist/account.test.d.ts +2 -0
- package/dist/account.test.d.ts.map +1 -0
- package/dist/account.test.js +324 -0
- package/dist/account.test.js.map +1 -0
- package/dist/artifacts.test.d.ts +2 -0
- package/dist/artifacts.test.d.ts.map +1 -0
- package/dist/artifacts.test.js +682 -0
- package/dist/artifacts.test.js.map +1 -0
- package/dist/environment.integration.test.d.ts +13 -0
- package/dist/environment.integration.test.d.ts.map +1 -0
- package/dist/environment.integration.test.js +296 -0
- package/dist/environment.integration.test.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/json.test.d.ts +2 -0
- package/dist/json.test.d.ts.map +1 -0
- package/dist/json.test.js +383 -0
- package/dist/json.test.js.map +1 -0
- package/dist/providers/TransactionHashTracker.test.d.ts +2 -0
- package/dist/providers/TransactionHashTracker.test.d.ts.map +1 -0
- package/dist/providers/TransactionHashTracker.test.js +284 -0
- package/dist/providers/TransactionHashTracker.test.js.map +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +16 -7
- package/src/account.ts +74 -0
- package/src/artifacts.ts +176 -0
- package/src/environment.ts +98 -0
- package/src/index.ts +24 -0
- package/src/json.ts +63 -0
- package/src/providers/BaseProvider.ts +13 -0
- package/src/providers/TransactionHashTracker.ts +26 -0
- package/src/providers/index.ts +1 -0
- package/src/types.ts +637 -0
|
@@ -0,0 +1,682 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { mergeABIs, mergeArtifacts } from './artifacts.js';
|
|
3
|
+
describe('Artifact Utilities', () => {
|
|
4
|
+
describe('mergeABIs', () => {
|
|
5
|
+
describe('basic merging', () => {
|
|
6
|
+
it('should merge two simple ABIs', () => {
|
|
7
|
+
const abi1 = [
|
|
8
|
+
{
|
|
9
|
+
type: 'function',
|
|
10
|
+
name: 'foo',
|
|
11
|
+
inputs: [],
|
|
12
|
+
outputs: [],
|
|
13
|
+
stateMutability: 'nonpayable',
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
const abi2 = [
|
|
17
|
+
{
|
|
18
|
+
type: 'function',
|
|
19
|
+
name: 'bar',
|
|
20
|
+
inputs: [],
|
|
21
|
+
outputs: [],
|
|
22
|
+
stateMutability: 'nonpayable',
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
const result = mergeABIs([
|
|
26
|
+
{ name: 'Contract1', abi: abi1 },
|
|
27
|
+
{ name: 'Contract2', abi: abi2 },
|
|
28
|
+
]);
|
|
29
|
+
expect(result.mergedABI).toHaveLength(2);
|
|
30
|
+
expect(result.mergedABI[0].name).toBe('foo');
|
|
31
|
+
expect(result.mergedABI[1].name).toBe('bar');
|
|
32
|
+
});
|
|
33
|
+
it('should handle ABI with no functions', () => {
|
|
34
|
+
const abi1 = [
|
|
35
|
+
{
|
|
36
|
+
type: 'event',
|
|
37
|
+
name: 'Transfer',
|
|
38
|
+
inputs: [],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
type: 'event',
|
|
42
|
+
name: 'Approval',
|
|
43
|
+
inputs: [],
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
const result = mergeABIs([{ name: 'Contract1', abi: abi1 }]);
|
|
47
|
+
// Both events should be included since they have different names
|
|
48
|
+
expect(result.mergedABI).toHaveLength(2);
|
|
49
|
+
expect(result.mergedABI[0].type).toBe('event');
|
|
50
|
+
expect(result.mergedABI[0].name).toBe('Transfer');
|
|
51
|
+
expect(result.mergedABI[1].type).toBe('event');
|
|
52
|
+
expect(result.mergedABI[1].name).toBe('Approval');
|
|
53
|
+
});
|
|
54
|
+
it('should handle empty ABI', () => {
|
|
55
|
+
const result = mergeABIs([{ name: 'Contract1', abi: [] }]);
|
|
56
|
+
expect(result.mergedABI).toHaveLength(0);
|
|
57
|
+
});
|
|
58
|
+
it('should handle errors', () => {
|
|
59
|
+
const abi = [
|
|
60
|
+
{
|
|
61
|
+
type: 'error',
|
|
62
|
+
name: 'InsufficientBalance',
|
|
63
|
+
inputs: [],
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
const result = mergeABIs([{ name: 'Contract1', abi: abi }]);
|
|
67
|
+
expect(result.mergedABI).toHaveLength(1);
|
|
68
|
+
expect(result.mergedABI[0].type).toBe('error');
|
|
69
|
+
expect(result.mergedABI[0].name).toBe('InsufficientBalance');
|
|
70
|
+
});
|
|
71
|
+
it('should skip constructors', () => {
|
|
72
|
+
const abi = [
|
|
73
|
+
{
|
|
74
|
+
type: 'constructor',
|
|
75
|
+
inputs: [],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
type: 'function',
|
|
79
|
+
name: 'foo',
|
|
80
|
+
inputs: [],
|
|
81
|
+
outputs: [],
|
|
82
|
+
stateMutability: 'nonpayable',
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
const result = mergeABIs([{ name: 'Contract1', abi: abi }]);
|
|
86
|
+
expect(result.mergedABI).toHaveLength(1);
|
|
87
|
+
expect(result.mergedABI[0].type).toBe('function');
|
|
88
|
+
});
|
|
89
|
+
it('should skip fallback and receive functions', () => {
|
|
90
|
+
const abi = [
|
|
91
|
+
{
|
|
92
|
+
type: 'fallback',
|
|
93
|
+
stateMutability: 'nonpayable',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
type: 'receive',
|
|
97
|
+
stateMutability: 'payable',
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
const result = mergeABIs([{ name: 'Contract1', abi: abi }]);
|
|
101
|
+
expect(result.mergedABI).toHaveLength(0);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe('duplicate handling', () => {
|
|
105
|
+
it('should deduplicate functions with same name but different signatures (first one wins)', () => {
|
|
106
|
+
const abi1 = [
|
|
107
|
+
{
|
|
108
|
+
type: 'function',
|
|
109
|
+
name: 'foo',
|
|
110
|
+
inputs: [],
|
|
111
|
+
outputs: [],
|
|
112
|
+
stateMutability: 'nonpayable',
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
const abi2 = [
|
|
116
|
+
{
|
|
117
|
+
type: 'function',
|
|
118
|
+
name: 'foo',
|
|
119
|
+
inputs: [{ type: 'uint256' }],
|
|
120
|
+
outputs: [],
|
|
121
|
+
stateMutability: 'nonpayable',
|
|
122
|
+
},
|
|
123
|
+
];
|
|
124
|
+
const result = mergeABIs([
|
|
125
|
+
{ name: 'Contract1', abi: abi1 },
|
|
126
|
+
{ name: 'Contract2', abi: abi2 },
|
|
127
|
+
]);
|
|
128
|
+
// Only one should be included since they have the same name
|
|
129
|
+
expect(result.mergedABI).toHaveLength(1);
|
|
130
|
+
expect(result.mergedABI[0].name).toBe('foo');
|
|
131
|
+
});
|
|
132
|
+
it('should include both functions when they have different names but same input types', () => {
|
|
133
|
+
const abi1 = [
|
|
134
|
+
{
|
|
135
|
+
type: 'function',
|
|
136
|
+
name: 'transfer',
|
|
137
|
+
inputs: [{ type: 'address' }, { type: 'uint256' }],
|
|
138
|
+
outputs: [],
|
|
139
|
+
stateMutability: 'nonpayable',
|
|
140
|
+
},
|
|
141
|
+
];
|
|
142
|
+
const abi2 = [
|
|
143
|
+
{
|
|
144
|
+
type: 'function',
|
|
145
|
+
name: 'transferTokens',
|
|
146
|
+
inputs: [{ type: 'address' }, { type: 'uint256' }],
|
|
147
|
+
outputs: [],
|
|
148
|
+
stateMutability: 'nonpayable',
|
|
149
|
+
},
|
|
150
|
+
];
|
|
151
|
+
const result = mergeABIs([
|
|
152
|
+
{ name: 'Contract1', abi: abi1 },
|
|
153
|
+
{ name: 'Contract2', abi: abi2 },
|
|
154
|
+
], { doNotCheckForConflicts: true });
|
|
155
|
+
// Both functions should be included since they have different names
|
|
156
|
+
expect(result.mergedABI).toHaveLength(2);
|
|
157
|
+
expect(result.mergedABI[0].name).toBe('transfer');
|
|
158
|
+
// Both functions should be included since they have different names (different selectors)
|
|
159
|
+
expect(result.mergedABI).toHaveLength(2);
|
|
160
|
+
expect(result.mergedABI[0].name).toBe('transfer');
|
|
161
|
+
expect(result.mergedABI[1].name).toBe('transferTokens');
|
|
162
|
+
});
|
|
163
|
+
it('should deduplicate events with same name', () => {
|
|
164
|
+
const abi1 = [
|
|
165
|
+
{
|
|
166
|
+
type: 'event',
|
|
167
|
+
name: 'Transfer',
|
|
168
|
+
inputs: [],
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
const abi2 = [
|
|
172
|
+
{
|
|
173
|
+
type: 'event',
|
|
174
|
+
name: 'Transfer',
|
|
175
|
+
inputs: [],
|
|
176
|
+
},
|
|
177
|
+
];
|
|
178
|
+
const result = mergeABIs([
|
|
179
|
+
{ name: 'Contract1', abi: abi1 },
|
|
180
|
+
{ name: 'Contract2', abi: abi2 },
|
|
181
|
+
]);
|
|
182
|
+
expect(result.mergedABI).toHaveLength(1);
|
|
183
|
+
expect(result.mergedABI[0].name).toBe('Transfer');
|
|
184
|
+
});
|
|
185
|
+
it('should deduplicate errors with same name', () => {
|
|
186
|
+
const abi1 = [
|
|
187
|
+
{
|
|
188
|
+
type: 'error',
|
|
189
|
+
name: 'InsufficientBalance',
|
|
190
|
+
inputs: [],
|
|
191
|
+
},
|
|
192
|
+
];
|
|
193
|
+
const abi2 = [
|
|
194
|
+
{
|
|
195
|
+
type: 'error',
|
|
196
|
+
name: 'InsufficientBalance',
|
|
197
|
+
inputs: [],
|
|
198
|
+
},
|
|
199
|
+
];
|
|
200
|
+
const result = mergeABIs([
|
|
201
|
+
{ name: 'Contract1', abi: abi1 },
|
|
202
|
+
{ name: 'Contract2', abi: abi2 },
|
|
203
|
+
]);
|
|
204
|
+
expect(result.mergedABI).toHaveLength(1);
|
|
205
|
+
expect(result.mergedABI[0].name).toBe('InsufficientBalance');
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
describe('return values', () => {
|
|
209
|
+
it('should return added map', () => {
|
|
210
|
+
const abi = [
|
|
211
|
+
{
|
|
212
|
+
type: 'function',
|
|
213
|
+
name: 'foo',
|
|
214
|
+
inputs: [],
|
|
215
|
+
outputs: [],
|
|
216
|
+
stateMutability: 'nonpayable',
|
|
217
|
+
},
|
|
218
|
+
];
|
|
219
|
+
const result = mergeABIs([{ name: 'Contract1', abi: abi }]);
|
|
220
|
+
expect(result.added.has('foo')).toBe(true);
|
|
221
|
+
expect(result.added.get('foo')).toEqual(abi[0]);
|
|
222
|
+
});
|
|
223
|
+
it('should return sigJSMap', () => {
|
|
224
|
+
const abi = [
|
|
225
|
+
{
|
|
226
|
+
type: 'function',
|
|
227
|
+
name: 'foo',
|
|
228
|
+
inputs: [],
|
|
229
|
+
outputs: [],
|
|
230
|
+
stateMutability: 'nonpayable',
|
|
231
|
+
},
|
|
232
|
+
];
|
|
233
|
+
const result = mergeABIs([{ name: 'Contract1', abi: abi }]);
|
|
234
|
+
expect(result.sigJSMap.size).toBe(1);
|
|
235
|
+
const selector = Array.from(result.sigJSMap.keys())[0];
|
|
236
|
+
const value = result.sigJSMap.get(selector);
|
|
237
|
+
expect(value.routeName).toBe('Contract1');
|
|
238
|
+
expect(value.functionName).toBe('foo');
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
describe('mixed ABI types', () => {
|
|
242
|
+
it('should handle mixed ABI with functions, events, and errors', () => {
|
|
243
|
+
const abi = [
|
|
244
|
+
{
|
|
245
|
+
type: 'function',
|
|
246
|
+
name: 'transfer',
|
|
247
|
+
inputs: [],
|
|
248
|
+
outputs: [],
|
|
249
|
+
stateMutability: 'nonpayable',
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
type: 'event',
|
|
253
|
+
name: 'Transfer',
|
|
254
|
+
inputs: [],
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
type: 'error',
|
|
258
|
+
name: 'InsufficientBalance',
|
|
259
|
+
inputs: [],
|
|
260
|
+
},
|
|
261
|
+
];
|
|
262
|
+
const result = mergeABIs([{ name: 'Contract1', abi: abi }]);
|
|
263
|
+
expect(result.mergedABI).toHaveLength(3);
|
|
264
|
+
expect(result.mergedABI[0].type).toBe('function');
|
|
265
|
+
expect(result.mergedABI[1].type).toBe('event');
|
|
266
|
+
expect(result.mergedABI[2].type).toBe('error');
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
describe('mergeArtifacts', () => {
|
|
271
|
+
describe('basic merging', () => {
|
|
272
|
+
it('should merge two artifacts', () => {
|
|
273
|
+
const artifact1 = {
|
|
274
|
+
abi: [
|
|
275
|
+
{
|
|
276
|
+
type: 'function',
|
|
277
|
+
name: 'foo',
|
|
278
|
+
inputs: [],
|
|
279
|
+
outputs: [],
|
|
280
|
+
stateMutability: 'nonpayable',
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
bytecode: '0x1234',
|
|
284
|
+
};
|
|
285
|
+
const artifact2 = {
|
|
286
|
+
abi: [
|
|
287
|
+
{
|
|
288
|
+
type: 'function',
|
|
289
|
+
name: 'bar',
|
|
290
|
+
inputs: [],
|
|
291
|
+
outputs: [],
|
|
292
|
+
stateMutability: 'nonpayable',
|
|
293
|
+
},
|
|
294
|
+
],
|
|
295
|
+
bytecode: '0x5678',
|
|
296
|
+
};
|
|
297
|
+
const result = mergeArtifacts([
|
|
298
|
+
{ name: 'Contract1', artifact: artifact1 },
|
|
299
|
+
{ name: 'Contract2', artifact: artifact2 },
|
|
300
|
+
]);
|
|
301
|
+
expect(result.mergedABI).toHaveLength(2);
|
|
302
|
+
expect(result.mergedABI[0].name).toBe('foo');
|
|
303
|
+
expect(result.mergedABI[1].name).toBe('bar');
|
|
304
|
+
});
|
|
305
|
+
it('should merge artifacts with empty documentation', () => {
|
|
306
|
+
const artifact1 = {
|
|
307
|
+
abi: [
|
|
308
|
+
{
|
|
309
|
+
type: 'function',
|
|
310
|
+
name: 'foo',
|
|
311
|
+
inputs: [],
|
|
312
|
+
outputs: [],
|
|
313
|
+
stateMutability: 'nonpayable',
|
|
314
|
+
},
|
|
315
|
+
],
|
|
316
|
+
bytecode: '0x1234',
|
|
317
|
+
};
|
|
318
|
+
const result = mergeArtifacts([{ name: 'Contract1', artifact: artifact1 }]);
|
|
319
|
+
expect(result.mergedABI).toHaveLength(1);
|
|
320
|
+
expect(result.mergedDevDocs).toBeDefined();
|
|
321
|
+
expect(result.mergedUserDocs).toBeDefined();
|
|
322
|
+
expect(result.mergedDevDocs.kind).toBe('dev');
|
|
323
|
+
expect(result.mergedDevDocs.version).toBe(1);
|
|
324
|
+
expect(result.mergedUserDocs.kind).toBe('user');
|
|
325
|
+
expect(result.mergedUserDocs.version).toBe(1);
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
describe('documentation merging', () => {
|
|
329
|
+
it('should merge devdoc from multiple artifacts', () => {
|
|
330
|
+
const artifact1 = {
|
|
331
|
+
abi: [
|
|
332
|
+
{
|
|
333
|
+
type: 'function',
|
|
334
|
+
name: 'foo',
|
|
335
|
+
inputs: [],
|
|
336
|
+
outputs: [],
|
|
337
|
+
stateMutability: 'nonpayable',
|
|
338
|
+
},
|
|
339
|
+
],
|
|
340
|
+
bytecode: '0x1234',
|
|
341
|
+
devdoc: {
|
|
342
|
+
kind: 'dev',
|
|
343
|
+
version: 1,
|
|
344
|
+
author: 'Alice',
|
|
345
|
+
title: 'Shared Title',
|
|
346
|
+
methods: {
|
|
347
|
+
'foo()': { details: 'Foo method' },
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
const artifact2 = {
|
|
352
|
+
abi: [
|
|
353
|
+
{
|
|
354
|
+
type: 'function',
|
|
355
|
+
name: 'bar',
|
|
356
|
+
inputs: [],
|
|
357
|
+
outputs: [],
|
|
358
|
+
stateMutability: 'nonpayable',
|
|
359
|
+
},
|
|
360
|
+
],
|
|
361
|
+
bytecode: '0x5678',
|
|
362
|
+
devdoc: {
|
|
363
|
+
kind: 'dev',
|
|
364
|
+
version: 1,
|
|
365
|
+
author: 'Alice',
|
|
366
|
+
title: 'Shared Title',
|
|
367
|
+
methods: {
|
|
368
|
+
'bar()': { details: 'Bar method' },
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
};
|
|
372
|
+
const result = mergeArtifacts([
|
|
373
|
+
{ name: 'Contract1', artifact: artifact1 },
|
|
374
|
+
{ name: 'Contract2', artifact: artifact2 },
|
|
375
|
+
]);
|
|
376
|
+
expect(result.mergedDevDocs.methods['foo()']).toEqual({ details: 'Foo method' });
|
|
377
|
+
expect(result.mergedDevDocs.methods['bar()']).toEqual({ details: 'Bar method' });
|
|
378
|
+
// Author from second artifact should be kept (or from first if it matches)
|
|
379
|
+
expect(result.mergedDevDocs.author).toBeDefined();
|
|
380
|
+
});
|
|
381
|
+
it('should merge userdoc from multiple artifacts', () => {
|
|
382
|
+
const artifact1 = {
|
|
383
|
+
abi: [
|
|
384
|
+
{
|
|
385
|
+
type: 'function',
|
|
386
|
+
name: 'foo',
|
|
387
|
+
inputs: [],
|
|
388
|
+
outputs: [],
|
|
389
|
+
stateMutability: 'nonpayable',
|
|
390
|
+
},
|
|
391
|
+
],
|
|
392
|
+
bytecode: '0x1234',
|
|
393
|
+
userdoc: {
|
|
394
|
+
kind: 'user',
|
|
395
|
+
version: 1,
|
|
396
|
+
notice: 'Shared User Notice',
|
|
397
|
+
methods: {
|
|
398
|
+
'foo()': { notice: 'Foo notice' },
|
|
399
|
+
},
|
|
400
|
+
},
|
|
401
|
+
};
|
|
402
|
+
const artifact2 = {
|
|
403
|
+
abi: [
|
|
404
|
+
{
|
|
405
|
+
type: 'function',
|
|
406
|
+
name: 'bar',
|
|
407
|
+
inputs: [],
|
|
408
|
+
outputs: [],
|
|
409
|
+
stateMutability: 'nonpayable',
|
|
410
|
+
},
|
|
411
|
+
],
|
|
412
|
+
bytecode: '0x5678',
|
|
413
|
+
userdoc: {
|
|
414
|
+
kind: 'user',
|
|
415
|
+
version: 1,
|
|
416
|
+
notice: 'Shared User Notice',
|
|
417
|
+
methods: {
|
|
418
|
+
'bar()': { notice: 'Bar notice' },
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
};
|
|
422
|
+
const result = mergeArtifacts([
|
|
423
|
+
{ name: 'Contract1', artifact: artifact1 },
|
|
424
|
+
{ name: 'Contract2', artifact: artifact2 },
|
|
425
|
+
]);
|
|
426
|
+
expect(result.mergedUserDocs.methods['foo()']).toEqual({ notice: 'Foo notice' });
|
|
427
|
+
expect(result.mergedUserDocs.methods['bar()']).toEqual({ notice: 'Bar notice' });
|
|
428
|
+
expect(result.mergedUserDocs.notice).toBe('Shared User Notice');
|
|
429
|
+
});
|
|
430
|
+
it('should merge devdoc events', () => {
|
|
431
|
+
const artifact1 = {
|
|
432
|
+
abi: [
|
|
433
|
+
{
|
|
434
|
+
type: 'event',
|
|
435
|
+
name: 'Transfer',
|
|
436
|
+
inputs: [],
|
|
437
|
+
},
|
|
438
|
+
],
|
|
439
|
+
bytecode: '0x1234',
|
|
440
|
+
devdoc: {
|
|
441
|
+
kind: 'dev',
|
|
442
|
+
version: 1,
|
|
443
|
+
events: {
|
|
444
|
+
'Transfer(address,address,uint256)': { details: 'Transfer event' },
|
|
445
|
+
},
|
|
446
|
+
},
|
|
447
|
+
};
|
|
448
|
+
const result = mergeArtifacts([{ name: 'Contract1', artifact: artifact1 }]);
|
|
449
|
+
expect(result.mergedDevDocs.events?.['Transfer(address,address,uint256)']).toEqual({
|
|
450
|
+
details: 'Transfer event',
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
it('should merge devdoc errors', () => {
|
|
454
|
+
const artifact1 = {
|
|
455
|
+
abi: [
|
|
456
|
+
{
|
|
457
|
+
type: 'error',
|
|
458
|
+
name: 'InsufficientBalance',
|
|
459
|
+
inputs: [],
|
|
460
|
+
},
|
|
461
|
+
],
|
|
462
|
+
bytecode: '0x1234',
|
|
463
|
+
devdoc: {
|
|
464
|
+
kind: 'dev',
|
|
465
|
+
version: 1,
|
|
466
|
+
errors: {
|
|
467
|
+
'InsufficientBalance(uint256)': { details: 'Insufficient balance error' },
|
|
468
|
+
},
|
|
469
|
+
},
|
|
470
|
+
};
|
|
471
|
+
const result = mergeArtifacts([{ name: 'Contract1', artifact: artifact1 }]);
|
|
472
|
+
expect(result.mergedDevDocs.errors?.['InsufficientBalance(uint256)']).toEqual({
|
|
473
|
+
details: 'Insufficient balance error',
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
it('should throw error for devdoc method conflicts', () => {
|
|
477
|
+
const artifact1 = {
|
|
478
|
+
abi: [
|
|
479
|
+
{
|
|
480
|
+
type: 'function',
|
|
481
|
+
name: 'foo',
|
|
482
|
+
inputs: [],
|
|
483
|
+
outputs: [],
|
|
484
|
+
stateMutability: 'nonpayable',
|
|
485
|
+
},
|
|
486
|
+
],
|
|
487
|
+
bytecode: '0x1234',
|
|
488
|
+
devdoc: {
|
|
489
|
+
kind: 'dev',
|
|
490
|
+
version: 1,
|
|
491
|
+
methods: {
|
|
492
|
+
'foo()': { details: 'Foo method 1' },
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
};
|
|
496
|
+
const artifact2 = {
|
|
497
|
+
abi: [],
|
|
498
|
+
bytecode: '0x5678',
|
|
499
|
+
devdoc: {
|
|
500
|
+
kind: 'dev',
|
|
501
|
+
version: 1,
|
|
502
|
+
methods: {
|
|
503
|
+
'foo()': { details: 'Foo method 2' },
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
};
|
|
507
|
+
expect(() => mergeArtifacts([
|
|
508
|
+
{ name: 'Contract1', artifact: artifact1 },
|
|
509
|
+
{ name: 'Contract2', artifact: artifact2 },
|
|
510
|
+
])).toThrow(/Doc.*conflict/);
|
|
511
|
+
});
|
|
512
|
+
it('should throw error for devdoc author conflict', () => {
|
|
513
|
+
const artifact1 = {
|
|
514
|
+
abi: [],
|
|
515
|
+
bytecode: '0x1234',
|
|
516
|
+
devdoc: {
|
|
517
|
+
kind: 'dev',
|
|
518
|
+
version: 1,
|
|
519
|
+
author: 'Alice',
|
|
520
|
+
},
|
|
521
|
+
};
|
|
522
|
+
const artifact2 = {
|
|
523
|
+
abi: [],
|
|
524
|
+
bytecode: '0x5678',
|
|
525
|
+
devdoc: {
|
|
526
|
+
kind: 'dev',
|
|
527
|
+
version: 1,
|
|
528
|
+
author: 'Bob',
|
|
529
|
+
},
|
|
530
|
+
};
|
|
531
|
+
expect(() => mergeArtifacts([
|
|
532
|
+
{ name: 'Contract1', artifact: artifact1 },
|
|
533
|
+
{ name: 'Contract2', artifact: artifact2 },
|
|
534
|
+
])).toThrow(/DevDoc author conflict/);
|
|
535
|
+
});
|
|
536
|
+
it('should throw error for devdoc title conflict', () => {
|
|
537
|
+
const artifact1 = {
|
|
538
|
+
abi: [],
|
|
539
|
+
bytecode: '0x1234',
|
|
540
|
+
devdoc: {
|
|
541
|
+
kind: 'dev',
|
|
542
|
+
version: 1,
|
|
543
|
+
author: 'Alice',
|
|
544
|
+
title: 'Title 1',
|
|
545
|
+
},
|
|
546
|
+
};
|
|
547
|
+
const artifact2 = {
|
|
548
|
+
abi: [],
|
|
549
|
+
bytecode: '0x5678',
|
|
550
|
+
devdoc: {
|
|
551
|
+
kind: 'dev',
|
|
552
|
+
version: 1,
|
|
553
|
+
author: 'Alice',
|
|
554
|
+
title: 'Title 2',
|
|
555
|
+
},
|
|
556
|
+
};
|
|
557
|
+
expect(() => mergeArtifacts([
|
|
558
|
+
{ name: 'Contract1', artifact: artifact1 },
|
|
559
|
+
{ name: 'Contract2', artifact: artifact2 },
|
|
560
|
+
])).toThrow(/DevDoc title conflict/);
|
|
561
|
+
});
|
|
562
|
+
it('should throw error for userdoc notice conflict', () => {
|
|
563
|
+
const artifact1 = {
|
|
564
|
+
abi: [],
|
|
565
|
+
bytecode: '0x1234',
|
|
566
|
+
userdoc: {
|
|
567
|
+
kind: 'user',
|
|
568
|
+
version: 1,
|
|
569
|
+
notice: 'Notice 1',
|
|
570
|
+
},
|
|
571
|
+
};
|
|
572
|
+
const artifact2 = {
|
|
573
|
+
abi: [],
|
|
574
|
+
bytecode: '0x5678',
|
|
575
|
+
userdoc: {
|
|
576
|
+
kind: 'user',
|
|
577
|
+
version: 1,
|
|
578
|
+
notice: 'Notice 2',
|
|
579
|
+
},
|
|
580
|
+
};
|
|
581
|
+
expect(() => mergeArtifacts([
|
|
582
|
+
{ name: 'Contract1', artifact: artifact1 },
|
|
583
|
+
{ name: 'Contract2', artifact: artifact2 },
|
|
584
|
+
])).toThrow(/UserDoc notice conflict/);
|
|
585
|
+
});
|
|
586
|
+
it('should merge same devdoc without error', () => {
|
|
587
|
+
const devdoc = {
|
|
588
|
+
kind: 'dev',
|
|
589
|
+
version: 1,
|
|
590
|
+
author: 'Alice',
|
|
591
|
+
title: 'Shared Title',
|
|
592
|
+
methods: {
|
|
593
|
+
'foo()': { details: 'Same details' },
|
|
594
|
+
},
|
|
595
|
+
};
|
|
596
|
+
const artifact1 = {
|
|
597
|
+
abi: [
|
|
598
|
+
{
|
|
599
|
+
type: 'function',
|
|
600
|
+
name: 'foo',
|
|
601
|
+
inputs: [],
|
|
602
|
+
outputs: [],
|
|
603
|
+
stateMutability: 'nonpayable',
|
|
604
|
+
},
|
|
605
|
+
],
|
|
606
|
+
bytecode: '0x1234',
|
|
607
|
+
devdoc: devdoc,
|
|
608
|
+
};
|
|
609
|
+
const artifact2 = {
|
|
610
|
+
abi: [],
|
|
611
|
+
bytecode: '0x5678',
|
|
612
|
+
devdoc: devdoc,
|
|
613
|
+
};
|
|
614
|
+
const result = mergeArtifacts([
|
|
615
|
+
{ name: 'Contract1', artifact: artifact1 },
|
|
616
|
+
{ name: 'Contract2', artifact: artifact2 },
|
|
617
|
+
]);
|
|
618
|
+
expect(result.mergedDevDocs.author).toBe('Alice');
|
|
619
|
+
expect(result.mergedDevDocs.title).toBe('Shared Title');
|
|
620
|
+
});
|
|
621
|
+
});
|
|
622
|
+
describe('return values', () => {
|
|
623
|
+
it('should return all expected properties', () => {
|
|
624
|
+
const artifact = {
|
|
625
|
+
abi: [
|
|
626
|
+
{
|
|
627
|
+
type: 'function',
|
|
628
|
+
name: 'foo',
|
|
629
|
+
inputs: [],
|
|
630
|
+
outputs: [],
|
|
631
|
+
stateMutability: 'nonpayable',
|
|
632
|
+
},
|
|
633
|
+
],
|
|
634
|
+
bytecode: '0x1234',
|
|
635
|
+
};
|
|
636
|
+
const result = mergeArtifacts([{ name: 'Contract1', artifact: artifact }]);
|
|
637
|
+
expect(result.mergedABI).toBeDefined();
|
|
638
|
+
expect(result.added).toBeDefined();
|
|
639
|
+
expect(result.mergedDevDocs).toBeDefined();
|
|
640
|
+
expect(result.mergedUserDocs).toBeDefined();
|
|
641
|
+
expect(result.sigJSMap).toBeDefined();
|
|
642
|
+
});
|
|
643
|
+
});
|
|
644
|
+
describe('with conflict checking disabled', () => {
|
|
645
|
+
it('should merge artifacts with conflict checking disabled', () => {
|
|
646
|
+
const artifact1 = {
|
|
647
|
+
abi: [
|
|
648
|
+
{
|
|
649
|
+
type: 'function',
|
|
650
|
+
name: 'transfer',
|
|
651
|
+
inputs: [{ type: 'address' }, { type: 'uint256' }],
|
|
652
|
+
outputs: [],
|
|
653
|
+
stateMutability: 'nonpayable',
|
|
654
|
+
},
|
|
655
|
+
],
|
|
656
|
+
bytecode: '0x1234',
|
|
657
|
+
};
|
|
658
|
+
const artifact2 = {
|
|
659
|
+
abi: [
|
|
660
|
+
{
|
|
661
|
+
type: 'function',
|
|
662
|
+
name: 'transferTokens',
|
|
663
|
+
inputs: [{ type: 'address' }, { type: 'uint256' }],
|
|
664
|
+
outputs: [],
|
|
665
|
+
stateMutability: 'nonpayable',
|
|
666
|
+
},
|
|
667
|
+
],
|
|
668
|
+
bytecode: '0x5678',
|
|
669
|
+
};
|
|
670
|
+
const result = mergeArtifacts([
|
|
671
|
+
{ name: 'Contract1', artifact: artifact1 },
|
|
672
|
+
{ name: 'Contract2', artifact: artifact2 },
|
|
673
|
+
], { doNotCheckForConflicts: true });
|
|
674
|
+
// Both should be included since they have different names
|
|
675
|
+
expect(result.mergedABI).toHaveLength(2);
|
|
676
|
+
expect(result.mergedABI[0].name).toBe('transfer');
|
|
677
|
+
expect(result.mergedABI[1].name).toBe('transferTokens');
|
|
678
|
+
});
|
|
679
|
+
});
|
|
680
|
+
});
|
|
681
|
+
});
|
|
682
|
+
//# sourceMappingURL=artifacts.test.js.map
|