forked from ordinals-wallet/ordinals-collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_colllections.py
109 lines (91 loc) · 3.79 KB
/
test_colllections.py
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
import os
import json
COLLECTIONS = "./collections"
def test_home_structure():
expected_directories = [
"LICENSE",
"requirements.txt",
".pytest_cache",
"tests",
"README.md",
"env",
".gitignore",
".git",
"collections",
".circleci",
"notebooks",
"scripts",
".DS_Store"
]
current_directories = os.listdir()
correct_directories = [x in expected_directories for x in current_directories]
assert all(correct_directories), 'Top level changes are not allowed'
def test_collections_structure():
current_collections = os.listdir(COLLECTIONS)
folders = [
not os.path.isfile("{}/{}".format(COLLECTIONS, x)) for x in current_collections
]
assert all(folders), 'Invalid structure, include your files in a nested directory'
def test_meta():
expected_meta = {
"name": "Based Apes",
"inscription_icon": "159f5b1437375424ba798c92f10670f19baf3e5d10be3bf5fbd4d4a50cf642ddi0",
"supply": "100",
"slug": "based-apes",
"description": "",
"twitter_link": "https://twitter.com/BasedApes",
"discord_link": "https://discord.com/invite/ordinalswallet",
"website_link": "",
}
current_collections = os.listdir(COLLECTIONS)
for x in current_collections:
with open("{}/{}/meta.json".format(COLLECTIONS, x), "r") as file:
meta = json.load(file)
assert set(meta.keys()) == set(expected_meta.keys()) , 'Invalid meta data keys'
for y in zip(meta.values(), meta.keys()):
assert isinstance(y[0], str) , 'Invalid data type, use a string'
if y[1].endswith('link'):
if y[0]:
assert y[0].startswith('https://') or y[0].startswith('http://'), 'link must start with https://'
assert (len(meta.get('inscription_icon')) == 66) or meta.get('inscription_icon'), 'Invalid inscription Id'
assert meta.get('slug').lower() == meta.get('slug'), 'Slug must be lowercase'
assert len(meta.get('name')) <= 60, 'Name is too long'
assert len(meta.get('slug')) < 60, 'Slug is too long'
assert meta.get('slug') == x, 'Slug does not match directory name'
def ishex(s):
try:
n = int(s,16)
return True
except ValueError:
return False
def test_inscriptions():
current_collections = os.listdir(COLLECTIONS)
for x in current_collections:
with open("{}/{}/inscriptions.json".format(COLLECTIONS, x), "r") as file:
inscriptions = json.load(file)
for y in inscriptions:
assert y.get('id')
assert y.get('meta')
assert y.get('attributes') is None, 'Attributes belong in meta object'
if y.get('meta').get('attributes'):
for a in y.get('meta').get('attributes'):
if x not in ['ordinal-gen1-pokemon', 'bitcoin-jpgs']:
assert 'trait_type' in a, 'Attribute must have trait type'
assert 'value' in a, 'Attribute must have trait value'
assert len(y.get('id').strip()) == 66
assert ishex(y.get('id')[0:64]), 'inscription ids must be valid hex'
assert isinstance(y.get('meta').get('name'), str)
def test_uniqueness():
input_collections = os.listdir(COLLECTIONS)
print('\n\n')
# add new collections
all_inscription_ids = []
for collection in input_collections:
with open("{}/{}/inscriptions.json".format(COLLECTIONS, collection), "r") as file:
inscriptions = json.load(file)
inscription_ids = []
for x in inscriptions:
inscription_ids.append(x.get('id'))
all_inscription_ids = all_inscription_ids + inscription_ids
duplicates = len(all_inscription_ids) - len(set(all_inscription_ids))
assert duplicates == 0