Lesson 7 - 11:36 - Why are we adding gasCost to the endingDeployerBalance? #272
-
In this test case, could someone please explain why the is "deployer" getting the gasCost? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Whoever calls the transaction, pays the gas costs associated with it. In this function, we are calling the Take this scenario.
If the 1 + 1 = 2 ETH... but they also paid the gas of calling the So they would have 1 + 1 - (gascosts) = ~1.9(ish) In our tests, we want to account for the gas costs to make it accurate. So, following our example, if you take the test: assert.equal(
//BigNumber.add() function is better to perform math operations, makes it easier
startingFundMeBalance.add(startingDeployerBalance),
endingDeployerBalance.add(gasCost).toString()
) We are saying that:
Does this make sense? |
Beta Was this translation helpful? Give feedback.
Whoever calls the transaction, pays the gas costs associated with it. In this function, we are calling the
withdraw
function.Take this scenario.
deployer
address has 1 ETHFundMe
contract has 1 ETHIf the
deployer
address calls thewithdraw
function and pulls the 1 ETH out of theFundMe
contract, how much ETH will they have?1 + 1 = 2 ETH... but they also paid the gas of calling the
withdraw
function.So they would have 1 + 1 - (gascosts) = ~1.9(ish)
In our tests, we want to account for the gas costs to make it accurate.
So, following our example, if you take the test: