-
-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/vyperlang/vyper into feat…
…/const_interface
- Loading branch information
Showing
26 changed files
with
444 additions
and
180 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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
sphinx==4.5.0 | ||
sphinx==5.0.0 | ||
recommonmark==0.6.0 | ||
sphinx_rtd_theme==0.5.2 |
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
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
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
31 changes: 31 additions & 0 deletions
31
tests/functional/codegen/modules/test_interface_imports.py
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,31 @@ | ||
def test_import_interface_types(make_input_bundle, get_contract): | ||
ifaces = """ | ||
interface IFoo: | ||
def foo() -> uint256: nonpayable | ||
""" | ||
|
||
foo_impl = """ | ||
import ifaces | ||
implements: ifaces.IFoo | ||
@external | ||
def foo() -> uint256: | ||
return block.number | ||
""" | ||
|
||
contract = """ | ||
import ifaces | ||
@external | ||
def test_foo(s: ifaces.IFoo) -> bool: | ||
assert s.foo() == block.number | ||
return True | ||
""" | ||
|
||
input_bundle = make_input_bundle({"ifaces.vy": ifaces}) | ||
|
||
foo = get_contract(foo_impl, input_bundle=input_bundle) | ||
c = get_contract(contract, input_bundle=input_bundle) | ||
|
||
assert c.test_foo(foo.address) is True |
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,78 @@ | ||
def test_module_constant(make_input_bundle, get_contract): | ||
mod1 = """ | ||
X: constant(uint256) = 12345 | ||
""" | ||
contract = """ | ||
import mod1 | ||
@external | ||
def foo() -> uint256: | ||
return mod1.X | ||
""" | ||
|
||
input_bundle = make_input_bundle({"mod1.vy": mod1}) | ||
|
||
c = get_contract(contract, input_bundle=input_bundle) | ||
|
||
assert c.foo() == 12345 | ||
|
||
|
||
def test_nested_module_constant(make_input_bundle, get_contract): | ||
# test nested module constants | ||
# test at least 3 modules deep to test the `path.reverse()` gizmo | ||
# in ConstantFolder.visit_Attribute() | ||
mod1 = """ | ||
X: constant(uint256) = 12345 | ||
""" | ||
mod2 = """ | ||
import mod1 | ||
X: constant(uint256) = 54321 | ||
""" | ||
mod3 = """ | ||
import mod2 | ||
X: constant(uint256) = 98765 | ||
""" | ||
|
||
contract = """ | ||
import mod1 | ||
import mod2 | ||
import mod3 | ||
@external | ||
def test_foo() -> bool: | ||
assert mod1.X == 12345 | ||
assert mod2.X == 54321 | ||
assert mod3.X == 98765 | ||
assert mod2.mod1.X == mod1.X | ||
assert mod3.mod2.mod1.X == mod1.X | ||
assert mod3.mod2.X == mod2.X | ||
return True | ||
""" | ||
|
||
input_bundle = make_input_bundle({"mod1.vy": mod1, "mod2.vy": mod2, "mod3.vy": mod3}) | ||
|
||
c = get_contract(contract, input_bundle=input_bundle) | ||
assert c.test_foo() is True | ||
|
||
|
||
def test_import_constant_array(make_input_bundle, get_contract, tx_failed): | ||
mod1 = """ | ||
X: constant(uint256[3]) = [1,2,3] | ||
""" | ||
contract = """ | ||
import mod1 | ||
@external | ||
def foo(ix: uint256) -> uint256: | ||
return mod1.X[ix] | ||
""" | ||
|
||
input_bundle = make_input_bundle({"mod1.vy": mod1}) | ||
|
||
c = get_contract(contract, input_bundle=input_bundle) | ||
|
||
assert c.foo(0) == 1 | ||
assert c.foo(1) == 2 | ||
assert c.foo(2) == 3 | ||
with tx_failed(): | ||
c.foo(3) |
File renamed without changes.
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
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
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 |
---|---|---|
|
@@ -90,7 +90,7 @@ def foo(): nonpayable | |
""" | ||
implements: self.x | ||
""", | ||
StructureException, | ||
InvalidType, | ||
), | ||
( | ||
""" | ||
|
Oops, something went wrong.