scaffold-eth / scaffold-eth-2

Open source forkable Ethereum dev stack
https://scaffoldeth.io
MIT License
1.41k stars 887 forks source link

issue: yarn deploy fails in case of multiple contracts in the same file in the Foundry version #947

Open nzmpi opened 2 months ago

nzmpi commented 2 months ago

Is there an existing issue for this?

Which method was used to setup Scaffold-ETH 2 ?

npx create-eth@latest

Current Behavior

In the Foundry version if you have a contract A in the same sol-file as the contract B that inherits it, running yarn deploy will throw Error: ENOENT: no such file or directory, open '/[path]/packages/foundry/out/A.sol/A.json'. Even though json-file is generated, but it's in /[path]/packages/foundry/out/B.sol/A.json.

Expected Behavior

yarn deploy should look for contract's ABI file in every folder of /foundry/out and not only in folders with the same name

Steps To Reproduce

In foundry/contracts create B.sol file with this code:

//SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

contract A {
  uint256 x;

  constructor() payable {
    x = 1;
  }

  function update(uint256 y) external virtual {
    x = y;
  }
}

contract B is A {
  function update(uint256 y) external override {
    x = y * 2;
  }
}

Then in foundry/script/Deploy.s.sol in the run function add

    B b = new B();
    console.logString(
      string.concat(
        "B deployed at: ", vm.toString(address(b))
      )
    );

Run yarn deploy

Anything else?

Some projects have multiple contracts (especially abstract contracts) in the same sol-file. They won't work with SE-2 (Foundry). Developers either will need to create every contract in their own sol-file or move json-files to their own folders in the foundry/out folder.

This problem only exists in the Foundry version. The Hardhat version works properly.