Skip to content

Commit

Permalink
Add test for validators, dapp image requirments (trustwallet#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
kolya182 authored Sep 3, 2019
1 parent 92c5f00 commit d263667
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 17 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<center><img src='https://raw.githubusercontent.com/trustwallet/assets/master/media/trust-wallet.png'></center>

Expand All @@ -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)
- `<subdomain>.<domain_name>.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` ...
Expand Down
92 changes: 77 additions & 15 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand All @@ -17,7 +20,7 @@ function checkRootDir () {
}
})

if(fs.existsSync("./images")) {
if(isPathExistsSync(`./images`)) {
exitWithMsg(`Adding to ./image folder is restricted, please update your fork`)
}
}
Expand All @@ -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`)
Expand All @@ -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`)
}
})
Expand All @@ -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}"`)
}
}
Expand All @@ -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`)
}

Expand All @@ -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`)
}
})
Expand All @@ -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) {
Expand Down

0 comments on commit d263667

Please sign in to comment.