Skip to content

Commit

Permalink
chore: add tests for caip map
Browse files Browse the repository at this point in the history
  • Loading branch information
blurpesec committed Feb 6, 2025
1 parent 7d7db48 commit 8ea0720
Show file tree
Hide file tree
Showing 3 changed files with 1,455 additions and 2 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"node": ">=14.0.0"
},
"scripts": {
"test": "node test"
"test": "node test && node ./test/caip.js",
"test:caip": "node ./test/caip.js"
},
"repository": {
"type": "git",
Expand All @@ -37,4 +38,4 @@
"ethereumjs-util": "^5.1.1",
"tape": "^4.6.3"
}
}
}
102 changes: 102 additions & 0 deletions test/caip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
const test = require("tape");
const contractMap = require("../buildindex.js");
const permittedFields = require("../permitted-fields.json");

const util = require("ethereumjs-util");
const fs = require("fs");
const path = require("path");

test("the object is parsable", function (t) {
t.equal(typeof contractMap, "object", "is an object");
t.end();
});

test("the eip155 accounts are valid checksum addresses", function (t) {
Object.keys(contractMap).forEach((caip19AssetId) => {
const idParts = caip19AssetId.split("/");
// ignore non-evm networks for validation for now
if (idParts[0].indexOf("eip155" === -1)) return;
const address = idParts[1].split(":")[1];
t.ok(
util.isValidChecksumAddress(address),
`Address should be valid checksum address: ${address}`,
);
});

t.end();
});

test("logos should correspond to an included web image file", function (t) {
Object.keys(contractMap).forEach((caip19AssetId) => {
const contract = contractMap[caip19AssetId];
if (!contract.logo) return;
const fileName = contract.logo;
t.ok(fs.existsSync(contract.logo), `file exists: "${fileName}"`);
});

t.end();
});

test("logos path names should be an svg", function (t) {
Object.keys(contractMap).forEach((caip19AssetId) => {
const contract = contractMap[caip19AssetId];
if (!contract.logo) return;
const fileName = contract.logo;
t.ok(fileName.includes(".svg"), `filename is an svg: "${fileName}"`);
});

t.end();
});

test("logos icon should not be empty", function (t) {
Object.keys(contractMap).forEach((caip19AssetId) => {
const contract = contractMap[caip19AssetId];
const logo = contract.logo;
t.notEqual(logo.length, 0);
});
t.end();
});

test("logos path names should not contain space", function (t) {
Object.keys(contractMap).forEach((caip19AssetId) => {
const contract = contractMap[caip19AssetId];
if (!contract.logo) return;
const fileName = contract.logo;
t.notOk(
fileName.includes(" "),
`filename does not include space: "${fileName}"`,
);
});

t.end();
});

test("symbols should be eleven or less characters", function (t) {
Object.keys(contractMap).forEach((caip19AssetId) => {
const contract = contractMap[caip19AssetId];
const symbol = contract.symbol;
if (symbol) {
t.notOk(
symbol.length > 11,
`symbol with more than 11 characters: "${symbol}"`,
);
}
});
t.end();
});

test("only permitted fields should be used", function (t) {
Object.keys(contractMap).forEach((caip19AssetId) => {
const contract = contractMap[caip19AssetId];

const fields = Object.keys(contract);
fields.forEach((field) => {
t.ok(
permittedFields.includes(field),
`${field} must be part of permitted fields.`,
);
});
});

t.end();
});
Loading

0 comments on commit 8ea0720

Please sign in to comment.