Assertion Fails with different values. #2774
-
I have faced may errors while testing my staging test at lesson 9 and managed to solve them but this one I don't understand. assert.equal(
winnerEndingBalance.toString(),
winnerStartingBalance.add(raffleEntranceFee).toString()
) The error I get is; 1) Raffle Unit Tests
fulfillRandomWords
works with live chainlink keepers and chainlink VRF, we get a random winner:
AssertionError: expected '1188256547412043550' to equal '1198256547515642318'
+ expected - actual
-1188256547412043550
+1198256547515642318
at FragmentRunningEvent.<anonymous> (test/staging/Raffle.staging.test.js:42:38)
at processTicksAndRejections (node:internal/process/task_queues:96:5) I thought the difference might be gas but it's unlikely. The tutorial just covers Full test; describe("fulfillRandomWords", function () {
it("works with live chainlink keepers and chainlink VRF, we get a random winner", async function () {
console.log("Setting up test...")
// grab starting timestamp
const startingTimestamp = await raffle.getLastestTimeStamp()
const accounts = await ethers.getSigners()
// set up a listener before we enter the raffle
// just incase the blockchain moves really fast
console.log("Setting up Listener...")
await new Promise(async (resolve, reject) => {
raffle.once("WinnerPicked", async () => {
console.log("WinnerPicked event fired!")
try {
// add our asserts here
const recentWinner = await raffle.getRecentWinner()
const raffleState = await raffle.getRaffleState()
const winnerEndingBalance = await accounts[0].getBalance()
const endingTimestamp = await raffle.getLastestTimeStamp()
await expect(raffle.getPlayers(0)).to.be.reverted
//assert.equal(recentWinner.toString(), deployer.toString())
assert.equal(recentWinner.toString(), accounts[0].address)
assert.equal(raffleState, 0)
assert.equal(
winnerEndingBalance.toString(),
winnerStartingBalance.add(raffleEntranceFee).toString()
)
assert(endingTimestamp > startingTimestamp)
resolve()
} catch (error) {
console.log(error)
reject(error)
}
})
// enter the raffle
console.log("Entering Raffle...")
await raffle.enterRaffle({ value: raffleEntranceFee })
console.log("Ok, time to wait...")
const winnerStartingBalance = await accounts[0].getBalance()
// this code won't complete until listener has finished listening
})
})
}) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
@othaime-en any ideas sir? |
Beta Was this translation helpful? Give feedback.
-
Hey @kihiuFrank please push your code to github and leave a link here. I can't see any error here. I need to run it locally and see if I can figure out what is wrong. |
Beta Was this translation helpful? Give feedback.
Hey @kihiuFrank please push your code to github and leave a link here. I can't see any error here. I need to run it locally and see if I can figure out what is wrong.