-
Notifications
You must be signed in to change notification settings - Fork 36
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 #59 from cosmology-tech/fix/optional-param
Add chainName as optional param to utils
- Loading branch information
Showing
9 changed files
with
264 additions
and
113 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
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,86 @@ | ||
import { assets, chains } from 'chain-registry'; | ||
|
||
import { | ||
ChainRegistryChainUtil, | ||
ChainRegistryChainUtilOptions, | ||
ChainRegistryClient, | ||
ChainRegistryClientOptions | ||
} from '../src'; | ||
|
||
describe('tests for asset-list-util', () => { | ||
const assetLists = assets.filter( | ||
({ chain_name }) => chain_name === 'osmosis' | ||
); | ||
const chainInfos = chains.filter( | ||
({ chain_name }) => chain_name === 'osmosis' | ||
); | ||
|
||
const regOptions: ChainRegistryClientOptions = { | ||
chainNames: ['osmosis'], | ||
chains: chainInfos, | ||
assetLists | ||
}; | ||
|
||
const regClient = new ChainRegistryClient(regOptions); | ||
const chainInfo = regClient.getChainInfo('osmosis'); | ||
const options: ChainRegistryChainUtilOptions = { | ||
chainInfo, | ||
chainName: 'osmosis' | ||
}; | ||
const client = new ChainRegistryChainUtil(options); | ||
|
||
it('getAssetByDenom', () => { | ||
const asset = client.getAssetByDenom('uosmo'); | ||
expect(asset.base).toEqual('uosmo'); | ||
}); | ||
|
||
it('getDenomByCoinGeckoId', () => { | ||
const denom1 = client.getDenomByCoinGeckoId('osmosis'); | ||
expect(denom1).toEqual('uosmo'); | ||
const denom2 = client.getDenomByCoinGeckoId('ion'); | ||
expect(denom2).toEqual('uion'); | ||
}); | ||
|
||
it('getSymbolByChainDenom', () => { | ||
const denom1 = client.getSymbolByChainDenom('uosmo'); | ||
expect(denom1).toEqual('OSMO'); | ||
const denom2 = client.getSymbolByChainDenom('uion'); | ||
expect(denom2).toEqual('ION'); | ||
}); | ||
|
||
it('getChainDenomBySymbol', () => { | ||
const denom1 = client.getChainDenomBySymbol('OSMO'); | ||
expect(denom1).toEqual('uosmo'); | ||
const denom2 = client.getChainDenomBySymbol('ION'); | ||
expect(denom2).toEqual('uion'); | ||
}); | ||
|
||
it('getExponentByDenom', () => { | ||
const exponent = client.getExponentByDenom('uosmo'); | ||
expect(exponent).toEqual(6); | ||
}); | ||
|
||
it('convertBaseUnitsToDollarValue', () => { | ||
const value = client.convertBaseUnitsToDollarValue({ uosmo: 1 }, 'OSMO', 5); | ||
expect(value).toEqual('0.000005'); | ||
}); | ||
|
||
it('convertDollarValueToDenomUnits', () => { | ||
const value = client.convertDollarValueToDenomUnits( | ||
{ uosmo: 1 }, | ||
'OSMO', | ||
0.00001 | ||
); | ||
expect(value).toEqual('10'); | ||
}); | ||
|
||
it('convertBaseUnitsToDisplayUnits', () => { | ||
const value = client.convertBaseUnitsToDisplayUnits('OSMO', 99); | ||
expect(value).toEqual('0.000099'); | ||
}); | ||
|
||
it('uosmo coingecko id', () => { | ||
const id = client.getCoinGeckoIdByDenom('uosmo'); | ||
expect(id).toEqual('osmosis'); | ||
}); | ||
}); |
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
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.