Skip to content

Commit

Permalink
codegen tests
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Apr 12, 2024
1 parent dcc4449 commit 8773519
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 58 deletions.
78 changes: 78 additions & 0 deletions tests/functional/codegen/modules/test_exports.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import pytest

from vyper.compiler import compile_code


def test_simple_export(make_input_bundle, get_contract):
lib1 = """
@external
Expand Down Expand Up @@ -147,3 +152,76 @@ def foo() -> uint256:
c = get_contract(main, input_bundle=input_bundle)

assert c.foo() == 5


@pytest.fixture
def simple_library(make_input_bundle):
ifoo = """
@external
def foo() -> uint256:
...
@external
def bar() -> uint256:
...
"""
ibar = """
@external
def bar() -> uint256:
...
@external
def qux() -> uint256:
...
"""
lib1 = """
import ifoo
import ibar
implements: ifoo
implements: ibar
@external
def foo() -> uint256:
return 1
@external
def bar() -> uint256:
return 2
@external
def qux() -> uint256:
return 3
"""
return make_input_bundle({"lib1.vy": lib1, "ifoo.vyi": ifoo, "ibar.vyi": ibar})


def test_exports_interface_simple(get_contract, simple_library):
main = """
import lib1
exports: lib1.__interface__
"""
c = get_contract(main, input_bundle=simple_library)
assert c.foo() == 1
assert c.bar() == 2
assert c.qux() == 3


def test_exports_interface2(get_contract, simple_library):
main = """
import lib1
exports: lib1.ifoo
"""
out = compile_code(
main, output_formats=["abi"], contract_path="main.vy", input_bundle=simple_library
)
fnames = [item["name"] for item in out["abi"]]
assert fnames == ["foo", "bar"]

c = get_contract(main, input_bundle=simple_library)
assert c.foo() == 1
assert c.bar() == 2
# TODO: check the selector table too
assert not hasattr(c, "qux")
58 changes: 0 additions & 58 deletions tests/functional/syntax/modules/test_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,61 +309,3 @@ def bar():
assert e.value.prev_decl.col_offset == 9
assert e.value.prev_decl.node_source_code == "lib1.foo"
assert e.value.prev_decl.module_node.path == "main.vy"


@pytest.fixture
def simple_library(make_input_bundle):
iface = """
@external
def foo() -> uint256:
...
@external
def bar() -> uint256:
...
"""
lib1 = """
import ilib
implements: ilib
@external
def foo() -> uint256:
return 1
@external
def bar() -> uint256:
return 2
"""
return make_input_bundle({"lib1.vy": lib1, "ilib.vyi": iface})


def test_exports_interface_simple(simple_library):
main = """
import lib1
exports: lib1.__interface__
"""
out = compile_code(
main,
output_formats=["abi", "ast_dict"],
contract_path="main.vy",
input_bundle=simple_library,
)
fnames = [item["name"] for item in out["abi"]]
assert fnames == ["foo", "bar"]


def test_exports_interface2(simple_library):
main = """
import lib1
exports: lib1.ilib
"""
out = compile_code(
main,
output_formats=["abi", "ast_dict"],
contract_path="main.vy",
input_bundle=simple_library,
)
fnames = [item["name"] for item in out["abi"]]
assert fnames == ["foo", "bar"]

0 comments on commit 8773519

Please sign in to comment.