From d263667f54e36cf64afb1939a9138b6b12f755aa Mon Sep 17 00:00:00 2001 From: Mykola <3277207+kolya182@users.noreply.github.com> Date: Mon, 2 Sep 2019 19:16:18 -0700 Subject: [PATCH] Add test for validators, dapp image requirments (#125) --- README.md | 13 ++++++-- test/index.js | 92 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 88 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 713748513..fb1076513 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,11 @@ Token repository [https://github.com/trustwallet/assets](https://github.com/trus 4. [coins](https://github.com/satoshilabs/slips/blob/master/slip-0044.md) integrated in [Wallet Core](https://developer.trustwallet.com/wallet-core) -5. dApp images available in `Browser` section in Trust Wallet and at https://dapps.trustwallet.com. [Folder for upload](https://github.com/trustwallet/assets/tree/master/dapps) +5. dApp images available in `Browser` section in Trust Wallet and at https://dapps.trustwallet.com and bookmarks icons. [read requirments](#dApp-image-naming-requirments) -6. Coming soon: token info, token price, blacklisted and whitelisted tokens (mostly scam/spam ones) +6. Staking validators info avalible on [Trust Wallet Staking Platform](https://github.com/trustwallet/developer/blob/master/platform/staking.md) + +7. Coming soon: token info, token price, blacklisted and whitelisted tokens (mostly scam/spam ones)
@@ -38,6 +40,13 @@ Token repository [https://github.com/trustwallet/assets](https://github.com/trus - background: preferably transparent - use simple drag and drop online service [tinypng](https://tinypng.com/) to optimize image size +## dApp image naming requirments +- [Folder for upload](https://github.com/trustwallet/assets/tree/master/dapps) +- `..png` e.g: + https://app.compound.finance/ => `app.compound.finance.png` + https://kyberswap.com/ => `kyberswap.com.png` + + ## Repository structure `blockchains` folder contains many subfolders and represents chains e.g. `ethereum`, `binance` ... diff --git a/test/index.js b/test/index.js index 4bbacaf8b..91249636b 100644 --- a/test/index.js +++ b/test/index.js @@ -1,13 +1,16 @@ const fs = require('fs') const axios = require('axios') const path = require('path') +const assert = require('assert') const pngExp = /\.png$/ -const upperCaseExp = /[A-F]/ +const uppercaseExp = /[A-F]/ -const isAddress = address => /^(0x)?[0-9a-f]{40}$/i.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address) +const isEthereumAddress = address => /^(0x)?[0-9a-f]{40}$/i.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address) const isFilePng = name => pngExp.test(name) const readDirSync = path => fs.readdirSync(path) +const isLowerCase = str => str.toLowerCase() === str +const blockchainsFolderPath = './blockchains' checkRootDir() function checkRootDir () { @@ -17,7 +20,7 @@ function checkRootDir () { } }) - if(fs.existsSync("./images")) { + if(isPathExistsSync(`./images`)) { exitWithMsg(`Adding to ./image folder is restricted, please update your fork`) } } @@ -26,7 +29,8 @@ checkBlockhainsFolder() function checkBlockhainsFolder(){ const currentBlockchains = 59 - const foundBlockchains = readDirSync('./blockchains') + + const foundBlockchains = readDirSync(blockchainsFolderPath) if (foundBlockchains.length !== currentBlockchains) { exitWithMsg(`Expected amount of chains in "./blockchains" = ${currentBlockchains}, found ${foundBlockchains.length}. Add tests for new folder`) @@ -42,17 +46,17 @@ function checkBlockhainsFolder(){ const assets = readDirSync(assetsPath) assets.forEach(asset => { - if (upperCaseExp.test(asset)) { + if (uppercaseExp.test(asset)) { exitWithMsg(`${asset} folder must be in lowercase`) } - if (!isAddress(asset)) { + if (!isEthereumAddress(asset)) { exitWithMsg(`Invalid asset naming "${assetsPath}"`) } // Check if asset folder contains logo.png image const assetLogoPath = `${assetsPath}/${asset}/logo.png` - if (!fs.existsSync(assetLogoPath)) { + if (!isPathExistsSync(assetLogoPath)) { exitWithMsg(`${assetLogoPath} mush have logo.png`) } }) @@ -66,18 +70,25 @@ function checkBlockhainsFolder(){ checkTron() } + // Check staking supported chains + const stakingChains = ["cosmos"] + if (stakingChains.indexOf(folder) !== -1) { + const folderPath = `${blockchainsFolderPath}/${folder}` + checkValidatorsFolder(folderPath) + } + console.log(`Folder ${folder} passed all checks`) }) } function commonChainCheck(folder) { - if (upperCaseExp.test(folder)) { + if (uppercaseExp.test(folder)) { exitWithMsg(`"${folder}" must be in lowercase register`) } const pathToInfo = path.join(__dirname, '..', `blockchains/${folder}/info/logo.png`) - if (!fs.existsSync(pathToInfo)) { + if (!isPathExistsSync(pathToInfo)) { exitWithMsg(`Can't find coin image inside "${pathToInfo}"`) } } @@ -88,7 +99,7 @@ async function checkBinance() { const assets = readDirSync(path) assets.forEach(asset => { - if (upperCaseExp.test(asset)) { + if (uppercaseExp.test(asset)) { exitWithMsg(`${asset} folder must be in lowercase`) } @@ -97,7 +108,7 @@ async function checkBinance() { } const assetLogoPath = `${path}/${asset}/logo.png` - if (!fs.existsSync(assetLogoPath)) { + if (!isPathExistsSync(assetLogoPath)) { exitWithMsg(`Path ${assetLogoPath} mush have logo.png`) } }) @@ -113,16 +124,67 @@ function checkTron() { } const assetLogoPath = `${path}/${asset}/logo.png` - if (!fs.existsSync(assetLogoPath)) { + if (!isPathExistsSync(assetLogoPath)) { exitWithMsg(`Path ${assetLogoPath} mush have logo.png`) } }) } -async function getBinanceTokenSymbols() { - return axios.get(`https://dex-atlantic.binance.org/api/v1/tokens?limit=1000`).then(res => { - return res.data.map(token => token.symbol) +function checkValidatorsFolder(networkPath) { + const validatorsFolderPath = `${networkPath}/validators` + + if (!isPathExistsSync(validatorsFolderPath)) { + exitWithMsg(`Validators folder doesn't exists at path ${networkPath}`) + } + + const validatorsAssetsFolderPath = validatorsFolderPath + `/assets` + if (!isPathExistsSync(validatorsAssetsFolderPath)) { + exitWithMsg(`Validators assets folder doesn't exists at path ${validatorsAssetsFolderPath}`) + } + + readDirSync(validatorsAssetsFolderPath).forEach(address => { + testCosmosAddress(address) + + const validatoAssetLogo = `${validatorsAssetsFolderPath}/${address}/logo.png` + if (!isPathExistsSync(validatoAssetLogo)) { + exitWithMsg(`Path ${validatoAssetLogo} mush have logo.png`) + } }) + + fs.readFile(validatorsFolderPath + `/list.json`, (err, data) => { + if (err) throw err + const validators = JSON.parse(data) + + validators.forEach(validator => { + const keys = Object.keys(validator) + if (keys.length !== 4) { + exitWithMsg(`Add test for new validator object key: ${keys.length}`) + } + + keys.forEach(key => { + const keyType = typeof key + if (keyType !== "string") { + exitWithMsg(`Key ${key} must be "string" type, actual ${keyType}`) + } + }) + }) + + }) + +} + +function testCosmosAddress(address) { + if (!isLowerCase(address)) { + exitWithMsg(`${address} folder must be in lowercase`) + } +} + +function isPathExistsSync(path) { + return fs.existsSync(path) +} + +async function getBinanceTokenSymbols() { + return axios.get(`https://dex-atlantic.binance.org/api/v1/tokens?limit=1000`).then(res => res.data.map(token => token.symbol)) } function exitWithMsg (msg) {