Getting an error as Error: VM Exception while processing transaction: reverted with reason string 'deposit more'
on Hardhat Test.js file
Test.js ->
it("should abe to withdraw if no one apply", 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);
}
I figured out that this error comes from Solidity function require(tasks[taskId].deposit > 0, "deposit more");
So, I even tried const salary = ethers.utils.parseEther("10"); // 10 Ether in Wei
with this
But still getting the same error
Here’s full code for better understanding -> https://github.com/akashpanda122/gig_board
Been stuck in this for a very long time!