-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f414e6
commit c6dc7f3
Showing
1 changed file
with
17 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,44 @@ | ||
import nock from 'nock'; | ||
|
||
import assets from '../../../__fixtures__/assets.json'; | ||
import chains from '../../../__fixtures__/chains.json'; | ||
import { ChainRegistryClient } from '../src/registry'; | ||
|
||
const osmosisChainData = { | ||
$schema: '../chain.schema.json', | ||
chain_name: 'osmosis', | ||
status: 'live', | ||
network_type: 'mainnet', | ||
website: 'https://osmosis.zone/', | ||
update_link: | ||
'https://raw.githubusercontent.com/osmosis-labs/osmosis/main/chain.schema.json', | ||
pretty_name: 'Osmosis', | ||
chain_id: 'osmosis-1', | ||
bech32_prefix: 'osmo', | ||
daemon_name: 'osmosisd', | ||
node_home: '$HOME/.osmosisd', | ||
key_algos: ['secp256k1'], | ||
slip44: 118 | ||
}; | ||
|
||
const osmosisAssetlistData = { | ||
$schema: '../assetlist.schema.json', | ||
chain_name: 'osmosis', | ||
assets: [ | ||
{ | ||
description: 'The native token of Osmosis', | ||
denom_units: [ | ||
{ | ||
denom: 'uosmo', | ||
exponent: 0 | ||
}, | ||
{ | ||
denom: 'osmo', | ||
exponent: 6 | ||
} | ||
], | ||
base: 'uosmo', | ||
name: 'Osmosis', | ||
display: 'osmo', | ||
symbol: 'OSMO', | ||
logo_URIs: { | ||
png: 'https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/osmo.png', | ||
svg: 'https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/osmo.svg' | ||
}, | ||
coingecko_id: 'osmosis', | ||
keywords: ['dex', 'staking'] | ||
} | ||
] | ||
}; | ||
|
||
const baseUrl = 'https://raw.githubusercontent.com'; | ||
|
||
function nockByChainName(chainName: string, chainData, assetlistData) { | ||
function nockByChainName(chainName: string) { | ||
const chainDataPath = `/cosmos/chain-registry/master/${chainName}/chain.json`; | ||
const assetlistDataPath = `/cosmos/chain-registry/master/${chainName}/assetlist.json`; | ||
|
||
const chainData = chains.find((chain) => chain.chain_name === chainName); | ||
const assetlistData = assets.find((asset) => asset.chain_name === chainName); | ||
|
||
nock(baseUrl).get(chainDataPath).reply(200, chainData); | ||
nock(baseUrl).get(assetlistDataPath).reply(200, assetlistData); | ||
} | ||
|
||
describe('Test client', () => { | ||
let client; | ||
|
||
beforeAll(async () => { | ||
nockByChainName('osmosis', osmosisChainData, osmosisAssetlistData); | ||
nockByChainName('stargaze'); | ||
client = new ChainRegistryClient({ | ||
chainNames: ['osmosis'] | ||
chainNames: ['stargaze'] | ||
}); | ||
await client.fetchUrls(); | ||
}); | ||
|
||
afterAll(() => { | ||
nock.restore(); | ||
}); | ||
|
||
it('Test mock fetching chain data', () => { | ||
const chainInfo = client.getChainInfo('osmosis'); | ||
expect(chainInfo.chainName).toEqual('osmosis'); | ||
const chainInfo = client.getChainInfo('stargaze'); | ||
expect(chainInfo.chainName).toEqual('stargaze'); | ||
}); | ||
|
||
it('Test mock fetching asset list', () => { | ||
const chainInfo = client.getChainInfo('osmosis'); | ||
const chainInfo = client.getChainInfo('stargaze'); | ||
expect(chainInfo.nativeAssetList.assets.length).toEqual(1); | ||
}); | ||
}); |