trustwallet-assets/script/action/eth-forks.ts
Adam R 102f2b88d4
[Internal] New infra for runnig checks (not as jest tests) (#2938)
* CMC mapping update.

* New check infrastructure, move root folder test to new infra.

* Move list of allowed files to config.

* Include new check in other tests.

* More generic way to call checks.

* Organize fix and update actions behind interfaces.

* Organize checks into steps, multiple steps per action.

* Simplify checkStep class/instance creation.

* Migrate chain logo checks.

* Migrate asset folder check.

* Migrate further chain checks.

* Migrate eth fork folder checks.

* Migrate binance chain check.

* Extra output.

* Output improvements.

* Async fix.

* Migrate Tron check.

* Add Tron check.

* Remove Tron check from old.

* White/blacklist check in new intra, combined with fix.

* Refine ETH checks.

* Remove from old infra.

* Migrate CMC check to new infra.

* Migrate validator tests to new check infra.

* Migrate Json files validity check to new check infra.

* Whitelist check fix.

* Cleanup helpers.ts.

* Move helpers.ts.

* Cleanup of models.ts.

* Move models.ts.

* Move index.test.ts.

* Update with BEP8 support.

* Descriptive names for jobs within the builds.

Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
2020-08-06 21:17:38 +02:00

119 lines
4.5 KiB
TypeScript

import { ethForkChains } from "../common/blockchains";
import {
getChainAssetsPath,
getChainAssetsList,
getChainAssetPath,
getChainAssetInfoPath,
getChainAssetFilesList,
isChainAssetInfoExistSync,
logoName,
logoExtension,
logoFullName,
getChainAssetLogoPath
} from "../common/repo-structure";
import { formatJsonFile } from "../common/json";
import {
getFileName,
getFileExt,
gitMove,
readDirSync,
isPathExistsSync,
} from "../common/filesystem";
import { isChecksum, toChecksum } from "../common/eth-web3";
import { ActionInterface, CheckStepInterface } from "./interface";
import { isLogoOK } from "../common/image";
import { isAssetInfoOK } from "../common/asset-info";
import * as bluebird from "bluebird";
function formatInfos() {
console.log(`Formatting info files...`);
ethForkChains.forEach(chain => {
let count: number = 0;
const chainAssets = getChainAssetsList(chain);
chainAssets.forEach(address => {
if (isChainAssetInfoExistSync(chain, address)) {
const chainAssetInfoPath = getChainAssetInfoPath(chain, address);
formatJsonFile(chainAssetInfoPath, true);
++count;
}
})
console.log(`Formatted ${count} info files for chain ${chain} (total ${chainAssets.length})`);
})
}
function checkAddressChecksum(assetsFolderPath: string, address: string) {
if (!isChecksum(address)) {
const checksumAddress = toChecksum(address);
gitMove(assetsFolderPath, address, checksumAddress);
console.log(`Renamed to checksum format ${checksumAddress}`);
}
}
function checkAddressChecksums() {
console.log(`Checking for checksum formats ...`);
ethForkChains.forEach(chain => {
const assetsPath = getChainAssetsPath(chain);
readDirSync(assetsPath).forEach(address => {
getChainAssetFilesList(chain, address).forEach(file => {
if (getFileName(file) == logoName && getFileExt(file) !== logoExtension) {
console.log(`Renaming incorrect asset logo extension ${file} ...`);
gitMove(getChainAssetPath(chain, address), file, logoFullName);
}
});
checkAddressChecksum(assetsPath, address);
});
});
}
export class EthForks implements ActionInterface {
getName(): string { return "Ethereum forks"; }
getChecks(): CheckStepInterface[] {
var steps: CheckStepInterface[] = [];
ethForkChains.forEach(chain => {
steps.push(
{
getName: () => { return `Folder structure for chain ${chain} (ethereum fork)`;},
check: async () => {
var error: string = "";
const assetsFolder = getChainAssetsPath(chain);
const assetsList = getChainAssetsList(chain);
console.log(` Found ${assetsList.length} assets for chain ${chain}`);
await bluebird.each(assetsList, async (address) => {
const assetPath = `${assetsFolder}/${address}`;
if (!isPathExistsSync(assetPath)) {
error += `Expect directory at path: ${assetPath}\n`;
}
if (!isChecksum(address)) {
error += `Expect asset at path ${assetPath} in checksum\n`;
}
const assetLogoPath = getChainAssetLogoPath(chain, address);
if (!isPathExistsSync(assetLogoPath)) {
error += `Missing file at path '${assetLogoPath}'\n`;
}
const [isOK, dimensionMsg] = await isLogoOK(assetLogoPath);
if (!isOK) {
error += dimensionMsg + "\n";
}
const [isInfoOK, infoMsg] = isAssetInfoOK(chain, address);
if (!isInfoOK) {
error += infoMsg + "\n";
}
});
return error;
}
}
);
});
return steps;
}
async fix(): Promise<void> {
formatInfos();
checkAddressChecksums();
}
update = null;
}