diff --git a/scripts/bytecodecompare/prepare_report.py b/scripts/bytecodecompare/prepare_report.py index 847e3ee0e..9a3d86c8d 100755 --- a/scripts/bytecodecompare/prepare_report.py +++ b/scripts/bytecodecompare/prepare_report.py @@ -5,37 +5,37 @@ import glob import subprocess import json -solc = sys.argv[1] -report = open("report.txt", "wb") +SOLC_BIN = sys.argv[1] +REPORT_FILE = open("report.txt", "wb") for optimize in [False, True]: for f in sorted(glob.glob("*.sol")): sources = {} sources[f] = {'content': open(f, 'r').read()} - input = { + input_json = { 'language': 'Solidity', 'sources': sources, 'settings': { 'optimizer': { 'enabled': optimize }, - 'outputSelection': { '*': { '*': ['evm.bytecode.object', 'metadata'] } } + 'outputSelection': {'*': {'*': ['evm.bytecode.object', 'metadata']}} } } - args = [solc, '--standard-json'] + args = [SOLC_BIN, '--standard-json'] if optimize: args += ['--optimize'] proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (out, err) = proc.communicate(json.dumps(input)) + (out, err) = proc.communicate(json.dumps(input_json)) try: result = json.loads(out.strip()) for filename in sorted(result['contracts'].keys()): for contractName in sorted(result['contracts'][filename].keys()): contractData = result['contracts'][filename][contractName] if 'evm' in contractData and 'bytecode' in contractData['evm']: - report.write(filename + ':' + contractName + ' ' + contractData['evm']['bytecode']['object'] + '\n') + REPORT_FILE.write(filename + ':' + contractName + ' ' + contractData['evm']['bytecode']['object'] + '\n') else: - report.write(filename + ':' + contractName + ' NO BYTECODE\n') - report.write(filename + ':' + contractName + ' ' + contractData['metadata'] + '\n') + REPORT_FILE.write(filename + ':' + contractName + ' NO BYTECODE\n') + REPORT_FILE.write(filename + ':' + contractName + ' ' + contractData['metadata'] + '\n') except KeyError: - report.write(f + ": ERROR\n") + REPORT_FILE.write(f + ": ERROR\n") diff --git a/scripts/extract_test_cases.py b/scripts/extract_test_cases.py index e6764b466..63314760c 100755 --- a/scripts/extract_test_cases.py +++ b/scripts/extract_test_cases.py @@ -8,12 +8,9 @@ import sys import re -import os -import hashlib -from os.path import join -def extract_test_cases(path): - lines = open(path, 'rb').read().splitlines() +def extract_test_cases(_path): + lines = open(_path, 'rb').read().splitlines() inside = False delimiter = '' @@ -23,27 +20,24 @@ def extract_test_cases(path): test_name = '' for l in lines: - if inside: - if l.strip().endswith(')' + delimiter + '";'): - open('%03d_%s.sol' % (ctr, test_name), 'wb').write(test) - ctr += 1 - inside = False - test = '' + if inside: + if l.strip().endswith(')' + delimiter + '";'): + open('%03d_%s.sol' % (ctr, test_name), 'wb').write(test) + ctr += 1 + inside = False + test = '' + else: + l = re.sub('^\t\t', '', l) + l = l.replace('\t', ' ') + test += l + '\n' else: - l = re.sub('^\t\t', '', l) - l = l.replace('\t', ' ') - test += l + '\n' - else: - m = re.search(r'BOOST_AUTO_TEST_CASE\(([^(]*)\)', l.strip()) - if m: - test_name = m.group(1) - m = re.search(r'R"([^(]*)\($', l.strip()) - if m: - inside = True - delimiter = m.group(1) - + m = re.search(r'BOOST_AUTO_TEST_CASE\(([^(]*)\)', l.strip()) + if m: + test_name = m.group(1) + m = re.search(r'R"([^(]*)\($', l.strip()) + if m: + inside = True + delimiter = m.group(1) if __name__ == '__main__': - path = sys.argv[1] - extract_test_cases(path) - + extract_test_cases(sys.argv[1])