[Internal] Add check for valid values of status field (#5951)

* Add check for valid values of status field

* Ad dmissing new file

Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
Adam R 2021-03-17 11:51:03 +01:00 committed by GitHub
parent e4337f3e2a
commit 1042aa9e63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 43 additions and 10 deletions

View File

@ -6,6 +6,6 @@
"description": "-", "description": "-",
"website": "https://realt.co/product/10024-28-appoline-st-detroit-mi-48227/", "website": "https://realt.co/product/10024-28-appoline-st-detroit-mi-48227/",
"explorer": "https://etherscan.io/token/0x5807CA447851C98569c567963B25B1C83D41BeBc", "explorer": "https://etherscan.io/token/0x5807CA447851C98569c567963B25B1C83D41BeBc",
"status": "abandned", "status": "abandoned",
"id": "0x5807CA447851C98569c567963B25B1C83D41BeBc" "id": "0x5807CA447851C98569c567963B25B1C83D41BeBc"
} }

View File

@ -6,6 +6,6 @@
"description": "-", "description": "-",
"website": "", "website": "",
"explorer": "https://etherscan.io/token/0x58a5d3e4873A75B07fB3c7CF477EeBc44ea73B3B", "explorer": "https://etherscan.io/token/0x58a5d3e4873A75B07fB3c7CF477EeBc44ea73B3B",
"status": "abandonned", "status": "abandoned",
"id": "0x58a5d3e4873A75B07fB3c7CF477EeBc44ea73B3B" "id": "0x58a5d3e4873A75B07fB3c7CF477EeBc44ea73B3B"
} }

View File

@ -6,6 +6,6 @@
"description": "-", "description": "-",
"website": "", "website": "",
"explorer": "https://etherscan.io/token/0x6aCf5940974E2a935f3F4e4FEDAc798583eEE826", "explorer": "https://etherscan.io/token/0x6aCf5940974E2a935f3F4e4FEDAc798583eEE826",
"status": "abandone", "status": "abandoned",
"id": "0x6aCf5940974E2a935f3F4e4FEDAc798583eEE826" "id": "0x6aCf5940974E2a935f3F4e4FEDAc798583eEE826"
} }

View File

@ -6,6 +6,6 @@
"description": "This token has been deprecated and replaced with contract address 0xef6344de1fcfC5F48c30234C16c1389e8CdC572C", "description": "This token has been deprecated and replaced with contract address 0xef6344de1fcfC5F48c30234C16c1389e8CdC572C",
"website": "https://encrypgen.com", "website": "https://encrypgen.com",
"explorer": "https://etherscan.io/token/0x82b0E50478eeaFde392D45D1259Ed1071B6fDa81", "explorer": "https://etherscan.io/token/0x82b0E50478eeaFde392D45D1259Ed1071B6fDa81",
"status": "inactive", "status": "abandoned",
"id": "0x82b0E50478eeaFde392D45D1259Ed1071B6fDa81" "id": "0x82b0E50478eeaFde392D45D1259Ed1071B6fDa81"
} }

View File

@ -6,6 +6,6 @@
"description": "HNB aims to build a decentralized blockchain network where individuals and enterprises can exchange products and services with trust and security.", "description": "HNB aims to build a decentralized blockchain network where individuals and enterprises can exchange products and services with trust and security.",
"website": "https://hnb.eco", "website": "https://hnb.eco",
"explorer": "https://etherscan.io/token/0x9c197c4b58527fAAAb67CB35E3145166B23D242e", "explorer": "https://etherscan.io/token/0x9c197c4b58527fAAAb67CB35E3145166B23D242e",
"status": "abadoned", "status": "abandoned",
"id": "0x9c197c4b58527fAAAb67CB35E3145166B23D242e" "id": "0x9c197c4b58527fAAAb67CB35E3145166B23D242e"
} }

View File

@ -6,6 +6,6 @@
"description": "-", "description": "-",
"website": "", "website": "",
"explorer": "https://etherscan.io/token/0xdD6Bf56CA2ada24c683FAC50E37783e55B57AF9F", "explorer": "https://etherscan.io/token/0xdD6Bf56CA2ada24c683FAC50E37783e55B57AF9F",
"status": "bandoned", "status": "abandoned",
"id": "0xdD6Bf56CA2ada24c683FAC50E37783e55B57AF9F" "id": "0xdD6Bf56CA2ada24c683FAC50E37783e55B57AF9F"
} }

View File

@ -9,6 +9,7 @@ import { arrayDiff } from "./types";
import { isValidJSON, readJsonFile, writeJsonFile } from "../generic/json"; import { isValidJSON, readJsonFile, writeJsonFile } from "../generic/json";
import { ActionInterface, CheckStepInterface } from "../generic/interface"; import { ActionInterface, CheckStepInterface } from "../generic/interface";
import { CoinType } from "@trustwallet/wallet-core"; import { CoinType } from "@trustwallet/wallet-core";
import { isValidStatusValue } from "../generic/status-values";
import * as bluebird from "bluebird"; import * as bluebird from "bluebird";
const requiredKeys = ["name", "type", "symbol", "decimals", "description", "website", "explorer", "status", "id"]; const requiredKeys = ["name", "type", "symbol", "decimals", "description", "website", "explorer", "status", "id"];
@ -38,12 +39,12 @@ function isAssetInfoValid(info: unknown, path: string, address: string, chain: s
// type // type
if (chainFromAssetType(info['type'].toUpperCase()) !== chain ) { if (chainFromAssetType(info['type'].toUpperCase()) !== chain ) {
return [`Incorrect value for type '${info['type']}' '${chain}' '${path}`, "", fixedInfo]; return [`Incorrect value for type '${info['type']}' '${chain}' ${path}`, "", fixedInfo];
} }
if (info['type'] !== info['type'].toUpperCase()) { if (info['type'] !== info['type'].toUpperCase()) {
// type is correct value, but casing is wrong, fix // type is correct value, but casing is wrong, fix
if (checkOnly) { if (checkOnly) {
return ["", `Wrong casing for type '${info['type']}' '${chain}' '${path}`, fixedInfo]; return ["", `Wrong casing for type '${info['type']}' '${chain}' ${path}`, fixedInfo];
} }
// fix // fix
if (!fixedInfo) { fixedInfo = info; } if (!fixedInfo) { fixedInfo = info; }
@ -54,16 +55,21 @@ function isAssetInfoValid(info: unknown, path: string, address: string, chain: s
if (info['id'] != address) { if (info['id'] != address) {
if (checkOnly) { if (checkOnly) {
if (info['id'].toUpperCase() != address.toUpperCase()) { if (info['id'].toUpperCase() != address.toUpperCase()) {
return [`Incorrect value for id '${info['id']}' '${chain}' '${path}`, "", fixedInfo]; return [`Incorrect value for id '${info['id']}' '${chain}' ${path}`, "", fixedInfo];
} }
// is is correct value, but casing is wrong // is is correct value, but casing is wrong
return ["", `Wrong casing for id '${info['id']}' '${chain}' '${path}`, fixedInfo]; return ["", `Wrong casing for id '${info['id']}' '${chain}' ${path}`, fixedInfo];
} }
// fix // fix
if (!fixedInfo) { fixedInfo = info; } if (!fixedInfo) { fixedInfo = info; }
fixedInfo['id'] = address; fixedInfo['id'] = address;
} }
// status
if (!isValidStatusValue(info['status'])) {
return [`Invalid value for status field, '${info['status']}'`, "", fixedInfo]
}
const isKeys2CorrectType = const isKeys2CorrectType =
typeof info['description'] === "string" && info['description'] !== "" && typeof info['description'] === "string" && info['description'] !== "" &&
// website should be set (exception description='-' marks empty infos) // website should be set (exception description='-' marks empty infos)

View File

@ -0,0 +1,16 @@
// see https://developer.trustwallet.com/add_new_asset
const StatusValues: string[] = [
'active',
'spam',
'abandoned'
];
export function isValidStatusValue(value: string): boolean {
if (!value) {
return false;
}
if (!StatusValues.find(e => e === value)) {
return false;
}
return true;
}

View File

@ -21,6 +21,7 @@ import {
reverseCase reverseCase
} from "../script/generic/types"; } from "../script/generic/types";
import { findImagesToFetch } from "../script/blockchain/binance"; import { findImagesToFetch } from "../script/blockchain/binance";
import { isValidStatusValue } from "../script/generic/status-values";
describe("Test eth-address helpers", () => { describe("Test eth-address helpers", () => {
test(`Test isChecksum`, () => { test(`Test isChecksum`, () => {
@ -134,3 +135,13 @@ describe("Test blockchain binance", () => {
expect(findImagesToFetch([], []), `empty`).toEqual([]); expect(findImagesToFetch([], []), `empty`).toEqual([]);
}); });
}); });
describe("Test status-values", () => {
test(`Test status-values`, () => {
expect(isValidStatusValue("active")).toEqual(true);
expect(isValidStatusValue("abandoned")).toEqual(true);
expect(isValidStatusValue("invalidvalue")).toEqual(false);
expect(isValidStatusValue("ACTIVE")).toEqual(false);
expect(isValidStatusValue("")).toEqual(false);
});
});