Skip to content

Commit

Permalink
[Internal] New infra for runnig checks (not as jest tests) (#2938)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
optout21 and catenocrypt committed Aug 6, 2020
1 parent 4390942 commit 102f2b8
Show file tree
Hide file tree
Showing 48 changed files with 1,500 additions and 1,125 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/fix-dryrun.yml
Expand Up @@ -7,7 +7,7 @@ on:
pull_request:
branches: [master]
jobs:
scripts:
fix-dryrun:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -21,6 +21,8 @@ jobs:
- name: Show fix result (diff); run 'npm run fix' locally
if: success()
run: git status
- name: Run check
run: npm run check
- name: Run test
run: npm t

5 changes: 3 additions & 2 deletions .github/workflows/fix.yml
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches: [ master ]
jobs:
scripts:
fix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -18,8 +18,9 @@ jobs:
- name: Run fix script
run: npm run fix
- name: Show fix result (diff); run 'npm run fix' locally
if: success()
run: git status
- name: Run check
run: npm run check
- name: Run test
run: npm t
- name: Commit changes if any
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/periodic-update.yml
Expand Up @@ -4,7 +4,7 @@ on:
# Run twice per day (at 7:00UTC/12amPST, 19:00UTC/12pmPST)
- cron: '0 7,19 * * *'
jobs:
scripts:
preiodic-update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -21,6 +21,8 @@ jobs:
- name: Show fix result (diff); run 'npm run fix' locally
if: success()
run: git status
- name: Run check
run: npm run check
- name: Run test
run: npm t
- name: Commit changes test pased
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/pr-ci.yml
Expand Up @@ -15,4 +15,6 @@ jobs:
with:
node-version: '12.x'
- uses: bahmutov/npm-install@v1
- run: npm t
- name: Run check
run: npm run check
- run: npm t
2 changes: 1 addition & 1 deletion .github/workflows/s3_upload.yml
Expand Up @@ -4,7 +4,7 @@ on:
branches:
- master
jobs:
build:
upload-s3:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
@@ -1,4 +1,4 @@
name: Test
name: Check
on:
push:
branches: [ master ]
Expand All @@ -12,5 +12,7 @@ jobs:
node-version: 12
- name: Install Dependencies
run: npm ci
- name: Run check
run: npm run check
- name: Run test
run: npm t
2 changes: 1 addition & 1 deletion jest.config.js
@@ -1,6 +1,6 @@
module.exports = {
"roots": [
"<rootDir>/src"
"<rootDir>/test"
],
testMatch: [
"**/__tests__/**/*.+(ts|tsx|js)",
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"test": "jest",
"check": "ts-node ./script/main/check",
"fix": "ts-node ./script/main/fix",
"update": "ts-node ./script/main/update"
},
Expand Down
165 changes: 165 additions & 0 deletions pricing/coinmarketcap/check.ts
@@ -0,0 +1,165 @@
import { CheckStepInterface } from "../../script/action/interface";
import { readFileSync } from "../../script/common/filesystem";
import { mapTiker, TickerType } from "../../script-old/models";
import { isChecksum } from "../../script/common/eth-web3";
import { isTRC10, isTRC20 } from "../../script/action/tron";
import { retrieveAssetSymbols } from "../../script/action/binance";

export function getChecks(): CheckStepInterface[] {
const cmcMap: mapTiker[] = JSON.parse(readFileSync("./pricing/coinmarketcap/mapping.json"));
return [
{
getName: () => { return "Must have items";},
check: async () => {
if (cmcMap.length == 0) {
return `CMC map must have items`;
}
return "";
}
},
{
getName: () => { return `Items must be sorted by "id" in ascending order`;},
check: async () => {
var error: string = "";
cmcMap.forEach((el, i) => {
if (i > 0) {
const prevID = cmcMap[i - 1].id;
const curID = el.id;
if (curID < prevID) {
error += `Item ${curID} must be greather or equal to ${prevID}\n`;
}
}
});
return error;
}
},
{
getName: () => { return `Items must be sorted by "coin" in ascending order if have same "id"`;},
check: async () => {
var error: string = "";
cmcMap.forEach((el, i) => {
if (i > 0) {
const prevEl = cmcMap[i - 1]

const prevCoin = prevEl.coin
const prevID = cmcMap[i - 1].id

const curCoin = el.coin
const curID = el.id

if (prevID == curID) {
if (curCoin < prevCoin) {
error += `Item ${JSON.stringify(el)} must be greather or equal to ${JSON.stringify(prevEl)}\n`;
}
}

}
});
return error;
}
},
{
getName: () => { return "Properies value shoud not contain spaces";},
check: async () => {
var error: string = "";
cmcMap.forEach((el, i) => {
Object.keys(el).forEach(key => {
const val = el[key]
if (typeof val === "string") {
if (val.indexOf(" ") >= 0) {
error += ` Property value "${val}" should not contain space\n`;
}
}
})
});
return error;
}
},
{
getName: () => { return "Params should have value and correct type";},
check: async () => {
var error: string = "";
cmcMap.forEach((el) => {
const {coin, type, id, token_id} = el;
if (typeof coin !== "number") {
error += `Coin ${coin} must be type "number"\n`;
}
if (type !== "token" && type !== "coin") {
error += `Element with id ${id} has wrong type: "${type}"\n`;
}
if (type === "token") {
if (!token_id) {
error += `token_id ${token_id} with id ${id} must be type not empty\n`;
}
}
if (type === "coin") {
if ("token_in" in el) {
error += `Element with id ${id} should not have property "token_id"\n`;
}
}
});
return error;
}
},
{
getName: () => { return `"token_id" should be in correct format`;},
check: async () => {
var error: string = "";
const bep2Symbols = await retrieveAssetSymbols();
cmcMap.forEach((el) => {
const {coin, token_id, type, id} = el
switch (coin) {
case 60:
if (type === TickerType.Token) {
if (!isChecksum(token_id)) {
error += `"token_id" ${token_id} with id ${id} must be in checksum'n`;
}
}
break;
case 195:
if (type === TickerType.Token) {
if (!isTRC10(token_id) && !isTRC20(token_id)) {
error += `"token_id" ${token_id} with id ${id} must be in TRC10 or TRC20\n`;
}
}
break;
case 714:
if (type === TickerType.Token) {
if (!(bep2Symbols.indexOf(token_id) >= 0)) {
error += `"token_id" ${token_id} with id ${id} must be BEP2 symbol\n`;
}
}
break;
default:
break;
}
});
return error;
}
},
{
getName: () => { return `"token_id" shoud be unique`;},
check: async () => {
var error: string = "";
const mappedList = cmcMap.reduce((acm, val) => {
if (val.hasOwnProperty("token_id")) {
if (acm.hasOwnProperty(val.token_id)) {
acm[val.token_id] == ++acm[val.token_id]
} else {
acm[val.token_id] = 0
}
}
return acm
}, {});
cmcMap.forEach((el) => {
if (el.hasOwnProperty("token_id")) {
if (mappedList[el.token_id] > 0) {
error += `CMC map ticker with "token_id" ${el.token_id} shoud be unique'n`;
}
}
});
return error;
}
},
];
}
15 changes: 15 additions & 0 deletions pricing/coinmarketcap/cmc-action.ts
@@ -0,0 +1,15 @@
import { ActionInterface, CheckStepInterface } from "../../script/action/interface";
import { run } from "./script";
import { getChecks } from "./check";

export class Coinmarketcap implements ActionInterface {
getName(): string { return "Coinmarketcap mapping"; }

getChecks(): CheckStepInterface[] { return getChecks(); }

fix = null;

async update(): Promise<void> {
await run();
}
}
18 changes: 7 additions & 11 deletions pricing/coinmarketcap/script.ts
@@ -1,21 +1,21 @@
import { toChecksum } from "../../src/test/helpers"
const BluebirdPromise = require("bluebird")
const axios = require("axios")
const chalk = require('chalk')
const fs = require("fs")
const path = require('path')
const constants = require('bip44-constants')
import { readFileSync } from "../../script/common/filesystem";
import { ethForkChains } from "../../script/common/blockchains";
import {
readFileSync,
toChecksum,
getChainAssetLogoPath,
isPathExistsSync,
makeDirSync,
getChainAssetPath,
ethSidechains,
getChainBlacklist,
getChainWhitelist,
} from "../../src/test/helpers";
import { TickerType, mapTiker, PlatformType } from "../../src/test/models";
} from "../../script-old/helpers";
import { TickerType, mapTiker, PlatformType } from "../../script-old/models";

// Steps required to run this:
// 1. (Optional) CMC API key already setup, use yours if needed. Install script deps "npm i" if hasn't been run before.
Expand Down Expand Up @@ -62,7 +62,7 @@ const allContracts: mapTiker[] = [] // Temp storage for mapped assets
let bnbOwnerToSymbol = {} // e.g: bnb1tawge8u97slduhhtumm03l4xl4c46dwv5m9yzk: WISH-2D5
let bnbOriginalSymbolToSymbol = {} // e.g: WISH: WISH-2D5

async function run() {
export async function run() {
try {
await Promise.all([initState(), setBinanceTokens()])
const [totalCrypto, coins] = await Promise.all([getTotalActiveCryptocurrencies(), getTickers()])
Expand Down Expand Up @@ -196,7 +196,7 @@ async function initState () {
}

async function mapChainsAssetsLists() {
ethSidechains.forEach(chain => {
ethForkChains.forEach(chain => {
Object.assign(mappedChainsWhitelistAssets, {[chain]: {}})
Object.assign(mappedChainsBlacklistAssets, {[chain]: {}})

Expand Down Expand Up @@ -352,7 +352,3 @@ function log(string, cb?) {
// }
// })
// }

export async function update() {
await run();
}
15 changes: 8 additions & 7 deletions script-old/arrange_files.ts
@@ -1,14 +1,16 @@
import * as fs from "fs"
const isImage = require("is-image");
import { rootDirAllowedFiles } from "../script/common/repo-structure";
import { ethForkChains, Ethereum } from "../script/common/blockchains";
import {
getFileExt,
getFileName
} from "../script/common/filesystem";
import {
Ethereum,
chainsFolderPath,
ethSidechains,
getChainAssetPath,
getChainAssetsPath,
getChainPath,
getFileExt,
getFileName,
getRootDirFilesList,
isChecksum,
isEthereumAddress,
Expand All @@ -17,12 +19,11 @@ import {
logoExtension,
makeDirIfDoestExist,
readDirSync,
rootDirAllowedFiles,
toChecksum,
isDirContainLogo
} from "../src/test/helpers"
} from "./helpers"

ethSidechains.forEach(chain => {
ethForkChains.forEach(chain => {
const chainAssetsPath = getChainAssetsPath(chain)

readDirSync(chainAssetsPath).forEach(async asset => {
Expand Down
12 changes: 3 additions & 9 deletions script-old/gen_info.ts
@@ -1,17 +1,11 @@
const bluebird = require("bluebird")
const nestedProperty = require("nested-property");
import { writeFileSync, readDirSync } from "../script/common/filesystem";
import {
chainsFolderPath,
getChainInfoPath,
isChainInfoExistSync,
writeFileSync,
readDirSync,
readFileSync,
getChainAssetInfoPath,
getChainAssetsPath,
isPathExistsSync
} from "../src/test/helpers"
import { CoinInfoList } from "../src/test/models";
} from "./helpers"
import { CoinInfoList } from "./models";

const dafaultInfoTemplate: CoinInfoList =
{
Expand Down

0 comments on commit 102f2b8

Please sign in to comment.