anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: eth-brownie/brownie
Issue: Key error when compiling with ABIEncoderV2 on solidity >= 0.7.2

### Environment information
```
Brownie v1.12.2 - Python development framework for Ethereum
Compiling contracts...
  Solc version: 0.7.2
  Optimizer: Enabled  Runs: 200
  EVM Version: Istanbul
Generating build data...
 - Test
  File "brownie/_cli/__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "brownie/_cli/compile.py", line 50, in main
    proj = project.load()
  File "brownie/project/main.py", line 725, in load
    return Project(name, project_path)
  File "brownie/project/main.py", line 174, in __init__
    self.load()
  File "brownie/project/main.py", line 227, in load
    self._compile(changed, self._compiler_config, False)
  File "brownie/project/main.py", line 90, in _compile
    build_json = compiler.compile_and_format(
  File "brownie/project/compiler/__init__.py", line 142, in compile_and_format
    build_json.update(generate_build_json(input_json, output_json, compiler_data, silent))
  File "brownie/project/compiler/__init__.py", line 313, in generate_build_json
    build_json[contract_alias] = solidity._get_unique_build_json(
  File "brownie/project/compiler/solidity.py", line 246, in _get_unique_build_json
    pc_map, statement_map, branch_map = _generate_coverage_data(
  File "brownie/project/compiler/solidity.py", line 369, in _generate_coverage_data
    active_source_node = source_nodes[contract_id]
KeyError: '1'
```

* `brownie` Version: 1.12.2
* `solc` Version: 0.7.2 to 0.7.5
* Python Version: 3.8
* OS: linux

### What was wrong?
Compiling this contract results in the error above:
```
pragma solidity >0.7.0;
pragma experimental ABIEncoderV2;

contract Test {
    function test() external view returns (uint256) {
        return 1;
    }
}
```

Removing the `pragma experimental ABIEncoderV2;` succeeds.
Changing the function to internal succeeds.
Changing the solc compiler to 0.7.1 succeeds (issue seems to appear on 0.7.2 and above)

Changed files:
brownie/project/compiler/solidity.py

diff --git a/brownie/project/compiler/solidity.py b/brownie/project/compiler/solidity.py
index bf5fca94..9fbac642 100644
--- a/brownie/project/compiler/solidity.py
+++ b/brownie/project/compiler/solidity.py
@@ -366,6 +366,12 @@ def _generate_coverage_data(
 
         # set contract path (-1 means none)
         contract_id = str(source[2])
+        if contract_id not in source_nodes:
+            # In Solidity >=0.7.2 contract ID can reference an AST within the YUL-optimization
+            # "generatedSources". Brownie does not support coverage evaluation within these
+            # sources, so we consider to this to be unmapped.
+            continue
+
         active_source_node = source_nodes[contract_id]
         pc_list[-1]["path"] = contract_id
Repository: eth-brownie/brownie
Issue: Nonpayable function heuristic is broken for vyper 0.2.5

### What was wrong?
Vyper 0.2.5 has added an optimization for reverting on nonpayable contracts: https://github.com/vyperlang/vyper/pull/2172 This breaks the existing heuristic.

### How can it be fixed?
Adjust the heuristic in `project/compiler/vyper.py`.

Changed files:
tests/network/transaction/test_revert_msg.py, brownie/project/compiler/vyper.py

diff --git a/brownie/project/compiler/vyper.py b/brownie/project/compiler/vyper.py
index 4554940c..5216a688 100644
--- a/brownie/project/compiler/vyper.py
+++ b/brownie/project/compiler/vyper.py
@@ -339,6 +339,11 @@ def _generate_coverage_data(
 
     pc_list[0]["path"] = "0"
     pc_list[0]["offset"] = [0, _convert_src(ast_json[-1]["src"])[1]]
+
+    if len(pc_list) > 7 and pc_list[0]["op"] == "CALLVALUE" and pc_list[6]["op"] == "REVERT":
+        # special case - initial nonpayable check on vyper >=0.2.5
+        pc_list[6]["dev"] = "Cannot send ether to nonpayable function"
+
     pc_map = dict((i.pop("pc"), i) for i in pc_list)
 
     return pc_map, {"0": statement_map}, {"0": branch_map}
diff --git a/tests/network/transaction/test_revert_msg.py b/tests/network/transaction/test_revert_msg.py
index 02f2688b..6395b8fc 100644
--- a/tests/network/transaction/test_revert_msg.py
+++ b/tests/network/transaction/test_revert_msg.py
@@ -153,5 +153,5 @@ def test_deployment_size_limit(accounts, console_mode):
 def baz():
     assert msg.sender != ZERO_ADDRESS, '{'blah'*10000}'
     """
-    tx = compile_source(code, vyper_version="").Vyper.deploy({"from": accounts[0]})
+    tx = compile_source(code, vyper_version="0.2.4").Vyper.deploy({"from": accounts[0]})
     assert tx.revert_msg == "exceeds EIP-170 size limit"
Repository: eth-brownie/brownie
Issue: `brownie bake` fails if the mix name capitalization does not match exactly

### Environment information

* `brownie` Version: 1.11.10
* `ganache-cli` Version: v6.9.1 (ganache-core: 2.10.2)
* `solc` Version: 0.7.4
* Python Version: 3.8.6
* OS: linux

### What was wrong?
Simply running `brownie bake` fails if the mix name is improperly capitalized.

```bash
brownie bake Token
```
Output:
```
Brownie v1.11.10 - Python development framework for Ethereum

Downloading from https://github.com/brownie-mix/Token-mix/archive/master.zip...
9.13kiB [00:00, 3.79MiB/s]
  File "brownie/_cli/__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "brownie/_cli/bake.py", line 26, in main
    path = project.from_brownie_mix(args["<mix>"], args["<path>"], args["--force"])
  File "brownie/project/main.py", line 577, in from_brownie_mix
    project_path.parent.joinpath(project_name + "-mix-master").rename(project_path)
  File "/usr/lib/python3.8/pathlib.py", line 1361, in rename
    self._accessor.rename(self, target)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/Token-mix-master' -> '/tmp/Token'
```

### How can it be fixed?
`brownie` should either normalize the name to lower case or (if the case could be significant) report that such a mix does not exist, hinting at the case as a possible cause.

Changed files:
brownie/project/main.py

diff --git a/brownie/project/main.py b/brownie/project/main.py
index 4aeabbf8..24e28b6d 100644
--- a/brownie/project/main.py
+++ b/brownie/project/main.py
@@ -564,7 +564,7 @@ def from_brownie_mix(
 
     Returns the path to the project as a string.
     """
-    project_name = str(project_name).replace("-mix", "")
+    project_name = str(project_name).lower().replace("-mix", "")
     url = MIXES_URL.format(project_name)
     if project_path is None:
         project_path = Path(".").joinpath(project_name)
Repository: eth-brownie/brownie
Issue: Unable to compile dependency

### Environment information

* `brownie` Version: 1.11.12 / 3fad0bdc7a65cd1c27d23c0dda4a5276f7255670 (locally)
* `ganache-cli` Version: N/A
* `solc` Version: 0.6.12
* Python Version: 3.8.6
* OS: osx

### What was wrong?
I am trying to add a dependency to another project and I am getting:
```
WARNING: Unable to compile Macarse/GenericKeep3rV2@0.0.1 due to a FileNotFoundError - you may still be able to import sources from the package, but will be unable to load the package directly.
```
Dependency is https://github.com/Macarse/GenericKeep3rV2/releases/tag/0.0.1

Please include information like:
I run brownie locally to find out more.
I added a `print(str(e))` to the warning  and the apparent file missing is: `interfaces/IKeep3rV1.sol`

I kept looking at the brownie code and found the exception happening at:
`changed_sources = {i: self._sources.get(i) for i in changed_paths}` in the `_compile_interfaces` method.
I tried shuffling the `changed_sources` array and all of them seem to be failing.

No idea what the `change_sources` is for.
Any idea what can be wrong?


Changed files:
brownie/project/sources.py

diff --git a/brownie/project/sources.py b/brownie/project/sources.py
index bb05f7bc..ebf3e434 100644
--- a/brownie/project/sources.py
+++ b/brownie/project/sources.py
@@ -72,14 +72,16 @@ class Sources:
 
         if key in self._contracts:
             return self._contract_sources[self._contracts[key]]
-
-        if key not in self._contract_sources:
-            # for sources outside this project (packages, other projects)
-            with Path(key).open() as fp:
-                source = fp.read()
-                self._contract_sources[key] = source
-
-        return self._contract_sources[key]
+        if key in self._contract_sources:
+            return self._contract_sources[key]
+        if key in self._interface_sources:
+            return self._interface_sources[key]
+
+        # for sources outside this project (packages, other projects)
+        with Path(key).open() as fp:
+            source = fp.read()
+            self._contract_sources[key] = source
+            return source
 
     def get_path_list(self) -> List:
         """Returns a sorted list of source code file paths for the active project."""
Repository: eth-brownie/brownie
Issue: ValueError: invalid literal for int() with base 16: '0x'

### Environment information

* `brownie` Version: master
* `ganache-cli` Version:  v6.12.2 (ganache-core: 2.13.2)
* `solc` Version: N/A
* Python Version: 3.8.6
* OS: osx and linux

### What was wrong?
I was helping a friend set up the env in windows and got the following error from the console
```
Brownie environment is ready.
>>> weth = Contract("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
  File "<console>", line 1, in <module>
  File "eth_brownie-1.13.0-py3.8.egg/brownie/network/contract.py", line 923, in __init__
    contract = self.from_explorer(address, owner=owner, silent=True)
  File "eth_brownie-1.13.0-py3.8.egg/brownie/network/contract.py", line 1102, in from_explorer
    if int(implementation_eip1967.hex(), 16):
ValueError: invalid literal for int() with base 16: '0x'
```

### How can it be fixed?
I will send a PR :)


Changed files:
brownie/network/contract.py

diff --git a/brownie/network/contract.py b/brownie/network/contract.py
index 6a90bbfe..174f6b1e 100644
--- a/brownie/network/contract.py
+++ b/brownie/network/contract.py
@@ -1099,9 +1099,9 @@ class Contract(_DeployedContractBase):
             )
             # always check for an EIP1822 proxy - https://eips.ethereum.org/EIPS/eip-1822
             implementation_eip1822 = web3.eth.getStorageAt(address, web3.keccak(text="PROXIABLE"))
-            if int(implementation_eip1967.hex(), 16):
+            if len(implementation_eip1967) > 0 and int(implementation_eip1967.hex(), 16):
                 as_proxy_for = _resolve_address(implementation_eip1967[12:])
-            elif int(implementation_eip1822.hex(), 16):
+            elif len(implementation_eip1822) > 0 and int(implementation_eip1822.hex(), 16):
                 as_proxy_for = _resolve_address(implementation_eip1822[12:])
             elif data["result"][0].get("Implementation"):
                 # for other proxy patterns, we only check if etherscan indicates
Repository: eth-brownie/brownie
Issue: Cant't deploy contract properly on BSC

### Environment information

* `brownie` Version: 14.2
* Python Version: 3.8.5
* OS: MacOS Big Sur (Tried on a Debian VPS too)

### What was wrong?

After thorough testing on BSC-main-fork and testnet, where everything works seamlessly, I deployed my contracts on Bsc-Mainnet. I have two contracts : token and master (of the token).

Compiling is OK, Token deployment works, but not Master where I'm stuck on a perpetual "Waiting for confirmation..." :

```python
master = Master.deploy(token.address, {"from":acct}, publish_source=True)
```

```
Transaction sent: 0x4f29f5b3a26a0eab08ae90756e24942154c0219076623afc7d9ecc0905e3f73c
  Gas price: 10.0 gwei   Gas limit: 2384969   Nonce: 6
Waiting for confirmation... 
````
Here's the log : https://bscscan.com/tx/0x4f29f5b3a26a0eab08ae90756e24942154c0219076623afc7d9ecc0905e3f73c

I've tried to start another session console and recover the deployed contract using the abi with Master.at([address]), but then Brownie just freezes.

Do you have any idea what is happening ? Could it be a RPC problem ?

[edit] : I deployed it through Truffle and verified it. Interestingly enough, running this freezes Brownie too :
```python
master = Contract.from_explorer("0x6E8d868F4a973F198162d638b6970f657B51f0c4")
````


Changed files:
brownie/network/middlewares/caching.py

diff --git a/brownie/network/middlewares/caching.py b/brownie/network/middlewares/caching.py
index e584ddd6..d379e0dc 100644
--- a/brownie/network/middlewares/caching.py
+++ b/brownie/network/middlewares/caching.py
@@ -111,6 +111,12 @@ class RequestCachingMiddleware(BrownieMiddlewareABC):
     @classmethod
     def get_layer(cls, w3: Web3, network_type: str) -> Optional[int]:
         if network_type == "live":
+            try:
+                # ensure that the node client supports filters
+                block_filter = w3.eth.filter("latest")
+                block_filter.get_new_entries()
+            except ValueError:
+                return None
             return 0
         else:
             return None
Repository: eth-brownie/brownie
Issue: __repr__ bug in brownie console

### Environment information

* `brownie` Version: 1.14.2
* `ganache-cli` Version: N/A
* `solc` Version: 0.6.0
* Python Version: 3.8.5
* OS: osx

### What was wrong?


I encountered RecursionError in brownie console after executing `globals()` to inspect what variables there are for me to use.  Here is the error message.


```
>>> globals()
  File "brownie/_cli/__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "brownie/_cli/console.py", line 59, in main
    shell.interact(banner="Brownie environment is ready.", exitmsg="")
  File "brownie/_cli/console.py", line 205, in interact
    super().interact(*args, **kwargs)
  File "/Users/derek/opt/miniconda3/lib/python3.8/code.py", line 232, in interact
    more = self.push(line)
  File "/Users/derek/opt/miniconda3/lib/python3.8/code.py", line 258, in push
    more = self.runsource(source, self.filename)
  File "brownie/_cli/console.py", line 250, in runsource
    self._console_write(self.locals["__ret_value__"])
  File "brownie/_cli/console.py", line 191, in _console_write
    text = color.pretty_dict(obj)
  File "brownie/utils/color.py", line 87, in pretty_dict
    text += "{" + self.pretty_dict(value[k], _indent)
  File "brownie/utils/color.py", line 87, in pretty_dict
    text += "{" + self.pretty_dict(value[k], _indent)
  File "brownie/utils/color.py", line 87, in pretty_dict
    text += "{" + self.pretty_dict(value[k], _indent)
  File line, line 983, in times]
  File "brownie/utils/color.py", line 92, in pretty_dict
    text += self._write(value[k])
  File "brownie/utils/color.py", line 120, in _write
    return f"{s}{value}{s}"
  File "<frozen, line line, in in
RecursionError: maximum recursion depth exceeded while getting the repr of an object

```


### How can it be fixed?

I am new to brownie and not sure what specifically causes this error.


Changed files:
brownie/_cli/console.py

diff --git a/brownie/_cli/console.py b/brownie/_cli/console.py
index ec349234..98829188 100644
--- a/brownie/_cli/console.py
+++ b/brownie/_cli/console.py
@@ -248,8 +248,8 @@ class Console(code.InteractiveConsole):
             pass
         self.runcode(code)
         if "__ret_value__" in self.locals and self.locals["__ret_value__"] is not None:
-            self._console_write(self.locals["__ret_value__"])
-            del self.locals["__ret_value__"]
+            return_value = self.locals.pop("__ret_value__")
+            self._console_write(return_value)
         return False
 
     def paste_event(self, event):
Repository: eth-brownie/brownie
Issue: `StopIteration` on show traceback with passing test

### Environment information

* `brownie` Version: 1.12.3
* `ganache-cli` Version: 6.12.1
* Python Version: 3.8.6
* OS: linux

