I am expecting a revert from an Imported Ownable.sol contract since the executing address is not the owner of the function but the test fails without matching the error message thrown from the Ownable.sol contract.
HardHad Config:
const path = require('path');
require('@nomiclabs/hardhat-ethers');
require("@nomiclabs/hardhat-truffle5");
require('@nomicfoundation/hardhat-toolbox')
require('dotenv').config({path: path.join(__dirname, '../.env')});
module.exports = {
networks: {
hardhat: {
forking: {
url : (process.env.INFURA_KOVAN_URL + process.env.INFURA_API_KEY),
}
}
},
solidity: "0.8.9",
};
Smart Contract:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract Custodian is Ownable {
function helloWorld() public pure returns(string memory){
return "Hello World";
}
function goodByeWorld() public view onlyOwner returns(string memory){
return "Goodbye World";
}
}
JS Test:
it('goodbye world from owner', async ()=> {
await expect(this.custodian.goodByeWorld({ from: other })).to.be.revertedWith("Ownable: caller is not the owner")
});
Error:
Contract: Custodian goodbye world from owner: Error: VM Exception while processing transaction: reverted with reason string 'Ownable: caller is not the owner'