I'm getting a console error in hardhat test case this is my solidity code
/**
* donateToCampaign - Allows a user to donate to a specific campaign.
*
* @param _id the ID of the campaign to donate to.
*/
function donateToCampaign(uint256 _id) public payable noReentrancy {
uint256 amount = msg.value;
Campaign storage campaign = campaigns[_id];
require(
campaign.status != CampaignStatus.Close,
"This campaign is not open to fund."
);
require(
campaign.deadline > block.timestamp &&
isCampaignOpen(campaign.status),
"The campaign is not open or has reached its goal."
);
require(
campaign.amountCollected + amount <= campaign.target,
"Donation exceeds campaign target."
);
campaign.amountCollected += amount;
campaign.donators.push(payable(msg.sender));
campaign.donations.push(amount);
if (campaign.amountCollected == campaign.target) {
campaign.status = CampaignStatus.Successful;
emit CampaginSuccessfullyFunded(campaign);
}
payable(address(this)).transfer(amount);
}
and the test case in hardhat using chai
it("should allow a user to donate to a campaign", async () => {
const target = ethers.utils.parseEther("1");
await contract.connect(aliceAccount).createCampaign(
"Test Campaign",
"Test Description",
target,
"testimage.jpg"
);
let cc = await contract.campaigns(0);
const tx = await contract
.connect(bobAccount)
.donateToCampaign(0, { value: ethers.utils.parseEther("0.5") });
const campaign = await contract.campaigns(0);
expect(campaign.amountCollected).to.equal(ethers.utils.parseEther("0.5"));
});