Skip to content

Commit

Permalink
feat: script'n'test
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Mar 27, 2024
1 parent d353e03 commit 8b53bbe
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 175 deletions.
19 changes: 10 additions & 9 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ Please review the following token assets:
## 📑 Description

<!-- Some basic information about the token you want to add -->
- Token Name: ...
- Project Website: https://... <!-- ⚠️ Your website MUST contain of the token address or the PR will be rejected -->
- Explorer URI: https://...

- Token Name: ...
- Project Website: https://... <!-- ⚠️ Your website MUST contain of the token address or the PR will be rejected -->
- Explorer URI: https://...

---

## ✅ Checks

<!-- Make sure your pr passes the CI checks and do check the following fields as needed - -->
- [ ] I created a new folder with the token address, **all in lowercase**
- [ ] I added the token's logo as a `32x32` PNG file, named `logo-32.png`
- [ ] I added the token's logo as a `128x128` PNG file, named `logo-128.png`
- [ ] I added the token's logo as a SVG file, named `logo.svg`
- [ ] My SVG logo is a proper SVG and not some base64 stuff
- [ ] My documentation/website clearly display the token address somewhere

- [ ] I created a new folder with the token address, **all in lowercase**
- [ ] I added the token's logo as a `32x32` PNG file, named `logo-32.png`
- [ ] I added the token's logo as a `128x128` PNG file, named `logo-128.png`
- [ ] I added the token's logo as a SVG file, named `logo.svg`
- [ ] My SVG logo is a proper SVG and not some base64 stuff
- [ ] My documentation/website clearly display the token address somewhere
44 changes: 23 additions & 21 deletions .github/scripts/generate-lists.mjs
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import fs from "fs-extra";
import path from "path";
import createKeccakHash from 'keccak'
import fs from 'fs-extra';
import path from 'path';
import createKeccakHash from 'keccak';

const DataDirectory = "./tokens";
const IndexName = "list.json";
const DataDirectory = './tokens';
const IndexName = 'list.json';

function toChecksumAddress(address) {
address = address.toLowerCase().replace('0x', '')
var hash = createKeccakHash('keccak256').update(address).digest('hex')
var ret = '0x'
address = address.toLowerCase().replace('0x', '');
var hash = createKeccakHash('keccak256').update(address).digest('hex');
var ret = '0x';

for (var i = 0; i < address.length; i++) {
if (parseInt(hash[i], 16) >= 8) {
ret += address[i].toUpperCase()
ret += address[i].toUpperCase();
} else {
ret += address[i]
ret += address[i];
}
}

return ret
return ret;
}

