Skip to content

Commit

Permalink
chore: add unit tests for verify plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kiriyaga committed Dec 27, 2023
1 parent c07e3b5 commit 74d6396
Show file tree
Hide file tree
Showing 13 changed files with 1,677 additions and 31 deletions.
2 changes: 1 addition & 1 deletion 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 Down
3 changes: 0 additions & 3 deletions packages/hardhat-zksync-verify/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { TASK_FLATTEN_GET_FLATTENED_SOURCE } from 'hardhat/builtin-tasks/task-na
import { Artifacts, HardhatRuntimeEnvironment, ResolvedFile } from 'hardhat/types';
import { isFullyQualifiedName, parseFullyQualifiedName } from 'hardhat/utils/contract-names';
import {
MULTIPLE_MATCHING_CONTRACTS,
CONTRACT_NAME_NOT_FOUND,
NO_MATCHING_CONTRACT,
LIBRARIES_EXPORT_ERROR,
Expand Down Expand Up @@ -48,8 +47,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 @@ -21,7 +21,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';
import { parseFullyQualifiedName } from 'hardhat/utils/contract-names';
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 @@ -246,7 +246,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 {
}
24 changes: 0 additions & 24 deletions packages/hardhat-zksync-verify/test/tests.ts

This file was deleted.

Loading

0 comments on commit 74d6396

Please sign in to comment.