forked from trustwallet/assets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Internal] New infra for runnig checks (not as jest tests) (trustwall…
…et#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 <[email protected]>
- Loading branch information
Showing
48 changed files
with
1,500 additions
and
1,125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
}, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.