Skip to content

Instantly share code, notes, and snippets.

@tanopwan
Last active October 8, 2022 08:05
Show Gist options
  • Save tanopwan/a758451ebc78c309277a2e76a3135f4f to your computer and use it in GitHub Desktop.
Save tanopwan/a758451ebc78c309277a2e76a3135f4f to your computer and use it in GitHub Desktop.
Foundry Workshop

Foundry Installation

https://book.getfoundry.sh/getting-started/installation

curl -L https://foundry.paradigm.xyz | bash

This will download foundryup. Then install Foundry by running

foundryup

Install Dependency

forge install @openzeppelin/openzeppelin-contracts
forge install dapphub/ds-test
forge install foundry-rs/forge-std

Fork Test

forge test --fork-url https://bsc-dataseed1.binance.org/ --match-path 'test/fork/*.t.sol' -vv
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract Certificate is ERC721 {
constructor() ERC721("Certificate", "CERT") {}
function mint(address to, uint256 tokenId) public {
_mint(to, tokenId);
}
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.9;
import "../contracts/Certificate.sol";
import "../lib/ds-test/src/test.sol";
contract Certificate_Test is DSTest {
Certificate certificate;
function setUp() external {
certificate = new Certificate();
}
function testName() external {
string memory name = certificate.name();
emit log_named_string("name", name);
}
function testMint() external {
certificate.mint(address(this), 1);
assertEq(certificate.balanceOf(address(this)), 1);
}
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.9;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "../../lib/ds-test/src/test.sol";
import {Vm} from "../../lib/forge-std/src/vm.sol";
contract Fork_Test is DSTest {
Vm internal constant vm = Vm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
ERC20 busd = ERC20(0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56);
function testBalance() external {
uint256 bal = busd.balanceOf(0x8894E0a0c962CB723c1976a4421c95949bE2D4E3);
emit log_named_uint("bal", bal);
// transfer
// expect balance after transfer
}
}
[profile.default]
src = 'contracts'
out = 'out'
libs = ['lib']
test = 'test'
@openzeppelin/=lib/openzeppelin-contracts/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment