New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Testing Your Deployment

BaseMon, Oct 9, 2023, 12:00 AM

Modify your test file to make use of the deploy script, allowing you to deploy your contract to different networks effortlessly. This saves time and ensures consistency in testing and deployment. Boost your confidence before launching your smart contract on test networks or mainnet. 🚀💡 📚 Head to Base Camp for full courses on smart contract development: https://docs.base.org/base-camp/docs/welcome ✅ Subscribe to our channel here: https://www.youtube.com/@BuildonBase ► Build on Base: https://base.org ► Follow us on Twitter: https://twitter.com/buildonbase ► Join our Discord: https://base.org/discord

Transcript

we could use our new deploy script to deploy our contract to a test Network right away but another thing that we can do is use our test that we wrote and modify it so that it makes use of this deploy script rather than deploying the contract within the test itself the advantage of doing this is that you only need to maintain one set of information and scripts to deploy your contract both for testing within the hardhat Network on your local computer and testing and final deployment on either a test Network or an actual mainnet Network when you're ready to Launch the first thing we need to do is add a tag to our deploy script which will help us find it in the test file we can add that with funk dot tags and we'll add just a single tag for deploy all and we'll save that and go over to our lock test file please do note that this is not the automatically generated test that you get when you create a new project that we explored in one of the videos but this is the test that you wrote yourself following the step-by-step written guide if you're not sure which one you have double check and make sure that the before function is present in the test file the first thing that we need to do is we need to import deployments from hard hat and this will allow us to access our deploy scripts in this file if you remember when writing these tests we set up the before function that's run before each test hence the name and we're going to make a couple of modifications here so that instead of deploying the contract within this file will instead use our deploy script we need to keep our last block timestamp because that's used in some of the tests below but we can get rid of these last two sections here that calculate the unlock time and deploy the contract instead will await deployments dot fixture and make use of that deploy all tag and then we'll get our deployment by awaiting deployments dot get our lock contract now that we have that we can recreate our lock instance with using the lock Factory still and connecting with our lockdeployment DOT address and the owner signer wallet all right with this set up we should be able to run npx hard hat test and our deployment and tests all work as before

Automatic transcript — names and jargon may be misspelled.