forked from traderjoe-xyz/joe-tokenlists
-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (82 loc) · 3.62 KB
/
test.yml
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
name: Tokenlist Validation CI
on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'
jobs:
validate_json:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Check JSON Structure
run: |
echo "Validating JSON structure for mc.tokenlist.json"
jq empty ./mc.tokenlist.json
- name: Check Required Keys in JSON Array
run: |
REQUIRED_KEYS=("chainId" "address" "decimals" "name" "symbol" "tags" "logoURI")
MISSING_KEYS=0
for key in "${REQUIRED_KEYS[@]}"; do
if [ "$(jq "[.tokens[] | has(\"$key\")] | contains([false])" mc.tokenlist.json)" == "true" ]; then
MISSING_KEYS=$((MISSING_KEYS+1))
echo "JSON validation failed: Missing key $key"
exit 1
fi
done
if [ "$MISSING_KEYS" -eq 0 ]; then
echo "All required keys are present in each element of tokenlist"
else
echo "JSON validation incomplete: $MISSING_KEYS missing key[s] in tokenlist."
fi
- name: Check Allowed 'chainId' Values
run: |
ALLOWED_CHAIN_IDS=(1 43113 43114 42161 42161 421613 56 97)
# Convert bash array to jq array format
JQ_ALLOWED_CHAIN_IDS=$(printf "[%s]" "$(IFS=, ; echo "${ALLOWED_CHAIN_IDS[*]}")")
INVALID_CHAIN_IDS=$(jq "[.tokens[].chainId] | map(select(. as \$id | ($JQ_ALLOWED_CHAIN_IDS | index(\$id)) == null))" mc.tokenlist.json)
if [ "$INVALID_CHAIN_IDS" != "[]" ]; then
echo "Invalid 'chainId' value(s) found: $INVALID_CHAIN_IDS. Must be one of ${ALLOWED_CHAIN_IDS[*]}"
exit 1
else
echo "All 'chainId' values are valid in the 'tokens' array."
fi
- name: Check 'tags' Values
run: |
ALLOWED_TAGS=("Stablecoins" "Top" "DeFi" "Meme" "GameFi" "NFT")
echo "Checking 'tags' values are within allowed list"
# Convert bash array to jq array format
JQ_ALLOWED_TAGS=$(printf '%s\n' "${ALLOWED_TAGS[@]}" | jq -R . | jq -s .)
INVALID_TAGS_FOUND=$(jq --argjson allowedTags "$JQ_ALLOWED_TAGS" '[.tokens[].tags[]] | map(select(. as $tag | ($allowedTags | index($tag)) == null))' mc.tokenlist.json)
if [ "$INVALID_TAGS_FOUND" != "[]" ]; then
echo "Invalid 'tags' value(s) found: $INVALID_TAGS_FOUND. Must be one of ${ALLOWED_TAGS[*]}"
exit 1
else
echo "All 'tags' values are valid in the 'tokens' array."
fi
- name: Check logos folder and file names
run: |
LOGOS_DIR="./logos"
ETH_ADDRESS_PATTERN="^0x[a-fA-F0-9]{40}$"
UPPERCASE_PATTERN="[A-F]"
for folder in "$LOGOS_DIR"/*; do
if [[ -d "$folder" ]]; then
folder_name=$(basename "$folder")
if [[ ! $folder_name =~ $ETH_ADDRESS_PATTERN ]]; then
echo "Invalid folder name: $folder_name is not a valid ETH address."
exit 1
elif [[ ! $folder_name =~ $UPPERCASE_PATTERN ]]; then
echo "Invalid folder name: $folder_name isn't checksummed address."
exit 1
fi
# Check if the logo.png file exists in the folder
if [[ ! -f "$folder/logo.png" ]]; then
echo "Missing (or wrongly named) logo.png file in folder: $folder_name"
exit 1
fi
fi
done
echo "Every folder has a valid name and contains logo.png."