prepare_report: Unify error/missing data handling between JS and Python versions

This commit is contained in:
Kamil Śliwak 2020-12-22 02:08:40 +01:00
parent a036cbea19
commit 9f58f77b50
2 changed files with 28 additions and 22 deletions

View File

@ -23,24 +23,27 @@ for (const optimize of [false, true])
}
const result = JSON.parse(compiler.compile(JSON.stringify(input)))
if (
!('contracts' in result) ||
Object.keys(result['contracts']).length === 0 ||
!result['contracts'][filename] ||
Object.keys(result['contracts'][filename]).length === 0
Object.keys(result['contracts']).every(file => Object.keys(result['contracts'][file]).length === 0)
)
// NOTE: do not exit here because this may be run on source which cannot be compiled
console.log(filename + ': ERROR')
else
for (const contractName in result['contracts'][filename])
{
const contractData = result['contracts'][filename][contractName];
if (contractData.evm !== undefined && contractData.evm.bytecode !== undefined)
console.log(filename + ':' + contractName + ' ' + contractData.evm.bytecode.object)
else
console.log(filename + ':' + contractName + ' NO BYTECODE')
console.log(filename + ':' + contractName + ' ' + contractData.metadata)
}
for (const contractFile in result['contracts'])
for (const contractName in result['contracts'][contractFile])
{
const contractResults = result['contracts'][contractFile][contractName]
let bytecode = 'NO BYTECODE'
if ('evm' in contractResults && 'bytecode' in contractResults['evm'] && 'object' in contractResults['evm']['bytecode'])
bytecode = contractResults.evm.bytecode.object
console.log(filename + ':' + contractName + ' ' + bytecode)
console.log(filename + ':' + contractName + ' ' + contractResults['metadata'])
}
}
}
}

View File

@ -28,16 +28,19 @@ for optimize in [False, True]:
args += ['--optimize']
proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = proc.communicate(json.dumps(input_json).encode('utf-8'))
try:
result = json.loads(out.decode('utf-8').strip())
result = json.loads(out.decode('utf-8').strip())
if (
'contracts' not in result or
len(result['contracts']) == 0 or
all(len(file_results) == 0 for file_name, file_results in result['contracts'].items())
):
REPORT_FILE.write(f + ": ERROR\n")
else:
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_FILE.write(filename + ':' + contractName + ' ' +
contractData['evm']['bytecode']['object'] + '\n')
else:
REPORT_FILE.write(filename + ':' + contractName + ' NO BYTECODE\n')
REPORT_FILE.write(filename + ':' + contractName + ' ' + contractData['metadata'] + '\n')
except KeyError:
REPORT_FILE.write(f + ": ERROR\n")
bytecode = result['contracts'][filename][contractName].get('evm', {}).get('bytecode', {}).get('object', 'NO BYTECODE')
metadata = result['contracts'][filename][contractName]['metadata']
REPORT_FILE.write(filename + ':' + contractName + ' ' + bytecode + '\n')
REPORT_FILE.write(filename + ':' + contractName + ' ' + metadata + '\n')