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

vm.roll can result in panic on L2 network #1649

Closed
1 of 2 tasks
RiccardoBiosas opened this issue May 17, 2022 · 4 comments
Closed
1 of 2 tasks

vm.roll can result in panic on L2 network #1649

RiccardoBiosas opened this issue May 17, 2022 · 4 comments
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge Cmd-forge-test Command: forge test P-high Priority: high T-bug Type: bug

Comments

@RiccardoBiosas
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

What command(s) is the bug in?

forge test

Operating System

Linux

Describe the bug

As described in this issue, forge does not currently handle the idiosyncrasies of each EVM-compatible L2 network. In the context of testing contracts which rely on a block.number delta against an Arbitrum fork pinned at a certain block, using vm.roll as a workaround would suffice until now.

However, after upgrading to foundry 2.0, forking an Arbitrum live network pinned at a certain block (i.e.: forge test --fork-url ARBITRUM_RPC --fork-block-number 1337) and then using vm.roll to set the test contract's block.number to an L1 value results in a panic. This prevents me from testing some logic where the L2 contract calculates the difference between a lastBlockNumber variable and the current block.number (both L1 values).

I think that the change responsible for this behavior is this commit. In fact, after downgrading foundry to the previous commit ( foundryup -C 4415ff47cc03c9f9657dd2959f57de411a4e67b2), the test/vm.roll worked again as expected

@RiccardoBiosas RiccardoBiosas added the T-bug Type: bug label May 17, 2022
@onbjerg onbjerg added this to Foundry May 17, 2022
@onbjerg onbjerg moved this to Todo in Foundry May 17, 2022
@onbjerg onbjerg added Cmd-forge-test Command: forge test C-forge Command: forge A-cheatcodes Area: cheatcodes P-high Priority: high labels May 19, 2022
@mattsse
Copy link
Member

mattsse commented May 22, 2022

thanks for raising this,

using vm.roll to set the test contract's block.number to an L1 value results in a panic.

this is the expected behavior, because the fork is bound to a specific chain.

#ceaecc660 introduced panics because that's the only safe behavior when we failed to look up data on the fork.

this is good feedback and we're working on making forking support more flexible for different L2s: #834

so you can easily switch the context from within your test and the use case you're describing should be possible.

@onbjerg
Copy link
Collaborator

onbjerg commented Jul 1, 2022

@mattsse Is this fixed by multi-fork? If so, can you kindly link PR and issue together? 😄

@mattsse
Copy link
Member

mattsse commented Aug 1, 2022

it's not handled automatically yet, a workaround is described here #748 (comment)

we decided to hold off on this until the major L2 upgrades are rolled out before baking in chain agnostic stuff.

but I think we can close this in favor of #748 ?

@onbjerg
Copy link
Collaborator

onbjerg commented Aug 1, 2022

Yeah, agreed 👍

@onbjerg onbjerg closed this as completed Aug 1, 2022
Repository owner moved this from Todo to Done in Foundry Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge Cmd-forge-test Command: forge test P-high Priority: high T-bug Type: bug
Projects
Archived in project
Development

No branches or pull requests

3 participants