Merge pull request #540 from embark-framework/profilerErrorLogFix

small fixes to ensure something of a better experience for error reports
This commit is contained in:
Iuri Matias 2018-06-15 17:24:35 -04:00 committed by GitHub
commit 6b11fb9e45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 13 deletions

View File

@ -25,18 +25,20 @@ class GasEstimator {
if (abiMethod.type === "constructor") { if (abiMethod.type === "constructor") {
// already provided for us // already provided for us
gasMap['constructor'] = contract.gasEstimates.creation.totalCost.toString(); gasMap['constructor'] = contract.gasEstimates.creation.totalCost.toString();
gasCb(); return gasCb(null, name, abiMethod.type);
} else if (abiMethod.type === "fallback") { } else if (abiMethod.type == "fallback") {
gasMap['fallback'] = contract.gasEstimates.external[""].toString(); gasMap['fallback'] = contract.gasEstimates.external[""].toString();
gasCb(); return gasCb(null, name, abiMethod.type);
} else if (abiMethod.inputs === null || abiMethod.inputs === undefined || abiMethod.inputs.length === 0) { } else if (
(abiMethod.inputs === null || abiMethod.inputs === undefined || abiMethod.inputs.length === 0)
) {
// just run it and register it // just run it and register it
contractObj.methods[name] contractObj.methods[name]
.apply(contractObj.methods[name], []) .apply(contractObj.methods[name], [])
.estimateGas((err, gasAmount) => { .estimateGas((err, gasAmount) => {
if (err) return gasCb(err); if (err) return gasCb(err, name, abiMethod.type);
gasMap[name] = gasAmount; gasMap[name] = gasAmount;
gasCb(); return gasCb(null, name, abiMethod.type);
}); });
} else { } else {
// async concatenate all the fuzz values and their gas cost outputs and check for equality // async concatenate all the fuzz values and their gas cost outputs and check for equality
@ -47,19 +49,22 @@ class GasEstimator {
}); });
}, (err, variance) => { }, (err, variance) => {
if (err) { if (err) {
return gasCb(err); return gasCb(err, name, abiMethod.type);
} else if (_.isEqual(variance[0], variance[1]) && _.isEqual(variance[1], variance[2])) { } else if (_.isEqual(variance[0], variance[1]) && _.isEqual(variance[1], variance[2])) {
gasMap[name] = variance[0]; gasMap[name] = variance[0];
} else { } else {
gasMap[name] = 'infinite'; gasMap[name] = 'infinite';
} }
gasCb(); return gasCb(null, name, abiMethod.type);
}); });
} }
}, },
(err) => { (err, name, type) => {
if (err) return cb(err); if (err) {
cb(null, gasMap); if (type === "constructor" || type === "fallback") name = type;
return cb(err, null, name);
}
cb(null, gasMap, null);
} }
); );
}); });

View File

@ -15,9 +15,10 @@ class Profiler {
const self = this; const self = this;
let table = new asciiTable(contractName); let table = new asciiTable(contractName);
table.setHeading('Function', 'Payable', 'Mutability', 'Inputs', 'Outputs', 'Gas Estimates'); table.setHeading('Function', 'Payable', 'Mutability', 'Inputs', 'Outputs', 'Gas Estimates');
self.gasEstimator.estimateGas(contractName, function(err, gastimates) { self.gasEstimator.estimateGas(contractName, function(err, gastimates, name) {
if (err) { if (err) {
self.logger.error(err); self.logger.error('error found in method: ', name);
self.logger.error(JSON.stringify(err));
return; return;
} }
contract.abiDefinition.forEach((abiMethod) => { contract.abiDefinition.forEach((abiMethod) => {