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

fix: allow accessing members of constant address #3261

Merged
merged 4 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/parser/features/test_address_balance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def test_constant_address_balance(w3, get_contract_with_gas_estimation):
code = """
a: constant(address) = 0x776Ba14735FF84789320718cf0aa43e91F7A8Ce1

@external
def foo() -> uint256:
x: uint256 = a.balance
return x
"""
address = "0x776Ba14735FF84789320718cf0aa43e91F7A8Ce1"

c = get_contract_with_gas_estimation(code)

assert c.foo() == 0

w3.eth.send_transaction({"to": address, "value": 1337})

assert c.foo() == 1337
9 changes: 0 additions & 9 deletions vyper/semantics/analysis/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ def visit_BoolOp(self, node, type_):
for value in node.values:
self.visit(value)

def visit_Bytes(self, node, type_):
node._metadata["type"] = type_

def visit_Call(self, node, type_):
call_type = get_exact_type_from_node(node.func)
node_type = type_ or call_type.fetch_call_return(node)
Expand Down Expand Up @@ -201,15 +198,9 @@ def visit_Constant(self, node, type_):
def visit_Dict(self, node, type_):
node._metadata["type"] = type_

def visit_Hex(self, node, type_):
node._metadata["type"] = type_

def visit_Index(self, node, type_):
self.visit(node.value, type_)

def visit_Int(self, node, type_):
node._metadata["type"] = type_

def visit_List(self, node, type_):
if type_ is None:
type_ = get_possible_types_from_node(node)
Expand Down