Skip to content

Commit

Permalink
Integration Tests Added and Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhasLingam committed Sep 18, 2024
1 parent e57b780 commit 1c91f09
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 35 deletions.
11 changes: 11 additions & 0 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
TestFundMeContract:testFundFailsWithLessEthSent() (gas: 27782)
TestFundMeContract:testFundIsGettingUpdatedWithMultipleUsers() (gas: 165488)
TestFundMeContract:testFundUpdatesFundedDataStructures() (gas: 104606)
TestFundMeContract:testFundersAddedToArray() (gas: 165497)
TestFundMeContract:testMinimumUSD() (gas: 8400)
TestFundMeContract:testOwnerMsgSender() (gas: 8588)
TestFundMeContract:testPriceFeedVersion() (gas: 13622)
TestFundMeContract:testTotalBalance() (gas: 8530)
TestFundMeContract:testWithdrawWithMultipleUsers() (gas: 507119)
TestFundMeContract:testWithdrawWithMultipleUsersCheaper() (gas: 506359)
TestFundMeContract:testWithdrawWithSingleFunder() (gas: 89007)
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "lib/chainlink-brownie-contracts"]
path = lib/chainlink-brownie-contracts
url = https://github.com/smartcontractkit/chainlink-brownie-contracts
[submodule "lib/foundry-devops"]
path = lib/foundry-devops
url = https://github.com/Cyfrin/foundry-devops
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-include .env

build:; forge build