### What was wrong?
```python
self = <Transaction '0x01f9dddc187e040669e200b5ee7abf6806b542ae5cbe856c19dcae22e669c2d2'>            
                                                                                                     
    @trace_inspection                                                                                
    def _traceback_string(self) -> str:                                                              
        """Returns an error traceback for the transaction."""                                        
        if self.status == 1:                                                                         
            return ""                                                                                
        trace = self.trace                                                                           
                                                                                                     
        try:                                                                                         
            idx = next(i for i in range(len(trace)) if trace[i]["op"] in ("REVERT", "INVALID"))       
            trace_range = range(idx, -1, -1)
        except StopIteration:                      
            return ""
                                                                                                     
>       result = [next(i for i in trace_range if trace[i]["source"])]                                 
E       StopIteration 
```

If I change this to catch the `StopIeration` exception and return `""` instead, there is no further issue with the test. Not sure if this is a false positive, or if the exception is the problem.

Changed files:
brownie/network/transaction.py

diff --git a/brownie/network/transaction.py b/brownie/network/transaction.py
index 0f61acde..16d2f947 100644
--- a/brownie/network/transaction.py
+++ b/brownie/network/transaction.py
@@ -716,8 +716,8 @@ class TransactionReceipt:
                     self._dev_revert_msg = ""
                 return
 
