-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy patherc721.py
103 lines (86 loc) · 2.7 KB
/
erc721.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
import re
import common
variations = {
"OZ": "OpenZeppelin",
"OZEnumerable": "OpenZeppelin Enumerable",
"OZConsecutive": "OpenZeppelin Consecutive",
"Solady": "Solady",
"Solmate": "Solmate",
"A": "ERC721A",
"B": "ERC721B",
"K": "ERC721K",
}
# Methods to format .gas-snapshot line to an object with relevant info
# For snapshots of methods with no variations
def regex_for_method_simple(method):
regex_string = "test_{}.+gas:\s(\d+)".format(method)
return re.compile(regex_string)
def fn_for_method_simple(method):
def get_gas(line):
match = re.search(regex_for_method_simple(method), line)
return {
"gas": match.group(1)
}
return get_gas
# For snapshots of methods with amount variations
def regex_for_method_amount(method):
regex_string = "test_{}_(\d+).+gas:\s(\d+)".format(method)
return re.compile(regex_string)
def fn_for_method_amount(method):
def get_gas(line):
match = re.search(regex_for_method_amount(method), line)
return {
"key": match.group(1),
"gas": match.group(2),
}
return get_gas
# For snapshots of methods with id variations
def regex_for_method_id(method):
regex_string = "test_{}_id(\d+).+gas:\s(\d+)".format(method)
return re.compile(regex_string)
def fn_for_method_id(method):
def get_gas(line):
match = re.search(regex_for_method_id(method), line)
return {
"key": match.group(1),
"gas": match.group(2),
}
return get_gas
def group_methods_and_variant(lines):
methods = common.group_by_method(lines)
grouped = {}
for key in methods:
grouped[key] = common.group_by_variant(methods[key])
return grouped
def group(lines):
methods = group_methods_and_variant(lines)
def rows_for_method(method_name, method_fn):
return common.rows_for_method(methods, variations, method_name, method_fn)
methods_simple = [
"deploy",
"isApprovedForAll",
"setApprovalForAll",
]
methods_amount = [
"deployERC2309",
"mint",
"safeMint",
"balanceOf",
"ownerOf",
"getApproved",
]
methods_id = [
"burn",
"transferToOwner",
"transferToNonOwner",
"safeTransferToOwner",
"safeTransferToNonOwner",
"approve",
]
for method in methods_simple:
methods[method] = rows_for_method(method, fn_for_method_simple(method))
for method in methods_amount:
methods[method] = rows_for_method(method, fn_for_method_amount(method))
for method in methods_id:
methods[method] = rows_for_method(method, fn_for_method_id(method))
return methods