I'm using vm.rollFork feature in foundry to get _token.totalSupply() at two different blocks but test failing because its returning same totalSupply number for two different blocks. I have checked and totalSupply number, if tested individually for these two blocks returns different number.

forge test --match-contract rollForkTest -vv --fork-url https://rpc.ankr.com/eth

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test, console2} from "forge-std/Test.sol";

interface ERC20 {
    function totalSupply() external view returns (uint256);

contract rollForkTest is Test {
    ERC20 _token;

    function setUp() public {
        // _token = ERC20(0x06325440D014e39736583c165C2963BA99fAf14E);  //dai
        _token = ERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); //weth

    function testTokenSupply() public {

        uint256 prev = _token.totalSupply();
        console2.log("totalSupply prev ", prev);
        console2.log("block", block.number, "timestamp", block.timestamp);


        uint256 later = _token.totalSupply();
        console2.log("totalSupply later", later);
        console2.log("block", block.number, "timestamp", block.timestamp);

        assertNotEq(prev, later);

1 Answer 1


I have run into this problem recently also.

Selecting the first fork in setup and doing vm.rollFork in the test will give you the correct behavior but its a bit of a work around.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.