Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/vyperlang/vyper into refa…
Browse files Browse the repository at this point in the history
…ctor/folding_alt2
  • Loading branch information
tserg committed Dec 21, 2023
2 parents 6505a94 + 3116e88 commit 6af3191
Show file tree
Hide file tree
Showing 114 changed files with 5,866 additions and 1,734 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ make dev-init
python setup.py test
```

## Developing (working on the compiler)

A useful script to have in your PATH is something like the following:
```bash
$ cat ~/.local/bin/vyc
#!/usr/bin/env bash
PYTHONPATH=. python vyper/cli/vyper_compile.py "$@"
```

To run a python performance profile (to find compiler perf hotspots):
```bash
PYTHONPATH=. python -m cProfile -s tottime vyper/cli/vyper_compile.py "$@"
```

To get a call graph from a python profile, https://stackoverflow.com/a/23164271/ is helpful.


# Contributing
* See Issues tab, and feel free to submit your own issues
* Add PRs if you discover a solution to an existing issue
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ If you are making a larger change, please consult first with the `Vyper (Smart C

Although we do CI testing, please make sure that the tests pass for supported Python version and ensure that it builds locally before submitting a pull request.

Thank you for your help! ​
Thank you for your help!
6 changes: 5 additions & 1 deletion examples/crowdfund.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Setup private variables (only callable from within the contract)
###########################################################################
## THIS IS EXAMPLE CODE, NOT MEANT TO BE USED IN PRODUCTION! CAVEAT EMPTOR!
###########################################################################

# example of a crowd funding contract

funders: HashMap[address, uint256]
beneficiary: address
Expand Down
2 changes: 1 addition & 1 deletion examples/market_maker/on_chain_market_maker.vy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ invariant: public(uint256)
token_address: ERC20
owner: public(address)

# Sets the on chain market maker with its owner, intial token quantity,
# Sets the on chain market maker with its owner, initial token quantity,
# and initial ether quantity
@external
@payable
Expand Down
7 changes: 6 additions & 1 deletion examples/tokens/ERC1155ownable.vy
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
###########################################################################
## THIS IS EXAMPLE CODE, NOT MEANT TO BE USED IN PRODUCTION! CAVEAT EMPTOR!
###########################################################################

# @version >=0.3.4
"""
@dev Implementation of ERC-1155 non-fungible token standard ownable, with approval, OPENSEA compatible (name, symbol)
@dev example implementation of ERC-1155 non-fungible token standard ownable, with approval, OPENSEA compatible (name, symbol)
@author Dr. Pixel (github: @Doc-Pixel)
"""

############### imports ###############
from vyper.interfaces import ERC165

Expand Down
6 changes: 5 additions & 1 deletion examples/tokens/ERC20.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# @dev Implementation of ERC-20 token standard.
###########################################################################
## THIS IS EXAMPLE CODE, NOT MEANT TO BE USED IN PRODUCTION! CAVEAT EMPTOR!
###########################################################################

# @dev example implementation of an ERC20 token
# @author Takayuki Jimba (@yudetamago)
# https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md

Expand Down
7 changes: 7 additions & 0 deletions examples/tokens/ERC4626.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# NOTE: Copied from https://github.com/fubuloubu/ERC4626/blob/1a10b051928b11eeaad15d80397ed36603c2a49b/contracts/VyperVault.vy

# example implementation of an ERC4626 vault

###########################################################################
## THIS IS EXAMPLE CODE, NOT MEANT TO BE USED IN PRODUCTION! CAVEAT EMPTOR!
###########################################################################

from vyper.interfaces import ERC20
from vyper.interfaces import ERC4626

Expand Down
6 changes: 5 additions & 1 deletion examples/tokens/ERC721.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# @dev Implementation of ERC-721 non-fungible token standard.
###########################################################################
## THIS IS EXAMPLE CODE, NOT MEANT TO BE USED IN PRODUCTION! CAVEAT EMPTOR!
###########################################################################

# @dev example implementation of ERC-721 non-fungible token standard.
# @author Ryuya Nakamura (@nrryuya)
# Modified from: https://github.com/vyperlang/vyper/blob/de74722bf2d8718cca46902be165f9fe0e3641dd/examples/tokens/ERC721.vy

Expand Down
7 changes: 5 additions & 2 deletions examples/wallet/wallet.vy
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# An example of how you can do a wallet in Vyper.
# Warning: NOT AUDITED. Do not use to store substantial quantities of funds.
###########################################################################
## THIS IS EXAMPLE CODE, NOT MEANT TO BE USED IN PRODUCTION! CAVEAT EMPTOR!
###########################################################################

# An example of how you can implement a wallet in Vyper.

# A list of the owners addresses (there are a maximum of 5 owners)
owners: public(address[5])
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"pytest-instafail>=0.4,<1.0",
"pytest-xdist>=2.5,<3.0",
"pytest-split>=0.7.0,<1.0",
"pytest-rerunfailures>=10.2,<11",
"eth-tester[py-evm]>=0.9.0b1,<0.10",
"py-evm>=0.7.0a1,<0.8",
"web3==6.0.0",
Expand Down
16 changes: 12 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from vyper import compiler
from vyper.ast.grammar import parse_vyper_source
from vyper.codegen.ir_node import IRnode
from vyper.compiler.input_bundle import FilesystemInputBundle
from vyper.compiler.input_bundle import FilesystemInputBundle, InputBundle
from vyper.compiler.settings import OptimizationLevel, Settings, _set_debug_mode
from vyper.ir import compile_ir, optimizer

Expand Down Expand Up @@ -103,6 +103,12 @@ def fn(sources_dict):
return fn


# for tests which just need an input bundle, doesn't matter what it is
@pytest.fixture
def dummy_input_bundle():
return InputBundle([])


# TODO: remove me, this is just string.encode("utf-8").ljust()
# only used in test_logging.py.
@pytest.fixture
Expand Down Expand Up @@ -255,9 +261,11 @@ def ir_compiler(ir, *args, **kwargs):
ir = IRnode.from_list(ir)
if optimize != OptimizationLevel.NONE:
ir = optimizer.optimize(ir)

bytecode, _ = compile_ir.assembly_to_evm(
compile_ir.compile_to_assembly(ir, optimize=optimize)
)

abi = kwargs.get("abi") or []
c = w3.eth.contract(abi=abi, bytecode=bytecode)
deploy_transaction = c.constructor()
Expand All @@ -279,8 +287,8 @@ def _get_contract(
settings.optimize = override_opt_level or optimize
out = compiler.compile_code(
source_code,
# test that metadata and natspecs get generated
output_formats=["abi", "bytecode", "metadata", "userdoc", "devdoc"],
# test that all output formats can get generated
output_formats=list(compiler.OUTPUT_FORMATS.keys()),
settings=settings,
input_bundle=input_bundle,
show_gas_estimates=True, # Enable gas estimates for testing
Expand Down Expand Up @@ -352,7 +360,7 @@ def _deploy_blueprint_for(w3, source_code, optimize, initcode_prefix=b"", **kwar
settings.optimize = optimize
out = compiler.compile_code(
source_code,
output_formats=["abi", "bytecode", "metadata", "userdoc", "devdoc"],
output_formats=list(compiler.OUTPUT_FORMATS.keys()),
settings=settings,
show_gas_estimates=True, # Enable gas estimates for testing
)
Expand Down
25 changes: 25 additions & 0 deletions tests/functional/builtins/codegen/test_uint2str.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import pytest

from vyper.compiler import compile_code
from vyper.exceptions import InvalidType, OverflowException

VALID_BITS = list(range(8, 257, 8))


Expand Down Expand Up @@ -37,3 +40,25 @@ def foo(x: uint{bits}) -> uint256:
"""
c = get_contract(code)
assert c.foo(2**bits - 1) == 0, bits


def test_bignum_throws():
code = """
@external
def test():
a: String[78] = uint2str(2**256)
pass
"""
with pytest.raises(OverflowException):
compile_code(code)


def test_int_fails():
code = """
@external
def test():
a: String[78] = uint2str(-1)
pass
"""
with pytest.raises(InvalidType):
compile_code(code)
5 changes: 4 additions & 1 deletion tests/functional/codegen/integration/test_crowdfund.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ def refund():
"""
a0, a1, a2, a3, a4, a5, a6 = w3.eth.accounts[:7]

c = get_contract_with_gas_estimation_for_constants(crowdfund, *[a1, 50, 60])
start_timestamp = w3.eth.get_block(w3.eth.block_number).timestamp

c.participate(transact={"value": 5})
assert c.timelimit() == 60
assert c.deadline() - c.block_timestamp() == 59
assert c.deadline() - start_timestamp == 60
assert not c.expired()
assert not c.reached()
c.participate(transact={"value": 49})
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/codegen/test_call_graph_stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def foo():

# check the .called_functions data structure on foo() directly
foo = t.vyper_module_folded.get_children(vy_ast.FunctionDef, filters={"name": "foo"})[0]
foo_t = foo._metadata["type"]
foo_t = foo._metadata["func_type"]
assert [f.name for f in foo_t.called_functions] == func_names

# now for sanity, ensure the order that the function definitions appear
Expand Down
Loading

0 comments on commit 6af3191

Please sign in to comment.