const perChain = {};
function generate(directory) {
for (let name of fs.readdirSync(directory)) {
if (name.startsWith(".") || name === IndexName || name === 'node_modules') continue;
if (name.startsWith('.') || name === IndexName || name === 'node_modules') continue;
const file = path.join(directory, name);
const stat = fs.lstatSync(file);
if (stat.isDirectory()) {
if (name.startsWith("0x")) {
const currentChain = Number(directory.split("/").pop());
if (name.startsWith('0x')) {
const currentChain = Number(directory.split('/').pop());
if (perChain[currentChain] === undefined) {
perChain[currentChain] = [];
}
Expand All @@ -41,21 +41,23 @@ function generate(directory) {
}

const cwd = process.cwd();
if (!fs.existsSync(path.join(cwd, ".git"))) {
console.error("Error: script should be run in the root of the repo.");
if (!fs.existsSync(path.join(cwd, '.git'))) {
console.error('Error: script should be run in the root of the repo.');
process.exit(1);
}

try {
generate(DataDirectory);
for (const chain in perChain) {
//load the existing list
const previousLists = fs.existsSync(path.join(DataDirectory, chain, IndexName)) ? JSON.parse(fs.readFileSync(path.join(DataDirectory, chain, IndexName))) : {};
const previousLists = fs.existsSync(path.join(DataDirectory, chain, IndexName))
? JSON.parse(fs.readFileSync(path.join(DataDirectory, chain, IndexName)))
: {};
if (!previousLists.version) {
previousLists.version = {
'major': 0,
'minor': 0,
'patch': 0
major: 0,
minor: 0,
patch: 0
};
}
if (!previousLists.tokens) {
Expand All @@ -64,7 +66,7 @@ try {
const newList = {
version: previousLists.version,
tokens: perChain[chain]
}
};
//compare the new list with the old one
if (JSON.stringify(previousLists.tokens) === JSON.stringify(newList.tokens)) {
console.log(`No changes detected for chain ${chain}`);
Expand Down
38 changes: 21 additions & 17 deletions .github/scripts/verify-chains.mjs
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
import fs from "fs-extra";
import path from "path";
import fs from 'fs-extra';
import path from 'path';

const DataDirectory = "./chains";
const IndexName = "index.json";
const DataDirectory = './chains';
const IndexName = 'index.json';

function validate(directory) {
let allValid = true;
for (let name of fs.readdirSync(directory)) {
if (name.startsWith(".") || name === IndexName || name === 'node_modules') continue;
if (name.startsWith('.') || name === IndexName || name === 'node_modules') continue;
const file = path.join(directory, name);
const stat = fs.lstatSync(file);
if (stat.isDirectory()) {
if (name.startsWith("_")) {
continue
if (name.startsWith('_')) {
continue;
}
if (name.match(/^[0-9]+$/) != null) {
if (!fs.existsSync(path.join(file, "logo-128.png"))) {
if (!fs.existsSync(path.join(file, 'logo-128.png'))) {
console.error(`Error: "${file}" is missing logo-128.png`);
allValid = false;
}
if (!fs.existsSync(path.join(file, "logo-32.png"))) {
if (!fs.existsSync(path.join(file, 'logo-32.png'))) {
console.error(`Error: "${file}" is missing logo-32.png`);
allValid = false;
}
if (!fs.existsSync(path.join(file, "logo.svg"))) {
if (!fs.existsSync(path.join(file, 'logo.svg'))) {
console.error(`Error: "${file}" is missing logo.svg`);
allValid = false;
} else {
const svgValue = fs.readFileSync(path.join(file, "logo.svg"));
if (svgValue.includes(`data:image/png;base64`) || svgValue.includes(`data:img/png;base64`) || svgValue.includes(`data:image/jpeg;base64`) || svgValue.includes(`data:img/jpeg;base64`)) {
const svgValue = fs.readFileSync(path.join(file, 'logo.svg'));
if (
svgValue.includes(`data:image/png;base64`) ||
svgValue.includes(`data:img/png;base64`) ||
svgValue.includes(`data:image/jpeg;base64`) ||
svgValue.includes(`data:img/jpeg;base64`)
) {
console.error(`Error: "${file}" logo.svg contains base64 encoded image.`);
allValid = false;
}
Expand All @@ -42,19 +47,18 @@ function validate(directory) {

function verify(dataDir) {
const valid = validate(dataDir);
if (!valid)
process.exit(1);
if (!valid) process.exit(1);
}

const cwd = process.cwd();
if (!fs.existsSync(path.join(cwd, ".git"))) {
console.error("Error: script should be run in the root of the repo.");
if (!fs.existsSync(path.join(cwd, '.git'))) {
console.error('Error: script should be run in the root of the repo.');
process.exit(1);
}

try {
verify(DataDirectory);
console.log("Ok: all files match schema definitions!");
console.log('Ok: all files match schema definitions!');
} catch (error) {
console.error(error);
process.exit(1);
Expand Down
56 changes: 36 additions & 20 deletions .github/scripts/verify-tokens.mjs
Original file line number Diff line number Diff line change
@@ -1,48 +1,65 @@
import fs from "fs-extra";
import path from "path";
import fs from 'fs-extra';
import path from 'path';

const DataDirectory = "./tokens";
const IndexName = "index.json";
const DataDirectory = './tokens';
const IndexName = 'index.json';

function getFilesizeInBytes(filename) {
var stats = fs.statSync(filename);
var fileSizeInBytes = stats.size;
return fileSizeInBytes;
}

function validate(directory) {
let allValid = true;
for (let name of fs.readdirSync(directory)) {
if (name.startsWith(".") || name === IndexName || name === 'node_modules') continue;
if (name.startsWith('.') || name === IndexName || name === 'node_modules') continue;
const file = path.join(directory, name);
const stat = fs.lstatSync(file);
if (stat.isDirectory()) {
if (name.startsWith("0x")) {
if (name.startsWith('0x')) {
try {
if (name.toLowerCase() !== name) {
console.error(`Error: "${name}" is not lowercased. Should be "${name.toLowerCase()}".`);
allValid = false;
}
} catch(error) {
} catch (error) {
console.error(`Error: "${name}" is not lowercased. Should be "${name.toLowerCase()}".`);
allValid = false;
}
}
if (name.startsWith("_")) {
continue
if (name.startsWith('_')) {
continue;
}
if (name.startsWith("0x")) {
if (!fs.existsSync(path.join(file, "logo-128.png"))) {
if (name.startsWith('0x')) {
if (!fs.existsSync(path.join(file, 'logo-128.png'))) {
console.error(`Error: "${file}" is missing logo-128.png`);
allValid = false;
}
if (!fs.existsSync(path.join(file, "logo-32.png"))) {
if (!fs.existsSync(path.join(file, 'logo-32.png'))) {
console.error(`Error: "${file}" is missing logo-32.png`);
allValid = false;
}
if (!fs.existsSync(path.join(file, "logo.svg"))) {
if (!fs.existsSync(path.join(file, 'logo.svg'))) {
console.error(`Error: "${file}" is missing logo.svg`);
allValid = false;
} else {
const svgValue = fs.readFileSync(path.join(file, "logo.svg"));
if (svgValue.includes(`data:image/png;base64`) || svgValue.includes(`data:img/png;base64`) || svgValue.includes(`data:image/jpeg;base64`) || svgValue.includes(`data:img/jpeg;base64`)) {
const svgValue = fs.readFileSync(path.join(file, 'logo.svg'));
if (
svgValue.includes(`data:image/png;base64`) ||
svgValue.includes(`data:img/png;base64`) ||
svgValue.includes(`data:image/jpeg;base64`) ||
svgValue.includes(`data:img/jpeg;base64`)
) {
console.error(`Error: "${file}" logo.svg contains base64 encoded image.`);
allValid = false;
}
// const fileSize = getFilesizeInBytes(path.join(file, 'logo.svg')) / 1000000;
// if (fileSize > 0.15) {
// console.error(`Error: "${file}" logo.svg is larger than 0.15mb.`);
// allValid = false;
// }

}
}
allValid &= validate(file);
Expand All @@ -53,19 +70,18 @@ function validate(directory) {

function verify(dataDir) {
const valid = validate(dataDir);
if (!valid)
process.exit(1);
if (!valid) process.exit(1);
}

const cwd = process.cwd();
if (!fs.existsSync(path.join(cwd, ".git"))) {
console.error("Error: script should be run in the root of the repo.");
if (!fs.existsSync(path.join(cwd, '.git'))) {
console.error('Error: script should be run in the root of the repo.');
process.exit(1);
}

try {
verify(DataDirectory);
console.log("Ok: all files match schema definitions!");
console.log('Ok: all files match schema definitions!');
} catch (error) {
console.error(error);
process.exit(1);
Expand Down
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"singleQuote": true,
"semi": true,
"useTabs": true,
"tabWidth": 4,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"bracketSameLine": true,
"singleAttributePerLine": true,
"printWidth": 120
}
Loading

0 comments on commit 8b53bbe

Please sign in to comment.