Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce contract verification #5164

Merged

Conversation

rimrakhimov
Copy link
Contributor

  • Because this PR includes a bug fix, relevant tests have been included.
  • Because this PR includes a new feature, the change was previously discussed on an Issue or with someone from the team.
  • I didn't do anything of this.

That PR adds the --force verification flag described in #5122, which allows the re-verification of already verified contracts (for blockscout-based explorers).

Notice that sometimes, an underlying explorer may return an error saying that the contract has already been verified. For blockscout-based explorers that happens if the contract is already verified with a full match, while for etherscan that is the only possible option for verified contracts. The PR considers those cases as errors and fails with a corresponding error message. I don't know if that is what is expected, though.

Also I plan to add some test cases, but would be glad to get some suggestions to start with

Copy link

changeset-bot bot commented Apr 24, 2024

🦋 Changeset detected

Latest commit: 425dbf4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@nomicfoundation/hardhat-verify Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Apr 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2024 10:26pm

@schaable
Copy link
Member

schaable commented May 6, 2024

Hi @rimrakhimov, the code looks good. I've updated the error message to include the contract FQN, as other error messages also do this. I'll do some manual testing tomorrow. Regarding adding tests, you could add some integration tests by mocking the block explorer's response in packages/hardhat-verify/test/integration/index.ts. I suggest adding a test where etherscan.isVerified is mocked to return true and includes the --force flag, and another test that throws the ContractAlreadyVerifiedError exception.

…the verification request. Add test cases for '--force' flag verifications.
@rimrakhimov
Copy link
Contributor Author

rimrakhimov commented May 8, 2024

Hi, @schaable, thank you for the feedback. I added some test cases as you'd suggested. Also, found a bug in the implementation as etherscan returns different "already verified" messages depending on whether the contract has been actually verified by some user (e.g., 0x7b45A6d08F26ecAD9422fb85FbCAb1a0fec806CB), or has been automatically found verified contract with the same deployed bytecode (e.g., 0x9498322CB2193Bc906d2dF94D7C04A17A59790C8)

@schaable
Copy link
Member

schaable commented May 8, 2024

Manual testing:

  • Unverified contract:
    • Without --force: contract verified.
    • With --force: contract verified.
  • Verified contract (full match):
    • Without --force: return with message The contract ${address} has already been verified on the block explorer.
    • With --force: throw ContractAlreadyVerifiedError error.
  • Verified contract (partial match - only Blockscout):
    • Without --force: return with message The contract ${address} has already been verified on the block explorer.
    • With --force: contract verified.

@schaable schaable merged commit 4290827 into NomicFoundation:main May 8, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready This issue is ready to be worked on
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants