forked from gkucmierz/contract-metadata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
108 lines (89 loc) · 3.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const test = require('tape')
const contractMap = require('../')
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 accounts are valid checksum addresses', function (t) {
Object.keys(contractMap).forEach(address => {
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(address => {
const contract = contractMap[address]
if (!contract.logo) return
const fileName = contract.logo
const filePath = path.join(__dirname, '..', 'images', fileName)
t.ok(fs.existsSync(filePath), `file exists: "${fileName}"`)
})
t.end()
})
test('logos path names should match exactly', function (t) {
const dirContent = fs.readdirSync(path.join(__dirname, '..', 'images'))
Object.keys(contractMap).forEach(address => {
const contract = contractMap[address]
if (!contract.logo) return
const fileName = contract.logo
t.ok(dirContent.includes(fileName), `filename matches exactly: "${fileName}"`)
})
t.end()
})
test('logos icon should not be empty', function (t) {
Object.keys(contractMap).forEach(address => {
const contract = contractMap[address]
const logo = contract.logo
t.notEqual(logo.length, 0)
})
t.end()
})
test('logos path names should not contain space', function (t) {
const dirContent = fs.readdirSync(path.join(__dirname, '..', 'images'))
Object.keys(contractMap).forEach(address => {
const contract = contractMap[address]
if (!contract.logo) return
const fileName = contract.logo
t.notOk(fileName.includes(' '), `filename does not include space: "${fileName}"`)
})
t.end()
})
test('symbols should be six or less characters', function (t) {
Object.keys(contractMap).forEach(address => {
const contract = contractMap[address]
const symbol = contract.symbol
if (symbol) {
t.notOk(symbol.length > 6, `symbol with more than 6 characters: "${symbol}"`)
}
})
t.end()
})
test('only permitted fields should be used', function (t) {
Object.keys(contractMap).forEach(address => {
const contract = contractMap[address]
const fields = Object.keys(contract)
fields.forEach(field => {
t.ok(permittedFields.includes(field), `${field} must be part of permitted fields.`)
})
})
t.end()
})
test('symbols should not overlap', function (t) {
const symbols = Object.values(contractMap).map(contract => contract.symbol)
const symbolsCheck = new Map()
let duplicateSymbol
symbols.forEach(symbol => {
if (symbolsCheck.has(symbol) && symbol !== undefined) {
duplicateSymbol = symbol
return
}
symbolsCheck.set(symbol, true)
})
const msg = duplicateSymbol ? `found overlapping symbol ${duplicateSymbol}` : 'symbols should not overlap'
t.notOk(duplicateSymbol, msg)
t.end()
})