smartcontractkit / full-blockchain-solidity-course-js

Learn Blockchain, Solidity, and Full Stack Web3 Development with Javascript
12.4k stars 2.99k forks source link

TypeError: Cannot read properties of undefined (reading 'waitForTransaction') #6270

Open RashInTech opened 11 months ago

RashInTech commented 11 months ago

Lesson

Lesson 9

Could you please leave a link to the timestamp in the video where this error occurs? (You can right click a video and "copy video URL at current time")

No response

Operating System

Windows

Describe the bug

const { assert, expect } = require("chai")

const { network, deployments, ethers, getNamedAccounts } = require("hardhat") const { developmentChains, networkConfig } = require("../../helper-hardhat-config")

!developmentChains.includes(network.name) ? describe.skip : describe("Raffle Unit Tests", function () { let raffle, VRFCoordinatorV2Mock, raffleEntranceFee, deployer const chainId = network.config.chainId beforeEach(async function () { deployer = (await getNamedAccounts()).deployer await deployments.fixture(["all"]) raffle = await ethers.getContract("Raffle", deployer) VRFCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock", deployer) raffleEntranceFee = await raffle.getEntranceFee() })

      describe("constuctor", async function () {
          it("initializes the raffle correctly", async function () {
              const raffleState = await raffle.getRaffleState()
              const interval = await raffle.getInterval()
              assert.equal(raffleState.toString(), "0")
              assert.equal(interval.toString(), networkConfig[chainId]["interval"])
          })
      })
      describe("enterRaffle", async function () {
          it("reverts when you don't pay enough", async function () {
              await expect(raffle.enterRaffle()).to.be.revertedWith(
                  "Raffle_NotEnoughETHEntered",
              )
          })

          it("Record when players enter", async function () {
              await raffle.enterRaffle({ value: raffleEntranceFee })
              const playerFromContract = await raffle.getPlayer(0)
              assert.equal(playerFromContract, deployer)
          })

          it("emits an event on enter", async function () {
              await expect(raffle.enterRaffle({ value: raffleEntranceFee })).to.emit(
                  raffle,
                  "raffleEnter",
              )
          })
      })
  })

I am getting TypeError: Cannot read properties of undefined (reading 'waitForTransaction') when emitting my event.Can anyone fix this?

surfiniaburger commented 3 months ago

Insteand of it("emits an event on enter", async function () { await expect(raffle.enterRaffle({ value: raffleEntranceFee })).to.emit( raffle, "raffleEnter", )

try this await expect(raffle.enterRaffle({ value: raffleEntranceFee }).to.eventually.equal(raffle);

krishna-vasudev commented 1 month ago

Reason: It is because you are ether v6 as your main depedency, but hardhat-waffle has ether v5 as a dependency. So there is conflict between ether versions which creates the issue.

Solution : hardhat-waffle uses ether v5 as a depedency, even for the latest version. So if you want to use hardhat-waffle, downgrade to ether v5, downgrade the dependent packages as well.

But if you want to use ether v6 then use hardhat-toolbox and hardhat-chai-matchers instead of hardhat-waffle.