2018-03-02 01:24:14 +00:00
|
|
|
import { configuredStore } from 'store';
|
2018-01-11 06:47:48 +00:00
|
|
|
import TOKENS from 'config/tokens';
|
|
|
|
import { isValidETHAddress } from 'libs/validators';
|
2018-03-02 01:24:14 +00:00
|
|
|
configuredStore.getState();
|
2018-01-11 06:47:48 +00:00
|
|
|
|
|
|
|
describe('Tokens JSON', () => {
|
|
|
|
Object.keys(TOKENS).forEach(network => {
|
|
|
|
it(`${network} tokens array properly formatted`, () => {
|
2018-03-07 23:36:05 +00:00
|
|
|
const tokens = (TOKENS as any)[network];
|
|
|
|
const addressCollisionMap: any = {};
|
|
|
|
const symbolCollisionMap: any = {};
|
2018-04-13 17:14:29 +00:00
|
|
|
const validationErrors: string[] = [];
|
2018-01-11 06:47:48 +00:00
|
|
|
|
2018-03-07 23:36:05 +00:00
|
|
|
tokens.forEach((token: any) => {
|
2018-01-11 06:47:48 +00:00
|
|
|
if (!isValidETHAddress(token.address)) {
|
2018-04-13 17:14:29 +00:00
|
|
|
validationErrors.push(
|
|
|
|
`Token ${token.symbol} has invalid contract address '${token.address}'`
|
|
|
|
);
|
2018-01-11 06:47:48 +00:00
|
|
|
}
|
|
|
|
if (addressCollisionMap[token.address]) {
|
2018-04-13 17:14:29 +00:00
|
|
|
validationErrors.push(
|
2018-01-11 06:47:48 +00:00
|
|
|
`Token ${token.symbol} has the same address as ${addressCollisionMap[token.address]}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (symbolCollisionMap[token.symbol]) {
|
2018-04-13 17:14:29 +00:00
|
|
|
validationErrors.push(
|
2018-01-11 06:47:48 +00:00
|
|
|
`Symbol ${token.symbol} is repeated between tokens at ${token.address} and ${
|
|
|
|
symbolCollisionMap[token.symbol]
|
|
|
|
}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
token.decimal < 0 ||
|
|
|
|
token.decimal > 18 ||
|
|
|
|
token.decimal === null ||
|
|
|
|
token.decimal === undefined
|
|
|
|
) {
|
2018-04-13 17:14:29 +00:00
|
|
|
validationErrors.push(`Token ${token.symbol} has invalid decimal '${token.decimal}'`);
|
2018-01-11 06:47:48 +00:00
|
|
|
}
|
|
|
|
addressCollisionMap[token.address] = token.symbol;
|
|
|
|
symbolCollisionMap[token.symbol] = token.address;
|
|
|
|
});
|
2018-04-13 17:14:29 +00:00
|
|
|
if (validationErrors.length > 0) {
|
|
|
|
throw Error(validationErrors.join('\n'));
|
|
|
|
}
|
2018-01-11 06:47:48 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|