Skip to content

Commit

Permalink
fix: vyper pcMap generation, better solution
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed May 28, 2022
1 parent b4ffca2 commit fc08501
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions brownie/project/compiler/vyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,7 @@ def _generate_coverage_data(
if pc_list[-1]["op"] not in ("JUMPI", "REVERT"):
continue

try:
node = _find_node_by_offset(ast_json, offset)
except StopIteration:
# TODO in vyper >0.3.3 this sometimes fails - unsure if the issue is in brownie or vyper
continue
node = _find_node_by_offset(ast_json, offset)

if pc_list[-1]["op"] == "REVERT" or _is_revert_jump(pc_list[-2:], revert_pc):
# custom revert error strings
Expand Down Expand Up @@ -422,14 +418,18 @@ def _convert_src(src: str) -> Tuple[int, int]:


def _find_node_by_offset(ast_json: List, offset: Tuple) -> Dict:
node = next(i for i in ast_json if is_inside_offset(offset, _convert_src(i["src"])))
if _convert_src(node["src"]) == offset:
return node
node_list = [i for i in node.values() if isinstance(i, dict) and "ast_type" in i]
node_list.extend([x for i in node.values() if isinstance(i, list) for x in i])
if node_list:
return _find_node_by_offset(node_list, offset)
return _find_node_by_offset(ast_json[ast_json.index(node) + 1 :], offset)
for node in [i for i in ast_json if is_inside_offset(offset, _convert_src(i["src"]))]:
if _convert_src(node["src"]) == offset:
return node
node_list = [i for i in node.values() if isinstance(i, dict) and "ast_type" in i]
node_list.extend([x for i in node.values() if isinstance(i, list) for x in i])
if node_list:
result = _find_node_by_offset(node_list, offset)
else:
result = _find_node_by_offset(ast_json[ast_json.index(node) + 1 :], offset)
if result is not None:
return result
return None


def _get_statement_nodes(ast_json: List) -> List:
Expand Down

0 comments on commit fc08501

Please sign in to comment.