2020-07-29 13:42:51 +00:00
|
|
|
import { stakingChains } from "../common/blockchains";
|
2020-08-06 19:17:38 +00:00
|
|
|
import {
|
|
|
|
getChainValidatorsListPath,
|
|
|
|
getChainValidatorAssetLogoPath,
|
|
|
|
getChainValidatorsAssets
|
|
|
|
} from "../common/repo-structure";
|
|
|
|
import { isPathExistsSync } from "../common/filesystem";
|
|
|
|
import { formatSortJsonFile, readJsonFile } from "../common/json";
|
|
|
|
import { ActionInterface, CheckStepInterface } from "./interface";
|
|
|
|
import { isValidJSON } from "../common/json";
|
|
|
|
import { ValidatorModel } from "../common/validator-models";
|
|
|
|
import { isLogoOK } from "../common/image";
|
|
|
|
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[] {
|
|
|
|
return readJsonFile(getChainValidatorsListPath(chain));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-08-24 15:06:21 +00:00
|
|
|
var steps: CheckStepInterface[] = [
|
2020-08-06 19:17:38 +00:00
|
|
|
{
|
|
|
|
getName: () => { return "Make sure tests added for new staking chain"},
|
2020-08-24 15:06:21 +00:00
|
|
|
check: async (): Promise<[string, string]> => {
|
2020-08-06 19:17:38 +00:00
|
|
|
if (stakingChains.length != 7) {
|
2020-08-24 15:06:21 +00:00
|
|
|
return [`Wrong number of staking chains ${stakingChains.length}`, ""];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
2020-08-24 15:06:21 +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`},
|
|
|
|
check: async () => {
|
|
|
|
const validatorsListPath = getChainValidatorsListPath(chain);
|
|
|
|
if (!isValidJSON(validatorsListPath)) {
|
2020-08-24 15:06:21 +00:00
|
|
|
return [`Not valid Json file at path ${validatorsListPath}`, ""];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var error: string = "";
|
|
|
|
const validatorsList = getChainValidatorsList(chain);
|
|
|
|
const chainValidatorsAssetsList = getChainValidatorsAssets(chain);
|
|
|
|
await bluebird.each(validatorsList, async (val: ValidatorModel) => {
|
|
|
|
if (!isValidatorHasAllKeys(val)) {
|
|
|
|
error += `Some key and/or type missing for validator ${JSON.stringify(val)}\n`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const id = val.id;
|
|
|
|
const path = getChainValidatorAssetLogoPath(chain, id);
|
|
|
|
if (!isPathExistsSync(path)) {
|
|
|
|
error += `Chain ${chain} asset ${id} logo must be present at path ${path}\n`;
|
|
|
|
}
|
|
|
|
const [isOk, logoMsg] = await isLogoOK(path);
|
|
|
|
if (!isOk) {
|
|
|
|
error += logoMsg + "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure validator has corresponding logo
|
|
|
|
if (!(chainValidatorsAssetsList.indexOf(id) >= 0)) {
|
|
|
|
error += `Expecting image asset for validator ${id} on chain ${chain}\n`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Make sure validator asset logo has corresponding info
|
|
|
|
chainValidatorsAssetsList.forEach(valAssetLogoID => {
|
|
|
|
if (validatorsList.filter(v => v.id === valAssetLogoID).length != 1) {
|
|
|
|
error += `Expect validator logo ${valAssetLogoID} to have info\n`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-08-24 15:06:21 +00:00
|
|
|
return [error, ""];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
return steps;
|
|
|
|
}
|
|
|
|
|
2020-08-10 08:56:41 +00:00
|
|
|
getConsistencyChecks = null;
|
|
|
|
|
|
|
|
async sanityFix(): Promise<void> {
|
2020-08-06 19:17:38 +00:00
|
|
|
formatValidators();
|
|
|
|
}
|
|
|
|
|
2020-08-10 08:56:41 +00:00
|
|
|
consistencyFix = null;
|
|
|
|
|
2020-08-06 19:17:38 +00:00
|
|
|
update = null;
|
2020-07-29 13:42:51 +00:00
|
|
|
}
|