Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(forge): warp effect is reversed when switching back to original fork #8168

Closed
2 tasks done
anajuliabit opened this issue Jun 14, 2024 · 3 comments · Fixed by #8466
Closed
2 tasks done

bug(forge): warp effect is reversed when switching back to original fork #8168

anajuliabit opened this issue Jun 14, 2024 · 3 comments · Fixed by #8466
Labels
C-forge Command: forge Cmd-forge-script Command: forge script Cmd-forge-test Command: forge test T-bug Type: bug

Comments

@anajuliabit
Copy link

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (6179312 2024-06-10T00:18:46.177980000Z)

What command(s) is the bug in?

forge script / forge test

Operating System

macOS (Apple Silicon)

Describe the bug

Scenario: two or more forks created using vm.createFork cheatcode
Bug: Use the warp cheatcode on fork 1 to move to a future timestamp, then switch to fork 2, and finally switch back to fork 1. The block.timestamp on fork 1 will be the block just before the warp.

Reproducing:

pragma solidity 0.8.19;

import {console} from "@forge-std/console.sol";
import {Script} from "@forge-std/Script.sol";

import "@forge-std/Test.sol";

contract MultipleForksWarp is Script, Test {
    /// @notice fork ID for moonbeam
    uint256 public moonbeamForkId =
        vm.createFork(vm.envString("MOONBEAM_RPC_URL"));

    /// @notice fork ID for base
    uint256 public baseForkId = vm.createFork(vm.envString("BASE_RPC_URL"));

    function run() public {
        console.log("Moonbeam fork selected");
        vm.selectFork(moonbeamForkId);
        console.log("Timestamp: ", block.timestamp);

        vm.warp(block.timestamp + 1000);
        console.log("Timestamp after warp: ", block.timestamp);

        console.log("Switching to base fork");
        vm.selectFork(baseForkId);

        console.log("Back to moonbeam fork");
        vm.selectFork(moonbeamForkId);

        console.log("Timestamp: ", block.timestamp);
    }
}
Script ran successfully.
Gas used: 36285

== Logs ==
  Moonbeam fork selected
  Timestamp:  1718386092
  Timestamp after warp:  1718387092
  Switching to base fork
  Back to moonbeam fork
  Timestamp:  1718386092
@anajuliabit anajuliabit added the T-bug Type: bug label Jun 14, 2024
@grandizzy
Copy link
Collaborator

grandizzy commented Jun 14, 2024

Can you please check if this happens also if you move initial forks creation / forks id recording in setUp function? (Or even directly in run)

@anajuliabit
Copy link
Author

anajuliabit commented Jun 14, 2024

@grandizzy yes, it also happens

contract MultipleForksWarp is Script, Test {
    /// @notice fork ID for moonbeam
    uint256 public moonbeamForkId;

    /// @notice fork ID for base
    uint256 public baseForkId;

    function run() public {
        moonbeamForkId = vm.createFork(vm.envString("MOONBEAM_RPC_URL"));

        baseForkId = vm.createFork(vm.envString("BASE_RPC_URL"));

        console.log("Moonbeam fork selected");
        vm.selectFork(moonbeamForkId);
        console.log("Timestamp: ", block.timestamp);

        vm.warp(block.timestamp + 1000);
        console.log("Timestamp after warp: ", block.timestamp);

        console.log("Switching to base fork");
        vm.selectFork(baseForkId);

        console.log("Back to moonbeam fork");
        vm.selectFork(moonbeamForkId);

        console.log("Timestamp: ", block.timestamp);
    }
}
Script ran successfully
Gas used: 60478        
                       
== Logs ==             
Script ran successfully.
Gas used: 60478

== Logs ==
  Moonbeam fork selected
  Timestamp:  1718387790
  Timestamp after warp:  1718388790
  Switching to base fork
  Back to moonbeam fork
  Timestamp:  1718387790

@zerosnacks zerosnacks added Cmd-forge-test Command: forge test C-forge Command: forge Cmd-forge-script Command: forge script labels Jun 27, 2024
@zerosnacks zerosnacks changed the title Warp effect is reversed when switching back to original fork bug(forge): warp effect is reversed when switching back to original fork Jul 16, 2024
@anajuliabit
Copy link
Author

Hey, @grandizzy this still happens when you switch for the third time. The fix works only until the second switch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-script Command: forge script Cmd-forge-test Command: forge test T-bug Type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants