I am trying to build a Dapp with hardhat installed in my vs Code my smart contracts parts are over and it gets compiled but I am facing a problem with test files I don't know why they are not getting compiled i have reinstalled hardhat again to check whether there is a problem with the configuration file or not but I am facing the same issue again and again. How can i fix this issue.

Whenever i try to compile my test file it appears with this error message.

PS D:\Blockchain Project> npx hardhat test

  0 passing (1ms)
  • Hi! Could you provide an example of one of your test files, and make sure that they're in the correct directory? Jan 4 at 10:27
  • Wdym by "Compiling" of test files. The test files are not written in solidity, they don't need to be compiled, they just need to be run. Make sure you have written test cases with the correct format. Jan 4 at 11:08

1 Answer 1

const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("DecentralizedBlog", function () {
  it("should create a post", async function () {
    const Blog = await ethers.getContractFactory("DecentralizedBlog");
    const blog = await Blog.deploy();
    await blog.deployed();

    await blog.createPost("Test Title", "Test Content");

    const post = await blog.posts(0);
    expect(post.title).to.equal("Test Title");
  it("should edit a post", async function () {
    // ... deploy contract, create a post ...

    // Edit the post
    await blog.editPost(0, "Edited Title", "Edited Content");

    // Retrieve the edited post and check if it's updated
    const editedPost = await blog.posts(0);
    expect(editedPost.title).to.equal("Edited Title");
    expect(editedPost.content).to.equal("Edited Content");
  it("should delete a post", async function () {
    // ... deploy contract, create a post ...

    // Delete the post
    await blog.deletePost(0);

    // Check if the post is deleted or handle how your contract responds to deleted posts
    // This depends on how you've implemented deletion in your contract
  it("should add a comment to a post", async function () {
    // ... deploy contract, create a post ...

    // Add a comment to the post
    await blog.addComment(0, "Test Comment");

    // Retrieve the comment and check its content
    const comment = await blog.comments(0, 0); // Adjust indexes based on how you retrieve comments
    expect(comment.content).to.equal("Test Comment");
  it("should like a post", async function () {
    // ... deploy contract, create a post ...

    // Like the post
    await blog.likePost(0);

    // Retrieve the like count and check it
    const likeCount = await blog.likes(0);

console.log("Deploying contract");
// Deploy the contract
console.log("Contract deployed");

This is my test file code which i couldn't able to run

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.