From 6ecb74d94ed9e25380467e50cf77e88ea2656982 Mon Sep 17 00:00:00 2001 From: Patricio Palladino Date: Wed, 1 Mar 2023 17:51:36 -0300 Subject: [PATCH 1/4] Fix hardcoded URL in the etherscan plugin --- .../src/etherscan/EtherscanService.ts | 13 +++++++++++-- packages/hardhat-etherscan/src/index.ts | 8 +++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/hardhat-etherscan/src/etherscan/EtherscanService.ts b/packages/hardhat-etherscan/src/etherscan/EtherscanService.ts index e215dae127..698cc2050c 100644 --- a/packages/hardhat-etherscan/src/etherscan/EtherscanService.ts +++ b/packages/hardhat-etherscan/src/etherscan/EtherscanService.ts @@ -156,12 +156,21 @@ export class EtherscanResponse { } export async function isAlreadyVerified( + apiURL: string, apiKey: string, address: string ): Promise { - const url = `https://api.etherscan.io/api?module=contract&action=getsourcecode&address=${address}&apikey=${apiKey}`; + const parameters = new URLSearchParams({ + module: "contract", + action: "getsourcecode", + address, + apikey: apiKey, + }); - const response = await sendGetRequest(new URL(url)); + const url = new URL(apiURL); + url.search = parameters.toString(); + + const response = await sendGetRequest(url); const json = await response.body.json(); if (json.message !== "OK") { diff --git a/packages/hardhat-etherscan/src/index.ts b/packages/hardhat-etherscan/src/index.ts index 993bd902da..e61e7f1f32 100644 --- a/packages/hardhat-etherscan/src/index.ts +++ b/packages/hardhat-etherscan/src/index.ts @@ -225,7 +225,13 @@ If your constructor has no arguments pass an empty array. E.g: verificationNetwork ); - if (await isAlreadyVerified(etherscanAPIKey, address)) { + const alreadyVerified = await isAlreadyVerified( + etherscanAPIEndpoints.apiURL, + etherscanAPIKey, + address + ); + + if (alreadyVerified) { console.log(`The contract ${address} has already been verified`); return; } From 4b4e21adda77b4e883ad3e5a42a01d1c6dc4e068 Mon Sep 17 00:00:00 2001 From: Patricio Palladino Date: Wed, 1 Mar 2023 18:35:28 -0300 Subject: [PATCH 2/4] Remove validation for Hardhat Network as this is handled in a generic way now --- packages/hardhat-etherscan/src/network/prober.ts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/packages/hardhat-etherscan/src/network/prober.ts b/packages/hardhat-etherscan/src/network/prober.ts index 65d81c95df..17742ff061 100644 --- a/packages/hardhat-etherscan/src/network/prober.ts +++ b/packages/hardhat-etherscan/src/network/prober.ts @@ -1,7 +1,4 @@ -import { - HARDHAT_NETWORK_NAME, - NomicLabsHardhatPluginError, -} from "hardhat/plugins"; +import { NomicLabsHardhatPluginError } from "hardhat/plugins"; import { EthereumProvider } from "hardhat/types"; import { pluginName } from "../constants"; @@ -14,13 +11,6 @@ export async function getEtherscanEndpoints( chainConfig: ChainConfig, customChains: CustomChain[] ): Promise { - if (networkName === HARDHAT_NETWORK_NAME) { - throw new NomicLabsHardhatPluginError( - pluginName, - `The selected network is ${networkName}. Please select a network supported by Etherscan.` - ); - } - const chainIdsToNames = new Map( entries(chainConfig).map(([chainName, config]) => [ config.chainId, From f8eb7cffc2a632410080928fb36f4302f30c9b41 Mon Sep 17 00:00:00 2001 From: Patricio Palladino Date: Wed, 1 Mar 2023 18:35:57 -0300 Subject: [PATCH 3/4] Fix broken tests --- packages/hardhat-etherscan/test/integration/PluginTests.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/hardhat-etherscan/test/integration/PluginTests.ts b/packages/hardhat-etherscan/test/integration/PluginTests.ts index ed8e6df0bb..07aee7e6f0 100644 --- a/packages/hardhat-etherscan/test/integration/PluginTests.ts +++ b/packages/hardhat-etherscan/test/integration/PluginTests.ts @@ -14,6 +14,7 @@ import { TASK_VERIFY_GET_MINIMUM_BUILD, } from "../../src/constants"; import { deployContract, getRandomString, useEnvironment } from "../helpers"; +import { EtherscanNetworkEntry } from "../../src/types"; // These are skipped because they can't currently be run in CI describe("Plugin integration tests", function () { @@ -336,12 +337,6 @@ describe("Plugin integration tests", function () { // This avoids failure due to compiler downloads. await this.env.run(TASK_COMPILE, { quiet: true }); - const { task }: { task: typeof taskT } = require("hardhat/config"); - - // We override this task to avoid posting to an actual endpoint and to avoid our own sanity checks. - task(TASK_VERIFY_GET_ETHERSCAN_ENDPOINT).setAction(async () => { - return "http://127.0.0.1:54321"; - }); const { ethers } = this.env as any; const signers = await ethers.getSigners(); signer = signers[0]; From 71c2ff127c68d558772f7fd3d63d5a7ff86c9c3f Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Thu, 2 Mar 2023 10:08:14 +0100 Subject: [PATCH 4/4] Fix linter --- packages/hardhat-etherscan/test/integration/PluginTests.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/hardhat-etherscan/test/integration/PluginTests.ts b/packages/hardhat-etherscan/test/integration/PluginTests.ts index 07aee7e6f0..d4c5d642cf 100644 --- a/packages/hardhat-etherscan/test/integration/PluginTests.ts +++ b/packages/hardhat-etherscan/test/integration/PluginTests.ts @@ -9,12 +9,8 @@ import { import { NomicLabsHardhatPluginError } from "hardhat/plugins"; import path from "path"; -import { - TASK_VERIFY_GET_ETHERSCAN_ENDPOINT, - TASK_VERIFY_GET_MINIMUM_BUILD, -} from "../../src/constants"; +import { TASK_VERIFY_GET_MINIMUM_BUILD } from "../../src/constants"; import { deployContract, getRandomString, useEnvironment } from "../helpers"; -import { EtherscanNetworkEntry } from "../../src/types"; // These are skipped because they can't currently be run in CI describe("Plugin integration tests", function () {