2020-09-23 13:47:24 +00:00
|
|
|
import { stakingChains } from "../generic/blockchains";
|
2020-08-06 19:17:38 +00:00
|
|
|
import {
|
|
|
|
getChainValidatorsListPath,
|
|
|
|
getChainValidatorAssetLogoPath,
|
|
|
|
getChainValidatorsAssets
|
2020-09-23 13:47:24 +00:00
|
|
|
} from "../generic/repo-structure";
|
|
|
|
import { isPathExistsSync } from "../generic/filesystem";
|
|
|
|
import { formatSortJsonFile, readJsonFile } from "../generic/json";
|
|
|
|
import { ActionInterface, CheckStepInterface } from "../generic/interface";
|
|
|
|
import { isValidJSON } from "../generic/json";
|
|
|
|
import { ValidatorModel } from "../generic/validator-models";
|
|
|
|
import { isLogoOK } from "../generic/image";
|
2020-08-06 19:17:38 +00:00
|
|
|
import * as bluebird from "bluebird";
|
2020-07-29 13:42:51 +00:00
|
|
|
|
|
|
|
function formatValidators() {
|
|
|
|
stakingChains.forEach(chain => {
|
|
|
|
const validatorsPath = getChainValidatorsListPath(chain);
|
|
|
|
formatSortJsonFile(validatorsPath);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-08-06 19:17:38 +00:00
|
|
|
function getChainValidatorsList(chain: string): ValidatorModel[] {
|
2020-09-18 14:39:31 +00:00
|
|
|
return readJsonFile(getChainValidatorsListPath(chain)) as ValidatorModel[];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isValidatorHasAllKeys(val: ValidatorModel): boolean {
|
|
|
|
return typeof val.id === "string"
|
|
|
|
&& typeof val.name === "string"
|
|
|
|
&& typeof val.description === "string"
|
|
|
|
&& typeof val.website === "string";
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Validators implements ActionInterface {
|
|
|
|
getName(): string { return "Validators"; }
|
|
|
|
|
2020-08-10 08:56:41 +00:00
|
|
|
getSanityChecks(): CheckStepInterface[] {
|
2020-09-18 14:39:31 +00:00
|
|
|
const steps: CheckStepInterface[] = [
|
2020-08-06 19:17:38 +00:00
|
|
|
{
|
|
|
|
getName: () => { return "Make sure tests added for new staking chain"},
|
2020-09-16 12:52:10 +00:00
|
|
|
check: async (): Promise<[string[], string[]]> => {
|
2020-08-31 20:55:31 +00:00
|
|
|
if (stakingChains.length != 8) {
|
2020-09-16 12:52:10 +00:00
|
|
|
return [[`Wrong number of staking chains ${stakingChains.length}`], []];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
2020-09-16 12:52:10 +00:00
|
|
|
return [[], []];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
];
|
|
|
|
stakingChains.forEach(chain => {
|
|
|
|
steps.push(
|
|
|
|
{
|
|
|
|
getName: () => { return `Make sure chain ${chain} has valid list file, has logo`},
|
2020-09-16 12:52:10 +00:00
|
|
|
check: async (): Promise<[string[], string[]]> => {
|
2020-08-06 19:17:38 +00:00
|
|
|
const validatorsListPath = getChainValidatorsListPath(chain);
|
|
|
|
if (!isValidJSON(validatorsListPath)) {
|
2020-09-16 12:52:10 +00:00
|
|
|
return [[`Not valid Json file at path ${validatorsListPath}`], []];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 14:39:31 +00:00
|
|
|
const errors: string[] = [];
|
2020-08-06 19:17:38 +00:00
|
|
|
const validatorsList = getChainValidatorsList(chain);
|
|
|
|
const chainValidatorsAssetsList = getChainValidatorsAssets(chain);
|
|
|
|
await bluebird.each(validatorsList, async (val: ValidatorModel) => {
|
|
|
|
if (!isValidatorHasAllKeys(val)) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`Some key and/or type missing for validator ${JSON.stringify(val)}`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const id = val.id;
|
|
|
|
const path = getChainValidatorAssetLogoPath(chain, id);
|
|
|
|
if (!isPathExistsSync(path)) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`Chain ${chain} asset ${id} logo must be present at path ${path}`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
const [isOk, logoMsg] = await isLogoOK(path);
|
|
|
|
if (!isOk) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(logoMsg);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure validator has corresponding logo
|
|
|
|
if (!(chainValidatorsAssetsList.indexOf(id) >= 0)) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`Expecting image asset for validator ${id} on chain ${chain}`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Make sure validator asset logo has corresponding info
|
|
|
|
chainValidatorsAssetsList.forEach(valAssetLogoID => {
|
|
|
|
if (validatorsList.filter(v => v.id === valAssetLogoID).length != 1) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`Expect validator logo ${valAssetLogoID} to have info`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-09-16 12:52:10 +00:00
|
|
|
return [errors, []];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
return steps;
|
|
|
|
}
|
|
|
|
|
2020-08-10 08:56:41 +00:00
|
|
|
async sanityFix(): Promise<void> {
|
2020-08-06 19:17:38 +00:00
|
|
|
formatValidators();
|
|
|
|
}
|
2020-07-29 13:42:51 +00:00
|
|
|
}
|