Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pyramation committed Dec 14, 2023
1 parent 899f598 commit 62453b1
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 4 deletions.
55 changes: 55 additions & 0 deletions packages/keplr/__tests__/__snapshots__/factory-tokens.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`config 1`] = `
{
"bech32Config": {
"bech32PrefixAccAddr": "pryzm",
"bech32PrefixAccPub": "pryzmpub",
"bech32PrefixConsAddr": "pryzmvalcons",
"bech32PrefixConsPub": "pryzmvalconspub",
"bech32PrefixValAddr": "pryzmvaloper",
"bech32PrefixValPub": "pryzmvaloperpub",
},
"bip44": {
"coinType": 118,
},
"chainId": "PRYZM_CHAIN_ID",
"chainName": "Pryzm Testnet",
"currencies": [
{
"coinDecimals": 6,
"coinDenom": "PRYZM",
"coinGeckoId": "pryzm",
"coinImageUrl": "https://raw.githubusercontent.com/cosmos/chain-registry/master/prism/images/prism-token.svg",
"coinMinimalDenom": "upryzm",
},
],
"features": [
"stargate",
"ibc-transfer",
],
"feeCurrencies": [
{
"coinDecimals": 6,
"coinDenom": "PRYZM",
"coinGeckoId": "pryzm",
"coinImageUrl": "https://raw.githubusercontent.com/cosmos/chain-registry/master/prism/images/prism-token.svg",
"coinMinimalDenom": "upryzm",
"gasPriceStep": {
"average": 0,
"high": 0.01,
"low": 0,
},
},
],
"rest": "",
"rpc": "",
"stakeCurrency": {
"coinDecimals": 6,
"coinDenom": "PRYZM",
"coinGeckoId": "pryzm",
"coinImageUrl": "https://raw.githubusercontent.com/cosmos/chain-registry/master/prism/images/prism-token.svg",
"coinMinimalDenom": "upryzm",
},
}
`;
91 changes: 91 additions & 0 deletions packages/keplr/__tests__/factory-tokens.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { chainRegistryChainToKeplr } from '@chain-registry/keplr';
import { AssetList, Chain } from '@chain-registry/types';
import { ChainInfo } from '@keplr-wallet/types';

const chain: Chain = {
chain_name: 'PRYZM_CHAIN_NAME',
chain_id: 'PRYZM_CHAIN_ID',
status: 'development',
network_type: 'testnet',
pretty_name: 'Pryzm Testnet',
bech32_prefix: 'pryzm',
slip44: 118,
staking: {
staking_tokens: [
{
denom: 'upryzm'
}
]
},
fees: {
fee_tokens: [
{
denom: 'upryzm',
fixed_min_gas_price: 0,
low_gas_price: 0,
average_gas_price: 0,
high_gas_price: 0.01
},
{
denom: 'factory/pryzm15k9s9p0ar0cx27nayrgk6vmhyec3lj7vkry7rx/uusdsim',
fixed_min_gas_price: 0,
low_gas_price: 0,
average_gas_price: 0,
high_gas_price: 0.01
}
]
}
};

const assets: AssetList = {
chain_name: 'PRYZM_CHAIN_NAME',
assets: [
{
description: 'Pryzm token',
denom_units: [
{
denom: 'upryzm',
exponent: 0
},
{
denom: 'pryzm',
exponent: 6
}
],
base: 'upryzm',
name: 'Pryzm',
display: 'pryzm',
symbol: 'PRYZM',
logo_URIs: {
png: 'https://raw.githubusercontent.com/cosmos/chain-registry/master/prism/images/prism-token.png',
svg: 'https://raw.githubusercontent.com/cosmos/chain-registry/master/prism/images/prism-token.svg'
},
coingecko_id: 'pryzm'
},
{
description: 'Another Pryzm token',
denom_units: [
{
denom: 'factory/pryzm15k9s9p0ar0cx27nayrgk6vmhyec3lj7vkry7rx/uusdsim',
exponent: 0
}
],
base: 'factory/pryzm15k9s9p0ar0cx27nayrgk6vmhyec3lj7vkry7rx/uusdsim',
name: 'Pryzm2',
display: 'pryzm2',
symbol: 'PRYZM2',
logo_URIs: {
png: 'https://raw.githubusercontent.com/cosmos/chain-registry/master/prism/images/prism-token.png',
svg: 'https://raw.githubusercontent.com/cosmos/chain-registry/master/prism/images/prism-token.svg'
},
coingecko_id: 'pryzm2'
}
]
};

const config: ChainInfo = chainRegistryChainToKeplr(chain, [assets]);

it('config', () => {
// console.log(config);
expect(config).toMatchSnapshot();
});
10 changes: 6 additions & 4 deletions packages/keplr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const getExplr = (chain: Chain): string => chain.explorers?.[0]?.url ?? '';
const cleanVer = (ver: string) => {
if (!semver.valid(ver)) {
// try to split by @ for repo@version
ver = ver.split("@").pop()
if (semver.valid(ver)) return ver
ver = ver.split('@').pop();
if (semver.valid(ver)) return ver;

const spaces = ver.split('.').length;
switch (spaces) {
case 1:
Expand All @@ -21,7 +21,9 @@ const cleanVer = (ver: string) => {
return ver + '.0';
case 3:
default:
throw new Error('contact maintainers: bad version');
throw new Error(
'contact @chain-registry/keplr maintainers: bad version'
);
}
}
};
Expand Down

0 comments on commit 62453b1

Please sign in to comment.