0

Actually i am validating an function to check that only whitelisted members or owner can access this function but when i am running this test file i am getting reverting error that Error

Validations
         should revert error for non whitelisted memeber:
     Error: VM Exception while processing transaction: reverted with reason string 'Only owner or whiteListed members allowed'
    at KeyboardNFT.isWhiteListedorOwner (contracts/nft_erc721.sol:1102)

Code

describe("Validations", function () {
    it("should revert error for non whitelisted memeber", async function () {
      const {hardhatToken, owner, addr1, addr2} = await loadFixture(deployTokenFixture);
      expect(await hardhatToken.connect(addr1).awardItem(addr1.address,"first nft")).to.throw("Only owner or whiteListed members allowed");
    });
  });
2
  • Pro tip: see my hardhat-template. You will probably not bump into this error. Commented Aug 21, 2022 at 16:14
  • thx @PaulRazvanBerg for suggestion i solved it
    – DereK
    Commented Aug 22, 2022 at 12:45

1 Answer 1

0

change

.to.throw ...

to

.to.be.revertedWith(<revertMessage>)

Example : await expect(Contract.add()).to.be.revertedWith("Only owner or whiteListed members allowed");

2
  • Thanks for the answer @sola24 but i want to edit it a bit, well you answer is correct but instead of adding await inside except i put it outside then it worked. but it does not work when it put that await inside expect.
    – DereK
    Commented Aug 22, 2022 at 12:47
  • ah yes. that too. I didn't see that
    – sola24
    Commented Aug 22, 2022 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.