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

rewrite internal calling convention #2447

Merged
merged 164 commits into from
Oct 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
4bbe415
allow any ABI-encodable type as args
charles-cooper Jul 27, 2021
6d27c3d
remove tests that blocked dynamic structs as args
charles-cooper Jul 27, 2021
75c2040
fix linter errors
charles-cooper Jul 27, 2021
53019b6
add a note about alignment
charles-cooper Jul 29, 2021
2f4869f
change FLAG comments to NOTE
charles-cooper Jul 30, 2021
3faea53
add a nested tuple test
charles-cooper Jul 30, 2021
71b4993
remove storage_prehashed cases
charles-cooper Aug 2, 2021
0fb8f92
clarify tuple wrapping behavior
charles-cooper Aug 3, 2021
b986d46
complex type
charles-cooper Aug 3, 2021
04feca8
simplify return logic
charles-cooper Aug 3, 2021
02c4142
wip: rewrite private function frame code
charles-cooper Aug 3, 2021
b6436e3
rewrite internal function calling convention
charles-cooper Aug 29, 2021
69d2f6d
wip cleanup internal calls
charles-cooper Aug 30, 2021
5273abf
wip handle return None cases
charles-cooper Aug 30, 2021
ccb167d
feat: add "code" location to LLL
charles-cooper Aug 31, 2021
295fe95
wip: external functions rewrite
charles-cooper Aug 31, 2021
1d7d488
wip add clampers to abi_decode
charles-cooper Aug 31, 2021
6eac3f6
wip external functions rewrite
charles-cooper Sep 1, 2021
54ce49c
wip: add notes on parse_type
charles-cooper Sep 1, 2021
2c6bc8a
remove validate_return_statement_balance method
charles-cooper Sep 2, 2021
eceb703
clarify ContractFunction.from_AnnAssign
charles-cooper Sep 2, 2021
d701ed7
wip
charles-cooper Sep 2, 2021
36f2e09
wip external kwargs
charles-cooper Sep 2, 2021
aef37f7
wip external kwargs
charles-cooper Sep 7, 2021
bc3ca37
rewrite FunctionSignature
charles-cooper Sep 7, 2021
ec47c62
wip self call kwargs
charles-cooper Sep 7, 2021
4f3a4cb
move pack_arguments to external_call
charles-cooper Sep 7, 2021
b4dd432
wip remove external_call_output function
charles-cooper Sep 7, 2021
80bae2e
remove a dead branch
charles-cooper Sep 7, 2021
b911f7d
wip external call rewrite
charles-cooper Sep 7, 2021
e035bef
add clamping to ABI decoder
charles-cooper Sep 8, 2021
155f166
polish work on new calling convention
charles-cooper Sep 10, 2021
d791ffe
fix some lint/surface errors
charles-cooper Sep 10, 2021
1dbd709
kill parse_sequence
charles-cooper Sep 10, 2021
d3177d2
lint a test
charles-cooper Sep 10, 2021
9e7f6e6
remove dead code
charles-cooper Sep 10, 2021
c6bd13b
only return len if it's asked for
charles-cooper Sep 11, 2021
adc7338
wip rewrite jump table
charles-cooper Sep 11, 2021
7a816e3
wip polish
charles-cooper Sep 11, 2021
e580503
add back a missing exception
charles-cooper Sep 11, 2021
9d1a455
wip polish
charles-cooper Sep 11, 2021
7c6689c
wip lint
charles-cooper Sep 11, 2021
bd1237d
wip polish, has compile
charles-cooper Sep 11, 2021
a6e3f32
wip polish, remove some dead code
charles-cooper Sep 11, 2021
345fde3
update BYTE_ARRAY_OVERHEAD
charles-cooper Sep 11, 2021
e2cb345
wip polish more, fix external calls
charles-cooper Sep 11, 2021
b91a2c8
fix returndatasize negative check
charles-cooper Sep 11, 2021
29db5be
wip fix more external call issues
charles-cooper Sep 11, 2021
9c72d0a
fix int_clamp for address and bool
charles-cooper Sep 11, 2021
cfff459
fix some bugs for list args
charles-cooper Sep 11, 2021
b35765a
fix called function name
charles-cooper Sep 12, 2021
d762ea6
add byte array copier cases for calldata and code
charles-cooper Sep 12, 2021
2027f6b
fix some kwarg handling issues
charles-cooper Sep 12, 2021
135da22
fix array arguments
charles-cooper Sep 12, 2021
b2dc1df
fix private frame size adjustment
charles-cooper Sep 12, 2021
8acd20a
fix mypy and lint issues
charles-cooper Sep 12, 2021
d3a2055
fix int_clamp argument
charles-cooper Sep 12, 2021
ad350a8
add annotation for fill return buffer sequence
charles-cooper Sep 13, 2021
034b8e1
fix lazy_abi_decode location for base types
charles-cooper Sep 13, 2021
8c303e6
allow indexing lazy_abi_decoded structs
charles-cooper Sep 13, 2021
ddc7786
redo lazy abi decoder
charles-cooper Sep 14, 2021
f0e3156
fix some minor bugs
charles-cooper Sep 14, 2021
e6038df
fix source map for new calling convention
charles-cooper Sep 14, 2021
6eb45e5
add missing bytes32 case to clamp_basetype
charles-cooper Sep 14, 2021
ff125bf
fix base handler check
charles-cooper Sep 14, 2021
fbba2ff
fix order of base arg hanlders
charles-cooper Sep 14, 2021
8bf5b98
improve annotation for internal function exit
charles-cooper Sep 14, 2021
ed4f545
fix init func exit sequence
charles-cooper Sep 14, 2021
80e55f3
improve annotation of method IDs
charles-cooper Sep 14, 2021
d1fa8db
fix stack handling of return_buffer
charles-cooper Sep 14, 2021
009c3a0
fix arg alignment for external call
charles-cooper Sep 14, 2021
2db19b0
fix some formatting
charles-cooper Sep 14, 2021
c0f609c
refactor external entry label generation
charles-cooper Sep 14, 2021
baf7794
fix mutating of LLLnodes
charles-cooper Sep 14, 2021
f189dcc
fix variable scoping in add_variable_offset
charles-cooper Sep 14, 2021
16b3383
make labels more human readable
charles-cooper Sep 14, 2021
a683b5a
optimize out clamps for types that don't need it
charles-cooper Sep 14, 2021
52c5552
add min_size to ABI api
charles-cooper Sep 15, 2021
7370c4e
fix returndatasize check
charles-cooper Sep 15, 2021
7c1c336
rewrite external call buffer allocation
charles-cooper Sep 15, 2021
8f6ca4d
fix abi_encode for expressions with side effects
charles-cooper Sep 15, 2021
5150ae1
improve some LLL annotations
charles-cooper Sep 15, 2021
a0972c8
fix debug function
charles-cooper Sep 15, 2021
0ccd339
wrap ABI values in tuples as needed
charles-cooper Sep 15, 2021
15bc342
clean up return.py a bit
charles-cooper Sep 15, 2021
f4fd134
fix abi tuple wrapping
charles-cooper Sep 16, 2021
0f4fc8f
fix special case in ABI for single struct return
charles-cooper Sep 16, 2021
eef4766
fix external call return wrapping
charles-cooper Sep 16, 2021
a1e9842
fix lint
charles-cooper Sep 16, 2021
e332a25
fix size calculation for bytestring copy
charles-cooper Sep 16, 2021
a50ea5b
fix some lint
charles-cooper Sep 16, 2021
53f6491
fix size bounds for nested dynamic types
charles-cooper Sep 16, 2021
93540d8
fix return type wrapping again
charles-cooper Sep 16, 2021
267a98d
fix bug in abi.py
charles-cooper Sep 16, 2021
e112c2c
improve an error message
charles-cooper Sep 16, 2021
1b9cb68
fix return wrapping again
charles-cooper Sep 16, 2021
c7b53ee
move unwrapping code deeper into external call
charles-cooper Sep 16, 2021
145d529
generalize key calculation to handle calldata
charles-cooper Sep 17, 2021
143d31b
generalize concat to more locations
charles-cooper Sep 17, 2021
149eca4
fix test for old bytestring layout
charles-cooper Sep 17, 2021
233c92e
fix storage layout for new bytestring layout
charles-cooper Sep 17, 2021
81f8f97
fix slice builtin for location=calldata
charles-cooper Sep 17, 2021
aee96fd
fix abi_encode test for needing to cache result
charles-cooper Sep 17, 2021
71dd34c
fix slice length in a new test
charles-cooper Sep 17, 2021
ba84944
improve annotation of add_variable_ofst LLL
charles-cooper Sep 17, 2021
f5f3433
fix abi_encode test, again
charles-cooper Sep 17, 2021
ae6d303
fix some lint
charles-cooper Sep 17, 2021
43ee4a3
clarify variable ofst annotation a bit
charles-cooper Sep 17, 2021
756d272
wip fix the jumptable for external kwarg handlers
charles-cooper Sep 18, 2021
3a508ea
add py-evm debug2 logging for tests
charles-cooper Sep 20, 2021
23a4985
add structured goto to LLL
charles-cooper Sep 20, 2021
e84c427
fix some lint
charles-cooper Sep 20, 2021
2156025
fix unwrapping of tuples for real tuples
charles-cooper Sep 20, 2021
ca7065c
fix nested abi encode size
charles-cooper Sep 20, 2021
1827c4b
fix memory allocation for abi_encode builtin
charles-cooper Sep 21, 2021
5926e88
add a note about dead code
charles-cooper Sep 21, 2021
de4d06c
wip reorganize parser lll
charles-cooper Sep 21, 2021
d95ec07
remove "optimization" which doesn't do anything
charles-cooper Sep 21, 2021
8a416c8
fix assert_reason for new bytestring length
charles-cooper Sep 21, 2021
1c6c605
fix sar emulation for pre-constantinople
charles-cooper Sep 21, 2021
868ad4c
fix clamp for abi-encoded static arrays
charles-cooper Sep 21, 2021
2f83f08
fix lint
charles-cooper Sep 21, 2021
f7e38b3
fix tests for new struct output format
charles-cooper Sep 21, 2021
88e9e88
fix sha256 for non-memory args
charles-cooper Sep 21, 2021
d8fd8aa
fix test for calldataload
charles-cooper Sep 21, 2021
b0d92a2
fix calculation of kwargs needed
charles-cooper Sep 21, 2021
1293120
fix type bug in self call arg passing routine
charles-cooper Sep 21, 2021
53d9c18
fix some output struct formats
charles-cooper Sep 21, 2021
4411679
remove max bound check on returndatasize
charles-cooper Sep 21, 2021
817b9ea
fix method_id calculation for external call
charles-cooper Sep 21, 2021
fa2bc12
only allocate kwarg slots once
charles-cooper Sep 21, 2021
dba73c1
fix abi test for new format
charles-cooper Sep 21, 2021
91e1929
fix returning out of a loop
charles-cooper Sep 22, 2021
a8170f1
make return out of loop test a bit harder
charles-cooper Sep 22, 2021
7ebf01e
fix lint
charles-cooper Sep 22, 2021
86bb6bf
add more cases to byte_array_to_num
charles-cooper Sep 22, 2021
9886288
add more location cases to extract32
charles-cooper Sep 22, 2021
377fde5
add a JSON_ABI encoding
charles-cooper Sep 22, 2021
837edcc
fix a broken assert
charles-cooper Sep 22, 2021
2a9fbdb
add more locations to convert builtin
charles-cooper Sep 22, 2021
464ca44
fix formatting on some test struct results
charles-cooper Sep 22, 2021
7f76cc0
protect argument buffer in self call
charles-cooper Sep 22, 2021
5e6c387
fix tests for get_size_of(bytes)
charles-cooper Sep 22, 2021
f2ebdf7
handle more locations in Expr.parse_Compare
charles-cooper Sep 22, 2021
d8c9314
fix constant folding test
charles-cooper Sep 22, 2021
5f4ac74
fix mypy/lint
charles-cooper Sep 22, 2021
d171852
Merge branch 'master' into abi_refactor
charles-cooper Sep 22, 2021
13fea45
clarify a comment
charles-cooper Sep 22, 2021
c9a9397
backport cached_property import
charles-cooper Sep 22, 2021
e0db365
drop python3.6 support
charles-cooper Sep 22, 2021
4bd0eca
clarify extcodesize check
charles-cooper Sep 24, 2021
82efdbd
import cached-property conditionally
charles-cooper Sep 24, 2021
100e484
comment clarifying maxlen for abi_encode+method_id
charles-cooper Sep 24, 2021
57aa48c
add annotation to int_clamp
charles-cooper Sep 28, 2021
cee64b0
strictly decode calldata args that needs clamps
charles-cooper Sep 24, 2021
43a3bc7
fix copy op for bytestrings located in code
charles-cooper Sep 29, 2021
eb0088d
fix lint and mypy
charles-cooper Sep 29, 2021
f2715e0
Prune inefficient jumps
charles-cooper Oct 1, 2021
e680e44
fix a breaking test
charles-cooper Oct 1, 2021
d2808d0
elide copies of zero-element tuples
charles-cooper Oct 1, 2021
5b8af90
rename add_variable_offset to get_element_ptr
charles-cooper Oct 1, 2021
2ab392d
fix lint
charles-cooper Oct 2, 2021
a022c95
fix nonreentrancy codegen for private functions
charles-cooper Oct 2, 2021
3e036aa
improve annotation for `in` expressions
charles-cooper Oct 2, 2021
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
23 changes: 0 additions & 23 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,6 @@ jobs:
- name: Run Tox
run: TOXENV=mypy tox -r

py36-core:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Set up Python 3.6
uses: actions/setup-python@v1
with:
python-version: 3.6

- name: Install Tox
run: pip install tox

- name: Run Tox
run: TOXENV=py36-core tox -r

- name: Upload Coverage
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml

py37-core:
runs-on: ubuntu-latest

Expand Down
2 changes: 1 addition & 1 deletion docs/built-in-functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ Utilities
Once this function has seen more use we provisionally plan to put it into the ``ethereum.abi`` namespace.

* ``*args``: Arbitrary arguments
* ``ensure_tuple``: If set to True, ensures that even a single argument is encoded as a tuple. In other words, ``bytes`` gets encoded as ``(bytes,)``. This is the calling convention for Vyper and Solidity functions. Except for very specific use cases, this should be set to True. Must be a literal.
* ``ensure_tuple``: If set to True, ensures that even a single argument is encoded as a tuple. In other words, ``bytes`` gets encoded as ``(bytes,)``, and ``(bytes,)`` gets encoded as ``((bytes,),)`` This is the calling convention for Vyper and Solidity functions. Except for very specific use cases, this should be set to True. Must be a literal.
* ``method_id``: A literal hex or Bytes[4] value to append to the beginning of the abi-encoded bytestring.

Returns a bytestring whose max length is determined by the arguments. For example, encoding a ``Bytes[32]`` results in a ``Bytes[64]`` (first word is the length of the bytestring variable).
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[tool.black]
line-length = 100
target-version = ['py36', 'py37', 'py38']
target-version = ['py37', 'py38', 'py39']
include = '\.pyi?$'
exclude = '''
/(
Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@
packages=find_packages(exclude=("tests", "docs")),
python_requires=">=3.6",
py_modules=["vyper"],
install_requires=["asttokens==2.0.4", "pycryptodome>=3.5.1,<4", "semantic-version==2.8.5"],
install_requires=[
"asttokens==2.0.4",
"pycryptodome>=3.5.1,<4",
"semantic-version==2.8.5",
"cached-property==1.5.2 ; python_version<'3.8'",
],
setup_requires=["pytest-runner"],
tests_require=extras_require["test"],
extras_require=extras_require,
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/outputs/test_storage_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ def public_bar():
"slot": 3,
},
"baz": {"type": "Bytes[65]", "location": "storage", "slot": 4},
"bar": {"type": "uint256", "location": "storage", "slot": 9},
"bar": {"type": "uint256", "location": "storage", "slot": 8},
fubuloubu marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 1 addition & 1 deletion tests/compiler/test_source_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_jump_map():
pos_map = source_map["pc_pos_map"]
jump_map = source_map["pc_jump_map"]

assert len([v for v in jump_map.values() if v == "o"]) == 3
assert len([v for v in jump_map.values() if v == "o"]) == 1
assert len([v for v in jump_map.values() if v == "i"]) == 2

code_lines = [i + "\n" for i in TEST_CODE.split("\n")]
Expand Down
7 changes: 5 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest
from eth_tester import EthereumTester
from eth_utils import setup_DEBUG2_logging
from hexbytes import HexBytes
from web3 import Web3
from web3.providers.eth_tester import EthereumTesterProvider
Expand All @@ -26,12 +27,14 @@


def set_evm_verbose_logging():
logger = logging.getLogger("evm")
logger.setLevel("TRACE")
logger = logging.getLogger("eth.vm.computation.Computation")
setup_DEBUG2_logging()
logger.setLevel("DEBUG2")


# Useful options to comment out whilst working:
# set_evm_verbose_logging()
#
# from vdb import vdb
# vdb.set_evm_opcode_debugger()

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/codegen/test_abi_encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def abi_encode(
pet_metadata: bytes32,
ensure_tuple: bool,
include_method_id: bool
) -> Bytes[260]:
) -> Bytes[548]:
fubuloubu marked this conversation as resolved.
Show resolved Hide resolved
human: Human = Human({
name: name,
pet: Animal({
Expand Down
28 changes: 12 additions & 16 deletions tests/functional/codegen/test_struct_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,29 @@ def test_nested_tuple(get_contract):
code = """
struct Animal:
location: address
fur: uint256
fur: String[32]

struct Human:
location: address
height: uint256
animal: Animal

@external
def return_nested_tuple() -> (Animal, Human):
animal: Animal = Animal({
location: 0x1234567890123456789012345678901234567890,
fur: 123
})
human: Human = Human({
location: 0x1234567890123456789012345678900000000000,
height: 456
})
def modify_nested_tuple(_human: Human) -> Human:
human: Human = _human

# do stuff, edit the structs
animal.fur += 1
human.height += 1
# (13 is the length of the result)
human.animal.fur = slice(concat(human.animal.fur, " is great"), 0, 13)

return animal, human
return human
"""
c = get_contract(code)
addr1 = "0x1234567890123456789012345678901234567890"
addr2 = "0x1234567890123456789012345678900000000000"
assert c.return_nested_tuple() == [(addr1, 124), (addr2, 457)]
# assert c.modify_nested_tuple([addr1, 123], [addr2, 456]) == [[addr1, 124], [addr2, 457]]
assert c.modify_nested_tuple(
{"location": addr1, "animal": {"location": addr2, "fur": "wool"}}
) == (addr1, (addr2, "wool is great"),)


@pytest.mark.parametrize("string", ["a", "abc", "abcde", "potato"])
Expand Down Expand Up @@ -61,4 +57,4 @@ def test_values(a: address) -> Person:
"""

c2 = get_contract(code)
assert c2.test_values(c1.address) == [string, 42]
assert c2.test_values(c1.address) == (string, 42)
3 changes: 1 addition & 2 deletions tests/functional/context/types/test_size_in_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def test_array_value_types(build_node, type_str, location, length, size):
node = build_node(f"{type_str}[{length}]")
type_definition = get_type_from_annotation(node, location)

# TODO once storage of bytes is optimized, remove the +32
assert type_definition.size_in_bytes == size + 32
assert type_definition.size_in_bytes == size


@pytest.mark.parametrize("type_str", BASE_TYPES)
Expand Down
16 changes: 8 additions & 8 deletions tests/functional/test_storage_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ def with_other_lock():

def test_storage_slots(get_contract):
c = get_contract(code)
assert c.a() == ["ok", [4, 5, 6]]
assert c.a() == ("ok", [4, 5, 6])
assert [c.b(i) for i in range(2)] == [7, 8]
assert c.c() == b"thisisthirtytwobytesokhowdoyoudo"
assert [c.d(i) for i in range(4)] == [-1, -2, -3, -4]
assert c.e() == "A realllllly long string but we wont use it all"
assert c.f(0) == 33
assert c.g(0) == [b"hello", [-66, 420], "another string"]
assert c.g(1) == [
assert c.g(0) == (b"hello", [-66, 420], "another string")
assert c.g(1) == (
b"gbye",
[1337, 888],
"whatifthisstringtakesuptheentirelengthwouldthatbesobadidothinkso",
]
)
assert [c.foo(0, i) for i in range(3)] == [987, 654, 321]
assert [c.foo(1, i) for i in range(3)] == [123, 456, 789]
assert c.h(0) == 123456789
Expand All @@ -80,18 +80,18 @@ def test_reentrancy_lock(get_contract):
c.with_lock()
c.with_other_lock()

assert c.a() == ["ok", [4, 5, 6]]
assert c.a() == ("ok", [4, 5, 6])
assert [c.b(i) for i in range(2)] == [7, 8]
assert c.c() == b"thisisthirtytwobytesokhowdoyoudo"
assert [c.d(i) for i in range(4)] == [-1, -2, -3, -4]
assert c.e() == "A realllllly long string but we wont use it all"
assert c.f(0) == 33
assert c.g(0) == [b"hello", [-66, 420], "another string"]
assert c.g(1) == [
assert c.g(0) == (b"hello", [-66, 420], "another string")
assert c.g(1) == (
b"gbye",
[1337, 888],
"whatifthisstringtakesuptheentirelengthwouldthatbesobadidothinkso",
]
)
assert [c.foo(0, i) for i in range(3)] == [987, 654, 321]
assert [c.foo(1, i) for i in range(3)] == [123, 456, 789]
assert c.h(0) == 123456789
25 changes: 0 additions & 25 deletions tests/parser/exceptions/test_argument_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,6 @@ def foo():
for i in range(1, 2, 3, 4):
pass
""",
"""
struct Foo:
a: Bytes[32]

@external
def foo(a: Foo):
pass
""",
"""
struct Foo:
a: String[32]

@external
def foo(a: Foo):
pass
""",
"""
struct Foo:
b: uint256
a: String[32]

@external
def foo(a: Foo):
pass
""",
]


Expand Down
2 changes: 1 addition & 1 deletion tests/parser/features/decorators/test_private.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def foo() -> A:
return self._foo([1, 2, 3, 4], 5)
""",
(),
[[1, 2, 3, 4], 5],
([1, 2, 3, 4], 5),
),
(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ def test(addr: address) -> (int128, address):
c1 = get_contract_with_gas_estimation(contract_1)
c2 = get_contract_with_gas_estimation(contract_2)

assert c1.out_literals() == [1, "0x0000000000000000000000000000000000012345"]
assert c1.out_literals() == (1, "0x0000000000000000000000000000000000012345")
assert c2.test(c1.address) == list(c1.out_literals())


Expand Down Expand Up @@ -862,7 +862,7 @@ def test(addr: address) -> (int128, String[{ln}], Bytes[{ln}]):
c1 = get_contract_with_gas_estimation(contract_1)
c2 = get_contract_with_gas_estimation(contract_2)

assert c1.get_struct_x() == [i, s, bytes(s, "utf-8")]
assert c1.get_struct_x() == (i, s, bytes(s, "utf-8"))
assert c2.test(c1.address) == list(c1.get_struct_x())


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ def wrap_get_my_struct_BROKEN(_e1: decimal) -> MyStruct:
return self.get_my_struct(_e1, block.timestamp)
"""
c = get_contract(code)
assert c.wrap_get_my_struct_WORKING(Decimal("0.1")) == [
assert c.wrap_get_my_struct_WORKING(Decimal("0.1")) == (
Decimal("0.1"),
w3.eth.getBlock(w3.eth.blockNumber)["timestamp"],
]
assert c.wrap_get_my_struct_BROKEN(Decimal("0.1")) == [
)
assert c.wrap_get_my_struct_BROKEN(Decimal("0.1")) == (
Decimal("0.1"),
w3.eth.getBlock(w3.eth.blockNumber)["timestamp"],
]
)
6 changes: 4 additions & 2 deletions tests/parser/features/iteration/test_repeater.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ def test_return_inside_repeater(get_contract, typ):
@internal
def _final(a: {typ}) -> {typ}:
for i in range(10):
if i > a:
return i
for j in range(10):
if j > 5:
if i > a:
return i
return 31337

@internal
Expand Down
5 changes: 3 additions & 2 deletions tests/parser/features/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def __init__(a: uint256):

assert c.val() == 123

# Make sure the init signature has no unecessary CALLDATLOAD copy.
# Make sure the init code does not access calldata
opcodes = vyper.compile_code(code, ["opcodes"])["opcodes"].split(" ")
lll_return_idx = opcodes.index("JUMP")

assert "CALLDATALOAD" in opcodes
assert "CALLDATACOPY" in opcodes
assert "CALLDATACOPY" not in opcodes[:lll_return_idx]
assert "CALLDATALOAD" not in opcodes[:lll_return_idx]
20 changes: 14 additions & 6 deletions tests/parser/functions/test_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,21 @@ def foo(s: MyStruct) -> MyStruct:
func_abi = abi[0]

assert func_abi["name"] == "foo"
expected = {

expected_output = [
{
"type": "tuple",
"name": "",
"components": [{"type": "address", "name": "a"}, {"type": "uint256", "name": "b"}],
}
]

assert func_abi["outputs"] == expected_output

expected_input = {
"type": "tuple",
"name": "",
"name": "s",
"components": [{"type": "address", "name": "a"}, {"type": "uint256", "name": "b"}],
}

assert func_abi["outputs"] == expected["components"]

expected["name"] = "s"
assert func_abi["inputs"][0] == expected
assert func_abi["inputs"][0] == expected_input
12 changes: 6 additions & 6 deletions tests/parser/functions/test_return_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test() -> Voter:

c = get_contract_with_gas_estimation(code)

assert c.test() == [123, True]
assert c.test() == (123, True)


def test_struct_return(get_contract_with_gas_estimation):
Expand Down Expand Up @@ -74,13 +74,13 @@ def pub6() -> Foo:
foo: Foo = Foo({x: 123, y: 456})
return self.return_arg(foo)
"""
foo = [123, 456]
foo = (123, 456)

c = get_contract_with_gas_estimation(code)

assert c.pub1() == [1, 2]
assert c.pub2() == [3, 4]
assert c.pub3() == [5, 6]
assert c.pub4() == [7, 8]
assert c.pub1() == (1, 2)
assert c.pub2() == (3, 4)
assert c.pub3() == (5, 6)
assert c.pub4() == (7, 8)
assert c.pub5(foo) == foo
assert c.pub6() == foo
5 changes: 3 additions & 2 deletions tests/parser/types/numbers/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,12 @@ def test_constant_folds(search_for_sublist):
def test() -> uint256:
# calculate some constant which is really unlikely to be randomly
# in bytecode
return 2**SOME_CONSTANT * SOME_PRIME
ret: uint256 = 2**SOME_CONSTANT * SOME_PRIME
return ret
"""

lll = compile_code(code, ["ir"])["ir"]
assert search_for_sublist(lll, ["mstore", [0], [2 ** 12 * some_prime]])
assert search_for_sublist(lll, ["mstore", [320], [2 ** 12 * some_prime]])
fubuloubu marked this conversation as resolved.
Show resolved Hide resolved


def test_constant_lists(get_contract):
Expand Down
Loading