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): vm.transact cheatcode not working #5929

Closed
2 tasks done
wp-lai opened this issue Sep 27, 2023 · 2 comments · Fixed by #6907
Closed
2 tasks done

bug(forge): vm.transact cheatcode not working #5929

wp-lai opened this issue Sep 27, 2023 · 2 comments · Fixed by #6907
Labels
T-bug Type: bug

Comments

@wp-lai
Copy link
Contributor

wp-lai commented Sep 27, 2023

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 (80df71f 2023-09-27T00:24:52.309432000Z)

What command(s) is the bug in?

No response

Operating System

macOS (Apple Silicon)

Describe the bug

I ran the vm.transact code example from the Foundry Book in a forge test, the test failed with reason "backend: failed committing transaction: Transaction(NonceTooLow { tx: 1, state: 2 })".

For MAINNET_RPC_URL, I was using "https://rpc.ankr.com/eth".

@wp-lai wp-lai added the T-bug Type: bug label Sep 27, 2023
@kustrun
Copy link

kustrun commented Jan 26, 2024

Am having a similar problem (same OS, same version of forge). It seems like the vm.transact is not working as expected.

Example to replicate:

    function test_transact_not_working() public {
        vm.createSelectFork("eth-main", 15625301);
        // NOT WORKING
        // https://etherscan.io/tx/0x96a129768ec66fd7d65114bf182f4e173bf0b73a44219adaf71f01381a3d0143
        vm.transact(hex"96a129768ec66fd7d65114bf182f4e173bf0b73a44219adaf71f01381a3d0143");

        // WORKING
        address from = address(0x66C3c5D24BaE428A69c72117fd2f84B69F697Aed);
        address to = address(0x90F765F63E7DC5aE97d6c576BF693FB6AF41C129);
        uint256 value = 0;
        bytes
            memory data = hex"0a5cb529000000000000000000000000430a35baa51ddeaccf89092a5edbda47aaae78e400000000000000000000000000000000000000000000000000000000000000e000000000000000000000000039aa39c021dfbae8fac545936693ac917d5e7563000000000000000000000000000000000000000000000000000000396a23a87f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000003887000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000125a65726f4578417069416461707465725634000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c87a1eb1b900000000000000000000000039aa39c021dfbae8fac545936693ac917d5e7563000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000001f6064abb01a13000000000000000000000000000000000000000000000000000000001f35739e0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000001cf6844fb63f74000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000039aa39c021dfbae8fac545936693ac917d5e7563000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000269e05bf9da9f000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000039aa39c021dfbae8fac545936693ac917d5e7563000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48869584cd00000000000000000000000010000000000000000000000000000000000000110000000000000000000000000000000000000000000000c26f2d71f363330926000000000000000000000000000000000000000000000000";
        vm.prank(from, from);

        (bool success, ) = to.call{value: value}(data);
        require(success);
    }

@Mouradif
Copy link

Mouradif commented Apr 16, 2024

Same issue here with

forge 0.2.0 (440ec52 2024-04-11T00:22:09.585245000Z)

What does the error mean?

My temporary workaround:

    function replay(
        bytes32 txHash,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        uint256 forkId = vm.createFork("rpc");
        vm.selectFork(forkId);
        vm.rollFork(txHash);
        vm.startPrank(from, from);
        to.call{ value: value }(data);
        vm.stopPrank();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants