add support for null inputs and fallback and constructor types

Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
VoR0220 2018-06-12 10:31:26 -05:00
parent 0ff39f48b3
commit 57f098239d
2 changed files with 10 additions and 5 deletions

View File

@ -23,10 +23,15 @@ class GasEstimator {
async.each(contract.abiDefinition,
(abiMethod, gasCb) => {
let name = abiMethod.name;
console.log("NAME: ", name);
console.log("ABI INPUTS: ", abiMethod.inputs);
if (abiMethod.type === "constructor") {
// already provided for us
gasCb(null, 'constructor', contract.gasEstimates.creation.totalCost);
} else if (abiMethod.inputs === []) {
gasCb(null, 'constructor', contract.gasEstimates.creation.totalCost.toString());
} else if (abiMethod.type === "fallback") {
gasCb(null, 'fallback', contract.gasEstimates.external[""].toString());
} else if (abiMethod.inputs === null || abiMethod.inputs === undefined || abiMethod.inputs.length === 0) {
console.log("Are we hitting here");
// just run it and register it
contractObj.methods[name]
.apply(contractObj.methods[name], [])
@ -46,7 +51,7 @@ class GasEstimator {
}, (err, variance) => {
if (err) {
gasCb(err)
} else if (variance.reduce(_.isEqual, variance[2])) {
} else if (_.isEqual(variance[0], variance[1]) && _.isEqual(variance[1], variance[2])) {
gasMap[name] = variance[0];
} else {
gasMap[name] = 'variable';

View File

@ -21,10 +21,10 @@ class Profiler {
console.log("Abi Method Gastimate: ", gastimates[abiMethod.name]);
switch(abiMethod.type) {
case "constructor":
table.addRow("constructor", abiMethod.payable, abiMethod.stateMutability, this.formatParams(abiMethod.inputs), this.formatParams(abiMethod.outputs), gastimates['constructor']);
table.addRow("constructor", abiMethod.payable, abiMethod.stateMutability, self.formatParams(abiMethod.inputs), self.formatParams(abiMethod.outputs), gastimates['constructor']);
break;
default:
table.addRow(abiMethod.name, abiMethod.payable, abiMethod.stateMutability, this.formatParams(abiMethod.inputs), this.formatParams(abiMethod.outputs), gastimates[abiMethod.name]);
table.addRow(abiMethod.name, abiMethod.payable, abiMethod.stateMutability, self.formatParams(abiMethod.inputs), self.formatParams(abiMethod.outputs), gastimates[abiMethod.name]);
}
});
self.logger.info(table.toString());