Skip to content

Commit 6fa24d3

Browse files
committed
Add basic tests
These tests are really checking if expectations meet reality.
1 parent 4446dd5 commit 6fa24d3

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

src/utils/chains.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { config } from '@streamr/config'
2+
import { defaultChainKey } from '../consts'
3+
import { parsedChainConfigExtension } from './chainConfigExtension'
4+
import {
5+
getChainDisplayName,
6+
getChainKey,
7+
getMarketplaceChainConfigs,
8+
isChainKey,
9+
} from './chains'
10+
11+
describe('getChainKey', () => {
12+
it('defaults to the default chain key', () => {
13+
expect(getChainKey('whatever')).toEqual(defaultChainKey)
14+
15+
expect(getChainKey(0)).toEqual(defaultChainKey)
16+
})
17+
18+
it('extracts chain key by slug', () => {
19+
expect(getChainKey('amoy')).toEqual('polygonAmoy')
20+
})
21+
22+
it('is case insensitive', () => {
23+
expect(getChainKey('AMOY')).toEqual('polygonAmoy')
24+
25+
expect(getChainKey('POlyGON')).toEqual('polygon')
26+
27+
expect(getChainKey('polygonamoy')).toEqual('polygonAmoy')
28+
})
29+
30+
it('resolves a number to a chain key', () => {
31+
expect(getChainKey(137)).toEqual('polygon')
32+
33+
expect(getChainKey(100)).toEqual('gnosis')
34+
})
35+
})
36+
37+
describe('isChainKey', () => {
38+
it('correctly identifies chain keys', () => {
39+
expect(isChainKey('whatever')).toBe(false)
40+
41+
expect(isChainKey('polygon')).toBe(true)
42+
43+
expect(isChainKey('gnosis')).toBe(true)
44+
})
45+
})
46+
47+
describe('getChainDisplayName', () => {
48+
it('used custom naming for chains that we provide it for', () => {
49+
// Local config extension provides a custom value
50+
expect(parsedChainConfigExtension['polygonAmoy']?.displayName).toEqual('Amoy')
51+
52+
// Config provides a diffrent value
53+
expect(config.polygonAmoy.name).not.toEqual('Amoy')
54+
55+
// Ultimately local name counts
56+
expect(getChainDisplayName('polygonAmoy')).toEqual('Amoy')
57+
})
58+
})
59+
60+
describe('getMarketplaceChainConfigs', () => {
61+
it('gives a list of configs for given keys', () => {
62+
const [config0, config1, config2] = getMarketplaceChainConfigs('polygon')
63+
64+
expect(config0.id).toEqual(config.gnosis.id)
65+
66+
expect(config1.id).toEqual(config.polygon.id)
67+
68+
expect(config2).toBeUndefined()
69+
})
70+
71+
it('gives an empty list of configs if there are no marketplace chain keys provided', () => {
72+
expect(getMarketplaceChainConfigs('ethereum').length).toEqual(0)
73+
})
74+
})

0 commit comments

Comments
 (0)