In order to debug why I couldn't publish the source of my contracts to Etherscan I ran:
brownie console --network rinkeby
>>> MyContract.get_verification_info()
File "<console>", line 1, in <module>
File "/Users/foo/git/brownie-fork/brownie/network/contract.py", line 299, in get_verification_info
self._flattener = Flattener(source_fp, self._name, remaps, compiler_settings)
File "/Users/foo/git/brownie-fork/brownie/project/flattener.py", line 30, in __init__
self.traverse(primary_source_fp)
File "/Users/foo/git/brownie-fork/brownie/project/flattener.py", line 71, in traverse
self.traverse(import_path)
File "/Users/foo/git/brownie-fork/brownie/project/flattener.py", line 50, in traverse
source = fp_obj.read_text()
File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/pathlib.py", line 1266, in read_text
with self.open(mode='r', encoding=encoding, errors=errors) as f:
File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/pathlib.py", line 1252, in open
return io.open(self, mode, buffering, encoding, errors, newline,
File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/pathlib.py", line 1120, in _opener
return self._accessor.open(self, flags, mode)
FileNotFoundError: [Errno 2] No such file or directory: '/<redacted>/backend/contracts/manifold-extensions/lib/manifoldxyz/libraries-solidity/contracts/access/AdminControlUpgradeable.sol'
Brownie successfully compiles the contracts given the same remappings so it seems to me that the Flattener remaps imports relative to the source file instead of the project root like the compiler does. In my case the Flattener tries to traverse an import that's supposed to be remapped to ./lib/manifoldxyz instead of ./contracts/manifold-extensions/lib/manifoldxyz.
Presumably by fixing the flattener to flatten the same way the compiler does. While looking through the tests, it seems that the verification test passes with imports that aren't remapped elsewhere in the project structure.
Environment information
brownie
Version: 1.18.1ganache
Version: ganache v7.0.3 (@ganache/cli: 0.1.4, @ganache/core: 0.1.4)solc
Version: Solc version: 0.8.11What was wrong?
In order to debug why I couldn't publish the source of my contracts to Etherscan I ran:
brownie console --network rinkeby
I have the following remappings:
brownie-config.yaml
My folder structure is:
Brownie successfully compiles the contracts given the same remappings so it seems to me that the Flattener remaps imports relative to the source file instead of the project root like the compiler does. In my case the Flattener tries to traverse an import that's supposed to be remapped to
./lib/manifoldxyz
instead of./contracts/manifold-extensions/lib/manifoldxyz
.Relevant code appears to be
https://github.com/eth-brownie/brownie/blob/master/brownie/project/flattener.py#L127.
How can it be fixed?
Presumably by fixing the flattener to flatten the same way the compiler does. While looking through the tests, it seems that the verification test passes with imports that aren't remapped elsewhere in the project structure.