fix the callback schema for async and pretty it up a bit
Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
parent
90f342b65a
commit
0ff39f48b3
|
@ -20,37 +20,46 @@ class GasEstimator {
|
|||
let fuzzMap = self.fuzzer.generateFuzz(3, contract);
|
||||
self.logger.info("-- Beginning gastimation for contract -- " + contractName);
|
||||
let contractObj = new web3.eth.Contract(contract.abiDefinition, contract.deployedAddress);
|
||||
async.each(contract.abiDefinition, function(abiMethod, gasCb) => {
|
||||
async.each(contract.abiDefinition,
|
||||
(abiMethod, gasCb) => {
|
||||
let name = abiMethod.name;
|
||||
if (abiMethod.type === "constructor") {
|
||||
// already provided for us
|
||||
gasCb(null, 'constructor', contract.gasEstimates.creation.totalCost);
|
||||
} else if (abiMethod.inputs.length === 0) {
|
||||
} else if (abiMethod.inputs === []) {
|
||||
// just run it and register it
|
||||
contractObj.methods[name]
|
||||
.apply(contractObj.methods[name], [])
|
||||
.estimateGas(function(err, gasAmount) {
|
||||
.estimateGas((err, gasAmount) => {
|
||||
if (err) gasCb(err);
|
||||
gasMap[name] = gasAmount;
|
||||
gasCb(err, gasAmount, name);
|
||||
});
|
||||
} else {
|
||||
// async concatenate all the fuzz values and their gas cost outputs and check for equality
|
||||
async.concat(fuzzMap[name], function(values, getVarianceCb) {
|
||||
async.concat(fuzzMap[name], (values, getVarianceCb) => {
|
||||
contractObj.methods[name]
|
||||
.apply(contractObj.methods[name], values)
|
||||
.estimateGas(function(err, gasAmount) {
|
||||
.estimateGas((err, gasAmount) => {
|
||||
getVarianceCb(err, [gasAmount]);
|
||||
});
|
||||
}, function(err, variance) {
|
||||
if (err) gasCb(err)
|
||||
else if (variance.reduce(_.isEqual) gasCb(null, variance[0], name);
|
||||
gasCb(null, 'variable', name);
|
||||
});
|
||||
});
|
||||
},
|
||||
function(err, gasAmount, name) => {
|
||||
if (err) return cb(err);
|
||||
gasMap[name] = gasAmount;
|
||||
}, (err, variance) => {
|
||||
if (err) {
|
||||
gasCb(err)
|
||||
} else if (variance.reduce(_.isEqual, variance[2])) {
|
||||
gasMap[name] = variance[0];
|
||||
} else {
|
||||
gasMap[name] = 'variable';
|
||||
}
|
||||
gasCb();
|
||||
});
|
||||
};
|
||||
},
|
||||
(err) => {
|
||||
if (err) return cb(err);
|
||||
cb(null, gasMap);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@ class Profiler {
|
|||
const self = this;
|
||||
let table = new asciiTable(contractName);
|
||||
table.setHeading('Function', 'Payable', 'Mutability', 'Inputs', 'Outputs', 'Gas Estimates');
|
||||
let gastimates = self.gasEstimator.estimateGas(contractName);
|
||||
self.gasEstimator.estimateGas(contractName, function(err, gastimates) {
|
||||
if (err) throw new Error(err);
|
||||
contract.abiDefinition.forEach((abiMethod) => {
|
||||
console.log("Abi Method Gastimate: ", gastimates[abiMethod.name]);
|
||||
switch(abiMethod.type) {
|
||||
|
@ -27,6 +28,7 @@ class Profiler {
|
|||
}
|
||||
});
|
||||
self.logger.info(table.toString());
|
||||
});
|
||||
}
|
||||
|
||||
formatParams(params) {
|
||||
|
|
Loading…
Reference in New Issue