Current location: Current location: Home > javascript > Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep153 Text
Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep153
[javascript] Time: 2025-07-11 11:53:57 Source: AIHackNode Author: article Click: 51 times
make one giant test to testkind of everything end to end and ai tools for developersyoucan add more tests later on yourself ifyou want to our staging test is going tobe really similar to this massive testthat we made down here and in fact we'regoing to use most of this code here asour boiler plate so let's create adescribe and we'll say and we'llactually just copy this describe forrandom words and paste it in here cuzagain we're going to be using a lot ofthe same code in our stating test heregreat so now we'll say it works withlive chain link Keepers and chain linkVF we get a random winner async functionboom so this is going to be our test inhere so in this test we of course wewant to enter the raffle and weshouldn't have to do anything elseexcept for enter this raffle because thechain L Keepers and the chain L vrf aregoing to be the ones to actually kickoff this lottery for us we'll do a quickgrabbing of the starting timestamp tohave it before all this kicks off sowe'll say const starting timestampequals await raffle doget last me getlatest timestamp get latest timestampwe're going to grab this because lateron we're going to test to see if thetime stamp has indeed moved forward wewant to enter the lottery right we wantto run the command we've been runningover here all the time we want to do youknow await raffle do enter raffle but wedon't want to call it yet because sameas what we did over here we want to setup our listener first now in here weprobably should have set up our listenerbefore we entered the raffle however wecontrolled the blockchain so putting itin that order was is was okay but wewant to set up the listener before weenter the raffle just in case theblockchain moves really fast and we'regoing to set up the listener the exactsame way we did it over here so we'regoing to say await new promise and thisis going to be an async function thattakes a resolve and areject and we're going to use a littlearrow notation here and in here we'regoing to set up the listener we're goingto say raffle do once once that winneris picked we're going to do anotherasync function using that ArrowArrow function syntax we'll sayconsole.log winnerpicked eventfired and only once we get this winnerpicked can we start doing our asserts inhere can we start making sure thatthere's a winner there's a verifiablyrandom winner it's been picked themoney's been moved Etc this is wherewe'll do our trycatch and if there's any error we'rejust going to automatically reject we'regoing to reject the promise and if allgoes well of course of course we'regoing to resolve the promise so ourlistener has been set up here we haven'tadded our asserts here but we will let'sjust go ahead and write the rest of thetest and then we'll go back and we'llupdate this listener so so our listenerhas been added and inside here isactually where we're going to enter theraffle so inside here await raffle doenterraffle value is going tobe raffle entrancefee and really that's it right so we'resetting up The Listener setting up thelistener then entering theraffle and this code won't completeuntil our listener has finishedlistening cuz again this whole SE is inand await so we're going to say okaycool set up the listener wait for thisto finish and then when it gets here itgoes ah okay this is the end of the codeuh are we all done executing oh noresolve or reject hasn't been called yetand that's because we're still waitingfor the listener to finish listening nowonce we get this winner picked eventemitted in here we're going to get thatrecent winner so we'll say const recentwinner equals awaitraffle.org get raffle State we'll getthe Winner's balance so we'll sayconst winner balance equalsawait recent winner and since we're onlyentering with our deployer we shouldcheck to see the deployer balance at theend and we can't do it right with thisdeployer object here so we'll have to dodeployer account equals await ethersdoget signers we'll wrap this actuallyactually we'll just say this is countshere like that and then we'll just doaccounts of zero because accounts ofzero is going to be our deployer so ourwinner balance is going to be account tozero dot get balance then we're going todo const endingtimestamp equalsawait raffle doget latest time stamp andwe should also get the starting balanceso we'll say winner ending balance weshould also get the starting balanceright after we enter so we'll say constwinner starting balance equals awaitaccounts 0. getet balance so that now wecan do some comparison all right greatlet's do the comparisons now so weshould first expect the raffle to bereset so we can do this a few differentways down here we did number of playerswe could also say await expect raffledoget player0.2b do reverted right because getplayer of zero should get revertedbecause there's not even going to be anobject at zero so that's another way wecan check to see if our player array hasbeen reset accept next we can do assertdo equal recentwinner. two string this should equal ouraccount zero. address AKA our deployerwhat else can we do we will assert equalrapal state to zero we want this enum togo back to open after we're done andthen we finally want to make sure thatthe money has been transferred correctlyso we'll do assert do equal this shouldbe winner ending balance. two stringshould be equal to winner startingbalanceadd raffle entrance fee. two string soif we look down here they enter theraffle we check their starting balanceright after they enter and theybasically should just get that raffleentrance feed back right because they'rethe only ones who have entered thisraffle and then we can do one moreassert we'll do assert at the ending Timstampis greater than the starting time stampand then we'll of course say resolve soif this all goes well we resolve ifthere's an issue with any of theseasserts we're going to catch thoseerrors and we're going to reject andthis is going to be false and this wholetest is
(Editor in charge: php)
Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep149Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep281
Related content
- GenAI Essentials – Full Course for Beginners - Ep59
- [Hindi (auto-generated)] Machine Learning FULL Course with Practical (10 HOURS) _ Learn Free ML in 2025 _ Part-1 - Ep91
- ROSÉ_ The rosie Interview _ Apple Music - Ep2
- [Hindi (auto-generated)] Machine Learning FULL Course with Practical (10 HOURS) _ Learn Free ML in 2025 _ Part-1 - Ep121
- Artificial Intelligence Full Course _ Artificial Intelligence Tutorial for Beginners _ Edureka - Ep33
- [Hindi (auto-generated)] Machine Learning FULL Course with Practical (10 HOURS) _ Learn Free ML in 2025 _ Part-1 - Ep91
- The 3 Year AI Reset_ How To Get Ahead While Others Lose Their Jobs (Prepare Now) _ Emad Mostaque - Ep1
- Artificial Intelligence Full Course 2024 _ AI Tutorial For Beginners _ AI Full Course_ Intellipaat - Ep28
- Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep45
- Miley Cyrus_ Something Beautiful, Touring & Stardom _ Zane Lowe Interview - Ep9
- [Hindi (auto-generated)] 2025's Most Important Career Podcast - AI Skills For All Ages _ Masters' Union Dr. Nandini Seth - Ep6
- How to use ChatGPT in 2025 _ ChatGPT Tutorial _ ChatGPT Full Course - Ep49
- Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep168
- The 3 Year AI Reset_ How To Get Ahead While Others Lose Their Jobs (Prepare Now) _ Emad Mostaque - Ep21
Wonderful recommendations
- Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep234
- [Hindi (auto-generated)] Machine Learning FULL Course with Practical (10 HOURS) _ Learn Free ML in 2025 _ Part-1 - Ep85
- How to use ChatGPT in 2025 _ ChatGPT Tutorial _ ChatGPT Full Course - Ep83
- [Hindi (auto-generated)] Machine Learning FULL Course with Practical (10 HOURS) _ Learn Free ML in 2025 _ Part-1 - Ep82
- Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep163
- Katt Williams _ This Past Weekend w_ Theo Von #558 - Ep11
Popular Clicks