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(cheatcodes): readFile / readAddress not consistent depending of OS (Linux / Mac) #6807

Closed
vjuge opened this issue Jan 14, 2024 · 1 comment · Fixed by #9107
Closed

bug(cheatcodes): readFile / readAddress not consistent depending of OS (Linux / Mac) #6807

vjuge opened this issue Jan 14, 2024 · 1 comment · Fixed by #9107
Labels
A-cheatcodes Area: cheatcodes T-bug Type: bug T-to-reproduce Type: requires reproduction
Milestone

Comments

@vjuge
Copy link

vjuge commented Jan 14, 2024

Context

i'm using this piece of code to persist contract addresses on a deploy script:

function updateContractAddressJson(string memory contractName, string memory __chainid, address __address) private returns (string memory outputObj1) {
        string memory deployments = vm.readFile("./contracts/broadcast/deployments.json");

        address contract31337 = deployments.readAddress(string.concat("$.",contractName, ".31337"));
        address contract1 = deployments.readAddress(string.concat("$.",contractName, ".1"));
        address contract80001 = deployments.readAddress(string.concat("$.",contractName, ".80001"));

         // [...]       
        vm.serializeAddress(obj, "31337", contract31337);
         // [...]       
        outputObj1 = vm.serializeAddress(obj, __chainid, __address);
        console.log(outputObj1);

}

to read/update the file ./contracts/broadcast/deployments.json:

{
  "DAOTreasury": {
    "1": "0x0000000000000000000000000000000000000020",
    "31337": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
    "80001": "0x0000000000000000000000000000000000000020"
  },
  "MockERC20": {
    "1": "0x0000000000000000000000000000000000000020",
    "31337": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
    "80001": "0xdaAe8d27687155dD49B7D6dBc33369fd00081255"
  }
}

Issue

I used to launch this script either from a linux PC(fedora) or from a macbook, and the json path is not interpreted the same depending of the OS the script runs from.

Caution

in some case we need to have a prefix "$.", in some case not.

linux working code:

        address contract31337 = deployments.readAddress(string.concat("$.",contractName, ".31337"));

macos working code:

        address contract31337 = deployments.readAddress(string.concat(contractName, ".31337"));

Otherwise, I have this kind of error (sample running without the "$."prefix on linux):

    ├─ [0] VM::parseJson(<JSON file>, MockERC20.31337) [staticcall]
    │   └─ ← "path error: 
$MockERC20.31337

As you can see, on linux we need to have the prefix "$.".

Is this something i'm missing or a bug ?

@onbjerg onbjerg transferred this issue from foundry-rs/book Jan 15, 2024
@gakonst gakonst added this to Foundry Jan 15, 2024
@github-project-automation github-project-automation bot moved this to Todo in Foundry Jan 15, 2024
@zerosnacks zerosnacks changed the title readFile / readAddress not consistent depending of OS (linux / Mac) bug(cheatcodes): readFile / readAddress not consistent depending of OS (linux / Mac) Jul 9, 2024
@zerosnacks zerosnacks added T-bug Type: bug A-cheatcodes Area: cheatcodes T-to-reproduce Type: requires reproduction labels Jul 9, 2024
@zerosnacks zerosnacks changed the title bug(cheatcodes): readFile / readAddress not consistent depending of OS (linux / Mac) bug(cheatcodes): readFile / readAddress not consistent depending of OS (Linux / Mac) Jul 9, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@grandizzy
Copy link
Collaborator

should be fixed with #9107 by using new cheatcodes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes T-bug Type: bug T-to-reproduce Type: requires reproduction
Projects
Archived in project
Status: Todo
Development

Successfully merging a pull request may close this issue.

3 participants