Skip to content

Commit

Permalink
working on a solution
Browse files Browse the repository at this point in the history
TODO: retrieve UDVT underlying type
  • Loading branch information
Amxx committed Mar 28, 2024
1 parent 0d93daa commit 35fe73a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/core.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,23 @@ Generated by [AVA](https://avajs.dev).
receive() external payable {}␊
}␊
contract $UdvtConflict {␊
bytes32 public constant __hh_exposed_bytecode_marker = "hardhat-exposed";␊
constructor() payable {␊
}␊
function $unwrap_UdvtConflict_myFirstType(UdvtConflict.myFirstType t) external pure returns (bytes32 ret0) {␊
(ret0) = UdvtConflict.unwrap(t);␊
}␊
function $unwrap_UdvtConflict_mySecondType(UdvtConflict.mySecondType t) external pure returns (bytes32 ret0) {␊
(ret0) = UdvtConflict.unwrap(t);␊
}␊
receive() external payable {}␊
}␊
`

## snapshot initializers
Expand Down
Binary file modified src/core.test.ts.snap
Binary file not shown.
9 changes: 7 additions & 2 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function getExposedContent(ast: SourceUnit, relativizePath: (p: string) => strin
]),
// external functions
...externalizableFunctions.map(fn => {
const fnName = clashingFunctions[getFunctionId(fn, c, deref)] === 1 ? fn.name : getFunctionNameQualified(fn, c, deref);
const fnName = clashingFunctions[getFunctionId(fn, c, deref)] === 1 ? fn.name : getFunctionNameQualified(fn, c, deref, false);
const fnArgs = getFunctionArguments(fn, c, deref);
const fnRets = getFunctionReturnParameters(fn, c, deref);
const evName = isNonViewWithReturns(fn) && (clashingEvents[fn.name] === 1 ? fn.name : getFunctionNameQualified(fn, c, deref, false));
Expand Down Expand Up @@ -284,7 +284,7 @@ function areFunctionsFullyImplemented(contract: ContractDefinition, deref: ASTDe
function getFunctionId(fn: FunctionDefinition, context: ContractDefinition, deref: ASTDereferencer): string {
const storageArgs = new Set<Argument>(getStorageArguments(fn, context, deref));
const nonStorageArgs = getFunctionArguments(fn, context, deref).filter(a => !storageArgs.has(a));
return fn.name + nonStorageArgs.map(a => a.type).join('');
return fn.name + nonStorageArgs.map(a => a.udvtType ?? a.type).join('');
}

function getFunctionNameQualified(fn: FunctionDefinition, context: ContractDefinition, deref: ASTDereferencer, onlyStorage: boolean = true): string {
Expand Down Expand Up @@ -439,6 +439,7 @@ interface Argument {
name: string;
storageVar?: string;
storageType?: string;
udvtType?: string;
}

const printArgument = (arg: Argument) => `${arg.type} ${arg.name}`;
Expand All @@ -451,6 +452,10 @@ function getFunctionArguments(fnDef: FunctionDefinition, context: ContractDefini
const storageVar = 'v_' + storageType.replace(/[^0-9a-zA-Z$_]+/g, '_');
// The argument is an index to an array in storage.
return { name, type: 'uint256', storageVar, storageType };
} else if (p.typeName?.nodeType == 'UserDefinedTypeName') {
const type = getVarType(p, context, deref, 'calldata');
const udvtType = 'bytes32'; // TODO: Do an actual resolution
return { name, type, udvtType };
} else {
const type = getVarType(p, context, deref, 'calldata');
return { name, type };
Expand Down

0 comments on commit 35fe73a

Please sign in to comment.