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

Raise exception on internal payable function declaration #3123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 15 additions & 1 deletion tests/parser/features/decorators/test_payable.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper.exceptions import CallViolation
from vyper.exceptions import CallViolation, FunctionDeclarationException


@pytest.mark.parametrize(
Expand Down Expand Up @@ -369,3 +369,17 @@ def __default__():
assert_tx_failed(
lambda: w3.eth.send_transaction({"to": c.address, "value": 100, "data": "0x12345678"})
)


def test_invalid_conflicting_decorators(get_contract, assert_compile_failed):
assert_compile_failed(
lambda: get_contract(
"""
@internal
@payable
def foo():
pass
"""
),
FunctionDeclarationException,
)
6 changes: 6 additions & 0 deletions vyper/semantics/types/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ def from_FunctionDef(
if kwargs["state_mutability"] == StateMutability.PURE and "nonreentrant" in kwargs:
raise StructureException("Cannot use reentrancy guard on pure functions", node)

if (
kwargs["state_mutability"] == StateMutability.PAYABLE
and kwargs["function_visibility"] == FunctionVisibility.INTERNAL
):
raise FunctionDeclarationException("Internal functions can't be payable", node)

# call arguments
if node.args.defaults and node.name == "__init__":
raise FunctionDeclarationException(
Expand Down