Oops! Hardhat Test Error "Error: Virtual Machine Exception occurred while processing transaction: reverted with reason 'Please deposit additional funds'."

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!

Answer №1

Thank you for sharing the GitHub link. The issue lies in the createTask() function, where three arguments are expected. However, in your test case, only two arguments - duration and jobDesc - are being passed. I adjusted the test to include the third argument, refId, and now it is functioning correctly. Please refer to the screenshot attached for more details.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adjust the canvas size to fit its parent element ion-grid

I am currently working on an Ionic 3 component that displays a grid of images connected by a canvas overlay. I have utilized Ionic's ion-grid, but I am facing an issue with resizing the canvas. The problem is that I cannot determine the correct dimens ...

Choosing groupings of courses

I am looking to dynamically load divs with different combinations of classes from an external file using jQuery's load function, but I am struggling with grouping them correctly. $("#somediv").load("somefile.html .class1"); // loads all divs with c ...

Utilizing jQuery and DOM to interact with form elements

Below is the form content <form method="post"> <input type="hidden" name="resulttype" value="Create"> <table> <tr> <td>Full Name</td> <td><input ...

Determining the successful completion of an ajax request using jQuery editable plugin

I recently started using Jeditable to enable inline editing on my website. $(".video_content_right .project_description").editable(BASE_URL+"/update/description", { indicator: "<img src='" + BASE_URL + "/resources/assets/front/images/indicator ...

It is likely that the variable is out of scope and is undefined

I have a piece of code that retrieves the description of a word in JSON format from website, which is provided by the user in the request JSON body. The issue I'm facing is that I am unable to send back the 'desc' variable in the res.send ...

"Encountering issue with componentDidMount() not functioning as expected, despite debugger being

Hello everyone! This is my first time sharing something here, so I'm eager to hear your feedback on both how I've posted and the content itself. I've only been programming for 8 weeks now, so I'm sure there are plenty of mistakes in wha ...

jQuery Load - Oops! There seems to be a syntax error: Unexpected token <

Error: Uncaught SyntaxError: Unexpected token < I encountered the error message mentioned above while trying to execute a jQuery load function: $('#footer').load(UrlOfFooterContent); The variable UrlOfFooterContent holds the URL of an MVC c ...

Looking to grasp the concept of calling inline functions within a React functional component

As a newcomer to React, I recently created a new view within my company. Following the example of many guides, I have utilized inline functions and function components exclusively. One common practice I have adopted is writing onClick events in this manne ...

Utilizing Ajax to dynamically load files within the Django framework

My current project involves working with Django, specifically a feature that requires loading a file and displaying its content in a textarea. Instead of storing the file on the server side or in a database, I am exploring the use of AJAX to send the file ...

Obtain information from a website, then initiate a lambda function to send an email and store the data in

As a beginner, I came across two different sets of instructions online. The first one was about using AWS Lambda to send data (Contact us - Email, Phone, etc) to my email via Amazon API Gateway and Amazon SES: https://aws.amazon.com/blogs/architecture/cre ...

Develop a custom autocomplete feature using Formik in React for selecting values from an array of objects

Looking to Add Autocomplete Functionality in Your React Application Using Formik for Seamless Selection of Single and Multiple Values from an Array of Objects? Take a Look at this Code snippet! [see image below] (https://i.stack.imgur.com/ekkAi.png) arra ...

What sets apart $document from $window.document in Angular?

After experimenting with the code on JSBin, I noticed that the first snippet successfully retrieved the canvas object, while the second one did not. JSBin: http://jsbin.com/natavejasa/1/edit?html,js,output var canvas = $window.document.getElementById(&ap ...

What is the best way to handle various sections with changing structures within a complex form using react-hook-form?

I am working on a complex form that has sections A, B, and C, each of which can be in shape A1 or A2, B1 or B2, C1, or C2. Users are required to fill out settings based on whether the section is set to "advanced" or "basic". I want users to submit the enti ...

Are you experiencing issues with the map displaying inaccurate latitude and longitude when clicking on a specific point?

I've successfully created a simple polyline on Google Maps and attached a click event listener to it. However, I'm encountering an issue where clicking on the line provides me with latitude and longitude coordinates that point to Canada, even th ...

Using Geolocation in HTML5 and JavaScript

Currently, I am working on my debut mobile web application and have successfully integrated Google Maps into it using Geolocation JavaScript API version 3. Now, I am looking to add a button that, when clicked by the user, centers the map on my location o ...

Drop down menus fail to appear after the screen has been resized

Creating responsive menus involves using ordered and unordered lists, along with CSS for styling. I have added a script to dynamically generate dropdown menus, but encountered an issue where nothing appears on the screen upon resizing - only the backgrou ...

Session is required for req.flash() function in node.js to work properly

I recently started working with Node.js and I'm encountering an issue with sessions. I developed a simple application and tried to run it locally, but ran into some errors. Below are the details of my code along with the error messages: BAPS.js (app. ...

Tips for placing a div within a curved div?

I've got a nested div situation, <div style="background-color: red; height: 100px; width: 100px; border-radius: 10px;" id="div1"> <div style="background-color: orange;" id="div2"> testing </div> </div ...

Adjust the class based on the model's value in AngularJS

items = {'apple', 'banana', 'lemon', 'cat', 'dog', 'monkey', 'tom', 'john', 'baby'} html <div class="variable" ng-repeat="item in items">{{item}} </div> ...

Is it possible to implement a custom sign-in form for AWS Cognito?

Is it possible to replace the AWS Cognito hosted UI with a custom form in my Next.js app that utilizes AWS Cognito for authentication? import { Domain } from "@material-ui/icons"; import NextAuth from "next-auth"; import Providers fro ...