-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestCompile.py
51 lines (44 loc) · 1.31 KB
/
testCompile.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
from solcx import *
from solcx.install import Version
contract_path = './examples/sol/array_length_manipulation.sol'
with open(contract_path) as f:
contract_content = f.read()
version = next((line.split()[2].strip(";").strip(
'^') for line in contract_content.splitlines() if line.startswith("pragma ")), '')
if version == '':
print("No version specified")
exit(1)
installed = next(
(v for v in get_installed_solc_versions() if str(v) == version), None)
if installed:
print(f'Using solc version {version}')
set_solc_version(installed)
version = installed
else:
version = install_solc(version, show_progress=True)
try:
compiled = compile_standard(
{
"language": "Solidity",
"sources": {contract_path: {"content": contract_content}},
"settings": {
"outputSelection": {
"*": {
"*": [],
"": [
"ast",
]
}
}
},
},
solc_version=version,
)
keys = compiled.keys()
print(keys)
# print(compiled['sources'])
for error in compiled['errors']:
print('\n\n\n')
print(error['formattedMessage'])
except Exception as e:
print(e)