1/5
## Testing Deploy Scripts We're going to continue testing smart contracts. We'll focus on a common issue that arises: testing a deploy script. Currently, our tests only verify the starting values. However, we haven't included tests for the changes our deploy script makes. Let's fix this by adding tests for the changes our deploy script makes. We are going to make use of the import system in Python, which can be done by importing modules, which are essentially folders or files that contain code we can access. The script folder in our project contains an `__init__.py` file, which informs Python that the folder is a module and allows us to import functions from it. We'll modify the import statement in our test file: ```python from script.deploy import deploy_favorites ``` We can then use our function in our tests to get the contract: ```python def test_starting_values(): favorites_contract = deploy_favorites() assert favorites_contract.retrieve() == 77 ``` Now, our tests will verify the starting values of our contracts. Let's also add a test to verify that our deploy script can change values. ```python def test_can_change_values(): favorites_contract = deploy_favorites() favorites_contract.store(42) assert favorites_contract.retrieve() == 42 ``` By using the import system and explicitly referencing our deploy script, we can effectively test the changes made to our contracts during deployment. Now, we'll run our tests: ```bash mox test ``` We can see that our tests pass.
We're going to continue testing smart contracts. We'll focus on a common issue that arises: testing a deploy script.
Currently, our tests only verify the starting values. However, we haven't included tests for the changes our deploy script makes.
Let's fix this by adding tests for the changes our deploy script makes.
We are going to make use of the import system in Python, which can be done by importing modules, which are essentially folders or files that contain code we can access.
The script folder in our project contains an __init__.py
file, which informs Python that the folder is a module and allows us to import functions from it.
We'll modify the import statement in our test file:
We can then use our function in our tests to get the contract:
Now, our tests will verify the starting values of our contracts.
Let's also add a test to verify that our deploy script can change values.
By using the import system and explicitly referencing our deploy script, we can effectively test the changes made to our contracts during deployment.
Now, we'll run our tests:
We can see that our tests pass.
A practical guide to testing deploy scripts - The lesson explains the importance of testing deploy scripts. It teaches you how to import functions from other files in a project for unit testing and how to write a test to ensure the deploy script functions correctly.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Python basics
Introduction to Web3.py
Introduction to Titanoboa
Introduction to Moccasin
How to create an ERC-20
How to test Python code and Vyper smart contract
How to deploy Vyper smart contracts on ZKsync using Moccasin
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on June 10, 2025
Duration: 2h 20min
Duration: 1h 51min
Duration: 58min
Duration: 2h 23min
Duration: 53min
Duration: 2h 24min
Duration: 28min
Duration: 1h 54min
Duration: 11min
Course Overview
About the course
Python basics
Introduction to Web3.py
Introduction to Titanoboa
Introduction to Moccasin
How to create an ERC-20
How to test Python code and Vyper smart contract
How to deploy Vyper smart contracts on ZKsync using Moccasin
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on June 10, 2025