Current location: Current location: Home > swift > Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep107 Text
Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep107
[swift] Time: 2025-07-11 11:27:28 Source: AIHackNode Author: rust Click: 59 times
codeare tested basically what we want to dois in our contracts we want to testminimal portions of our code to makesure that they work correctly then onceour small pieces of the test work wewant to do psycho killer seriesa staging test or maybe anintegration test this might be where werun our code on a test net or someactual Network you can think of astaging test as kind of the last stopbefore you deploy to a main net they'renot always 100% necessary but they canbe really really helpful remember we dowant to be conscientious of how much weuse our test Nets but we absolutely 100%want to make sure that everything workslocally and that we unit test and we runall of our code locally then we can usea staging test on an actual test net tomake sure that our code will work withactual other contracts now you tests canbe done with a local hard hat Network ora forked hard hat Network we'll talkabout this forked hard hat Network verysoon right now let's build these unittests these unit tests are going to bebasically what we saw in our lastsection so let's go in and let's jump inand write some of these unit tests solet's create a new test we'll call itfundme. JS and we'll start making our testin here now we did test previously inour last section but our test here aregoing to look a little bit differentlywe're actually going to use hard hatdeploy to automatically set up our testas if both of these deploy functions hadbeen run so let's go ahead and get thisstarted so we're still going to do thatsame setup though we're going to dodescribe we're going to sayfundme and this is going to have thatasyncfunction like so and in here we're goingto have a before eachand we're going to have some its andsome describes and everything now sincewe want to unit test this we're going togo a little bit heavier on the test herethan with our last project but in thefuture we'll go a little bit lighterwith some of the tests so let's getstarted if we run yarn hardhead testrightnow we we're going to get zero passingnow if we run yarn hard hatcoverage we're going to get somethingthat looks like this saying hey uhyou're missing a lot of stuff so let'stry to cover some more lines with ourtests and one way we can do that isactually we can group our tests basedoff of different functions so let's haveour first set of tests be around ourConstructor to do that inside of ourfirst describe we can add anotherdescribe and have this described be justthe Constructor this larger scope willbe for the entire fundme contract andeverything inside this one will justbefore the Constructor so this will alsobe an asyncfunction and these test will be just forthe Constructor but before we even workon this describe we probably want todeploy our fundme contract so let'slearn how to do that so we'll do abefore each which will be an async[Music]function and we're going to deploy ourfundme contract using hard hat deploysince we use hard hat deploy our fundmecontract will come even with our Mockand everything so above the before eachlet's dolet fundmeand in here we're going to deploy fundmethe way we're going to deploy our fundmecontract is first by pulling in ourdeployment object from hard hat deployso we'll do constdeployments equalsrequire hard hat and this deploymentsobject has has a function called fixturewhat fixture does is it allows us tobasically run our entire deploy folderwith as many tags as we want you'llnotice I added this all tag in both ofour Scripts this means that in thisdeployment. fixtures excuse me awaitdeployment. fixtures if I run awaitdeployments fixture I'll run through ourdeploy script on our local network anddeploy all of the contracts so that wecan use them in our scripts and in ourtesting and we can deploy everything inthat deploy folder with just this oneline isn't that helpful now once all ofour contracts have been deployed we canstart getting them we'll say fundmeequalsawait ethers and we'll pull an ethersfrom hardhead aswell dot and this is where hard hatdeploy is helpful again hardhead deploywraps ethers with a function called getcontract this get Contract function isgoing to get the most recent deploymentof whatever contract we tell it so we'llsay get Contract of fundme so this willgive us the most recently Le deployedfundme contract in just this one lineand now fundme will be equal to thisline here now we're going to make abunch of transactions on our fundme totest it of course we can also tellethers which account we want connectedto fundme so I can sayconst deployer equals equals a away getnamed accounts exactly like we did inour deploy script and then we just needto import it from hardap in our deployscripts we imported geted accountsinside of our input parameters for ourdeploy function remember get accountsand deployments was abstracted from ifwe look up here from the hardheadruntime environment and like I said thehardhead runtime environment isbasically the same thing as hard hat sowe can just go ahead and import it likethis actually like this because weactually need to abstract just thedeployer from get named accounts and nowwhat we can do is we can connect ourdeployer to our fundme account sowhenever we call a function with fundmeit'll automatically be from thatdeployer account which is great anotherway you you can get different accountsdirectly from your heead config is youcould say const accounts equals awaitethers doget signers ethers dogetsigners is going to return whatever isin this account section of your networkif you're on your default Network hardhat it's going to give you a list of 10fake accounts that we can work with youthen of course can do something likeconst count one equalsaccounts more correctly would be accountZ equals account Z and click that we'llleave that commented out just in caseyou need a reference to it in the futureokay great so now we have our fundmecontract let's go ahead and write sometest for testing the Constructor andwe're probably going to want to use thisdeployer object down here
(Editor in charge: go)
GenAI Essentials – Full Course for Beginners - Ep154Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep79
Related content
- Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep258
- [Hindi (auto-generated)] Machine Learning FULL Course with Practical (10 HOURS) _ Learn Free ML in 2025 _ Part-1 - Ep12
- [Hindi (auto-generated)] Machine Learning FULL Course with Practical (10 HOURS) _ Learn Free ML in 2025 _ Part-1 - Ep34
- [Hindi (auto-generated)] Machine Learning FULL Course with Practical (10 HOURS) _ Learn Free ML in 2025 _ Part-1 - Ep20
- Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep83
- Artificial Intelligence Full Course _ Artificial Intelligence Tutorial for Beginners _ Edureka [DownSub.com](1).txt - Ep13
- Harvard CS50’s Artificial Intelligence with Python – Full University Course - Ep56
- Harvard CS50’s Artificial Intelligence with Python – Full University Course - Ep83
- XRP Ripple LIVE Senate Brad Garlinghouse - FROM WALL STREET TO WEB3 - Martyn Lucas Investor - Ep3
- [Hindi (auto-generated)] Machine Learning FULL Course with Practical (10 HOURS) _ Learn Free ML in 2025 _ Part-1 - Ep52
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep9
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep87
- Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep57
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep226
Wonderful recommendations
- Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep33
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep32
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep213
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep228
- GenAI Essentials – Full Course for Beginners - Ep8
- Artificial Intelligence Full Course _ Artificial Intelligence Tutorial for Beginners _ Edureka [DownSub.com](1).txt - Ep44
Popular Clicks