2020-08-06 19:17:38 +00:00
|
|
|
import { BinanceAction } from "./binance";
|
|
|
|
import { CosmosAction } from "./cosmos";
|
|
|
|
import { EthForks } from "./eth-forks";
|
|
|
|
import { FoldersFiles } from "./folders-and-files";
|
|
|
|
import { JsonAction } from "./json";
|
|
|
|
import { KavaAction } from "./kava";
|
|
|
|
import { LogoSize } from "./logo-size";
|
|
|
|
import { TerraAction } from "./terra";
|
|
|
|
import { TezosAction } from "./tezos";
|
|
|
|
import { TronAction } from "./tron";
|
|
|
|
import { Validators } from "./validators";
|
|
|
|
import { WavesAction } from "./waves";
|
2020-08-18 06:50:32 +00:00
|
|
|
import { Allowlist } from "./allowlists";
|
2020-08-06 19:17:38 +00:00
|
|
|
import { ActionInterface, CheckStepInterface } from "./interface";
|
|
|
|
import * as chalk from 'chalk';
|
|
|
|
import * as bluebird from "bluebird";
|
|
|
|
|
|
|
|
const actionList: ActionInterface[] = [
|
|
|
|
new FoldersFiles(),
|
|
|
|
new EthForks(),
|
|
|
|
new LogoSize(),
|
2020-08-18 06:50:32 +00:00
|
|
|
new Allowlist(),
|
2020-08-06 19:17:38 +00:00
|
|
|
new Validators(),
|
|
|
|
new JsonAction(),
|
|
|
|
// chains:
|
|
|
|
new BinanceAction(),
|
|
|
|
new CosmosAction(),
|
|
|
|
new KavaAction(),
|
|
|
|
new TerraAction(),
|
|
|
|
new TezosAction(),
|
|
|
|
new TronAction(),
|
2020-08-31 16:25:21 +00:00
|
|
|
new WavesAction()
|
2020-08-06 19:17:38 +00:00
|
|
|
];
|
|
|
|
|
2020-08-24 15:06:21 +00:00
|
|
|
async function checkStepList(steps: CheckStepInterface[]): Promise<[string[], string[]]> {
|
2020-08-12 08:03:28 +00:00
|
|
|
var errors: string[] = [];
|
2020-08-24 15:06:21 +00:00
|
|
|
var warnings: string[] = [];
|
2020-08-06 19:17:38 +00:00
|
|
|
await bluebird.each(steps, async (step) => {
|
|
|
|
try {
|
|
|
|
//console.log(` Running check step '${step.getName()}'...`);
|
2020-08-24 15:06:21 +00:00
|
|
|
const [error, warning] = await step.check();
|
2020-08-06 19:17:38 +00:00
|
|
|
if (error && error.length > 0) {
|
|
|
|
console.log(`- ${chalk.red('X')} '${step.getName()}': '${error}'`);
|
2020-08-12 08:03:28 +00:00
|
|
|
errors.push(`${step.getName()}: ${error}`);
|
2020-08-24 15:06:21 +00:00
|
|
|
}
|
|
|
|
if (warning && warning.length > 0) {
|
|
|
|
console.log(`- ${chalk.yellow('!')} '${step.getName()}': '${warning}'`);
|
|
|
|
warnings.push(`${step.getName()}: ${warning}`);
|
|
|
|
}
|
|
|
|
if (error.length == 0 && warning.length == 0) {
|
2020-08-06 19:17:38 +00:00
|
|
|
console.log(`- ${chalk.green('✓')} '${step.getName()}' OK`);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log(`- ${chalk.red('X')} '${step.getName()}': Caught error: ${error.message}`);
|
2020-08-12 08:03:28 +00:00
|
|
|
errors.push(`${step.getName()}: Exception: ${error.message}`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
});
|
2020-08-24 15:06:21 +00:00
|
|
|
return [errors, warnings];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
2020-08-24 15:06:21 +00:00
|
|
|
async function sanityCheckByActionList(actions: ActionInterface[]): Promise<[string[], string[]]> {
|
2020-08-10 08:56:41 +00:00
|
|
|
console.log("Running sanity checks...");
|
2020-08-12 08:03:28 +00:00
|
|
|
var errors: string[] = [];
|
2020-08-24 15:06:21 +00:00
|
|
|
var warnings: string[] = [];
|
2020-08-06 19:17:38 +00:00
|
|
|
await bluebird.each(actions, async (action) => {
|
|
|
|
try {
|
2020-08-10 08:56:41 +00:00
|
|
|
if (action.getSanityChecks) {
|
|
|
|
const steps = action.getSanityChecks();
|
2020-08-06 19:17:38 +00:00
|
|
|
if (steps && steps.length > 0) {
|
|
|
|
console.log(` Action '${action.getName()}' has ${steps.length} check steps`);
|
2020-08-24 15:06:21 +00:00
|
|
|
const [errors1, warnings1] = await checkStepList(steps);
|
2020-08-12 08:03:28 +00:00
|
|
|
if (errors1.length > 0) {
|
|
|
|
errors1.forEach(e => errors.push(e));
|
2020-08-24 15:06:21 +00:00
|
|
|
}
|
|
|
|
if (warnings1.length > 0) {
|
|
|
|
warnings1.forEach(w => warnings.push(w));
|
|
|
|
}
|
|
|
|
if (errors1.length == 0 && warnings1.length == 0) {
|
2020-08-06 19:17:38 +00:00
|
|
|
console.log(`- ${chalk.green('✓')} Action '${action.getName()}' OK, all ${steps.length} steps`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log(`- ${chalk.red('X')} '${action.getName()}' Caught error: ${error.message}`);
|
2020-08-12 08:03:28 +00:00
|
|
|
errors.push(`${action.getName()}: Exception: ${error.message}`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
});
|
2020-08-24 15:06:21 +00:00
|
|
|
console.log(`All sanity checks done, found ${errors.length} errors, ${warnings.length} warnings`);
|
|
|
|
return [errors, warnings];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
2020-08-24 15:06:21 +00:00
|
|
|
async function consistencyCheckByActionList(actions: ActionInterface[]): Promise<[string[], string[]]> {
|
2020-08-10 08:56:41 +00:00
|
|
|
console.log("Running consistency checks...");
|
2020-08-12 08:03:28 +00:00
|
|
|
var errors: string[] = [];
|
2020-08-24 15:06:21 +00:00
|
|
|
var warnings: string[] = [];
|
2020-08-10 08:56:41 +00:00
|
|
|
await bluebird.each(actions, async (action) => {
|
|
|
|
try {
|
|
|
|
if (action.getConsistencyChecks) {
|
|
|
|
const steps = action.getConsistencyChecks();
|
|
|
|
if (steps && steps.length > 0) {
|
|
|
|
console.log(` Action '${action.getName()}' has ${steps.length} check steps`);
|
2020-08-24 15:06:21 +00:00
|
|
|
const [errors1, warnings1] = await checkStepList(steps);
|
2020-08-12 08:03:28 +00:00
|
|
|
if (errors1.length > 0) {
|
|
|
|
errors1.forEach(e => errors.push(e));
|
2020-08-24 15:06:21 +00:00
|
|
|
}
|
|
|
|
if (warnings1.length > 0) {
|
|
|
|
warnings1.forEach(w => warnings.push(w));
|
|
|
|
}
|
|
|
|
if (errors1.length == 0 && warnings1.length == 0) {
|
2020-08-10 08:56:41 +00:00
|
|
|
console.log(`- ${chalk.green('✓')} Action '${action.getName()}' OK, all ${steps.length} steps`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log(`- ${chalk.red('X')} '${action.getName()}' Caught error: ${error.message}`);
|
2020-08-12 08:03:28 +00:00
|
|
|
errors.push(`${action.getName()}: Exception: ${error.message}`);
|
2020-08-10 08:56:41 +00:00
|
|
|
}
|
|
|
|
});
|
2020-08-24 15:06:21 +00:00
|
|
|
console.log(`All consistency checks done, found ${errors.length} errors, ${warnings.length} warnings`);
|
|
|
|
return [errors, warnings];
|
2020-08-10 08:56:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function sanityFixByList(actions: ActionInterface[]) {
|
|
|
|
console.log("Running sanity fixes...");
|
2020-08-06 19:17:38 +00:00
|
|
|
await bluebird.each(actions, async (action) => {
|
|
|
|
try {
|
2020-08-10 08:56:41 +00:00
|
|
|
if (action.sanityFix) {
|
|
|
|
console.log(`Sanity fix '${action.getName()}':`);
|
|
|
|
await action.sanityFix();
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log(`Caught error: ${error.message}`);
|
|
|
|
}
|
|
|
|
});
|
2020-08-10 08:56:41 +00:00
|
|
|
console.log("All sanity fixes done.");
|
|
|
|
}
|
|
|
|
|
|
|
|
async function consistencyFixByList(actions: ActionInterface[]) {
|
|
|
|
console.log("Running consistency fixes...");
|
|
|
|
await bluebird.each(actions, async (action) => {
|
|
|
|
try {
|
|
|
|
if (action.consistencyFix) {
|
|
|
|
console.log(`Sanity fix '${action.getName()}':`);
|
|
|
|
await action.consistencyFix();
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log(`Caught error: ${error.message}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
console.log("All consistency fixes done.");
|
2020-07-29 13:42:51 +00:00
|
|
|
}
|
|
|
|
|
2020-08-06 19:17:38 +00:00
|
|
|
async function updateByList(actions: ActionInterface[]) {
|
2020-07-29 13:42:51 +00:00
|
|
|
console.log("Running updates (using external data sources) ...");
|
2020-08-06 19:17:38 +00:00
|
|
|
await bluebird.each(actions, async (action) => {
|
|
|
|
try {
|
|
|
|
if (action.update) {
|
|
|
|
console.log(`Update '${action.getName()}':`);
|
|
|
|
await action.update();
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log(`Caught error: ${error.message}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
console.log("All updates done.");
|
|
|
|
}
|
|
|
|
|
2020-08-24 15:06:21 +00:00
|
|
|
export async function sanityCheckAll(): Promise<[string[], string[]]> {
|
2020-08-10 08:56:41 +00:00
|
|
|
return await sanityCheckByActionList(actionList);
|
|
|
|
}
|
|
|
|
|
2020-08-24 15:06:21 +00:00
|
|
|
export async function consistencyCheckAll(): Promise<[string[], string[]]> {
|
2020-08-10 08:56:41 +00:00
|
|
|
return await consistencyCheckByActionList(actionList);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function sanityFixAll() {
|
|
|
|
await sanityFixByList(actionList);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
2020-08-10 08:56:41 +00:00
|
|
|
export async function consistencyFixAll() {
|
|
|
|
await consistencyFixByList(actionList);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function updateAll() {
|
|
|
|
await updateByList(actionList);
|
2020-07-29 13:42:51 +00:00
|
|
|
}
|