Skip to content

Commit cd522f7

Browse files
author
Alor
committed
our first commit!
1 parent 0f3b21b commit cd522f7

File tree

7 files changed

+84
-6
lines changed

7 files changed

+84
-6
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ docs/
1212

1313
# Dotenv file
1414
.env
15+
16+
broadcast/
17+
18+
lib/

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
url = https://github.com/smartcontractkit/chainlink-brownie-contracts
77
[submodule "lib/foundry-devops"]
88
path = lib/foundry-devops
9-
url = https://github.com/ChainAccelOrg/foundry-devops
9+
url = https://github.com/Cyfrin/foundry-devops

Makefile

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

foundry.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ src = "src"
33
out = "out"
44
libs = ["lib"]
55
remappings = ["@chainlink/=lib/chainlink-brownie-contracts/"]
6+
ffi = true
7+
68

79
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

script/Interactions.s.sol

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,45 @@
55

66
pragma solidity ^0.8.18;
77

8-
import {Script} from "forge-std/Script.sol";
8+
import {Script, console} from "forge-std/Script.sol";
9+
import {DevOpsTools} from "foundry-devops/src/DevOpsTools.sol";
10+
import {FundMe} from "../src/FundMe.sol";
911

1012
contract FundFundMe is Script {
11-
function run() external {}
13+
uint256 constant SEND_VALUE = 0.01 ether;
14+
15+
function fundFundMe(address mostRecentlyDeployed) public {
16+
vm.startBroadcast();
17+
FundMe(payable(mostRecentlyDeployed)).fund{value: SEND_VALUE}();
18+
vm.stopBroadcast();
19+
console.log("Funded FundMe with %s", SEND_VALUE);
20+
}
21+
22+
function run() external {
23+
address mostRecentlyDeployed = DevOpsTools.get_most_recent_deployment(
24+
"FundMe",
25+
block.chainid
26+
);
27+
vm.startBroadcast();
28+
fundFundMe(mostRecentlyDeployed);
29+
vm.stopBroadcast();
30+
}
1231
}
1332

14-
contract WithdrawFundMe is Script {}
33+
contract WithdrawFundMe is Script {
34+
function withdrawFundMe(address mostRecentlyDeployed) public {
35+
vm.startBroadcast();
36+
FundMe(payable(mostRecentlyDeployed)).withdraw();
37+
vm.stopBroadcast();
38+
}
39+
40+
function run() external {
41+
address mostRecentlyDeployed = DevOpsTools.get_most_recent_deployment(
42+
"FundMe",
43+
block.chainid
44+
);
45+
vm.startBroadcast();
46+
withdrawFundMe(mostRecentlyDeployed);
47+
vm.stopBroadcast();
48+
}
49+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.18;
4+
import {Test, console} from "forge-std/Test.sol";
5+
import {FundMe} from "../../src/FundMe.sol";
6+
import {DeployFundMe} from "../../script/DeployFundMe.s.sol";
7+
import {FundFundMe, WithdrawFundMe} from "../../script/Interactions.s.sol";
8+
9+
contract InteractionsTest is Test {
10+
FundMe fundMe;
11+
12+
address USER = makeAddr("user");
13+
uint256 constant SEND_VALUE = 0.1 ether;
14+
uint256 constant STARTING_BALANCE = 10 ether;
15+
uint256 constant GAS_PRICE = 1;
16+
17+
function setUp() external {
18+
DeployFundMe deployFundMe = new DeployFundMe();
19+
fundMe = deployFundMe.run();
20+
vm.deal(USER, STARTING_BALANCE);
21+
}
22+
23+
function testUserCanFundInteractions() external {
24+
FundFundMe fundFundMe = new FundFundMe();
25+
fundFundMe.fundFundMe(address(fundMe));
26+
27+
WithdrawFundMe withdrawFundMe = new WithdrawFundMe();
28+
withdrawFundMe.withdrawFundMe(address(fundMe));
29+
30+
assert(address(fundMe).balance == 0);
31+
}
32+
}

test/FundMeTest.t.sol renamed to test/unit/FundMeTest.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
pragma solidity ^0.8.18;
44
import {Test, console} from "forge-std/Test.sol";
5-
import {FundMe} from "../src/FundMe.sol";
6-
import {DeployFundMe} from "../script/DeployFundMe.s.sol";
5+
import {FundMe} from "../../src/FundMe.sol";
6+
import {DeployFundMe} from "../../script/DeployFundMe.s.sol";
77

88
contract FundMeTest is Test {
99
address USER = makeAddr("user");

0 commit comments

Comments
 (0)