Skip to content

Commit

Permalink
fix: introduce forceContrectsToCompile to ensure that contracts not p…
Browse files Browse the repository at this point in the history
…resent in the source path are compiled (#1290)

Co-authored-by: Marko Arambasic <makiarambasic@gmail.com>
  • Loading branch information
kiriyaga-txfusion and kiriyaga authored Aug 15, 2024
1 parent 846d869 commit fcbcd1f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/hardhat-zksync-solc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_NAMES, async (args: { sourcePaths: stri
return await runSuper(args);
}

if (hre.config.zksolc.settings.forceContractsToCompile) {
return hre.config.zksolc.settings.forceContractsToCompile;
}

const contractsToCompile: string[] | undefined = hre.config.zksolc.settings.contractsToCompile;

if (!contractsToCompile || contractsToCompile.length === 0) {
Expand Down
4 changes: 3 additions & 1 deletion packages/hardhat-zksync-solc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ export interface ZkSolcConfig {
forceEvmla?: boolean;
// Evmla intermediate representation
forceEVMLA?: boolean;
// Specific contracts to be compiled
// Specific contracts present in source to be compiled
contractsToCompile?: string[];
// Specific only contracts forced to be compiled even if they are not present in source
forceContractsToCompile?: string[];
// Dump all IR (Yul, EVMLA, LLVM IR, assembly) to files in the specified directory. Only for testing and debugging.
debugOutputDir?: string;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.4.22 <0.9.0;

contract Greeter {

string greeting;
string bad;
constructor(string memory _greeting) {
greeting = _greeting;
bad = "baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaad";
}

function greet() public view returns (string memory) {
return greeting;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.4.22 <0.9.0;

contract Greeter2 {

string greeting;
string bad;
constructor(string memory _greeting) {
greeting = _greeting;
bad = "baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaad";
}

function greet() public view returns (string memory) {
return greeting;
}

}
15 changes: 15 additions & 0 deletions packages/hardhat-zksync-solc/test/tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ describe('zksolc plugin', async function () {
assert.equal(1, sourceNames.length);
assert.equal('contracts/Greeter.sol', sourceNames[0]);
});

it('Should successfully return only Greeter contract for compiling which is not present in source paths', async function () {
this.env.config.zksolc.settings.forceContractsToCompile = ['overrideContracts/Greeter.sol'];

const rootPath = this.env.config.paths.root;
const sourcePaths: string[] = [`${rootPath}/contracts/Greeter.sol`, `${rootPath}/contracts/Greeter2.sol`];

const sourceNames: string[] = await this.env.run(TASK_COMPILE_SOLIDITY_GET_SOURCE_NAMES, {
rootPath,
sourcePaths,
});

assert.equal(1, sourceNames.length);
assert.equal('overrideContracts/Greeter.sol', sourceNames[0]);
});
});

describe('Compilation jobs', async function () {
Expand Down

0 comments on commit fcbcd1f

Please sign in to comment.