I have a smart contract here that have mints NFTs and claim reward functions, and I have used custom errors
instead of require
error stakeNotOver();
function claimReward(uint256 stakeId) external nonReentrant returns (bool){
if(addressStaked[_msgSender()] == false)
revert notParticipant();
if(stakerTokensInfo[_msgSender()][stakeId].endTS > block.timestamp)
revert stakeNotOver();
if(stakerTokensInfo[_msgSender()][stakeId].claimed > 0)
revert alreadyClaimed();
for(uint256 i =0; i< stakingId[msg.sender].length; i++){
if(stakeId != stakingId[msg.sender][i])
revert NoSuchStakingExists();
}
but now as I am writing test cases using chai
, I don't know how to deal with them. I tried something I found on the internet but it didn't work either
it("Should not unstake if the time is not completed", async function () {
await testToken.connect(owner).transfer(hyperStaking.address, 1000)
await hyperStaking.connect(owner).stakeToken(500, 1)
await expect(hyperStaking.connect(owner).claimReward(1)).to.be.revertedWithCustomError(hyperStaking, "stakeNotOver");
});
Please let me know if I am doing anything wrong or is there no support for custom errors as of yet