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.

https://i.sstatic.net/hOIU9.png

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

Develop a list of findings from the search

Is there a way to extract the name from the image shown below? return testData.then((data) => { console.log(data) var results = []; var toSearch = params.suggestTerm; data = data["data"]["0"]; console.log(" ...

What is the reason behind the requirement in Javascript (ES.next) that a function must be declared as async in order to utilize await functionality?

Shouldn't a compiler or parser be intelligent enough to recognize when a function utilizes await, and automatically convert it to an async function? Why is there a requirement for me to explicitly type the async keyword? It just clutters the code, an ...

How can you maintain the "link" text in a div while removing the final hyperlink?

I am currently designing a breadcrumb navigation for a website. The breadcrumbs are generated using a templating language before the page is displayed. However, after rendering the page, I need to make some adjustments. Instead of using multiple IF/ELSE s ...

Delete items from several arrays on a click event in React

I'm working with an array of objects that contain multiple arrays. My goal is to remove the item when a button is clicked, but I keep getting undefined as a result. JSON Data [ { "services": [ { "id": "1b9 ...

Problem with YouTube iFrame API in IE when using JavaScript

Apologies for the unclear heading, but I'm facing a peculiar issue. The YouTube iFrame API works perfectly on all browsers except Internet Explorer. In IE, none of the JavaScript code runs initially. However, when I open DevTools and refresh the page, ...

Webpack is struggling to locate core-js paths when running on Windows operating systems

When running webpack, I am encountering the following errors: ERROR in ./node_modules/core-js/index.js Module not found: Error: Can't resolve './es' in 'pathtoproject\node_modules\core-js' @ ./node_modules/core-js/index. ...

What is the best way to utilize jQuery in order to present additional options within a form?

Let's consider a scenario where you have an HTML form: <form> <select name="vehicles"> <option value="all">All Vehicles</option> <option value="car1">Car 1</option> <option value="car2">Car 2< ...

Issue with background image resizing when touched on mobile Chrome due to background-size property set to cover

My current challenge involves setting a background image for a mobile page using a new image specifically designed for mobile devices. The image is set with the property background-size: cover, and it works perfectly on all platforms except for mobile Chro ...

Problem with full-page navigation sliding in and fading in and out

Upon the user's click on <a href="#slide-nav" class="slide-nav-trigger">, a full-page navigation smoothly slides into view. This animation is triggered by CSS and uses jQuery for event delegation. The Dilemma Instead of abruptly turning on and ...

NuxtJS using Babel 7: the spread operator persists in compiled files

Struggling to get my NuxtJS app functioning properly on IE11. Despite multiple attempts to configure Babel for compatibility, spread operators are still present in the built pages files, suggesting that Nuxt code is not being transformed correctly. Below ...

When hovering over a div, reveal another div on top of a third div

Imagine two adjacent divs, A on the left and B on the right with some other elements in between. Is it possible to have a third div, C, appear over div A when hovering over div B? I can control the display property using CSS, but I am unsure how to make d ...

What steps can be taken to convert this function into a more concise, dry function?

I'm attempting to customize a typewriter effect on my webpage, and while it successfully displays predefined data, I am struggling with converting it into a function that can receive values and then display those values. I have made attempts to modif ...

Encountering an issue while trying to set up a fresh react application

Issue encountered when trying to start a new React project ...

Performing multiple http requests in a loop and combining the retrieved data using AngularJS

I am currently working with a piece of source code that looks like this: var projectPromises = $http.get('http://myapi.com/api/v3/projects?private_token=abcde123456'); $q.all([projectPromises]).then(function(data) { console.log(data); ...

Ways to shift placeholder text slightly to the right within a select dropdown?

Struggling with this issue for hours, I can't seem to figure out how to: Adjust the position of the placeholder text (Search) by 10 pixels to the right in my select component Reduce the height of the field (maybe by 5px) without success. Could someo ...

Using Angular's ng-switch directive within a select dropdown option

Can we implement the [Data Presentation Format] to be utilized in the [Dropdown Box]? Specifically, I would like the "parent" items to appear as is within the dropdown, while the "child" items should have a [tab] indentation to denote their relationship wi ...

Converting large numbers (exceeding 53 bits) into a string using JavaScript

I have a REST service that returns JSON. One of the properties in the JSON contains a very large integer, and I need to retrieve it as a string before Javascript messes it up. Is there a way to do this? I attempted to intercept every response using Angular ...

Modifying the attribute of an element inside an array

Presented below is an object: { "_id" : ObjectId("5a8d83d5d5048f1c9ae877a8"), "websites" : [ "", "", "" ], "keys" : [ { "_id" : ObjectId("5a8d83d5d5048f1c9ae877af"), "name ...

Navigating through content using jQuery scroll bar

Could someone please assist me with scrolling the content on my website? For example, I have a link like this: <a href="#">content3</a> When a user clicks that link, I would like the content to scroll to div content3. I am looking for guidan ...

What is the best way to separate a table column into a distinct column at the specified delimiter count?

I successfully wrote code that splits the third column into new columns at the slash delimiter. However, I am struggling to modify it to split at the nth (i.e. 2nd) occurrence. I couldn't find a solution online, so I'm reaching out here for help ...