Current location: Home > cpp > Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep68 Text
Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep68
Time: 2025-07-11 11:41:36 Source: Codora.ai Author: cs Reading: 674 times
right but theo von podcastrememberwhen we call this end Lottery functionwe're going to make a request to a chainlink node and that chain link node isgoing to respond by calling this fulfillRandomness function so we actually haveto wait for that chain link node tofinish now typically it's within a fewblocks so normally what we can do is wecan just do a Time dossleep for something like 60 seconds andtypically in that time the chain lcknode will have responded so we'll justdo importtime top time. sleep and then we can seewho that recent winner is if that chainlink node responded with a recent winnerso we can say printF Lottery a recentwinner is the newwinner all right now of course for thoseof you who are thinking ahead a littlebit you might be thinking hey wellthere's no chain link nodes watching ourlocal ganache and you're exactly correctso what happens when we add our endLotteryfunction to our main function here doyou think that we're going to actuallyget a recent winner back why are we notwhat do you actually think well let'sgive it a shot do brownie run scriptsemploy lotterydepy so we're doing a lot oftransactions here we've started thelottery we're entering ing the lotteryyou entered the lottery we're sendingsome link token now we just called theend Lottery function while we're waitinghere this is when the chain link nodewould go ahead and start responding withour Randomness however as you'reprobably astutely telling however as youprobably astutely guessed there's nochain link node that's going to callthis fulfill Randomness function rightnow so for our ganache chain this willhypothetically end with nothing rightthere's no chain link node actuallyresponding zero is the new winner ofcourse this means that the chain linknode actually didn't respond becausethere is no chain link node on our localganache for our testing purposes we'regoing to figure out how to actually getaround that and deal with that awesomeit looks like we have everything set upto be successful in our Lottery here butwe want to do our due diligence we wantto make sure that our tests are reallysolid on a development chain before weactually test this on an actual test netso let's jump into some of these testswe've already started with this testlottery. piy bit here but we're going toiterate on this and make this evenbetter now before we get into thesetests there's a couple things we want totalk about here and that's going to beintegration tests and unit tests unittest is a way of testing the smallestpieces of code in an isolated system andwe're going to use it to Loosely Definetesting independent functions in ourLottery cont we also want to do what'scalled integration testing which isgoing to be testing across multiplecomplex pieces typically I like to runmy unit tests exclusively on adevelopment environment and myintegration tests on a test net this isreally helpful because we can test themajority of our application like we saidon a development Network and then stillbe able to see what actually happens ona real testet and see what happens onether scan and everything like thattypically what people do is INS sidetheir test folder they'll create twodifferent folders one forunit and another folder for increation since for this demo we're onlygoing to have one file for both I'm justgoing to go ahead and not create thisfoldersbut but it's a pretty commonpractice instead what I'm going to do isI'm going to rename this I'm going tohit enter to renamed it and dounderscore typeunit for unit test and we're going tocreate a new file called test lotteryintegration. so this this one we'll doour integration tests and in this onewe'll do our unit tests now when writingunit tests we really want to testhypothetically every single line of codein our smart contract this is incrediblyimportant of course because smartcontracts are open to everybody to seeand interact with so we really want totest every single line of code we havein here so let's go ahead and let's goahead and finish writing a get entrancefee test that will work on a localdevelopment Network as you can see we'realready going to have to re Factor thisfrom what we originally had let's goahead and just delete everything underhere for now we already learned so muchmore from there all right so how are wegoing to test this get entrance viewfunction now so first we're going towant to deploy our Lottery again sincewehave a deploy Lottery script already wecan just use this deployed Lotteryscript as well if we wanted to we couldjust copy paste this whole part into ourtest but we're just going to go aheadand work from this deploy Lottery scriptso we're going to import this and thenwe can actually even get rid of thisfrom web three line for now we can getrid of these two comments too and we'llsay from scripts. deployLotteryimportdeploy Lottery and this deploy Lotteryfunction would say Lottery equals deployLottery and we will return our Lotterynow on a unit test we'll say Lotteryequals deployLottery and this will give us ourLottery contract once we have ourLottery contract we can just call thisget entrance fee so we can say entrancefee equals lottery. getet entrancefee and oops let's just make sure we'redoing therrangeACT certainer mentality here and we'regoing to want to make sure this entrancefee is what we expected to be so what dowe expect it to be well again ourhelpful scripts is going to deploy thesemocks right it's going to deploy thisMock and the initial value is this 2,000number so if theprice of e here is2,000 $2,000 FUSD feed and theUSD entry fee is 50 we' say 2,00 over 1is equal to 50X which is going to be equal to0.025 so we can go ahead and even dothis mathhere we can sayexpected expected entrancefee is going to be equal to it's goingto be equal to 50 divided 2,000 we'lljust do0.025 but we'll do this in way do fromweb 3 support web3 say this is web3.2 way 0.25 ether and now we'll assertour expected entrance feeequals the entrance fee now to test thiswe'll do browny test-K and perfect this is working exactly aswe anticipated so
(Editor in charge: go)
Latest content
- ·Artificial Intelligence Full Course _ Artificial Intelligence Tutorial for Beginners _ Edureka - Ep24
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep57
- ·Getting started with Web3 in 2025 _ Deep Dive Explainer - Ep8
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep69
- ·The Basics of Web3 - Ep7
- ·Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep34
- ·Web3 & Crypto Will Change The World As We Know It! Yat Siu - Ep6
- ·Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep59
- ·GenAI Essentials – Full Course for Beginners - Ep5
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep6
Hot content
- ·Godfather of AI_ I Tried to Warn Them, But We’ve Already Lost Control! Geoffrey Hinton - Ep5
- ·Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep22
- ·Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep42
- ·XRP Ripple LIVE Senate Brad Garlinghouse - FROM WALL STREET TO WEB3 - Martyn Lucas Investor - Ep22
- ·Artificial Intelligence Full Course _ Artificial Intelligence Tutorial for Beginners _ Edureka - Ep34
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep264
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep18
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep112
- ·Godfather of AI_ I Tried to Warn Them, But We’ve Already Lost Control! Geoffrey Hinton - Ep13
- ·Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep49