Skip to content

fix: remove StdStorage in CommonBase contract #241

New issue

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

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

Already on GitHub? # to your account

Merged
merged 5 commits into from
Nov 30, 2022

Conversation

graykode
Copy link
Contributor

@graykode graykode commented Nov 27, 2022

Remove StdStorage in Common.sol
If there is StdStorage in Common.sol, this testcase cant return ERROR when run with forge

pragma solidity ^0.8.0;

import "forge-std/Test.sol";

contract good is Test {
    uint256 a;

    function testAAA() public {
        uint256 id = vm.snapshot();
        a = 1;
        assertEq(a, uint256(2));
        vm.revertTo(id);
    }
}

image

@mds1
Copy link
Collaborator

mds1 commented Nov 28, 2022

Holding off on merging this per discussion in foundry-rs/foundry#3055 — let's move discussion there, cc @ZeroEkkusu if you have any thoughts on this PR

Copy link
Collaborator

@ZeroEkkusu ZeroEkkusu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initializing a struct before DSTest is inherited causes the example to pass.

Since it's a false positive (dangerous), let's fix the issue immediately. @graykode, could you please move TestBase to the of the inheritance chain instead:

abstract contract Test is DSTest, StdAssertions, StdCheats, StdUtils, TestBase {}

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, let's merge and I'll debug the root cause.

@mds1 probably need another patch release?

@ZeroEkkusu
Copy link
Collaborator

My comment was unclear: we are discarding all the changes and only doing this 👇

abstract contract Test is DSTest, StdAssertions, StdCheats, StdUtils, TestBase {}

@mds1
Copy link
Collaborator

mds1 commented Nov 30, 2022

@ZeroEkkusu I pushed the required changes and verified the test now fails as expected. Feel free to review/merge

@ZeroEkkusu ZeroEkkusu merged commit 08d0f48 into foundry-rs:master Nov 30, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants