Skip to content

Advanced-foundry: Section 3 - DeFi Protocoll video 18 - DSCE advanced testing | Written lesson content does not match to video content #361

Open
@MrRobWeb

Description

Even though I celebrate the content of written lesson about the different layers of testing it doesn't match to the video content. Unfortunately, I haven't found the video for "Leveling up testing". I would really appreciate a video about this content!

The written lesson should have covered the following test + the challenge to write some tests:

///////////////////////
// Constructor Tests //
///////////////////////
address[] public tokenAddresses;
address[] public feedAddresses;

function testRevertsIfTokenLengthDoesntMatchPriceFeeds() public {
    tokenAddresses.push(weth);
    feedAddresses.push(ethUsdPriceFeed);
    feedAddresses.push(btcUsdPriceFeed);

    vm.expectRevert(DSCEngine.DSCEngine__TokenAddressesAndPriceFeedAddressesMustBeSameLength.selector);
    new DSCEngine(tokenAddresses, feedAddresses, address(dsc));
}

...

function testGetTokenAmountFromUsd() public {
        // If we want $100 of WETH @ $2000/WETH, that would be 0.05 WETH
        uint256 expectedWeth = 0.05 ether;
        uint256 amountWeth = dsce.getTokenAmountFromUsd(weth, 100 ether);
        assertEq(amountWeth, expectedWeth);
    }

....

modifier depositedCollateral() {
    vm.startPrank(USER);
    ERC20Mock(weth).approve(address(dsce), AMOUNT_COLLATERAL);
    dsce.depositCollateral(weth, AMOUNT_COLLATERAL);
    vm.stopPrank();
    _;
}

function testCanDepositedCollateralAndGetAccountInfo() public depositedCollateral {
    (uint256 totalDscMinted, uint256 collateralValueInUsd) = dsce.getAccountInformation(USER);
    uint256 expectedDepositedAmount = dsce.getTokenAmountFromUsd(weth, collateralValueInUsd);
    assertEq(totalDscMinted, 0);
    assertEq(expectedDepositedAmount, AMOUNT_COLLATERAL);
}

But it covers something about layers of testing:

Image

Image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions