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

revertWithCustomError requires interface property on a contract #6018

Closed
bogdan opened this issue Dec 5, 2024 · 1 comment
Closed

revertWithCustomError requires interface property on a contract #6018

bogdan opened this issue Dec 5, 2024 · 1 comment
Assignees

Comments

@bogdan
Copy link

bogdan commented Dec 5, 2024

Version of Hardhat

2.22.17

What happened?

revertedWithCustomError requires interface property to exist on an object, which is not present for contract obtained from getContractAt

Minimal reproduction steps

      const contract = await hre.viem.getContractAt(
        "MinterRoleMock",
        minterRole.address,
        { client: { wallet: minter } }
      );

      await expect(contract.write.grantMinter([other1.account.address]))
        .to.be.revertedWithCustomError(contract, "OwnableUnauthorizedAccount")

Search terms

hardhat-chai-matchers chai revert test

@schaable
Copy link
Member

schaable commented Dec 5, 2024

Hi @bogdan, revertedWithCustomError is a Hardhat Chai matcher, which were designed to work specifically with hardhat-ethers. It won’t work as expected with hardhat-viem.

We’re planning to introduce viem-specific matchers in Hardhat 3. For now, the simplest alternative is to assert the rejection message directly:

await expect(contract.write.grantMinter([other1.account.address])).to.be.rejectedWith(
  "your rejection message"
);

Let me know if you have any other questions!

@schaable schaable closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2024
@github-project-automation github-project-automation bot moved this from Backlog to Done in Hardhat Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

2 participants