-        step = next(i for i in trace[::-1] if i["op"] in ("REVERT", "INVALID"))
-        self._revert_msg = "invalid opcode" if step["op"] == "INVALID" else ""
+        op = next((i["op"] for i in trace[::-1] if i["op"] in ("REVERT", "INVALID")), None)
+        self._revert_msg = "invalid opcode" if op == "INVALID" else ""
 
     def _expand_trace(self) -> None:
         """Adds the following attributes to each step of the stack trace:
@@ -1101,7 +1101,10 @@ class TransactionReceipt:
         except StopIteration:
             return ""
 
-        result = [next(i for i in trace_range if trace[i]["source"])]
+        try:
+            result = [next(i for i in trace_range if trace[i]["source"])]
+        except StopIteration:
+            return ""
         depth, jump_depth = trace[idx]["depth"], trace[idx]["jumpDepth"]
 
         while True:
Repository: eth-brownie/brownie
Issue: TypeError on running 'brownie bake token'

_Originally posted by @rattle99 as https://github.com/brownie-mix/token-mix/issues/3..._

```
Ubuntu 18.04.4 LTS
Python 3.6.9
```
Running `brownie bake token` returns error.
```
Brownie v1.9.7 - Python development framework for Ethereum

Downloading from https://github.com/brownie-mix/token-mix/archive/master.zip...
110iB [00:00, 5.47kiB/s]
  File "brownie/_cli/__main__.py", line 56, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "brownie/_cli/bake.py", line 26, in main
    path = project.from_brownie_mix(args["<mix>"], args["<path>"], args["--force"])
  File "brownie/project/main.py", line 571, in from_brownie_mix
    _stream_download(url, str(project_path.parent))
  File "brownie/project/main.py", line 876, in _stream_download
    content += data
TypeError: can't concat str to bytes
```

Changed files:
brownie/project/main.py

diff --git a/brownie/project/main.py b/brownie/project/main.py
index fd6ba759..715055dd 100644
--- a/brownie/project/main.py
+++ b/brownie/project/main.py
@@ -867,6 +867,18 @@ def _load_sources(project_path: Path, subfolder: str, allow_json: bool) -> Dict:
 
 def _stream_download(download_url: str, target_path: str) -> None:
     response = requests.get(download_url, stream=True, headers=REQUEST_HEADERS)
+
+    if response.status_code == 404:
+        raise ConnectionError(
+            f"404 error when attempting to download from {download_url} - "
+            "are you sure this is a valid mix? https://github.com/brownie-mix"
+        )
+    if response.status_code != 200:
+        raise ConnectionError(
+            f"Received status code {response.status_code} when attempting "
+            f"to download from {download_url}"
+        )
+
     total_size = int(response.headers.get("content-length", 0))
     progress_bar = tqdm(total=total_size, unit="iB", unit_scale=True)
     content = bytes()
Repository: eth-brownie/brownie
Issue: ReturnValue should be hashable

```
>>> r = ReturnValue([0, 1, 2])
>>> set(r)
TypeError: unhashable type: 'ReturnValue'
```

`ReturnValue` is subclassed from`tuple`, this shouldn't be happening. Along with fixing, we should write unit tests to verify the tuple-ness of `ReturnValue`.

Changed files:
tests/network/test_return_value.py, brownie/convert.py

diff --git a/brownie/convert.py b/brownie/convert.py
index 624f6582..2e75f50f 100644
--- a/brownie/convert.py
+++ b/brownie/convert.py
@@ -355,6 +355,9 @@ class ReturnValue(tuple):
             self._dict[i['name']] = values[c]
         return self
 
+    def __hash__(self):
+        return super().__hash__()
+
     def __eq__(self, other):
         return _kwargtuple_compare(self, other)
 
diff --git a/tests/network/test_return_value.py b/tests/convert/test_return_value.py
similarity index 95%
rename from tests/network/test_return_value.py
rename to tests/convert/test_return_value.py
index 49d09fd3..d3b986de 100644
--- a/tests/network/test_return_value.py
+++ b/tests/convert/test_return_value.py
@@ -112,3 +112,8 @@ def test_hexstring_length(return_value):
     b = HexString('0x1234', "bytes32")
     assert b == "0x1234"
     assert b == "0x000000000000001234"
+
+
+def test_hashable(return_value):
+    assert hash(ReturnValue([1, 2])) == hash(tuple([1, 2]))
+    assert set(ReturnValue([3, 1, 3, 3, 7])) == set([3, 1, 3, 3, 7])
Repository: eth-brownie/brownie
Issue: 'SourceUnit' object has no attribute 'name' - when trying to fetch a contract from explorer

### Environment information

* `brownie` Version: 1.16.0
* `ganache-cli` Version: 6.12.1
* `solc` Version: 0.8.4+commit.c7e474f2.Darwin.appleclang
* Python Version: 3.9.5
* OS: osx/linux/win MacOS 10.15.7 (19H1217)

### What was wrong?

I was running tests and they were failing, the error was 'SourceUnit' object has no attribute 'name' 

I then tried to run the command:
`Contract.from_explorer("0xBA12222222228d8Ba445958a75a0704d566BF2C8")` 
Getting the same error message: `'SourceUnit' object has no attribute 'name' `
Which tries to fetch the Balancer Vault Contract from Etherscan, this seems to break the emulation


### Full output
```
brownie console

Brownie environment is ready.
>>> Contract.from_explorer("0xBA12222222228d8Ba445958a75a0704d566BF2C8")
Fetching source of 0xBA12222222228d8Ba445958a75a0704d566BF2C8 from api.etherscan.io...
  File "<console>", line 1, in <module>
  File "brownie/network/contract.py", line 1208, in from_explorer
    build_json = compiler.generate_build_json(input_json, output_json)
  File "brownie/project/compiler/__init__.py", line 317, in generate_build_json
    build_json[contract_alias] = solidity._get_unique_build_json(
  File "brownie/project/compiler/solidity.py", line 260, in _get_unique_build_json
    pc_map, statement_map, branch_map = _generate_coverage_data(
  File "brownie/project/compiler/solidity.py", line 451, in _generate_coverage_data
    active_fn_node, active_fn_name = _get_active_fn(active_source_node, offset)
  File "brownie/project/compiler/solidity.py", line 596, in _get_active_fn
    return fn_node, f"{fn_node.parent().name}.{name}"
AttributeError: 'SourceUnit' object has no attribute 'name'
>>>
```

### How can it be fixed?

Not sure, but would just want brownie to run the bytecode without knowing what the contract is

Changed files:
brownie/project/compiler/solidity.py

diff --git a/brownie/project/compiler/solidity.py b/brownie/project/compiler/solidity.py
index a413c521..e244735b 100644
--- a/brownie/project/compiler/solidity.py
+++ b/brownie/project/compiler/solidity.py
@@ -593,6 +593,12 @@ def _get_active_fn(source_node: NodeBase, offset: Tuple[int, int]) -> Tuple[Node
             name = "<constructor>"
         else:
             name = "<fallback>"
+
+    parent = fn_node.parent()
+    if parent.nodeType == "SourceUnit":
+        # the function exists outside a contract
+        return fn_node, name
+
     return fn_node, f"{fn_node.parent().name}.{name}"