diff --git a/src/shared/fs.ts b/src/shared/fs.ts index 9031160..898333d 100644 --- a/src/shared/fs.ts +++ b/src/shared/fs.ts @@ -178,6 +178,14 @@ export const getUserFacetsAndFunctions = (ctx: Context): FacetDefinition[] => { .filter( node => node.visibility === 'external' || (ctx.config.diamond.publicMethods && node.visibility === 'public') ) + .map(node => { + // rename public methods to external if publicMethods is true + if (node.visibility === 'public') { + trace(`Renamed public method to external: ${contract.name}.${node.name}`) + node.visibility = 'external' + } + return node + }) const functions = functionDefinitions.map(node => { const fnParamParsingContext: FunctionParsingContext = { diff --git a/test/common-build-steps.ts b/test/common-build-steps.ts index 7b0979a..00d47d2 100644 --- a/test/common-build-steps.ts +++ b/test/common-build-steps.ts @@ -264,6 +264,46 @@ function getData() external view returns (Data memory);`, }) }) + describe('if public methods are configured to be included', () => { + beforeEach(async () => { + removeFile(join(cwd, `${contractSrcBasePath}/facets/ExampleFacet.sol`)) + + writeFile(join(cwd, `${contractSrcBasePath}/facets/ExampleFacet.sol`), ` + pragma solidity >=0.8.21; + import "../libs/LibAppStorage.sol"; + contract ExampleFacet { + function getInt() external view returns (uint) { + return 1; + } + function getIntPublic() public view returns (uint) { + return 2; + } + } + `) + + await updateConfigFile(join(cwd, 'gemforge.config.cjs'), (cfg: GemforgeConfig) => { + cfg.diamond.publicMethods = true + return cfg + }) + }) + + it("generates proxy interface and renames public methods to external", async () => { + const ret = cli('build', { cwd }) + expect(ret.success).to.be.true + + const filePath = path.join(cwd, `${contractSrcBasePath}/generated/IDiamondProxy.sol`) + assertFileMatchesTemplate(filePath, 'IDiamondProxy.sol', { + __SOLC_SPDX__: 'MIT', + __SOLC_VERSION__: '0.8.21', + __LIB_DIAMOND_PATH__: 'lib/diamond-2-hardhat', + __CUSTOM_IMPORTS__: `import "../shared/Structs.sol";\n`, + __METHODS__: `function setData(Data calldata d) external; +function getInt() external view returns (uint); +function getIntPublic() external view returns (uint);`, + }) + }) + }) + if (framework === 'foundry') { it("generates test helper", async () => { expect(cli('build', { cwd }).success).to.be.true diff --git a/tsconfig.json b/tsconfig.json index 93c5eb5..51af350 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,7 @@ "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "allowJs": true, - "skipLibCheck": false, + "skipLibCheck": true, "declaration": true, "resolveJsonModule": true, "isolatedModules": true,