This repo demonstrates a streamlined workflow for testing Vyper smart contracts using Foundry’s Solidity test framework (t.sol).
By combining Moccasin for Vyper scaffolding and Foundry for testing, you get the best of both worlds — clean Vyper code with powerful, fast Solidity-based tests.
Testing Vyper contracts directly in Foundry:
- ✅ Avoids writing separate Python test suites.
- ✅ Lets you use Foundry’s cheatcodes (
deployCode,prank,deal, etc.). - ✅ Integrates seamlessly with Solidity tooling, coverage, and CI pipelines.
- ✅ Speeds up iteration — deploy and test in-memory without spinning up external chains.
-
Initialize a Moccasin template
mox init
-
Force initialize a Foundry template in the same directory
forge init --force
-
Write your Vyper contracts
- Place .vy files in src/ (e.g., src/Counter.vy).
- Keep them clean and idiomatic Vyper.
-
Write Solidity interfaces for your Vyper contracts
- Example: src/ICounter.sol (This matches the ABI of your Vyper contract so Solidity tests can call it.)
-
(Optional) Write a deploy script
- Useful for deploying to a live chain, but not required for Foundry tests.
-
Write Foundry tests in the test folder
- Use deployCode("Counter.vy") to deploy your Vyper contract inside the test environment.
for instance:
contract CounterTest is Test { ICounter public counter; function setUp() public { counter = ICounter(deployCode("Counter.vy")); } function test_SetNumber() public { counter.set_number(42); assertEq(counter.number(), 42); } }
forge test -vvvKeep complex types (DynArray, HashMap) private in Vyper and write explicit getters to avoid ABI mismatches