Foundry: Gen 2 of Ethereum Tooling

Smart Contract Development With the Forge Tool

A Simple Example

contract ERC20 { address immutable owner; mapping(address => uint256) public balanceOf; constructor() { owner = msg.sender; } function mint(address user, uint256 amount) external { require(msg.sender == owner, "Only owner can mint"); balanceOf[user] += amount; } function transfer(address to, uint amount) external { balanceOf[msg.sender] -= amount; balanceOf[to] += amount; } // Other functions... }
contract ERC20Test is Test { ERC20 token; // Contract under test address Alice = makeAddr("Alice"); address Bob = makeAddr("Bob"); address Eve = makeAddr("Eve"); function setUp() public { token = new ERC20(); token.mint(Alice, 10 ether); token.mint(Bob, 20 ether); token.mint(Eve, 30 ether); } function testTransfer(address from, address to, uint256 amount) public { vm.assume(token.balanceOf(from) >= amount); uint256 preBalanceFrom = token.balanceOf(from); uint256 preBalanceTo = token.balanceOf(to); vm.prank(from); token.transfer(to, amount); if(from == to) { assertEq(token.balanceOf(from), preBalanceFrom); assertEq(token.balanceOf(to), preBalanceTo); } else { assertEq(token.balanceOf(from), preBalanceFrom - amount); assertEq(token.balanceOf(to), preBalanceTo + amount); } } }

Running Tests Against Mainnet

Why should you be using Foundry?

Alchemix and Foundry Tooling

A Word from the Alchemix Team

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Runtime Verification

Runtime Verification

157 Followers

Runtime Verification Inc. is a technology startup providing cutting edge formal verification tools and services for aerospace, automotive, and the blockchain.