Skip to content

Commit e8da37a

Browse files
committed
First Commit
0 parents  commit e8da37a

15 files changed

+829
-0
lines changed

.gas-snapshot

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FundMeTest:testAddsFunderToArrayOfFunder() (gas: 100198)
2+
FundMeTest:testFundFailedWithoutEnoughEth() (gas: 23094)
3+
FundMeTest:testFundUpdatesFundedDataStructure() (gas: 99814)
4+
FundMeTest:testMinimumDollarIsFive() (gas: 8445)
5+
FundMeTest:testOnlyOwnerCanWithdraw() (gas: 100079)
6+
FundMeTest:testOwnerIsMsgSender() (gas: 12526)
7+
FundMeTest:testPriceFeedVersionIsAccurate() (gas: 13665)
8+
FundMeTest:testWithDrawWithASingleFunder() (gas: 85743)
9+
FundMeTest:testWithdrawFromMultipleFunders() (gas: 681272)
10+
FundMeTest:testWithdrawFromMultipleFundersCheaper() (gas: 680800)
11+
12+
# Like 400 gas saved with the cheaper version

.github/workflows/test.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: test
2+
3+
on: workflow_dispatch
4+
5+
env:
6+
FOUNDRY_PROFILE: ci
7+
8+
jobs:
9+
check:
10+
strategy:
11+
fail-fast: true
12+
13+
name: Foundry project
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
submodules: recursive
19+
20+
- name: Install Foundry
21+
uses: foundry-rs/foundry-toolchain@v1
22+
with:
23+
version: nightly
24+
25+
- name: Run Forge build
26+
run: |
27+
forge --version
28+
forge build --sizes
29+
id: build
30+
31+
- name: Run Forge tests
32+
run: |
33+
forge test -vvv
34+
id: test

.gitignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Compiler files
2+
cache/
3+
out/
4+
5+
# Ignores development broadcast logs
6+
!/broadcast
7+
/broadcast/*/31337/
8+
/broadcast/**/dry-run/
9+
10+
# Docs
11+
docs/
12+
13+
# Dotenv file
14+
.env
15+
16+
broadcast/
17+
lib/
18+
19+

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-include .env
2+
3+
build:; forge build
4+
5+
deploy-sepolia:
6+
forge script script/DeployFundMe.s.sol:DeployFundMe --rpc-url $(SEPOLIA_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast --verify --etherscan-api-key $(ETHERSCAN_API_KEY) -vvvv
7+

README.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
## Foundry
2+
3+
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**
4+
5+
Foundry consists of:
6+
7+
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
8+
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
9+
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
10+
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.
11+
12+
## Documentation
13+
14+
https://book.getfoundry.sh/
15+
16+
## Usage
17+
18+
### Build
19+
20+
```shell
21+
$ forge build
22+
```
23+
24+
### Test
25+
26+
```shell
27+
$ forge test
28+
```
29+
30+
### Format
31+
32+
```shell
33+
$ forge fmt
34+
```
35+
36+
### Gas Snapshots
37+
38+
```shell
39+
$ forge snapshot
40+
```
41+
42+
### Anvil
43+
44+
```shell
45+
$ anvil
46+
```
47+
48+
### Deploy
49+
50+
```shell
51+
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
52+
```
53+
54+
### Cast
55+
56+
```shell
57+
$ cast <subcommand>
58+
```
59+
60+
### Help
61+
62+
```shell
63+
$ forge --help
64+
$ anvil --help
65+
$ cast --help
66+
```
67+
68+
69+
### How To Proper README
70+
71+
1. Proper README
72+
2. Integration tests
73+
2. Programatic Verification

Revision1.txt

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
1220 forge install smartcontractkit/[email protected] --no-commit
2+
1221 forge build
3+
1222 clear
4+
1223 forge test
5+
1224 clear
6+
1225 forge test
7+
1226 forge test -vv
8+
1227 forge test -vvv
9+
1228 forge test -v
10+
1229 clear
11+
1230 ls
12+
1231 clear
13+
1232 lss
14+
1233 ls
15+
1234 clear
16+
1235 ls
17+
1236 cd foundryCourse/
18+
1237 cd foundry-simple-storage-f233/
19+
1238 clear
20+
1239 echo $PRIVATE_KEY
21+
1240 source .env
22+
1241 echo $PRIVATE_KEY
23+
1242 echo $RPC_URL
24+
1243 clear
25+
1244 cat wallet list
26+
1245 cast wallet list
27+
1246 where defaultkey
28+
1247 which defaultkey
29+
1248 cast wallet address defaultkey
30+
1249 code .
31+
1250 ext
32+
1251 exit
33+
1252 cast send 0x0e62a8d35Eea27EBDb4A1949b0F774Bb9b9Dd4CE "store(uint256)" 123
34+
1253 cast send 0x0e62a8d35Eea27EBDb4A1949b0F774Bb9b9Dd4CE "store(uint256)" 123 --rpc-url $RPC_URL --private-key $PRIVATE_KEY
35+
1254 source .env
36+
1255 cast send 0x0e62a8d35Eea27EBDb4A1949b0F774Bb9b9Dd4CE "store(uint256)" 123 --rpc-url $RPC_URL --private-key $PRIVATE_KEY
37+
1256 clear
38+
1257 ls
39+
1258 clear
40+
1259 cd ..
41+
1260 mkdir foundry-fund-me-f23
42+
1261 code foundry-fund-me-f23/
43+
1262 exit
44+
1263 clear
45+
1264 forge test -vv
46+
1265 clear
47+
1266 forge test -vv
48+
1267 clear
49+
1268 forge script script/DeployFundMe.s.sol
50+
1269 clear
51+
1270 forge test -vvv
52+
1271 forge script script/DeployFundMe.s.sol
53+
1272 clear
54+
1273 forge script script/DeployFundMe.s.sol
55+
1274 forge test
56+
1275 forge script script/DeployFundMe.s.sol
57+
1276 forge test
58+
1277 clear
59+
1278 forge test -m testPriceFeedVersionIsAccurate
60+
1279 forge test --help
61+
1280 forge test testPriceFeedVersionIsAccurate
62+
1281 forge test -m testPriceFeedVersionIsAccurate -vv
63+
1282 forge test
64+
1283 forge test --help
65+
1284 forge test --match-test testPriceFeedVersionIsAccurate
66+
1285 clear
67+
1286 forge test --match-test testPriceFeedVersionIsAccurate -vvv
68+
1287 clear
69+
1288 ls
70+
1289 cler
71+
1290 clear
72+
1291 source .env
73+
1292 echo $SEPOLIA_RPC_URL
74+
1293 forge test --match-test testPriceFeedVersionIsAccurate -vvv --fork-url $SEPOLIA_RPC_URL
75+
1294 clear
76+
1295 ls
77+
1296 clear
78+
1297 forge coverage --fork-url $SEPOLIA_RPC_URL
79+
1298 clear
80+
1299 ls
81+
1300 clear
82+
1301 forge test --fork-url $SEPOLIA_RPC_URL
83+
1302 clear
84+
1303 forge test --fork-url $SEPOLIA_RPC_URL
85+
1304 clear
86+
1305 forge test
87+
1306 clear
88+
1307 forge test --fork-url $SE
89+
1308 forge test --fork-url $SEPOLIA_RPC_URL
90+
1309 source .env
91+
1310 echo $MAINNET_RPC_URL
92+
1311 forge test --fork-url $MAINNET_RPC_URL
93+
1312 clear
94+
1313 echo $history
95+
1314 echo history
96+
1315 echo "$history"
97+
1316 clear
98+
1317 history
99+
1318 history | tail 100 >> Revision1.txt
100+
1319 history | tail -100 >> Revision1.txt
101+
102+
103+
1320 forge test match-test testAddsFunderToArrayOfFunders
104+
1321 forge test --match-test testAddsFunderToArrayOfFunders
105+
1322 forge test --match-test testAddsFunderToArrayOFunders
106+
1323 forge test --match-test testAddsFunderToArrayOfFunder
107+
1324 clear
108+
1325 forge test --match-test testAddsFunderToArrayOfFunder
109+
1326 clear
110+
1327 forge test --match-test testOnlyOwnerCanWithdraw
111+
1328 clear
112+
1329 forge test --match-test testWithDrawWithASingleFunder
113+
1330 clear
114+
1331 forge test --match-test testWithdrawFromMultipleFunders
115+
1332 clear
116+
1333 forge coverage
117+
1334 cd foundryCourse/foundry-fund-me-f23/
118+
1335 clear
119+
1336 code .
120+
1337 chisel
121+
1338 clear
122+
1339 forge snapshot --match-test testWithdrawFromMultipleFunders
123+
1340 history
124+
1341 history | tail -30 >> Revision1.txt
125+
1342 clear
126+
1343 forge test --match-test testWithDrawWithASingleFunder
127+
1344 clear
128+
1345 forge test --match-test testWithDrawWithASingleFunder -vvv
129+
1346 clear
130+
1347 forge inspect FundMe storageLayout
131+
1348 cat Revision1.txt
132+
1349 history | tail -30 >> Revision1.txt
133+
134+

foundry.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[profile.default]
2+
3+
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-optionssrc = "src"
4+
out = "out"
5+
libs = ["lib"]
6+
remappings = [
7+
"@chainlink/contracts/=lib/chainlink-brownie-contracts/contracts/",
8+
]
9+
ffi = true

script/DeployFundMe.s.sol

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
2+
pragma solidity ^0.8.19;
3+
4+
import {Script} from "forge-std/Script.sol";
5+
import {FundMe} from "../src/FundMe.sol";
6+
import {HelperConfig} from "./HelperConfig.s.sol";
7+
8+
contract DeployFundMe is Script {
9+
function run() external returns (FundMe) {
10+
//Anything before startBroadcast => not a real txn and doesn't require gas
11+
HelperConfig helperConfig = new HelperConfig();
12+
address ethUsdPriceFeed = helperConfig.activeNetworkConfig();
13+
14+
vm.startBroadcast();
15+
16+
// Deploy the MockV3Aggregator first
17+
// MockV3Aggregator mockPriceFeed = new MockV3Aggregator(2000 * 10 ** 8);
18+
19+
// Then deploy FundMe, passing the address of the mock price feed
20+
FundMe fundMe = new FundMe(ethUsdPriceFeed);
21+
vm.stopBroadcast();
22+
23+
return fundMe;
24+
}
25+
}

script/HelperConfig.s.sol

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// 1. Deploy mocks when we are on a local anvil chain
2+
// 2. Keep track of contract addresses across different chains
3+
4+
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
5+
pragma solidity ^0.8.19;
6+
7+
import {Script} from "forge-std/Script.sol";
8+
import {MockV3Aggregator} from "../test/mocks/MockV3Aggregator.sol";
9+
10+
contract HelperConfig is Script {
11+
// If we are on a local anvil, we deploy mocks
12+
//Otherwise, grab the existing addresses from the live network
13+
14+
NetworkConfig public activeNetworkConfig;
15+
16+
struct NetworkConfig {
17+
address priceFeed; //ETH/USD price feed address
18+
}
19+
20+
uint8 public constant DECIMALS = 8;
21+
int256 public constant INITIAL_PRICE = 2000e8;
22+
23+
constructor() {
24+
if (block.chainid == 11155111) {
25+
//chainlist.org for chainid's
26+
activeNetworkConfig = getSepoliaEthConfig();
27+
} else if (block.chainid == 1) {
28+
activeNetworkConfig = getMainnetEthConfig();
29+
} else {
30+
activeNetworkConfig = getOrCreateAnvilEthConfig();
31+
}
32+
}
33+
34+
function getSepoliaEthConfig() public pure returns (NetworkConfig memory) {
35+
//price feed address
36+
NetworkConfig memory sepoliaConfig = NetworkConfig({priceFeed: 0x694AA1769357215DE4FAC081bf1f309aDC325306});
37+
return sepoliaConfig;
38+
}
39+
40+
function getMainnetEthConfig() public pure returns (NetworkConfig memory) {
41+
//price feed address
42+
NetworkConfig memory mainnetConfig = NetworkConfig({priceFeed: 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419});
43+
return mainnetConfig;
44+
}
45+
46+
function getOrCreateAnvilEthConfig() public returns (NetworkConfig memory) {
47+
if (activeNetworkConfig.priceFeed != address(0)) {
48+
return activeNetworkConfig;
49+
}
50+
//Price feed address
51+
//1.Deploy the mocks
52+
//2. Return the mock address
53+
vm.startBroadcast();
54+
MockV3Aggregator mockPriceFeed = new MockV3Aggregator(DECIMALS, INITIAL_PRICE);
55+
vm.stopBroadcast();
56+
57+
NetworkConfig memory anvilConfig = NetworkConfig({priceFeed: address(mockPriceFeed)});
58+
return anvilConfig;
59+
}
60+
}

0 commit comments

Comments
 (0)