I am trying to run test of the contract that requires to enter ETH using hardhat and mocha. Test fails in “Allows player to enter” even though everything looks the same for “Allows player to enter”
const hre = require("hardhat");
const {expect} = require ("chai");
let account, account2, account3;
let lottery;
beforeEach(async () => {
[account, account2, account3] = await hre.ethers.getSigners();
const Lottery = await hre.ethers.getContractFactory("Lottery");
lottery = await Lottery.deploy();
await lottery.waitForDeployment();
});
describe("Lottery Contract", () => {
it("Deploys a contract", () =>{
expect(lottery.target).to.be.ok;
});
it("Allows player to enter", async() =>{
await lottery.enter({
from: account,
value: hre.ethers.parseUnits("0.11","ether"),
});
const players = await lottery.getPlayers({
from: account
});
expect(account.address, players[0]).to.equal;
expect(1, players.length).to.equal;
});
it("Allow multiple players to enter", async() =>{
await lottery.enter({
from: account.address,
value: hre.ethers.parseUnits("0.11","ether"),
});
await lottery.enter({
from: account2.address,
value: hre.ethers.parseUnits("0.11","ether"),
});
await lottery.enter({
from: account3,
value: hre.ethers.parseUnits("0.11","ether"),
});
const players = await lottery.getPlayers({
from: account
});
expect(account.address, players[0]).to.equal;
expect(account2.address, players[1]).to.equal;
expect(account3.address, players[2]).to.equal;
expect(3, players.length).to.equal;
});
});
enter function just pushes msg,sender into players array:
function enter() external payable minLimit{
players.push(msg.sender);
}
I tried to search problem but didn’t find any solution. This is the code from Stephen Grider course in hardhat. I am using hardhat local network.
Here is the console error:
Lottery Contract
√ Deploys a contract
√ Allows player to enter
1) Allow multiple players to enter
2 passing (2s)
1 failing
1) Lottery Contract
Allow multiple players to enter:
TypeError: from address mismatch (argument="transaction", value={ "data": "0xe97dcb62", "from": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", "to": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9", "value": 110000000000000000 }, code=INVALID_ARGUMENT, version=6.13.1)
at makeError (node_modulesetherssrc.tsutilserrors.ts:687:21)
at assert (node_modulesetherssrc.tsutilserrors.ts:715:25)
at assertArgument (node_modulesetherssrc.tsutilserrors.ts:727:5)
at C:UsersЗаурDesktoplotterynode_modules@nomicfoundationhardhat-etherssrcsigners.ts:214:25
at async Promise.all (index 0)
at HardhatEthersSigner._sendUncheckedTransaction (node_modules@nomicfoundationhardhat-etherssrcsigners.ts:256:7)
at HardhatEthersSigner.sendTransaction (node_modules@nomicfoundationhardhat-etherssrcsigners.ts:125:18)
at send (node_modulesetherssrc.tscontractcontract.ts:313:20)
at Proxy.enter (node_modulesetherssrc.tscontractcontract.ts:352:16)
at Context.<anonymous> (testLottery.test.js:39:5)