changes to the logic around gas estimator and profiler
Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
parent
311ec7d9cb
commit
5c7e9f0054
|
@ -1,5 +1,7 @@
|
|||
const ContractFuzzer = require('../fuzzer');
|
||||
|
||||
/*global web3*/
|
||||
|
||||
class GasEstimator {
|
||||
constructor(embark) {
|
||||
this.embark = embark;
|
||||
|
@ -16,20 +18,32 @@ class GasEstimator {
|
|||
let fuzzMap = self.fuzzer.generateFuzz(3, contract);
|
||||
self.logger.info("-- Beginning gastimation for contract -- " + contractName);
|
||||
let tempGasMap = {};
|
||||
let contractObj = new web3.eth.Contract(contract.abiDefinition, contract.deployedAddress);
|
||||
for (let i = 0; i < 3; i++) {
|
||||
tempGasMap[i] = {}
|
||||
tempGasMap[i] = {};
|
||||
for (let name in fuzzMap[i]) {
|
||||
tempGasMap[i][name] = contract.methods[name].apply(contract.methods[name], fuzzMap[i][name]).estimateGas();
|
||||
tempGasMap[i][name] = contractObj.methods[name]
|
||||
.apply(contractObj.methods[name], fuzzMap[i][name])
|
||||
.estimateGas()
|
||||
.then(estimatedGas => estimatedGas)
|
||||
.catch(err => err);
|
||||
}
|
||||
};
|
||||
tempGasMap.forEach((name) => {
|
||||
if (name === "constructor") {
|
||||
}
|
||||
contract.abiDefinition.forEach((abiMethod) => {
|
||||
let name = abiMethod.name;
|
||||
console.log("estimaticating the gas for method name: ", name);
|
||||
if (abiMethod.type === "constructor") {
|
||||
gasMap[name] = contract.gasEstimates.creation.totalCost;
|
||||
} else if (tempGasMap[name][0] !== tempGasMap[name][1] && tempGasMap[name][1] !== tempGasMap[name][2]) {
|
||||
} else if (abiMethod.inputs.length === 0) {
|
||||
gasMap[name] = contractObj.methods[name].apply(contractObj.methods[name], []).estimateGas()
|
||||
.then(estimatedGas => estimatedGas)
|
||||
.catch(err => err);
|
||||
} else if (tempGasMap[0][name] !== tempGasMap[1][name] && tempGasMap[1][name] !== tempGasMap[2][name]) {
|
||||
gasMap[name] = 'variable';
|
||||
} else {
|
||||
gasMap[name] = tempGasMap[name][0];
|
||||
}
|
||||
console.log("Estimate Gas ForEAch: ", gasMap[name]);
|
||||
});
|
||||
return gasMap;
|
||||
});
|
||||
|
|
|
@ -17,6 +17,7 @@ class Profiler {
|
|||
table.setHeading('Function', 'Payable', 'Mutability', 'Inputs', 'Outputs', 'Gas Estimates');
|
||||
let gastimates = self.gasEstimator.estimateGas(contractName);
|
||||
contract.abiDefinition.forEach((abiMethod) => {
|
||||
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']);
|
||||
|
|
Loading…
Reference in New Issue