@rosen-bridge/utils 1.0.0 → 2.0.1
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/downloadRosenAssets.js +1 -1
- package/dist/downloadTssBinary.js +1 -1
- package/dist/utils/github.d.ts.map +1 -1
- package/dist/utils/github.js +1 -1
- package/dist/utils/rosen.js +1 -1
- package/package.json +19 -11
- package/.eslintignore +0 -1
- package/babel.config.json +0 -3
- package/jest.config.json +0 -7
- package/lib/constants.ts +0 -2
- package/lib/downloadRosenAssets.ts +0 -72
- package/lib/downloadTssBinary.ts +0 -61
- package/lib/error.ts +0 -3
- package/lib/index.ts +0 -4
- package/lib/types/index.ts +0 -13
- package/lib/utils/github.ts +0 -169
- package/lib/utils/rosen.ts +0 -34
- package/tests/data/octokit.data.ts +0 -210
- package/tests/downloadRosenAssets.spec.ts +0 -200
- package/tests/downloadTssBinary.spec.ts +0 -153
- package/tests/mocks/octokit.mock.ts +0 -41
- package/tests/setup.ts +0 -1
- package/tests/utils/github.spec.ts +0 -409
- package/tests/utils/rosen.spec.ts +0 -197
- package/tsconfig.build.json +0 -8
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -8
|
@@ -1,409 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fetchReleasesPage,
|
|
3
|
-
findLatestRelease,
|
|
4
|
-
hasAssetForChainType,
|
|
5
|
-
findLastRelease,
|
|
6
|
-
isStableReleaseForChainType,
|
|
7
|
-
isStableReleaseForRegexTagType,
|
|
8
|
-
findLatestStableRelease,
|
|
9
|
-
getReleaseByTag,
|
|
10
|
-
hasMatchedTagPrefix,
|
|
11
|
-
findLatestStableReleaseByPrefixTag,
|
|
12
|
-
findLatestReleaseByPrefixTag,
|
|
13
|
-
} from '../../lib/utils/github';
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
mainNetPrereleaseRelease,
|
|
17
|
-
mainNetStableRelease,
|
|
18
|
-
contractReleases,
|
|
19
|
-
testNetPrereleaseRelease,
|
|
20
|
-
testNetStableRelease,
|
|
21
|
-
tssTag2,
|
|
22
|
-
tssTag3PreRelease,
|
|
23
|
-
tssTag1,
|
|
24
|
-
tssReleases,
|
|
25
|
-
} from '../data/octokit.data';
|
|
26
|
-
|
|
27
|
-
import { mockOctokit, mockOctokitGetReleaseByTag } from '../mocks/octokit.mock';
|
|
28
|
-
|
|
29
|
-
describe('fetchReleasesPage', () => {
|
|
30
|
-
/**
|
|
31
|
-
* @target `fetchReleasesPage` should generate contractReleases correctly
|
|
32
|
-
* @dependencies
|
|
33
|
-
* - mocked Octokit
|
|
34
|
-
* @scenario
|
|
35
|
-
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
36
|
-
* - create an iterator by calling `fetchReleasesPage` generator function
|
|
37
|
-
* - get results by consuming iterator
|
|
38
|
-
* @expected
|
|
39
|
-
* - first result value should have length of 5
|
|
40
|
-
* - second result value should have length of 4
|
|
41
|
-
* - third result value should be undefined
|
|
42
|
-
* - third result done property should be true
|
|
43
|
-
*/
|
|
44
|
-
it('should generate releases correctly', async () => {
|
|
45
|
-
mockOctokit(contractReleases);
|
|
46
|
-
|
|
47
|
-
const iterator = fetchReleasesPage('contract');
|
|
48
|
-
|
|
49
|
-
expect((await iterator.next()).value).toHaveLength(5);
|
|
50
|
-
expect((await iterator.next()).value).toHaveLength(4);
|
|
51
|
-
expect((await iterator.next()).value).toEqual(undefined);
|
|
52
|
-
expect((await iterator.next()).done).toEqual(true);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('findLastRelease', () => {
|
|
57
|
-
beforeEach(() => {
|
|
58
|
-
mockOctokit(contractReleases);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* @target `findLastRelease` should find last release correctly
|
|
63
|
-
* @dependencies
|
|
64
|
-
* - mocked Octokit
|
|
65
|
-
* @scenario
|
|
66
|
-
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
67
|
-
* - get result by calling `findLastRelease` with a predicate
|
|
68
|
-
* @expected
|
|
69
|
-
* - result id should equal mainnet stable release id
|
|
70
|
-
*/
|
|
71
|
-
it('should find last release correctly when a predicate is provided', async () => {
|
|
72
|
-
const foundRelease = await findLastRelease(
|
|
73
|
-
'contract',
|
|
74
|
-
(release) => release.id === mainNetStableRelease.id
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
expect(foundRelease?.id).toEqual(mainNetStableRelease.id);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* @target `findLastRelease` should return last release when no predicate is
|
|
82
|
-
* provided
|
|
83
|
-
* @dependencies
|
|
84
|
-
* - mocked Octokit
|
|
85
|
-
* @scenario
|
|
86
|
-
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
87
|
-
* - get result by calling `findLastRelease` without a predicate
|
|
88
|
-
* @expected
|
|
89
|
-
* - result id should equal the last release id
|
|
90
|
-
*/
|
|
91
|
-
it('should return last release when no predicate is provided', async () => {
|
|
92
|
-
const foundRelease = await findLastRelease('contract');
|
|
93
|
-
|
|
94
|
-
expect(foundRelease?.id).toEqual(contractReleases[0].id);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @target `findLastRelease` should return null when no matching release is
|
|
99
|
-
* found
|
|
100
|
-
* @dependencies
|
|
101
|
-
* - mocked Octokit
|
|
102
|
-
* @scenario
|
|
103
|
-
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
104
|
-
* - get result by calling `findLastRelease` with a predicate which does not
|
|
105
|
-
* match any release
|
|
106
|
-
* @expected
|
|
107
|
-
* - result should be null
|
|
108
|
-
*/
|
|
109
|
-
it('should return null when no matching release is found', async () => {
|
|
110
|
-
const foundRelease = await findLastRelease(
|
|
111
|
-
'contract',
|
|
112
|
-
(release) => release.id === 100
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
expect(foundRelease).toEqual(null);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe('getReleaseByTag', () => {
|
|
120
|
-
/**
|
|
121
|
-
* @target `getReleaseByTag` should get release by tag
|
|
122
|
-
* @dependencies
|
|
123
|
-
* - mocked `getReleaseByTag` of Octokit
|
|
124
|
-
* @scenario
|
|
125
|
-
* - call the function
|
|
126
|
-
* @expected
|
|
127
|
-
* - the release should be the expected one
|
|
128
|
-
*/
|
|
129
|
-
it('should get release by tag', async () => {
|
|
130
|
-
mockOctokitGetReleaseByTag(contractReleases);
|
|
131
|
-
|
|
132
|
-
const release = await getReleaseByTag('contract', '2.0.1-0b08045');
|
|
133
|
-
|
|
134
|
-
expect(release.id).toEqual(3);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe('hasAssetForChainType', () => {
|
|
139
|
-
/**
|
|
140
|
-
* @target `hasAssetForChainType` should return `true` if a release has asset
|
|
141
|
-
* for a specific chain type
|
|
142
|
-
* @dependencies
|
|
143
|
-
* @scenario
|
|
144
|
-
* - get result by calling `hasAssetForChainType('mainnet')` with a mainnet
|
|
145
|
-
* release
|
|
146
|
-
* @expected
|
|
147
|
-
* - result should be true
|
|
148
|
-
*/
|
|
149
|
-
it('should return `true` if a release has asset for a specific chain type', () => {
|
|
150
|
-
const hasAssetForMainNet = hasAssetForChainType('mainnet')(
|
|
151
|
-
mainNetPrereleaseRelease as any
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
expect(hasAssetForMainNet).toEqual(true);
|
|
155
|
-
});
|
|
156
|
-
/**
|
|
157
|
-
* @target `hasAssetForChainType` should return `false` if a release does not
|
|
158
|
-
* have asset for a specific chain type
|
|
159
|
-
* @dependencies
|
|
160
|
-
* @scenario
|
|
161
|
-
* - get result by calling `hasAssetForChainType('mainnet')` with a mainnet
|
|
162
|
-
* release
|
|
163
|
-
* @expected
|
|
164
|
-
* - result should be false
|
|
165
|
-
*/
|
|
166
|
-
it('should return `false` if a release does not have asset for a specific chain type', () => {
|
|
167
|
-
const hasAssetForMainNet = hasAssetForChainType('mainnet')(
|
|
168
|
-
testNetPrereleaseRelease as any
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
expect(hasAssetForMainNet).toEqual(false);
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
describe('isStableReleaseForChainType', () => {
|
|
176
|
-
/**
|
|
177
|
-
* @target `isStableReleaseForChainType`
|
|
178
|
-
* @dependencies
|
|
179
|
-
* @scenario
|
|
180
|
-
* - get result by calling `isStableReleaseForChainType('mainnet')` with a
|
|
181
|
-
* mainnet stable release
|
|
182
|
-
* @expected
|
|
183
|
-
* - result should be true
|
|
184
|
-
*/
|
|
185
|
-
it('should return `true` if a release is stable (that is, non-prerelease) and has asset for a specific chain type', () => {
|
|
186
|
-
const isMatchingRelease = isStableReleaseForChainType('mainnet')(
|
|
187
|
-
mainNetStableRelease as any
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
expect(isMatchingRelease).toEqual(true);
|
|
191
|
-
});
|
|
192
|
-
/**
|
|
193
|
-
* @target `isStableReleaseForChainType` should return `false` if a release
|
|
194
|
-
* has asset for a specific chain type but is prerelease
|
|
195
|
-
* @dependencies
|
|
196
|
-
* @scenario
|
|
197
|
-
* - get result by calling `isStableReleaseForChainType('mainnet')` with a
|
|
198
|
-
* mainnet prerelease release
|
|
199
|
-
* @expected
|
|
200
|
-
* - result should be false
|
|
201
|
-
*/
|
|
202
|
-
it('should return `false` if a release has asset for a specific chain type but is prerelease', () => {
|
|
203
|
-
const isMatchingRelease = isStableReleaseForChainType('mainnet')(
|
|
204
|
-
mainNetPrereleaseRelease as any
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
expect(isMatchingRelease).toEqual(false);
|
|
208
|
-
});
|
|
209
|
-
/**
|
|
210
|
-
* @target `isStableReleaseForChainType` should return `false` if a release is
|
|
211
|
-
* stable (that is, non-prerelease) but does not have asset for a specific
|
|
212
|
-
* chain type
|
|
213
|
-
* @dependencies
|
|
214
|
-
* @scenario
|
|
215
|
-
* - get result by calling `isStableReleaseForChainType('mainnet')` with a
|
|
216
|
-
* testnet stable release
|
|
217
|
-
* @expected
|
|
218
|
-
* - result should be false
|
|
219
|
-
*/
|
|
220
|
-
it('should return `false` if a release is stable (that is, non-prerelease) but does not have asset for a specific chain type', () => {
|
|
221
|
-
const isMatchingRelease = isStableReleaseForChainType('mainnet')(
|
|
222
|
-
testNetStableRelease as any
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
expect(isMatchingRelease).toEqual(false);
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
describe('hasMatchedTagPrefix', () => {
|
|
230
|
-
/**
|
|
231
|
-
* @target `hasMatchedTagPrefix` should return `true` if a release
|
|
232
|
-
* has asset using a prefix tag
|
|
233
|
-
* @dependencies
|
|
234
|
-
* @scenario
|
|
235
|
-
* - get a result by calling `hasMatchedTagPrefix('tss-api-')` with a
|
|
236
|
-
* tss-api prerelease release
|
|
237
|
-
* @expected
|
|
238
|
-
* - result should be true
|
|
239
|
-
*/
|
|
240
|
-
it('should return `true` if a release has asset using a prefix tag', () => {
|
|
241
|
-
const isMatchingRelease = hasMatchedTagPrefix('tss-api-')(
|
|
242
|
-
tssTag3PreRelease as any
|
|
243
|
-
);
|
|
244
|
-
|
|
245
|
-
expect(isMatchingRelease).toEqual(true);
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* @target `hasMatchedTagPrefix` should return `false`,
|
|
250
|
-
* if doesn't exist matched tag prefix
|
|
251
|
-
* @dependencies
|
|
252
|
-
* @scenario
|
|
253
|
-
* - get result by calling `hasMatchedTagPrefix('no-tag')` with a
|
|
254
|
-
* tss-api stable release
|
|
255
|
-
* @expected
|
|
256
|
-
* - result should be false
|
|
257
|
-
*/
|
|
258
|
-
it("should return `false` if doesn't exist matched tag prefix", () => {
|
|
259
|
-
const isMatchingRelease = hasMatchedTagPrefix('no-tag')(tssTag1 as any);
|
|
260
|
-
|
|
261
|
-
expect(isMatchingRelease).toEqual(false);
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
describe('isStableReleaseForRegexTagType', () => {
|
|
266
|
-
/**
|
|
267
|
-
* @target `isStableReleaseForRegexTagType` should return `true` if a release
|
|
268
|
-
* is stable and has asset using a prefix tag
|
|
269
|
-
* @dependencies
|
|
270
|
-
* @scenario
|
|
271
|
-
* - get result by calling `isStableReleaseForRegexTagType('tss-api-')` with a
|
|
272
|
-
* tss-api stable release
|
|
273
|
-
* @expected
|
|
274
|
-
* - result should be true
|
|
275
|
-
*/
|
|
276
|
-
it('should return `true` if a release is stable and has asset using a prefix tag', () => {
|
|
277
|
-
const isMatchingRelease = isStableReleaseForRegexTagType('tss-api-')(
|
|
278
|
-
tssTag2 as any
|
|
279
|
-
);
|
|
280
|
-
|
|
281
|
-
expect(isMatchingRelease).toEqual(true);
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* @target `isStableReleaseForRegexTagType` should return `false` if a release
|
|
286
|
-
* has asset for a prefix tag but is prerelease
|
|
287
|
-
* @dependencies
|
|
288
|
-
* @scenario
|
|
289
|
-
* - get result by calling `isStableReleaseForRegexTagType('tss-api')` with a
|
|
290
|
-
* tss-api prerelease release
|
|
291
|
-
* @expected
|
|
292
|
-
* - result should be false
|
|
293
|
-
*/
|
|
294
|
-
it('should return `false` if a release has asset for a prefix tag but is prerelease', () => {
|
|
295
|
-
const isMatchingRelease = isStableReleaseForRegexTagType('tss-api')(
|
|
296
|
-
tssTag3PreRelease as any
|
|
297
|
-
);
|
|
298
|
-
|
|
299
|
-
expect(isMatchingRelease).toEqual(false);
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* @target `isStableReleaseForRegexTagType` should return `false` if a release is
|
|
304
|
-
* stable but does not have a release with prefix tag
|
|
305
|
-
* @dependencies
|
|
306
|
-
* @scenario
|
|
307
|
-
* - get result by calling `isStableReleaseForRegexTagType('no-tag')` with a
|
|
308
|
-
* tss stable release tag
|
|
309
|
-
* @expected
|
|
310
|
-
* - result should be false
|
|
311
|
-
*/
|
|
312
|
-
it('should return `false` if a release is stable but does not have prefix tag', () => {
|
|
313
|
-
const isMatchingRelease = isStableReleaseForRegexTagType('no-tag')(
|
|
314
|
-
tssTag1 as any
|
|
315
|
-
);
|
|
316
|
-
|
|
317
|
-
expect(isMatchingRelease).toEqual(false);
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
describe('findLatestRelease', () => {
|
|
322
|
-
/**
|
|
323
|
-
* @target `findLatestRelease` should find latest release for a chain type
|
|
324
|
-
* correctly
|
|
325
|
-
* @dependencies
|
|
326
|
-
* - mocked Octokit
|
|
327
|
-
* @scenario
|
|
328
|
-
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
329
|
-
* - get result by calling `findLatestRelease` with mainnet chain type
|
|
330
|
-
* @expected
|
|
331
|
-
* - result id should equal mainnet prerelease release id
|
|
332
|
-
*/
|
|
333
|
-
it('should find latest release for a chain type correctly', async () => {
|
|
334
|
-
mockOctokit(contractReleases);
|
|
335
|
-
|
|
336
|
-
const latestMainNet = await findLatestRelease('contract', 'mainnet');
|
|
337
|
-
|
|
338
|
-
expect(latestMainNet?.id).toEqual(mainNetPrereleaseRelease.id);
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
describe('findLatestStableRelease', () => {
|
|
343
|
-
/**
|
|
344
|
-
* @target `findLatestStableRelease` should find latest stable (that is,
|
|
345
|
-
* non-prerelease) release for a chain type correctly
|
|
346
|
-
* @dependencies
|
|
347
|
-
* - mocked Octokit
|
|
348
|
-
* @scenario
|
|
349
|
-
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
350
|
-
* - get result by calling `findLatestStableRelease` with mainnet chain type
|
|
351
|
-
* @expected
|
|
352
|
-
* - result id should equal mainnet stable release id
|
|
353
|
-
*/
|
|
354
|
-
it('should find latest stable (that is, non-prerelease) release for a chain type correctly', async () => {
|
|
355
|
-
mockOctokit(contractReleases);
|
|
356
|
-
|
|
357
|
-
const latestMainNet = await findLatestStableRelease('contract', 'mainnet');
|
|
358
|
-
|
|
359
|
-
expect(latestMainNet?.id).toEqual(mainNetStableRelease.id);
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
describe('findLatestReleaseByPrefixTag', () => {
|
|
364
|
-
/**
|
|
365
|
-
* @target `findLatestReleaseByPrefixTag` should find latest release with
|
|
366
|
-
* a prefix tag correctly
|
|
367
|
-
* @dependencies
|
|
368
|
-
* - mocked Octokit
|
|
369
|
-
* @scenario
|
|
370
|
-
* - mock Octokit `listReleases` to return tssReleases
|
|
371
|
-
* - get result by calling `findLatestReleaseByPrefixTag` with tss-api prefix tag
|
|
372
|
-
* @expected
|
|
373
|
-
* - result id should equal tssTag3PreRelease release id
|
|
374
|
-
*/
|
|
375
|
-
it('should find latest release for tss-api prefix tag correctly', async () => {
|
|
376
|
-
mockOctokit(tssReleases);
|
|
377
|
-
|
|
378
|
-
const latestTss = await findLatestReleaseByPrefixTag(
|
|
379
|
-
'sign-protocols',
|
|
380
|
-
'tss-api'
|
|
381
|
-
);
|
|
382
|
-
|
|
383
|
-
expect(latestTss?.id).toEqual(tssTag3PreRelease.id);
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
describe('findLatestStableReleaseByPrefixTag', () => {
|
|
388
|
-
/**
|
|
389
|
-
* @target `findLatestStableReleaseByPrefixTag` should find latest stable (that is,
|
|
390
|
-
* non-prerelease) release with a prefix tag
|
|
391
|
-
* @dependencies
|
|
392
|
-
* - mocked Octokit
|
|
393
|
-
* @scenario
|
|
394
|
-
* - mock Octokit `listReleases` to return tssReleases
|
|
395
|
-
* - get result by calling `findLatestStableReleaseByPrefixTag` with tss-api prefix tag
|
|
396
|
-
* @expected
|
|
397
|
-
* - result id should equal tssTag2 stable release id
|
|
398
|
-
*/
|
|
399
|
-
it('should find latest stable (that is, non-prerelease) release for tss-api prefix tag correctly', async () => {
|
|
400
|
-
mockOctokit(tssReleases);
|
|
401
|
-
|
|
402
|
-
const latestTss = await findLatestStableReleaseByPrefixTag(
|
|
403
|
-
'sign-protocols',
|
|
404
|
-
'tss-api'
|
|
405
|
-
);
|
|
406
|
-
|
|
407
|
-
expect(latestTss?.id).toEqual(tssTag2.id);
|
|
408
|
-
});
|
|
409
|
-
});
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isValidAssetName,
|
|
3
|
-
isValidOS,
|
|
4
|
-
truncateAssetName,
|
|
5
|
-
} from '../../lib/utils/rosen';
|
|
6
|
-
|
|
7
|
-
describe('isValidAssetName', () => {
|
|
8
|
-
/**
|
|
9
|
-
* @target
|
|
10
|
-
* `isValidAssetName` should return `true` if an address file name matches a
|
|
11
|
-
* chain type
|
|
12
|
-
* @dependencies
|
|
13
|
-
* @scenario
|
|
14
|
-
* - get result by calling `isValidAssetName('mainnet')` with a mainnet
|
|
15
|
-
* address file name
|
|
16
|
-
* @expected
|
|
17
|
-
* - result should be true
|
|
18
|
-
*/
|
|
19
|
-
it('should return `true` if an address file name matches a chain type', () => {
|
|
20
|
-
const matchAssetName = 'contracts-awesome-chain-main-net-1.json';
|
|
21
|
-
const isMatchingAssetName = isValidAssetName('main-net')(matchAssetName);
|
|
22
|
-
|
|
23
|
-
expect(isMatchingAssetName).toEqual(true);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @target
|
|
28
|
-
* `isValidAssetName` should return `false` if an address file name does not
|
|
29
|
-
* match a chain type
|
|
30
|
-
* @dependencies
|
|
31
|
-
* @scenario
|
|
32
|
-
* - get result by calling `isValidAssetName('mainnet')` with a testnet
|
|
33
|
-
* address file name
|
|
34
|
-
* @expected
|
|
35
|
-
* - result should be false
|
|
36
|
-
*/
|
|
37
|
-
it('should return `false` if an address file name does not match a chain type', () => {
|
|
38
|
-
const notMatchAssetName = 'contracts-awesomechain-testnet-1.json';
|
|
39
|
-
const isMatchingAssetName = isValidAssetName('mainnet')(notMatchAssetName);
|
|
40
|
-
|
|
41
|
-
expect(isMatchingAssetName).toEqual(false);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @target
|
|
46
|
-
* `isValidAssetName` should return `true` if a tokensMap file name matches a
|
|
47
|
-
* chain type
|
|
48
|
-
* @dependencies
|
|
49
|
-
* @scenario
|
|
50
|
-
* - get result by calling `isValidAssetName('mainnet')` with a mainnet
|
|
51
|
-
* tokensMap file name
|
|
52
|
-
* @expected
|
|
53
|
-
* - result should be true
|
|
54
|
-
*/
|
|
55
|
-
it('should return `true` if a tokensMap file name matches a chain type', () => {
|
|
56
|
-
const matchAssetName = 'tokensMap-mainnet-1.json';
|
|
57
|
-
const isMatchingAssetName = isValidAssetName('mainnet')(matchAssetName);
|
|
58
|
-
|
|
59
|
-
expect(isMatchingAssetName).toEqual(true);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @target
|
|
64
|
-
* `isValidAssetName` should return `false` if a tokensMap file name does not
|
|
65
|
-
* match a chain type
|
|
66
|
-
* @dependencies
|
|
67
|
-
* @scenario
|
|
68
|
-
* - get result by calling `isValidAssetName('mainnet')` with a testnet
|
|
69
|
-
* tokensMap file name
|
|
70
|
-
* @expected
|
|
71
|
-
* - result should be false
|
|
72
|
-
*/
|
|
73
|
-
it('should return `false` if a tokensMap file name does not match a chain type', () => {
|
|
74
|
-
const notMatchAssetName = 'tokensMap-testnet-1.json';
|
|
75
|
-
const isMatchingAssetName = isValidAssetName('mainnet')(notMatchAssetName);
|
|
76
|
-
|
|
77
|
-
expect(isMatchingAssetName).toEqual(false);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* @target
|
|
82
|
-
* `isValidAssetName` should return false when asset name doesn't match Rosen
|
|
83
|
-
* format assets
|
|
84
|
-
* @dependencies
|
|
85
|
-
* @scenario
|
|
86
|
-
* - get result by calling `isValidAssetName('mainnet')` with an invalid asset
|
|
87
|
-
* file name
|
|
88
|
-
* @expected
|
|
89
|
-
* - result should be false
|
|
90
|
-
*/
|
|
91
|
-
it("should return false when asset name doesn't match Rosen format assets", () => {
|
|
92
|
-
const invalidAssetName = 'invalid-name.json';
|
|
93
|
-
const isMatchingAssetName = isValidAssetName('mainnet')(invalidAssetName);
|
|
94
|
-
|
|
95
|
-
expect(isMatchingAssetName).toEqual(false);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe('truncateAssetName', () => {
|
|
100
|
-
/**
|
|
101
|
-
* @target
|
|
102
|
-
* `truncateAssetName` should truncate contract file names correctly
|
|
103
|
-
* @dependencies
|
|
104
|
-
* @scenario
|
|
105
|
-
* - get result by calling `truncateAssetName` with a contract file name
|
|
106
|
-
* @expected
|
|
107
|
-
* - result should be truncated name
|
|
108
|
-
*/
|
|
109
|
-
it('should truncate contract file names correctly', () => {
|
|
110
|
-
const addressAssetName =
|
|
111
|
-
'contracts-awesome-chain-main-net-2.0.1-0b08041.json';
|
|
112
|
-
const truncatedName = truncateAssetName(
|
|
113
|
-
addressAssetName,
|
|
114
|
-
'main-net',
|
|
115
|
-
'2.0.1-0b08041'
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
expect(truncatedName).toEqual('contracts-awesome-chain.json');
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* @target
|
|
123
|
-
* `truncateAssetName` should truncate tokensMap file names correctly
|
|
124
|
-
* @dependencies
|
|
125
|
-
* @scenario
|
|
126
|
-
* - get result by calling `truncateAssetName` with a tokensMap file name
|
|
127
|
-
* @expected
|
|
128
|
-
* - result should be truncated name
|
|
129
|
-
*/
|
|
130
|
-
it('should truncate contract file names correctly', () => {
|
|
131
|
-
const tokensMapAssetName = 'tokensMap-mainnet-2.0.1-0b08041.json';
|
|
132
|
-
const truncatedName = truncateAssetName(
|
|
133
|
-
tokensMapAssetName,
|
|
134
|
-
'mainnet',
|
|
135
|
-
'2.0.1-0b08041'
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
expect(truncatedName).toEqual('tokensMap.json');
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* @target
|
|
143
|
-
* `truncateAssetName` should truncate asset name and append suffix correctly
|
|
144
|
-
* @dependencies
|
|
145
|
-
* @scenario
|
|
146
|
-
* - get result by calling `truncateAssetName` with an asset name
|
|
147
|
-
* @expected
|
|
148
|
-
* - result should be truncated name with suffix
|
|
149
|
-
*/
|
|
150
|
-
it('should truncate asset name and append suffix correctly', () => {
|
|
151
|
-
const assetName = 'contracts-awesome-chain-mainnet-2.0.1-0b08041.json';
|
|
152
|
-
const truncatedNameWithSuffix = truncateAssetName(
|
|
153
|
-
assetName,
|
|
154
|
-
'mainnet',
|
|
155
|
-
'2.0.1-0b08041',
|
|
156
|
-
'suffix'
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
expect(truncatedNameWithSuffix).toEqual(
|
|
160
|
-
'contracts-awesome-chain-suffix.json'
|
|
161
|
-
);
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
describe('isValidOS', () => {
|
|
166
|
-
/**
|
|
167
|
-
* @target
|
|
168
|
-
* `isValidOS` should return `true` if an asset file name matches an OS name
|
|
169
|
-
* @dependencies
|
|
170
|
-
* @scenario
|
|
171
|
-
* - get result by calling `isValidOS('linux')` with a linux tss-api file name
|
|
172
|
-
* @expected
|
|
173
|
-
* - result should be true
|
|
174
|
-
*/
|
|
175
|
-
it('should return `true` if an os name matches a tss-api asset file', () => {
|
|
176
|
-
const matchOSName = 'rosenTss-linux-4.0.0.zip';
|
|
177
|
-
const isMatchingAssetName = isValidOS('linux')(matchOSName);
|
|
178
|
-
|
|
179
|
-
expect(isMatchingAssetName).toEqual(true);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* @target
|
|
184
|
-
* `isValidOS` should return `false` if an asset file name does not match an OS name
|
|
185
|
-
* @dependencies
|
|
186
|
-
* @scenario
|
|
187
|
-
* - get result by calling `isValidOS('linux')` with a linux tss-api file name
|
|
188
|
-
* @expected
|
|
189
|
-
* - result should be false
|
|
190
|
-
*/
|
|
191
|
-
it('should return `false` if an os name does not match a tss-api asset file', () => {
|
|
192
|
-
const notMatchOSName = 'rosenTss-pi-4.0.0.zip';
|
|
193
|
-
const isMatchingAssetName = isValidOS('linux')(notMatchOSName);
|
|
194
|
-
|
|
195
|
-
expect(isMatchingAssetName).toEqual(false);
|
|
196
|
-
});
|
|
197
|
-
});
|