forked from eoscafe/eos-airdrops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokens.spec.ts
77 lines (66 loc) · 2.29 KB
/
tokens.spec.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
import tokens from "./tokens.json"
import {Asset, Int64, Name} from '@wharfkit/antelope'
import {describe, expect, test} from 'bun:test'
import fs from "fs";
const BASE_URL = 'https://raw.githubusercontent.com/eoscafe/eos-airdrops/master/logos/';
const CHAINS = ["eos", "telos", "wax", "proton"];
test('must be *.png or *.jpg', async () => {
for ( const token of tokens ) {
expect(token.logo).toMatch(/^https:\/\/.*\.(png|jpg)$/)
expect(token.logo_lg).toMatch(/^https:\/\/.*\.(png|jpg)$/)
}
})
test('matches url schema', async () => {
for ( const token of tokens ) {
expect(token.logo.startsWith(BASE_URL)).toBe(true)
expect(token.logo_lg.startsWith(BASE_URL)).toBe(true)
}
})
test('must be valid chain', async () => {
for ( const token of tokens ) {
expect(CHAINS.includes(token.chain)).toBe(true)
}
})
test('missing logo file', async () => {
for ( const token of tokens ) {
expect(fs.existsSync(`./logos/${token.logo.replace(BASE_URL, '')}`)).toBe(true)
expect(fs.existsSync(`./logos/${token.logo_lg.replace(BASE_URL, '')}`)).toBe(true)
}
})
test('logo file not associated with a token', async () => {
const logos = new Set();
for ( const token of tokens ) {
logos.add(token.logo.replace(BASE_URL, ''))
logos.add(token.logo_lg.replace(BASE_URL, ''))
}
const files = fs.readdirSync('./logos');
for ( const file of files ) {
if ( file === ".DS_Store" ) continue;
// if ( !logos.has(file) ) {
// fs.rmSync(`./logos/${file}`)
// }
expect(logos.has(file)).toBe(true)
}
})
test('must be valid account name', async () => {
for ( const token of tokens ) {
expect(Name.from(token.account).toString()).toBe(token.account)
}
})
test('must be valid symbol', async () => {
for ( const token of tokens ) {
expect(Asset.SymbolCode.from(token.symbol).toString()).toBe(token.symbol)
}
})
test('token name must be sorted alphabetically', async () => {
let last = '';
for ( const token of tokens ) {
if (last === '') {
last = token.name
continue
}
expect(token.name[0].toLocaleLowerCase() >= last[0].toLocaleLowerCase()).toBe(true)
last = token.name
}
})
// no duplicate tokens