Encountering an issue with the following error message:
Error: VM Exception while processing transaction: reverted with reason string 'deposit more'
in the Hardhat Test.js file
Test.js ->
it("should be able to withdraw if no one applies", async function() {
const salary = "10" + "000000000000000000";
const jobDesc = "https://example.com";
const startBalance = await addrs[0].getBalance();
const duration = 30 * 86400;
//await addrs[0].sendTransaction({ to: tasksV1.address, value: salary });
//taskid should be 3
await tasksV1.connect(addrs[0])
.createTask(duration, jobDesc, { value: salary });
const taskId = 3;
await tasksV1.connect(addrs[0]).cancelTask(taskId);
await tasksV1.connect(addrs[0]).withdrawDeposit(taskId);
const newBalance = await addrs[0].getBalance();
expect(startBalance.sub(newBalance).div("1000000000000000000")).equal(0);
});
Solidity Function ->
function withdrawDeposit(uint256 taskId) external {
require(tasks[taskId].creator == msg.sender, "Not creator");
require(tasks[taskId].deposit > 0, "deposit more");
require(
tasks[taskId].status == TaskStatus.failed
||
(tasks[taskId].status == TaskStatus.cancelled && applicants[taskId].length == 0)
||
(tasks[taskId].status == TaskStatus.cancelled && block.timestamp > tasks[taskId].createdTime + unlockTime)
, "Cannot withdraw");
uint256 valueToWithdraw = tasks[taskId].deposit;
tasks[taskId].deposit = 0;
payable(msg.sender).transfer(valueToWithdraw);
emit TaskUpdate(taskId, msg.sender, TaskActions.withdraw);
}
After investigation, it appears that the error stems from the Solidity function
require(tasks[taskId].deposit > 0, "deposit more");
Attempts were made with
const salary = ethers.utils.parseEther("10"); // 10 Ether in Wei
yet the same error persists
For a comprehensive overview, refer to the full code available at -> https://github.com/akashpanda122/gig_board
Struggling with this issue for quite some time now!