[internal] Script restructuring/refactoring (#4070)

* Make non-mandatory action interface elements optional.

* Remove one unused import

* Scripts main renamed to entrypoint.

* Script common rename to generic

* Move generic scripts from action to generic.

* Move chain-specific scripts to blockchain.

Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
Adam R 2020-09-23 15:47:24 +02:00 committed by GitHub
parent 242cb8aa44
commit ec1fe7f6ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 104 additions and 195 deletions

View File

@ -1,5 +1,5 @@
import { fail, warn, markdown } from "danger";
import { sanityCheckAll } from "./script/action/update-all";
import { sanityCheckAll } from "./script/generic/update-all";
sanityCheckAll().then(([errors, warnings]) => {
errors.forEach(err => fail(err));

View File

@ -5,11 +5,11 @@
"main": "index.js",
"scripts": {
"test": "jest",
"check": "ts-node ./script/main/check",
"check-sanity": "ts-node ./script/main/check-sanity",
"fix": "ts-node ./script/main/fix",
"fix-sanity": "ts-node ./script/main/fix-sanity",
"update": "ts-node ./script/main/update",
"check": "ts-node ./script/entrypoint/check",
"check-sanity": "ts-node ./script/entrypoint/check-sanity",
"fix": "ts-node ./script/entrypoint/fix",
"fix-sanity": "ts-node ./script/entrypoint/fix-sanity",
"update": "ts-node ./script/entrypoint/update",
"lint": "npx eslint . --ext .js,.jsx,.ts,.tsx"
},
"repository": {

View File

@ -4,16 +4,16 @@ import * as fs from "fs";
import * as path from "path";
import * as chalk from 'chalk';
import * as config from "../config";
import { ActionInterface, CheckStepInterface } from "./interface";
import { getChainAssetsPath } from "../common/repo-structure";
import { Binance } from "../common/blockchains";
import { readDirSync } from "../common/filesystem";
import { readJsonFile } from "../common/json";
import { ActionInterface, CheckStepInterface } from "../generic/interface";
import { getChainAssetsPath } from "../generic/repo-structure";
import { Binance } from "../generic/blockchains";
import { readDirSync } from "../generic/filesystem";
import { readJsonFile } from "../generic/json";
import {
getChainAssetLogoPath,
getChainDenylistPath
} from "../common/repo-structure";
} from "../generic/repo-structure";
const binanceChain = "binance";
const binanceUrlTokens2 = config.binanceUrlTokens2;
@ -121,12 +121,6 @@ export class BinanceAction implements ActionInterface {
},
];
}
getConsistencyChecks = null;
sanityFix = null;
consistencyFix = null;
async update(): Promise<void> {
// retrieve missing token images; BEP2 (bep8 not supported)

View File

@ -1,7 +1,7 @@
import { Cosmos } from "../common/blockchains";
import { getChainValidatorsAssets } from "../common/repo-structure";
import { ActionInterface, CheckStepInterface } from "./interface";
import { isLowerCase } from "../common/types";
import { Cosmos } from "../generic/blockchains";
import { getChainValidatorsAssets } from "../generic/repo-structure";
import { ActionInterface, CheckStepInterface } from "../generic/interface";
import { isLowerCase } from "../generic/types";
export class CosmosAction implements ActionInterface {
getName(): string { return "Cosmos chain"; }
@ -31,12 +31,4 @@ export class CosmosAction implements ActionInterface {
},
];
}
getConsistencyChecks = null;
sanityFix = null;
consistencyFix = null;
update = null;
}

View File

@ -1,7 +1,7 @@
import { Kava } from "../common/blockchains";
import { getChainValidatorsAssets } from "../common/repo-structure";
import { ActionInterface, CheckStepInterface } from "./interface";
import { isLowerCase } from "../common/types";
import { Kava } from "../generic/blockchains";
import { getChainValidatorsAssets } from "../generic/repo-structure";
import { ActionInterface, CheckStepInterface } from "../generic/interface";
import { isLowerCase } from "../generic/types";
export class KavaAction implements ActionInterface {
getName(): string { return "Kava chain"; }
@ -31,12 +31,4 @@ export class KavaAction implements ActionInterface {
},
];
}
getConsistencyChecks = null;
sanityFix = null;
consistencyFix = null;
update = null;
}

View File

