-
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.
Merge pull request #80 from cosmology-tech/feat/improve-api
improve chain-registry/cilent api
- Loading branch information
Showing
22 changed files
with
520 additions
and
716 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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import request from 'supertest'; | ||
|
||
import { ChainRegistryClient } from '../src/client'; | ||
|
||
const timeout = 30000; | ||
const host = 'https://raw.githubusercontent.com'; | ||
|
||
describe('Test chain registry urls', () => { | ||
it( | ||
'test urls generated by client', | ||
() => { | ||
const client = new ChainRegistryClient({ | ||
chainNames: ['osmosis', 'juno'] | ||
}); | ||
expect(client.urls.length).toEqual(5); | ||
|
||
return Promise.all( | ||
client.urls.map((url) => | ||
request(host) | ||
.get(url.slice(host.length)) | ||
.timeout(timeout) | ||
.expect(200) | ||
.then((response) => { | ||
expect(JSON.parse(response?.text).$schema).toBeDefined(); | ||
}) | ||
) | ||
); | ||
}, | ||
timeout | ||
); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { ChainRegistryClient } from '../src'; | ||
|
||
const timeout = 30000; | ||
const urls = [ | ||
'https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/chain.json', | ||
'https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/assetlist.json', | ||
'https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/assetlist.json', | ||
'https://raw.githubusercontent.com/cosmos/chain-registry/master/secretnetwork/assetlist.json', | ||
'https://raw.githubusercontent.com/cosmos/chain-registry/master/_IBC/juno-osmosis.json', | ||
'https://raw.githubusercontent.com/cosmos/chain-registry/master/_IBC/osmosis-secretnetwork.json' | ||
]; | ||
|
||
describe('Test client fetch', () => { | ||
let client: ChainRegistryClient; | ||
|
||
beforeAll((done) => { | ||
client = new ChainRegistryClient(); | ||
client.fetch({ urls }).then(() => done()); | ||
}, timeout); | ||
|
||
it( | ||
'Test chain registry', | ||
() => { | ||
expect(client.chains.length).toBe(1); | ||
expect(client.assetLists.length).toBe(3); | ||
expect(client.ibcInfo.length).toBe(2); | ||
}, | ||
timeout | ||
); | ||
|
||
it( | ||
'Test chain info', | ||
() => { | ||
const chainData = client.getChainFullData('osmosis'); | ||
const ibcAssetList = client.getChainIbcAssetList('osmosis'); | ||
expect(chainData.ibcAssetList).toEqual(ibcAssetList); | ||
|
||
const osmosis = client.getChain('osmosis'); | ||
expect(chainData.chain).toEqual(osmosis); | ||
|
||
const osmosisAssets = client.getChainAssetList('osmosis'); | ||
expect(chainData.assetList).toEqual(osmosisAssets); | ||
}, | ||
timeout | ||
); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
import nock from 'nock'; | ||
|
||
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'] | ||
} | ||
] | ||
}; | ||
import assets from '../../../__fixtures__/assets.json'; | ||
import chains from '../../../__fixtures__/chains.json'; | ||
import { ChainRegistryClient } from '../src/client'; | ||
|
||
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; | ||
let client: ChainRegistryClient; | ||
|
||
beforeAll(async () => { | ||
nockByChainName('osmosis', osmosisChainData, osmosisAssetlistData); | ||
client = new ChainRegistryClient({ | ||
chainNames: ['osmosis'] | ||
}); | ||
await client.fetchUrls(); | ||
nockByChainName('stargaze'); | ||
client = new ChainRegistryClient({ chainNames: ['stargaze'] }); | ||
await client.fetch(); | ||
}); | ||
|
||
afterAll(() => { | ||
nock.restore(); | ||
}); | ||
|
||
it('Test mock fetching chain data', () => { | ||
const chainInfo = client.getChainInfo('osmosis'); | ||
expect(chainInfo.chainName).toEqual('osmosis'); | ||
const chainData = client.getChain('stargaze'); | ||
expect(chainData?.chain_name).toEqual('stargaze'); | ||
}); | ||
|
||
it('Test mock fetching asset list', () => { | ||
const chainInfo = client.getChainInfo('osmosis'); | ||
expect(chainInfo.nativeAssetList.assets.length).toEqual(1); | ||
const assetList = client.getChainAssetList('stargaze'); | ||
expect(assetList?.assets.length).toEqual(1); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ChainRegistryClient } from '../src/client'; | ||
|
||
const timeout = 30000; | ||
|
||
describe('Test client', () => { | ||
let client: ChainRegistryClient; | ||
|
||
beforeAll(async () => { | ||
client = new ChainRegistryClient({ chainNames: ['osmosis'] }); | ||
await client.fetch(); | ||
}, timeout); | ||
|
||
it('Test fetching chain', () => { | ||
const chain = client.getChain('osmosis'); | ||
expect(chain?.chain_name).toEqual('osmosis'); | ||
}); | ||
|
||
it( | ||
'Test fetching chain ibc info', | ||
async () => { | ||
expect(client.ibcInfo.length).toEqual(0); | ||
|
||
await client.fetch({ chainNames: ['juno'] }); | ||
|
||
expect(client.urls.length).toEqual(5); | ||
expect(client.chains.length).toEqual(2); | ||
expect(client.ibcInfo.length).toEqual(1); | ||
expect(client.ibcInfo[0].chain_1.chain_name).toEqual('juno'); | ||
}, | ||
timeout | ||
); | ||
|
||
it('Test fetching asset list', () => { | ||
const chainData = client.getChainFullData('osmosis'); | ||
const assetList = client.getChainAssetList('osmosis'); | ||
expect(chainData.assetList).toEqual(assetList); | ||
}); | ||
|
||
it('Test chain utils', () => { | ||
const chainUtils = client.getChainUtils('osmosis'); | ||
const asset = chainUtils.getAssetByDenom('uosmo'); | ||
expect(asset.name).toEqual('Osmosis'); | ||
}); | ||
}); |
Oops, something went wrong.