-
Hello there, guys! I got a little confused about how Patrick finds out the raffle winner on this unit test. In this timestamp, Patrick says "we gotta make sure our winner is correct", because we want to do some assertion on his balance. With some console.log, in this timestamp, he finds out winner is player on index number 1. Console.logs to find out the winner (only present during the video): Final code during the video (winnerStartingBalance defined as accounts[1] balance): This is the code on the repository for Lesson 9 (deleted the comments so it would have my comments only). Apparently the code was changed to accounts[2]: ...
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 winnerBalance = await accounts[2].getBalance() // also accounts[2] information
const endingTimeStamp = await raffle.getLastTimeStamp()
await expect(raffle.getPlayer(0)).to.be.reverted
assert.equal(recentWinner.toString(), accounts[2].address) // also accounts[2] information
assert.equal(raffleState, 0)
assert.equal(
winnerBalance.toString(),
startingBalance
.add(
raffleEntranceFee
.mul(additionalEntrances)
.add(raffleEntranceFee)
)
.toString()
)
assert(endingTimeStamp > startingTimeStamp)
resolve()
} catch (e) {
reject(e)
}
})
const tx = await raffle.performUpkeep("0x")
const txReceipt = await tx.wait(1)
// why is the balance for accounts[2] being selected here? Is it guaranteed this is going to be the winner?
const startingBalance = await accounts[2].getBalance()
await vrfCoordinatorV2Mock.fulfillRandomWords(
txReceipt.events[1].args.requestId,
raffle.address
)
})
... My question is: I understand that player number 1 was the winner on that raffle, but how is it that we know player number 1 is always going to win the raffle on that unit test? I feel like I'm missing something, obviously. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Can you outline the specific code snippet you are doubtful of? So I can elaborate. |
Beta Was this translation helpful? Give feedback.
Can you outline the specific code snippet you are doubtful of? So I can elaborate.