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") {
// 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) => {