@rosen-bridge/utils 0.1.0 → 0.2.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 +6 -0
- package/dist/lib/constants.d.ts +0 -1
- package/dist/lib/constants.d.ts.map +1 -1
- package/dist/lib/constants.js +1 -2
- package/dist/lib/downloadRosenAssets.d.ts.map +1 -1
- package/dist/lib/downloadRosenAssets.js +5 -4
- package/dist/lib/downloadTssBinary.d.ts.map +1 -1
- package/dist/lib/downloadTssBinary.js +2 -2
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +2 -1
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/index.d.ts.map +1 -1
- package/dist/lib/types/index.js +1 -1
- package/dist/lib/utils/github.d.ts +221 -7
- package/dist/lib/utils/github.d.ts.map +1 -1
- package/dist/lib/utils/github.js +42 -11
- package/dist/lib/utils/rosen.d.ts +5 -0
- package/dist/lib/utils/rosen.d.ts.map +1 -1
- package/dist/lib/utils/rosen.js +6 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/lib/constants.ts +0 -1
- package/lib/downloadRosenAssets.ts +5 -3
- package/lib/downloadTssBinary.ts +61 -0
- package/lib/index.ts +1 -0
- package/lib/types/index.ts +2 -0
- package/lib/utils/github.ts +60 -10
- package/lib/utils/rosen.ts +7 -0
- package/package.json +1 -1
- package/tests/data/octokit.data.ts +88 -10
- package/tests/downloadRosenAssets.spec.ts +9 -9
- package/tests/downloadTssBinary.spec.ts +153 -0
- package/tests/mocks/octokit.mock.ts +4 -4
- package/tests/utils/github.spec.ts +173 -21
- package/tests/utils/rosen.spec.ts +39 -1
|
@@ -4,27 +4,35 @@ import {
|
|
|
4
4
|
hasAssetForChainType,
|
|
5
5
|
findLastRelease,
|
|
6
6
|
isStableReleaseForChainType,
|
|
7
|
+
isStableReleaseForRegexTagType,
|
|
7
8
|
findLatestStableRelease,
|
|
8
9
|
getReleaseByTag,
|
|
10
|
+
hasMatchedTagPrefix,
|
|
11
|
+
findLatestStableReleaseByPrefixTag,
|
|
12
|
+
findLatestReleaseByPrefixTag,
|
|
9
13
|
} from '../../lib/utils/github';
|
|
10
14
|
|
|
11
15
|
import {
|
|
12
16
|
mainNetPrereleaseRelease,
|
|
13
17
|
mainNetStableRelease,
|
|
14
|
-
|
|
18
|
+
contractReleases,
|
|
15
19
|
testNetPrereleaseRelease,
|
|
16
20
|
testNetStableRelease,
|
|
21
|
+
tssTag2,
|
|
22
|
+
tssTag3PreRelease,
|
|
23
|
+
tssTag1,
|
|
24
|
+
tssReleases,
|
|
17
25
|
} from '../data/octokit.data';
|
|
18
26
|
|
|
19
27
|
import { mockOctokit, mockOctokitGetReleaseByTag } from '../mocks/octokit.mock';
|
|
20
28
|
|
|
21
29
|
describe('fetchReleasesPage', () => {
|
|
22
30
|
/**
|
|
23
|
-
* @target `fetchReleasesPage` should generate
|
|
31
|
+
* @target `fetchReleasesPage` should generate contractReleases correctly
|
|
24
32
|
* @dependencies
|
|
25
33
|
* - mocked Octokit
|
|
26
34
|
* @scenario
|
|
27
|
-
* - mock Octokit `listReleases` to return 9
|
|
35
|
+
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
28
36
|
* - create an iterator by calling `fetchReleasesPage` generator function
|
|
29
37
|
* - get results by consuming iterator
|
|
30
38
|
* @expected
|
|
@@ -34,9 +42,9 @@ describe('fetchReleasesPage', () => {
|
|
|
34
42
|
* - third result done property should be true
|
|
35
43
|
*/
|
|
36
44
|
it('should generate releases correctly', async () => {
|
|
37
|
-
mockOctokit();
|
|
45
|
+
mockOctokit(contractReleases);
|
|
38
46
|
|
|
39
|
-
const iterator = fetchReleasesPage();
|
|
47
|
+
const iterator = fetchReleasesPage('contract');
|
|
40
48
|
|
|
41
49
|
expect((await iterator.next()).value).toHaveLength(5);
|
|
42
50
|
expect((await iterator.next()).value).toHaveLength(4);
|
|
@@ -47,7 +55,7 @@ describe('fetchReleasesPage', () => {
|
|
|
47
55
|
|
|
48
56
|
describe('findLastRelease', () => {
|
|
49
57
|
beforeEach(() => {
|
|
50
|
-
mockOctokit();
|
|
58
|
+
mockOctokit(contractReleases);
|
|
51
59
|
});
|
|
52
60
|
|
|
53
61
|
/**
|
|
@@ -55,13 +63,14 @@ describe('findLastRelease', () => {
|
|
|
55
63
|
* @dependencies
|
|
56
64
|
* - mocked Octokit
|
|
57
65
|
* @scenario
|
|
58
|
-
* - mock Octokit `listReleases` to return 9
|
|
66
|
+
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
59
67
|
* - get result by calling `findLastRelease` with a predicate
|
|
60
68
|
* @expected
|
|
61
69
|
* - result id should equal mainnet stable release id
|
|
62
70
|
*/
|
|
63
|
-
it('should find last
|
|
71
|
+
it('should find last release correctly when a predicate is provided', async () => {
|
|
64
72
|
const foundRelease = await findLastRelease(
|
|
73
|
+
'contract',
|
|
65
74
|
(release) => release.id === mainNetStableRelease.id
|
|
66
75
|
);
|
|
67
76
|
|
|
@@ -74,15 +83,15 @@ describe('findLastRelease', () => {
|
|
|
74
83
|
* @dependencies
|
|
75
84
|
* - mocked Octokit
|
|
76
85
|
* @scenario
|
|
77
|
-
* - mock Octokit `listReleases` to return 9
|
|
86
|
+
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
78
87
|
* - get result by calling `findLastRelease` without a predicate
|
|
79
88
|
* @expected
|
|
80
89
|
* - result id should equal the last release id
|
|
81
90
|
*/
|
|
82
91
|
it('should return last release when no predicate is provided', async () => {
|
|
83
|
-
const foundRelease = await findLastRelease();
|
|
92
|
+
const foundRelease = await findLastRelease('contract');
|
|
84
93
|
|
|
85
|
-
expect(foundRelease?.id).toEqual(
|
|
94
|
+
expect(foundRelease?.id).toEqual(contractReleases[0].id);
|
|
86
95
|
});
|
|
87
96
|
|
|
88
97
|
/**
|
|
@@ -91,14 +100,17 @@ describe('findLastRelease', () => {
|
|
|
91
100
|
* @dependencies
|
|
92
101
|
* - mocked Octokit
|
|
93
102
|
* @scenario
|
|
94
|
-
* - mock Octokit `listReleases` to return 9
|
|
103
|
+
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
95
104
|
* - get result by calling `findLastRelease` with a predicate which does not
|
|
96
105
|
* match any release
|
|
97
106
|
* @expected
|
|
98
107
|
* - result should be null
|
|
99
108
|
*/
|
|
100
109
|
it('should return null when no matching release is found', async () => {
|
|
101
|
-
const foundRelease = await findLastRelease(
|
|
110
|
+
const foundRelease = await findLastRelease(
|
|
111
|
+
'contract',
|
|
112
|
+
(release) => release.id === 100
|
|
113
|
+
);
|
|
102
114
|
|
|
103
115
|
expect(foundRelease).toEqual(null);
|
|
104
116
|
});
|
|
@@ -115,9 +127,9 @@ describe('getReleaseByTag', () => {
|
|
|
115
127
|
* - the release should be the expected one
|
|
116
128
|
*/
|
|
117
129
|
it('should get release by tag', async () => {
|
|
118
|
-
mockOctokitGetReleaseByTag();
|
|
130
|
+
mockOctokitGetReleaseByTag(contractReleases);
|
|
119
131
|
|
|
120
|
-
const release = await getReleaseByTag('3');
|
|
132
|
+
const release = await getReleaseByTag('contract', '3');
|
|
121
133
|
|
|
122
134
|
expect(release.id).toEqual(3);
|
|
123
135
|
});
|
|
@@ -214,6 +226,98 @@ describe('isStableReleaseForChainType', () => {
|
|
|
214
226
|
});
|
|
215
227
|
});
|
|
216
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
|
+
|
|
217
321
|
describe('findLatestRelease', () => {
|
|
218
322
|
/**
|
|
219
323
|
* @target `findLatestRelease` should find latest release for a chain type
|
|
@@ -221,15 +325,15 @@ describe('findLatestRelease', () => {
|
|
|
221
325
|
* @dependencies
|
|
222
326
|
* - mocked Octokit
|
|
223
327
|
* @scenario
|
|
224
|
-
* - mock Octokit `listReleases` to return 9
|
|
328
|
+
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
225
329
|
* - get result by calling `findLatestRelease` with mainnet chain type
|
|
226
330
|
* @expected
|
|
227
331
|
* - result id should equal mainnet prerelease release id
|
|
228
332
|
*/
|
|
229
333
|
it('should find latest release for a chain type correctly', async () => {
|
|
230
|
-
mockOctokit();
|
|
334
|
+
mockOctokit(contractReleases);
|
|
231
335
|
|
|
232
|
-
const latestMainNet = await findLatestRelease('mainnet');
|
|
336
|
+
const latestMainNet = await findLatestRelease('contract', 'mainnet');
|
|
233
337
|
|
|
234
338
|
expect(latestMainNet?.id).toEqual(mainNetPrereleaseRelease.id);
|
|
235
339
|
});
|
|
@@ -242,16 +346,64 @@ describe('findLatestStableRelease', () => {
|
|
|
242
346
|
* @dependencies
|
|
243
347
|
* - mocked Octokit
|
|
244
348
|
* @scenario
|
|
245
|
-
* - mock Octokit `listReleases` to return 9
|
|
349
|
+
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
246
350
|
* - get result by calling `findLatestStableRelease` with mainnet chain type
|
|
247
351
|
* @expected
|
|
248
352
|
* - result id should equal mainnet stable release id
|
|
249
353
|
*/
|
|
250
354
|
it('should find latest stable (that is, non-prerelease) release for a chain type correctly', async () => {
|
|
251
|
-
mockOctokit();
|
|
355
|
+
mockOctokit(contractReleases);
|
|
252
356
|
|
|
253
|
-
const latestMainNet = await findLatestStableRelease('mainnet');
|
|
357
|
+
const latestMainNet = await findLatestStableRelease('contract', 'mainnet');
|
|
254
358
|
|
|
255
359
|
expect(latestMainNet?.id).toEqual(mainNetStableRelease.id);
|
|
256
360
|
});
|
|
257
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,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
isValidAssetName,
|
|
3
|
+
isValidOS,
|
|
4
|
+
truncateAssetName,
|
|
5
|
+
} from '../../lib/utils/rosen';
|
|
2
6
|
|
|
3
7
|
describe('isValidAssetName', () => {
|
|
4
8
|
/**
|
|
@@ -143,3 +147,37 @@ describe('truncateAssetName', () => {
|
|
|
143
147
|
);
|
|
144
148
|
});
|
|
145
149
|
});
|
|
150
|
+
|
|
151
|
+
describe('isValidOS', () => {
|
|
152
|
+
/**
|
|
153
|
+
* @target
|
|
154
|
+
* `isValidOS` should return `true` if an asset file name matches an OS name
|
|
155
|
+
* @dependencies
|
|
156
|
+
* @scenario
|
|
157
|
+
* - get result by calling `isValidOS('linux')` with a linux tss-api file name
|
|
158
|
+
* @expected
|
|
159
|
+
* - result should be true
|
|
160
|
+
*/
|
|
161
|
+
it('should return `true` if an os name matches a tss-api asset file', () => {
|
|
162
|
+
const matchOSName = 'rosenTss-linux-4.0.0.zip';
|
|
163
|
+
const isMatchingAssetName = isValidOS('linux')(matchOSName);
|
|
164
|
+
|
|
165
|
+
expect(isMatchingAssetName).toEqual(true);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @target
|
|
170
|
+
* `isValidOS` should return `false` if an asset file name does not match an OS name
|
|
171
|
+
* @dependencies
|
|
172
|
+
* @scenario
|
|
173
|
+
* - get result by calling `isValidOS('linux')` with a linux tss-api file name
|
|
174
|
+
* @expected
|
|
175
|
+
* - result should be false
|
|
176
|
+
*/
|
|
177
|
+
it('should return `false` if an os name does not match a tss-api asset file', () => {
|
|
178
|
+
const notMatchOSName = 'rosenTss-pi-4.0.0.zip';
|
|
179
|
+
const isMatchingAssetName = isValidOS('linux')(notMatchOSName);
|
|
180
|
+
|
|
181
|
+
expect(isMatchingAssetName).toEqual(false);
|
|
182
|
+
});
|
|
183
|
+
});
|