1/5
## Testing for Reverts We will learn how to test for reverts in our smart contracts. When we test our smart contracts, we also want to test that they revert correctly. For example, if somebody calls our fund function without enough money, we should expect this to actually revert. So, how do we test when a function reverts? We can use the `boa.reverts` method. We can add this code to our test file: ```python def test_fund_fails_without_enough_eth(coffee): with boa.reverts(): coffee.fund() ``` This will test that the `fund` function reverts when called without enough ETH. We can even check the exact revert message. We can add this code to our test file: ```python def test_fund_fails_without_enough_eth(coffee): with boa.reverts("You must spend more ETH!"): coffee.fund() ``` This will test that the `fund` function reverts with the message "You must spend more ETH!". To run a specific test, we can use the following command: ```bash mox test -k test_fund_fails_without_enough_eth ``` This will only run the test called `test_fund_fails_without_enough_eth`.
A practical guide to testing for reverts in Vyper smart contracts - The lesson covers testing for reverts using Boa, a Python testing library for Vyper contracts. It demonstrates how to test for reverts using the `with boa.reverts` function.
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