@ -1,7 +1,7 @@
import { Terra } from "../common/blockchains";
import { getChainValidatorsAssets } from "../common/repo-structure";
import { ActionInterface, CheckStepInterface } from "./interface";
import { isLowerCase } from "../common/types";
import { Terra } from "../generic/blockchains";
import { getChainValidatorsAssets } from "../generic/repo-structure";
import { ActionInterface, CheckStepInterface } from "../generic/interface";
import { isLowerCase } from "../generic/types";
export class TerraAction implements ActionInterface {
getName(): string { return "Terra chain"; }
@ -31,12 +31,4 @@ export class TerraAction implements ActionInterface {
},
];
}
getConsistencyChecks = null;
sanityFix = null;
consistencyFix = null;
update = null;
}

View File

@ -5,12 +5,12 @@ import {
getChainValidatorsPath,
getChainValidatorsListPath,
getChainValidatorsAssets
} from "../common/repo-structure";
import { Tezos } from "../common/blockchains";
import { readFileSync } from "../common/filesystem";
import { writeJsonFile } from "../common/json";
import { ActionInterface, CheckStepInterface } from "./interface";
import { ValidatorModel } from "../common/validator-models";
} from "../generic/repo-structure";
import { Tezos } from "../generic/blockchains";
import { readFileSync } from "../generic/filesystem";
import { writeJsonFile } from "../generic/json";
import { ActionInterface, CheckStepInterface } from "../generic/interface";
import { ValidatorModel } from "../generic/validator-models";
interface BakingBadBaker {
address: string,
@ -96,12 +96,6 @@ export class TezosAction implements ActionInterface {
];
}
getConsistencyChecks = null;
sanityFix = null;
consistencyFix = null;
async update(): Promise<void> {
await gen_validators_tezos();
}

View File

@ -1,9 +1,9 @@
import { ActionInterface, CheckStepInterface } from "./interface";
import { getChainAssetsPath } from "../common/repo-structure";
import { Tron } from "../common/blockchains";
import { readDirSync, isPathExistsSync } from "../common/filesystem";
import { getChainAssetLogoPath, getChainValidatorsAssets } from "../common/repo-structure";
import { isLowerCase, isUpperCase } from "../common/types";
import { ActionInterface, CheckStepInterface } from "../generic/interface";
import { getChainAssetsPath } from "../generic/repo-structure";
import { Tron } from "../generic/blockchains";
import { readDirSync, isPathExistsSync } from "../generic/filesystem";
import { getChainAssetLogoPath, getChainValidatorsAssets } from "../generic/repo-structure";
import { isLowerCase, isUpperCase } from "../generic/types";
import * as bluebird from "bluebird";
export function isTRC10(str: string): boolean {
@ -55,12 +55,4 @@ export class TronAction implements ActionInterface {
}
];
}
getConsistencyChecks = null;
sanityFix = null;
consistencyFix = null;
update = null;
}

View File

@ -1,7 +1,7 @@
import { Waves } from "../common/blockchains";
import { getChainValidatorsAssets } from "../common/repo-structure";
import { ActionInterface, CheckStepInterface } from "./interface";
import { isLowerCase, isUpperCase } from "../common/types";
import { Waves } from "../generic/blockchains";
import { getChainValidatorsAssets } from "../generic/repo-structure";
import { ActionInterface, CheckStepInterface } from "../generic/interface";
import { isLowerCase, isUpperCase } from "../generic/types";
export function isWavesAddress(address: string): boolean {
return address.length == 35 &&
@ -30,12 +30,4 @@ export class WavesAction implements ActionInterface {
},
];
}
getConsistencyChecks = null;
sanityFix = null;
consistencyFix = null;
update = null;
}

View File

@ -1,4 +1,4 @@
import { sanityCheckAll } from "../action/update-all";
import { sanityCheckAll } from "../generic/update-all";
export async function main(): Promise<void> {
try {

View File

@ -1,4 +1,4 @@
import { sanityCheckAll, consistencyCheckAll } from "../action/update-all";
import { sanityCheckAll, consistencyCheckAll } from "../generic/update-all";
export async function main(): Promise<void> {
let returnCode = 0;

View File

@ -1,4 +1,4 @@
import { sanityFixAll } from "../action/update-all";
import { sanityFixAll } from "../generic/update-all";
export async function main(): Promise<void> {
try {

View File

@ -1,4 +1,4 @@
import { sanityFixAll, consistencyFixAll } from "../action/update-all";
import { sanityFixAll, consistencyFixAll } from "../generic/update-all";
export async function main(): Promise<void> {
try {

View File

@ -1,4 +1,4 @@
import { updateAll } from "../action/update-all";
import { updateAll } from "../generic/update-all";
export async function main(): Promise<void> {
try {

View File

@ -1,18 +1,18 @@
import { chainsWithDenylist } from "../common/blockchains";
import { chainsWithDenylist } from "../generic/blockchains";
import {
getChainAssetsList,
getChainAllowlistPath,
getChainDenylistPath
} from "../common/repo-structure";
import { readFileSync, writeFileSync } from "../common/filesystem";
} from "../generic/repo-structure";
import { readFileSync, writeFileSync } from "../generic/filesystem";
import {
arrayDiff,
arrayDiffNocase,
findCommonElementsOrDuplicates,
makeUnique
} from "../common/types";
import { ActionInterface, CheckStepInterface } from "./interface";
import { formatSortJson } from "../common/json";
} from "../generic/types";
import { ActionInterface, CheckStepInterface } from "../generic/interface";
import { formatSortJson } from "../generic/json";
import * as bluebird from "bluebird";
async function checkUpdateAllowDenyList(chain: string, checkOnly: boolean ): Promise<[boolean, string[], string[]]> {
@ -109,11 +109,7 @@ export class Allowlist implements ActionInterface {
return steps;
}
sanityFix = null;
async consistencyFix(): Promise<void> {
await bluebird.each(chainsWithDenylist, async (chain) => await checkUpdateAllowDenyList(chain, false));
}
update = null;
}

View File

@ -1,7 +1,7 @@
import { getChainAssetInfoPath } from "./repo-structure";
import { readFileSync, isPathExistsSync } from "./filesystem";
import { arrayDiff } from "./types";
import { isValidJSON } from "../common/json";
import { isValidJSON } from "../generic/json";
const requiredKeys = ["explorer", "name", "website", "short_description"];

View File

@ -1,4 +1,4 @@
import { ethForkChains } from "../common/blockchains";
import { ethForkChains } from "../generic/blockchains";
import {
getChainAssetsPath,
getChainAssetsList,
@ -10,18 +10,18 @@ import {
logoExtension,
logoFullName,
getChainAssetLogoPath
} from "../common/repo-structure";
import { formatJsonFile } from "../common/json";
} from "../generic/repo-structure";
import { formatJsonFile } from "../generic/json";
import {
getFileName,
getFileExt,
gitMove,
readDirSync,
isPathExistsSync,
} from "../common/filesystem";
import { toChecksum } from "../common/eth-web3";
import { ActionInterface, CheckStepInterface } from "./interface";
import { isAssetInfoOK } from "../common/asset-info";
} from "../generic/filesystem";
import { toChecksum } from "../generic/eth-web3";
import { ActionInterface, CheckStepInterface } from "../generic/interface";
import { isAssetInfoOK } from "../generic/asset-info";
import * as bluebird from "bluebird";
async function formatInfos() {
@ -105,14 +105,8 @@ export class EthForks implements ActionInterface {
return steps;
}
getConsistencyChecks = null;
async sanityFix(): Promise<void> {
await formatInfos();
await checkAddressChecksums();
}
consistencyFix = null;
update = null;
}

View File

@ -1,22 +1,21 @@
import {
readDirSync,
isPathExistsSync
} from "../common/filesystem";
import { CheckStepInterface, ActionInterface } from "./interface";
} from "../generic/filesystem";
import { CheckStepInterface, ActionInterface } from "../generic/interface";
import {
chainsPath,
getChainLogoPath,
getChainAssetsPath,
getChainAssetPath,
getChainAssetLogoPath,
getChainAssetInfoPath,
assetFolderAllowedFiles,
getChainFolderFilesList,
chainFolderAllowedFiles,
rootDirAllowedFiles
} from "../common/repo-structure";
import { isLogoOK } from "../common/image";
import { isLowerCase } from "../common/types";
} from "../generic/repo-structure";
import { isLogoOK } from "../generic/image";
import { isLowerCase } from "../generic/types";
import * as bluebird from "bluebird";
const foundChains = readDirSync(chainsPath)
@ -133,12 +132,4 @@ export class FoldersFiles implements ActionInterface {
}
];
}
getConsistencyChecks = null;
sanityFix = null;
consistencyFix = null;
update = null;
}

View File

@ -11,10 +11,10 @@ export interface ActionInterface {
// return check steps for sanity check (0, 1, or more)
getSanityChecks(): CheckStepInterface[];
// return check steps for consistenct check (0, 1, or more)
getConsistencyChecks(): CheckStepInterface[];
sanityFix(): Promise<void>;
consistencyFix(): Promise<void>;
update(): Promise<void>;
getConsistencyChecks?(): CheckStepInterface[];
sanityFix?(): Promise<void>;
consistencyFix?(): Promise<void>;
update?(): Promise<void>;
}
export enum FixCheckMode {

View File

@ -1,7 +1,7 @@
import { chainsPath } from "../common/repo-structure";
import { findFiles } from "../common/filesystem";
import { ActionInterface, CheckStepInterface } from "./interface";
import { isValidJSON } from "../common/json";
import { chainsPath } from "../generic/repo-structure";
import { findFiles } from "../generic/filesystem";
import { ActionInterface, CheckStepInterface } from "../generic/interface";
import { isValidJSON } from "../generic/json";
import * as bluebird from "bluebird";
export class JsonAction implements ActionInterface {
@ -27,12 +27,4 @@ export class JsonAction implements ActionInterface {
},
];
}
getConsistencyChecks = null;
sanityFix = null;
consistencyFix = null;
update = null;
}

