Skip to content

Commit

Permalink
feat: update tests to support 0.3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
z80dev committed Oct 24, 2023
1 parent 9b05ad3 commit 70f21c9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ape_vyper/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ def _get_pcmap(bytecode: Dict) -> PCMap:
error_str = RuntimeErrorType.FALLBACK_NOT_DEFINED.value
use_loc = False
elif "bad calldatasize or callvalue" in error_type:
# Only on >=0.3.10rc3.
# Only on >=0.3.10.
# NOTE: We are no longer able to get Nonpayable checks errors since they
# are now combined.
error_str = RuntimeErrorType.INVALID_CALLDATA_OR_VALUE.value
Expand Down
2 changes: 1 addition & 1 deletion ape_vyper/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(self, **kwargs):

class InvalidCalldataOrValueError(VyperRuntimeError):
"""
Raises on Vyper versions >= 0.3.10rc3 in place of NonPayableError.
Raises on Vyper versions >= 0.3.10 in place of NonPayableError.
"""

def __init__(self, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
"0.3.4",
"0.3.7",
"0.3.9",
"0.3.10rc3",
"0.3.10",
)

CONTRACT_VERSION_GEN_MAP = {
"": (
"0.3.7",
"0.3.9",
"0.3.10rc3",
"0.3.10",
),
"sub_reverts": ALL_VERSIONS,
}
Expand Down Expand Up @@ -188,7 +188,7 @@ def account():
return ape.accounts.test_accounts[0]


@pytest.fixture(params=("037", "039", "0310rc3"))
@pytest.fixture(params=("037", "039", "0310"))
def traceback_contract(request, account, project, geth_provider):
return _get_tb_contract(request.param, project, account)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @version 0.3.9
# @version 0.3.10

# Test dev messages in various code placements
@external
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ape_reverts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def older_reverts_contract(account, project, geth_provider, request):
return container.deploy(sender=account)


@pytest.fixture(params=("037", "039", "0310rc3"))
@pytest.fixture(params=("037", "039", "0310"))
def reverts_contract_instance(account, project, geth_provider, request):
sub_reverts_container = project.get_contract(f"sub_reverts_{request.param}")
sub_reverts = sub_reverts_container.deploy(sender=account)
Expand Down
16 changes: 11 additions & 5 deletions tests/test_compiler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import pprint

import pytest
from ape.exceptions import ContractLogicError
Expand All @@ -21,7 +22,7 @@

OLDER_VERSION_FROM_PRAGMA = Version("0.2.16")
VERSION_37 = Version("0.3.7")
VERSION_FROM_PRAGMA = Version("0.3.9")
VERSION_FROM_PRAGMA = Version("0.3.10")


@pytest.fixture
Expand Down Expand Up @@ -80,7 +81,9 @@ def test_get_version_map(project, compiler, all_versions):
x for x in project.contracts_folder.iterdir() if x.is_file() and x.suffix == ".vy"
]
actual = compiler.get_version_map(vyper_files)
pprint.pprint(actual)
expected_versions = [Version(v) for v in all_versions]
pprint.pprint(expected_versions)

for version, sources in actual.items():
if version in expected_versions:
Expand All @@ -98,12 +101,15 @@ def test_get_version_map(project, compiler, all_versions):
"contract_with_dev_messages.vy",
"erc20.vy",
"use_iface.vy",
"optimize_codesize.vy",
"use_iface2.vy",
"contract_no_pragma.vy", # no pragma should compile with latest version
"empty.vy", # empty file still compiles with latest version
]

# Add the 0.3.9 contracts.
# Add the 0.3.10 contracts.
for template in TEMPLATES:
expected.append(f"{template}_039.vy")
expected.append(f"{template}_0310.vy")

names = [x.name for x in actual[VERSION_FROM_PRAGMA]]
failures = []
Expand Down Expand Up @@ -263,7 +269,7 @@ def line(cont: str) -> int:
if nonpayable_checks:
assert len(nonpayable_checks) >= 1
else:
# NOTE: Vyper 0.3.10rc3 doesn't have these anymore.
# NOTE: Vyper 0.3.10 doesn't have these anymore.
# But they do have a new error type instead.
checks = _all(RuntimeErrorType.INVALID_CALLDATA_OR_VALUE)
assert len(checks) >= 1
Expand Down Expand Up @@ -322,7 +328,7 @@ def test_enrich_error_int_overflow(geth_provider, traceback_contract, account):


def test_enrich_error_non_payable_check(geth_provider, traceback_contract, account):
if traceback_contract.contract_type.name.endswith("0310rc3"):
if traceback_contract.contract_type.name.endswith("0310"):
# NOTE: Nonpayable error is combined with calldata check now.
with pytest.raises(InvalidCalldataOrValueError):
traceback_contract.addBalance(123, sender=account, value=1)
Expand Down

0 comments on commit 70f21c9

Please sign in to comment.