0

I'm having problems with my testing. I'm using hardhat and chai library.

Solidity contract:

function setMsg(string memory _message) public{
        message = _message;
    }

and my testing file is this:

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

describe("Private Messages Contract Testing...\n", function () {

    const setup = async () => {
        const [owner, addr1, addr2] = await ethers.getSigners()
        const Message = await ethers.getContractFactory("Message")
        const deployed = await Message.deploy()

        return {
            owner,
            addr1,
            addr2,
            deployed
        }
    }

   
   
    describe("Testing Message Functions\n", () => {
        it("Owner can set and get a new message", async () => {
          
            const { deployed, owner } = await setup();

           

            await deployed.setMessage(
                    "Hello from Owner!",
                    { from: owner.address}
                );

            const message = await deployed.viewMessage();
            expect(message).to.be.a('string').and.equal("Hello from Owner!");
            
        });
        
    });

   
    it("User can set and get a new message", async () => {

        const { deployed, owner, addr1 } = await setup();

        

        await deployed.setMessage(
            "Hello from User 1",
            { from: addr1.address }
        );

        let userMsg = await deployed.viewMessage();
        expect(userMsg).to.be.a('string').and.equal("Hello from User 1");


    })
   
});

1 Answer 1

0

I found the solution:

 await deployedContract.connect(addr1).setMessage("Hello from User 1");

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.