Skip to content

Commit

Permalink
Unit Test aded
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrade committed Sep 23, 2024
1 parent bc7d041 commit 9c540e3
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 49 deletions.
3 changes: 2 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
src = "src"
out = "out"
libs = ["lib"]
remappings = ["@openzeppelin=lib/openzeppelin-contracts/contracts"]
remappings = ["@openzeppelin=lib/openzeppelin-contracts/contracts",
"@chainlink=lib/chainlink-brownie-contracts/contracts/src/v0.8",]
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
2 changes: 1 addition & 1 deletion lib/chainlink-brownie-contracts
8 changes: 4 additions & 4 deletions script/DeployDSC.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ contract DeployDSC is Script {
address[] public priceFeedAddresses;

function run() public returns (DecentralizedStableCoin, DSCEngine, HelperConfig) {

HelperConfig config = new HelperConfig();

(address wethUsdPriceFeed, address wbtcUsdPriceFeed, address weth, address wbtc, uint256 deployerKey) = config.activeNetworkConfig();
(address wethUsdPriceFeed, address wbtcUsdPriceFeed, address weth, address wbtc, uint256 deployerKey) =
config.activeNetworkConfig();

priceFeedAddresses = [wethUsdPriceFeed, wbtcUsdPriceFeed];
tokenAddresses = [weth, wbtc];
Expand All @@ -26,6 +26,6 @@ contract DeployDSC is Script {
DSCEngine engine = new DSCEngine(tokenAddresses, priceFeedAddresses, address(dsc));
dsc.transferOwnership(address(engine));
vm.stopBroadcast();
return(dsc, engine, config);
return (dsc, engine, config);
}
}
}
15 changes: 7 additions & 8 deletions script/HelperConfig.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.18;

import {Script} from "forge-std/Script.sol";
import {MockV3Aggregator} from "../test/mocks/MockV3Aggregator.t.sol";
import {ERC20Mock} from "@openzeppelin/contracts/mocks/token/ERC20Mock.sol";
import {ERC20Mock} from "@openzeppelin/mocks/token/ERC20Mock.sol";

contract HelperConfig is Script {
struct NetworkConfig {
Expand All @@ -18,7 +18,7 @@ contract HelperConfig is Script {
// constants
uint8 public constant WETH_DECIMALS = 8;
uint8 public constant WBTC_DECIMALS = 8;
int256 public constant WETH_USD_PRICE = 2800 * 10 ** 8;
int256 public constant WETH_USD_PRICE = 2000 * 10 ** 8;
int256 public constant WBTC_USD_PRICE = 60000 * 10 ** 8;
uint256 public constant ANVIL_DEPLOYER_KEY = 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80;

Expand All @@ -27,8 +27,7 @@ contract HelperConfig is Script {
constructor() {
if (block.chainid == 11155111) {
activeNetworkConfig = getSepoliaEthConfig();
}
else {
} else {
activeNetworkConfig = getOrCreateAnvilConfig();
}
}
Expand All @@ -43,7 +42,7 @@ contract HelperConfig is Script {
});
}

function getOrCreateAnvilConfig() public returns (NetworkConfig memory){
function getOrCreateAnvilConfig() public returns (NetworkConfig memory) {
// check to see if we have an existing config
if (activeNetworkConfig.wethUsdPriceFeed != address(0)) {
return activeNetworkConfig;
Expand All @@ -53,11 +52,11 @@ contract HelperConfig is Script {
vm.startBroadcast();
//weth mock $ PriceFeeds
MockV3Aggregator wethUsdPriceFeed = new MockV3Aggregator(WETH_DECIMALS, WETH_USD_PRICE);
ERC20Mock wethMock = new ERC20Mock( );
ERC20Mock wethMock = new ERC20Mock();

// wbtc mock and PriceFeeds
MockV3Aggregator wbtcUsdPriceFeed = new MockV3Aggregator(WETH_DECIMALS, WBTC_USD_PRICE);
ERC20Mock wbtcMock = new ERC20Mock( );
ERC20Mock wbtcMock = new ERC20Mock();
vm.stopBroadcast();

return NetworkConfig({
Expand All @@ -68,4 +67,4 @@ contract HelperConfig is Script {
deployerKey: ANVIL_DEPLOYER_KEY
});
}
}
}
Loading

0 comments on commit 9c540e3

Please sign in to comment.