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

Impossible to catch a reverted error with .to.be.reverted #5486

Closed
YannSuissa opened this issue Jul 5, 2024 · 2 comments
Closed

Impossible to catch a reverted error with .to.be.reverted #5486

YannSuissa opened this issue Jul 5, 2024 · 2 comments
Assignees

Comments

@YannSuissa
Copy link

Hi,

I can't catch a reverter error for the Onlyowner modifier from Openzepplin :

ProviderError: Error: VM Exception while processing transaction: reverted with custom error 'OwnableUnauthorizedAccount("0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC")'

I tried without success:

expect(await nft_contract.connect(addrs[2]).set_sale_step(1)).to.be.revertedWithCustomError(nft_contract, "OwnableUnauthorizedAccount").withArgs("0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC");
expect(await nft_contract.connect(addrs[2]).set_sale_step(1)).to.be.revertedWithCustomError(nft_contract, "OwnableUnauthorizedAccount")
expect(await nft_contract.connect(addrs[2]).set_sale_step(1)).to.be.revertedWithCustomError(nft_contract, "/OwnableUnauthorizedAccount.*/")
expect(await nft_contract.connect(addrs[2]).set_sale_step(1)).to.be.revertedWithCustomError(nft_contract, "/OwnableUnauthorizedAccount(.*)/")
expect(await nft_contract.connect(addrs[2]).set_sale_step(1)).to.be.reverted
expect(await nft_contract.connect(addrs[2]).set_sale_step(1)).to.be.revertedWith("OwnableUnauthorizedAccount")
expect(await nft_contract.connect(addrs[2]).set_sale_step(1)).to.be.revertedWith("/OwnableUnauthorizedAccount.*/")
expect(await nft_contract.connect(addrs[2]).set_sale_step(1)).to.be.revertedWith("/OwnableUnauthorizedAccount(.*)/")

In openzepplin it's this kind of error :

error OwnableUnauthorizedAccount(address account);
...
if (owner() != _msgSender()) {
  revert OwnableUnauthorizedAccount(_msgSender());
}

here are my versions :

"@nomicfoundation/hardhat-chai-matchers": "^2.0.7",
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"@nomicfoundation/hardhat-ignition": "^0.15.5",
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.5",
"@nomicfoundation/hardhat-network-helpers": "^1.0.11",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.8",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"chai": "4",
"ethers": "^6.13.1",
"hardhat": "^2.22.6",
"hardhat-gas-reporter": "^2.2.0",
"solidity-coverage": "^0.8.12",
"typechain": "^8.3.2" 
@Varadiell
Copy link

Hi there, you should try like this:

await expect(nft_contract.connect(addrs[2]).set_sale_step(1)).to.be.revertedWithCustomError(nft_contract, "OwnableUnauthorizedAccount").withArgs("0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC");

Your await is most likely not at the right place.

@YannSuissa
Copy link
Author

Thanks all my test were wrong because of the await ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

3 participants