Skip to content

Commit

Permalink
fix client tests not passing
Browse files Browse the repository at this point in the history
  • Loading branch information
marslavish committed Dec 19, 2023
1 parent 693050e commit 24aa0b8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
25 changes: 12 additions & 13 deletions packages/client/__tests__/client.api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,29 @@ describe('tests for asset-list-util', () => {
const client = new ChainRegistryChainUtil(options);

it('getAssetByDenom', () => {
expect(() => client.getAssetByDenom('uosmo')).toThrowError();
const asset = client.getAssetByDenom('uosmo');
expect(asset.base).toEqual('uosmo');
});

it('getDenomByCoinGeckoId', () => {
const denom1 = client.getDenomByCoinGeckoId('jackal');
expect(denom1).toEqual('ujkl');
const denom2 = client.getDenomByCoinGeckoId('stargaze');
expect(denom2).toEqual('ustars');
const denom1 = client.getDenomByCoinGeckoId('osmosis');
expect(denom1).toEqual('uosmo');
const denom2 = client.getDenomByCoinGeckoId('ion');
expect(denom2).toEqual('uion');
});

it('getSymbolByChainDenom', () => {
const denom1 = client.getSymbolByChainDenom('swth');
expect(denom1).toEqual('SWTH');
const denom2 = client.getSymbolByChainDenom('uusdc');
expect(denom2).toEqual('USDC');
const denom1 = client.getSymbolByChainDenom('uosmo');
expect(denom1).toEqual('OSMO');
const denom2 = client.getSymbolByChainDenom('uion');
expect(denom2).toEqual('ION');
});

it('getChainDenomBySymbol', () => {
const denom1 = client.getChainDenomBySymbol('OCTA');
expect(denom1).toEqual('uocta');
const denom2 = client.getChainDenomBySymbol('NOM');
expect(denom2).toEqual('unom');
const denom1 = client.getChainDenomBySymbol('OSMO');
expect(denom1).toEqual('uosmo');
const denom2 = client.getChainDenomBySymbol('ION');
expect(denom2).toEqual('uion');
});

it('getExponentByDenom', () => {
Expand Down
16 changes: 9 additions & 7 deletions packages/client/src/chain-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ export class ChainRegistryChainUtil {
constructor(options: ChainRegistryChainUtilOptions) {
this.chainName = options.chainName;
this.chainInfo = options.chainInfo;
this.allAsset = this.chainInfo.assetLists.reduce(
(m, it) => {
[].push.apply(m, it.assets);
return m;
},
[...this.chainInfo.nativeAssetLists.assets]
);
this.allAsset = [
{
assets: [
...this.chainInfo.nativeAssetLists.assets,
...this.chainInfo.assetLists.flatMap(({ assets }) => assets)
],
chain_name: this.chainName
}
];
}

getAssetByDenom(denom: CoinDenom): Asset {
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/src/asset-list-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function getCoinGeckoIdByDenom(
): string | null {
const filteredAssetLists = assets.filter(({ chain_name }) => {
return (
(!chainName || chainName == chainName) &&
(!chainName || chain_name === chainName) &&
(allowTestnet || !chain_name.includes('testnet')) &&
!excludedChainNames.includes(chain_name)
);
Expand Down Expand Up @@ -140,7 +140,7 @@ export function convertBaseUnitsToDollarValue(
): string {
const denom = getChainDenomBySymbol(assets, symbol, chainName);
return new BigNumber(amount)
.shiftedBy(-getExponentByDenom(assets, denom))
.shiftedBy(-getExponentByDenom(assets, denom, chainName))
.multipliedBy(prices[denom])
.toString();
}
Expand All @@ -155,7 +155,7 @@ export function convertDollarValueToDenomUnits(
const denom = getChainDenomBySymbol(assets, symbol, chainName);
return new BigNumber(value)
.dividedBy(prices[denom])
.shiftedBy(getExponentByDenom(assets, denom))
.shiftedBy(getExponentByDenom(assets, denom, chainName))
.toString();
}

Expand Down

0 comments on commit 24aa0b8

Please sign in to comment.