PatrickAlphaC / hardhat-smartcontract-lottery-fcc

MIT License
117 stars 183 forks source link

WinnerPicked event not caught by listener #165

Closed aimaneharrak closed 1 year ago

aimaneharrak commented 1 year ago

Hi,

In the tests, both on local network and testnet, the raffle.once listener doesn't seem to catch the event that it fires.

await new Promise(async (resolve, reject) => {
                      raffle.once("WinnerPicked", async () => {
                          console.log("WinnerPicked event fired!");
                          try {
                              const recentWinner =
                                  await raffle.getRecentWinner();
                              const raffleState = await raffle.getRaffleState();
                              const winnerEndingBalance =
                                  await ethers.provider.getBalance(deployer);
                              const endingTimeStamp =
                                  await raffle.getLatestTimeStamp();
                              await expect(raffle.getPlayer(0)).to.be.reverted;
                              assert.equal(recentWinner, deployer);
                              assert.equal(
                                  winnerEndingBalance,
                                  winnerStartingBalance + raffleEntranceFee
                              );
                              assert(endingTimeStamp > startingTimeStamp);
                              resolve();
                          } catch (error) {
                              console.log(error);
                              reject(e);
                          }
                      });

                      console.log("OK");
                      await raffle.enterRaffle({
                          value: raffleEntranceFee,
                      });
                      const winnerStartingBalance =
                          await ethers.provider.getBalance(deployer);
                  });

This is a screenshot of the event emitted from Etherscan Sepolia.

image

If I add the line below by hand at the end of the Promise, the listener gets triggered however ! But not when it is emitted from the fulfillRandomWords function.

raffle.emit("WinnerPicked");

Thanks !

rajdama commented 1 year ago

Hey are u using cron for chain link keepers?

PatrickAlphaC commented 1 year ago

Hm..... It seems to be firing for me...

aimaneharrak commented 1 year ago

Hm..... It seems to be firing for me...

I cloned your repo and it works for me with your dependencies and code.

I think it has to do with ethers, since I'm using version 6.6.0.

And I noticed my dependencies got quite messy at one point with some errors because of ethers version mainly.

Thanks anyways ! I'm going to close the issue now