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");
})
});