forked from vyperlang/vyper
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from cyberthirst/fork/charles-cooper/feat/impr…
…ove-event-kwargs-recommendation add tests for event kwargs hint
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |