|
| 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