-
Notifications
You must be signed in to change notification settings - Fork 33
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 #40 from cosmology-tech/fix/client-property-camelcase
Fix/client property camelcase
- Loading branch information
Showing
12 changed files
with
417 additions
and
115 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 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,47 @@ | ||
import { | ||
ChainRegistryClient, | ||
ChainRegistryClientOptions | ||
} from '../src/registry'; | ||
|
||
const timeout = 30000; // miliseconds | ||
|
||
describe('Test client', () => { | ||
let client; | ||
beforeAll((done) => { | ||
const options: ChainRegistryClientOptions = { | ||
chainNames: ['osmosis'] | ||
}; | ||
|
||
client = new ChainRegistryClient(options); | ||
client.fetchUrls().then(() => done()); | ||
}, timeout); | ||
|
||
it( | ||
'Test fetching chain Info', | ||
() => { | ||
const chainInfo = client.getChainInfo('osmosis'); | ||
expect(chainInfo.chainName).toEqual('osmosis'); | ||
}, | ||
timeout | ||
); | ||
|
||
it( | ||
'Test chain util', | ||
() => { | ||
const chainUtil = client.getChainUtil('osmosis'); | ||
const asset = chainUtil.getAssetByDenom('uosmo'); | ||
expect(asset.name).toEqual('Osmosis'); | ||
}, | ||
timeout | ||
); | ||
|
||
it( | ||
'Test fetching asset list', | ||
() => { | ||
const chainInfo = client.getChainInfo('osmosis'); | ||
const generated = client.getGeneratedAssetLists('osmosis'); | ||
expect(chainInfo.assetLists).toEqual(generated); | ||
}, | ||
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,32 @@ | ||
import request from 'supertest'; | ||
|
||
import { ChainRegistryClient } from '../src/registry'; | ||
|
||
const timeout = 30000; // miliseconds | ||
|
||
describe('Test client', () => { | ||
it( | ||
'test urls generated by client', | ||
async () => { | ||
const client = new ChainRegistryClient({ | ||
chainNames: ['osmosis', 'juno'] | ||
}); | ||
expect(client.urls.length).toEqual(5); | ||
|
||
const host = 'https://raw.githubusercontent.com'; | ||
const responses = await Promise.all( | ||
client.urls.map((url) => | ||
request(host) | ||
.get(url.substring(host.length)) | ||
.timeout(timeout) | ||
.expect(200) | ||
) | ||
); | ||
|
||
responses?.forEach((res) => { | ||
expect(JSON.parse(res?.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,80 @@ | ||
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'] | ||
} | ||
] | ||
}; | ||
|
||
const baseUrl = 'https://raw.githubusercontent.com'; | ||
|
||
function nockByChainName(chainName: string, chainData, assetlistData) { | ||
const chainDataPath = `/cosmos/chain-registry/master/${chainName}/chain.json`; | ||
const assetlistDataPath = `/cosmos/chain-registry/master/${chainName}/assetlist.json`; | ||
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); | ||
client = new ChainRegistryClient({ | ||
chainNames: ['osmosis'] | ||
}); | ||
await client.fetchUrls(); | ||
}); | ||
|
||
it('Test mock fetching chain data', () => { | ||
const chainInfo = client.getChainInfo('osmosis'); | ||
expect(chainInfo.chainName).toEqual('osmosis'); | ||
}); | ||
|
||
it('Test mock fetching asset list', () => { | ||
const chainInfo = client.getChainInfo('osmosis'); | ||
expect(chainInfo.nativeAssetLists.assets.length).toEqual(1); | ||
}); | ||
}); |
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,57 @@ | ||
import { | ||
ChainRegistryFetcher, | ||
ChainRegistryFetcherOptions | ||
} from '../src/fetcher'; | ||
|
||
const timeout = 30000; // miliseconds | ||
|
||
describe('Test fetcher', () => { | ||
let fetcher; | ||
beforeAll((done) => { | ||
const options: ChainRegistryFetcherOptions = { | ||
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' | ||
] | ||
}; | ||
|
||
fetcher = new ChainRegistryFetcher(options); | ||
fetcher.fetchUrls().then(() => done()); | ||
}, timeout); | ||
|
||
it( | ||
'Test chain registry', | ||
(done) => { | ||
expect(fetcher.chains.length).toBe(1); | ||
expect(fetcher.assetLists.length).toBe(3); | ||
done(); | ||
}, | ||
timeout | ||
); | ||
|
||
it( | ||
'Test chain info', | ||
(done) => { | ||
const chainInfo = fetcher.getChainInfo('osmosis'); | ||
const generated = fetcher.getGeneratedAssetLists('osmosis'); | ||
expect(chainInfo.assetLists).toEqual(generated); | ||
|
||
const osmosis = fetcher.getChain('osmosis'); | ||
expect(chainInfo.chain).toEqual(osmosis); | ||
|
||
const osmosisAssets = fetcher.getChainAssetList('osmosis'); | ||
expect(chainInfo.nativeAssetLists).toEqual(osmosisAssets); | ||
|
||
const num = osmosisAssets.assets.length; | ||
const numGenerated = generated[0].assets.length; | ||
expect(numGenerated > num).toBe(true); | ||
|
||
done(); | ||
}, | ||
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
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
Oops, something went wrong.