trustwallet-assets/test/index.test.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

109 lines
5.9 KiB
TypeScript

import {
findDuplicate,
findCommonElementOrDuplicate,
} from "../script/common/types";
import {
isChecksum,
toChecksum
} from "../script/common/eth-web3";
import {
isDimensionTooLarge,
isDimensionOK,
calculateTargetSize
} from "../script/common/image";
import {
mapList,
sortElements,
makeUnique,
arrayDiff
} from "../script/common/types";
import { findImagesToFetch } from "../script/action/binance";
describe("Test eth-web3 helpers", () => {
test(`Test isChecksum`, () => {
expect(isChecksum("0x7Bb09bC8aDE747178e95B1D035ecBeEBbB18cFee"), `checksum`).toBe(true);
expect(isChecksum("0x7bb09bc8ade747178e95b1d035ecbeebbb18cfee"), `lowercase`).toBe(false);
expect(isChecksum("0x7Bb09bC8aDE747178e95B1D035ecBe"), `too short`).toBe(false);
});
test(`Test toChecksum`, () => {
expect(toChecksum("0x7bb09bc8ade747178e95b1d035ecbeebbb18cfee"), `from lowercase`).toEqual("0x7Bb09bC8aDE747178e95B1D035ecBeEBbB18cFee");
expect(toChecksum("0x7Bb09bC8aDE747178e95B1D035ecBeEBbB18cFee"), `from checksum`).toEqual("0x7Bb09bC8aDE747178e95B1D035ecBeEBbB18cFee");
});
});
describe("Test image helpers", () => {
test(`Test isDimensionTooLarge`, () => {
expect(isDimensionTooLarge(256, 256), `256x256`).toBe(false);
expect(isDimensionTooLarge(64, 64), `64x64`).toBe(false);
expect(isDimensionTooLarge(800, 800), `800x800`).toBe(true);
expect(isDimensionTooLarge(256, 800), `256x800`).toBe(true);
expect(isDimensionTooLarge(800, 256), `800x256`).toBe(true);
});
test(`Test isDimensionOK`, () => {
expect(isDimensionOK(256, 256), `256x256`).toBe(true);
expect(isDimensionOK(64, 64), `64x64`).toBe(true);
expect(isDimensionOK(800, 800), `800x800`).toBe(false);
expect(isDimensionOK(256, 800), `256x800`).toBe(false);
expect(isDimensionOK(800, 256), `800x256`).toBe(false);
expect(isDimensionOK(60, 60), `60x60`).toBe(false);
expect(isDimensionOK(64, 60), `64x60`).toBe(false);
expect(isDimensionOK(60, 64), `60x64`).toBe(false);
});
test(`Test calculateReducedSize`, () => {
expect(calculateTargetSize(256, 256, 512, 512), `small 1.0`).toEqual({width: 512, height: 512});
expect(calculateTargetSize(800, 800, 512, 512), `large 1.0`).toEqual({width: 512, height: 512});
expect(calculateTargetSize(200, 100, 512, 512), `small 2.0`).toEqual({width: 512, height: 256});
expect(calculateTargetSize(100, 200, 512, 512), `small 0.5`).toEqual({width: 256, height: 512});
expect(calculateTargetSize(1200, 600, 512, 512), `small 2.0`).toEqual({width: 512, height: 256});
expect(calculateTargetSize(600, 1200, 512, 512), `small 0.5`).toEqual({width: 256, height: 512});
expect(calculateTargetSize(256, 0, 512, 512), `zero`).toEqual({width: 512, height: 512});
});
});
describe("Test type helpers", () => {
test(`Test mapList`, () => {
expect(mapList(["a", "b", "c"]), `3 elems`).toEqual({"a": "", "b":"", "c": ""});
});
test(`Test sortElements`, () => {
expect(sortElements(["c", "a", "b"]), `3 elems`).toEqual(["a", "b", "c"]);
expect(sortElements(["C", "a", "b"]), `mixed case`).toEqual(["a", "b", "C"]);
expect(sortElements(["1", "2", "11"]), `numerical`).toEqual(["1", "2", "11"]);
expect(sortElements(["C", "a", "1", "b", "2", "11"]), `complex`).toEqual(["1", "2", "11", "a", "b", "C"]);
});
test(`Test makeUnique`, () => {
expect(makeUnique(["a", "b", "c", "b"]), `4 elems with 1 duplicate`).toEqual(["a", "b", "c"]);
});
test(`Test arrayDiff`, () => {
expect(arrayDiff(["a", "b", "c"], ["c"]), `4 elems with 1 duplicate`).toEqual(["a", "b"]);
});
test(`Test findDuplicate`, () => {
expect(findDuplicate(["a", "bb", "ccc"]), `No duplicates`).toBe(null)
expect(findDuplicate(["a", "bb", "ccc", "bb"]), `One double duplicate`).toBe("bb")
expect(findDuplicate([]), `Empty array`).toBe(null)
expect(findDuplicate(["a"]), `One element`).toBe(null)
expect(findDuplicate(["a", "bb", "ccc", "bb", "d", "bb"]), `One triple duplicate`).toBe("bb")
expect(findDuplicate(["a", "bb", "ccc", "bb", "a"]), `Two double duplicates`).toBe("a")
});
test(`Test findCommonElementOrDuplicate`, () => {
expect(findCommonElementOrDuplicate(["a", "bb", "ccc"], ["1", "22", "333"]), `No intersection or duplicates`).toBe(null)
expect(findCommonElementOrDuplicate(["a", "bb", "ccc"], ["1", "bb", "333"]), `Common element`).toBe("bb")
expect(findCommonElementOrDuplicate(["a", "bb", "ccc", "bb"], ["1", "22", "333"]), `Duplicate in first`).toBe("bb")
expect(findCommonElementOrDuplicate(["a", "bb", "ccc"], ["1", "22", "333", "22"]), `Duplicate in second`).toBe("22")
expect(findCommonElementOrDuplicate(["a", "bb", "ccc", "1", "bb"], ["1", "22", "333", "22"]), `Intersection and duplicates`).toBe("22")
expect(findCommonElementOrDuplicate([], []), `Empty lists`).toBe(null)
});
});
describe("Test action binance", () => {
test(`Test findImagesToFetch`, () => {
const assetsInfoListNonexisting: any[] = [{asset: "A1", assetImg: "imgurl1"}, {asset: "A2", assetImg: "imgurl2"}];
const assetsInfoListExisting: any[] = [{asset: "BUSD-BD1", assetImg: "imgurlBUSD"}, {asset: "ETH-1C9", assetImg: "imgurlETH"}];
const blackListEmpty: string[] = [];
const blackListA1: string[] = ["A1"];
expect(findImagesToFetch(assetsInfoListNonexisting, blackListEmpty), `2 nonexisting`).toEqual(assetsInfoListNonexisting);
expect(findImagesToFetch(assetsInfoListNonexisting, blackListA1), `2 nonexisting with 1 blacklisted`).toEqual([{asset: "A2", assetImg: "imgurl2"}]);
expect(findImagesToFetch(assetsInfoListExisting, blackListEmpty), `2 existing`).toEqual([]);
expect(findImagesToFetch([], []), `empty`).toEqual([]);
});
});