deploy-sepolia:
forge script script/FundMe.s.sol --rpc-url $(SEPOLIA_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast --verify --etherscan-api-key $(ETHERSCAN_API_KEY) --force -vvvv


62 changes: 32 additions & 30 deletions broadcast/FundMe.s.sol/11155111/run-latest.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
{
"transactions": [
{
"hash": "0x0d7a9bb846b47826dc9f0cacc2cdbe807fbcfa12578f2ddddb59e3a8a68b4c8e",
"hash": "0x251eef868774091e0b6b9ca5aeab391ca85ec5a4bd2ee1014c4ddcff8b988cc0",
"transactionType": "CREATE2",
"contractName": "PriceConverter",
"contractAddress": "0x0479621f4d4b5b65fe8aa759cc02abfa84c38241",
"contractAddress": "0x00b6a8090afa0bfa1990b5c042483f783754472a",
"function": null,
"arguments": null,
"transaction": {
"from": "0x49f1d1f19fc03bba72589bbf621208bca6a77c00",
"to": "0x4e59b44847b379578588920ca78fbf26c0b4956c",
"gas": "0x451fc",
"input": "0x0000000000000000000000000000000000000000000000000000000000000000610287610039600b82828239805160001a607314602c57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100405760003560e01c806398d5fdca14610045578063d2d265f01461005f575b600080fd5b61004d610072565b60405190815260200160405180910390f35b61004d61006d366004610142565b61010e565b60008073feeff7c3fb57d18c5c6cdd71e45d2d0b4f9377bf90506000816001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa1580156100cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100f0919061017a565b505050915050806402540be40061010791906101e2565b9250505090565b600080610119610072565b90506000670de0b6b3a76400006101308584610218565b61013a919061022f565b949350505050565b60006020828403121561015457600080fd5b5035919050565b805169ffffffffffffffffffff8116811461017557600080fd5b919050565b600080600080600060a0868803121561019257600080fd5b61019b8661015b565b602087015160408801516060890151929750909550935091506101c06080870161015b565b90509295509295909350565b634e487b7160e01b600052601160045260246000fd5b80820260008212600160ff1b841416156101fe576101fe6101cc565b8181058314821517610212576102126101cc565b92915050565b8082028115828204841417610212576102126101cc565b60008261024c57634e487b7160e01b600052601260045260246000fd5b50049056fea26469706673582212203e930d5b579b4b9cf3f70a6050ba670d88e312df358b2166b8795dd50beb569f64736f6c634300081b0033",
"nonce": "0x18",
"gas": "0x40761",
"input": "0x000000000000000000000000000000000000000000000000000000000000000061027c610039600b82828239805160001a607314602c57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100355760003560e01c806318d5b20d1461003a575b600080fd5b61004d61004836600461011a565b61005f565b60405190815260200160405180910390f35b60008061006b83610097565b90506000670de0b6b3a7640000610082868461016c565b61008c9190610183565b925050505b92915050565b600080826001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa1580156100d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100fc91906101c4565b505050915050806402540be4006101139190610216565b9392505050565b6000806040838503121561012d57600080fd5b8235915060208301356001600160a01b038116811461014b57600080fd5b809150509250929050565b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761009157610091610156565b6000826101a057634e487b7160e01b600052601260045260246000fd5b500490565b805169ffffffffffffffffffff811681146101bf57600080fd5b919050565b600080600080600060a086880312156101dc57600080fd5b6101e5866101a5565b6020870151604088015160608901519297509095509350915061020a608087016101a5565b90509295509295909350565b80820260008212600160ff1b8414161561023257610232610156565b81810583148215176100915761009161015656fea2646970667358221220aecccec4f07318147454f1f5d4730d9add37baa10ace509de552c4f0f451805964736f6c634300081b0033",
"nonce": "0x1f",
"chainId": "0xaa36a7"
},
"additionalContracts": [],
"isFixedGasLimit": false
},
{
"hash": "0x12f9d017ab10ee522cc41a7f14a6ef94f787ec1bb13e219f0c75c85aadca07dc",
"hash": "0x769b2620564525be40ce869413cd56d1514a6b18f4d448546c8704e87000e87f",
"transactionType": "CREATE",
"contractName": "FundMe",
"contractAddress": "0x6186f5058668ed52761ebe48baabce308fd85b2e",
"contractAddress": "0xec84bd23f237f101470d029f67b8796e5b34c950",
"function": null,
"arguments": null,
"arguments": [
"0x694AA1769357215DE4FAC081bf1f309aDC325306"
],
"transaction": {
"from": "0x49f1d1f19fc03bba72589bbf621208bca6a77c00",
"gas": "0x71268",
"gas": "0x9c440",
"value": "0x0",
"input": "0x60a0604052348015600f57600080fd5b503360805260805161057f6100356000396000818160fe015261028a015261057f6000f3fe6080604052600436106100595760003560e01c80633430a88c146100705780633ccfd60b1461009f57806381e729c1146100b4578063b60d428814610068578063dba6335f146100ec578063deaf2cf01461012057610068565b366100685761006661014d565b005b61006661014d565b34801561007c57600080fd5b5061008c674563918244f4000081565b6040519081526020015b60405180910390f35b3480156100ab57600080fd5b5061006661027f565b3480156100c057600080fd5b506100d46100cf3660046104aa565b610406565b6040516001600160a01b039091168152602001610096565b3480156100f857600080fd5b506100d47f000000000000000000000000000000000000000000000000000000000000000081565b34801561012c57600080fd5b5061008c61013b3660046104c3565b60016020526000908152604090205481565b604051630d2d265f60e41b8152346004820152674563918244f4000090730479621f4d4b5b65fe8aa759cc02abfa84c382419063d2d265f090602401602060405180830381865af41580156101a6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101ca91906104f3565b101561021d5760405162461bcd60e51b815260206004820152601e60248201527f496e73756666696369656e742066756e6473207472616e73666572726564000060448201526064015b60405180910390fd5b60008054600181810183557f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56390910180546001600160a01b03191633908117909155825260205260408120805434929061027890849061050c565b9091555050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146102ef5760405162461bcd60e51b81526020600482015260156024820152742cb7ba9030b932903737ba103a34329027bbb732b960591b6044820152606401610214565b60005b60005481101561034257600080828154811061031057610310610533565b60009182526020808320909101546001600160a01b0316825260019081905260408220919091559190910190506102f2565b50604080516000808252602082019283905290516103609290610430565b50604051600090339047908381818185875af1925050503d80600081146103a3576040519150601f19603f3d011682016040523d82523d6000602084013e6103a8565b606091505b50509050806104035760405162461bcd60e51b815260206004820152602160248201527f5769746864726177204661696c6564205573696e672043616c6c204d6574686f6044820152601960fa1b6064820152608401610214565b50565b6000818154811061041657600080fd5b6000918252602090912001546001600160a01b0316905081565b828054828255906000526020600020908101928215610485579160200282015b8281111561048557825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190610450565b50610491929150610495565b5090565b5b808211156104915760008155600101610496565b6000602082840312156104bc57600080fd5b5035919050565b6000602082840312156104d557600080fd5b81356001600160a01b03811681146104ec57600080fd5b9392505050565b60006020828403121561050557600080fd5b5051919050565b8082018082111561052d57634e487b7160e01b600052601160045260246000fd5b92915050565b634e487b7160e01b600052603260045260246000fdfea2646970667358221220720709b7456e6c040ecf3063f563581db22149fbd12dc00a47141bc3984b8a6864736f6c634300081b0033",
"nonce": "0x19",
"input": "0x60a060405234801561001057600080fd5b5060405161083538038061083583398101604081905261002f91610058565b33608052600280546001600160a01b0319166001600160a01b0392909216919091179055610088565b60006020828403121561006a57600080fd5b81516001600160a01b038116811461008157600080fd5b9392505050565b6080516107846100b16000396000818161010e015281816103b101526104d701526107846000f3fe60806040526004361061008a5760003560e01c80633b6c8999116100595780633b6c8999146101625780633ccfd60b14610182578063a13fe71f14610197578063b60d428814610099578063c71daccb146101ac57610099565b80630d8e6e2c146100a15780630e17de55146100c95780631036e0a8146100ff5780633430a88c1461014657610099565b36610099576100976101bf565b005b6100976101bf565b3480156100ad57600080fd5b506100b6610304565b6040519081526020015b60405180910390f35b3480156100d557600080fd5b506100b66100e436600461066e565b6001600160a01b031660009081526001602052604090205490565b34801561010b57600080fd5b507f00000000000000000000000000000000000000000000000000000000000000005b6040516001600160a01b0390911681526020016100c0565b34801561015257600080fd5b506100b6674563918244f4000081565b34801561016e57600080fd5b5061012e61017d36600461069e565b610377565b34801561018e57600080fd5b506100976103a6565b3480156101a357600080fd5b506100976104cc565b3480156101b857600080fd5b50476100b6565b6002546040516318d5b20d60e01b81523460048201526001600160a01b039091166024820152674563918244f40000907300b6a8090afa0bfa1990b5c042483f783754472a906318d5b20d90604401602060405180830381865af415801561022b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061024f91906106b7565b10156102a25760405162461bcd60e51b815260206004820152601e60248201527f496e73756666696369656e742066756e6473207472616e73666572726564000060448201526064015b60405180910390fd5b60008054600181810183557f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56390910180546001600160a01b0319163390811790915582526020526040812080543492906102fd9084906106d0565b9091555050565b6002546040805163054fd4d560e41b815290516000926001600160a01b0316916354fd4d509160048083019260209291908290030181865afa15801561034e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061037291906106b7565b905090565b600080828154811061038b5761038b6106f7565b6000918252602090912001546001600160a01b031692915050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146103ef5760405163579610db60e01b815260040160405180910390fd5b60005b600054811015610442576000808281548110610410576104106106f7565b60009182526020808320909101546001600160a01b0316825260019081905260408220919091559190910190506103f2565b506040805160008082526020820192839052905161046092906105f4565b50604051600090339047908381818185875af1925050503d80600081146104a3576040519150601f19603f3d011682016040523d82523d6000602084013e6104a8565b606091505b50509050806104c95760405162461bcd60e51b81526004016102999061070d565b50565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146105155760405163579610db60e01b815260040160405180910390fd5b60008054905b81811015610569576000808281548110610537576105376106f7565b60009182526020808320909101546001600160a01b03168252600190819052604082209190915591909101905061051b565b506040805160008082526020820192839052905161058792906105f4565b50604051600090339047908381818185875af1925050503d80600081146105ca576040519150601f19603f3d011682016040523d82523d6000602084013e6105cf565b606091505b50509050806105f05760405162461bcd60e51b81526004016102999061070d565b5050565b828054828255906000526020600020908101928215610649579160200282015b8281111561064957825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190610614565b50610655929150610659565b5090565b5b80821115610655576000815560010161065a565b60006020828403121561068057600080fd5b81356001600160a01b038116811461069757600080fd5b9392505050565b6000602082840312156106b057600080fd5b5035919050565b6000602082840312156106c957600080fd5b5051919050565b808201808211156106f157634e487b7160e01b600052601160045260246000fd5b92915050565b634e487b7160e01b600052603260045260246000fd5b60208082526021908201527f5769746864726177204661696c6564205573696e672043616c6c204d6574686f6040820152601960fa1b60608201526080019056fea26469706673582212205171565fc828a010d1c95faf6c58710d415bd21a68770c5f5443e2b4a555b98364736f6c634300081b0033000000000000000000000000694aa1769357215de4fac081bf1f309adc325306",
"nonce": "0x20",
"chainId": "0xaa36a7"
},
"additionalContracts": [],
Expand All @@ -40,48 +42,48 @@
"receipts": [
{
"status": "0x1",
"cumulativeGasUsed": "0x9e087f",
"cumulativeGasUsed": "0x72be52",
"logs": [],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"type": "0x2",
"transactionHash": "0x0d7a9bb846b47826dc9f0cacc2cdbe807fbcfa12578f2ddddb59e3a8a68b4c8e",
"transactionIndex": "0x5e",
"blockHash": "0x285c83c1871ee69a14a2f110997a3e10894f74b52fe2da1142230646450c0255",
"blockNumber": "0x661e00",
"gasUsed": "0x2f467",
"effectiveGasPrice": "0x754600d",
"transactionHash": "0x251eef868774091e0b6b9ca5aeab391ca85ec5a4bd2ee1014c4ddcff8b988cc0",
"transactionIndex": "0x3b",
"blockHash": "0x1fcb1153f3c8349815c904f1d5d0e8d2407e47cbe5e93b27e2be6e2c3124e271",
"blockNumber": "0x668133",
"gasUsed": "0x2eae0",
"effectiveGasPrice": "0x14137ff4",
"from": "0x49f1d1f19fc03bba72589bbf621208bca6a77c00",
"to": "0x4e59b44847b379578588920ca78fbf26c0b4956c",
"contractAddress": null
},
{
"status": "0x1",
"cumulativeGasUsed": "0xa3797a",
"cumulativeGasUsed": "0x7a421d",
"logs": [],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"type": "0x2",
"transactionHash": "0x12f9d017ab10ee522cc41a7f14a6ef94f787ec1bb13e219f0c75c85aadca07dc",
"transactionIndex": "0x5f",
"blockHash": "0x285c83c1871ee69a14a2f110997a3e10894f74b52fe2da1142230646450c0255",
"blockNumber": "0x661e00",
"gasUsed": "0x570fb",
"effectiveGasPrice": "0x754600d",
"transactionHash": "0x769b2620564525be40ce869413cd56d1514a6b18f4d448546c8704e87000e87f",
"transactionIndex": "0x3c",
"blockHash": "0x1fcb1153f3c8349815c904f1d5d0e8d2407e47cbe5e93b27e2be6e2c3124e271",
"blockNumber": "0x668133",
"gasUsed": "0x783cb",
"effectiveGasPrice": "0x14137ff4",
"from": "0x49f1d1f19fc03bba72589bbf621208bca6a77c00",
"to": null,
"contractAddress": "0x6186f5058668ed52761ebe48baabce308fd85b2e"
"contractAddress": "0xec84bd23f237f101470d029f67b8796e5b34c950"
}
],
"libraries": [
"src/FundMe.sol:PriceConverter:0x0479621f4D4b5b65fe8aA759Cc02abFA84C38241"
"src/PriceConverter.sol:PriceConverter:0x00b6A8090AFa0BfA1990b5C042483F783754472a"
],
"pending": [],
"returns": {
"0": {
"internal_type": "contract FundMe",
"value": "0x6186F5058668Ed52761EbE48bAABce308fd85b2E"
"value": "0xEc84bd23f237f101470d029F67b8796e5B34C950"
}
},
"timestamp": 1726349582,
"timestamp": 1726699217,
"chain": 11155111,
"commit": "5cf27a9"
"commit": "e57b780"
}
5 changes: 4 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ libs = ["lib"]
remappings = [
"@chainlink/contracts/=lib/chainlink-brownie-contracts/contracts/",
]

fs_permissions = [
{ access = "read", path = "./broadcast" },
{ access = "read", path = "./reports" },
]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
1 change: 1 addition & 0 deletions lib/foundry-devops
Submodule foundry-devops added at 47393d
42 changes: 42 additions & 0 deletions script/Interactions.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {FundMe} from "../src/FundMe.sol";
import {Script, console} from "../lib/forge-std/src/Script.sol";
import {DevOpsTools} from "../lib/foundry-devops/src/DevOpsTools.sol";

contract FundFundMe is Script {
uint256 SEND_VALUE = 0.01 ether;

function fundFundMe(address mostRecentDeployedAddress) public {
vm.startBroadcast();
FundMe(payable(mostRecentDeployedAddress)).fund{value: SEND_VALUE}();
vm.stopBroadcast();
console.log("Account Funded");
}

function run() external {
address mostRecentDeployedAddress = DevOpsTools
.get_most_recent_deployment("FundMe", block.chainid);
vm.startBroadcast();
fundFundMe(mostRecentDeployedAddress);
vm.stopBroadcast();
}
}

contract WithdrawFundMe is Script {
function withdrawFundMe(address mostRecentDeployedAddress) public {
vm.startBroadcast();
FundMe(payable(mostRecentDeployedAddress)).withdrawCheaper();
vm.stopBroadcast();
console.log("Funds Withdrawn");
}

function run() external {
address mostRecentDeployedAddress = DevOpsTools
.get_most_recent_deployment("FundMe", block.chainid);
vm.startBroadcast();
withdrawFundMe(mostRecentDeployedAddress);
vm.stopBroadcast();
}
}
13 changes: 13 additions & 0 deletions src/FundMe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ contract FundMe {
s_addressToAmountFunded[msg.sender] += msg.value;
}

function withdrawCheaper() public ownerOnly {
uint256 fundersLength = s_allFundersAddress.length;
for (uint256 i = 0; i < fundersLength; i++) {
address funder = s_allFundersAddress[i];
s_addressToAmountFunded[funder] = 0;
}
s_allFundersAddress = new address[](0);
(bool success, ) = payable(msg.sender).call{
value: address(this).balance
}("");
require(success, "Withdraw Failed Using Call Method");
}

function withdraw() public ownerOnly {
for (uint256 i = 0; i < s_allFundersAddress.length; i++) {
address funder = s_allFundersAddress[i];
Expand Down
Loading

0 comments on commit 1c91f09

Please sign in to comment.