Update test

This commit is contained in:
Mykola 2020-01-21 01:20:02 -08:00
parent 0f2a2b997b
commit 99c59d87a5
3 changed files with 20 additions and 13 deletions

View File

@ -1,6 +1,6 @@
import * as fs from "fs"
import * as path from "path"
import { ValidatorModel } from "./models";
const axios = require('axios')
const Web3 = require('web3')
const web3 = new Web3('ws://localhost:8546');
@ -125,4 +125,11 @@ export const calculateAspectRatioFit = (srcWidth: number, srcHeight: number, max
} catch {
return false
}
}
}
export const isValidatorHasAllKeys = (val: ValidatorModel): boolean => {
return typeof val.id === "string"
&& typeof val.name === "string"
&& typeof val.description === "string"
&& typeof val.website === "string"
}

View File

@ -23,9 +23,10 @@ import {
getChainBlacklistPath,
mapList,
findFiles,
isValidJSON
isValidJSON,
isValidatorHasAllKeys
} from "./helpers"
import { ValidatorModel } from "./models";
enum TickerType {
Token = "token",
Coin = "coin"
@ -135,16 +136,9 @@ describe(`Test "blockchains" folder`, () => {
stakingChains.forEach(chain => {
const validatorsList = JSON.parse(readFileSync(getChainValidatorsListPath(chain)))
test(`Make sure ${chain} validators list has correct structure`, () => {
validatorsList.forEach(val => {
const keys = Object.keys(val)
expect(keys.length, `Wrong keys amount`).toBeGreaterThanOrEqual(4)
keys.forEach(key => {
const type = typeof key
expect(type, `Wrong key type`).toBe("string")
})
validatorsList.forEach((val: ValidatorModel) => {
expect(isValidatorHasAllKeys(val), `Come key and/or type missing for validator ${JSON.stringify(val)}`).toBe(true)
})
})

6
src/test/models.ts Normal file
View File

@ -0,0 +1,6 @@
export interface ValidatorModel {
id: string,
name: string,
description: string,
website: string,
}