convert console logs to embark logger and this baby is ready to rock
Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
parent
a7629d2ac0
commit
773f5a7921
|
@ -16,25 +16,20 @@ class ContractFuzzer {
|
||||||
// main function to call, takes in iteration number and a contract and returns a map object
|
// main function to call, takes in iteration number and a contract and returns a map object
|
||||||
// composed of method names -> fuzzed inputs.
|
// composed of method names -> fuzzed inputs.
|
||||||
generateFuzz(iterations, contract) {
|
generateFuzz(iterations, contract) {
|
||||||
|
const self = this;
|
||||||
let fuzzMap = {};
|
let fuzzMap = {};
|
||||||
for (let i = 0; i < iterations; i++) contract.abiDefinition.filter((x) => x.inputs && x.inputs.length != 0).forEach((abiMethod) => {
|
for (let i = 0; i < iterations; i++) contract.abiDefinition.filter((x) => x.inputs && x.inputs.length != 0).forEach((abiMethod) => {
|
||||||
let name = abiMethod.type === "constructor" ? "constructor" : abiMethod.name;
|
let name = abiMethod.type === "constructor" ? "constructor" : abiMethod.name;
|
||||||
console.log("name");
|
|
||||||
let inputTypes = abiMethod.inputs.map(input => input.type);
|
let inputTypes = abiMethod.inputs.map(input => input.type);
|
||||||
console.log("INPUT TYPES:", inputTypes);
|
|
||||||
let fuzzedInputs = _.map(inputTypes, this.getTypeFuzz.bind(this));
|
let fuzzedInputs = _.map(inputTypes, this.getTypeFuzz.bind(this));
|
||||||
console.log("FUZZED INPUTS:", fuzzedInputs);
|
|
||||||
fuzzMap[name] = fuzzedInputs;
|
fuzzMap[name] = fuzzedInputs;
|
||||||
console.log("FUZZ KEYS SO FAR:", Object.keys(fuzzMap));
|
|
||||||
console.log("FUZZ VALS SO FAR:", Object.values(fuzzMap));
|
|
||||||
});
|
});
|
||||||
console.log("FUZZ:", Object.keys(fuzzMap), Object.values(fuzzMap));
|
for (let key in fuzzMap) self.logger.info(key + ":" + fuzzMap[key]);
|
||||||
return fuzzMap;
|
return fuzzMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
getTypeFuzz(typeString) {
|
getTypeFuzz(typeString) {
|
||||||
const self = this;
|
const self = this;
|
||||||
console.log("TYPESTRING:", typeString);
|
|
||||||
// Group 0: uint256[3]
|
// Group 0: uint256[3]
|
||||||
// Group 1: uint256
|
// Group 1: uint256
|
||||||
// Group 2: uint
|
// Group 2: uint
|
||||||
|
@ -42,22 +37,15 @@ class ContractFuzzer {
|
||||||
// Group 4: [3]
|
// Group 4: [3]
|
||||||
// Group 5: 3
|
// Group 5: 3
|
||||||
let regexObj = typeString.match(/((bool|int|uint|bytes|string|address)([0-9]*)?)(\[([0-9]*)\])*$/);
|
let regexObj = typeString.match(/((bool|int|uint|bytes|string|address)([0-9]*)?)(\[([0-9]*)\])*$/);
|
||||||
console.log("REGEX OBJ:", regexObj);
|
|
||||||
let type = regexObj[1];
|
let type = regexObj[1];
|
||||||
console.log("type:", type);
|
|
||||||
let kind = regexObj[2];
|
let kind = regexObj[2];
|
||||||
console.log("kind:", kind);
|
|
||||||
let size = regexObj[3];
|
let size = regexObj[3];
|
||||||
console.log("size:", size);
|
|
||||||
let array = regexObj[4];
|
let array = regexObj[4];
|
||||||
console.log("array:", array);
|
|
||||||
let arraySize = regexObj[5];
|
let arraySize = regexObj[5];
|
||||||
console.log("array size:", arraySize);
|
|
||||||
switch(true) {
|
switch(true) {
|
||||||
case array !== undefined: {
|
case array !== undefined: {
|
||||||
// if it's a dynamic array pick a number between 1 and 256 for length of array
|
// if it's a dynamic array pick a number between 1 and 256 for length of array
|
||||||
let length = arraySize === undefined || arraySize === null || arraySize === '' ? Math.floor((Math.random() * 256) + 1) : arraySize;
|
let length = arraySize === undefined || arraySize === null || arraySize === '' ? Math.floor((Math.random() * 256) + 1) : arraySize;
|
||||||
console.log("LENGTH: ", length);
|
|
||||||
return self.generateArrayOfType(length, type);
|
return self.generateArrayOfType(length, type);
|
||||||
}
|
}
|
||||||
case kind == "bool":
|
case kind == "bool":
|
||||||
|
@ -81,10 +69,7 @@ class ContractFuzzer {
|
||||||
|
|
||||||
generateArrayOfType(length, type) {
|
generateArrayOfType(length, type) {
|
||||||
var arr = [];
|
var arr = [];
|
||||||
for (var i = 0; i < length; i++) {
|
for (var i = 0; i < length; i++) arr.push(this.getTypeFuzz(type));
|
||||||
arr.push(this.getTypeFuzz(type));
|
|
||||||
}
|
|
||||||
console.log("Final Array:", arr);
|
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue