hedera-smart-contracts icon indicating copy to clipboard operation
hedera-smart-contracts copied to clipboard

Hedera Token Service return `EvmError: InvalidEFOpcode` while running forking tests with foundry

Open sqrlfirst opened this issue 7 months ago • 1 comments

Description

I'm trying to run I'm trying to run mainnet fork test in foundry, however I'm getting following error while I try to execute vm.deal cheat code to mint erc20:

Ran 1 test for test/foundry/testforissue.t.sol:DealCheatCodeIssue
[FAIL. Reason: setup failed: EvmError: Revert] setUp() (gas: 0)
Traces:
  [1040430288] DealCheatCodeIssue::setUp()
    ├─ [0] VM::addr(<pk>) [staticcall]
    │   └─ ← [Return] user_one: [0x10717341b635a148A81A6e6e8c0EDe50E59490B2]
    ├─ [0] VM::label(user_one: [0x10717341b635a148A81A6e6e8c0EDe50E59490B2], "user_one")
    │   └─ ← [Return] 
    ├─ [0] VM::deal(user_one: [0x10717341b635a148A81A6e6e8c0EDe50E59490B2], 100000000000 [1e11])
    │   └─ ← [Return] 
    ├─ [1040398513] 0x000000000000000000000000000000000006f89a::balanceOf(user_one: [0x10717341b635a148A81A6e6e8c0EDe50E59490B2]) [staticcall]
    │   ├─ [0] 0x0000000000000000000000000000000000000167::redirectForToken() [delegatecall]
    │   │   └─ ← [InvalidEFOpcode] EvmError: InvalidEFOpcode
    │   └─ ← [Revert] EvmError: Revert
    └─ ← [Revert] EvmError: Revert

Steps to reproduce

  1. Run the test with following command:
forge test --fork-url "https://mainnet.hashio.io/api" --match-contract "DealCheatCodeIssue"  -vvvv 

Example of test:

// SPDX-License-Identifier: unlicensed
pragma solidity ^0.8.17;

import {Test, Vm, console} from "forge-std/Test.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract DealCheatCodeIssue is Test {
    address USDC_mainnet = 0x000000000000000000000000000000000006f89a;
    address user1;

    function setUp() public {
        user1 = makeAddr("user_one");

        deal(user1, 100 * 10e8);
        deal(USDC_mainnet, user1, 1000 * 10e8);
    }

    function test_UserBalance() public {
        uint256 userBalance = IERC20(USDC_mainnet).balanceOf(user1);
        assertEq(userBalance, 1000 * 10e8);
    }
}

Additional context

No response

Hedera network

mainnet

Version

v0.1.0

Operating system

macOS

sqrlfirst avatar Jul 17 '24 09:07 sqrlfirst