Skip to content

Commit

Permalink
Add test with AST fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
z80dev committed Oct 28, 2023
1 parent bfb7986 commit d3bc93b
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions tests/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,23 @@ def foo():
assert len(references) == 0


def test_find_nodes_referencing_constant_folded(ast):
src = """
x: constant(uint256) = 10 ** 2
y: uint256
@external
def foo():
self.y = x
"""
ast.build_ast(src)
references = ast.find_nodes_referencing_constant("x")
assert len(references) == 1
assert (
references[0].lineno == 7
) # line number of self.y = x, counting first newline


def test_find_nodes_referencing_enum(ast):
src = """
enum Foo:
Expand All @@ -199,10 +216,14 @@ def test_find_nodes_referencing_enum(ast):
def foo():
x: Foo = Foo.Bar
y: Foo = Foo.Baz
@external
def bar() -> Foo:
return Foo.Bar
"""
ast.build_ast(src)
references = ast.find_nodes_referencing_enum("Foo")
assert len(references) == 4
assert len(references) == 6
assert references[0].lineno == 8 # line number of self.Bar, counting first newline
assert references[3].lineno == 9 # line number of self.Baz, counting first newline

Expand Down Expand Up @@ -237,10 +258,14 @@ def test_find_nodes_referencing_struct(ast):
@external
def foo():
x: Foo = Foo({bar: 123, baz: msg.sender})
@external
def bar() -> Foo:
return Foo({bar: 123, baz: msg.sender})
"""
ast.build_ast(src)
references = ast.find_nodes_referencing_struct("Foo")
assert len(references) == 2
assert len(references) == 4
assert (
references[0].lineno == 8
) # line number of x: Foo = Foo, counting first newline
Expand Down

0 comments on commit d3bc93b

Please sign in to comment.