From 352beb47ec17246163d4ad08e873589678af02ce Mon Sep 17 00:00:00 2001 From: nikola-bozin-txfusion <147805948+nikola-bozin-txfusion@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:05:49 +0200 Subject: [PATCH] chore: increase test coverage (#1012) --- .../test/tests/plugin.test.ts | 6 +++++ .../test/tests/solc/bytecode.test.ts | 17 ++++++++++++ .../test/tests/task-actions.test.ts | 26 +++++++++++++++++-- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/packages/hardhat-zksync-verify/test/tests/plugin.test.ts b/packages/hardhat-zksync-verify/test/tests/plugin.test.ts index d1dbd084f..1f715becb 100644 --- a/packages/hardhat-zksync-verify/test/tests/plugin.test.ts +++ b/packages/hardhat-zksync-verify/test/tests/plugin.test.ts @@ -394,6 +394,12 @@ Instead, this name was received: ${contractFQN}`); name: 'localGreeter', }); }); + + it('should return the empty object', async function () { + const libraries = await getLibraries({} as any); + + expect(libraries).to.deep.equal({}); + }); }); describe('checkVerificationStatus', async function () { diff --git a/packages/hardhat-zksync-verify/test/tests/solc/bytecode.test.ts b/packages/hardhat-zksync-verify/test/tests/solc/bytecode.test.ts index 5391f5bd6..1b8fe3bce 100644 --- a/packages/hardhat-zksync-verify/test/tests/solc/bytecode.test.ts +++ b/packages/hardhat-zksync-verify/test/tests/solc/bytecode.test.ts @@ -41,6 +41,23 @@ describe('compareBytecode', () => { expect(result).to.equal(null); }); + it('should correctly normalize bytecode with address placeholder', async () => { + const bytecodeWithPlaceholder = + '73000000000000000000000000000000000000000000000000000000000000000000' + 'someBytecode'; + const symbolsWithPush20Opcode = { + object: '73' + 'someRuntimeBytecode', + }; + + const normalizedResult = await bytecodes.normalizeBytecode( + bytecodeWithPlaceholder, + symbolsWithPush20Opcode as any, + ); + + const expectedNormalizedBytecode = 'someBytecode'; // Adjust this based on your zeroOutSlices implementation + + expect(normalizedResult.normalizedBytecode).to.include(expectedNormalizedBytecode); + }); + it('should return the normalized bytecode when it matches the reference bytecode', async () => { const deployedBytecode: Bytecode = new Bytecode('deployedBytecode'); const runtimeBytecodeSymbols = { diff --git a/packages/hardhat-zksync-verify/test/tests/task-actions.test.ts b/packages/hardhat-zksync-verify/test/tests/task-actions.test.ts index 41faaf852..dab9eab16 100644 --- a/packages/hardhat-zksync-verify/test/tests/task-actions.test.ts +++ b/packages/hardhat-zksync-verify/test/tests/task-actions.test.ts @@ -534,7 +534,6 @@ describe('verify', async function () { }, run: sinon.stub().resolves({}), }; - await verify( { address: '0x1234567890', @@ -557,7 +556,7 @@ describe('verify', async function () { const hre = { network: { zksync: true, - verifyURL: 'http://localhost:3000/verify', + verifyURL: undefined, }, run: sinon.stub().resolves({}), }; @@ -622,6 +621,29 @@ describe('getConstructorArguments', async function () { sinon.restore(); }); + it('should throw an error if constructorArguments are neither an array nor start with 0x', async function () { + const args = { + constructorArgsModule: 'path/to/module', + }; + const hre = { + network: { + zksync: true, + }, + }; + const runSuperStub = sinon.stub().resolves(); + const extractModuleStub = sinon.stub(utils, 'extractModule').resolves('invalidConstructorArguments'); + + try { + await getConstructorArguments(args, hre as any, runSuperStub as any); + fail('Expected a ZkSyncVerifyPluginError to be thrown'); + } catch (error: any) { + console.info(error.message); + expect(error.message).to.include('Importing the module for the constructor arguments list failed'); + } finally { + extractModuleStub.restore(); + } + }); + it('should call runSuper if zksync is false', async function () { const args = {}; const hre = {