View File

@ -6,14 +6,14 @@ import {
getChainAssetLogoPath,
getChainValidatorsListPath,
getChainValidatorAssetLogoPath
} from "../common/repo-structure";
} from "../generic/repo-structure";
import {
readDirSync,
readFileSync,
isPathExistsSync
} from "../common/filesystem";
import { checkResizeIfTooLarge } from "../common/image";
import { ActionInterface, CheckStepInterface } from "./interface";
} from "../generic/filesystem";
import { checkResizeIfTooLarge } from "../generic/image";
import { ActionInterface, CheckStepInterface } from "../generic/interface";
// return name of large logo, or empty
async function checkDownsize(chains, checkOnly: boolean): Promise<string[]> {
@ -89,14 +89,8 @@ export class LogoSize implements ActionInterface {
];
}
getConsistencyChecks = null;
async sanityFix(): Promise<void> {
const foundChains = readDirSync(chainsPath);
await checkDownsize(foundChains, false);
}
consistencyFix = null;
update = null;
}

View File

@ -1,17 +1,17 @@
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";
import { Allowlist } from "./allowlists";
import { ActionInterface, CheckStepInterface } from "./interface";
import { BinanceAction } from "../blockchain/binance";
import { CosmosAction } from "../blockchain/cosmos";
import { EthForks } from "../generic/eth-forks";
import { FoldersFiles } from "../generic/folders-and-files";
import { JsonAction } from "../generic/json-format";
import { KavaAction } from "../blockchain/kava";
import { LogoSize } from "../generic/logo-size";
import { TerraAction } from "../blockchain/terra";
import { TezosAction } from "../blockchain/tezos";
import { TronAction } from "../blockchain/tron";
import { Validators } from "../generic/validators";
import { WavesAction } from "../blockchain/waves";
import { Allowlist } from "../generic/allowlists";
import { ActionInterface, CheckStepInterface } from "../generic/interface";
import * as chalk from 'chalk';
import * as bluebird from "bluebird";

View File

@ -1,15 +1,15 @@
import { stakingChains } from "../common/blockchains";
import { stakingChains } from "../generic/blockchains";
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";
} 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";
import * as bluebird from "bluebird";
function formatValidators() {
@ -94,13 +94,7 @@ export class Validators implements ActionInterface {
return steps;
}
getConsistencyChecks = null;
async sanityFix(): Promise<void> {
formatValidators();
}
consistencyFix = null;
update = null;
}

View File

@ -1,17 +1,17 @@
import {
findDuplicates,
findCommonElementsOrDuplicates,
} from "../script/common/types";
} from "../script/generic/types";
import {
isChecksum,
toChecksum,
isEthereumAddress
} from "../script/common/eth-web3";
} from "../script/generic/eth-web3";
import {
isDimensionTooLarge,
isDimensionOK,
calculateTargetSize
} from "../script/common/image";
} from "../script/generic/image";
import {
sortElements,
makeUnique,
@ -19,8 +19,8 @@ import {
arrayDiffNocase,
arrayEqual,
reverseCase
} from "../script/common/types";
import { findImagesToFetch } from "../script/action/binance";
} from "../script/generic/types";
import { findImagesToFetch } from "../script/blockchain/binance";
describe("Test eth-web3 helpers", () => {
test(`Test isChecksum`, () => {
@ -116,7 +116,7 @@ describe("Test type helpers", () => {
});
});
describe("Test action binance", () => {
describe("Test blockchain binance", () => {
test(`Test findImagesToFetch`, () => {
const assetsInfoListNonexisting = [{asset: "A1", assetImg: "imgurl1"}, {asset: "A2", assetImg: "imgurl2"}];
const assetsInfoListExisting = [{asset: "BUSD-BD1", assetImg: "imgurlBUSD"}, {asset: "ETH-1C9", assetImg: "imgurlETH"}];