Skip to content

Commit

Permalink
fix: check variables and duplicated selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
agusduha committed Apr 8, 2024
1 parent f6fb037 commit 6ddead6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions solidity/interfaces/IContractBAbstract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pragma solidity ^0.8.0;

interface IContractBAbstract {
function undefinedInterfaceFunc(uint256 _someNumber) external returns (bool _result);
function uintVariable() external view returns (uint256 _uintVariable);
}
22 changes: 17 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,31 @@ export async function renderAbstractUnimplementedFunctions(contract: ContractDef
let content = '';

if (contract.vLinearizedBaseContracts.length > 1) {
const functions = contract.vFunctions;
const variablesSelectors = contract.vStateVariables.map((variable) => variable.raw?.functionSelector);
const functionsSelectors = contract.vFunctions.map((func) => func.raw?.functionSelector);
const newFunctions = [];

for (const base of contract.vLinearizedBaseContracts) {
// Skip the first contract, which is the current contract
if (base.id === contract.id) continue;

for (const baseFunction of base.vFunctions) {
// If the function is not implemented in the current contract, render it
if (!functions.some((func) => func.raw?.functionSelector === baseFunction.raw?.functionSelector)) {
content += await renderNodeMock(baseFunction);
}
// Skip the functions that are already implemented in the current contract as variables
if (variablesSelectors.includes(baseFunction.raw?.functionSelector)) continue;

// Skip the functions that are already implemented in the current contract as functions
if (functionsSelectors.includes(baseFunction.raw?.functionSelector)) continue;

// If the function is already in the new functions array, skip it
if (newFunctions.some((func) => func.raw?.functionSelector === baseFunction.raw?.functionSelector)) continue;

newFunctions.push(baseFunction);
}
}

for (const func of newFunctions) {
content += await renderNodeMock(func);
}
}

return content;
Expand Down

0 comments on commit 6ddead6

Please sign in to comment.