gas estimator and fuzzer

Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
VoR0220 2018-05-21 08:38:13 -05:00
parent d3c4f6275c
commit f4bca2710f
2 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,57 @@
const ethAbi = require('web3-eth-abi');
const utils = require('web3-utils');
const _ = require('underscore');
// generates random inputs based on the inputs of an ABI
class ContractFuzzer {
constructor(abi) {
this.abi = abi;
}
generateFuzz() {
this.abi.forEach((abiMethod) => {
let inputTypes = abiMethod.inputs.map(input => input.type);
let fuzzedInputType = _.reduce(inputTypes, decipherType, 0);
})
}
getTypeFuzz(type) {
switch() {
case 'uintN' || 'intN':
case 'bytesN':
return generateRandomStaticBytes(size);
case 'string' || 'bytes':
return generateRandomDynamicType()
case 'address':
return generateRandomAddress();
default:
}
}
generateArrayOfType(length, type) {
var arr = [];
for (var i = 0; i < length; i++) {
arr.push(getTypeFuzz(type));
}
return arr;
}
generateRandomDynamicType() {
return Math.random().toString(36).slice(2);
}
generateRandomStaticBytes(size) {
return utils.randomHex(size);
}
generateRandomInt(size) {
return utils.hexToNumber(utils.randomHex(size));
}
generateRandomAddress() {
return utils.randomHex(20);
}
}

View File

@ -0,0 +1,11 @@
const ethAbi = require('web3-eth-abi');
const contract = require('web3-eth-contract');
class GasEstimator {
constructor(provider, abi, iterations) {
this.abi = abi;
this.iters = iterations;
}
}