Skip to content

feat(cheatcodes): add vm.storeTransient and vm.loadTransient #8165

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

Open
0xteddybear opened this issue Jun 14, 2024 · 3 comments
Open

feat(cheatcodes): add vm.storeTransient and vm.loadTransient #8165

0xteddybear opened this issue Jun 14, 2024 · 3 comments
Labels
A-cheatcodes Area: cheatcodes T-feature Type: feature T-to-discuss Type: requires discussion

Comments

@0xteddybear
Copy link

Component

Forge

Describe the feature you would like

A cheatcode that sets a contract's transient storage slot to a particular value, and another one allowing to read it

Additional context

It'd be consistent to have methods to read/write transient storage similar to those that already perform those operations on regular storage

They are useful for mocks & unit testing of contracts using transient storage, and would be extra useful given there are currently no solidity variables of transient type and that makes it more cumbersome to write mocks by hand or with automated mocking tools such as smock-foundry

Setting the transient storage slot from outside the contract enables devs to do less mocking

@0xteddybear 0xteddybear added the T-feature Type: feature label Jun 14, 2024
@0xteddybear
Copy link
Author

this is related to #6908

@mattsse
Copy link
Member

mattsse commented Jun 14, 2024

@klkvr would this be possible with --isolate?

@klkvr
Copy link
Member

klkvr commented Jun 14, 2024

@klkvr would this be possible with --isolate?

only if cheatcode is invoked inside of isolated subcall

contract TransientAssert {
    function assertLocked() external {
        bool locked;
        assembly { locked := tload(0) }
        assertTrue(locked);
    }
}

contract TestTransient {
    TransientAssert target = new TransientAssert();
    
    // passes only without --isolate
    function test_root() {
        vm.tstore(target, bytes32(0), bytes32(1));
        target.assertLocked();
    }
    
    // passes always
    function test_subcall() {
        this.test_root();
    }
}

we can probably allow it always, even though I think testing transient storage makes sense only with --isolate

@zerosnacks zerosnacks added the A-cheatcodes Area: cheatcodes label Jun 27, 2024
@zerosnacks zerosnacks changed the title Feature request: vm.storeTransient and vm.loadTransient feat: vm.storeTransient and vm.loadTransient Jul 10, 2024
@zerosnacks zerosnacks added the T-to-discuss Type: requires discussion label Jul 10, 2024
@zerosnacks zerosnacks changed the title feat: vm.storeTransient and vm.loadTransient feat(cheatcodes): add vm.storeTransient and vm.loadTransient Jul 16, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@grandizzy grandizzy removed this from the v1.0.0 milestone Oct 1, 2024
@github-project-automation github-project-automation bot moved this to Todo in Foundry Oct 1, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-cheatcodes Area: cheatcodes T-feature Type: feature T-to-discuss Type: requires discussion
Projects
Archived in project
Development

No branches or pull requests

5 participants