@ggflutter/sumo
Advanced tools
Comparing version 2.5.7492 to 2.5.7493
{ | ||
"author": "Luigi Allocca", | ||
"name": "@ggflutter/sumo", | ||
"version": "2.5.7492", | ||
"version": "2.5.7493", | ||
"description": "A mutation testing tool for Ethereum smart contracts", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -11,37 +11,38 @@ const Mutation = require('../../../mutation'); | ||
console.log("Visitatore chiamato"); // Verifica se il visitatore viene chiamato | ||
visit({ | ||
ExpressionStatement: (node) => { | ||
console.log("Trovato ExpressionStatement: ", JSON.stringify(node, null, 2)); | ||
}, | ||
MemberExpression: (node) => { | ||
console.log("Trovato MemberExpression: ", JSON.stringify(node, null, 2)); | ||
}, | ||
BinaryExpression: (node) => { | ||
console.log("Trovato BinaryExpression: ", JSON.stringify(node, null, 2)); | ||
}, | ||
CallExpression: (node) => { | ||
console.log("Trovato CallExpression"); // Verifica se si entra nel CallExpression | ||
// Verifica se è un'operazione binaria (assegnazione) | ||
if (node.expression.type === 'BinaryOperation') { | ||
const binaryOperation = node.expression; | ||
if ( | ||
node.callee.name === 'keccak256' && | ||
node.arguments.length === 1 && | ||
node.arguments[0].callee.object.name === 'abi' && | ||
node.arguments[0].callee.property.name === 'encodePacked' | ||
) { | ||
console.log("Trovato keccak256 con abi.encodePacked"); | ||
// Verifica se l'operazione è un assegnamento a una chiamata di funzione (FunctionCall) | ||
if (binaryOperation.right.type === 'FunctionCall') { | ||
const functionCall = binaryOperation.right; | ||
const start = node.range[0]; | ||
const end = node.range[1]; | ||
const startLine = node.loc.start.line; | ||
const endLine = node.loc.end.line; | ||
const original = source.slice(start, end); | ||
// Verifica se la funzione chiamata è `keccak256` | ||
if (functionCall.expression.name === 'keccak256') { | ||
// Sostituzione della funzione di hashing con `data` | ||
const replacement = source.substring(0, start) + 'data' + source.substring(end); | ||
// Verifica se l'argomento di `keccak256` è una chiamata a `abi.encodePacked` | ||
const innerFunctionCall = functionCall.arguments[0]; | ||
if ( | ||
innerFunctionCall.type === 'FunctionCall' && | ||
innerFunctionCall.expression.type === 'MemberAccess' && | ||
innerFunctionCall.expression.expression.name === 'abi' && | ||
innerFunctionCall.expression.memberName === 'encodePacked' | ||
) { | ||
console.log("Trovato keccak256 con abi.encodePacked"); | ||
const start = functionCall.range[0]; | ||
const end = functionCall.range[1]; | ||
const startLine = node.loc.start.line; | ||
const endLine = node.loc.end.line; | ||
const original = source.slice(start, end); | ||
mutations.push(new Mutation(file, start, end, startLine, endLine, original, replacement, this.ID)); | ||
} else { | ||
console.log("CallExpression diversa da keccak256 con abi.encodePacked"); | ||
// Sostituzione della funzione di hashing con `data` | ||
const replacement = source.substring(0, start) + 'data' + source.substring(end); | ||
mutations.push(new Mutation(file, start, end, startLine, endLine, original, replacement, this.ID)); | ||
} | ||
} | ||
} | ||
} | ||
@@ -48,0 +49,0 @@ } |
351036