@rosen-bridge/utils 0.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.
Files changed (42) hide show
  1. package/.eslintignore +1 -0
  2. package/README.md +25 -0
  3. package/babel.config.json +3 -0
  4. package/dist/lib/constants.d.ts +4 -0
  5. package/dist/lib/constants.d.ts.map +1 -0
  6. package/dist/lib/constants.js +4 -0
  7. package/dist/lib/downloadRosenAssets.d.ts +10 -0
  8. package/dist/lib/downloadRosenAssets.d.ts.map +1 -0
  9. package/dist/lib/downloadRosenAssets.js +43 -0
  10. package/dist/lib/error.d.ts +4 -0
  11. package/dist/lib/error.d.ts.map +1 -0
  12. package/dist/lib/error.js +4 -0
  13. package/dist/lib/index.d.ts +3 -0
  14. package/dist/lib/index.d.ts.map +1 -0
  15. package/dist/lib/index.js +3 -0
  16. package/dist/lib/types/index.d.ts +6 -0
  17. package/dist/lib/types/index.d.ts.map +1 -0
  18. package/dist/lib/types/index.js +2 -0
  19. package/dist/lib/utils/github.d.ts +412 -0
  20. package/dist/lib/utils/github.d.ts.map +1 -0
  21. package/dist/lib/utils/github.js +69 -0
  22. package/dist/lib/utils/rosen.d.ts +14 -0
  23. package/dist/lib/utils/rosen.d.ts.map +1 -0
  24. package/dist/lib/utils/rosen.js +14 -0
  25. package/dist/tsconfig.build.tsbuildinfo +1 -0
  26. package/jest.config.json +7 -0
  27. package/lib/constants.ts +3 -0
  28. package/lib/downloadRosenAssets.ts +56 -0
  29. package/lib/error.ts +3 -0
  30. package/lib/index.ts +3 -0
  31. package/lib/types/index.ts +11 -0
  32. package/lib/utils/github.ts +103 -0
  33. package/lib/utils/rosen.ts +22 -0
  34. package/package.json +48 -0
  35. package/tests/data/octokit.data.ts +121 -0
  36. package/tests/downloadRosenAssets.spec.ts +170 -0
  37. package/tests/mocks/octokit.mock.ts +23 -0
  38. package/tests/setup.ts +1 -0
  39. package/tests/utils/github.spec.ts +237 -0
  40. package/tests/utils/rosen.spec.ts +145 -0
  41. package/tsconfig.build.json +4 -0
  42. package/tsconfig.json +8 -0
@@ -0,0 +1,121 @@
1
+ import { GithubRelease } from '../../lib/types';
2
+
3
+ export type PartialReleases = Partial<GithubRelease>[];
4
+
5
+ export const mainNetPrereleaseRelease = {
6
+ id: 1,
7
+ prerelease: true,
8
+ assets: [
9
+ {
10
+ browser_download_url:
11
+ 'https://example.com/contracts-awesomechain-mainnet-7.json',
12
+ name: 'contracts-awesomechain-mainnet-7.json',
13
+ } as any,
14
+ {
15
+ browser_download_url: 'https://example.com/tokensMap-mainnet-7.json',
16
+ name: 'tokensMap-mainnet-6.json',
17
+ } as any,
18
+ ],
19
+ };
20
+
21
+ export const mainNetStableRelease = {
22
+ id: 2,
23
+ prerelease: false,
24
+ assets: [
25
+ {
26
+ browser_download_url:
27
+ 'https://example.com/contracts-awesomechain-mainnet-6.json',
28
+ name: 'contracts-awesomechain-mainnet-6.json',
29
+ } as any,
30
+ {
31
+ browser_download_url: 'https://example.com/tokensMap-mainnet-6.json',
32
+ name: 'tokensMap-mainnet-6.json',
33
+ } as any,
34
+ ],
35
+ };
36
+
37
+ export const testNetPrereleaseRelease = {
38
+ id: 4,
39
+ prerelease: true,
40
+ assets: [
41
+ {
42
+ browser_download_url:
43
+ 'https://example.com/contracts-awesomechain-testnet-1.json',
44
+ name: 'contracts-awesomechain-testnet-1.json',
45
+ } as any,
46
+ ],
47
+ };
48
+
49
+ export const testNetStableRelease = {
50
+ id: 5,
51
+ prerelease: false,
52
+ assets: [
53
+ {
54
+ browser_download_url:
55
+ 'https://example.com/contracts-awesomechain-testnet-1.json',
56
+ name: 'contracts-awesomechain-testnet-1.json',
57
+ } as any,
58
+ ],
59
+ };
60
+
61
+ export const releases = [
62
+ mainNetPrereleaseRelease,
63
+ mainNetStableRelease,
64
+ {
65
+ id: 3,
66
+ prerelease: false,
67
+ assets: [
68
+ {
69
+ browser_download_url:
70
+ 'https://example.com/contracts-awesomechain-mainnet-5.json',
71
+ name: 'contracts-awesomechain-mainnet-5.json',
72
+ } as any,
73
+ ],
74
+ },
75
+ testNetPrereleaseRelease,
76
+ testNetStableRelease,
77
+ {
78
+ id: 6,
79
+ prerelease: false,
80
+ assets: [
81
+ {
82
+ browser_download_url:
83
+ 'https://example.com/contracts-awesomechain-mainnet-4.json',
84
+ name: 'contracts-awesomechain-mainnet-4.json',
85
+ } as any,
86
+ ],
87
+ },
88
+ {
89
+ id: 7,
90
+ prerelease: false,
91
+ assets: [
92
+ {
93
+ browser_download_url:
94
+ 'https://example.com/contracts-awesomechain-mainnet-3.json',
95
+ name: 'contracts-awesomechain-mainnet-3.json',
96
+ } as any,
97
+ ],
98
+ },
99
+ {
100
+ id: 8,
101
+ prerelease: false,
102
+ assets: [
103
+ {
104
+ browser_download_url:
105
+ 'https://example.com/contracts-awesomechain-mainnet-2.json',
106
+ name: 'contracts-awesomechain-mainnet-2.json',
107
+ } as any,
108
+ ],
109
+ },
110
+ {
111
+ id: 9,
112
+ prerelease: false,
113
+ assets: [
114
+ {
115
+ browser_download_url:
116
+ 'https://example.com/contracts-awesomechain-mainnet-1.json',
117
+ name: 'contracts-awesomechain-mainnet-1.json',
118
+ } as any,
119
+ ],
120
+ },
121
+ ] satisfies PartialReleases;
@@ -0,0 +1,170 @@
1
+ import download from 'download';
2
+
3
+ import downloadRosenAssets from '../lib/downloadRosenAssets';
4
+
5
+ import { RosenAssetsDownloadError } from '../lib';
6
+
7
+ import {
8
+ mainNetPrereleaseRelease,
9
+ mainNetStableRelease,
10
+ } from './data/octokit.data';
11
+
12
+ import { mockOctokit } from './mocks/octokit.mock';
13
+
14
+ jest.mock('download');
15
+
16
+ describe('downloadRosenAssets', () => {
17
+ beforeEach(() => {
18
+ mockOctokit();
19
+ });
20
+
21
+ /**
22
+ * @target `downloadRosenAssets` should download Rosen assets correctly
23
+ * @dependencies
24
+ * - mocked Octokit
25
+ * @scenario
26
+ * - mock Octokit `listReleases` to return 9 releases
27
+ * - call `downloadRosenAssets` with mainnet chain type and `rosen` download
28
+ * directory
29
+ * @expected
30
+ * - `download` function should be called with first asset of mainnet stable
31
+ * release download url, `rosen` download directory and corresponding
32
+ * truncated asset name
33
+ * - `download` function should be called with second asset of mainnet stable
34
+ * release download url, `rosen` download directory and corresponding
35
+ * truncated asset name
36
+ */
37
+ it('should download Rosen assets correctly', async () => {
38
+ await downloadRosenAssets('mainnet', 'rosen');
39
+
40
+ expect(download).toHaveBeenCalledWith(
41
+ mainNetStableRelease.assets[0].browser_download_url,
42
+ 'rosen',
43
+ {
44
+ filename: 'contracts-awesomechain.json',
45
+ }
46
+ );
47
+ expect(download).toHaveBeenCalledWith(
48
+ mainNetStableRelease.assets[1].browser_download_url,
49
+ 'rosen',
50
+ {
51
+ filename: 'tokensMap.json',
52
+ }
53
+ );
54
+ });
55
+
56
+ /**
57
+ * @target `downloadRosenAssets` should download Rosen assets correctly when
58
+ * including prereleases
59
+ * @dependencies
60
+ * - mocked Octokit
61
+ * @scenario
62
+ * - mock Octokit `listReleases` to return 9 releases
63
+ * - call `downloadRosenAssets` with mainnet chain type, `rosen` download
64
+ * directory and including prereleases
65
+ * @expected
66
+ * - `download` function should be called with first asset of mainnet
67
+ * prerelease release download url, `rosen` download directory and
68
+ * corresponding truncated asset name
69
+ * - `download` function should be called with second asset of mainnet
70
+ * prerelease release download url, `rosen` download directory and
71
+ * corresponding truncated asset name
72
+ */
73
+ it('should download Rosen assets correctly when including prereleases', async () => {
74
+ await downloadRosenAssets('mainnet', 'rosen', true);
75
+
76
+ expect(download).toHaveBeenCalledWith(
77
+ mainNetPrereleaseRelease.assets[0].browser_download_url,
78
+ 'rosen',
79
+ {
80
+ filename: 'contracts-awesomechain.json',
81
+ }
82
+ );
83
+ expect(download).toHaveBeenCalledWith(
84
+ mainNetPrereleaseRelease.assets[1].browser_download_url,
85
+ 'rosen',
86
+ {
87
+ filename: 'tokensMap.json',
88
+ }
89
+ );
90
+ });
91
+
92
+ /**
93
+ * @target `downloadRosenAssets` should download Rosen assets and add a suffix
94
+ * correctly
95
+ * @dependencies
96
+ * - mocked Octokit
97
+ * @scenario
98
+ * - mock Octokit `listReleases` to return 9 releases
99
+ * - call `downloadRosenAssets` with mainnet chain type, `rosen` download
100
+ * directory, including prereleases and a providing a suffix
101
+ * @expected
102
+ * - `download` function should be called with first asset of mainnet stable
103
+ * release download url, `rosen` download directory and corresponding
104
+ * truncated asset name
105
+ * - `download` function should be called with second asset of mainnet stable
106
+ * release download url, `rosen` download directory and corresponding
107
+ * truncated asset name
108
+ */
109
+ it('should download Rosen assets and add a suffix correctly', async () => {
110
+ await downloadRosenAssets('mainnet', 'rosen', false, 'suffix');
111
+
112
+ expect(download).toHaveBeenCalledWith(
113
+ mainNetStableRelease.assets[0].browser_download_url,
114
+ 'rosen',
115
+ {
116
+ filename: 'contracts-awesomechain-suffix.json',
117
+ }
118
+ );
119
+ expect(download).toHaveBeenCalledWith(
120
+ mainNetStableRelease.assets[1].browser_download_url,
121
+ 'rosen',
122
+ {
123
+ filename: 'tokensMap-suffix.json',
124
+ }
125
+ );
126
+ });
127
+
128
+ /**
129
+ * @target `downloadRosenAssets` should not call `download` function when no
130
+ * matching release is found
131
+ * @dependencies
132
+ * - mocked Octokit
133
+ * - emptied mocked download package
134
+ * @scenario
135
+ * - mock Octokit `listReleases` to return 9 releases
136
+ * - clear download package mock data (so that we can check calls count)
137
+ * - call `downloadRosenAssets` with "no-release-net" chain type and `rosen`
138
+ * download directory
139
+ * @expected
140
+ * - `download` function should not get called
141
+ */
142
+ it('should not call `download` function when no matching release is found', async () => {
143
+ jest.mocked(download).mockClear();
144
+
145
+ await downloadRosenAssets('no-release-net', 'rosen');
146
+
147
+ expect(download).toHaveBeenCalledTimes(0);
148
+ });
149
+
150
+ /**
151
+ * @target `downloadRosenAssets` should throw an error when an error happens
152
+ * @dependencies
153
+ * - mocked Octokit
154
+ * - mocked download package
155
+ * @scenario
156
+ * - mock Octokit `listReleases` to return 9 releases
157
+ * - mock download package to throw an error
158
+ * - call `downloadRosenAssets` with mainnet chain type and `rosen` download
159
+ * directory
160
+ * @expected
161
+ * - `download` function should throw `RosenAssetsDownloadError`
162
+ */
163
+ it('should throw an error when an error happens', async () => {
164
+ jest.mocked(download).mockRejectedValue(new Error('Bad!'));
165
+
166
+ const downloadPromise = downloadRosenAssets('mainnet', 'rosen');
167
+
168
+ await expect(downloadPromise).rejects.toThrow(RosenAssetsDownloadError);
169
+ });
170
+ });
@@ -0,0 +1,23 @@
1
+ import { Octokit } from 'octokit';
2
+
3
+ import { releases } from '../data/octokit.data';
4
+
5
+ import { DEFAULT_RELEASES_FETCHING_PAGE_SIZE } from '../../lib/constants';
6
+
7
+ export const mockOctokit = () =>
8
+ jest.mocked(Octokit).mockImplementation(() => {
9
+ let page = 0;
10
+ return {
11
+ rest: {
12
+ repos: {
13
+ listReleases: async () => {
14
+ const currentIndex = DEFAULT_RELEASES_FETCHING_PAGE_SIZE * page;
15
+ page += 1;
16
+ return {
17
+ data: releases.slice(currentIndex, currentIndex + 5),
18
+ };
19
+ },
20
+ },
21
+ },
22
+ } as any;
23
+ });
package/tests/setup.ts ADDED
@@ -0,0 +1 @@
1
+ jest.mock('octokit');
@@ -0,0 +1,237 @@
1
+ import {
2
+ fetchReleasesPage,
3
+ findLatestRelease,
4
+ hasAssetForChainType,
5
+ findLastRelease,
6
+ isStableReleaseForChainType,
7
+ findLatestStableRelease,
8
+ } from '../../lib/utils/github';
9
+
10
+ import {
11
+ mainNetPrereleaseRelease,
12
+ mainNetStableRelease,
13
+ releases,
14
+ testNetPrereleaseRelease,
15
+ testNetStableRelease,
16
+ } from '../data/octokit.data';
17
+
18
+ import { mockOctokit } from '../mocks/octokit.mock';
19
+
20
+ describe('fetchReleasesPage', () => {
21
+ /**
22
+ * @target `fetchReleasesPage` should generate releases correctly
23
+ * @dependencies
24
+ * - mocked Octokit
25
+ * @scenario
26
+ * - mock Octokit `listReleases` to return 9 releases
27
+ * - create an iterator by calling `fetchReleasesPage` generator function
28
+ * - get results by consuming iterator
29
+ * @expected
30
+ * - first result value should have length of 5
31
+ * - second result value should have length of 4
32
+ * - third result value should be undefined
33
+ * - third result done property should be true
34
+ */
35
+ it('should generate releases correctly', async () => {
36
+ mockOctokit();
37
+
38
+ const iterator = fetchReleasesPage();
39
+
40
+ expect((await iterator.next()).value).toHaveLength(5);
41
+ expect((await iterator.next()).value).toHaveLength(4);
42
+ expect((await iterator.next()).value).toEqual(undefined);
43
+ expect((await iterator.next()).done).toEqual(true);
44
+ });
45
+ });
46
+
47
+ describe('findLastRelease', () => {
48
+ beforeEach(() => {
49
+ mockOctokit();
50
+ });
51
+
52
+ /**
53
+ * @target `findLastRelease` should find last release correctly
54
+ * @dependencies
55
+ * - mocked Octokit
56
+ * @scenario
57
+ * - mock Octokit `listReleases` to return 9 releases
58
+ * - get result by calling `findLastRelease` with a predicate
59
+ * @expected
60
+ * - result id should equal mainnet stable release id
61
+ */
62
+ it('should find last releases correctly when a predicate is provided', async () => {
63
+ const foundRelease = await findLastRelease(
64
+ (release) => release.id === mainNetStableRelease.id
65
+ );
66
+
67
+ expect(foundRelease?.id).toEqual(mainNetStableRelease.id);
68
+ });
69
+
70
+ /**
71
+ * @target `findLastRelease` should return last release when no predicate is
72
+ * provided
73
+ * @dependencies
74
+ * - mocked Octokit
75
+ * @scenario
76
+ * - mock Octokit `listReleases` to return 9 releases
77
+ * - get result by calling `findLastRelease` without a predicate
78
+ * @expected
79
+ * - result id should equal the last release id
80
+ */
81
+ it('should return last release when no predicate is provided', async () => {
82
+ const foundRelease = await findLastRelease();
83
+
84
+ expect(foundRelease?.id).toEqual(releases[0].id);
85
+ });
86
+
87
+ /**
88
+ * @target `findLastRelease` should return null when no matching release is
89
+ * found
90
+ * @dependencies
91
+ * - mocked Octokit
92
+ * @scenario
93
+ * - mock Octokit `listReleases` to return 9 releases
94
+ * - get result by calling `findLastRelease` with a predicate which does not
95
+ * match any release
96
+ * @expected
97
+ * - result should be null
98
+ */
99
+ it('should return null when no matching release is found', async () => {
100
+ const foundRelease = await findLastRelease((release) => release.id === 100);
101
+
102
+ expect(foundRelease).toEqual(null);
103
+ });
104
+ });
105
+
106
+ describe('hasAssetForChainType', () => {
107
+ /**
108
+ * @target `hasAssetForChainType` should return `true` if a release has asset
109
+ * for a specific chain type
110
+ * @dependencies
111
+ * @scenario
112
+ * - get result by calling `hasAssetForChainType('mainnet')` with a mainnet
113
+ * release
114
+ * @expected
115
+ * - result should be true
116
+ */
117
+ it('should return `true` if a release has asset for a specific chain type', () => {
118
+ const hasAssetForMainNet = hasAssetForChainType('mainnet')(
119
+ mainNetPrereleaseRelease as any
120
+ );
121
+
122
+ expect(hasAssetForMainNet).toEqual(true);
123
+ });
124
+ /**
125
+ * @target `hasAssetForChainType` should return `false` if a release does not
126
+ * have asset for a specific chain type
127
+ * @dependencies
128
+ * @scenario
129
+ * - get result by calling `hasAssetForChainType('mainnet')` with a mainnet
130
+ * release
131
+ * @expected
132
+ * - result should be false
133
+ */
134
+ it('should return `false` if a release does not have asset for a specific chain type', () => {
135
+ const hasAssetForMainNet = hasAssetForChainType('mainnet')(
136
+ testNetPrereleaseRelease as any
137
+ );
138
+
139
+ expect(hasAssetForMainNet).toEqual(false);
140
+ });
141
+ });
142
+
143
+ describe('isStableReleaseForChainType', () => {
144
+ /**
145
+ * @target `isStableReleaseForChainType`
146
+ * @dependencies
147
+ * @scenario
148
+ * - get result by calling `isStableReleaseForChainType('mainnet')` with a
149
+ * mainnet stable release
150
+ * @expected
151
+ * - result should be true
152
+ */
153
+ it('should return `true` if a release is stable (that is, non-prerelease) and has asset for a specific chain type', () => {
154
+ const isMatchingRelease = isStableReleaseForChainType('mainnet')(
155
+ mainNetStableRelease as any
156
+ );
157
+
158
+ expect(isMatchingRelease).toEqual(true);
159
+ });
160
+ /**
161
+ * @target `isStableReleaseForChainType` should return `false` if a release
162
+ * has asset for a specific chain type but is prerelease
163
+ * @dependencies
164
+ * @scenario
165
+ * - get result by calling `isStableReleaseForChainType('mainnet')` with a
166
+ * mainnet prerelease release
167
+ * @expected
168
+ * - result should be false
169
+ */
170
+ it('should return `false` if a release has asset for a specific chain type but is prerelease', () => {
171
+ const isMatchingRelease = isStableReleaseForChainType('mainnet')(
172
+ mainNetPrereleaseRelease as any
173
+ );
174
+
175
+ expect(isMatchingRelease).toEqual(false);
176
+ });
177
+ /**
178
+ * @target `isStableReleaseForChainType` should return `false` if a release is
179
+ * stable (that is, non-prerelease) but does not have asset for a specific
180
+ * chain type
181
+ * @dependencies
182
+ * @scenario
183
+ * - get result by calling `isStableReleaseForChainType('mainnet')` with a
184
+ * testnet stable release
185
+ * @expected
186
+ * - result should be false
187
+ */
188
+ it('should return `false` if a release is stable (that is, non-prerelease) but does not have asset for a specific chain type', () => {
189
+ const isMatchingRelease = isStableReleaseForChainType('mainnet')(
190
+ testNetStableRelease as any
191
+ );
192
+
193
+ expect(isMatchingRelease).toEqual(false);
194
+ });
195
+ });
196
+
197
+ describe('findLatestRelease', () => {
198
+ /**
199
+ * @target `findLatestRelease` should find latest release for a chain type
200
+ * correctly
201
+ * @dependencies
202
+ * - mocked Octokit
203
+ * @scenario
204
+ * - mock Octokit `listReleases` to return 9 releases
205
+ * - get result by calling `findLatestRelease` with mainnet chain type
206
+ * @expected
207
+ * - result id should equal mainnet prerelease release id
208
+ */
209
+ it('should find latest release for a chain type correctly', async () => {
210
+ mockOctokit();
211
+
212
+ const latestMainNet = await findLatestRelease('mainnet');
213
+
214
+ expect(latestMainNet?.id).toEqual(mainNetPrereleaseRelease.id);
215
+ });
216
+ });
217
+
218
+ describe('findLatestStableRelease', () => {
219
+ /**
220
+ * @target `findLatestStableRelease` should find latest stable (that is,
221
+ * non-prerelease) release for a chain type correctly
222
+ * @dependencies
223
+ * - mocked Octokit
224
+ * @scenario
225
+ * - mock Octokit `listReleases` to return 9 releases
226
+ * - get result by calling `findLatestStableRelease` with mainnet chain type
227
+ * @expected
228
+ * - result id should equal mainnet stable release id
229
+ */
230
+ it('should find latest stable (that is, non-prerelease) release for a chain type correctly', async () => {
231
+ mockOctokit();
232
+
233
+ const latestMainNet = await findLatestStableRelease('mainnet');
234
+
235
+ expect(latestMainNet?.id).toEqual(mainNetStableRelease.id);
236
+ });
237
+ });
@@ -0,0 +1,145 @@
1
+ import { isValidAssetName, truncateAssetName } from '../../lib/utils/rosen';
2
+
3
+ describe('isValidAssetName', () => {
4
+ /**
5
+ * @target
6
+ * `isValidAssetName` should return `true` if an address file name matches a
7
+ * chain type
8
+ * @dependencies
9
+ * @scenario
10
+ * - get result by calling `isValidAssetName('mainnet')` with a mainnet
11
+ * address file name
12
+ * @expected
13
+ * - result should be true
14
+ */
15
+ it('should return `true` if an address file name matches a chain type', () => {
16
+ const matchAssetName = 'contracts-awesomechain-mainnet-1.json';
17
+ const isMatchingAssetName = isValidAssetName('mainnet')(matchAssetName);
18
+
19
+ expect(isMatchingAssetName).toEqual(true);
20
+ });
21
+
22
+ /**
23
+ * @target
24
+ * `isValidAssetName` should return `false` if an address file name does not
25
+ * match a chain type
26
+ * @dependencies
27
+ * @scenario
28
+ * - get result by calling `isValidAssetName('mainnet')` with a testnet
29
+ * address file name
30
+ * @expected
31
+ * - result should be false
32
+ */
33
+ it('should return `false` if an address file name does not match a chain type', () => {
34
+ const notMatchAssetName = 'contracts-awesomechain-testnet-1.json';
35
+ const isMatchingAssetName = isValidAssetName('mainnet')(notMatchAssetName);
36
+
37
+ expect(isMatchingAssetName).toEqual(false);
38
+ });
39
+
40
+ /**
41
+ * @target
42
+ * `isValidAssetName` should return `true` if a tokensMap file name matches a
43
+ * chain type
44
+ * @dependencies
45
+ * @scenario
46
+ * - get result by calling `isValidAssetName('mainnet')` with a mainnet
47
+ * tokensMap file name
48
+ * @expected
49
+ * - result should be true
50
+ */
51
+ it('should return `true` if a tokensMap file name matches a chain type', () => {
52
+ const matchAssetName = 'tokensMap-mainnet-1.json';
53
+ const isMatchingAssetName = isValidAssetName('mainnet')(matchAssetName);
54
+
55
+ expect(isMatchingAssetName).toEqual(true);
56
+ });
57
+
58
+ /**
59
+ * @target
60
+ * `isValidAssetName` should return `false` if a tokensMap file name does not
61
+ * match a chain type
62
+ * @dependencies
63
+ * @scenario
64
+ * - get result by calling `isValidAssetName('mainnet')` with a testnet
65
+ * tokensMap file name
66
+ * @expected
67
+ * - result should be false
68
+ */
69
+ it('should return `false` if a tokensMap file name does not match a chain type', () => {
70
+ const notMatchAssetName = 'tokensMap-testnet-1.json';
71
+ const isMatchingAssetName = isValidAssetName('mainnet')(notMatchAssetName);
72
+
73
+ expect(isMatchingAssetName).toEqual(false);
74
+ });
75
+
76
+ /**
77
+ * @target
78
+ * `isValidAssetName` should return false when asset name doesn't match Rosen
79
+ * format assets
80
+ * @dependencies
81
+ * @scenario
82
+ * - get result by calling `isValidAssetName('mainnet')` with an invalid asset
83
+ * file name
84
+ * @expected
85
+ * - result should be false
86
+ */
87
+ it("should return false when asset name doesn't match Rosen format assets", () => {
88
+ const invalidAssetName = 'invalid-name.json';
89
+ const isMatchingAssetName = isValidAssetName('mainnet')(invalidAssetName);
90
+
91
+ expect(isMatchingAssetName).toEqual(false);
92
+ });
93
+ });
94
+
95
+ describe('truncateAssetName', () => {
96
+ /**
97
+ * @target
98
+ * `truncateAssetName` should truncate contract file names correctly
99
+ * @dependencies
100
+ * @scenario
101
+ * - get result by calling `truncateAssetName` with a contract file name
102
+ * @expected
103
+ * - result should be truncated name
104
+ */
105
+ it('should truncate contract file names correctly', () => {
106
+ const addressAssetName = 'contracts-awesomechain-mainnet-1.json';
107
+ const truncatedName = truncateAssetName(addressAssetName);
108
+
109
+ expect(truncatedName).toEqual('contracts-awesomechain.json');
110
+ });
111
+
112
+ /**
113
+ * @target
114
+ * `truncateAssetName` should truncate tokensMap file names correctly
115
+ * @dependencies
116
+ * @scenario
117
+ * - get result by calling `truncateAssetName` with a tokensMap file name
118
+ * @expected
119
+ * - result should be truncated name
120
+ */
121
+ it('should truncate contract file names correctly', () => {
122
+ const tokensMapAssetName = 'tokensMap-mainnet-1.json';
123
+ const truncatedName = truncateAssetName(tokensMapAssetName);
124
+
125
+ expect(truncatedName).toEqual('tokensMap.json');
126
+ });
127
+
128
+ /**
129
+ * @target
130
+ * `truncateAssetName` should truncate asset name and append suffix correctly
131
+ * @dependencies
132
+ * @scenario
133
+ * - get result by calling `truncateAssetName` with an asset name
134
+ * @expected
135
+ * - result should be truncated name with suffix
136
+ */
137
+ it('should truncate asset name and append suffix correctly', () => {
138
+ const assetName = 'contracts-awesomechain-mainnet-1.json';
139
+ const truncatedNameWithSuffix = truncateAssetName(assetName, 'suffix');
140
+
141
+ expect(truncatedNameWithSuffix).toEqual(
142
+ 'contracts-awesomechain-suffix.json'
143
+ );
144
+ });
145
+ });
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": ["tests"]
4
+ }