Skip to content

Commit

Permalink
Merge pull request #52 from cyberthirst/fork/charles-cooper/feat/impr…
Browse files Browse the repository at this point in the history
…ove-event-kwargs-recommendation

add tests for event kwargs hint
  • Loading branch information
charles-cooper authored Dec 6, 2024
2 parents 3c98587 + 6550ac6 commit fe34000
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/functional/syntax/test_event_kwarg_hint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import warnings

import pytest

from vyper.compiler import compile_code


def test_event_kwarg_hint():
code = """
from ethereum.ercs import IERC20
def foo():
log IERC20.Transfer(msg.sender, msg.sender, 123)
"""

with warnings.catch_warnings(record=True) as w:
assert compile_code(code) is not None

expected = "Instantiating events with positional arguments is deprecated "
expected += "as of v0.4.1 and will be disallowed in a future release. "
expected += "Use kwargs instead e.g.:\n"
expected += "```\nIERC20.Transfer(sender=msg.sender, receiver=msg.sender, value=123)\n```"

assert len(w) == 1, [s.message for s in w]
assert str(w[0].message).startswith(expected)


# https://github.com/vyperlang/vyper/pull/4275#issuecomment-2394910693
# explains the xfail
@pytest.mark.xfail(raises=AssertionError)
def test_event_hint_single_char_argument():
code = """
from ethereum.ercs import IERC20
def foo():
log IERC20.Transfer(msg.sender, msg.sender, 1)
"""

with warnings.catch_warnings(record=True) as w:
assert compile_code(code) is not None

expected = "Instantiating events with positional arguments is deprecated "
expected += "as of v0.4.1 and will be disallowed in a future release. "
expected += "Use kwargs instead e.g.:\n"
expected += "```\nIERC20.Transfer(sender=msg.sender, receiver=msg.sender, value=1)\n```"

assert len(w) == 1, [s.message for s in w]
assert str(w[0].message).startswith(expected)

0 comments on commit fe34000

Please sign in to comment.