small fixes to ensure something of a better experience for error reporting on the profiler side

Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
VoR0220 2018-06-15 15:22:27 -05:00
parent 6ea395ca76
commit ad6a6cf328
2 changed files with 20 additions and 14 deletions

View File

@ -22,21 +22,23 @@ class GasEstimator {
async.each(contract.abiDefinition.filter((x) => x.type !== "event"),
(abiMethod, gasCb) => {
let name = abiMethod.name;
if (abiMethod.type === "constructor") {
if (abiMethod.type == "constructor") {
// already provided for us
gasMap['constructor'] = contract.gasEstimates.creation.totalCost.toString();
gasCb();
} else if (abiMethod.type === "fallback") {
return gasCb(null, name, abiMethod.type);
} else if (abiMethod.type == "fallback") {
gasMap['fallback'] = contract.gasEstimates.external[""].toString();
gasCb();
} else if (abiMethod.inputs === null || abiMethod.inputs === undefined || abiMethod.inputs.length === 0) {
return gasCb(null, name, abiMethod.type);
} else if (
(abiMethod.inputs === null || abiMethod.inputs === undefined || abiMethod.inputs.length === 0)
) {
// just run it and register it
contractObj.methods[name]
.apply(contractObj.methods[name], [])
.estimateGas((err, gasAmount) => {
if (err) return gasCb(err);
if (err) return gasCb(err, name, abiMethod.type);
gasMap[name] = gasAmount;
gasCb();
return gasCb(null, name, abiMethod.type);
});
} else {
// async concatenate all the fuzz values and their gas cost outputs and check for equality
@ -47,19 +49,22 @@ class GasEstimator {
});
}, (err, variance) => {
if (err) {
return gasCb(err);
return gasCb(err, name, abiMethod.type);
} else if (_.isEqual(variance[0], variance[1]) && _.isEqual(variance[1], variance[2])) {
gasMap[name] = variance[0];
} else {
gasMap[name] = 'infinite';
}
gasCb();
return gasCb(null, name, abiMethod.type);
});
}
},
(err) => {
if (err) return cb(err);
cb(null, gasMap);
(err, name, type) => {
if (err) {
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;
let table = new asciiTable(contractName);
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) {
self.logger.error(err);
self.logger.error('error found in method: ', name);
self.logger.error(JSON.stringify(err));
return;
}
contract.abiDefinition.forEach((abiMethod) => {