@rosen-bridge/utils 0.0.1 → 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 +13 -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 +6 -3
- package/dist/lib/downloadRosenAssets.d.ts.map +1 -1
- package/dist/lib/downloadRosenAssets.js +15 -10
- package/dist/lib/downloadTssBinary.d.ts +13 -0
- package/dist/lib/downloadTssBinary.d.ts.map +1 -0
- package/dist/lib/downloadTssBinary.js +45 -0
- 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 +318 -6
- package/dist/lib/utils/github.d.ts.map +1 -1
- package/dist/lib/utils/github.js +53 -9
- 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/dist/tsconfig.tsbuildinfo +1 -0
- package/lib/constants.ts +0 -1
- package/lib/downloadRosenAssets.ts +21 -10
- package/lib/downloadTssBinary.ts +61 -0
- package/lib/index.ts +1 -0
- package/lib/types/index.ts +2 -0
- package/lib/utils/github.ts +74 -8
- package/lib/utils/rosen.ts +7 -0
- package/package.json +3 -4
- package/tests/data/octokit.data.ts +88 -1
- package/tests/downloadRosenAssets.spec.ts +39 -9
- package/tests/downloadTssBinary.spec.ts +153 -0
- package/tests/mocks/octokit.mock.ts +20 -2
- package/tests/utils/github.spec.ts +192 -20
- package/tests/utils/rosen.spec.ts +39 -1
|
@@ -4,26 +4,35 @@ import {
|
|
|
4
4
|
hasAssetForChainType,
|
|
5
5
|
findLastRelease,
|
|
6
6
|
isStableReleaseForChainType,
|
|
7
|
+
isStableReleaseForRegexTagType,
|
|
7
8
|
findLatestStableRelease,
|
|
9
|
+
getReleaseByTag,
|
|
10
|
+
hasMatchedTagPrefix,
|
|
11
|
+
findLatestStableReleaseByPrefixTag,
|
|
12
|
+
findLatestReleaseByPrefixTag,
|
|
8
13
|
} from '../../lib/utils/github';
|
|
9
14
|
|
|
10
15
|
import {
|
|
11
16
|
mainNetPrereleaseRelease,
|
|
12
17
|
mainNetStableRelease,
|
|
13
|
-
|
|
18
|
+
contractReleases,
|
|
14
19
|
testNetPrereleaseRelease,
|
|
15
20
|
testNetStableRelease,
|
|
21
|
+
tssTag2,
|
|
22
|
+
tssTag3PreRelease,
|
|
23
|
+
tssTag1,
|
|
24
|
+
tssReleases,
|
|
16
25
|
} from '../data/octokit.data';
|
|
17
26
|
|
|
18
|
-
import { mockOctokit } from '../mocks/octokit.mock';
|
|
27
|
+
import { mockOctokit, mockOctokitGetReleaseByTag } from '../mocks/octokit.mock';
|
|
19
28
|
|
|
20
29
|
describe('fetchReleasesPage', () => {
|
|
21
30
|
/**
|
|
22
|
-
* @target `fetchReleasesPage` should generate
|
|
31
|
+
* @target `fetchReleasesPage` should generate contractReleases correctly
|
|
23
32
|
* @dependencies
|
|
24
33
|
* - mocked Octokit
|
|
25
34
|
* @scenario
|
|
26
|
-
* - mock Octokit `listReleases` to return 9
|
|
35
|
+
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
27
36
|
* - create an iterator by calling `fetchReleasesPage` generator function
|
|
28
37
|
* - get results by consuming iterator
|
|
29
38
|
* @expected
|
|
@@ -33,9 +42,9 @@ describe('fetchReleasesPage', () => {
|
|
|
33
42
|
* - third result done property should be true
|
|
34
43
|
*/
|
|
35
44
|
it('should generate releases correctly', async () => {
|
|
36
|
-
mockOctokit();
|
|
45
|
+
mockOctokit(contractReleases);
|
|
37
46
|
|
|
38
|
-
const iterator = fetchReleasesPage();
|
|
47
|
+
const iterator = fetchReleasesPage('contract');
|
|
39
48
|
|
|
40
49
|
expect((await iterator.next()).value).toHaveLength(5);
|
|
41
50
|
expect((await iterator.next()).value).toHaveLength(4);
|
|
@@ -46,7 +55,7 @@ describe('fetchReleasesPage', () => {
|
|
|
46
55
|
|
|
47
56
|
describe('findLastRelease', () => {
|
|
48
57
|
beforeEach(() => {
|
|
49
|
-
mockOctokit();
|
|
58
|
+
mockOctokit(contractReleases);
|
|
50
59
|
});
|
|
51
60
|
|
|
52
61
|
/**
|
|
@@ -54,13 +63,14 @@ describe('findLastRelease', () => {
|
|
|
54
63
|
* @dependencies
|
|
55
64
|
* - mocked Octokit
|
|
56
65
|
* @scenario
|
|
57
|
-
* - mock Octokit `listReleases` to return 9
|
|
66
|
+
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
58
67
|
* - get result by calling `findLastRelease` with a predicate
|
|
59
68
|
* @expected
|
|
60
69
|
* - result id should equal mainnet stable release id
|
|
61
70
|
*/
|
|
62
|
-
it('should find last
|
|
71
|
+
it('should find last release correctly when a predicate is provided', async () => {
|
|
63
72
|
const foundRelease = await findLastRelease(
|
|
73
|
+
'contract',
|
|
64
74
|
(release) => release.id === mainNetStableRelease.id
|
|
65
75
|
);
|
|
66
76
|
|
|
@@ -73,15 +83,15 @@ describe('findLastRelease', () => {
|
|
|
73
83
|
* @dependencies
|
|
74
84
|
* - mocked Octokit
|
|
75
85
|
* @scenario
|
|
76
|
-
* - mock Octokit `listReleases` to return 9
|
|
86
|
+
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
77
87
|
* - get result by calling `findLastRelease` without a predicate
|
|
78
88
|
* @expected
|
|
79
89
|
* - result id should equal the last release id
|
|
80
90
|
*/
|
|
81
91
|
it('should return last release when no predicate is provided', async () => {
|
|
82
|
-
const foundRelease = await findLastRelease();
|
|
92
|
+
const foundRelease = await findLastRelease('contract');
|
|
83
93
|
|
|
84
|
-
expect(foundRelease?.id).toEqual(
|
|
94
|
+
expect(foundRelease?.id).toEqual(contractReleases[0].id);
|
|
85
95
|
});
|
|
86
96
|
|
|
87
97
|
/**
|
|
@@ -90,19 +100,41 @@ describe('findLastRelease', () => {
|
|
|
90
100
|
* @dependencies
|
|
91
101
|
* - mocked Octokit
|
|
92
102
|
* @scenario
|
|
93
|
-
* - mock Octokit `listReleases` to return 9
|
|
103
|
+
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
94
104
|
* - get result by calling `findLastRelease` with a predicate which does not
|
|
95
105
|
* match any release
|
|
96
106
|
* @expected
|
|
97
107
|
* - result should be null
|
|
98
108
|
*/
|
|
99
109
|
it('should return null when no matching release is found', async () => {
|
|
100
|
-
const foundRelease = await findLastRelease(
|
|
110
|
+
const foundRelease = await findLastRelease(
|
|
111
|
+
'contract',
|
|
112
|
+
(release) => release.id === 100
|
|
113
|
+
);
|
|
101
114
|
|
|
102
115
|
expect(foundRelease).toEqual(null);
|
|
103
116
|
});
|
|
104
117
|
});
|
|
105
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', '3');
|
|
133
|
+
|
|
134
|
+
expect(release.id).toEqual(3);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
106
138
|
describe('hasAssetForChainType', () => {
|
|
107
139
|
/**
|
|
108
140
|
* @target `hasAssetForChainType` should return `true` if a release has asset
|
|
@@ -194,6 +226,98 @@ describe('isStableReleaseForChainType', () => {
|
|
|
194
226
|
});
|
|
195
227
|
});
|
|
196
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
|
+
|
|
197
321
|
describe('findLatestRelease', () => {
|
|
198
322
|
/**
|
|
199
323
|
* @target `findLatestRelease` should find latest release for a chain type
|
|
@@ -201,15 +325,15 @@ describe('findLatestRelease', () => {
|
|
|
201
325
|
* @dependencies
|
|
202
326
|
* - mocked Octokit
|
|
203
327
|
* @scenario
|
|
204
|
-
* - mock Octokit `listReleases` to return 9
|
|
328
|
+
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
205
329
|
* - get result by calling `findLatestRelease` with mainnet chain type
|
|
206
330
|
* @expected
|
|
207
331
|
* - result id should equal mainnet prerelease release id
|
|
208
332
|
*/
|
|
209
333
|
it('should find latest release for a chain type correctly', async () => {
|
|
210
|
-
mockOctokit();
|
|
334
|
+
mockOctokit(contractReleases);
|
|
211
335
|
|
|
212
|
-
const latestMainNet = await findLatestRelease('mainnet');
|
|
336
|
+
const latestMainNet = await findLatestRelease('contract', 'mainnet');
|
|
213
337
|
|
|
214
338
|
expect(latestMainNet?.id).toEqual(mainNetPrereleaseRelease.id);
|
|
215
339
|
});
|
|
@@ -222,16 +346,64 @@ describe('findLatestStableRelease', () => {
|
|
|
222
346
|
* @dependencies
|
|
223
347
|
* - mocked Octokit
|
|
224
348
|
* @scenario
|
|
225
|
-
* - mock Octokit `listReleases` to return 9
|
|
349
|
+
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
226
350
|
* - get result by calling `findLatestStableRelease` with mainnet chain type
|
|
227
351
|
* @expected
|
|
228
352
|
* - result id should equal mainnet stable release id
|
|
229
353
|
*/
|
|
230
354
|
it('should find latest stable (that is, non-prerelease) release for a chain type correctly', async () => {
|
|
231
|
-
mockOctokit();
|
|
355
|
+
mockOctokit(contractReleases);
|
|
232
356
|
|
|
233
|
-
const latestMainNet = await findLatestStableRelease('mainnet');
|
|
357
|
+
const latestMainNet = await findLatestStableRelease('contract', 'mainnet');
|
|
234
358
|
|
|
235
359
|
expect(latestMainNet?.id).toEqual(mainNetStableRelease.id);
|
|
236
360
|
});
|
|
237
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
|
+
});
|