Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create forwarder to #1324

Merged
merged 2 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/built-in-functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,11 @@ Note: To give it a more Python like syntax, the assert function can be called wi

Emits a log without specifying the abi type, with the arguments entered as the first input.

**create_with_code_of**
**create_forwarder_to**
-----------------------
::

def create_with_code_of(a, value=b):
def create_forwarder_to(a, value=b):
"""
:param a: the address of the contract to duplicate.
:type a: address
Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ Following the principles and goals, Vyper **does not** provide the following fea
Compatibility-breaking Changelog
********************************

* **2019.02.14**: Creating a persistent contract address can only be done using the _address_ syntax: `bar_contact: address(ERC20)`.
* **2019.03.04**: `create_with_code_of` has been renamed to `create_forwarder_to`. (`#1177 <https://github.com/ethereum/vyper/issues/1177>`_)
* **2019.02.14**: Assigning a persistent contract address can only be done using the `bar_contact = ERC20(<address>)` syntax.
* **2019.02.12**: ERC20 interface has to be imported using `from vyper.interfaces import ERC20` to use.
* **2019.01.30**: Byte array literals need to be annoted using `b""`, strings are represented as `""`.
* **2018.12.12**: Disallow use of `None`, disallow use of `del`, implemented `clear()` built-in function.
Expand Down
2 changes: 1 addition & 1 deletion tests/parser/exceptions/test_constancy_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def foo() -> int128:
@public
@constant
def foo() -> int128:
x = create_with_code_of(0x1234567890123456789012345678901234567890, value=9)
x = create_forwarder_to(0x1234567890123456789012345678901234567890, value=9)
return 5
""",
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/parser/exceptions/test_invalid_literal_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def foo():
"""
@public
def foo():
x = create_with_code_of(0x123456789012345678901234567890123456789)
x = create_forwarder_to(0x123456789012345678901234567890123456789)
""",
"""
@public
Expand Down
4 changes: 2 additions & 2 deletions tests/parser/exceptions/test_structure_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def foo():
"""
@public
def foo():
x = create_with_code_of(0x1234567890123456789012345678901234567890, b"cow")
x = create_forwarder_to(0x1234567890123456789012345678901234567890, b"cow")
""",
"""
@public
Expand All @@ -108,7 +108,7 @@ def foo():
"""
@public
def foo():
x = create_with_code_of(0x1234567890123456789012345678901234567890, outsize=4)
x = create_forwarder_to(0x1234567890123456789012345678901234567890, outsize=4)
""",
"""
x: public()
Expand Down
2 changes: 1 addition & 1 deletion tests/parser/features/test_assert.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test():
code = """
@public
def test():
assert create_with_code_of(self) == 1
assert create_forwarder_to(self) == 1
"""
assert_compile_failed(lambda: get_contract(code), ConstancyViolationException)

Expand Down
10 changes: 5 additions & 5 deletions tests/parser/functions/test_create_with_code_of.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@


def test_create_with_code_of_create(get_contract):
def test_create_forwarder_to_create(get_contract):
code = """
main: address

@public
def test() -> address:
self.main = create_with_code_of(self)
self.main = create_forwarder_to(self)
return self.main
"""

Expand All @@ -15,7 +15,7 @@ def test() -> address:
assert c.test() == '0x4F9DA333DCf4E5A53772791B95c161B2FC041859'


def test_create_with_code_of_call(get_contract, w3):
def test_create_forwarder_to_call(get_contract, w3):
code = """

contract SubContract:
Expand All @@ -28,7 +28,7 @@ def hello() -> bytes[100]: constant

@public
def test() -> address:
self.other = create_with_code_of(self)
self.other = create_forwarder_to(self)
return self.other


Expand Down Expand Up @@ -63,7 +63,7 @@ def hello(a: uint256) -> bytes[100]: constant

@public
def test() -> address:
self.other = create_with_code_of(self)
self.other = create_forwarder_to(self)
return self.other


Expand Down
12 changes: 6 additions & 6 deletions tests/parser/functions/test_raw_call.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from vyper.functions import get_create_with_code_of_bytecode
from vyper.functions import get_create_forwarder_to_bytecode


def test_caller_code(get_contract_with_gas_estimation):
Expand Down Expand Up @@ -36,21 +36,21 @@ def returnten() -> int128:
outer_code = """
@public
def create_and_call_returnten(inp: address) -> int128:
x: address = create_with_code_of(inp)
x: address = create_forwarder_to(inp)
o: int128 = extract32(raw_call(x, convert("\xd0\x1f\xb1\xb8", bytes[4]), outsize=32, gas=50000), 0, type=int128) # noqa: E501
return o

@public
def create_and_return_forwarder(inp: address) -> address:
x: address = create_with_code_of(inp)
x: address = create_forwarder_to(inp)
return x
"""

c2 = get_contract_with_gas_estimation(outer_code)
assert c2.create_and_call_returnten(c.address) == 10
c2.create_and_call_returnten(c.address, transact={})

expected_forwarder_code_mask = get_create_with_code_of_bytecode()[12:]
expected_forwarder_code_mask = get_create_forwarder_to_bytecode()[12:]

c3 = c2.create_and_return_forwarder(c.address, call={})
c2.create_and_return_forwarder(c.address, transact={})
Expand Down Expand Up @@ -78,13 +78,13 @@ def returnten() -> int128:
outer_code = """
@public
def create_and_call_returnten(inp: address) -> int128:
x: address = create_with_code_of(inp)
x: address = create_forwarder_to(inp)
o: int128 = extract32(raw_call(x, convert("\xd0\x1f\xb1\xb8", bytes[4]), outsize=32, gas=50000), 0, type=int128) # noqa: E501
return o

@public
def create_and_return_forwarder(inp: address) -> address:
return create_with_code_of(inp)
return create_forwarder_to(inp)
"""

c2 = get_contract_with_gas_estimation(outer_code)
Expand Down
2 changes: 1 addition & 1 deletion tests/parser/syntax/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""
@public
def foo() -> int128:
x: address = create_with_code_of(
x: address = create_forwarder_to(
0x1234567890123456789012345678901234567890,
value=block.timestamp,
)
Expand Down
8 changes: 4 additions & 4 deletions tests/parser/syntax/test_create_with_code_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""
@public
def foo():
x: address = create_with_code_of(0x1234567890123456789012345678901234567890, value=4, value=9)
x: address = create_forwarder_to(0x1234567890123456789012345678901234567890, value=4, value=9)
"""
]

Expand All @@ -23,20 +23,20 @@ def test_type_mismatch_exception(bad_code):
"""
@public
def foo():
x: address = create_with_code_of(0x1234567890123456789012345678901234567890)
x: address = create_forwarder_to(0x1234567890123456789012345678901234567890)
""",
"""
@public
def foo():
x: address = create_with_code_of(
x: address = create_forwarder_to(
0x1234567890123456789012345678901234567890,
value=as_wei_value(9, "wei")
)
""",
"""
@public
def foo():
x: address = create_with_code_of(0x1234567890123456789012345678901234567890, value=9)
x: address = create_forwarder_to(0x1234567890123456789012345678901234567890, value=9)
"""
]

Expand Down
10 changes: 5 additions & 5 deletions vyper/functions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ def shift(expr, args, kwargs, context):
)


def get_create_with_code_of_bytecode():
def get_create_forwarder_to_bytecode():
from vyper.compile_lll import (
assembly_to_evm,
num_to_bytearray
Expand Down Expand Up @@ -1047,7 +1047,7 @@ def get_create_with_code_of_bytecode():


@signature('address', value=Optional('uint256', zero_value))
def create_with_code_of(expr, args, kwargs, context):
def create_forwarder_to(expr, args, kwargs, context):

value = kwargs['value']
if value != zero_value:
Expand All @@ -1060,7 +1060,7 @@ def create_with_code_of(expr, args, kwargs, context):
)
placeholder = context.new_placeholder(ByteArrayType(96))

kode = get_create_with_code_of_bytecode()
kode = get_create_forwarder_to_bytecode()
high = bytes_to_int(kode[:32])
low = bytes_to_int((kode + b'\x00' * 32)[47:79])

Expand Down Expand Up @@ -1159,7 +1159,7 @@ def _clear():
'uint256_addmod': uint256_addmod,
'uint256_mulmod': uint256_mulmod,
'shift': shift,
'create_with_code_of': create_with_code_of,
'create_forwarder_to': create_forwarder_to,
'min': _min,
'max': _max,
}
Expand All @@ -1170,5 +1170,5 @@ def _clear():
'selfdestruct': selfdestruct,
'raw_call': raw_call,
'raw_log': raw_log,
'create_with_code_of': create_with_code_of,
'create_forwarder_to': create_forwarder_to,
}