Writing tests for your Solidity smart contract

An essential introduction to Writing Basic Foundry Tests for the FundMe Contract - Master the basics of Foundry testing by configuring test files, leveraging `forge-std/Test`, and utilizing the `setUp` function. Learn to deploy contracts under test, write fundamental assertions with `assertEq`, and debug effectively using `console.log`.

Solidity Developer

Foundry Fundamentals

1. Introduction
A comprehensive guide to Foundry Fund Me - Introduction - Rebuild the Fund Me project within the professional Foundry framework, covering essential smart contract engineering practices. Learn project structuring, advanced Solidity, deployment scripting, robust testing, gas optimization, and version control with GitHub. Duration: 3min
2. Fund Me project setup
A foundational guide to Setting Up Your Foundry Fund Me Project - Learn how to create a new project directory and initialize it with the standard Foundry structure using `forge init`. Get familiar with the core folders (`src`, `test`, `script`) and the default example contract. Duration: 2min
3. Introduction to smart contracts testing
A foundational guide to Understanding Smart Contract Testing with Foundry - Learn the essential structure for Foundry tests, including the `test` directory and `*.t.sol` naming convention. Discover how to write basic test functions using `setUp` and `assertEq`, and execute them via the `forge test` command. Duration: 2min
4. Finishing the setup
A practical transition guide to Setting Up FundMe in Foundry: Imports and Dependencies - Learn to clean a new Foundry project and import existing Solidity code from Remix. Resolve common compilation errors by installing dependencies with `forge install` and configuring import remappings. Duration: 7min
5. Writing tests for your Solidity smart contract
An essential introduction to Writing Basic Foundry Tests for the FundMe Contract - Master the basics of Foundry testing by configuring test files, leveraging `forge-std/Test`, and utilizing the `setUp` function. Learn to deploy contracts under test, write fundamental assertions with `assertEq`, and debug effectively using `console.log`. Duration: 9min
6. Quiz 6 Quiz
Questions: 12
7. Debug your Solidity tests
A context-focused guide to Debugging Foundry Tests: Understanding `msg.sender` and Contract Ownership - Uncover why `msg.sender` behaves differently during contract deployment in `setUp` versus within test functions. Master using `address(this)` to correctly verify owner assignment in Foundry tests. Duration: 3min
8. Advanced deploy scripts
A scripting-focused guide to Creating a Basic Foundry Deployment Script for FundMe - Learn the essential structure of a Foundry deployment script (.s.sol). Deploy the FundMe contract using the run() function and vm.startBroadcast/vm.stopBroadcast cheatcodes. Duration: 3min
9. Running tests on chains forks
A hands-on guide to Testing External Contracts with Foundry Forking - Discover why local tests struggle with external calls (e.g., Chainlink) and master Foundry's forking. Use `forge test --fork-url` to simulate live network state for realistic interaction testing. Duration: 9min
10. Refactoring your tests
A modularity-focused guide to Refactoring FundMe for Modularity and Test Consistency - Eliminate hardcoded Chainlink price feed addresses to make your contracts network-agnostic. Align your Foundry test environment with deployment scripts for improved consistency and easier maintenance. Duration: 7min
11. Deploy a mock priceFeed
A portability-enhancing guide to Refactoring for Multi-Chain Deployments: The Helper Config Pattern - Eliminate hardcoded network addresses using Foundry's Helper Config pattern and `block.chainid`. Make your deployment scripts and tests seamlessly adapt to different blockchains like Sepolia, Mainnet, or local networks. Duration: 13min
12. Refactoring the mock smart contract
A testing-centric guide to Refactoring HelperConfig for Local Development with Mocks - Adapt your configuration contract to deploy mock Chainlink dependencies using Foundry Scripting. Enable reliable local development and testing by simulating external contracts on blank networks like Anvil. Duration: 4min
13. Quiz 13 Quiz
Questions: 10
14. How to refactor magic number
A code-quality guide to Eliminating Magic Numbers in Solidity - Learn to identify and replace ambiguous hardcoded values ("magic numbers") with descriptive constants. Improve your smart contract's readability, maintainability, and reduce the risk of errors. Duration: 2min
15. Refactoring the mock smart contract pt.2
A network-agnostic technique for Refactoring Fund Me: Advanced Mocking in Foundry - Make your `HelperConfig` deploy mocks idempotently, only when needed on local networks using the `address(0)` check. Streamline testing across environments and drastically speed up local test runs. Duration: 4min
16. Foundry tests cheatcodes
A practical guide to Improving FundMe Tests with Foundry Cheatcodes - Learn to boost test coverage by specifically testing failure conditions and state updates. Leverage Foundry cheatcodes like `vm.expectRevert`, `vm.prank`, and `vm.deal` to simulate diverse scenarios. Duration: 13min
17. Adding more coverage to the tests
A practical guide to Writing Robust Foundry Tests - Learn to verify core contract logic like funder tracking, access control (`vm.expectRevert`), and single/multi-funder withdrawals using cheatcodes and the AAA pattern. Improve test structure with modifiers and ensure thoroughness with `forge coverage`. Duration: 15min
18. Introduction to Foundry Chisel
An interactive introduction to Interactive Solidity with Foundry Chisel - Explore Foundry's `chisel`, a powerful interactive Solidity REPL that runs directly in your terminal. Learn to quickly test, debug, and experiment with small code snippets without disrupting your development workflow. Duration: 1min
19. Calculate Withdraw gas costs
A gas-focused guide to Measuring and Understanding Gas Costs in Foundry - Learn to benchmark your function's gas consumption using `forge snapshot` to establish optimization baselines. Understand how Foundry's default zero gas price impacts tests and how to simulate real transaction costs when needed. Duration: 5min
20. Introduction to Storage optimization
A gas-focused guide to Solidity Storage Layout and Gas Optimization - Learn how Solidity arranges state variables in storage slots and why this impacts gas costs. Discover how constants, immutables, and dynamic types are handled, and use Foundry tools to inspect the layout. Duration: 10min
21. Optimise the withdraw function gas costs
A gas-saving guide to Optimizing FundMe Withdraw for Gas Efficiency - Reduce transaction costs by caching storage reads like array lengths in memory variables, avoiding expensive `SLOAD`s within loops. Learn to verify gas savings using Foundry's `forge snapshot` tool. Duration: 8min
22. Quiz 22 Quiz
Questions: 13
23. Create integration tests
A project-finishing guide to Finalizing Your Foundry Fund Me Project - Learn to create professional READMEs and build interaction scripts using `foundry-devops`. Implement integration tests to validate the end-to-end deployment and user interaction flow. Duration: 15min
24. Automate your smart contracts actions - Makefile
A workflow-boosting guide to Streamlining Your Foundry Workflow with Makefiles - Learn to automate tedious `forge script` commands for deployment and verification using Makefiles. Create simple shortcuts to save time and eliminate errors in your Foundry development process. Duration: 8min
25. Zksync Devops
An essential guide to Robust Foundry Testing for EVM and zkSync - Master conditional testing techniques for contracts targeting both EVM and zkSync environments using Foundry. Leverage `cyfrin/foundry-devops` helpers like `skipZkSync` and `onlyZkSync` to ensure tests run appropriately based on the execution context. Duration: 15min
26. Pushing to Github
A step-by-step guide to Pushing Your Foundry Smart Contract Project to GitHub - Learn to initialize a Git repository for your Foundry project, manage sensitive files with `.gitignore`, and push your code to GitHub. Share your work, collaborate, and build your Web3 portfolio effectively. Duration: 16min
27. Section recap
A comprehensive recap to Foundry Fund Me Recap - Solidify your understanding of professional smart contract development with Foundry, covering project structure, modular code, scripting, advanced testing strategies, and workflow automation. Review key concepts like Makefiles, gas optimization, and Git best practices before moving forward. Duration: 2min

Course Overview

About the course

What you'll learn

Foundryup, Foundry Forge, and Anvil

Blockchain Oracles

How to create local Blockchain testnets

How to verify a smart contract

How to write and run smart contract tests

Course Description

Who is this course for?

  • Software engineers
  • Web3 developers
  • Blockchain security researchers

Potential Careers

Security researcher

$49,999 - $120,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)

Smart Contract Auditor

$100,000 - $200,000 (avg. salary)

Meet your instructors

Patrick Collins

Patrick Collins

Founder at Cyfrin

Web3 engineer, educator, and Cyfrin co-founder. Patrick's smart contract development and security courses have helped hundreds of thousands of engineers kickstarting their careers into web3.

Guest lecturers:

Richard Gottleber

Richard Gottleber

Developer relations at Chainlink

Vasiliy Gualoto

Vasiliy Gualoto

Developer relations at ThirdWeb

Last updated on May 27, 2025