Skip to content

Commit

Permalink
fix: add missing setting properties to support isSystem and forceEvml… (
Browse files Browse the repository at this point in the history
#965)

* fix: add missing setting properties to support isSystem and forceEvmla flags

* chore: update test cases for zksolc setting

---------

Co-authored-by: Marko Arambasic <makiarambasic@gmail.com>
  • Loading branch information
kiriyaga-txfusion and kiriyaga authored Apr 3, 2024
1 parent 642f37f commit b32243a
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 32 deletions.
12 changes: 10 additions & 2 deletions packages/hardhat-zksync-verify/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,21 @@ Instead, this name was received: ${contractFQN}`,
}
}

export function getSolidityStandardJsonInput(resolvedFiles: ResolvedFile[], input: CompilerInput): any {
export function getSolidityStandardJsonInput(
hre: HardhatRuntimeEnvironment,
resolvedFiles: ResolvedFile[],
input: CompilerInput,
): any {
return {
language: input.language,
sources: Object.fromEntries(
resolvedFiles.map((file) => [file.sourceName, { content: file.content.rawContent }]),
),
settings: input.settings,
settings: {
...input.settings,
isSystem: hre.config.zksolc.settings.isSystem ?? false,
forceEvmla: hre.config.zksolc.settings.forceEvmla ?? false,
},
};
}

Expand Down
6 changes: 5 additions & 1 deletion packages/hardhat-zksync-verify/src/task-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@ export async function verifyContract(

const request = {
contractAddress: address,
sourceCode: getSolidityStandardJsonInput(dependencyGraph.getResolvedFiles(), contractInformation.compilerInput),
sourceCode: getSolidityStandardJsonInput(
hre,
dependencyGraph.getResolvedFiles(),
contractInformation.compilerInput,
),
codeFormat: JSON_INPUT_CODE_FORMAT,
contractName: contractInformation.contractName,
compilerSolcVersion: solcVersion,
Expand Down
129 changes: 100 additions & 29 deletions packages/hardhat-zksync-verify/test/tests/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,46 +238,117 @@ Instead, this name was received: ${contractFQN}`);

describe('getSolidityStandardJsonInput', async function () {
useEnvironment('localGreeter');
it('should return the Solidity standard JSON input', async function () {
const resolvedFiles: ResolvedFile[] = [
{
sourceName: 'contracts/Contract.sol',
absolutePath: 'contracts/Contract.sol',
lastModificationDate: new Date(),
contentHash: '0x1234567890',
getVersionedName: () => 'contracts/Contract.sol',
content: {
rawContent: 'contract Contract {}',
imports: [],
versionPragmas: ['0.8.0'],
},
},
];

const solidityStandardJsonInput = getSolidityStandardJsonInput(resolvedFiles, {
language: 'Solidity',
sources: {
'contracts/Contract.sol': {
content: 'contract Contract {}',
},
const resolvedFiles: ResolvedFile[] = [
{
sourceName: 'contracts/Contract.sol',
absolutePath: 'contracts/Contract.sol',
lastModificationDate: new Date(),
contentHash: '0x1234567890',
getVersionedName: () => 'contracts/Contract.sol',
content: {
rawContent: 'contract Contract {}',
imports: [],
versionPragmas: ['0.8.0'],
},
},
];

const input = {
language: 'Solidity',
sources: {
'contracts/Contract.sol': {
content: 'contract Contract {}',
},
settings: {
optimizer: {
enabled: true,
},
settings: {
optimizer: {
enabled: true,
},
outputSelection: {
'*': {
'*': ['evm'],
},
outputSelection: {
'*': {
'*': ['evm'],
},
},
},
};

it('should return the Solidity standard JSON input', async function () {
const hre = {
config: {
zksolc: {
settings: {},
},
},
});
};

const solidityStandardJsonInput = getSolidityStandardJsonInput(hre as any, resolvedFiles, input);

expect(solidityStandardJsonInput.language).to.equal('Solidity');
expect(solidityStandardJsonInput.sources['contracts/Contract.sol'].content).to.equal(
'contract Contract {}',
);
expect(solidityStandardJsonInput.settings.optimizer.enabled).to.equal(true);
expect(solidityStandardJsonInput.settings.isSystem).to.equal(false);
expect(solidityStandardJsonInput.settings.forceEvmla).to.equal(false);
});

it('should return proper zksolc setting params', async function () {
const hre = {
config: {
zksolc: {
settings: {},
},
},
};

const solidityStandardJsonInput = getSolidityStandardJsonInput(hre as any, resolvedFiles, input);

expect(solidityStandardJsonInput.settings.isSystem).to.equal(false);
expect(solidityStandardJsonInput.settings.forceEvmla).to.equal(false);

const hre1 = {
config: {
zksolc: {
settings: {
isSystem: true,
},
},
},
};

const solidityStandardJsonInput2 = getSolidityStandardJsonInput(hre1 as any, resolvedFiles, input);
expect(solidityStandardJsonInput2.settings.isSystem).to.equal(true);
expect(solidityStandardJsonInput2.settings.forceEvmla).to.equal(false);

const hre2 = {
config: {
zksolc: {
settings: {
forceEvmla: true,
},
},
},
};

const solidityStandardJsonInput3 = getSolidityStandardJsonInput(hre2 as any, resolvedFiles, input);
expect(solidityStandardJsonInput3.settings.isSystem).to.equal(false);
expect(solidityStandardJsonInput3.settings.forceEvmla).to.equal(true);

const hre3 = {
config: {
zksolc: {
settings: {
isSystem: true,
forceEvmla: true,
},
},
},
};

const solidityStandardJsonInput4 = getSolidityStandardJsonInput(hre3 as any, resolvedFiles, input);
expect(solidityStandardJsonInput4.settings.isSystem).to.equal(true);
expect(solidityStandardJsonInput4.settings.forceEvmla).to.equal(true);
});
});

Expand Down

0 comments on commit b32243a

Please sign in to comment.