Lesson 9: Why is gas not added to the ending balance when comparing with assert #1408
-
In the hardhat-fund-me unit tests we compared starting balance and ending balance like this: assert.equal(
startingDeployerBalance.add(startingFundMeBalance).toString(),
endingDeployerBalance.add(gasCost).toString()
) But now we don't care about gas cost, why? assert.equal(
winnerEndingBalance.toString(),
winnerStartingBalance.add(raffleEntranceFee).toString()
) |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 11 replies
-
Going by sheer memory here, but pretty sure raffleEntranceFee is inclusive of gas fees. If this is not the case, let me know |
Beta Was this translation helpful? Give feedback.
-
@woojiq In the Fund Me contract, the deployer, or owner, is the one to call the withdraw function and therefore has to pay the gas fees in order to call that function. In the Raffle contract, the funds are transferred internally through the |
Beta Was this translation helpful? Give feedback.
-
@woojiq In the fund me contract, the deployer account was calling a withdraw function and that's why gas was deducted from the deployer account. But in the raffle case, Hope it clears your query. |
Beta Was this translation helpful? Give feedback.
-
@alymurtazamemon But when we fund the smart contract with 0.1ETH, we'll be spending some gas fees. Isn't it? Am I missing something? Don't we need to add it to startingBalance? |
Beta Was this translation helpful? Give feedback.
@woojiq In the fund me contract, the deployer account was calling a withdraw function and that's why gas was deducted from the deployer account. But in the raffle case,
fulfillRandomWords
was called by the Chainlink node and we already paid them a fee for it. That calling triggered the event and we select the winner, so the fee was never deducted from the winner's account that's why we did not calculate like the fund me contract.Hope it clears your query.