I have a struct and getter function that should return the id to zero when I delete it from my function but I dont know on how to return from my testing script
Here is my struct, mapping & functions that i wanted to test From SC
struct Campaign {
address owner;
string title;
string description;
uint256 target;
uint256 deadline;
uint256 amountCollected;
string image;
address[] donators;
uint256[] donations;
bool claimed;
}
// a getter mapping
mapping(uint256 => Campaign) public campaigns;
// delete the campaign id using this function
function cancelCampaign(uint256 _id, address _owner) external {
Campaign memory campaign = campaigns[_id];
if (_owner != msg.sender) revert CrowdFund__NotOwner();
if (campaign.deadline > block.timestamp) revert CrowdFund__Started();
delete campaigns[_id];
emit CancelCampaign(_id);
}
// another getter function based on the total campaign created from a specific user
function getCampaigns() public view returns (Campaign[] memory) {
Campaign[] memory allCampaigns = new Campaign[](numberOfCampaigns);
for (uint i = 0; i < numberOfCampaigns; i++) {
Campaign storage item = campaigns[i];
allCampaigns[i] = item;
}
return allCampaigns;
}
So on my test script, i wanted to test the cancelCampaign function and delete the id. I tested it on Remix but it returns to a struct object so I'm not sure on how to put it on my test.
Test script
describe("Cancel Campaign", () => {
describe("Success", () => {
let deadline: any, remove: any, result: any;
const hundredDays = 100 * 24 * 60 * 60;
const increasetime = async () => {
await network.provider.send("evm_increaseTime", [hundredDays]);
await network.provider.send("evm_mine");
};
beforeEach(async () => {
await increasetime();
deadline = await time.latest();
await cf
.connect(user1)
.createCampaign(
user1.address,
"Test Title",
"Test Description",
token(1),
deadline,
"Image1.jpeg"
);
await cf.connect(user1).cancelCampaign(1, user1.address);
});
it("should delete the campaign id", async () => {
expect(await cf.connect(user1).getCampaigns()).to.equal(0);
});
});
});
This is what I get when I tested it in Remix:
{
"0": "address: owner 0x0000000000000000000000000000000000000000",
"1": "string: title ",
"2": "string: description ",
"3": "uint256: target 0",
"4": "uint256: deadline 0",
"5": "uint256: amountCollected 0",
"6": "string: image "
}
Thanks