mirror of
https://github.com/Instadapp/trustwallet-assets.git
synced 2024-07-29 22:37:31 +00:00
Add test for validators, dapp image requirments (#125)
This commit is contained in:
parent
92c5f00648
commit
d263667f54
13
README.md
13
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)
|
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>
|
<center><img src='https://raw.githubusercontent.com/trustwallet/assets/master/media/trust-wallet.png'></center>
|
||||||
|
|
||||||
|
@ -38,6 +40,13 @@ Token repository [https://github.com/trustwallet/assets](https://github.com/trus
|
||||||
- background: preferably transparent
|
- background: preferably transparent
|
||||||
- use simple drag and drop online service [tinypng](https://tinypng.com/) to optimize image size
|
- 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
|
## Repository structure
|
||||||
|
|
||||||
`blockchains` folder contains many subfolders and represents chains e.g. `ethereum`, `binance` ...
|
`blockchains` folder contains many subfolders and represents chains e.g. `ethereum`, `binance` ...
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const assert = require('assert')
|
||||||
|
|
||||||
const pngExp = /\.png$/
|
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 isFilePng = name => pngExp.test(name)
|
||||||
const readDirSync = path => fs.readdirSync(path)
|
const readDirSync = path => fs.readdirSync(path)
|
||||||
|
const isLowerCase = str => str.toLowerCase() === str
|
||||||
|
const blockchainsFolderPath = './blockchains'
|
||||||
|
|
||||||
checkRootDir()
|
checkRootDir()
|
||||||
function 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`)
|
exitWithMsg(`Adding to ./image folder is restricted, please update your fork`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +29,8 @@ checkBlockhainsFolder()
|
||||||
|
|
||||||
function checkBlockhainsFolder(){
|
function checkBlockhainsFolder(){
|
||||||
const currentBlockchains = 59
|
const currentBlockchains = 59
|
||||||
const foundBlockchains = readDirSync('./blockchains')
|
|
||||||
|
const foundBlockchains = readDirSync(blockchainsFolderPath)
|
||||||
|
|
||||||
if (foundBlockchains.length !== currentBlockchains) {
|
if (foundBlockchains.length !== currentBlockchains) {
|
||||||
exitWithMsg(`Expected amount of chains in "./blockchains" = ${currentBlockchains}, found ${foundBlockchains.length}. Add tests for new folder`)
|
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)
|
const assets = readDirSync(assetsPath)
|
||||||
|
|
||||||
assets.forEach(asset => {
|
assets.forEach(asset => {
|
||||||
if (upperCaseExp.test(asset)) {
|
if (uppercaseExp.test(asset)) {
|
||||||
exitWithMsg(`${asset} folder must be in lowercase`)
|
exitWithMsg(`${asset} folder must be in lowercase`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isAddress(asset)) {
|
if (!isEthereumAddress(asset)) {
|
||||||
exitWithMsg(`Invalid asset naming "${assetsPath}"`)
|
exitWithMsg(`Invalid asset naming "${assetsPath}"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if asset folder contains logo.png image
|
// Check if asset folder contains logo.png image
|
||||||
const assetLogoPath = `${assetsPath}/${asset}/logo.png`
|
const assetLogoPath = `${assetsPath}/${asset}/logo.png`
|
||||||
if (!fs.existsSync(assetLogoPath)) {
|
if (!isPathExistsSync(assetLogoPath)) {
|
||||||
exitWithMsg(`${assetLogoPath} mush have logo.png`)
|
exitWithMsg(`${assetLogoPath} mush have logo.png`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -66,18 +70,25 @@ function checkBlockhainsFolder(){
|
||||||
checkTron()
|
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`)
|
console.log(`Folder ${folder} passed all checks`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function commonChainCheck(folder) {
|
function commonChainCheck(folder) {
|
||||||
if (upperCaseExp.test(folder)) {
|
if (uppercaseExp.test(folder)) {
|
||||||
exitWithMsg(`"${folder}" must be in lowercase register`)
|
exitWithMsg(`"${folder}" must be in lowercase register`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const pathToInfo = path.join(__dirname, '..', `blockchains/${folder}/info/logo.png`)
|
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}"`)
|
exitWithMsg(`Can't find coin image inside "${pathToInfo}"`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +99,7 @@ async function checkBinance() {
|
||||||
const assets = readDirSync(path)
|
const assets = readDirSync(path)
|
||||||
|
|
||||||
assets.forEach(asset => {
|
assets.forEach(asset => {
|
||||||
if (upperCaseExp.test(asset)) {
|
if (uppercaseExp.test(asset)) {
|
||||||
exitWithMsg(`${asset} folder must be in lowercase`)
|
exitWithMsg(`${asset} folder must be in lowercase`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +108,7 @@ async function checkBinance() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const assetLogoPath = `${path}/${asset}/logo.png`
|
const assetLogoPath = `${path}/${asset}/logo.png`
|
||||||
if (!fs.existsSync(assetLogoPath)) {
|
if (!isPathExistsSync(assetLogoPath)) {
|
||||||
exitWithMsg(`Path ${assetLogoPath} mush have logo.png`)
|
exitWithMsg(`Path ${assetLogoPath} mush have logo.png`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -113,16 +124,67 @@ function checkTron() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const assetLogoPath = `${path}/${asset}/logo.png`
|
const assetLogoPath = `${path}/${asset}/logo.png`
|
||||||
if (!fs.existsSync(assetLogoPath)) {
|
if (!isPathExistsSync(assetLogoPath)) {
|
||||||
exitWithMsg(`Path ${assetLogoPath} mush have logo.png`)
|
exitWithMsg(`Path ${assetLogoPath} mush have logo.png`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getBinanceTokenSymbols() {
|
function checkValidatorsFolder(networkPath) {
|
||||||
return axios.get(`https://dex-atlantic.binance.org/api/v1/tokens?limit=1000`).then(res => {
|
const validatorsFolderPath = `${networkPath}/validators`
|
||||||
return res.data.map(token => token.symbol)
|
|
||||||
|
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) {
|
function exitWithMsg (msg) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user