@ggflutter/sumo
Advanced tools
Comparing version 2.5.7494 to 2.5.7495
{ | ||
"author": "Luigi Allocca", | ||
"name": "@ggflutter/sumo", | ||
"version": "2.5.7494", | ||
"version": "2.5.7495", | ||
"description": "A mutation testing tool for Ethereum smart contracts", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -15,6 +15,4 @@ const Mutation = require('../../../mutation'); | ||
// Accede direttamente agli statements nel corpo della funzione | ||
const bodyStatements = node.body.statements; | ||
// Verifica se ci sono statements nel corpo della funzione | ||
if (bodyStatements && Array.isArray(bodyStatements)) { | ||
@@ -26,41 +24,34 @@ console.log("Found function body statements"); | ||
const start = statement.range[0]; | ||
const end = statement.range[1]; | ||
const startLine = statement.loc.start.line; | ||
const endLine = statement.loc.end.line; | ||
const original = source.slice(start, end); | ||
// Estendi l'analisi per espressioni diverse | ||
if (statement.type === "ExpressionStatement") { | ||
const expression = statement.expression; | ||
if (expression.type === "FunctionCall") { | ||
const args = expression.arguments; | ||
args.forEach((arg, index) => { | ||
const start = arg.range[0]; | ||
const end = arg.range[1]; | ||
const original = source.slice(start, end); | ||
// Inserisce un valore nullo o predefinito in una variabile di input | ||
let replacement; | ||
let replacement = original; | ||
if (statement.type === "ExpressionStatement" && statement.expression.type === "Assignment") { | ||
const variable = statement.expression.left.name; | ||
const variableType = statement.expression.right.typeName; | ||
if (arg.typeName.name === "uint256" || arg.typeName.name === "int256" || arg.typeName.name === "uint" || arg.typeName.name === "int") { | ||
replacement = "0"; | ||
} else if (arg.typeName.name === "address") { | ||
replacement = "address(0)"; | ||
} else if (arg.typeName.name === "bool") { | ||
replacement = "false"; | ||
} else if (arg.typeName.type === "ArrayTypeName" || arg.typeName.type === "Mapping") { | ||
replacement = "[]"; | ||
} else if (arg.typeName.type === "UserDefinedTypeName") { | ||
replacement = "0"; | ||
} else { | ||
replacement = "''"; // String o altro | ||
} | ||
console.log(`Found assignment to variable '${variable}' of type '${variableType.name}'`); | ||
const replacementString = source.slice(0, start) + replacement + source.slice(end); | ||
if (variableType.name === "uint256" || variableType.name === "int256" || variableType.name === "uint" || variableType.name === "int") { | ||
replacement = `${variable} = 0;`; | ||
console.log(`Replacing with: ${replacement}`); | ||
} else if (variableType.name === "address") { | ||
replacement = `${variable} = address(0);`; | ||
console.log(`Replacing with: ${replacement}`); | ||
} else if (variableType.name === "bool") { | ||
replacement = `${variable} = false;`; | ||
console.log(`Replacing with: ${replacement}`); | ||
} else if (variableType.type === "ArrayTypeName" || variableType.type === "Mapping") { | ||
replacement = `${variable} = [];`; | ||
console.log(`Replacing with: ${replacement}`); | ||
} else if (variableType.type === "UserDefinedTypeName") { | ||
replacement = `${variable} = 0;`; // Assume è un tipo definito dall'utente con un valore predefinito di 0 | ||
console.log(`Replacing with: ${replacement}`); | ||
} else { | ||
replacement = `${variable} = '';`; // Per stringhe o altri tipi | ||
console.log(`Replacing with: ${replacement}`); | ||
mutations.push(new Mutation(file, start, end, statement.loc.start.line, statement.loc.end.line, original, replacementString, this.ID)); | ||
console.log(`Mutation added for argument ${index} in function call.`); | ||
}); | ||
} | ||
const replacementString = source.slice(0, start) + replacement + source.slice(end); | ||
mutations.push(new Mutation(file, start, end, startLine, endLine, original, replacementString, this.ID)); | ||
console.log("Mutation added"); | ||
} | ||
@@ -67,0 +58,0 @@ }); |
351609
6825