foundry icon indicating copy to clipboard operation
foundry copied to clipboard

bug(`forge test`): test reported as passed even though the assertions are failing

Open yashagarwal1994 opened this issue 1 year ago • 1 comments

Component

Forge

Have you ensured that all of these are up to date?

  • [X] Foundry
  • [ ] Foundryup

What version of Foundry are you on?

forge 0.2.0 (9444c62 2024-07-26T00:20:35.095786516Z)

What command(s) is the bug in?

forge test

Operating System

Linux

Describe the bug

Running forge test -w -vvv --fork-url <base-mainnet-rpc> I get that the test has passed but actually it hasn't

[PASS] testNoEthLeftInRouterAfterGraduation() (gas: 4606306)
Logs:
  Passed 1
  Passed 2
  Error: Router should have no ETH after graduation
  Error: a == b not satisfied [uint]
    Expected: 0
      Actual: 145448186

This it the test case

    function testNoEthLeftInRouterAfterGraduation() public {
        // Setup
        uint256 graduationAmount = 574 * oneMillionToken;
        Router.BondingCurve curveType = Router.BondingCurve.HOLD;
        Router.TokenCreateParams memory params = getTokenCreateParams(graduationAmount, curveType);
        address tokenCreated = getTokenCreated(params, 1 * oneMillionToken, 20 ether);

        // Buy tokens until just before graduation
        uint256 remainingAmount = graduationAmount - 1 * oneMillionToken - 1000;
        uint256 price = router.getBuyPriceAfterFee(tokenCreated, remainingAmount);
        vm.deal(address(this), price * 2);
        router.buyToken{value: price * 2}(tokenCreated, remainingAmount);

        // Check router's ETH balance before graduation
        uint256 routerBalanceBefore = address(router).balance;
        assertGt(routerBalanceBefore, 0, "Router should have ETH before graduation");
        console.log("Passed 1");
        // Graduate the token
        uint256 finalAmount = 1 * oneMillionToken;
        uint256 finalPrice = router.getBuyPriceAfterFee(tokenCreated, finalAmount);
        vm.deal(address(this), finalPrice * 2);
        router.buyToken{value: finalPrice * 2}(tokenCreated, finalAmount);

        // Check if the token has graduated
        assertTrue(router.isTokenGraduated(tokenCreated), "Token should be graduated");
        console.log("Passed 2");

        // Check router's ETH balance after graduation
        uint256 routerBalanceAfter = address(router).balance;
        assertEq(routerBalanceAfter, 0, "Router should have no ETH after graduation");
    }

foundry.toml

[profile.default]
src = "src"
out = "out"
libs = ["lib"]
via_ir = true
optimizer = false
optimizer-runs = 1

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

yashagarwal1994 avatar Aug 27 '24 18:08 yashagarwal1994

@yashagarwal1994 do you see the same behavior if setting legacy_assertions = true in profile default?

grandizzy avatar Aug 28 '24 09:08 grandizzy

closing due to inactivity, please reopen if the issue persists @yashagarwal1994

jenpaff avatar Sep 24 '24 13:09 jenpaff