Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
Gere321123 committed Oct 9, 2024
1 parent 2746c69 commit 42d1dc0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
16 changes: 12 additions & 4 deletions script/DeployDSC.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ import {Script} from "forge-std/Script.sol";
import {DecentralizedStableCoin} from "../src/DecentralizedStableCoin.sol";
import {DSCEngine} from "../src/DSCEngine.sol";
import {HelperConfig} from "./HelperConfig.s.sol";
import {console} from "forge-std/console.sol";

contract DeployDSC is Script {
function run() external returns (DecentralizedStableCoin, DSCEngine) {
address[] public tokenAddresses;
address[] public priceFeedAddresses;

function run() external returns (DecentralizedStableCoin, DSCEngine, HelperConfig) {
HelperConfig config = new HelperConfig();
(address wethUsdPriceFeed, address wbtcUsdPriceFeed, address weth, address wbtc, uint256 deployerKey) =
config.activeNetworkConfig();
vm.startBroadcast();
tokenAddresses = [weth, wbtc];
priceFeedAddresses = [wethUsdPriceFeed, wbtcUsdPriceFeed];
vm.startBroadcast(deployerKey);
DecentralizedStableCoin dsc = new DecentralizedStableCoin();
//DSCEngine engine = new DSCEngine();
vm.startBroadcast();
DSCEngine engine = new DSCEngine(tokenAddresses, priceFeedAddresses, address(dsc));
vm.stopBroadcast();
console.log("Broadcast stopped.");
return (dsc, engine, config);
}
}
37 changes: 37 additions & 0 deletions test/unit/DSCEngineTest.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity ^0.8.18;

import {Test} from "forge-std/Test.sol";
import {console} from "forge-std/console.sol";
import {DeployDSC} from "../../script/DeployDSC.s.sol";
import {DecentralizedStableCoin} from "../../src/DecentralizedStableCoin.sol";
import {DSCEngine} from "../../src/DSCEngine.sol";
import {HelperConfig} from "../../script/HelperConfig.s.sol";

contract DSCEngineTest is Test {
DeployDSC deployer;
DecentralizedStableCoin dsc;
DSCEngine engine;
HelperConfig config;
address ethUsdPriceFeed;
address weth;

function setUp() public {
console.log("1");
deployer = new DeployDSC();
console.log("2");
(dsc, engine, config) = deployer.run();
console.log("3");
(ethUsdPriceFeed,, weth,,) = config.activeNetworkConfig();
}

//Price Test

function testGetUsdValue() public {
uint256 ethAmount = 15e18;
uint256 expectedUsd = 30000e18;
uint256 actualUsd = engine.getUsdValue(weth, ethAmount);
console.log(actualUsd);
assertEq(expectedUsd, actualUsd);
}
}

0 comments on commit 42d1dc0

Please sign in to comment.