Skip to content

Commit

Permalink
chore: update unit tests for verify plugin (#635)
Browse files Browse the repository at this point in the history
* chore: add unit tests for verify plugin

* chore: skip console log test

* chore: extend lint config and update tests

---------

Co-authored-by: Marko Arambasic <makiarambasic@gmail.com>
  • Loading branch information
kiriyaga-txfusion and kiriyaga authored Dec 30, 2023
1 parent b7c4f5e commit dbc4302
Show file tree
Hide file tree
Showing 14 changed files with 1,611 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/hardhat-zksync-verify/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
"format": ["camelCase", "PascalCase", "snake_case"],
"leadingUnderscore": "allow",
"filter": {
"regex": "^[a-zA-Z0-9-_]+$",
"regex": "^[a-zA-Z0-9-_/*\\.]+$",
"match": false
}
},
Expand Down
6 changes: 4 additions & 2 deletions packages/hardhat-zksync-verify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"fmt": "yarn prettier --write",
"eslint": "eslint 'src/**/*.ts' 'test/**/*.ts'",
"prettier": "prettier 'src/**/*.ts' 'test/**/*.ts'",
"test": "NODE_ENV=test c8 mocha test/tests.ts --no-timeout --exit",
"test": "c8 mocha --recursive \"test/tests/**/*.ts\" --exit",
"build": "tsc --build .",
"clean": "rimraf dist"
},
Expand All @@ -44,7 +44,9 @@
"zksync-ethers": "^6.0.0",
"cbor": "^8.1.0",
"debug":"^4.1.1",
"@openzeppelin/contracts": "^4.9.2"
"@openzeppelin/contracts": "^4.9.2",
"sinon-chai": "^3.7.0",
"sinon": "^16.0.0"
},
"devDependencies": {
"@nomicfoundation/hardhat-verify": "^2.0.0",
Expand Down
9 changes: 1 addition & 8 deletions packages/hardhat-zksync-verify/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import { Artifacts, HardhatRuntimeEnvironment, ResolvedFile } from 'hardhat/type
import { isFullyQualifiedName, parseFullyQualifiedName } from 'hardhat/utils/contract-names';
import path from 'path';
import chalk from 'chalk';
import {
MULTIPLE_MATCHING_CONTRACTS,
CONTRACT_NAME_NOT_FOUND,
NO_MATCHING_CONTRACT,
LIBRARIES_EXPORT_ERROR,
} from './constants';
import { CONTRACT_NAME_NOT_FOUND, NO_MATCHING_CONTRACT, LIBRARIES_EXPORT_ERROR } from './constants';
import { Bytecode, extractMatchingContractInformation } from './solc/bytecode';
import { ZkSyncVerifyPluginError } from './errors';
import { executeVeificationWithRetry } from './utils';
Expand Down Expand Up @@ -48,8 +43,6 @@ export async function inferContractArtifacts(

if (contractMatches.length === 0) throw new ZkSyncVerifyPluginError(NO_MATCHING_CONTRACT);

if (contractMatches.length > 1) throw new ZkSyncVerifyPluginError(MULTIPLE_MATCHING_CONTRACTS);

return contractMatches[0];
}

Expand Down
6 changes: 3 additions & 3 deletions packages/hardhat-zksync-verify/src/task-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
BUILD_INFO_NOT_FOUND_ERROR,
} from './constants';

import { encodeArguments, retrieveContractBytecode } from './utils';
import { encodeArguments, extractModule, retrieveContractBytecode } from './utils';
import { Libraries } from './types';
import { ZkSyncVerifyPluginError } from './errors';

Expand Down Expand Up @@ -109,7 +109,7 @@ export async function getConstructorArguments(
const constructorArgsModulePath = path.resolve(process.cwd(), args.constructorArgsModule);

try {
const constructorArguments = (await import(constructorArgsModulePath)).default;
const constructorArguments = await extractModule(constructorArgsModulePath);

// Since our plugin supports both encoded and decoded constructor arguments, we need to check how are they passed
if (!Array.isArray(constructorArguments) && !constructorArguments.startsWith('0x')) {
Expand Down Expand Up @@ -248,7 +248,7 @@ export async function getContractInfo(
deployedBytecode,
);

if (contractInformation === null) {
if (contractInformation === undefined || contractInformation === null) {
throw new ZkSyncVerifyPluginError(NO_MATCHING_CONTRACT);
}
} else {
Expand Down
5 changes: 5 additions & 0 deletions packages/hardhat-zksync-verify/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,8 @@ export function parseWrongConstructorArgumentsError(string: string): string {

return `The number of constructor arguments you provided (${data.values}) does not match the number of constructor arguments the contract has been deployed with (${data.types}).`;
}

export async function extractModule(constructorArgsModulePath: string) {
const constructorArguments = (await import(constructorArgsModulePath)).default;
return constructorArguments;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
"name": "localGreeter",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.16;

contract Contract {
}
Loading

0 comments on commit dbc4302

Please sign in to comment.