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

Inconsistent loading of imported contracts into project #1581

Open
gnpar opened this issue Jul 15, 2022 · 0 comments
Open

Inconsistent loading of imported contracts into project #1581

gnpar opened this issue Jul 15, 2022 · 0 comments

Comments

@gnpar
Copy link

gnpar commented Jul 15, 2022

Environment information

  • brownie Version: v1.19.0
  • ganache-cli Version: v7.3.2
  • solc Version: 0.8.6
  • Python Version: 3.8.10
  • OS: linux

What was wrong?

There seems to be an issue with how contracts are loaded into the project.

When run on a clean directory (no build), imported contracts are loaded into the project's namespace.

When run a second time when the contracts were already built, only project contracts are loaded into the namespace.

It can be consistently reproduced:

  1. Setup a new project
brownie init reproducer
cd reproducer
  1. Create a simple contract in contracts/HelloWorld.sol:
pragma solidity ^0.8.0;

import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

contract HelloWorld {
    string public message;

    constructor(string memory initMessage) {
        message = initMessage;
    }
}
  1. Add remapping for external dependency in brownie-config.yaml:
compiler:
  solc:
    remappings:
    - "@openzeppelin=node_modules/@openzeppelin"
  1. Install external dependency:
npm i @openzeppelin/contracts
  1. Run the following script with brownie run scripts/reproducer.py:
import brownie


def main():
    try:
        getattr(brownie.project.ReproducerProject, "ERC1967Proxy")
        print("GOOD")
    except AttributeError:
        print(f"BAD {dir(brownie.project.ReproducerProject)}")
  1. It should print "GOOD". Run it again: brownie run scripts/reproducer.py and it should print "BAD" followed by the listing of project attributes.

  2. Remove the build directory and run again, it prints "GOOD"

How can it be fixed?

I've been looking at the code but am not sure how to fix it. The problem seems to have been introduced by #1411

Up until then, because all the contracts were always compiled all imported contracts were also loaded into the project.

If someone can point me in the right direction I may be able to provide a working patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant