1/5
## Tests We've deployed our contract, and now we're ready to write some tests. We're not going to go in-depth with writing tests in this video, but we'll show a simple test case to get you started. In our project, we've created a `tests` folder. We can create a new file here called `test_token.py` and start to write our test. First, we'll import the `deploy` function from our `deploy.py` file: ```python from script.deploy import deploy, INITIAL_SUPPLY ``` Next, we'll create a test function: ```python def test_token_supply(): snek_token = deploy() assert snek_token.total_supply() == INITIAL_SUPPLY ``` The `test_token_supply` function will test the total supply of our token. We first deploy our token using the `deploy` function and store the contract in the `snek_token` variable. Then, we assert that the total supply is equal to `INITIAL_SUPPLY`, which we also imported from our `deploy.py` file. To run our test, we can open a terminal and run the following command: ```bash mox test ``` The test will run and pass, since we've deployed our token with an initial supply of 1000. We can write many more tests to test different functionality of our token. We can also create separate tests for our other functions like `mint`, `transfer`, and `burn`. The most important takeaway from this video is that we should be writing tests for our smart contracts to ensure that they function correctly.
A simple guide to writing a test for a Vyper smart contract using Python and Vyper. The lesson covers the basics of writing unit tests, testing total supply, and verifying the results using the "mox" test command.
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 April 21, 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 April 21, 2025
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar