Lesson 9: Has anyone tried refactoring code to not emit RequestedRaffleWinner event? #1858
-
In lesson 9, at around 15:47, Patrick explains we don't need this line of code in Raffle.sol:
Because the VRFCoordinatorV2 function
In our Raffle.test.js code, we're testing to make sure we can get requestId from the logs after calling PerformUpkeep. Has anyone successfully refactored this? I imagine the steps would be something along the lines of:
Anyone have any luck with this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
@PatrickAlphaC a little help here. :) |
Beta Was this translation helpful? Give feedback.
-
a little more detail... Changes to raffle.sol:Here's what performUpkeep looks like now.I commented out
This is what I see in VRFCoordinatorMock2 - this is the event we need to access:
Changes to Raffle.test.sol:This is the original PerformUpkeep test in Raffle.test.sol:
I figure I need to change this line:
Instead of going to the events index at 1, I think I need to go to the events index at 0. But when I tried that I was getting an empty object and after playing around printing to console I got stuck and gave up. |
Beta Was this translation helpful? Give feedback.
-
Hey @atenger and @PatrickAlphaC I think I cracked it. Okay so we know
So now, we can even request the arguments same as we did with the second event at index 1.
And...whadyya know... there it was, the entire event and some other args. (Of course the test failed, but I just wanted to see if it worked)
So with this, I just replaced 1 with 0 in my initial code and I was good to go. Long story short, add this event declaration code in your raffle contract and replace
|
Beta Was this translation helpful? Give feedback.
Hey @atenger and @PatrickAlphaC I think I cracked it. Okay so we know
i_vrfCoordinater.requestRandomWords()
method emits an event calledRandomWordsRequested
It is emitted in our Raffle contract but our contract doesn't have an event declaration for this said event. So i figured, what if I initialized/declared thisRandomWordsRequested
event in my raffle contract similar to the one in the VRFCoordinatorV2Mock. I mean we already know it is emitted (the first event at index 0), we just need to sort of catch it right? So I added this code in my raffle contract event sections