-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.test.ts
197 lines (168 loc) · 6.89 KB
/
index.test.ts
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
const eztz = require('eztz-lib')
import {
Ethereum, Binance, Cosmos, Tezos, Tron, IoTeX, Waves, Classic, POA, TomoChain, GoChain, Wanchain, ThunderCore,
chainsFolderPath,
getChainLogoPath,
getChainAssetsPath,
getChainAssetLogoPath,
getChainValidatorsAssets,
getChainValidatorsListPath,
getChainValidatorAssetLogoPath,
readDirSync,
isPathExistsSync,
readFileSync,
isLowerCase,
isChecksum,
getBinanceBEP2Symbols,
isTRC10, isTRC20,
isLogoOK,
} from "./helpers"
describe("Check repository root dir", () => {
const rootDirAllowedFiles = [
".github",
"blockchains",
"dapps",
"media",
"node_modules",
"script",
"src",
".gitignore",
".travis.yml",
"jest.config.js",
"LICENSE",
"package-lock.json",
"package.json",
"README.md",
".git",
"pricing"
]
const dirActualFiles = readDirSync(".")
test("Root should contains only predefined files", () => {
dirActualFiles.forEach(file => {
expect(rootDirAllowedFiles.indexOf(file), `File "${file}" should not be in root or added to predifined list`).not.toBe(-1)
})
})
})
describe(`Test "blockchains" folder`, () => {
const foundChains = readDirSync(chainsFolderPath)
test(`Chain should have "logo.png" image`, () => {
foundChains.forEach(chain => {
const chainLogoPath = getChainLogoPath(chain)
expect(isPathExistsSync(chainLogoPath), `File missing at path "${chainLogoPath}"`).toBe(true)
const [isOk, msg] = isLogoOK(chainLogoPath)
expect(isOk, msg).toBe(true)
})
})
test("Chain folder must have lowercase naming", () => {
foundChains.forEach(chain => {
expect(isLowerCase(chain), `Chain folder must be in lowercase "${chain}"`).toBe(true)
})
})
describe("Check Ethereum side-chain folders", () => {
const ethSidechains = [Ethereum, Classic, POA, TomoChain, GoChain, Wanchain, ThunderCore]
ethSidechains.forEach(chain => {
test(`Test chain ${chain} folder`, () => {
const assetsPath = getChainAssetsPath(chain)
readDirSync(assetsPath).forEach(addr => {
expect(isChecksum(addr), `Address ${addr} on chain ${chain} must be in checksum`).toBe(true)
const assetLogoPath = getChainAssetLogoPath(chain, addr)
expect(isPathExistsSync(assetLogoPath), `Missing file at path "${assetLogoPath}"`).toBe(true)
const [isOk, msg] = isLogoOK(assetLogoPath)
expect(isOk, msg).toBe(true)
})
})
})
})
describe(`Check "binace" folder`, () => {
it("Asset must exist on chain and", async () => {
const tokenSymbols = await getBinanceBEP2Symbols()
const assets = readDirSync(getChainAssetsPath(Binance))
assets.forEach(asset => {
expect(tokenSymbols.indexOf(asset), `Asset ${asset} missing on chain`).not.toBe(-1)
})
})
})
describe(`Check "tron" folder`, () => {
const path = getChainAssetsPath(Tron)
test("Expect asset to be TRC10 or TRC20", () => {
readDirSync(path).forEach(asset => {
expect(isTRC10(asset) || isTRC20(asset), `Asset ${asset} non TRC10 nor TRC20`).toBe(true)
const assetsLogoPath = getChainAssetLogoPath(Tron, asset)
expect(isPathExistsSync(assetsLogoPath), `Missing file at path "${assetsLogoPath}"`).toBe(true)
const [isOk, msg] = isLogoOK(assetsLogoPath)
expect(isOk, msg).toBe(true)
})
})
})
describe("Check Staking chains", () => {
const stakingChains = [Tezos, Cosmos, IoTeX, Tron, Waves]
test("Make sure tests added for new staking chain", () => {
expect(stakingChains.length).toBe(5)
})
stakingChains.forEach(chain => {
const validatorsList = JSON.parse(readFileSync(getChainValidatorsListPath(chain)))
test(`Make sure ${chain} validators list has correct structure`, () => {
validatorsList.forEach(val => {
const keys = Object.keys(val)
expect(keys.length, `Wrong keys amount`).toBe(4)
keys.forEach(key => {
const type = typeof key
expect(type, `Wrong key type`).toBe("string")
})
})
})
test(`Chain ${chain} validator must have corresponding asset logo`, () => {
validatorsList.forEach(({ id }) => {
const path = getChainValidatorAssetLogoPath(chain, id)
expect(isPathExistsSync(path), `Chain ${chain} asset ${id} logo must be present at path ${path}`).toBe(true)
const [isOk, msg] = isLogoOK(path)
expect(isOk, msg).toBe(true)
})
})
const chainValidatorsAssetsList = getChainValidatorsAssets(chain)
switch (chain) {
case Cosmos:
testCosmosValidatorsAddress(chainValidatorsAssetsList)
break;
case Tezos:
testTezosValidatorsAssets(chainValidatorsAssetsList)
break;
case Tron:
testTronValidatorsAssets(chainValidatorsAssetsList)
break;
// TODO Add LOOM
// TODO Add Waves
// TODO Add IoTex
default:
break;
}
test("Make sure number of validators in the list match validators assets", () => {
expect(validatorsList.length).toBe(chainValidatorsAssetsList.length)
})
})
})
})
function testTezosValidatorsAssets(assets) {
test("Tezos assets must be correctly formated tz1 address", () => {
assets.forEach(addr => {
expect(eztz.crypto.checkAddress(addr), `Ivalid Tezos address: ${addr}`).toBe(true)
})
})
}
function testTronValidatorsAssets(assets) {
test("TRON assets must be correctly formated", () => {
assets.forEach(addr => {
expect(isTRC20(addr), `Address ${addr} should be TRC20`).toBe(true)
})
})
}
function testCosmosValidatorsAddress(assets) {
test("Cosmos assets must be correctly formated", () => {
assets.forEach(addr => {
expect(addr.startsWith("cosmosvaloper1"), `Address ${addr} should start from "cosmosvaloper1"`).toBe(true)
expect(addr.length, `Address ${addr} should have length 52`).toBe(52)
expect(isLowerCase(addr), `Address ${addr} should be in lowercase`).toBe(true)
})
})
}
// TODO test whitelist