@ggflutter/sumo
Advanced tools
Comparing version 2.5.739 to 2.5.740
{ | ||
"author": "Luigi Allocca", | ||
"name": "@ggflutter/sumo", | ||
"version": "2.5.739", | ||
"version": "2.5.740", | ||
"description": "A mutation testing tool for Ethereum smart contracts", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -24,34 +24,33 @@ const Mutation = require('../../../mutation'); | ||
for (let i = 0; i < blockStatements.length - 1; i++) { | ||
const currentStatement = blockStatements[i]; | ||
const nextStatement = blockStatements[i + 1]; | ||
const statement = body[i]; | ||
const nextStatement = body[i + 1]; | ||
// Skip if either statement is missing | ||
if (!currentStatement || !nextStatement) { | ||
console.log("Skipping mutation: Not enough statements to mutate."); | ||
continue; | ||
} | ||
if (!statement || !nextStatement) { | ||
console.log("Skipping mutation: Not enough statements to mutate."); | ||
continue; | ||
} | ||
// Ensure the statements are of the right types | ||
if (currentStatement.type === "ExpressionStatement" && nextStatement.type === "ExpressionStatement") { | ||
const currentStatementRange = currentStatement.range; | ||
const nextStatementRange = nextStatement.range; | ||
// Check if the statement is a state change (e.g., assignment or update) | ||
const isStateChange = statement.type === "ExpressionStatement" && ( | ||
statement.expression.type === "AssignmentExpression" || | ||
statement.expression.type === "UpdateExpression" | ||
); | ||
// Create the original and replacement code | ||
const start = currentStatementRange[1] + 1; // Start right after the end of the current statement | ||
const end = nextStatementRange[0]; // End right before the start of the next statement | ||
const startLine = currentStatement.loc.end.line; | ||
const endLine = nextStatement.loc.start.line; | ||
// Check if the next statement is an external call | ||
const isExternalCall = nextStatement.type === "ExpressionStatement" && | ||
nextStatement.expression.type === "CallExpression" && | ||
nextStatement.expression.callee.type === "MemberExpression" && | ||
["call", "delegatecall", "send"].includes(nextStatement.expression.callee.property.name); | ||
// Extract original code segments | ||
const original = source.slice(currentStatementRange[0], nextStatementRange[1]); | ||
if (isStateChange && isExternalCall) { | ||
const startLine = statement.loc.start.line; | ||
const endLine = nextStatement.loc.end.line; | ||
const original = source.slice(statement.range[0], nextStatement.range[1]); | ||
// Create the replacement code by swapping the two statements | ||
const replacement = source.slice(nextStatementRange[0], nextStatementRange[1]) + "\n" + | ||
source.slice(currentStatementRange[0], currentStatementRange[1]); | ||
const swapped = source.slice(nextStatement.range[0], nextStatement.range[1]) + "\n" + | ||
source.slice(statement.range[0], statement.range[1]); | ||
// Create the new source code with the mutation applied | ||
const newSource = source.substring(0, currentStatementRange[0]) + replacement + source.substring(nextStatementRange[1]); | ||
const replacement = source.substring(0, statement.range[0]) + swapped + source.substring(nextStatement.range[1]); | ||
// Add the mutation | ||
mutations.push(new Mutation(file, currentStatementRange[0], nextStatementRange[1], startLine, endLine, original, newSource, this.ID)); | ||
mutations.push(new Mutation(file, statement.range[0], nextStatement.range[1], startLine, endLine, original, replacement, this.ID)); | ||
} | ||
@@ -58,0 +57,0 @@ } |
349620
6791