lesson-9 testing
Question
#2363
-
Can someone explain me this any easy explanation would be helpful. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 14 replies
-
@MasterofBlockchain on line 37, |
Beta Was this translation helpful? Give feedback.
-
@MasterofBlockchain : Let me clear your question in layman language : In background our contract is running and we need to mimic all the steps and input parameters of our function in order to execute the test successfully : e.g : function EnterLottery(uint256 entranceFee) : You have to put the entranceFee because its the input parameter of this function. So, Now, In order to record the player you need to enter in the lottery first. So, In your it statement first line is : Now, If you run your assert statement : You know why ? Because PlayerFromContract didn't enter the lottery, because he didn't pay the required entranceFee to the contract. So, He will not be recorded in GetPlayers array,
There will be no one there! Now, Lets pay the required entranceFee as an input parameter when entering the lottery :
So, now the PlayerFromContract did actually paid the required entranceFee to the contract, He will now be recorded in GetPlayers array, So, you can check it by :
And you will get your deployer address! After that when you run you assert statement : That's why we needed entranceFee input parameter for our function EnterLottery in our tests! Hopefully, This explanation will clear your doubt! |
Beta Was this translation helpful? Give feedback.
@MasterofBlockchain on line 37,
playerFromContract
is assigned tolottery.GetPlayer(0)
If you look at the contract code, the functionGetPlayer(0)
returns the player that joined the lottery (at index 0). In this case, on line 35, you joined the lottery with thedeployer
account. Which means that thes_players
array already contrains one player: The deployer. So calling thegetPlayer(0)
function should return the deployer account assigned toplayerFromContract
. Therefore that is why we check ifplayerFromContract
is similar todeployer
to make sure that indeed the right account got stored in the players array