From 26ae9906d92d3dbdf0d6f935234ab8ad9f357cf9 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Wed, 29 Mar 2023 09:58:57 +0800 Subject: [PATCH 01/14] drop python 38 and 39 --- .github/workflows/build.yml | 4 ++-- .github/workflows/test.yml | 22 +++++++++++----------- .pre-commit-config.yaml | 2 +- .readthedocs.yaml | 2 +- Dockerfile | 2 +- pyproject.toml | 2 +- setup.py | 4 +--- tox.ini | 6 ++---- vyper/ast/README.md | 2 +- 9 files changed, 21 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5737f4bcb5..872d8366e1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,7 +33,7 @@ jobs: - name: Python uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: "3.10" - name: Generate Binary run: >- @@ -60,7 +60,7 @@ jobs: - name: Python uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: "3.10" - name: Generate Binary run: >- diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b435ca3e90..c862cb2eb5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,10 +17,10 @@ jobs: steps: - uses: actions/checkout@v1 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.10 - name: Install Dependencies run: pip install .[lint] @@ -42,10 +42,10 @@ jobs: steps: - uses: actions/checkout@v1 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.10 - name: Install Tox run: pip install tox @@ -59,10 +59,10 @@ jobs: steps: - uses: actions/checkout@v1 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.10 - name: Install Tox run: pip install tox @@ -75,7 +75,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [["3.8", "38"], ["3.9", "39"], ["3.10", "310"]] + python-version: [["3.10", "310"]] # run in default (optimized) and --no-optimize mode flag: ["core", "no-opt"] @@ -126,10 +126,10 @@ jobs: steps: - uses: actions/checkout@v1 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.10 - name: Install Tox run: pip install tox @@ -167,10 +167,10 @@ jobs: steps: - uses: actions/checkout@v1 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.10 - name: Install Tox run: pip install tox diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9fbe957c15..739e977c96 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,4 +24,4 @@ repos: - "types-setuptools" default_language_version: - python: python3.8 + python: python3.10 diff --git a/.readthedocs.yaml b/.readthedocs.yaml index da7e2e4ec6..7bcb51e797 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -11,6 +11,6 @@ formats: all # Explicitly set the version of Python and its requirements python: - version: 3.8 + version: 3.10 install: - requirements: requirements-docs.txt diff --git a/Dockerfile b/Dockerfile index d5f60c5d79..c2245ee981 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.8-slim +FROM python:3.10-slim # Specify label-schema specific arguments and labels. ARG BUILD_DATE diff --git a/pyproject.toml b/pyproject.toml index f646c2f664..af87f2b5cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ [tool.black] line-length = 100 -target-version = ['py37', 'py38', 'py39'] +target-version = ['py310'] include = '\.pyi?$' exclude = ''' /( diff --git a/setup.py b/setup.py index 1f59f035a5..a167fadf06 100644 --- a/setup.py +++ b/setup.py @@ -89,7 +89,7 @@ def _global_version(version): keywords="ethereum evm smart contract language", include_package_data=True, packages=find_packages(exclude=("tests", "docs")), - python_requires=">=3.8,<4", + python_requires=">=3.10,<4", py_modules=["vyper"], install_requires=[ "asttokens>=2.0.5,<3", @@ -112,8 +112,6 @@ def _global_version(version): classifiers=[ "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", ], package_data={"vyper.ast": ["grammar.lark"]}, diff --git a/tox.ini b/tox.ini index 87a67c3c85..0b17eae0ca 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{38,39,310}-{core,no-opt} + py{310}-{core,no-opt} lint mypy docs @@ -11,8 +11,6 @@ commands = core: pytest -m "not fuzzing" --showlocals {posargs:tests/} no-opt: pytest -m "not fuzzing" --showlocals --no-optimize {posargs:tests/} basepython = - py38: python3.8 - py39: python3.9 py310: python3.10 extras = test @@ -47,7 +45,7 @@ whitelist_externals = make basepython = python3 extras = lint commands = - black -C -t py38 {toxinidir}/vyper {toxinidir}/tests {toxinidir}/setup.py + black -C -t py310 {toxinidir}/vyper {toxinidir}/tests {toxinidir}/setup.py flake8 {toxinidir}/vyper {toxinidir}/tests isort {toxinidir}/vyper {toxinidir}/tests {toxinidir}/setup.py diff --git a/vyper/ast/README.md b/vyper/ast/README.md index 826bc55e59..320c69da0c 100644 --- a/vyper/ast/README.md +++ b/vyper/ast/README.md @@ -99,7 +99,7 @@ silently included in the nodes. To learn more about `__slots__`: -* Python Documentation: [`__slots__`](https://docs.python.org/3.8/reference/datamodel.html#slots) +* Python Documentation: [`__slots__`](https://docs.python.org/3.10/reference/datamodel.html#slots) * Stack Overflow: [Usage of `__slots__`?](https://stackoverflow.com/a/28059785/11451521) ### Interface Files (`.pyi`) From 212d98dc003070b40c25a00bdcd0957e96c5bc7a Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Wed, 29 Mar 2023 10:34:01 +0800 Subject: [PATCH 02/14] fix python version in CI --- .github/workflows/test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c862cb2eb5..d6808a000b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: - name: Set up Python 3.10 uses: actions/setup-python@v1 with: - python-version: 3.10 + python-version: "3.10" - name: Install Dependencies run: pip install .[lint] @@ -45,7 +45,7 @@ jobs: - name: Set up Python 3.10 uses: actions/setup-python@v1 with: - python-version: 3.10 + python-version: "3.10" - name: Install Tox run: pip install tox @@ -62,7 +62,7 @@ jobs: - name: Set up Python 3.10 uses: actions/setup-python@v1 with: - python-version: 3.10 + python-version: "3.10" - name: Install Tox run: pip install tox @@ -129,7 +129,7 @@ jobs: - name: Set up Python 3.10 uses: actions/setup-python@v1 with: - python-version: 3.10 + python-version: "3.10" - name: Install Tox run: pip install tox @@ -170,7 +170,7 @@ jobs: - name: Set up Python 3.10 uses: actions/setup-python@v1 with: - python-version: 3.10 + python-version: "3.10" - name: Install Tox run: pip install tox From 4984b75166a2fbe89b1d17572dc2cfb5dac3306f Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Wed, 29 Mar 2023 10:45:11 +0800 Subject: [PATCH 03/14] bump black; remove black dependency pin for click --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index a167fadf06..ae7bcf4d07 100644 --- a/setup.py +++ b/setup.py @@ -22,8 +22,7 @@ "hypothesis[lark]>=5.37.1,<6.0", ], "lint": [ - "black==21.9b0", - "click<8.1.0", # temporary pin - black21.9b0 fails with 8.1.0 + "black==23.3.0", "flake8==3.9.2", "flake8-bugbear==20.1.4", "flake8-use-fstring==1.1", From ff682cd6a672c72db2a89153d14699a8881c909a Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Wed, 29 Mar 2023 10:45:24 +0800 Subject: [PATCH 04/14] update new black lint --- vyper/__main__.py | 1 - vyper/ast/folding.py | 6 +- vyper/ast/natspec.py | 1 - vyper/ast/nodes.py | 4 +- vyper/ast/validation.py | 2 +- vyper/builtins/_convert.py | 6 +- vyper/builtins/_signatures.py | 1 - vyper/builtins/functions.py | 81 +++++-------------- vyper/cli/vyper_compile.py | 2 - vyper/cli/vyper_json.py | 1 - vyper/cli/vyper_serve.py | 1 - vyper/codegen/abi_encoder.py | 1 - vyper/codegen/arithmetic.py | 28 +++---- vyper/codegen/core.py | 7 +- vyper/codegen/expr.py | 5 +- .../function_definitions/external_function.py | 1 - vyper/codegen/ir_node.py | 4 +- vyper/codegen/return_.py | 2 - vyper/compiler/output.py | 3 +- vyper/compiler/phases.py | 1 - vyper/ir/compile_ir.py | 6 +- vyper/ir/optimizer.py | 4 +- vyper/semantics/analysis/annotation.py | 2 - vyper/semantics/analysis/common.py | 1 - vyper/semantics/analysis/data_positions.py | 5 +- vyper/semantics/analysis/local.py | 2 - vyper/semantics/analysis/module.py | 2 - vyper/semantics/analysis/utils.py | 2 - vyper/semantics/types/function.py | 2 - vyper/semantics/types/primitives.py | 6 +- vyper/semantics/types/subscriptable.py | 3 +- vyper/semantics/types/user.py | 1 - vyper/utils.py | 34 ++++---- 33 files changed, 73 insertions(+), 155 deletions(-) diff --git a/vyper/__main__.py b/vyper/__main__.py index 5fe6f54cd6..371975c301 100644 --- a/vyper/__main__.py +++ b/vyper/__main__.py @@ -5,7 +5,6 @@ from vyper.cli import vyper_compile, vyper_ir, vyper_serve if __name__ == "__main__": - allowed_subcommands = ("--vyper-compile", "--vyper-ir", "--vyper-serve") if len(sys.argv) <= 1 or sys.argv[1] not in allowed_subcommands: diff --git a/vyper/ast/folding.py b/vyper/ast/folding.py index cd0fcc3c55..fbd1dfc2f4 100644 --- a/vyper/ast/folding.py +++ b/vyper/ast/folding.py @@ -15,11 +15,11 @@ "empty(bytes32)", ), # NOQA: E501 "ZERO_ADDRESS": (vy_ast.Hex, "0x0000000000000000000000000000000000000000", "empty(address)"), - "MAX_INT128": (vy_ast.Int, 2 ** 127 - 1, "max_value(int128)"), - "MIN_INT128": (vy_ast.Int, -(2 ** 127), "min_value(int128)"), + "MAX_INT128": (vy_ast.Int, 2**127 - 1, "max_value(int128)"), + "MIN_INT128": (vy_ast.Int, -(2**127), "min_value(int128)"), "MAX_DECIMAL": (vy_ast.Decimal, SizeLimits.MAX_AST_DECIMAL, "max_value(decimal)"), "MIN_DECIMAL": (vy_ast.Decimal, SizeLimits.MIN_AST_DECIMAL, "min_value(decimal)"), - "MAX_UINT256": (vy_ast.Int, 2 ** 256 - 1, "max_value(uint256)"), + "MAX_UINT256": (vy_ast.Int, 2**256 - 1, "max_value(uint256)"), } diff --git a/vyper/ast/natspec.py b/vyper/ast/natspec.py index f169c7695e..e6f0fcd00b 100644 --- a/vyper/ast/natspec.py +++ b/vyper/ast/natspec.py @@ -73,7 +73,6 @@ def _parse_docstring( params: Optional[Tuple] = None, return_length: int = 0, ) -> dict: - natspec: dict = {} if params is None: params = tuple() diff --git a/vyper/ast/nodes.py b/vyper/ast/nodes.py index 39add6905b..cbbd019337 100644 --- a/vyper/ast/nodes.py +++ b/vyper/ast/nodes.py @@ -939,7 +939,7 @@ class Invert(Operator): _pretty = "~" def _op(self, value): - return (2 ** 256 - 1) ^ value + return (2**256 - 1) ^ value class BinOp(ExprNode): @@ -1048,7 +1048,7 @@ def _op(self, left, right): raise TypeMismatch("Cannot perform exponentiation on decimal values.", self._parent) if right < 0: raise InvalidOperation("Cannot calculate a negative power", self._parent) - return int(left ** right) + return int(left**right) class BitAnd(Operator): diff --git a/vyper/ast/validation.py b/vyper/ast/validation.py index cd169178f6..7742d60c01 100644 --- a/vyper/ast/validation.py +++ b/vyper/ast/validation.py @@ -45,7 +45,7 @@ def validate_call_args( # -1 is sentinel which means we have varargs. # set arg_count[1] to some large number that we # would never see in practice - arg_count = (arg_count[0], 2 ** 64) + arg_count = (arg_count[0], 2**64) if arg_count[0] == arg_count[1]: arg_count == arg_count[0] diff --git a/vyper/builtins/_convert.py b/vyper/builtins/_convert.py index 08657c57d3..407a32f3e9 100644 --- a/vyper/builtins/_convert.py +++ b/vyper/builtins/_convert.py @@ -109,7 +109,7 @@ def _clamp_numeric_convert(arg, arg_bounds, out_bounds, arg_is_signed): if arg_hi > out_hi: # out_hi must be smaller than MAX_UINT256, so clample makes sense. # add an assertion, just in case this assumption ever changes. - assert out_hi < 2 ** 256 - 1, "bad assumption in numeric convert" + assert out_hi < 2**256 - 1, "bad assumption in numeric convert" CLAMP_OP = "sle" if arg_is_signed else "le" arg = clamp(CLAMP_OP, arg, out_hi) @@ -156,7 +156,6 @@ def _int_to_int(arg, out_typ): # _clamp_numeric_convert(arg, arg.typ.int_bounds, out_typ.int_bounds, arg.typ.is_signed) # but with better code size and gas. if arg.typ.is_signed and not out_typ.is_signed: - # e.g. (clample (clampge arg 0) (2**128 - 1)) # note that when out_typ.bits == 256, @@ -164,7 +163,6 @@ def _int_to_int(arg, out_typ): # see similar assertion in _clamp_numeric_convert. if out_typ.bits < arg.typ.bits: - assert out_typ.bits < 256, "unreachable" # note: because of the usage of signed=False, and the fact # that out_bits < 256 in this branch, below implies @@ -359,7 +357,7 @@ def to_decimal(expr, arg, out_typ): elif arg.typ == BoolT(): # TODO: consider adding is_signed and bits to bool so we can use _int_to_fixed - arg = ["mul", arg, 10 ** out_typ.decimals] + arg = ["mul", arg, 10**out_typ.decimals] return IRnode.from_list(arg, typ=out_typ) else: raise CompilerPanic("unreachable") # pragma: notest diff --git a/vyper/builtins/_signatures.py b/vyper/builtins/_signatures.py index 3ee379a806..d39a4a085f 100644 --- a/vyper/builtins/_signatures.py +++ b/vyper/builtins/_signatures.py @@ -75,7 +75,6 @@ def decorator_fn(self, node, context): class BuiltinFunction: - _has_varargs = False _kwargs: Dict[str, KwargSettings] = {} diff --git a/vyper/builtins/functions.py b/vyper/builtins/functions.py index 64452c39ac..6c00678d5c 100644 --- a/vyper/builtins/functions.py +++ b/vyper/builtins/functions.py @@ -133,7 +133,6 @@ def infer_arg_types(self, node): class Floor(BuiltinFunction): - _id = "floor" _inputs = [("value", DecimalT())] # TODO: maybe use int136? @@ -161,7 +160,6 @@ def build_IR(self, expr, args, kwargs, context): class Ceil(BuiltinFunction): - _id = "ceil" _inputs = [("value", DecimalT())] # TODO: maybe use int136? @@ -189,7 +187,6 @@ def build_IR(self, expr, args, kwargs, context): class Convert(BuiltinFunction): - _id = "convert" def fetch_call_return(self, node): @@ -283,7 +280,6 @@ def _build_adhoc_slice_node(sub: IRnode, start: IRnode, length: IRnode, context: # note: this and a lot of other builtins could be refactored to accept any uint type class Slice(BuiltinFunction): - _id = "slice" _inputs = [ ("b", (BYTES32_T, BytesT.any(), StringT.any())), @@ -344,7 +340,6 @@ def infer_arg_types(self, node): @process_inputs def build_IR(self, expr, args, kwargs, context): - src, start, length = args # Handle `msg.data`, `self.code`, and `
.code` @@ -362,7 +357,6 @@ def build_IR(self, expr, args, kwargs, context): b2, start, ), length.cache_when_complex("length") as (b3, length): - if is_bytes32: src_maxlen = 32 else: @@ -458,7 +452,6 @@ def build_IR(self, expr, args, kwargs, context): class Len(BuiltinFunction): - _id = "len" _inputs = [("b", (StringT.any(), BytesT.any(), DArrayT.any()))] _return_type = UINT256_T @@ -484,7 +477,6 @@ def build_IR(self, node, context): class Concat(BuiltinFunction): - _id = "concat" def fetch_call_return(self, node): @@ -557,7 +549,6 @@ def build_IR(self, expr, context): # TODO: optimize for the case where all lengths are statically known. for arg in args: - dst_data = add_ofst(bytes_data_ptr(dst), ofst) if isinstance(arg.typ, _BytestringT): @@ -569,7 +560,6 @@ def build_IR(self, expr, context): argdata = bytes_data_ptr(arg) with get_bytearray_length(arg).cache_when_complex("len") as (b2, arglen): - do_copy = [ "seq", copy_bytes(dst_data, argdata, arglen, arg.typ.maxlen), @@ -592,7 +582,6 @@ def build_IR(self, expr, context): class Keccak256(BuiltinFunction): - _id = "keccak256" # TODO allow any BytesM_T _inputs = [("value", (BytesT.any(), BYTES32_T, StringT.any()))] @@ -641,7 +630,6 @@ def _make_sha256_call(inp_start, inp_len, out_start, out_len): class Sha256(BuiltinFunction): - _id = "sha256" _inputs = [("value", (BYTES32_T, BytesT.any(), StringT.any()))] _return_type = BYTES32_T @@ -714,7 +702,6 @@ def build_IR(self, expr, args, kwargs, context): class MethodID(FoldedFunction): - _id = "method_id" def evaluate(self, node): @@ -755,7 +742,6 @@ def infer_kwarg_types(self, node): class ECRecover(BuiltinFunction): - _id = "ecrecover" _inputs = [ ("hash", BYTES32_T), @@ -805,7 +791,6 @@ def _getelem(arg, ind): class ECAdd(BuiltinFunction): - _id = "ecadd" _inputs = [("a", SArrayT(UINT256_T, 2)), ("b", SArrayT(UINT256_T, 2))] _return_type = SArrayT(UINT256_T, 2) @@ -832,7 +817,6 @@ def build_IR(self, expr, args, kwargs, context): class ECMul(BuiltinFunction): - _id = "ecmul" _inputs = [("point", SArrayT(UINT256_T, 2)), ("scalar", UINT256_T)] _return_type = SArrayT(UINT256_T, 2) @@ -871,7 +855,6 @@ def _storage_element_getter(index): class Extract32(BuiltinFunction): - _id = "extract32" _inputs = [("b", BytesT.any()), ("start", IntegerT.unsigneds())] # "TYPE_DEFINITION" is a placeholder value for a type definition string, and @@ -984,20 +967,19 @@ def build_IR(self, expr, args, kwargs, context): class AsWeiValue(BuiltinFunction): - _id = "as_wei_value" _inputs = [("value", (IntegerT.any(), DecimalT())), ("unit", StringT.any())] _return_type = UINT256_T wei_denoms = { ("wei",): 1, - ("femtoether", "kwei", "babbage"): 10 ** 3, - ("picoether", "mwei", "lovelace"): 10 ** 6, - ("nanoether", "gwei", "shannon"): 10 ** 9, - ("microether", "szabo"): 10 ** 12, - ("milliether", "finney"): 10 ** 15, - ("ether",): 10 ** 18, - ("kether", "grand"): 10 ** 21, + ("femtoether", "kwei", "babbage"): 10**3, + ("picoether", "mwei", "lovelace"): 10**6, + ("nanoether", "gwei", "shannon"): 10**9, + ("microether", "szabo"): 10**12, + ("milliether", "finney"): 10**15, + ("ether",): 10**18, + ("kether", "grand"): 10**21, } def get_denomination(self, node): @@ -1025,7 +1007,7 @@ def evaluate(self, node): if value < 0: raise InvalidLiteral("Negative wei value not allowed", node.args[0]) - if isinstance(value, int) and value >= 2 ** 256: + if isinstance(value, int) and value >= 2**256: raise InvalidLiteral("Value out of range for uint256", node.args[0]) if isinstance(value, Decimal) and value > SizeLimits.MAX_AST_DECIMAL: raise InvalidLiteral("Value out of range for decimal", node.args[0]) @@ -1083,7 +1065,6 @@ def build_IR(self, expr, args, kwargs, context): class RawCall(BuiltinFunction): - _id = "raw_call" _inputs = [("to", AddressT()), ("data", BytesT.any())] _kwargs = { @@ -1230,7 +1211,6 @@ def build_IR(self, expr, args, kwargs, context): class Send(BuiltinFunction): - _id = "send" _inputs = [("to", AddressT()), ("value", UINT256_T)] # default gas stipend is 0 @@ -1246,7 +1226,6 @@ def build_IR(self, expr, args, kwargs, context): class SelfDestruct(BuiltinFunction): - _id = "selfdestruct" _inputs = [("to", AddressT())] _return_type = None @@ -1261,7 +1240,6 @@ def build_IR(self, expr, args, kwargs, context): class BlockHash(BuiltinFunction): - _id = "blockhash" _inputs = [("block_num", UINT256_T)] _return_type = BYTES32_T @@ -1275,7 +1253,6 @@ def build_IR(self, expr, args, kwargs, contact): class RawRevert(BuiltinFunction): - _id = "raw_revert" _inputs = [("data", BytesT.any())] @@ -1296,7 +1273,6 @@ def build_IR(self, expr, args, kwargs, context): class RawLog(BuiltinFunction): - _id = "raw_log" _inputs = [("topics", DArrayT(BYTES32_T, 4)), ("data", (BYTES32_T, BytesT.any()))] @@ -1348,7 +1324,6 @@ def build_IR(self, expr, args, kwargs, context): class BitwiseAnd(BuiltinFunction): - _id = "bitwise_and" _inputs = [("x", UINT256_T), ("y", UINT256_T)] _return_type = UINT256_T @@ -1363,7 +1338,7 @@ def evaluate(self, node): for arg in node.args: if not isinstance(arg, vy_ast.Num): raise UnfoldableNode - if arg.value < 0 or arg.value >= 2 ** 256: + if arg.value < 0 or arg.value >= 2**256: raise InvalidLiteral("Value out of range for uint256", arg) value = node.args[0].value & node.args[1].value @@ -1375,7 +1350,6 @@ def build_IR(self, expr, args, kwargs, context): class BitwiseOr(BuiltinFunction): - _id = "bitwise_or" _inputs = [("x", UINT256_T), ("y", UINT256_T)] _return_type = UINT256_T @@ -1390,7 +1364,7 @@ def evaluate(self, node): for arg in node.args: if not isinstance(arg, vy_ast.Num): raise UnfoldableNode - if arg.value < 0 or arg.value >= 2 ** 256: + if arg.value < 0 or arg.value >= 2**256: raise InvalidLiteral("Value out of range for uint256", arg) value = node.args[0].value | node.args[1].value @@ -1402,7 +1376,6 @@ def build_IR(self, expr, args, kwargs, context): class BitwiseXor(BuiltinFunction): - _id = "bitwise_xor" _inputs = [("x", UINT256_T), ("y", UINT256_T)] _return_type = UINT256_T @@ -1417,7 +1390,7 @@ def evaluate(self, node): for arg in node.args: if not isinstance(arg, vy_ast.Num): raise UnfoldableNode - if arg.value < 0 or arg.value >= 2 ** 256: + if arg.value < 0 or arg.value >= 2**256: raise InvalidLiteral("Value out of range for uint256", arg) value = node.args[0].value ^ node.args[1].value @@ -1429,7 +1402,6 @@ def build_IR(self, expr, args, kwargs, context): class BitwiseNot(BuiltinFunction): - _id = "bitwise_not" _inputs = [("x", UINT256_T)] _return_type = UINT256_T @@ -1445,10 +1417,10 @@ def evaluate(self, node): raise UnfoldableNode value = node.args[0].value - if value < 0 or value >= 2 ** 256: + if value < 0 or value >= 2**256: raise InvalidLiteral("Value out of range for uint256", node.args[0]) - value = (2 ** 256 - 1) - value + value = (2**256 - 1) - value return vy_ast.Int.from_node(node, value=value) @process_inputs @@ -1457,7 +1429,6 @@ def build_IR(self, expr, args, kwargs, context): class Shift(BuiltinFunction): - _id = "shift" _inputs = [("x", (UINT256_T, INT256_T)), ("_shift", IntegerT.any())] _return_type = UINT256_T @@ -1467,7 +1438,7 @@ def evaluate(self, node): if [i for i in node.args if not isinstance(i, vy_ast.Num)]: raise UnfoldableNode value, shift = [i.value for i in node.args] - if value < 0 or value >= 2 ** 256: + if value < 0 or value >= 2**256: raise InvalidLiteral("Value out of range for uint256", node.args[0]) if shift < -256 or shift > 256: # this validation is performed to prevent the compiler from hanging @@ -1478,7 +1449,7 @@ def evaluate(self, node): if shift < 0: value = value >> -shift else: - value = (value << shift) % (2 ** 256) + value = (value << shift) % (2**256) return vy_ast.Int.from_node(node, value=value) def fetch_call_return(self, node): @@ -1507,7 +1478,6 @@ def build_IR(self, expr, args, kwargs, context): class _AddMulMod(BuiltinFunction): - _inputs = [("a", UINT256_T), ("b", UINT256_T), ("c", UINT256_T)] _return_type = UINT256_T @@ -1518,7 +1488,7 @@ def evaluate(self, node): for arg in node.args: if not isinstance(arg, vy_ast.Num): raise UnfoldableNode - if arg.value < 0 or arg.value >= 2 ** 256: + if arg.value < 0 or arg.value >= 2**256: raise InvalidLiteral("Value out of range for uint256", arg) value = self._eval_fn(node.args[0].value, node.args[1].value) % node.args[2].value @@ -1557,7 +1527,7 @@ def evaluate(self, node): if left.value < 0 or right.value < 0: raise UnfoldableNode - value = pow(left.value, right.value, 2 ** 256) + value = pow(left.value, right.value, 2**256) return vy_ast.Int.from_node(node, value=value) def build_IR(self, expr, context): @@ -1604,6 +1574,7 @@ def build_IR(self, expr, context): # CREATE* functions + # create helper functions # generates CREATE op sequence + zero check for result def _create_ir(value, buf, length, salt=None, checked=True): @@ -1686,7 +1657,6 @@ def eip1167_bytecode(): # returns the code starting from 0x0b with len `codesize`. # NOTE: it assumes codesize <= 2**24. def _create_preamble(codesize): - from vyper.ir.compile_ir import assembly_to_evm evm_len = 0x0B # 11 bytes @@ -1750,7 +1720,6 @@ def _add_gas_estimate(self, args, should_use_create2): return _create_addl_gas_estimate(bytecode_len, should_use_create2) def _build_create_IR(self, expr, args, context, value, salt): - target_address = args[0] buf = context.new_internal_variable(BytesT(96)) @@ -1794,7 +1763,6 @@ def build_IR(self, expr, context): class CreateCopyOf(_CreateBase): - _id = "create_copy_of" _inputs = [("target", AddressT())] @@ -1840,7 +1808,6 @@ def _build_create_IR(self, expr, args, context, value, salt): class CreateFromBlueprint(_CreateBase): - _id = "create_from_blueprint" _inputs = [("target", AddressT())] _kwargs = { @@ -1934,7 +1901,6 @@ def _build_create_IR(self, expr, args, context, value, salt, code_offset, raw_ar class _UnsafeMath(BuiltinFunction): - # TODO add unsafe math for `decimal`s _inputs = [("a", IntegerT.any()), ("b", IntegerT.any())] @@ -1977,7 +1943,7 @@ def build_IR(self, expr, args, kwargs, context): else: # e.g. uint8 -> (mod (add x y) 256) # TODO mod_bound could be a really large literal - ret = ["mod", ret, 2 ** a.typ.bits] + ret = ["mod", ret, 2**a.typ.bits] return IRnode.from_list(ret, typ=otyp) @@ -2001,7 +1967,6 @@ class UnsafeDiv(_UnsafeMath): class _MinMax(BuiltinFunction): - _inputs = [("a", (DecimalT(), IntegerT.any())), ("b", (DecimalT(), IntegerT.any()))] def evaluate(self, node): @@ -2051,7 +2016,6 @@ def build_IR(self, expr, args, kwargs, context): b2, right, ): - if left.typ == right.typ: if left.typ != UINT256_T: # if comparing like types that are not uint256, use SLT or SGT @@ -2105,7 +2069,6 @@ def build_IR(self, expr, args, kwargs, context): n_digits = return_t.maxlen with args[0].cache_when_complex("val") as (b1, val): - buf = context.new_internal_variable(return_t) i = IRnode.from_list(context.fresh_varname("uint2str_i"), typ=UINT256_T) @@ -2150,7 +2113,6 @@ def build_IR(self, expr, args, kwargs, context): class Sqrt(BuiltinFunction): - _id = "sqrt" _inputs = [("d", DecimalT())] _return_type = DecimalT() @@ -2207,7 +2169,6 @@ def build_IR(self, expr, args, kwargs, context): class ISqrt(BuiltinFunction): - _id = "isqrt" _inputs = [("d", UINT256_T)] _return_type = UINT256_T @@ -2242,7 +2203,7 @@ def build_IR(self, expr, args, kwargs, context): ["seq", ["set", y, shr(16, y)], ["set", z, shl(8, z)]], ], ] - ret.append(["set", z, ["div", ["mul", z, ["add", y, 2 ** 16]], 2 ** 18]]) + ret.append(["set", z, ["div", ["mul", z, ["add", y, 2**16]], 2**18]]) for _ in range(7): ret.append(["set", z, ["div", ["add", ["div", x, z], z], 2]]) @@ -2258,7 +2219,6 @@ def build_IR(self, expr, args, kwargs, context): class Empty(TypenameFoldedFunction): - _id = "empty" def fetch_call_return(self, node): @@ -2535,7 +2495,6 @@ def build_IR(self, expr, args, kwargs, context): data = ensure_in_memory(data, context) with data.cache_when_complex("to_decode") as (b1, data): - data_ptr = bytes_data_ptr(data) data_len = get_bytearray_length(data) diff --git a/vyper/cli/vyper_compile.py b/vyper/cli/vyper_compile.py index 40f87d860a..09ddd971ee 100755 --- a/vyper/cli/vyper_compile.py +++ b/vyper/cli/vyper_compile.py @@ -199,7 +199,6 @@ def get_interface_codes(root_path: Path, contract_sources: ContractCodes) -> Dic interface_codes = extract_file_interface_imports(code) for interface_name, interface_path in interface_codes.items(): - base_paths = [parent_path] if not interface_path.startswith(".") and root_path.joinpath(file_path).exists(): base_paths.append(root_path) @@ -257,7 +256,6 @@ def compile_files( storage_layout: Iterable[str] = None, no_bytecode_metadata: bool = False, ) -> OrderedDict: - root_path = Path(root_folder).resolve() if not root_path.exists(): raise FileNotFoundError(f"Invalid root path - '{root_path.as_posix()}' does not exist") diff --git a/vyper/cli/vyper_json.py b/vyper/cli/vyper_json.py index 0abefdebff..dcbf61740a 100755 --- a/vyper/cli/vyper_json.py +++ b/vyper/cli/vyper_json.py @@ -392,7 +392,6 @@ def compile_from_input_dict( def format_to_output_dict(compiler_data: Dict) -> Dict: output_dict: Dict = {"compiler": f"vyper-{vyper.__version__}", "contracts": {}, "sources": {}} for id_, (path, data) in enumerate(compiler_data.items()): - output_dict["sources"][path] = {"id": id_} if "ast_dict" in data: output_dict["sources"][path]["ast"] = data["ast_dict"]["ast"] diff --git a/vyper/cli/vyper_serve.py b/vyper/cli/vyper_serve.py index 564e0d0110..87fd3a3387 100755 --- a/vyper/cli/vyper_serve.py +++ b/vyper/cli/vyper_serve.py @@ -64,7 +64,6 @@ def do_GET(self): return def do_POST(self): - if self.path == "/compile": content_len = int(self.headers.get("content-length")) post_body = self.rfile.read(content_len) diff --git a/vyper/codegen/abi_encoder.py b/vyper/codegen/abi_encoder.py index 112385e992..e76fbf2f64 100644 --- a/vyper/codegen/abi_encoder.py +++ b/vyper/codegen/abi_encoder.py @@ -190,7 +190,6 @@ def abi_encode(dst, ir_node, context, bufsz, returns_len=False): with ir_node.cache_when_complex("to_encode") as (b1, ir_node), dst.cache_when_complex( "dst" ) as (b2, dst): - dyn_ofst = "dyn_ofst" # current offset in the dynamic section if ir_node.typ._is_prim_word: diff --git a/vyper/codegen/arithmetic.py b/vyper/codegen/arithmetic.py index c91d0ecc58..8f8a9f904b 100644 --- a/vyper/codegen/arithmetic.py +++ b/vyper/codegen/arithmetic.py @@ -41,9 +41,9 @@ def calculate_largest_power(a: int, num_bits: int, is_signed: bool) -> int: raise CompilerPanic("Exponential operation is useless!") value_bits = num_bits - (1 if is_signed else 0) - if a >= 2 ** value_bits: # pragma: no cover + if a >= 2**value_bits: # pragma: no cover raise TypeCheckFailure("Value is too large and will always throw") - if a < -(2 ** value_bits): # pragma: no cover + if a < -(2**value_bits): # pragma: no cover raise TypeCheckFailure("Value is too small and will always throw") a_is_negative = a < 0 @@ -65,11 +65,11 @@ def calculate_largest_power(a: int, num_bits: int, is_signed: bool) -> int: # x = ln(2**value_bits) / ln(a) num_iterations = 0 - while a ** (b + 1) < 2 ** value_bits: + while a ** (b + 1) < 2**value_bits: b += 1 num_iterations += 1 assert num_iterations < 10000 - while a ** b >= 2 ** value_bits: + while a**b >= 2**value_bits: b -= 1 num_iterations += 1 assert num_iterations < 10000 @@ -78,7 +78,7 @@ def calculate_largest_power(a: int, num_bits: int, is_signed: bool) -> int: # (-a) ** (b + 1) == -(2 ** value_bits) # we can squeak one more out of it because lower bound of signed ints # is slightly wider than upper bound - if a_is_negative and (-a) ** (b + 1) == -(2 ** value_bits): # NOTE: a = abs(a) + if a_is_negative and (-a) ** (b + 1) == -(2**value_bits): # NOTE: a = abs(a) return b + 1 else: return b # Exact @@ -132,11 +132,11 @@ def calculate_largest_base(b: int, num_bits: int, is_signed: bool) -> Tuple[int, a = math.ceil(2 ** (decimal.Decimal(value_bits) / decimal.Decimal(b))) # Do a bit of iteration to ensure we have the exact number num_iterations = 0 - while (a + 1) ** b < 2 ** value_bits: + while (a + 1) ** b < 2**value_bits: a += 1 num_iterations += 1 assert num_iterations < 10000 - while a ** b >= 2 ** value_bits: + while a**b >= 2**value_bits: a -= 1 num_iterations += 1 assert num_iterations < 10000 @@ -144,7 +144,7 @@ def calculate_largest_base(b: int, num_bits: int, is_signed: bool) -> Tuple[int, if not is_signed: return 0, a - if (a + 1) ** b == (2 ** value_bits): + if (a + 1) ** b == (2**value_bits): # edge case: lower bound is slightly wider than upper bound return -(a + 1), a else: @@ -231,7 +231,6 @@ def safe_mul(x, y): DIV = "sdiv" if typ.is_signed else "div" with res.cache_when_complex("ans") as (b1, res): - ok = [1] # True if typ.bits > 128: # check overflow mod 256 @@ -247,7 +246,7 @@ def safe_mul(x, y): if version_check(begin="constantinople"): upper_bound = ["shl", 255, 1] else: - upper_bound = -(2 ** 255) + upper_bound = -(2**255) check_x = ["ne", x, upper_bound] check_y = ["ne", ["not", y], 0] @@ -257,7 +256,7 @@ def safe_mul(x, y): ok = ["and", ok, ["or", check_x, check_y]] # TODO push some of this constant folding into optimizer - elif x.is_literal and x.value == -(2 ** 255): + elif x.is_literal and x.value == -(2**255): ok = ["and", ok, check_y] elif y.is_literal and y.value == -1: ok = ["and", ok, check_x] @@ -291,7 +290,7 @@ def safe_div(x, y): if is_decimal_type(x.typ): lo, hi = typ.int_bounds - if max(abs(lo), abs(hi)) * typ.divisor > 2 ** 256 - 1: + if max(abs(lo), abs(hi)) * typ.divisor > 2**256 - 1: # stub to prevent us from adding fixed point numbers we don't know # how to deal with raise UnimplementedException("safe_mul for decimal{typ.bits}x{typ.decimals}") @@ -300,18 +299,17 @@ def safe_div(x, y): DIV = "sdiv" if typ.is_signed else "div" res = IRnode.from_list([DIV, x, clamp("gt", y, 0)], typ=typ) with res.cache_when_complex("res") as (b1, res): - # TODO: refactor this condition / push some things into the optimizer if typ.is_signed and typ.bits == 256: if version_check(begin="constantinople"): upper_bound = ["shl", 255, 1] else: - upper_bound = -(2 ** 255) + upper_bound = -(2**255) if not x.is_literal and not y.is_literal: ok = ["or", ["ne", y, ["not", 0]], ["ne", x, upper_bound]] # TODO push these rules into the optimizer - elif x.is_literal and x.value == -(2 ** 255): + elif x.is_literal and x.value == -(2**255): ok = ["ne", y, ["not", 0]] elif y.is_literal and y.value == -1: ok = ["ne", x, upper_bound] diff --git a/vyper/codegen/core.py b/vyper/codegen/core.py index cde65adc9e..ca161ddb8d 100644 --- a/vyper/codegen/core.py +++ b/vyper/codegen/core.py @@ -114,7 +114,6 @@ def make_byte_array_copier(dst, src): with src.cache_when_complex("src") as (b1, src): with get_bytearray_length(src).cache_when_complex("len") as (b2, len_): - max_bytes = src.typ.maxlen ret = ["seq"] @@ -171,7 +170,6 @@ def _dynarray_make_setter(dst, src): return ret with src.cache_when_complex("darray_src") as (b1, src): - # for ABI-encoded dynamic data, we must loop to unpack, since # the layout does not match our memory layout should_loop = src.encoding == Encoding.ABI and src.typ.value_type.abi_type.is_dynamic() @@ -237,7 +235,6 @@ def copy_bytes(dst, src, length, length_bound): with src.cache_when_complex("src") as (b1, src), length.cache_when_complex( "copy_bytes_count" ) as (b2, length), dst.cache_when_complex("dst") as (b3, dst): - assert isinstance(length_bound, int) and length_bound >= 0 # correctness: do not clobber dst @@ -484,7 +481,6 @@ def has_length_word(typ): # TODO simplify this code, especially the ABI decoding def _get_element_ptr_array(parent, key, array_bounds_check): - assert is_array_like(parent.typ) if not is_integer_type(key.typ): @@ -750,7 +746,7 @@ def FAIL(): # pragma: no cover else: if len(left.typ.member_types) != len(right.typ.member_types): FAIL() # pragma: notest - for (l, r) in zip(left.typ.member_types, right.typ.member_types): + for l, r in zip(left.typ.member_types, right.typ.member_types): # TODO recurse into left, right if literals? check_assign(dummy_node_for_type(l), dummy_node_for_type(r)) @@ -886,7 +882,6 @@ def _complex_make_setter(left, right): # general case # TODO use copy_bytes when the generated code is above a certain size with left.cache_when_complex("_L") as (b1, left), right.cache_when_complex("_R") as (b2, right): - for k in keys: l_i = get_element_ptr(left, k, array_bounds_check=False) r_i = get_element_ptr(right, k, array_bounds_check=False) diff --git a/vyper/codegen/expr.py b/vyper/codegen/expr.py index e95bec884c..33c400941e 100644 --- a/vyper/codegen/expr.py +++ b/vyper/codegen/expr.py @@ -159,7 +159,6 @@ def parse_NameConstant(self): # Variable names def parse_Name(self): - if self.expr.id == "self": return IRnode.from_list(["address"], typ=AddressT()) elif self.expr.id in self.context.vars: @@ -203,7 +202,7 @@ def parse_Attribute(self): ): # 0, 1, 2, .. 255 enum_id = typ._enum_members[self.expr.attr] - value = 2 ** enum_id # 0 => 0001, 1 => 0010, 2 => 0100, etc. + value = 2**enum_id # 0 => 0001, 1 => 0010, 2 => 0100, etc. return IRnode.from_list(value, typ=typ) # x.balance: balance of address x @@ -602,7 +601,7 @@ def parse_UnaryOp(self): # `operand`. `mask` could be a very large constant and # hurt codesize, but most user enums will likely have few # enough members that the mask will not be large. - mask = (2 ** n_members) - 1 + mask = (2**n_members) - 1 return IRnode.from_list(["xor", mask, operand], typ=operand.typ) if operand.typ == UINT256_T: diff --git a/vyper/codegen/function_definitions/external_function.py b/vyper/codegen/function_definitions/external_function.py index 6de5bab16f..feb2973e2a 100644 --- a/vyper/codegen/function_definitions/external_function.py +++ b/vyper/codegen/function_definitions/external_function.py @@ -28,7 +28,6 @@ def _register_function_args(context: Context, sig: FunctionSignature) -> List[IR base_args_ofst = IRnode(4, location=CALLDATA, typ=base_args_t, encoding=Encoding.ABI) for i, arg in enumerate(sig.base_args): - arg_ir = get_element_ptr(base_args_ofst, i) if needs_clamp(arg.typ, Encoding.ABI): diff --git a/vyper/codegen/ir_node.py b/vyper/codegen/ir_node.py index 9bfe20abe7..c2c127b9d5 100644 --- a/vyper/codegen/ir_node.py +++ b/vyper/codegen/ir_node.py @@ -152,7 +152,7 @@ def _check(condition, err): _check(len(self.args) == 0, "int can't have arguments") # integers must be in the range (MIN_INT256, MAX_UINT256) - _check(-(2 ** 255) <= self.value < 2 ** 256, "out of range") + _check(-(2**255) <= self.value < 2**256, "out of range") self.valency = 1 self._gas = 5 @@ -442,9 +442,7 @@ def _colorise_keywords(val): return val def repr(self) -> str: - if not len(self.args): - if self.annotation: return f"{self.repr_value} " + OKLIGHTBLUE + f"<{self.annotation}>" + ENDC else: diff --git a/vyper/codegen/return_.py b/vyper/codegen/return_.py index 6f2250ddeb..1cd50075a1 100644 --- a/vyper/codegen/return_.py +++ b/vyper/codegen/return_.py @@ -19,7 +19,6 @@ # Generate code for return stmt def make_return_stmt(ir_val: IRnode, stmt: Any, context: Context) -> Optional[IRnode]: - sig = context.sig jump_to_exit = ["exit_to", f"_sym_{sig.exit_sequence_label}"] @@ -55,7 +54,6 @@ def finalize(fill_return_buffer): return finalize(fill_return_buffer) else: # return from external function - external_return_type = calculate_type_for_external_return(context.return_type) maxlen = external_return_type.abi_type.size_bound() diff --git a/vyper/compiler/output.py b/vyper/compiler/output.py index 3c2808d0e6..82e583c160 100644 --- a/vyper/compiler/output.py +++ b/vyper/compiler/output.py @@ -177,7 +177,6 @@ def _build_asm(asm_list): output_string = "" in_push = 0 for node in asm_list: - if isinstance(node, list): output_string += "{ " + _build_asm(node) + "} " continue @@ -253,7 +252,7 @@ def build_blueprint_bytecode_output(compiler_data: CompilerData) -> str: # EIP-170. Ref: https://eips.ethereum.org/EIPS/eip-170 -EIP170_CONTRACT_SIZE_LIMIT: int = 2 ** 14 + 2 ** 13 +EIP170_CONTRACT_SIZE_LIMIT: int = 2**14 + 2**13 def build_bytecode_runtime_output(compiler_data: CompilerData) -> str: diff --git a/vyper/compiler/phases.py b/vyper/compiler/phases.py index 5f9d8a7164..5d16517bc8 100644 --- a/vyper/compiler/phases.py +++ b/vyper/compiler/phases.py @@ -192,7 +192,6 @@ def generate_ast(source_code: str, source_id: int, contract_name: str) -> vy_ast def generate_unfolded_ast( vyper_module: vy_ast.Module, interface_codes: Optional[InterfaceImports] ) -> vy_ast.Module: - vy_ast.validation.validate_literal_nodes(vyper_module) vy_ast.folding.replace_builtin_constants(vyper_module) vy_ast.folding.replace_builtin_functions(vyper_module) diff --git a/vyper/ir/compile_ir.py b/vyper/ir/compile_ir.py index bc5e17fa40..c24b3a67a2 100644 --- a/vyper/ir/compile_ir.py +++ b/vyper/ir/compile_ir.py @@ -256,11 +256,11 @@ def _height_of(witharg): # Numbers elif isinstance(code.value, int): - if code.value < -(2 ** 255): + if code.value < -(2**255): raise Exception(f"Value too low: {code.value}") - elif code.value >= 2 ** 256: + elif code.value >= 2**256: raise Exception(f"Value too high: {code.value}") - return PUSH(code.value % 2 ** 256) + return PUSH(code.value % 2**256) # Variables connected to with statements elif isinstance(code.value, str) and code.value in withargs: diff --git a/vyper/ir/optimizer.py b/vyper/ir/optimizer.py index 4382c54eef..f54b0e8115 100644 --- a/vyper/ir/optimizer.py +++ b/vyper/ir/optimizer.py @@ -31,7 +31,7 @@ def _evm_int(node: IRnode, unsigned: bool = True) -> Optional[int]: if unsigned and ret < 0: return signed_to_unsigned(ret, 256, strict=True) - elif not unsigned and ret > 2 ** 255 - 1: + elif not unsigned and ret > 2**255 - 1: return unsigned_to_signed(ret, 256, strict=True) return ret @@ -97,7 +97,7 @@ def _shorten_annotation(annotation): def _wrap256(x, unsigned=UNSIGNED): - x %= 2 ** 256 + x %= 2**256 # wrap in a signed way. if not unsigned: x = unsigned_to_signed(x, 256, strict=True) diff --git a/vyper/semantics/analysis/annotation.py b/vyper/semantics/analysis/annotation.py index 40362bc553..3d2397f30d 100644 --- a/vyper/semantics/analysis/annotation.py +++ b/vyper/semantics/analysis/annotation.py @@ -36,7 +36,6 @@ def visit(self, node, *args): class StatementAnnotationVisitor(_AnnotationVisitorBase): - ignored_types = (vy_ast.Break, vy_ast.Continue, vy_ast.Pass, vy_ast.Raise) def __init__(self, fn_node: vy_ast.FunctionDef, namespace: dict) -> None: @@ -99,7 +98,6 @@ def visit_For(self, node): class ExpressionAnnotationVisitor(_AnnotationVisitorBase): - ignored_types = () def __init__(self, fn_node: ContractFunctionT): diff --git a/vyper/semantics/analysis/common.py b/vyper/semantics/analysis/common.py index eb3bde46e0..193d1892e1 100644 --- a/vyper/semantics/analysis/common.py +++ b/vyper/semantics/analysis/common.py @@ -4,7 +4,6 @@ class VyperNodeVisitorBase: - ignored_types: Tuple = () scope_name = "" diff --git a/vyper/semantics/analysis/data_positions.py b/vyper/semantics/analysis/data_positions.py index 0cfb350638..5c1347d5a3 100644 --- a/vyper/semantics/analysis/data_positions.py +++ b/vyper/semantics/analysis/data_positions.py @@ -53,7 +53,7 @@ def _reserve_slots(self, slots: List[int], var_name: str) -> None: self._reserve_slot(slot, var_name) def _reserve_slot(self, slot: int, var_name: str) -> None: - if slot < 0 or slot >= 2 ** 256: + if slot < 0 or slot >= 2**256: raise StorageLayoutException( f"Invalid storage slot for var {var_name}, out of bounds: {slot}" ) @@ -112,7 +112,6 @@ def set_storage_slots_with_overrides( # Iterate through variables for node in vyper_module.get_children(vy_ast.VariableDecl): - # Ignore immutable parameters if node.get("annotation.func.id") == "immutable": continue @@ -178,7 +177,6 @@ def set_storage_slots(vyper_module: vy_ast.Module) -> StorageLayout: storage_slot += 1 for node in vyper_module.get_children(vy_ast.VariableDecl): - # skip non-storage variables if node.is_constant or node.is_immutable: continue @@ -210,7 +208,6 @@ def set_memory_offsets(fn_node: vy_ast.FunctionDef) -> None: def set_code_offsets(vyper_module: vy_ast.Module) -> Dict: - ret = {} offset = 0 diff --git a/vyper/semantics/analysis/local.py b/vyper/semantics/analysis/local.py index e4e3a1b00d..56eaf33f70 100644 --- a/vyper/semantics/analysis/local.py +++ b/vyper/semantics/analysis/local.py @@ -49,7 +49,6 @@ def validate_functions(vy_module: vy_ast.Module) -> None: - """Analyzes a vyper ast and validates the function-level namespaces.""" err_list = ExceptionList() @@ -160,7 +159,6 @@ def _validate_msg_data_attribute(node: vy_ast.Attribute) -> None: class FunctionNodeVisitor(VyperNodeVisitorBase): - ignored_types = (vy_ast.Constant, vy_ast.Pass) scope_name = "function" diff --git a/vyper/semantics/analysis/module.py b/vyper/semantics/analysis/module.py index b1be5c29b4..a5c6a6e692 100644 --- a/vyper/semantics/analysis/module.py +++ b/vyper/semantics/analysis/module.py @@ -57,7 +57,6 @@ def _find_cyclic_call(fn_names: list, self_members: dict) -> Optional[list]: class ModuleAnalyzer(VyperNodeVisitorBase): - scope_name = "module" def __init__( @@ -124,7 +123,6 @@ def __init__( raise CallViolation(f"Function '{node.name}' calls into itself", self_node) for fn_name in sorted(function_names): - if fn_name not in self_members: # the referenced function does not exist - this is an issue, but we'll report # it later when parsing the function so we can give more meaningful output diff --git a/vyper/semantics/analysis/utils.py b/vyper/semantics/analysis/utils.py index 0329d6f4e4..342de27019 100644 --- a/vyper/semantics/analysis/utils.py +++ b/vyper/semantics/analysis/utils.py @@ -288,7 +288,6 @@ def types_from_Constant(self, node): raise InvalidLiteral(f"Could not determine type for literal value '{node.value}'", node) def types_from_List(self, node): - # literal array if _is_empty_list(node): # empty list literal `[]` @@ -455,7 +454,6 @@ def get_common_types(*nodes: vy_ast.VyperNode, filter_fn: Callable = None) -> Li # TODO push this into `ArrayT.validate_literal()` def _validate_literal_array(node, expected): - # validate that every item within an array has the same type if isinstance(expected, SArrayT): if len(node.elements) != expected.length: diff --git a/vyper/semantics/types/function.py b/vyper/semantics/types/function.py index 6910d1a2e0..568e843291 100644 --- a/vyper/semantics/types/function.py +++ b/vyper/semantics/types/function.py @@ -188,10 +188,8 @@ def from_FunctionDef( ) else: - # FunctionDef with decorators (normal functions) for decorator in node.decorator_list: - if isinstance(decorator, vy_ast.Call): if "nonreentrant" in kwargs: raise StructureException( diff --git a/vyper/semantics/types/primitives.py b/vyper/semantics/types/primitives.py index 72433fcb91..5b1ab5ab8e 100644 --- a/vyper/semantics/types/primitives.py +++ b/vyper/semantics/types/primitives.py @@ -154,11 +154,11 @@ def validate_numeric_op( # TODO double check: this code seems duplicated with constant eval # constant folding ensures one of `(left, right)` is never a literal if isinstance(left, vy_ast.Int): - if left.value >= 2 ** value_bits: + if left.value >= 2**value_bits: raise OverflowException( "Base is too large, calculation will always overflow", left ) - elif left.value < -(2 ** value_bits): + elif left.value < -(2**value_bits): raise OverflowException( "Base is too small, calculation will always underflow", left ) @@ -284,7 +284,7 @@ def decimals(self) -> int: @cached_property def divisor(self) -> int: - return 10 ** self.decimals + return 10**self.decimals @cached_property def epsilon(self) -> Decimal: diff --git a/vyper/semantics/types/subscriptable.py b/vyper/semantics/types/subscriptable.py index d6635d93cb..fb4505fb20 100644 --- a/vyper/semantics/types/subscriptable.py +++ b/vyper/semantics/types/subscriptable.py @@ -100,8 +100,7 @@ class _SequenceT(_SubscriptableT): _is_array_type: bool = True def __init__(self, value_type: VyperType, length: int): - - if not 0 < length < 2 ** 256: + if not 0 < length < 2**256: raise InvalidType("Array length is invalid") super().__init__(UINT256_T, value_type) diff --git a/vyper/semantics/types/user.py b/vyper/semantics/types/user.py index ac0eae2ef7..dda4dfc32f 100644 --- a/vyper/semantics/types/user.py +++ b/vyper/semantics/types/user.py @@ -261,7 +261,6 @@ def to_toplevel_abi_dict(self) -> List[Dict]: class InterfaceT(_UserType): - _type_members = {"address": AddressT()} _is_prim_word = True _as_array = True diff --git a/vyper/utils.py b/vyper/utils.py index 608a014f4e..2df78f1c2d 100644 --- a/vyper/utils.py +++ b/vyper/utils.py @@ -45,7 +45,7 @@ def fourbytes_to_int(inp): # Converts an integer to four bytes def int_to_fourbytes(n: int) -> bytes: - assert n < 2 ** 32 + assert n < 2**32 return n.to_bytes(4, byteorder="big") @@ -60,7 +60,7 @@ def signed_to_unsigned(int_, bits, strict=False): lo, hi = int_bounds(signed=True, bits=bits) assert lo <= int_ <= hi if int_ < 0: - return int_ + 2 ** bits + return int_ + 2**bits return int_ @@ -75,7 +75,7 @@ def unsigned_to_signed(int_, bits, strict=False): lo, hi = int_bounds(signed=False, bits=bits) assert lo <= int_ <= hi if int_ > (2 ** (bits - 1)) - 1: - return int_ - (2 ** bits) + return int_ - (2**bits) return int_ @@ -188,7 +188,7 @@ def calc_mem_gas(memsize): # A decimal value can store multiples of 1/DECIMAL_DIVISOR MAX_DECIMAL_PLACES = 10 -DECIMAL_DIVISOR = 10 ** MAX_DECIMAL_PLACES +DECIMAL_DIVISOR = 10**MAX_DECIMAL_PLACES DECIMAL_EPSILON = decimal.Decimal(1) / DECIMAL_DIVISOR @@ -200,13 +200,13 @@ def int_bounds(signed, bits): """ if signed: return -(2 ** (bits - 1)), (2 ** (bits - 1)) - 1 - return 0, (2 ** bits) - 1 + return 0, (2**bits) - 1 # e.g. -1 -> -(2**256 - 1) def evm_twos_complement(x: int) -> int: # return ((o + 2 ** 255) % 2 ** 256) - 2 ** 255 - return ((2 ** 256 - 1) ^ x) + 1 + return ((2**256 - 1) ^ x) + 1 # EVM div semantics as a python function @@ -231,7 +231,7 @@ def evm_mod(x, y): # (which can generated, for ex. in the unevaluated branch of the Shift builtin) def evm_pow(x, y): assert x >= 0 and y >= 0 - return pow(x, y, 2 ** 256) + return pow(x, y, 2**256) # memory used for system purposes, not for variables @@ -243,18 +243,18 @@ class MemoryPositions: # Sizes of different data types. Used to clamp types. class SizeLimits: - MAX_INT128 = 2 ** 127 - 1 - MIN_INT128 = -(2 ** 127) - MAX_INT256 = 2 ** 255 - 1 - MIN_INT256 = -(2 ** 255) - MAXDECIMAL = 2 ** 167 - 1 # maxdecimal as EVM value - MINDECIMAL = -(2 ** 167) # mindecimal as EVM value + MAX_INT128 = 2**127 - 1 + MIN_INT128 = -(2**127) + MAX_INT256 = 2**255 - 1 + MIN_INT256 = -(2**255) + MAXDECIMAL = 2**167 - 1 # maxdecimal as EVM value + MINDECIMAL = -(2**167) # mindecimal as EVM value # min decimal allowed as Python value - MIN_AST_DECIMAL = -decimal.Decimal(2 ** 167) / DECIMAL_DIVISOR + MIN_AST_DECIMAL = -decimal.Decimal(2**167) / DECIMAL_DIVISOR # max decimal allowed as Python value - MAX_AST_DECIMAL = decimal.Decimal(2 ** 167 - 1) / DECIMAL_DIVISOR - MAX_UINT8 = 2 ** 8 - 1 - MAX_UINT256 = 2 ** 256 - 1 + MAX_AST_DECIMAL = decimal.Decimal(2**167 - 1) / DECIMAL_DIVISOR + MAX_UINT8 = 2**8 - 1 + MAX_UINT256 = 2**256 - 1 # Otherwise reserved words that are whitelisted for function declarations From 6edd34768b28bd62f441ccd1b2a57ea62ba87b57 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Wed, 29 Mar 2023 11:46:35 +0800 Subject: [PATCH 05/14] bump docs dependencies --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ae7bcf4d07..c3bb46ef72 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ "isort==5.9.3", "mypy==0.910", ], - "docs": ["recommonmark", "sphinx>=3.0,<4.0", "sphinx_rtd_theme>=0.5,<0.6"], + "docs": ["recommonmark", "sphinx>=6.0,<7.0", "sphinx_rtd_theme>=1.2,<1.3"], "dev": ["ipython", "pre-commit", "pyinstaller", "twine"], } From c0e44d78c923508da0cda4229f98d76d27534a43 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Wed, 29 Mar 2023 11:55:53 +0800 Subject: [PATCH 06/14] fix black lint for tests --- .../ast/nodes/test_evaluate_binop_decimal.py | 4 +- tests/ast/nodes/test_evaluate_binop_int.py | 5 +- tests/ast/nodes/test_evaluate_boolop.py | 2 - tests/base_conftest.py | 4 +- tests/builtins/folding/test_abs.py | 6 +- tests/builtins/folding/test_addmod_mulmod.py | 2 +- tests/builtins/folding/test_bitwise.py | 5 +- tests/builtins/folding/test_floor_ceil.py | 2 +- .../folding/test_fold_as_wei_value.py | 2 +- tests/builtins/folding/test_keccak_sha.py | 1 - tests/builtins/folding/test_min_max.py | 4 +- tests/builtins/folding/test_powmod.py | 2 +- tests/compiler/ir/test_compile_ir.py | 4 +- tests/compiler/ir/test_optimize_ir.py | 110 +++++++++--------- tests/conftest.py | 1 - .../auctions/test_simple_open_auction.py | 8 +- tests/examples/company/test_company.py | 4 +- .../test_on_chain_market_maker.py | 6 +- .../test_safe_remote_purchase.py | 1 - tests/examples/tokens/test_erc20.py | 2 +- tests/examples/tokens/test_erc4626.py | 30 ++--- tests/examples/wallet/test_wallet.py | 8 +- .../semantics/analysis/test_array_index.py | 2 +- .../analysis/test_potential_types.py | 4 +- tests/fuzzing/test_exponents.py | 72 ++++++------ .../features/decorators/test_payable.py | 4 +- .../external_contracts/test_erc20_abi.py | 5 +- .../test_external_contract_calls.py | 7 +- tests/parser/features/test_assert.py | 2 +- .../features/test_assert_unreachable.py | 2 +- tests/parser/features/test_bytes_map_keys.py | 2 +- tests/parser/features/test_clampers.py | 64 +++++----- tests/parser/features/test_constructor.py | 6 +- tests/parser/features/test_immutable.py | 8 +- tests/parser/features/test_logging.py | 6 - tests/parser/functions/test_abi_decode.py | 4 +- tests/parser/functions/test_abi_encode.py | 16 +-- tests/parser/functions/test_bitwise.py | 6 +- tests/parser/functions/test_ceil.py | 4 +- tests/parser/functions/test_convert.py | 8 +- .../parser/functions/test_default_function.py | 6 +- .../functions/test_default_parameters.py | 4 +- tests/parser/functions/test_extract32.py | 2 +- tests/parser/functions/test_floor.py | 4 +- tests/parser/functions/test_interfaces.py | 7 +- tests/parser/functions/test_minmax.py | 18 +-- tests/parser/functions/test_mkstr.py | 4 +- tests/parser/functions/test_raw_call.py | 3 - tests/parser/functions/test_slice.py | 15 +-- tests/parser/functions/test_tx.py | 2 +- tests/parser/functions/test_unary.py | 12 +- tests/parser/functions/test_unsafe_math.py | 6 +- tests/parser/syntax/test_abi_encode.py | 1 - tests/parser/syntax/test_as_uint256.py | 1 - tests/parser/syntax/test_block.py | 1 - tests/parser/syntax/test_blockscope.py | 2 - tests/parser/syntax/test_bool.py | 1 - tests/parser/syntax/test_chainid.py | 1 - tests/parser/syntax/test_code_size.py | 1 - tests/parser/syntax/test_concat.py | 1 - tests/parser/syntax/test_extract32.py | 1 - tests/parser/syntax/test_functions_call.py | 1 - tests/parser/syntax/test_len.py | 1 - tests/parser/syntax/test_list.py | 1 - tests/parser/syntax/test_logging.py | 1 - tests/parser/syntax/test_minmax_value.py | 1 - tests/parser/syntax/test_msg_data.py | 4 +- tests/parser/syntax/test_raw_call.py | 1 - tests/parser/syntax/test_return_tuple.py | 1 - tests/parser/syntax/test_selfdestruct.py | 1 - tests/parser/syntax/test_slice.py | 1 - tests/parser/types/numbers/test_constants.py | 20 ++-- tests/parser/types/numbers/test_isqrt.py | 3 +- .../parser/types/numbers/test_signed_ints.py | 8 +- .../types/numbers/test_unsigned_ints.py | 12 +- tests/parser/types/test_bytes.py | 2 +- tests/parser/types/test_bytes_zero_padding.py | 2 +- tests/parser/types/test_dynamic_array.py | 3 +- tests/parser/types/test_enum.py | 8 +- tests/parser/types/test_lists.py | 20 ++-- tests/parser/types/test_node_types.py | 1 - tests/parser/types/test_string.py | 3 +- tests/parser/types/value/test_as_wei_value.py | 16 +-- 83 files changed, 295 insertions(+), 344 deletions(-) diff --git a/tests/ast/nodes/test_evaluate_binop_decimal.py b/tests/ast/nodes/test_evaluate_binop_decimal.py index cfe23c87f6..c6c69626b8 100644 --- a/tests/ast/nodes/test_evaluate_binop_decimal.py +++ b/tests/ast/nodes/test_evaluate_binop_decimal.py @@ -8,7 +8,7 @@ from vyper.exceptions import OverflowException, TypeMismatch, ZeroDivisionException st_decimals = st.decimals( - min_value=-(2 ** 32), max_value=2 ** 32, allow_nan=False, allow_infinity=False, places=10 + min_value=-(2**32), max_value=2**32, allow_nan=False, allow_infinity=False, places=10 ) @@ -75,7 +75,7 @@ def foo({input_value}) -> decimal: try: vy_ast.folding.replace_literal_ops(vyper_ast) expected = vyper_ast.body[0].value.value - is_valid = -(2 ** 127) <= expected < 2 ** 127 + is_valid = -(2**127) <= expected < 2**127 except (OverflowException, ZeroDivisionException): # for overflow or division/modulus by 0, expect the contract call to revert is_valid = False diff --git a/tests/ast/nodes/test_evaluate_binop_int.py b/tests/ast/nodes/test_evaluate_binop_int.py index a3f8c491f6..d632a95461 100644 --- a/tests/ast/nodes/test_evaluate_binop_int.py +++ b/tests/ast/nodes/test_evaluate_binop_int.py @@ -5,7 +5,7 @@ from vyper import ast as vy_ast from vyper.exceptions import ZeroDivisionException -st_int32 = st.integers(min_value=-(2 ** 32), max_value=2 ** 32) +st_int32 = st.integers(min_value=-(2**32), max_value=2**32) @pytest.mark.fuzzing @@ -38,7 +38,7 @@ def foo(a: int128, b: int128) -> int128: assert_tx_failed(lambda: contract.foo(left, right)) -st_uint64 = st.integers(min_value=0, max_value=2 ** 64) +st_uint64 = st.integers(min_value=0, max_value=2**64) @pytest.mark.fuzzing @@ -95,7 +95,6 @@ def foo(a: uint256, b: uint256) -> uint256: ops=st.lists(st.sampled_from("+-*/%"), min_size=11, max_size=11), ) def test_binop_nested(get_contract, assert_tx_failed, values, ops): - variables = "abcdefghij" input_value = ",".join(f"{i}: int128" for i in variables[: len(values)]) return_value = " ".join(f"{a} {b}" for a, b in zip(variables[: len(values)], ops)) diff --git a/tests/ast/nodes/test_evaluate_boolop.py b/tests/ast/nodes/test_evaluate_boolop.py index c28a706954..6bd9ecc6cb 100644 --- a/tests/ast/nodes/test_evaluate_boolop.py +++ b/tests/ast/nodes/test_evaluate_boolop.py @@ -12,7 +12,6 @@ @given(values=st.lists(st.booleans(), min_size=2, max_size=10)) @pytest.mark.parametrize("comparator", ["and", "or"]) def test_boolop_simple(get_contract, values, comparator): - input_value = ",".join(f"{i}: bool" for i in variables[: len(values)]) return_value = f" {comparator} ".join(variables[: len(values)]) @@ -39,7 +38,6 @@ def foo({input_value}) -> bool: comparators=st.lists(st.sampled_from(["and", "or"]), min_size=11, max_size=11), ) def test_boolop_nested(get_contract, values, comparators): - input_value = ",".join(f"{i}: bool" for i in variables[: len(values)]) return_value = " ".join(f"{a} {b}" for a, b in zip(variables[: len(values)], comparators)) return_value = return_value.rsplit(maxsplit=1)[0] diff --git a/tests/base_conftest.py b/tests/base_conftest.py index aa6ee55923..3263bad2b0 100644 --- a/tests/base_conftest.py +++ b/tests/base_conftest.py @@ -85,7 +85,7 @@ def _none_addr(datatype, data): def tester(): # set absurdly high gas limit so that london basefee never adjusts # (note: 2**63 - 1 is max that evm allows) - custom_genesis = PyEVMBackend._generate_genesis_params(overrides={"gas_limit": 10 ** 10}) + custom_genesis = PyEVMBackend._generate_genesis_params(overrides={"gas_limit": 10**10}) custom_genesis["base_fee_per_gas"] = 0 backend = PyEVMBackend(genesis_parameters=custom_genesis) return EthereumTester(backend=backend) @@ -114,7 +114,7 @@ def _get_contract(w3, source_code, no_optimize, *args, **kwargs): parse_vyper_source(source_code) # Test grammar. abi = out["abi"] bytecode = out["bytecode"] - value = kwargs.pop("value_in_eth", 0) * 10 ** 18 # Handle deploying with an eth value. + value = kwargs.pop("value_in_eth", 0) * 10**18 # Handle deploying with an eth value. c = w3.eth.contract(abi=abi, bytecode=bytecode) deploy_transaction = c.constructor(*args) tx_info = {"from": w3.eth.accounts[0], "value": value, "gasPrice": 0} diff --git a/tests/builtins/folding/test_abs.py b/tests/builtins/folding/test_abs.py index 058177b71c..58f861ed0c 100644 --- a/tests/builtins/folding/test_abs.py +++ b/tests/builtins/folding/test_abs.py @@ -9,7 +9,7 @@ @pytest.mark.fuzzing @settings(max_examples=50, deadline=1000) -@given(a=st.integers(min_value=-(2 ** 255) + 1, max_value=2 ** 255 - 1)) +@given(a=st.integers(min_value=-(2**255) + 1, max_value=2**255 - 1)) @example(a=0) def test_abs(get_contract, a): source = """ @@ -28,7 +28,7 @@ def foo(a: int256) -> int256: @pytest.mark.fuzzing @settings(max_examples=50, deadline=1000) -@given(a=st.integers(min_value=2 ** 255, max_value=2 ** 256 - 1)) +@given(a=st.integers(min_value=2**255, max_value=2**256 - 1)) def test_abs_upper_bound_folding(get_contract, a): source = f""" @external @@ -47,7 +47,7 @@ def foo(a: int256) -> int256: """ contract = get_contract(source) - assert_tx_failed(lambda: contract.foo(-(2 ** 255))) + assert_tx_failed(lambda: contract.foo(-(2**255))) def test_abs_lower_bound_folded(get_contract, assert_tx_failed): diff --git a/tests/builtins/folding/test_addmod_mulmod.py b/tests/builtins/folding/test_addmod_mulmod.py index c697cc6b2a..0514dea18a 100644 --- a/tests/builtins/folding/test_addmod_mulmod.py +++ b/tests/builtins/folding/test_addmod_mulmod.py @@ -5,7 +5,7 @@ from vyper import ast as vy_ast from vyper.builtins import functions as vy_fn -st_uint256 = st.integers(min_value=0, max_value=2 ** 256 - 1) +st_uint256 = st.integers(min_value=0, max_value=2**256 - 1) @pytest.mark.fuzzing diff --git a/tests/builtins/folding/test_bitwise.py b/tests/builtins/folding/test_bitwise.py index 7d3f85592f..9be0b6817d 100644 --- a/tests/builtins/folding/test_bitwise.py +++ b/tests/builtins/folding/test_bitwise.py @@ -5,7 +5,7 @@ from vyper import ast as vy_ast from vyper.builtins import functions as vy_fn -st_uint256 = st.integers(min_value=0, max_value=2 ** 256 - 1) +st_uint256 = st.integers(min_value=0, max_value=2**256 - 1) @pytest.mark.fuzzing @@ -13,7 +13,6 @@ @given(a=st_uint256, b=st_uint256) @pytest.mark.parametrize("op", ["&", "|", "^"]) def test_bitwise_and_or(get_contract, a, b, op): - source = f""" @external def foo(a: uint256, b: uint256) -> uint256: @@ -32,7 +31,6 @@ def foo(a: uint256, b: uint256) -> uint256: @settings(max_examples=50, deadline=1000) @given(value=st_uint256) def test_bitwise_not(get_contract, value): - source = """ @external def foo(a: uint256) -> uint256: @@ -51,7 +49,6 @@ def foo(a: uint256) -> uint256: @settings(max_examples=50, deadline=1000) @given(value=st_uint256, steps=st.integers(min_value=-256, max_value=256)) def test_shift(get_contract, value, steps): - source = """ @external def foo(a: uint256, b: int128) -> uint256: diff --git a/tests/builtins/folding/test_floor_ceil.py b/tests/builtins/folding/test_floor_ceil.py index 1e834e4d6e..763f8fec63 100644 --- a/tests/builtins/folding/test_floor_ceil.py +++ b/tests/builtins/folding/test_floor_ceil.py @@ -8,7 +8,7 @@ from vyper.builtins import functions as vy_fn st_decimals = st.decimals( - min_value=-(2 ** 32), max_value=2 ** 32, allow_nan=False, allow_infinity=False, places=10 + min_value=-(2**32), max_value=2**32, allow_nan=False, allow_infinity=False, places=10 ) diff --git a/tests/builtins/folding/test_fold_as_wei_value.py b/tests/builtins/folding/test_fold_as_wei_value.py index 61818e291a..11d23bd3bf 100644 --- a/tests/builtins/folding/test_fold_as_wei_value.py +++ b/tests/builtins/folding/test_fold_as_wei_value.py @@ -39,7 +39,7 @@ def foo(a: decimal) -> uint256: @pytest.mark.fuzzing @settings(max_examples=10, deadline=1000) -@given(value=st.integers(min_value=0, max_value=2 ** 128)) +@given(value=st.integers(min_value=0, max_value=2**128)) @pytest.mark.parametrize("denom", denoms) def test_integer(get_contract, value, denom): source = f""" diff --git a/tests/builtins/folding/test_keccak_sha.py b/tests/builtins/folding/test_keccak_sha.py index e6cf1d1581..8e283566de 100644 --- a/tests/builtins/folding/test_keccak_sha.py +++ b/tests/builtins/folding/test_keccak_sha.py @@ -13,7 +13,6 @@ @settings(max_examples=50, deadline=1000) @pytest.mark.parametrize("fn_name", ["keccak256", "sha256"]) def test_string(get_contract, value, fn_name): - source = f""" @external def foo(a: String[100]) -> bytes32: diff --git a/tests/builtins/folding/test_min_max.py b/tests/builtins/folding/test_min_max.py index 13f5dd0537..e2d33237ca 100644 --- a/tests/builtins/folding/test_min_max.py +++ b/tests/builtins/folding/test_min_max.py @@ -13,8 +13,8 @@ allow_infinity=False, places=10, ) -st_int128 = st.integers(min_value=-(2 ** 127), max_value=2 ** 127 - 1) -st_uint256 = st.integers(min_value=0, max_value=2 ** 256 - 1) +st_int128 = st.integers(min_value=-(2**127), max_value=2**127 - 1) +st_uint256 = st.integers(min_value=0, max_value=2**256 - 1) @pytest.mark.fuzzing diff --git a/tests/builtins/folding/test_powmod.py b/tests/builtins/folding/test_powmod.py index 3ea96bfbed..fdc0e300ab 100644 --- a/tests/builtins/folding/test_powmod.py +++ b/tests/builtins/folding/test_powmod.py @@ -5,7 +5,7 @@ from vyper import ast as vy_ast from vyper.builtins import functions as vy_fn -st_uint256 = st.integers(min_value=0, max_value=2 ** 256) +st_uint256 = st.integers(min_value=0, max_value=2**256) @pytest.mark.fuzzing diff --git a/tests/compiler/ir/test_compile_ir.py b/tests/compiler/ir/test_compile_ir.py index 03c4f33095..91007da33a 100644 --- a/tests/compiler/ir/test_compile_ir.py +++ b/tests/compiler/ir/test_compile_ir.py @@ -5,8 +5,8 @@ from vyper.ir.s_expressions import parse_s_exp fail_list = [ - [-(2 ** 255) - 3], - [2 ** 256 + 3], + [-(2**255) - 3], + [2**256 + 3], ["set", "_poz"], [["set", "var_1", 0, 0]], ["with", "var_1", 0, ["set", 1, 1]], diff --git a/tests/compiler/ir/test_optimize_ir.py b/tests/compiler/ir/test_optimize_ir.py index 6c4cf50fc1..bac0e18d65 100644 --- a/tests/compiler/ir/test_optimize_ir.py +++ b/tests/compiler/ir/test_optimize_ir.py @@ -34,23 +34,23 @@ # conditions (["ge", "x", 0], [1]), # x >= 0 == True (["ge", ["sload", 0], 0], None), # no-op - (["gt", "x", 2 ** 256 - 1], [0]), # x >= MAX_UINT256 == False + (["gt", "x", 2**256 - 1], [0]), # x >= MAX_UINT256 == False # (x > 0) => x == 0 (["iszero", ["gt", "x", 0]], ["iszero", ["iszero", ["iszero", "x"]]]), # !(x < MAX_UINT256) => x == MAX_UINT256 - (["iszero", ["lt", "x", 2 ** 256 - 1]], ["iszero", ["iszero", ["iszero", ["not", "x"]]]]), + (["iszero", ["lt", "x", 2**256 - 1]], ["iszero", ["iszero", ["iszero", ["not", "x"]]]]), # !(x < MAX_INT256) => x == MAX_INT256 ( - ["iszero", ["slt", "x", 2 ** 255 - 1]], - ["iszero", ["iszero", ["iszero", ["xor", "x", 2 ** 255 - 1]]]], + ["iszero", ["slt", "x", 2**255 - 1]], + ["iszero", ["iszero", ["iszero", ["xor", "x", 2**255 - 1]]]], ), # !(x > MIN_INT256) => x == MIN_INT256 ( - ["iszero", ["sgt", "x", -(2 ** 255)]], - ["iszero", ["iszero", ["iszero", ["xor", "x", -(2 ** 255)]]]], + ["iszero", ["sgt", "x", -(2**255)]], + ["iszero", ["iszero", ["iszero", ["xor", "x", -(2**255)]]]], ), - (["sgt", "x", 2 ** 255 - 1], [0]), # signed x > MAX_INT256 == False - (["sge", "x", 2 ** 255 - 1], ["eq", "x", 2 ** 255 - 1]), + (["sgt", "x", 2**255 - 1], [0]), # signed x > MAX_INT256 == False + (["sge", "x", 2**255 - 1], ["eq", "x", 2**255 - 1]), (["eq", -1, "x"], ["iszero", ["not", "x"]]), (["iszero", ["eq", -1, "x"]], ["iszero", ["iszero", ["not", "x"]]]), (["le", "x", 0], ["iszero", "x"]), @@ -58,10 +58,10 @@ (["le", 0, ["sload", 0]], None), # no-op (["ge", "x", 0], [1]), # boundary conditions - (["slt", "x", -(2 ** 255)], [0]), - (["sle", "x", -(2 ** 255)], ["eq", "x", -(2 ** 255)]), - (["lt", "x", 2 ** 256 - 1], None), - (["le", "x", 2 ** 256 - 1], [1]), + (["slt", "x", -(2**255)], [0]), + (["sle", "x", -(2**255)], ["eq", "x", -(2**255)]), + (["lt", "x", 2**256 - 1], None), + (["le", "x", 2**256 - 1], [1]), (["gt", "x", 0], ["iszero", ["iszero", "x"]]), # x < 0 => false (["lt", "x", 0], [0]), @@ -73,18 +73,18 @@ (["slt", "x", 1], None), (["gt", "x", 1], None), (["sgt", "x", 1], None), - (["gt", "x", 2 ** 256 - 2], ["iszero", ["not", "x"]]), - (["lt", "x", 2 ** 256 - 2], None), - (["slt", "x", 2 ** 256 - 2], None), - (["sgt", "x", 2 ** 256 - 2], None), - (["slt", "x", -(2 ** 255) + 1], ["eq", "x", -(2 ** 255)]), - (["sgt", "x", -(2 ** 255) + 1], None), - (["lt", "x", -(2 ** 255) + 1], None), - (["gt", "x", -(2 ** 255) + 1], None), - (["sgt", "x", 2 ** 255 - 2], ["eq", "x", 2 ** 255 - 1]), - (["slt", "x", 2 ** 255 - 2], None), - (["gt", "x", 2 ** 255 - 2], None), - (["lt", "x", 2 ** 255 - 2], None), + (["gt", "x", 2**256 - 2], ["iszero", ["not", "x"]]), + (["lt", "x", 2**256 - 2], None), + (["slt", "x", 2**256 - 2], None), + (["sgt", "x", 2**256 - 2], None), + (["slt", "x", -(2**255) + 1], ["eq", "x", -(2**255)]), + (["sgt", "x", -(2**255) + 1], None), + (["lt", "x", -(2**255) + 1], None), + (["gt", "x", -(2**255) + 1], None), + (["sgt", "x", 2**255 - 2], ["eq", "x", 2**255 - 1]), + (["slt", "x", 2**255 - 2], None), + (["gt", "x", 2**255 - 2], None), + (["lt", "x", 2**255 - 2], None), # 5 > x; x < 5; x <= 4 (["iszero", ["gt", 5, "x"]], ["iszero", ["le", "x", 4]]), (["iszero", ["ge", 5, "x"]], None), @@ -109,18 +109,18 @@ # 5 <= x; x >= 5; x > 4 (["sle", 5, "x"], ["sgt", "x", 4]), # tricky constant folds - (["sgt", 2 ** 256 - 1, 0], [0]), # -1 > 0 - (["gt", 2 ** 256 - 1, 0], [1]), # -1 > 0 - (["gt", 2 ** 255, 0], [1]), # 0x80 > 0 - (["sgt", 2 ** 255, 0], [0]), # 0x80 > 0 - (["sgt", 2 ** 255, 2 ** 255 - 1], [0]), # 0x80 > 0x81 - (["gt", -(2 ** 255), 2 ** 255 - 1], [1]), # 0x80 > 0x81 - (["slt", 2 ** 255, 2 ** 255 - 1], [1]), # 0x80 < 0x7f - (["lt", -(2 ** 255), 2 ** 255 - 1], [0]), # 0x80 < 0x7f - (["sle", -1, 2 ** 256 - 1], [1]), # -1 <= -1 - (["sge", -(2 ** 255), 2 ** 255], [1]), # 0x80 >= 0x80 - (["sgt", -(2 ** 255), 2 ** 255], [0]), # 0x80 > 0x80 - (["slt", 2 ** 255, -(2 ** 255)], [0]), # 0x80 < 0x80 + (["sgt", 2**256 - 1, 0], [0]), # -1 > 0 + (["gt", 2**256 - 1, 0], [1]), # -1 > 0 + (["gt", 2**255, 0], [1]), # 0x80 > 0 + (["sgt", 2**255, 0], [0]), # 0x80 > 0 + (["sgt", 2**255, 2**255 - 1], [0]), # 0x80 > 0x81 + (["gt", -(2**255), 2**255 - 1], [1]), # 0x80 > 0x81 + (["slt", 2**255, 2**255 - 1], [1]), # 0x80 < 0x7f + (["lt", -(2**255), 2**255 - 1], [0]), # 0x80 < 0x7f + (["sle", -1, 2**256 - 1], [1]), # -1 <= -1 + (["sge", -(2**255), 2**255], [1]), # 0x80 >= 0x80 + (["sgt", -(2**255), 2**255], [0]), # 0x80 > 0x80 + (["slt", 2**255, -(2**255)], [0]), # 0x80 < 0x80 # arithmetic (["ceil32", "x"], None), (["ceil32", 0], [0]), @@ -159,17 +159,17 @@ (["mod", "x", 128], ["and", "x", 127]), (["sdiv", "x", 64], None), (["smod", "x", 64], None), - (["exp", 3, 5], [3 ** 5]), - (["exp", 3, 256], [(3 ** 256) % (2 ** 256)]), + (["exp", 3, 5], [3**5]), + (["exp", 3, 256], [(3**256) % (2**256)]), (["exp", 2, 257], [0]), (["exp", "x", 0], [1]), (["exp", "x", 1], ["x"]), (["exp", 1, "x"], [1]), (["exp", 0, "x"], ["iszero", "x"]), # bitwise ops - (["xor", "x", 2 ** 256 - 1], ["not", "x"]), - (["and", "x", 2 ** 256 - 1], ["x"]), - (["or", "x", 2 ** 256 - 1], [2 ** 256 - 1]), + (["xor", "x", 2**256 - 1], ["not", "x"]), + (["and", "x", 2**256 - 1], ["x"]), + (["or", "x", 2**256 - 1], [2**256 - 1]), (["shr", 0, "x"], ["x"]), (["sar", 0, "x"], ["x"]), (["shl", 0, "x"], ["x"]), @@ -195,12 +195,12 @@ (["iszero", ["or", 1, ["sload", 0]]], None), # nested optimizations (["eq", 0, ["sub", 1, 1]], [1]), - (["eq", 0, ["add", 2 ** 255, 2 ** 255]], [1]), # test compile-time wrapping - (["eq", 0, ["add", 2 ** 255, -(2 ** 255)]], [1]), # test compile-time wrapping + (["eq", 0, ["add", 2**255, 2**255]], [1]), # test compile-time wrapping + (["eq", 0, ["add", 2**255, -(2**255)]], [1]), # test compile-time wrapping (["eq", -1, ["add", 0, -1]], [1]), # test compile-time wrapping - (["eq", -1, ["add", 2 ** 255, 2 ** 255 - 1]], [1]), # test compile-time wrapping - (["eq", -1, ["add", -(2 ** 255), 2 ** 255 - 1]], [1]), # test compile-time wrapping - (["eq", -2, ["add", 2 ** 256 - 1, 2 ** 256 - 1]], [1]), # test compile-time wrapping + (["eq", -1, ["add", 2**255, 2**255 - 1]], [1]), # test compile-time wrapping + (["eq", -1, ["add", -(2**255), 2**255 - 1]], [1]), # test compile-time wrapping + (["eq", -2, ["add", 2**256 - 1, 2**256 - 1]], [1]), # test compile-time wrapping (["eq", "x", "x"], [1]), (["eq", "callvalue", "callvalue"], None), (["ne", "x", "x"], [0]), @@ -229,23 +229,23 @@ def test_ir_optimizer(ir): ["assert", ["lt", 1, 1]], ["assert", ["lt", "x", 0]], # +x < 0 ["assert", ["le", 1, 0]], - ["assert", ["le", 2 ** 256 - 1, 0]], + ["assert", ["le", 2**256 - 1, 0]], ["assert", ["gt", 1, 2]], ["assert", ["gt", 1, 1]], - ["assert", ["gt", 0, 2 ** 256 - 1]], - ["assert", ["gt", "x", 2 ** 256 - 1]], + ["assert", ["gt", 0, 2**256 - 1]], + ["assert", ["gt", "x", 2**256 - 1]], ["assert", ["ge", 1, 2]], ["assert", ["ge", 1, 2]], ["assert", ["slt", 2, 1]], ["assert", ["slt", 1, 1]], - ["assert", ["slt", 0, 2 ** 256 - 1]], # 0 < -1 - ["assert", ["slt", -(2 ** 255), 2 ** 255]], # 0x80 < 0x80 - ["assert", ["sle", 0, 2 ** 255]], # 0 < 0x80 + ["assert", ["slt", 0, 2**256 - 1]], # 0 < -1 + ["assert", ["slt", -(2**255), 2**255]], # 0x80 < 0x80 + ["assert", ["sle", 0, 2**255]], # 0 < 0x80 ["assert", ["sgt", 1, 2]], ["assert", ["sgt", 1, 1]], - ["assert", ["sgt", 2 ** 256 - 1, 0]], # -1 > 0 - ["assert", ["sgt", 2 ** 255, -(2 ** 255)]], # 0x80 > 0x80 - ["assert", ["sge", 2 ** 255, 0]], # 0x80 > 0 + ["assert", ["sgt", 2**256 - 1, 0]], # -1 > 0 + ["assert", ["sgt", 2**255, -(2**255)]], # 0x80 > 0x80 + ["assert", ["sge", 2**255, 0]], # 0x80 > 0 ] diff --git a/tests/conftest.py b/tests/conftest.py index 881058aa36..a8d4005059 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -148,7 +148,6 @@ def set_decorator_to_contract_function(w3, tester, contract, source_code, func): @pytest.fixture def get_contract_with_gas_estimation(tester, w3, no_optimize): def get_contract_with_gas_estimation(source_code, *args, **kwargs): - contract = _get_contract(w3, source_code, no_optimize, *args, **kwargs) for abi in contract._classic_contract.functions.abi: if abi["type"] == "function": diff --git a/tests/examples/auctions/test_simple_open_auction.py b/tests/examples/auctions/test_simple_open_auction.py index 21aeb4d4a7..cf0bb8cc20 100644 --- a/tests/examples/auctions/test_simple_open_auction.py +++ b/tests/examples/auctions/test_simple_open_auction.py @@ -56,9 +56,9 @@ def test_bid(w3, tester, auction_contract, assert_tx_failed): # Check that highest bidder and highest bid have changed accordingly assert auction_contract.highestBidder() == k5 assert auction_contract.highestBid() == 5 - auction_contract.bid(transact={"value": 1 * 10 ** 10, "from": k1}) + auction_contract.bid(transact={"value": 1 * 10**10, "from": k1}) pending_return_before_outbid = auction_contract.pendingReturns(k1) - auction_contract.bid(transact={"value": 2 * 10 ** 10, "from": k2}) + auction_contract.bid(transact={"value": 2 * 10**10, "from": k2}) pending_return_after_outbid = auction_contract.pendingReturns(k1) # Account has a greater pending return balance after being outbid assert pending_return_after_outbid > pending_return_before_outbid @@ -76,7 +76,7 @@ def test_end_auction(w3, tester, auction_contract, assert_tx_failed): k1, k2, k3, k4, k5 = w3.eth.accounts[:5] # Fails if auction end time has not been reached assert_tx_failed(lambda: auction_contract.endAuction()) - auction_contract.bid(transact={"value": 1 * 10 ** 10, "from": k2}) + auction_contract.bid(transact={"value": 1 * 10**10, "from": k2}) # Move block timestamp foreward to reach auction end time # tester.time_travel(tester.get_block_by_number('latest')['timestamp'] + EXPIRY) w3.testing.mine(EXPIRY) @@ -84,7 +84,7 @@ def test_end_auction(w3, tester, auction_contract, assert_tx_failed): auction_contract.endAuction(transact={"from": k2}) balance_after_end = w3.eth.get_balance(k1) # Beneficiary receives the highest bid - assert balance_after_end == balance_before_end + 1 * 10 ** 10 + assert balance_after_end == balance_before_end + 1 * 10**10 # Bidder cannot bid after auction end time has been reached assert_tx_failed(lambda: auction_contract.bid(transact={"value": 10, "from": k1})) # Auction cannot be ended twice diff --git a/tests/examples/company/test_company.py b/tests/examples/company/test_company.py index d281652e5a..71141b8bb5 100644 --- a/tests/examples/company/test_company.py +++ b/tests/examples/company/test_company.py @@ -5,7 +5,7 @@ def c(w3, get_contract): with open("examples/stock/company.vy") as f: contract_code = f.read() - contract = get_contract(contract_code, *[w3.eth.accounts[0], 1000, 10 ** 6]) + contract = get_contract(contract_code, *[w3.eth.accounts[0], 1000, 10**6]) return contract @@ -107,7 +107,7 @@ def test_logs(w3, c, get_logs): assert logs[0].args.value == 4 # Pay is logged - amount = 10 ** 4 + amount = 10**4 logs = get_logs(c.payBill(a3, amount, transact={}), c, "Pay") assert len(logs) == 1 assert logs[0].args.amount == amount diff --git a/tests/examples/market_maker/test_on_chain_market_maker.py b/tests/examples/market_maker/test_on_chain_market_maker.py index fdbf59370f..546ecc15a8 100644 --- a/tests/examples/market_maker/test_on_chain_market_maker.py +++ b/tests/examples/market_maker/test_on_chain_market_maker.py @@ -11,8 +11,8 @@ def market_maker(get_contract): TOKEN_NAME = "Vypercoin" TOKEN_SYMBOL = "FANG" TOKEN_DECIMALS = 18 -TOKEN_INITIAL_SUPPLY = 21 * 10 ** 6 -TOKEN_TOTAL_SUPPLY = TOKEN_INITIAL_SUPPLY * (10 ** TOKEN_DECIMALS) +TOKEN_INITIAL_SUPPLY = 21 * 10**6 +TOKEN_TOTAL_SUPPLY = TOKEN_INITIAL_SUPPLY * (10**TOKEN_DECIMALS) @pytest.fixture @@ -39,7 +39,7 @@ def test_initiate(w3, market_maker, erc20, assert_tx_failed): ) assert market_maker.totalEthQty() == w3.toWei(2, "ether") assert market_maker.totalTokenQty() == w3.toWei(1, "ether") - assert market_maker.invariant() == 2 * 10 ** 36 + assert market_maker.invariant() == 2 * 10**36 assert market_maker.owner() == a0 assert erc20.name() == TOKEN_NAME assert erc20.decimals() == TOKEN_DECIMALS diff --git a/tests/examples/safe_remote_purchase/test_safe_remote_purchase.py b/tests/examples/safe_remote_purchase/test_safe_remote_purchase.py index 50aa873397..5cd80a989a 100644 --- a/tests/examples/safe_remote_purchase/test_safe_remote_purchase.py +++ b/tests/examples/safe_remote_purchase/test_safe_remote_purchase.py @@ -100,7 +100,6 @@ def test_received(w3, get_contract, assert_tx_failed, get_balance, contract_code def test_received_reentrancy(w3, get_contract, assert_tx_failed, get_balance, contract_code): - buyer_contract_code = """ interface PurchaseContract: diff --git a/tests/examples/tokens/test_erc20.py b/tests/examples/tokens/test_erc20.py index c693959309..cba7769bae 100644 --- a/tests/examples/tokens/test_erc20.py +++ b/tests/examples/tokens/test_erc20.py @@ -5,7 +5,7 @@ from web3.exceptions import ValidationError ZERO_ADDRESS = "0x0000000000000000000000000000000000000000" -MAX_UINT256 = (2 ** 256) - 1 # Max uint256 value +MAX_UINT256 = (2**256) - 1 # Max uint256 value TOKEN_NAME = "Vypercoin" TOKEN_SYMBOL = "FANG" TOKEN_DECIMALS = 18 diff --git a/tests/examples/tokens/test_erc4626.py b/tests/examples/tokens/test_erc4626.py index a8e57e7eff..2469a7abd0 100644 --- a/tests/examples/tokens/test_erc4626.py +++ b/tests/examples/tokens/test_erc4626.py @@ -1,6 +1,6 @@ import pytest -AMOUNT = 100 * 10 ** 18 +AMOUNT = 100 * 10**18 TOKEN_NAME = "Vypercoin" TOKEN_SYMBOL = "FANG" TOKEN_DECIMALS = 18 @@ -28,18 +28,18 @@ def test_asset(vault, token): def test_max_methods(w3, vault): a = w3.eth.accounts[0] - assert vault.maxDeposit(a) == 2 ** 256 - 1 - assert vault.maxMint(a) == 2 ** 256 - 1 - assert vault.maxWithdraw(a) == 2 ** 256 - 1 - assert vault.maxRedeem(a) == 2 ** 256 - 1 + assert vault.maxDeposit(a) == 2**256 - 1 + assert vault.maxMint(a) == 2**256 - 1 + assert vault.maxWithdraw(a) == 2**256 - 1 + assert vault.maxRedeem(a) == 2**256 - 1 def test_preview_methods(w3, token, vault): a = w3.eth.accounts[0] assert vault.totalAssets() == 0 - assert vault.convertToAssets(10 ** 18) == 0 # no assets - assert vault.convertToShares(10 ** 18) == 10 ** 18 # 1:1 price + assert vault.convertToAssets(10**18) == 0 # no assets + assert vault.convertToShares(10**18) == 10**18 # 1:1 price assert vault.previewDeposit(AMOUNT) == AMOUNT # 1:1 price assert vault.previewMint(AMOUNT) == AMOUNT # 1:1 price assert vault.previewWithdraw(AMOUNT) == 0 # but no assets @@ -50,8 +50,8 @@ def test_preview_methods(w3, token, vault): vault.deposit(AMOUNT, transact={"from": a}) assert vault.totalAssets() == AMOUNT - assert vault.convertToAssets(10 ** 18) == 10 ** 18 # 1:1 price - assert vault.convertToShares(10 ** 18) == 10 ** 18 # 1:1 price + assert vault.convertToAssets(10**18) == 10**18 # 1:1 price + assert vault.convertToShares(10**18) == 10**18 # 1:1 price assert vault.previewDeposit(AMOUNT) == AMOUNT # 1:1 price assert vault.previewMint(AMOUNT) == AMOUNT # 1:1 price assert vault.previewWithdraw(AMOUNT) == AMOUNT # 1:1 price @@ -60,8 +60,8 @@ def test_preview_methods(w3, token, vault): token.mint(vault.address, AMOUNT, transact={"from": a}) assert vault.totalAssets() == 2 * AMOUNT - assert vault.convertToAssets(10 ** 18) == 2 * 10 ** 18 # 2:1 price - assert vault.convertToShares(2 * 10 ** 18) == 10 ** 18 # 2:1 price + assert vault.convertToAssets(10**18) == 2 * 10**18 # 2:1 price + assert vault.convertToShares(2 * 10**18) == 10**18 # 2:1 price assert vault.previewDeposit(AMOUNT) == AMOUNT // 2 # 2:1 price assert vault.previewMint(AMOUNT // 2) == AMOUNT # 2:1 price assert vault.previewWithdraw(AMOUNT) == AMOUNT // 2 # 2:1 price @@ -70,8 +70,8 @@ def test_preview_methods(w3, token, vault): vault.DEBUG_steal_tokens(AMOUNT, transact={"from": a}) assert vault.totalAssets() == AMOUNT - assert vault.convertToAssets(10 ** 18) == 10 ** 18 # 1:1 price - assert vault.convertToShares(10 ** 18) == 10 ** 18 # 1:1 price + assert vault.convertToAssets(10**18) == 10**18 # 1:1 price + assert vault.convertToShares(10**18) == 10**18 # 1:1 price assert vault.previewDeposit(AMOUNT) == AMOUNT # 1:1 price assert vault.previewMint(AMOUNT) == AMOUNT # 1:1 price assert vault.previewWithdraw(AMOUNT) == AMOUNT # 1:1 price @@ -80,8 +80,8 @@ def test_preview_methods(w3, token, vault): vault.DEBUG_steal_tokens(AMOUNT // 2, transact={"from": a}) assert vault.totalAssets() == AMOUNT // 2 - assert vault.convertToAssets(10 ** 18) == 10 ** 18 // 2 # 1:2 price - assert vault.convertToShares(10 ** 18 // 2) == 10 ** 18 # 1:2 price + assert vault.convertToAssets(10**18) == 10**18 // 2 # 1:2 price + assert vault.convertToShares(10**18 // 2) == 10**18 # 1:2 price assert vault.previewDeposit(AMOUNT) == 2 * AMOUNT # 1:2 price assert vault.previewMint(2 * AMOUNT) == AMOUNT # 1:2 price assert vault.previewWithdraw(AMOUNT) == 2 * AMOUNT # 1:2 price diff --git a/tests/examples/wallet/test_wallet.py b/tests/examples/wallet/test_wallet.py index c15f74ffe5..8114006f28 100644 --- a/tests/examples/wallet/test_wallet.py +++ b/tests/examples/wallet/test_wallet.py @@ -11,7 +11,7 @@ def c(w3, get_contract): code = f.read() # Sends wei to the contract for future transactions gas costs c = get_contract(code, *[[a1, a2, a3, a4, a5], 3]) - w3.eth.send_transaction({"to": c.address, "value": 10 ** 17}) + w3.eth.send_transaction({"to": c.address, "value": 10**17}) return c @@ -32,7 +32,7 @@ def test_approve(w3, c, tester, assert_tx_failed, sign): a0, a1, a2, a3, a4, a5, a6 = w3.eth.accounts[:7] k0, k1, k2, k3, k4, k5, k6, k7 = tester.backend.account_keys[:8] - to, value, data = b"\x35" * 20, 10 ** 16, b"" + to, value, data = b"\x35" * 20, 10**16, b"" to_address = w3.toChecksumAddress(to) def pack_and_sign(seq, *args): @@ -110,12 +110,12 @@ def test_javascript_signatures(w3, get_contract): owners = [w3.toChecksumAddress(x) for x in accounts + [a3, zero_address, zero_address]] x2 = get_contract(f.read(), *[owners, 2]) - w3.eth.send_transaction({"to": x2.address, "value": 10 ** 17}) + w3.eth.send_transaction({"to": x2.address, "value": 10**17}) # There's no need to pass in signatures because the owners are 0 addresses # causing them to default to valid signatures x2.approve( - 0, recipient, 25, b"", sigs + [[0, 0, 0]] * 3, call={"to": x2.address, "value": 10 ** 17} + 0, recipient, 25, b"", sigs + [[0, 0, 0]] * 3, call={"to": x2.address, "value": 10**17} ) print("Javascript signature tests passed") diff --git a/tests/functional/semantics/analysis/test_array_index.py b/tests/functional/semantics/analysis/test_array_index.py index e025dde2f5..27c0634cf8 100644 --- a/tests/functional/semantics/analysis/test_array_index.py +++ b/tests/functional/semantics/analysis/test_array_index.py @@ -41,7 +41,7 @@ def foo(): validate_semantics(vyper_module, {}) -@pytest.mark.parametrize("value", [-1, 3, -(2 ** 127), 2 ** 127 - 1, 2 ** 256 - 1]) +@pytest.mark.parametrize("value", [-1, 3, -(2**127), 2**127 - 1, 2**256 - 1]) def test_out_of_bounds(namespace, value): code = f""" diff --git a/tests/functional/semantics/analysis/test_potential_types.py b/tests/functional/semantics/analysis/test_potential_types.py index 0fe44a1d41..74cdc9ae0f 100644 --- a/tests/functional/semantics/analysis/test_potential_types.py +++ b/tests/functional/semantics/analysis/test_potential_types.py @@ -13,7 +13,7 @@ from vyper.semantics.types import AddressT, BoolT, DArrayT, SArrayT from vyper.semantics.types.shortcuts import INT128_T -INTEGER_LITERALS = [(42, 31337), (-1, 1), (69, 2 ** 128)] +INTEGER_LITERALS = [(42, 31337), (-1, 1), (69, 2**128)] DECIMAL_LITERALS = [("4.2", "-1.337")] BOOL_LITERALS = [(True, False), (True, True), (False, False)] STRING_LITERALS = [("'hi'", "'there'"), ("'foo'", "'bar'"), ("'longer'", "'short'")] @@ -67,7 +67,7 @@ def test_binop(build_node, namespace, op, left, right): @pytest.mark.parametrize("op", "+-*/%") -@pytest.mark.parametrize("left,right", [(42, "2.3"), (-1, 2 ** 255)]) +@pytest.mark.parametrize("left,right", [(42, "2.3"), (-1, 2**255)]) def test_binop_type_mismatch(build_node, namespace, op, left, right): node = build_node(f"{left}{op}{right}") with namespace.enter_scope(): diff --git a/tests/fuzzing/test_exponents.py b/tests/fuzzing/test_exponents.py index 376acc0eaf..29c1f198ed 100644 --- a/tests/fuzzing/test_exponents.py +++ b/tests/fuzzing/test_exponents.py @@ -14,8 +14,8 @@ def foo(a: uint256) -> uint256: return a ** {power} """ _min_base, max_base = calculate_largest_base(power, 256, False) - assert max_base ** power < 2 ** 256 - assert (max_base + 1) ** power >= 2 ** 256 + assert max_base**power < 2**256 + assert (max_base + 1) ** power >= 2**256 c = get_contract(code) @@ -33,11 +33,11 @@ def foo(a: int128) -> int128: """ min_base, max_base = calculate_largest_base(power, 128, True) - assert -(2 ** 127) <= max_base ** power < 2 ** 127 - assert -(2 ** 127) <= min_base ** power < 2 ** 127 + assert -(2**127) <= max_base**power < 2**127 + assert -(2**127) <= min_base**power < 2**127 - assert not -(2 ** 127) <= (max_base + 1) ** power < 2 ** 127 - assert not -(2 ** 127) <= (min_base - 1) ** power < 2 ** 127 + assert not -(2**127) <= (max_base + 1) ** power < 2**127 + assert not -(2**127) <= (min_base - 1) ** power < 2**127 c = get_contract(code) @@ -58,11 +58,11 @@ def foo(a: int16) -> int16: """ min_base, max_base = calculate_largest_base(power, 16, True) - assert -(2 ** 15) <= max_base ** power < 2 ** 15 - assert -(2 ** 15) <= min_base ** power < 2 ** 15 + assert -(2**15) <= max_base**power < 2**15 + assert -(2**15) <= min_base**power < 2**15 - assert not -(2 ** 15) <= (max_base + 1) ** power < 2 ** 15 - assert not -(2 ** 15) <= (min_base - 1) ** power < 2 ** 15 + assert not -(2**15) <= (max_base + 1) ** power < 2**15 + assert not -(2**15) <= (min_base - 1) ** power < 2**15 c = get_contract(code) @@ -74,24 +74,24 @@ def foo(a: int16) -> int16: @pytest.mark.fuzzing -@given(a=st.integers(min_value=2, max_value=2 ** 256 - 1)) +@given(a=st.integers(min_value=2, max_value=2**256 - 1)) # 8 bits -@example(a=2 ** 7) -@example(a=2 ** 7 - 1) +@example(a=2**7) +@example(a=2**7 - 1) # 16 bits -@example(a=2 ** 15) -@example(a=2 ** 15 - 1) +@example(a=2**15) +@example(a=2**15 - 1) # 32 bits -@example(a=2 ** 31) -@example(a=2 ** 31 - 1) +@example(a=2**31) +@example(a=2**31 - 1) # 64 bits -@example(a=2 ** 63) -@example(a=2 ** 63 - 1) +@example(a=2**63) +@example(a=2**63 - 1) # 128 bits -@example(a=2 ** 127) -@example(a=2 ** 127 - 1) +@example(a=2**127) +@example(a=2**127 - 1) # 256 bits -@example(a=2 ** 256 - 1) +@example(a=2**256 - 1) @settings(max_examples=200, deadline=1000) def test_max_exp(get_contract, assert_tx_failed, a): code = f""" @@ -104,29 +104,29 @@ def foo(b: uint256) -> uint256: max_power = calculate_largest_power(a, 256, False) - assert a ** max_power < 2 ** 256 - assert a ** (max_power + 1) >= 2 ** 256 + assert a**max_power < 2**256 + assert a ** (max_power + 1) >= 2**256 c.foo(max_power) assert_tx_failed(lambda: c.foo(max_power + 1)) @pytest.mark.fuzzing -@given(a=st.integers(min_value=2, max_value=2 ** 127 - 1)) +@given(a=st.integers(min_value=2, max_value=2**127 - 1)) # 8 bits -@example(a=2 ** 7) -@example(a=2 ** 7 - 1) +@example(a=2**7) +@example(a=2**7 - 1) # 16 bits -@example(a=2 ** 15) -@example(a=2 ** 15 - 1) +@example(a=2**15) +@example(a=2**15 - 1) # 32 bits -@example(a=2 ** 31) -@example(a=2 ** 31 - 1) +@example(a=2**31) +@example(a=2**31 - 1) # 64 bits -@example(a=2 ** 63) -@example(a=2 ** 63 - 1) +@example(a=2**63) +@example(a=2**63 - 1) # 128 bits -@example(a=2 ** 127 - 1) +@example(a=2**127 - 1) @settings(max_examples=200, deadline=1000) def test_max_exp_int128(get_contract, assert_tx_failed, a): code = f""" @@ -139,8 +139,8 @@ def foo(b: int128) -> int128: max_power = calculate_largest_power(a, 128, True) - assert -(2 ** 127) <= a ** max_power < 2 ** 127 - assert not -(2 ** 127) <= a ** (max_power + 1) < 2 ** 127 + assert -(2**127) <= a**max_power < 2**127 + assert not -(2**127) <= a ** (max_power + 1) < 2**127 c.foo(max_power) assert_tx_failed(lambda: c.foo(max_power + 1)) diff --git a/tests/parser/features/decorators/test_payable.py b/tests/parser/features/decorators/test_payable.py index aabdfbdf37..420af1cad9 100644 --- a/tests/parser/features/decorators/test_payable.py +++ b/tests/parser/features/decorators/test_payable.py @@ -181,7 +181,7 @@ def test_nonpayable_runtime_assertion(assert_tx_failed, get_contract, code): c = get_contract(code) c.foo(transact={"value": 0}) - assert_tx_failed(lambda: c.foo(transact={"value": 10 ** 18})) + assert_tx_failed(lambda: c.foo(transact={"value": 10**18})) payable_code = [ @@ -332,7 +332,7 @@ def bar() -> bool: def test_payable_runtime_assertion(get_contract, code): c = get_contract(code) - c.foo(transact={"value": 10 ** 18}) + c.foo(transact={"value": 10**18}) c.foo(transact={"value": 0}) diff --git a/tests/parser/features/external_contracts/test_erc20_abi.py b/tests/parser/features/external_contracts/test_erc20_abi.py index ecc6edceb8..4a09ce68fa 100644 --- a/tests/parser/features/external_contracts/test_erc20_abi.py +++ b/tests/parser/features/external_contracts/test_erc20_abi.py @@ -4,8 +4,8 @@ TOKEN_NAME = "Vypercoin" TOKEN_SYMBOL = "FANG" TOKEN_DECIMALS = 18 -TOKEN_INITIAL_SUPPLY = 21 * 10 ** 6 -TOKEN_TOTAL_SUPPLY = TOKEN_INITIAL_SUPPLY * (10 ** TOKEN_DECIMALS) +TOKEN_INITIAL_SUPPLY = 21 * 10**6 +TOKEN_TOTAL_SUPPLY = TOKEN_INITIAL_SUPPLY * (10**TOKEN_DECIMALS) @pytest.fixture @@ -82,7 +82,6 @@ def test_initial_state(w3, erc20_caller): def test_call_transfer(w3, erc20, erc20_caller, assert_tx_failed): - # Basic transfer. erc20.transfer(erc20_caller.address, 10, transact={}) assert erc20.balanceOf(erc20_caller.address) == 10 diff --git a/tests/parser/features/external_contracts/test_external_contract_calls.py b/tests/parser/features/external_contracts/test_external_contract_calls.py index c51df0b9db..524a0e958d 100644 --- a/tests/parser/features/external_contracts/test_external_contract_calls.py +++ b/tests/parser/features/external_contracts/test_external_contract_calls.py @@ -815,7 +815,7 @@ def bar(arg1: address) -> (address, Bytes[3], address): """ c2 = get_contract(contract_2) - assert c.foo() == [(2 ** 160) - 1, b"dog", (2 ** 160) - 2] + assert c.foo() == [(2**160) - 1, b"dog", (2**160) - 2] result = c2.bar(c.address) assert len(result) == 3 assert result[0].lower() == "0xffffffffffffffffffffffffffffffffffffffff" @@ -848,7 +848,7 @@ def bar(arg1: address) -> (address, Bytes[3], address): """ c2 = get_contract(contract_2) - assert c.foo() == [(2 ** 160) - 1, b"dog", 2 ** 160] + assert c.foo() == [(2**160) - 1, b"dog", 2**160] assert_tx_failed(lambda: c2.bar(c.address)) @@ -1438,7 +1438,6 @@ def call_baz(): def test_invalid_keyword_on_call(assert_compile_failed, get_contract_with_gas_estimation): - contract_1 = """ interface Bar: def set_lucky(arg1: int128): nonpayable @@ -1455,7 +1454,6 @@ def get_lucky(amount_to_send: int128) -> int128: def test_invalid_contract_declaration(assert_compile_failed, get_contract_with_gas_estimation): - contract_1 = """ interface Bar: def set_lucky(arg1: int128): nonpayable @@ -1508,7 +1506,6 @@ def foo(a: address, x: uint256, y: uint256): @pytest.mark.parametrize("bad_code", FAILING_CONTRACTS_STRUCTURE_EXCEPTION) def test_bad_code_struct_exc(assert_compile_failed, get_contract_with_gas_estimation, bad_code): - assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), ArgumentException) diff --git a/tests/parser/features/test_assert.py b/tests/parser/features/test_assert.py index db521f556a..842b32d815 100644 --- a/tests/parser/features/test_assert.py +++ b/tests/parser/features/test_assert.py @@ -16,7 +16,7 @@ def foo(): """ c = get_contract_with_gas_estimation(code) a0 = w3.eth.accounts[0] - gas_sent = 10 ** 6 + gas_sent = 10**6 tx_hash = c.foo(transact={"from": a0, "gas": gas_sent, "gasPrice": 10}) # More info on receipt status: # https://github.com/ethereum/EIPs/blob/master/EIPS/eip-658.md#specification. diff --git a/tests/parser/features/test_assert_unreachable.py b/tests/parser/features/test_assert_unreachable.py index 79023a1e60..90ed31a22e 100644 --- a/tests/parser/features/test_assert_unreachable.py +++ b/tests/parser/features/test_assert_unreachable.py @@ -7,7 +7,7 @@ def foo(): c = get_contract(code) a0 = w3.eth.accounts[0] - gas_sent = 10 ** 6 + gas_sent = 10**6 tx_hash = c.foo(transact={"from": a0, "gas": gas_sent, "gasPrice": 10}) tx_receipt = w3.eth.get_transaction_receipt(tx_hash) diff --git a/tests/parser/features/test_bytes_map_keys.py b/tests/parser/features/test_bytes_map_keys.py index 9a648b762d..4913182d52 100644 --- a/tests/parser/features/test_bytes_map_keys.py +++ b/tests/parser/features/test_bytes_map_keys.py @@ -58,7 +58,7 @@ def get(k: Bytes[34]) -> int128: c = get_contract(code) - c.set(b"a" * 34, 6789, transact={"gas": 10 ** 6}) + c.set(b"a" * 34, 6789, transact={"gas": 10**6}) assert c.get(b"a" * 34) == 6789 diff --git a/tests/parser/features/test_clampers.py b/tests/parser/features/test_clampers.py index 0df7e81c74..006fb0b4e4 100644 --- a/tests/parser/features/test_clampers.py +++ b/tests/parser/features/test_clampers.py @@ -142,7 +142,7 @@ def foo(s: int{bits}) -> int{bits}: def test_sint_clamper_failing(w3, assert_tx_failed, get_contract, n, evm_version): bits = 8 * (n + 1) lo, hi = int_bounds(True, bits) - values = [-(2 ** 255), 2 ** 255 - 1, lo - 1, hi + 1] + values = [-(2**255), 2**255 - 1, lo - 1, hi + 1] code = f""" @external def foo(s: int{bits}) -> int{bits}: @@ -168,7 +168,7 @@ def foo(s: bool) -> bool: @pytest.mark.parametrize("evm_version", list(EVM_VERSIONS)) -@pytest.mark.parametrize("value", [2, 3, 4, 8, 16, 2 ** 256 - 1]) +@pytest.mark.parametrize("value", [2, 3, 4, 8, 16, 2**256 - 1]) def test_bool_clamper_failing(w3, assert_tx_failed, get_contract, value, evm_version): code = """ @external @@ -181,7 +181,7 @@ def foo(s: bool) -> bool: @pytest.mark.parametrize("evm_version", list(EVM_VERSIONS)) -@pytest.mark.parametrize("value", [0] + [2 ** i for i in range(5)]) +@pytest.mark.parametrize("value", [0] + [2**i for i in range(5)]) def test_enum_clamper_passing(w3, get_contract, value, evm_version): code = """ enum Roles: @@ -201,7 +201,7 @@ def foo(s: Roles) -> Roles: @pytest.mark.parametrize("evm_version", list(EVM_VERSIONS)) -@pytest.mark.parametrize("value", [2 ** i for i in range(5, 256)]) +@pytest.mark.parametrize("value", [2**i for i in range(5, 256)]) def test_enum_clamper_failing(w3, assert_tx_failed, get_contract, value, evm_version): code = """ enum Roles: @@ -224,7 +224,7 @@ def foo(s: Roles) -> Roles: @pytest.mark.parametrize("n", list(range(32))) def test_uint_clamper_passing(w3, get_contract, evm_version, n): bits = 8 * (n + 1) - values = [0, 1, 2 ** bits - 1] + values = [0, 1, 2**bits - 1] code = f""" @external def foo(s: uint{bits}) -> uint{bits}: @@ -240,7 +240,7 @@ def foo(s: uint{bits}) -> uint{bits}: @pytest.mark.parametrize("n", list(range(31))) # uint256 has no failing cases def test_uint_clamper_failing(w3, assert_tx_failed, get_contract, evm_version, n): bits = 8 * (n + 1) - values = [-1, -(2 ** 255), 2 ** bits] + values = [-1, -(2**255), 2**bits] code = f""" @external def foo(s: uint{bits}) -> uint{bits}: @@ -278,7 +278,7 @@ def foo(s: address) -> address: @pytest.mark.parametrize("evm_version", list(EVM_VERSIONS)) -@pytest.mark.parametrize("value", [2 ** 160, 2 ** 256 - 1]) +@pytest.mark.parametrize("value", [2**160, 2**256 - 1]) def test_address_clamper_failing(w3, assert_tx_failed, get_contract, value, evm_version): code = """ @external @@ -297,8 +297,8 @@ def foo(s: address) -> address: 0, 1, -1, - Decimal(2 ** 167 - 1) / 10 ** 10, - -Decimal(2 ** 167) / 10 ** 10, + Decimal(2**167 - 1) / 10**10, + -Decimal(2**167) / 10**10, "0.0", "1.0", "-1.0", @@ -326,8 +326,8 @@ def foo(s: decimal) -> decimal: @pytest.mark.parametrize( "value", [ - 2 ** 167, - -(2 ** 167 + 1), + 2**167, + -(2**167 + 1), 187072209578355573530071658587684226515959365500928, # 2 ** 167 -187072209578355573530071658587684226515959365500929, # - (2 ** 127 - 1e-10) ], @@ -344,7 +344,7 @@ def foo(s: decimal) -> decimal: assert_tx_failed(lambda: _make_tx(w3, c.address, "foo(fixed168x10)", [value])) -@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) def test_int128_array_clamper_passing(w3, get_contract, value): code = """ @external @@ -356,10 +356,10 @@ def foo(a: uint256, b: int128[5], c: uint256) -> int128[5]: # to ensure there are no off-by-one errors d = [value] * 5 c = get_contract(code) - assert c.foo(2 ** 127, [value] * 5, 2 ** 127) == d + assert c.foo(2**127, [value] * 5, 2**127) == d -@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) +@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) @pytest.mark.parametrize("idx", range(5)) def test_int128_array_clamper_failing(w3, assert_tx_failed, get_contract, bad_value, idx): # ensure the invalid value is detected at all locations in the array @@ -376,7 +376,7 @@ def foo(b: int128[5]) -> int128[5]: assert_tx_failed(lambda: _make_tx(w3, c.address, "foo(int128[5])", values)) -@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) def test_int128_array_looped_clamper_passing(w3, get_contract, value): # when an array is > 5 items, the arg clamper runs in a loop to reduce bytecode size code = """ @@ -387,10 +387,10 @@ def foo(a: uint256, b: int128[10], c: uint256) -> int128[10]: d = [value] * 10 c = get_contract(code) - assert c.foo(2 ** 127, d, 2 ** 127) == d + assert c.foo(2**127, d, 2**127) == d -@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) +@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) @pytest.mark.parametrize("idx", range(10)) def test_int128_array_looped_clamper_failing(w3, assert_tx_failed, get_contract, bad_value, idx): code = """ @@ -406,7 +406,7 @@ def foo(b: int128[10]) -> int128[10]: assert_tx_failed(lambda: _make_tx(w3, c.address, "foo(int128[10])", values)) -@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) def test_multidimension_array_clamper_passing(w3, get_contract, value): code = """ @external @@ -417,10 +417,10 @@ def foo(a: uint256, b: int128[6][3][1][8], c: uint256) -> int128[6][3][1][8]: # 6 * 3 * 1 * 8 = 144, the total number of values in our multidimensional array d = [[[[value] * 6] * 3] * 1] * 8 c = get_contract(code) - assert c.foo(2 ** 127, d, 2 ** 127, call={"gasPrice": 0}) == d + assert c.foo(2**127, d, 2**127, call={"gasPrice": 0}) == d -@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) +@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) @pytest.mark.parametrize("idx", range(12)) def test_multidimension_array_clamper_failing(w3, assert_tx_failed, get_contract, bad_value, idx): code = """ @@ -436,7 +436,7 @@ def foo(b: int128[6][1][2]) -> int128[6][1][2]: assert_tx_failed(lambda: _make_tx(w3, c.address, "foo(int128[6][1][2]])", values)) -@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) def test_int128_dynarray_clamper_passing(w3, get_contract, value): code = """ @external @@ -448,10 +448,10 @@ def foo(a: uint256, b: DynArray[int128, 5], c: uint256) -> DynArray[int128, 5]: # to ensure there are no off-by-one errors d = [value] * 5 c = get_contract(code) - assert c.foo(2 ** 127, d, 2 ** 127) == d + assert c.foo(2**127, d, 2**127) == d -@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) +@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) @pytest.mark.parametrize("idx", range(5)) def test_int128_dynarray_clamper_failing( w3, abi_encode, assert_tx_failed, get_contract, bad_value, idx @@ -473,7 +473,7 @@ def foo(b: int128[5]) -> int128[5]: assert_tx_failed(lambda: _make_invalid_dynarray_tx(w3, c.address, signature, data)) -@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) def test_int128_dynarray_looped_clamper_passing(w3, get_contract, value): # when an array is > 5 items, the arg clamper runs in a loop to reduce bytecode size code = """ @@ -483,10 +483,10 @@ def foo(a: uint256, b: DynArray[int128, 10], c: uint256) -> DynArray[int128, 10] """ d = [value] * 10 c = get_contract(code) - assert c.foo(2 ** 127, d, 2 ** 127) == d + assert c.foo(2**127, d, 2**127) == d -@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) +@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) @pytest.mark.parametrize("idx", range(10)) def test_int128_dynarray_looped_clamper_failing(w3, assert_tx_failed, get_contract, bad_value, idx): code = """ @@ -505,7 +505,7 @@ def foo(b: DynArray[int128, 10]) -> DynArray[int128, 10]: assert_tx_failed(lambda: _make_invalid_dynarray_tx(w3, c.address, signature, data)) -@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) def test_multidimension_dynarray_clamper_passing(w3, get_contract, value): code = """ @external @@ -519,10 +519,10 @@ def foo( # Out of gas exception if outermost length is 6 and greater d = [[[[value] * 5] * 6] * 7] * 8 c = get_contract(code) - assert c.foo(2 ** 127, d, 2 ** 127, call={"gasPrice": 0}) == d + assert c.foo(2**127, d, 2**127, call={"gasPrice": 0}) == d -@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) +@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) @pytest.mark.parametrize("idx", range(4)) def test_multidimension_dynarray_clamper_failing( w3, abi_encode, assert_tx_failed, get_contract, bad_value, idx @@ -549,7 +549,7 @@ def foo(b: DynArray[DynArray[int128, 2], 2]) -> DynArray[DynArray[int128, 2], 2] assert_tx_failed(lambda: _make_invalid_dynarray_tx(w3, c.address, signature, data)) -@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) def test_dynarray_list_clamper_passing(w3, abi_encode, get_contract, value): code = """ @external @@ -562,10 +562,10 @@ def foo( """ d = [[value] * 5] * 6 c = get_contract(code) - assert c.foo(2 ** 127, d, 2 ** 127) == d + assert c.foo(2**127, d, 2**127) == d -@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) +@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) @pytest.mark.parametrize("idx", range(10)) def test_dynarray_list_clamper_failing( w3, abi_encode, assert_tx_failed, get_contract, bad_value, idx diff --git a/tests/parser/features/test_constructor.py b/tests/parser/features/test_constructor.py index 297e54d216..c9dfcfc5df 100644 --- a/tests/parser/features/test_constructor.py +++ b/tests/parser/features/test_constructor.py @@ -82,10 +82,10 @@ def foo(x: int128) -> int128: c = get_contract_with_gas_estimation(large_input_code) c.foo(1274124) - c.foo(2 ** 120) + c.foo(2**120) with pytest.raises(ValidationError): - c.foo(2 ** 130) + c.foo(2**130) def test_large_input_code_2(w3, get_contract_with_gas_estimation): @@ -102,7 +102,7 @@ def foo() -> int128: get_contract_with_gas_estimation(large_input_code_2, *[17]) with pytest.raises(TypeError): - get_contract_with_gas_estimation(large_input_code_2, *[2 ** 130]) + get_contract_with_gas_estimation(large_input_code_2, *[2**130]) print("Passed invalid input tests") diff --git a/tests/parser/features/test_immutable.py b/tests/parser/features/test_immutable.py index 4ce26ce459..bb01b3fc07 100644 --- a/tests/parser/features/test_immutable.py +++ b/tests/parser/features/test_immutable.py @@ -5,8 +5,8 @@ "typ,value", [ ("uint256", 42), - ("int256", -(2 ** 200)), - ("int128", -(2 ** 126)), + ("int256", -(2**200)), + ("int128", -(2**126)), ("address", "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"), ("bytes32", b"deadbeef" * 4), ("bool", True), @@ -32,7 +32,7 @@ def get_value() -> {typ}: assert c.get_value() == value -@pytest.mark.parametrize("val", [0, 1, 2 ** 256 - 1]) +@pytest.mark.parametrize("val", [0, 1, 2**256 - 1]) def test_usage_in_constructor(get_contract, val): code = """ A: immutable(uint256) @@ -101,7 +101,7 @@ def __init__(_a: uint256, _b: uint256, _c: address, _d: int256): def get_my_struct() -> MyStruct: return my_struct """ - values = (100, 42, "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", -(2 ** 200)) + values = (100, 42, "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", -(2**200)) c = get_contract(code, *values) assert c.get_my_struct() == values diff --git a/tests/parser/features/test_logging.py b/tests/parser/features/test_logging.py index 71e61474e4..426402bf44 100644 --- a/tests/parser/features/test_logging.py +++ b/tests/parser/features/test_logging.py @@ -810,7 +810,6 @@ def foo(): def test_variable_list_packing(get_logs, get_contract_with_gas_estimation): - code = """ event Bar: _value: int128[4] @@ -828,7 +827,6 @@ def foo(): def test_literal_list_packing(get_logs, get_contract_with_gas_estimation): - code = """ event Bar: _value: int128[4] @@ -845,7 +843,6 @@ def foo(): def test_storage_list_packing(get_logs, bytes_helper, get_contract_with_gas_estimation): - code = """ event Bar: _value: int128[4] @@ -872,7 +869,6 @@ def set_list(): def test_passed_list_packing(get_logs, get_contract_with_gas_estimation): - code = """ event Bar: _value: int128[4] @@ -910,7 +906,6 @@ def foo(): def test_storage_byte_packing(get_logs, bytes_helper, get_contract_with_gas_estimation): - code = """ event MyLog: arg1: Bytes[29] @@ -937,7 +932,6 @@ def setbytez(): def test_storage_decimal_list_packing(get_logs, bytes_helper, get_contract_with_gas_estimation): - code = """ event Bar: _value: decimal[4] diff --git a/tests/parser/functions/test_abi_decode.py b/tests/parser/functions/test_abi_decode.py index 8426b48658..d3ffc339cf 100644 --- a/tests/parser/functions/test_abi_decode.py +++ b/tests/parser/functions/test_abi_decode.py @@ -284,7 +284,7 @@ def foo(bs: Bytes[160]) -> (uint256, DynArray[uint256, 3]): c = get_contract(code) bs = [1, 2, 3] encoded = abi_encode("(uint256[])", (bs,)) - assert c.foo(encoded) == [2 ** 256 - 1, bs] + assert c.foo(encoded) == [2**256 - 1, bs] def test_abi_decode_private_nested_dynarray(get_contract, abi_encode): @@ -308,7 +308,7 @@ def foo(bs: Bytes[1696]) -> (uint256, DynArray[DynArray[DynArray[uint256, 3], 3] [[19, 20, 21], [22, 23, 24], [25, 26, 27]], ] encoded = abi_encode("(uint256[][][])", (bs,)) - assert c.foo(encoded) == [2 ** 256 - 1, bs] + assert c.foo(encoded) == [2**256 - 1, bs] def test_abi_decode_return(get_contract, abi_encode): diff --git a/tests/parser/functions/test_abi_encode.py b/tests/parser/functions/test_abi_encode.py index f1c2577797..73227719d5 100644 --- a/tests/parser/functions/test_abi_encode.py +++ b/tests/parser/functions/test_abi_encode.py @@ -82,7 +82,7 @@ def abi_encode3(x: uint256, ensure_tuple: bool, include_method_id: bool) -> Byte """ c = get_contract(code) - method_id = 0xDEADBEEF .to_bytes(4, "big") + method_id = 0xDEADBEEF.to_bytes(4, "big") # test each method once each with ensure_tuple set to True and False @@ -149,7 +149,7 @@ def abi_encode(d: DynArray[uint256, 3], ensure_tuple: bool, include_method_id: b """ c = get_contract(code) - method_id = 0xDEADBEEF .to_bytes(4, "big") + method_id = 0xDEADBEEF.to_bytes(4, "big") arg = [123, 456, 789] assert c.abi_encode(arg, False, False).hex() == abi_encode("uint256[]", arg).hex() @@ -193,7 +193,7 @@ def abi_encode( """ c = get_contract(code) - method_id = 0xDEADBEEF .to_bytes(4, "big") + method_id = 0xDEADBEEF.to_bytes(4, "big") assert c.abi_encode(args, False, False).hex() == abi_encode("uint256[][]", args).hex() assert c.abi_encode(args, True, False).hex() == abi_encode("(uint256[][])", (args,)).hex() @@ -244,7 +244,7 @@ def abi_encode( """ c = get_contract(code) - method_id = 0xDEADBEEF .to_bytes(4, "big") + method_id = 0xDEADBEEF.to_bytes(4, "big") assert c.abi_encode(args, False, False).hex() == abi_encode("uint256[][][]", args).hex() assert c.abi_encode(args, True, False).hex() == abi_encode("(uint256[][][])", (args,)).hex() @@ -285,7 +285,7 @@ def foo(addr: address) -> Bytes[164]: c2 = get_contract(contract_2) - method_id = 0xDEADBEEF .to_bytes(4, "big") + method_id = 0xDEADBEEF.to_bytes(4, "big") # call to get_counter() should be evaluated only once get_counter_encoded = abi_encode("((uint256,string))", ((1, "hello"),)) @@ -309,7 +309,7 @@ def foo(bs: Bytes[32]) -> (uint256, Bytes[96]): """ c = get_contract(code) bs = "0" * 32 - assert c.foo(bs) == [2 ** 256 - 1, abi_encode("(bytes)", (bs,))] + assert c.foo(bs) == [2**256 - 1, abi_encode("(bytes)", (bs,))] def test_abi_encode_private_dynarray(get_contract, abi_encode): @@ -326,7 +326,7 @@ def foo(bs: DynArray[uint256, 3]) -> (uint256, Bytes[160]): """ c = get_contract(code) bs = [1, 2, 3] - assert c.foo(bs) == [2 ** 256 - 1, abi_encode("(uint256[])", (bs,))] + assert c.foo(bs) == [2**256 - 1, abi_encode("(uint256[])", (bs,))] def test_abi_encode_private_nested_dynarray(get_contract, abi_encode): @@ -348,7 +348,7 @@ def foo(bs: DynArray[DynArray[DynArray[uint256, 3], 3], 3]) -> (uint256, Bytes[1 [[10, 11, 12], [13, 14, 15], [16, 17, 18]], [[19, 20, 21], [22, 23, 24], [25, 26, 27]], ] - assert c.foo(bs) == [2 ** 256 - 1, abi_encode("(uint256[][][])", (bs,))] + assert c.foo(bs) == [2**256 - 1, abi_encode("(uint256[][][])", (bs,))] @pytest.mark.parametrize("empty_literal", ('b""', '""', "empty(Bytes[1])", "empty(String[1])")) diff --git a/tests/parser/functions/test_bitwise.py b/tests/parser/functions/test_bitwise.py index b807de2254..171ba7daeb 100644 --- a/tests/parser/functions/test_bitwise.py +++ b/tests/parser/functions/test_bitwise.py @@ -50,10 +50,10 @@ def test_test_bitwise(get_contract_with_gas_estimation, evm_version): assert c._bitwise_and(x, y) == (x & y) assert c._bitwise_or(x, y) == (x | y) assert c._bitwise_xor(x, y) == (x ^ y) - assert c._bitwise_not(x) == 2 ** 256 - 1 - x + assert c._bitwise_not(x) == 2**256 - 1 - x assert c._shift(x, 3) == x * 8 assert c._shift(x, 255) == 0 - assert c._shift(y, 255) == 2 ** 255 + assert c._shift(y, 255) == 2**255 assert c._shift(x, 256) == 0 assert c._shift(x, 0) == x assert c._shift(x, -1) == x // 2 @@ -61,7 +61,7 @@ def test_test_bitwise(get_contract_with_gas_estimation, evm_version): assert c._shift(x, -256) == 0 assert c._negatedShift(x, -3) == x * 8 assert c._negatedShift(x, -255) == 0 - assert c._negatedShift(y, -255) == 2 ** 255 + assert c._negatedShift(y, -255) == 2**255 assert c._negatedShift(x, -256) == 0 assert c._negatedShift(x, -0) == x assert c._negatedShift(x, 1) == x // 2 diff --git a/tests/parser/functions/test_ceil.py b/tests/parser/functions/test_ceil.py index 64e1f05c48..c0bf45fd83 100644 --- a/tests/parser/functions/test_ceil.py +++ b/tests/parser/functions/test_ceil.py @@ -43,7 +43,7 @@ def fou() -> int256: assert c.x_ceil() == 505 assert c.foo() == 1 assert c.fop() == 1 - assert c.foq() == math.ceil(Decimal(2 ** 167) / 10 ** 10) + assert c.foq() == math.ceil(Decimal(2**167) / 10**10) assert c.fos() == 0 assert c.fou() == 4 @@ -100,7 +100,7 @@ def ceil_param(p: decimal) -> int256: assert c.fop() == -5 assert c.foq() == 0 assert c.fos() == -5472 - assert c.fot() == math.ceil(-(Decimal(2 ** 167 - 1)) / 10 ** 10) + assert c.fot() == math.ceil(-(Decimal(2**167 - 1)) / 10**10) assert c.fou() == -3 assert c.ceil_param(Decimal("-0.5")) == 0 assert c.ceil_param(Decimal("-7777777.7777777")) == -7777777 diff --git a/tests/parser/functions/test_convert.py b/tests/parser/functions/test_convert.py index d0813f975a..80271bb4a5 100644 --- a/tests/parser/functions/test_convert.py +++ b/tests/parser/functions/test_convert.py @@ -249,7 +249,7 @@ def _signextend(val_bytes, bits): as_sint = unsigned_to_signed(as_uint, bits) - return (as_sint % 2 ** 256).to_bytes(32, byteorder="big") + return (as_sint % 2**256).to_bytes(32, byteorder="big") def _convert_int_to_int(val, o_typ): @@ -410,7 +410,6 @@ def _vyper_literal(val, typ): def test_convert_passing( get_contract_with_gas_estimation, assert_compile_failed, i_typ, o_typ, val ): - expected_val = _py_convert(val, i_typ, o_typ) if isinstance(o_typ, AddressT) and expected_val == "0x" + "00" * 20: # web3 has special formatter for zero address @@ -473,7 +472,7 @@ def test_memory_variable_convert(x: {i_typ}) -> {o_typ}: @pytest.mark.parametrize("typ", ["uint8", "int128", "int256", "uint256"]) -@pytest.mark.parametrize("val", [1, 2, 2 ** 128, 2 ** 256 - 1, 2 ** 256 - 2]) +@pytest.mark.parametrize("val", [1, 2, 2**128, 2**256 - 1, 2**256 - 2]) def test_enum_conversion(get_contract_with_gas_estimation, assert_compile_failed, val, typ): roles = "\n ".join([f"ROLE_{i}" for i in range(256)]) contract = f""" @@ -497,7 +496,7 @@ def bar(a: uint256) -> Roles: @pytest.mark.parametrize("typ", ["uint8", "int128", "int256", "uint256"]) -@pytest.mark.parametrize("val", [1, 2, 3, 4, 2 ** 128, 2 ** 256 - 1, 2 ** 256 - 2]) +@pytest.mark.parametrize("val", [1, 2, 3, 4, 2**128, 2**256 - 1, 2**256 - 2]) def test_enum_conversion_2( get_contract_with_gas_estimation, assert_compile_failed, assert_tx_failed, val, typ ): @@ -530,7 +529,6 @@ def foo(a: {typ}) -> Status: def test_convert_builtin_constant( get_contract_with_gas_estimation, builtin_constant, out_type, out_value ): - contract = f""" @external def convert_builtin_constant() -> {out_type}: diff --git a/tests/parser/functions/test_default_function.py b/tests/parser/functions/test_default_function.py index 6ec3ea0380..35c2f7292c 100644 --- a/tests/parser/functions/test_default_function.py +++ b/tests/parser/functions/test_default_function.py @@ -28,7 +28,7 @@ def __default__(): """ c = get_contract_with_gas_estimation(code) - logs = get_logs(w3.eth.send_transaction({"to": c.address, "value": 10 ** 17}), c, "Sent") + logs = get_logs(w3.eth.send_transaction({"to": c.address, "value": 10**17}), c, "Sent") assert w3.eth.accounts[0] == logs[0].args.sender assert w3.eth.get_balance(c.address) == w3.toWei(0.1, "ether") @@ -51,7 +51,7 @@ def __default__(): """ c = get_contract_with_gas_estimation(code) - logs = get_logs(w3.eth.send_transaction({"to": c.address, "value": 10 ** 17}), c, "Sent") + logs = get_logs(w3.eth.send_transaction({"to": c.address, "value": 10**17}), c, "Sent") assert w3.eth.accounts[0] == logs[0].args.sender assert w3.eth.get_balance(c.address) == w3.toWei(0.1, "ether") @@ -67,7 +67,7 @@ def __default__(): """ c = get_contract_with_gas_estimation(code) - assert_tx_failed(lambda: w3.eth.send_transaction({"to": c.address, "value": 10 ** 17})) + assert_tx_failed(lambda: w3.eth.send_transaction({"to": c.address, "value": 10**17})) def test_multi_arg_default(assert_compile_failed, get_contract_with_gas_estimation): diff --git a/tests/parser/functions/test_default_parameters.py b/tests/parser/functions/test_default_parameters.py index 2e36c3f377..a90f5e6624 100644 --- a/tests/parser/functions/test_default_parameters.py +++ b/tests/parser/functions/test_default_parameters.py @@ -167,8 +167,8 @@ def validate_value(cls, value): monkeypatch.setattr("eth_abi.encoding.NumberEncoder.validate_value", validate_value) - assert c.bar(200, 2 ** 127 - 1) == [200, 2 ** 127 - 1] - assert_tx_failed(lambda: c.bar(200, 2 ** 127)) + assert c.bar(200, 2**127 - 1) == [200, 2**127 - 1] + assert_tx_failed(lambda: c.bar(200, 2**127)) def test_default_param_private(get_contract): diff --git a/tests/parser/functions/test_extract32.py b/tests/parser/functions/test_extract32.py index 5e3b4e1984..c1a333ae32 100644 --- a/tests/parser/functions/test_extract32.py +++ b/tests/parser/functions/test_extract32.py @@ -74,7 +74,7 @@ def foq(inp: Bytes[32]) -> address: assert_tx_failed(lambda: c.foo(b"\x80" + b"\x00" * 30)) - assert c.bar(b"\x80" + b"\x00" * 31) == 2 ** 255 + assert c.bar(b"\x80" + b"\x00" * 31) == 2**255 assert c.baz(b"crow" * 8) == b"crow" * 8 assert c.fop(b"crow" * 8) == b"crow" * 8 diff --git a/tests/parser/functions/test_floor.py b/tests/parser/functions/test_floor.py index 80957cb2ea..dc53545ac3 100644 --- a/tests/parser/functions/test_floor.py +++ b/tests/parser/functions/test_floor.py @@ -45,7 +45,7 @@ def fou() -> int256: assert c.x_floor() == 504 assert c.foo() == 1 assert c.fop() == 1 - assert c.foq() == math.floor(Decimal(2 ** 167 - 1) / 10 ** 10) + assert c.foq() == math.floor(Decimal(2**167 - 1) / 10**10) assert c.fos() == 0 assert c.fot() == 0 assert c.fou() == 3 @@ -104,7 +104,7 @@ def floor_param(p: decimal) -> int256: assert c.fop() == -27 assert c.foq() == -9001 assert c.fos() == -1 - assert c.fot() == math.floor(-Decimal(2 ** 167) / 10 ** 10) + assert c.fot() == math.floor(-Decimal(2**167) / 10**10) assert c.fou() == -4 assert c.floor_param(Decimal("-5.6")) == -6 assert c.floor_param(Decimal("-0.0000000001")) == -1 diff --git a/tests/parser/functions/test_interfaces.py b/tests/parser/functions/test_interfaces.py index f0f6cf6d62..fff2a6bda3 100644 --- a/tests/parser/functions/test_interfaces.py +++ b/tests/parser/functions/test_interfaces.py @@ -187,7 +187,6 @@ def bar() -> uint256: @pytest.mark.parametrize("code", VALID_IMPORT_CODE) def test_extract_file_interface_imports(code): - assert extract_file_interface_imports(code[0]) == {"Foo": code[1]} @@ -249,8 +248,8 @@ def test(): @pytest.mark.parametrize( "kwarg,typ,expected", [ - ("max_value(uint256)", "uint256", 2 ** 256 - 1), - ("min_value(int128)", "int128", -(2 ** 127)), + ("max_value(uint256)", "uint256", 2**256 - 1), + ("min_value(int128)", "int128", -(2**127)), ("empty(uint8[2])", "uint8[2]", [0, 0]), ('method_id("vyper()", output_type=bytes4)', "bytes4", b"\x82\xcbE\xfb"), ("epsilon(decimal)", "decimal", Decimal("1E-10")), @@ -372,7 +371,7 @@ def test_fail3() -> int256: interface_codes={"BadCode": {"type": "vyper", "code": external_contract}}, ) assert bad_c.ok() == 1 - assert bad_c.should_fail() == -(2 ** 255) + assert bad_c.should_fail() == -(2**255) assert c.test_ok() == 1 assert_tx_failed(lambda: c.test_fail()) diff --git a/tests/parser/functions/test_minmax.py b/tests/parser/functions/test_minmax.py index 5c43886a08..da939d605a 100644 --- a/tests/parser/functions/test_minmax.py +++ b/tests/parser/functions/test_minmax.py @@ -104,11 +104,11 @@ def both_literals() -> uint256: return max(2 ** 200, 2) """ c = get_contract_with_gas_estimation(code) - assert c.foo() == 2 ** 200 + 5 - assert c.goo() == 2 ** 200 + 5 + assert c.foo() == 2**200 + 5 + assert c.goo() == 2**200 + 5 assert c.bar() == 5 + 5 assert c.baz() == 5 + 5 - assert c.both_literals() == 2 ** 200 + assert c.both_literals() == 2**200 def test_min_var_uint256_literal_int128(get_contract_with_gas_estimation): @@ -241,8 +241,8 @@ def foo4() -> uint256: c = get_contract_with_gas_estimation(code) assert c.foo1() == 0 assert c.foo2() == 0 - assert c.foo3() == 2 ** 255 - assert c.foo4() == 2 ** 255 + assert c.foo3() == 2**255 + assert c.foo4() == 2**255 def test_signed(get_contract_with_gas_estimation): @@ -265,7 +265,7 @@ def foo4() -> int128: """ c = get_contract_with_gas_estimation(code) - assert c.foo1() == -(2 ** 127) - assert c.foo2() == -(2 ** 127) - assert c.foo3() == 2 ** 127 - 1 - assert c.foo4() == 2 ** 127 - 1 + assert c.foo1() == -(2**127) + assert c.foo2() == -(2**127) + assert c.foo3() == 2**127 - 1 + assert c.foo4() == 2**127 - 1 diff --git a/tests/parser/functions/test_mkstr.py b/tests/parser/functions/test_mkstr.py index c3b998664d..9d2b7fe3f5 100644 --- a/tests/parser/functions/test_mkstr.py +++ b/tests/parser/functions/test_mkstr.py @@ -15,7 +15,7 @@ def foo(inp: uint{bits}) -> String[{n_digits}]: """ c = get_contract_with_gas_estimation(code) - for i in [1, 2, 2 ** bits - 1, 0]: + for i in [1, 2, 2**bits - 1, 0]: assert c.foo(i) == str(i), (i, c.foo(i)) @@ -36,4 +36,4 @@ def foo(x: uint{bits}) -> uint256: return y """ c = get_contract(code) - assert c.foo(2 ** bits - 1) == 0, bits + assert c.foo(2**bits - 1) == 0, bits diff --git a/tests/parser/functions/test_raw_call.py b/tests/parser/functions/test_raw_call.py index cef5bf5682..b9d1f92cd4 100644 --- a/tests/parser/functions/test_raw_call.py +++ b/tests/parser/functions/test_raw_call.py @@ -205,7 +205,6 @@ def foo_call(_addr: address): def test_static_call(get_contract): - target_source = """ @external @view @@ -262,7 +261,6 @@ def __default__(): def test_static_call_fails_nonpayable(get_contract, assert_tx_failed): - target_source = """ baz: int128 @@ -292,7 +290,6 @@ def foo(_addr: address) -> int128: def test_checkable_raw_call(get_contract, assert_tx_failed): - target_source = """ baz: int128 @external diff --git a/tests/parser/functions/test_slice.py b/tests/parser/functions/test_slice.py index b47e118e41..11d834bf42 100644 --- a/tests/parser/functions/test_slice.py +++ b/tests/parser/functions/test_slice.py @@ -165,12 +165,12 @@ def foo(x: uint256, y: uint256) -> (uint256, String[12]): return dont_clobber_me, self.bytez """ c = get_contract(code) - assert c.foo(0, 12) == [2 ** 256 - 1, "hello, world"] - assert c.foo(12, 0) == [2 ** 256 - 1, ""] - assert c.foo(7, 5) == [2 ** 256 - 1, "world"] - assert c.foo(0, 5) == [2 ** 256 - 1, "hello"] - assert c.foo(0, 1) == [2 ** 256 - 1, "h"] - assert c.foo(11, 1) == [2 ** 256 - 1, "d"] + assert c.foo(0, 12) == [2**256 - 1, "hello, world"] + assert c.foo(12, 0) == [2**256 - 1, ""] + assert c.foo(7, 5) == [2**256 - 1, "world"] + assert c.foo(0, 5) == [2**256 - 1, "hello"] + assert c.foo(0, 1) == [2**256 - 1, "h"] + assert c.foo(11, 1) == [2**256 - 1, "d"] def test_slice_storage_bytes32(get_contract): @@ -326,7 +326,6 @@ def bar() -> Bytes[32]: @pytest.mark.parametrize("code", code_bytes32) @pytest.mark.parametrize("start,length", _fun_bytes32_bounds) def test_slice_bytes32(get_contract, code, start, length): - c = get_contract(code.format(start=start, length=length)) assert c.bar() == _generate_bytes(32)[start : start + length] @@ -350,7 +349,6 @@ def bar(foo: bytes32) -> Bytes[32]: @pytest.mark.parametrize("code", code_bytes32_calldata) @pytest.mark.parametrize("start,length", _fun_bytes32_bounds) def test_slice_bytes32_calldata(get_contract, code, start, length): - c = get_contract(code.format(start=start, length=length)) assert c.bar(_generate_bytes(32)) == _generate_bytes(32)[start : start + length] @@ -393,7 +391,6 @@ def bar(a: uint256, foo: bytes32, b: uint256) -> Bytes[32]: @pytest.mark.parametrize("code,result", code_bytes32_calldata_extended) def test_slice_bytes32_calldata_extended(get_contract, code, result): - c = get_contract(code) assert ( c.bar(3, "0x0001020304050607080910111213141516171819202122232425262728293031", 5).hex() diff --git a/tests/parser/functions/test_tx.py b/tests/parser/functions/test_tx.py index ebec7ccdc7..3bc6ce2eff 100644 --- a/tests/parser/functions/test_tx.py +++ b/tests/parser/functions/test_tx.py @@ -6,4 +6,4 @@ def tx_gasprice() -> uint256: """ c = get_contract(code) for i in range(10): - assert c.tx_gasprice(call={"gasPrice": 10 ** i}) == 10 ** i + assert c.tx_gasprice(call={"gasPrice": 10**i}) == 10**i diff --git a/tests/parser/functions/test_unary.py b/tests/parser/functions/test_unary.py index 05c76629af..da3823edfe 100644 --- a/tests/parser/functions/test_unary.py +++ b/tests/parser/functions/test_unary.py @@ -20,10 +20,10 @@ def negate(a: int128) -> int128: """ c = get_contract(code) # This test should revert on overflow condition - assert_tx_failed(lambda: c.negate(-(2 ** 127))) + assert_tx_failed(lambda: c.negate(-(2**127))) -@pytest.mark.parametrize("val", [-(2 ** 127) + 1, 0, 2 ** 127 - 1]) +@pytest.mark.parametrize("val", [-(2**127) + 1, 0, 2**127 - 1]) def test_unary_sub_int128_pass(get_contract, val): code = """@external def negate(a: int128) -> int128: @@ -33,8 +33,8 @@ def negate(a: int128) -> int128: assert c.negate(val) == -val -min_decimal = -(2 ** 127) + 1 -max_decimal = 2 ** 127 - 1 +min_decimal = -(2**127) + 1 +max_decimal = 2**127 - 1 @pytest.mark.parametrize("val", [min_decimal, 0, max_decimal]) @@ -79,5 +79,5 @@ def bar() -> int128: return -(a+1) """ c = get_contract(code) - assert c.foo() == -(2 ** 127) - assert c.bar() == 2 ** 127 - 1 + assert c.foo() == -(2**127) + assert c.bar() == 2**127 - 1 diff --git a/tests/parser/functions/test_unsafe_math.py b/tests/parser/functions/test_unsafe_math.py index 84acdeefd7..da44000759 100644 --- a/tests/parser/functions/test_unsafe_math.py +++ b/tests/parser/functions/test_unsafe_math.py @@ -39,14 +39,14 @@ def foo(x: {typ}) -> {typ}: xs = [random.randrange(lo, hi) for _ in range(NUM_CASES)] ys = [random.randrange(lo, hi) for _ in range(NUM_CASES)] - mod_bound = 2 ** typ.bits + mod_bound = 2**typ.bits # poor man's fuzzing - hypothesis doesn't make it easy # with the parametrized strategy if typ.is_signed: xs += [lo, lo + 1, -1, 0, 1, hi - 1, hi] ys += [lo, lo + 1, -1, 0, 1, hi - 1, hi] - for (x, y) in itertools.product(xs, ys): + for x, y in itertools.product(xs, ys): expected = unsigned_to_signed(fn(x, y) % mod_bound, typ.bits) assert c1.foo(x, y) == expected @@ -60,7 +60,7 @@ def foo(x: {typ}) -> {typ}: fixed_pt = 2 ** (typ.bits - 1) xs += [0, 1, hi - 1, hi, fixed_pt] ys += [0, 1, hi - 1, hi, fixed_pt] - for (x, y) in itertools.product(xs, ys): + for x, y in itertools.product(xs, ys): expected = fn(x, y) % mod_bound assert c1.foo(x, y) == expected diff --git a/tests/parser/syntax/test_abi_encode.py b/tests/parser/syntax/test_abi_encode.py index 8e8a694070..37d15e7e56 100644 --- a/tests/parser/syntax/test_abi_encode.py +++ b/tests/parser/syntax/test_abi_encode.py @@ -51,7 +51,6 @@ def foo(x: uint256) -> Bytes[36]: @pytest.mark.parametrize("bad_code,exc", fail_list) def test_abi_encode_fail(bad_code, exc): - with pytest.raises(exc): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_as_uint256.py b/tests/parser/syntax/test_as_uint256.py index f76bdb751a..577cb69d33 100644 --- a/tests/parser/syntax/test_as_uint256.py +++ b/tests/parser/syntax/test_as_uint256.py @@ -37,6 +37,5 @@ def test(): @pytest.mark.parametrize("bad_code,exc", fail_list) def test_as_uint256_fail(bad_code, exc): - with pytest.raises(exc): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_block.py b/tests/parser/syntax/test_block.py index 07ee28816b..1e6bfcf0e2 100644 --- a/tests/parser/syntax/test_block.py +++ b/tests/parser/syntax/test_block.py @@ -85,7 +85,6 @@ def foo() -> int128: @pytest.mark.parametrize("bad_code", fail_list) def test_block_fail(bad_code): - if isinstance(bad_code, tuple): with raises(bad_code[1]): compiler.compile_code(bad_code[0]) diff --git a/tests/parser/syntax/test_blockscope.py b/tests/parser/syntax/test_blockscope.py index 7a70649a6e..942aa3fa68 100644 --- a/tests/parser/syntax/test_blockscope.py +++ b/tests/parser/syntax/test_blockscope.py @@ -50,7 +50,6 @@ def foo(choice: bool): @pytest.mark.parametrize("bad_code", fail_list) def test_fail_undeclared(bad_code): - with raises(UndeclaredDefinition): compiler.compile_code(bad_code) @@ -67,7 +66,6 @@ def foo(): @pytest.mark.parametrize("bad_code", fail_list_collision) def test_fail_collision(bad_code): - with raises(NamespaceCollision): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_bool.py b/tests/parser/syntax/test_bool.py index 91c60f1326..09f799d91c 100644 --- a/tests/parser/syntax/test_bool.py +++ b/tests/parser/syntax/test_bool.py @@ -77,7 +77,6 @@ def test(a: address) -> bool: @pytest.mark.parametrize("bad_code", fail_list) def test_bool_fail(bad_code): - if isinstance(bad_code, tuple): with raises(bad_code[1]): compiler.compile_code(bad_code[0]) diff --git a/tests/parser/syntax/test_chainid.py b/tests/parser/syntax/test_chainid.py index a418d54dbd..eb2ed36325 100644 --- a/tests/parser/syntax/test_chainid.py +++ b/tests/parser/syntax/test_chainid.py @@ -69,7 +69,6 @@ def foo(inp: Bytes[10]) -> Bytes[3]: @pytest.mark.parametrize("bad_code", fail_list) def test_chain_fail(bad_code): - if isinstance(bad_code, tuple): with pytest.raises(bad_code[1]): compiler.compile_code(bad_code[0], evm_version="istanbul") diff --git a/tests/parser/syntax/test_code_size.py b/tests/parser/syntax/test_code_size.py index 197468a57b..bc5511fafb 100644 --- a/tests/parser/syntax/test_code_size.py +++ b/tests/parser/syntax/test_code_size.py @@ -15,7 +15,6 @@ def foo() -> int128: @pytest.mark.parametrize("bad_code", fail_list) def test_block_fail(bad_code): - with pytest.raises(StructureException): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_concat.py b/tests/parser/syntax/test_concat.py index 0f4ce0a03c..e128e7c6ae 100644 --- a/tests/parser/syntax/test_concat.py +++ b/tests/parser/syntax/test_concat.py @@ -90,7 +90,6 @@ def large_output(a: String[33], b: String[33], reverse=True) -> String[64]: @pytest.mark.parametrize("bad_code,exc", fail_list) def test_block_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code, exc): - assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc) diff --git a/tests/parser/syntax/test_extract32.py b/tests/parser/syntax/test_extract32.py index a0de52c8ae..b04c8b8742 100644 --- a/tests/parser/syntax/test_extract32.py +++ b/tests/parser/syntax/test_extract32.py @@ -49,7 +49,6 @@ def foo(inp: Bytes[32]) -> bool: @pytest.mark.parametrize("bad_code,exc", fail_list) def test_extract32_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code, exc): - assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc) diff --git a/tests/parser/syntax/test_functions_call.py b/tests/parser/syntax/test_functions_call.py index 9aa836f22e..a1a23b6bc2 100644 --- a/tests/parser/syntax/test_functions_call.py +++ b/tests/parser/syntax/test_functions_call.py @@ -41,7 +41,6 @@ def burn(_value: uint256): @pytest.mark.parametrize("bad_code,exc", fail_list) def test_functions_call_fail(bad_code, exc): - with pytest.raises(exc): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_len.py b/tests/parser/syntax/test_len.py index aedbde6847..bbde7e4897 100644 --- a/tests/parser/syntax/test_len.py +++ b/tests/parser/syntax/test_len.py @@ -20,7 +20,6 @@ def foo(inp: int128) -> uint256: @pytest.mark.parametrize("bad_code", fail_list) def test_block_fail(bad_code): - if isinstance(bad_code, tuple): with raises(bad_code[1]): compiler.compile_code(bad_code[0]) diff --git a/tests/parser/syntax/test_list.py b/tests/parser/syntax/test_list.py index bd29b40d7c..6d941fa2df 100644 --- a/tests/parser/syntax/test_list.py +++ b/tests/parser/syntax/test_list.py @@ -231,7 +231,6 @@ def foo(x: int128[2][2]): @pytest.mark.parametrize("bad_code,exc", fail_list) def test_block_fail(bad_code, exc): - with pytest.raises(exc): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_logging.py b/tests/parser/syntax/test_logging.py index cf20c099d5..39573642c0 100644 --- a/tests/parser/syntax/test_logging.py +++ b/tests/parser/syntax/test_logging.py @@ -39,7 +39,6 @@ def test(): @pytest.mark.parametrize("bad_code", fail_list) def test_logging_fail(bad_code): - if isinstance(bad_code, tuple): with pytest.raises(bad_code[1]): compiler.compile_code(bad_code[0]) diff --git a/tests/parser/syntax/test_minmax_value.py b/tests/parser/syntax/test_minmax_value.py index f71dc92e40..e154cad23f 100644 --- a/tests/parser/syntax/test_minmax_value.py +++ b/tests/parser/syntax/test_minmax_value.py @@ -18,5 +18,4 @@ def foo(): @pytest.mark.parametrize("bad_code", fail_list) def test_block_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code): - assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), InvalidType) diff --git a/tests/parser/syntax/test_msg_data.py b/tests/parser/syntax/test_msg_data.py index a05184ff11..598b990bfc 100644 --- a/tests/parser/syntax/test_msg_data.py +++ b/tests/parser/syntax/test_msg_data.py @@ -48,7 +48,7 @@ def foo(bar: uint256) -> Bytes[36]: assert contract.foo(42).hex() == expected_result -@pytest.mark.parametrize("bar", [0, 1, 42, 2 ** 256 - 1]) +@pytest.mark.parametrize("bar", [0, 1, 42, 2**256 - 1]) def test_calldata_private(get_contract, bar): code = """ @external @@ -73,7 +73,7 @@ def foo() -> (uint256, Bytes[4], uint256): """ contract = get_contract(code) - assert contract.foo() == [2 ** 256 - 1, bytes(keccak(text="foo()")[:4]), 2 ** 256 - 1] + assert contract.foo() == [2**256 - 1, bytes(keccak(text="foo()")[:4]), 2**256 - 1] def test_assignment_to_storage(w3, get_contract, keccak): diff --git a/tests/parser/syntax/test_raw_call.py b/tests/parser/syntax/test_raw_call.py index dee1d1d50b..b1286e7a8e 100644 --- a/tests/parser/syntax/test_raw_call.py +++ b/tests/parser/syntax/test_raw_call.py @@ -38,7 +38,6 @@ def foo(): @pytest.mark.parametrize("bad_code,exc", fail_list) def test_raw_call_fail(bad_code, exc): - with pytest.raises(exc): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_return_tuple.py b/tests/parser/syntax/test_return_tuple.py index 6fa373f988..8ad2e37172 100644 --- a/tests/parser/syntax/test_return_tuple.py +++ b/tests/parser/syntax/test_return_tuple.py @@ -16,7 +16,6 @@ def unmatched_tupl_length() -> (Bytes[8], int128, Bytes[8]): @pytest.mark.parametrize("bad_code", fail_list) def test_tuple_return_fail(bad_code): - with pytest.raises(FunctionDeclarationException): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_selfdestruct.py b/tests/parser/syntax/test_selfdestruct.py index bd5b83ef99..8f80a56ce1 100644 --- a/tests/parser/syntax/test_selfdestruct.py +++ b/tests/parser/syntax/test_selfdestruct.py @@ -14,7 +14,6 @@ def foo(): @pytest.mark.parametrize("bad_code", fail_list) def test_block_fail(bad_code): - with pytest.raises(InvalidType): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_slice.py b/tests/parser/syntax/test_slice.py index 80bdbe9da2..8fe162fc2b 100644 --- a/tests/parser/syntax/test_slice.py +++ b/tests/parser/syntax/test_slice.py @@ -33,7 +33,6 @@ def foo(inp: Bytes[10]) -> Bytes[3]: @pytest.mark.parametrize("bad_code,exc", fail_list) def test_slice_fail(bad_code, exc): - with pytest.raises(exc): compiler.compile_code(bad_code) diff --git a/tests/parser/types/numbers/test_constants.py b/tests/parser/types/numbers/test_constants.py index ea56968d14..0d5e386dad 100644 --- a/tests/parser/types/numbers/test_constants.py +++ b/tests/parser/types/numbers/test_constants.py @@ -48,8 +48,8 @@ def test_arithmetic(a: int128) -> int128: assert c.test_zaddress("0x0000000000000000000000000000000000000000") is True assert c.test_zaddress("0x0000000000000000000000000000000000000012") is False - assert c.test_int128(2 ** 127 - 1) == [True, False] - assert c.test_int128(-(2 ** 127)) == [False, True] + assert c.test_int128(2**127 - 1) == [True, False] + assert c.test_int128(-(2**127)) == [False, True] assert c.test_int128(0) == [False, False] assert c.test_decimal(Decimal("18707220957835557353007165858768422651595.9365500927")) == [ @@ -62,9 +62,9 @@ def test_arithmetic(a: int128) -> int128: ] assert c.test_decimal(Decimal("0.1")) == [False, False] - assert c.test_uint256(2 ** 256 - 1) is True + assert c.test_uint256(2**256 - 1) is True - assert c.test_arithmetic(5000) == 2 ** 127 - 1 - 5000 + assert c.test_arithmetic(5000) == 2**127 - 1 - 5000 def test_builtin_constants_assignment(get_contract_with_gas_estimation): @@ -107,17 +107,17 @@ def zoo() -> uint256: c = get_contract_with_gas_estimation(code) - assert c.foo() == 2 ** 127 - 1 - assert c.goo() == -(2 ** 127) + assert c.foo() == 2**127 - 1 + assert c.goo() == -(2**127) assert c.hoo() == b"\x00" * 32 assert c.joo() is None - assert c.koo() == Decimal(2 ** 167 - 1) / 10 ** 10 - assert c.loo() == Decimal(-(2 ** 167)) / 10 ** 10 + assert c.koo() == Decimal(2**167 - 1) / 10**10 + assert c.loo() == Decimal(-(2**167)) / 10**10 - assert c.zoo() == 2 ** 256 - 1 + assert c.zoo() == 2**256 - 1 def test_custom_constants(get_contract): @@ -208,7 +208,7 @@ def test() -> uint256: ir = compile_code(code, ["ir"])["ir"] assert search_for_sublist( - ir, ["mstore", [MemoryPositions.RESERVED_MEMORY], [2 ** 12 * some_prime]] + ir, ["mstore", [MemoryPositions.RESERVED_MEMORY], [2**12 * some_prime]] ) diff --git a/tests/parser/types/numbers/test_isqrt.py b/tests/parser/types/numbers/test_isqrt.py index a8b0f79def..ce26d24d06 100644 --- a/tests/parser/types/numbers/test_isqrt.py +++ b/tests/parser/types/numbers/test_isqrt.py @@ -40,7 +40,7 @@ def test(a: uint256) -> uint256: val = 3333 assert c.test(val) == math.isqrt(val) - val = 10 ** 17 + val = 10**17 assert c.test(val) == math.isqrt(val) assert c.test(0) == 0 @@ -75,7 +75,6 @@ def test(a: uint256) -> uint256: def test_isqrt_storage_internal_variable(get_contract_with_gas_estimation): - val = 44444 code = f""" s_var: uint256 diff --git a/tests/parser/types/numbers/test_signed_ints.py b/tests/parser/types/numbers/test_signed_ints.py index 2e062c78b4..281aab429c 100644 --- a/tests/parser/types/numbers/test_signed_ints.py +++ b/tests/parser/types/numbers/test_signed_ints.py @@ -86,7 +86,7 @@ def foo() -> int16: return y """ c = get_contract(code) - assert c.foo() == -(2 ** 15) + assert c.foo() == -(2**15) @pytest.mark.parametrize("base,power", itertools.product((-2, -1, 0, 1, 2), (0, 1))) @@ -99,7 +99,7 @@ def foo() -> int256: return x ** {power} """ c = get_contract(code) - assert c.foo() == base ** power + assert c.foo() == base**power @pytest.mark.parametrize("typ", types) @@ -118,7 +118,7 @@ def foo(x: {typ}) -> {typ}: if x * 2 >= typ.bits or x < 0: # out of bounds assert_tx_failed(lambda: c.foo(x)) else: - assert c.foo(x) == 4 ** x + assert c.foo(x) == 4**x @pytest.mark.parametrize("typ", types) @@ -285,7 +285,7 @@ def foo() -> {typ}: # edge cases that are tricky to reason about and MUST be tested assert lo in xs and -1 in ys - for (x, y) in itertools.product(xs, ys): + for x, y in itertools.product(xs, ys): expected = fn(x, y) in_bounds = lo <= expected <= hi diff --git a/tests/parser/types/numbers/test_unsigned_ints.py b/tests/parser/types/numbers/test_unsigned_ints.py index 41be4909b0..97a4097923 100644 --- a/tests/parser/types/numbers/test_unsigned_ints.py +++ b/tests/parser/types/numbers/test_unsigned_ints.py @@ -127,9 +127,9 @@ def foo() -> {typ}: ys += [random.randrange(lo, hi) for _ in range(NUM_CASES)] # mirror signed integer tests - assert 2 ** (bits - 1) in xs and (2 ** bits) - 1 in ys + assert 2 ** (bits - 1) in xs and (2**bits) - 1 in ys - for (x, y) in itertools.product(xs, ys): + for x, y in itertools.product(xs, ys): expected = fn(x, y) in_bounds = lo <= expected <= hi @@ -211,13 +211,13 @@ def _uint256_mulmod(x: uint256, y: uint256, z: uint256) -> uint256: assert c._uint256_addmod(1, 2, 2) == 1 assert c._uint256_addmod(32, 2, 32) == 2 - assert c._uint256_addmod((2 ** 256) - 1, 0, 2) == 1 - assert c._uint256_addmod(2 ** 255, 2 ** 255, 6) == 4 + assert c._uint256_addmod((2**256) - 1, 0, 2) == 1 + assert c._uint256_addmod(2**255, 2**255, 6) == 4 assert_tx_failed(lambda: c._uint256_addmod(1, 2, 0)) assert c._uint256_mulmod(3, 1, 2) == 1 assert c._uint256_mulmod(200, 3, 601) == 600 - assert c._uint256_mulmod(2 ** 255, 1, 3) == 2 - assert c._uint256_mulmod(2 ** 255, 2, 6) == 4 + assert c._uint256_mulmod(2**255, 1, 3) == 2 + assert c._uint256_mulmod(2**255, 2, 6) == 4 assert_tx_failed(lambda: c._uint256_mulmod(2, 2, 0)) diff --git a/tests/parser/types/test_bytes.py b/tests/parser/types/test_bytes.py index b3721af2f0..555412a687 100644 --- a/tests/parser/types/test_bytes.py +++ b/tests/parser/types/test_bytes.py @@ -198,7 +198,7 @@ def testsome_storage(y: Bytes[1]) -> bool: assert c.getsome() == b"\x0e" assert c.testsome(b"a") assert c.testsome(b"\x61") - assert c.testsome(0b1100001 .to_bytes(1, "big")) + assert c.testsome(0b1100001.to_bytes(1, "big")) assert not c.testsome(b"b") assert c.testsome_storage(b"a") assert not c.testsome_storage(b"x") diff --git a/tests/parser/types/test_bytes_zero_padding.py b/tests/parser/types/test_bytes_zero_padding.py index db9eddb615..9bc774f12f 100644 --- a/tests/parser/types/test_bytes_zero_padding.py +++ b/tests/parser/types/test_bytes_zero_padding.py @@ -26,7 +26,7 @@ def get_count(counter: uint256) -> Bytes[24]: @pytest.mark.fuzzing -@hypothesis.given(value=hypothesis.strategies.integers(min_value=0, max_value=2 ** 64)) +@hypothesis.given(value=hypothesis.strategies.integers(min_value=0, max_value=2**64)) @hypothesis.settings(deadline=400) def test_zero_pad_range(little_endian_contract, value): actual_bytes = value.to_bytes(8, byteorder="little") diff --git a/tests/parser/types/test_dynamic_array.py b/tests/parser/types/test_dynamic_array.py index 4c83133f05..04c0688245 100644 --- a/tests/parser/types/test_dynamic_array.py +++ b/tests/parser/types/test_dynamic_array.py @@ -1093,7 +1093,7 @@ def foo() -> DynArray[{subtyp}, 3]: assert c.foo() == data -@pytest.mark.parametrize("subtyp,lit", [("uint8", 256), ("uint256", -1), ("int128", 2 ** 127)]) +@pytest.mark.parametrize("subtyp,lit", [("uint8", 256), ("uint256", -1), ("int128", 2**127)]) def test_append_invalid_literal(get_contract, assert_compile_failed, subtyp, lit): code = f""" @external @@ -1689,6 +1689,7 @@ def foo() -> {typ}: # TODO test negative public(DynArray) cases? + # CMC 2022-08-04 these are blocked due to typechecker bug; leaving as # negative tests so we know if/when the typechecker is fixed. # (don't consider it a high priority to fix since membership in diff --git a/tests/parser/types/test_enum.py b/tests/parser/types/test_enum.py index 201d1ba9d0..c66efff566 100644 --- a/tests/parser/types/test_enum.py +++ b/tests/parser/types/test_enum.py @@ -67,11 +67,11 @@ def is_not_boss(a: Roles) -> bool: c = get_contract(code) for i in range(4): - assert c.is_boss(2 ** i) is False - assert c.is_not_boss(2 ** i) is True + assert c.is_boss(2**i) is False + assert c.is_not_boss(2**i) is True - assert c.is_boss(2 ** 4) is True - assert c.is_not_boss(2 ** 4) is False + assert c.is_boss(2**4) is True + assert c.is_not_boss(2**4) is False def test_bitwise(get_contract, assert_tx_failed): diff --git a/tests/parser/types/test_lists.py b/tests/parser/types/test_lists.py index fc17945167..0715eb3870 100644 --- a/tests/parser/types/test_lists.py +++ b/tests/parser/types/test_lists.py @@ -652,12 +652,12 @@ def foo(x: Bar[2][2][2]) -> uint256: [ ("decimal", [5.0, 11.0, 17.0, 29.0, 37.0, 41.0]), ("uint8", [0, 1, 17, 250, 255, 2]), - ("int128", [0, -1, 1, -(2 ** 127), 2 ** 127 - 1, -50]), - ("int256", [0, -1, 1, -(2 ** 255), 2 ** 255 - 1, -50]), - ("uint256", [0, 1, 2 ** 8, 2 ** 255 + 1, 2 ** 256 - 1, 100]), + ("int128", [0, -1, 1, -(2**127), 2**127 - 1, -50]), + ("int256", [0, -1, 1, -(2**255), 2**255 - 1, -50]), + ("uint256", [0, 1, 2**8, 2**255 + 1, 2**256 - 1, 100]), ( "uint256", - [2 ** 255 + 1, 2 ** 255 + 2, 2 ** 255 + 3, 2 ** 255 + 4, 2 ** 255 + 5, 2 ** 255 + 6], + [2**255 + 1, 2**255 + 2, 2**255 + 3, 2**255 + 4, 2**255 + 5, 2**255 + 6], ), ("bool", [True, False, True, False, True, False]), ], @@ -750,15 +750,15 @@ def ix(i: uint256) -> address: [ ("decimal", [[5.0, 11.0], [17.0, 29.0], [37.0, 41.0]]), ("uint8", [[0, 1], [17, 250], [255, 2]]), - ("int128", [[0, -1], [1, -(2 ** 127)], [2 ** 127 - 1, -50]]), - ("int256", [[0, -1], [1, -(2 ** 255)], [2 ** 255 - 1, -50]]), - ("uint256", [[0, 1], [2 ** 8, 2 ** 255 + 1], [2 ** 256 - 1, 100]]), + ("int128", [[0, -1], [1, -(2**127)], [2**127 - 1, -50]]), + ("int256", [[0, -1], [1, -(2**255)], [2**255 - 1, -50]]), + ("uint256", [[0, 1], [2**8, 2**255 + 1], [2**256 - 1, 100]]), ( "uint256", [ - [2 ** 255 + 1, 2 ** 255 + 2], - [2 ** 255 + 3, 2 ** 255 + 4], - [2 ** 255 + 5, 2 ** 255 + 6], + [2**255 + 1, 2**255 + 2], + [2**255 + 3, 2**255 + 4], + [2**255 + 5, 2**255 + 6], ], ), ("bool", [[True, False], [True, False], [True, False]]), diff --git a/tests/parser/types/test_node_types.py b/tests/parser/types/test_node_types.py index 8689d51f8f..b6561ae8eb 100644 --- a/tests/parser/types/test_node_types.py +++ b/tests/parser/types/test_node_types.py @@ -15,7 +15,6 @@ def test_bytearray_node_type(): - node1 = BytesT(12) node2 = BytesT(12) diff --git a/tests/parser/types/test_string.py b/tests/parser/types/test_string.py index 560449a504..9193c5f69d 100644 --- a/tests/parser/types/test_string.py +++ b/tests/parser/types/test_string.py @@ -56,7 +56,7 @@ def get(k: String[34]) -> int128: c = get_contract(code) - c.set(b"a" * 34, 6789, transact={"gas": 10 ** 6}) + c.set(b"a" * 34, 6789, transact={"gas": 10**6}) assert c.get(b"a" * 34) == 6789 @@ -152,7 +152,6 @@ def test(addr: address) -> (int128, address, String[10]): def test_default_arg_string(get_contract_with_gas_estimation): - code = """ @external def test(a: uint256, b: String[50] = "foo") -> Bytes[100]: diff --git a/tests/parser/types/value/test_as_wei_value.py b/tests/parser/types/value/test_as_wei_value.py index 3fef80a967..249ac4b2ff 100644 --- a/tests/parser/types/value/test_as_wei_value.py +++ b/tests/parser/types/value/test_as_wei_value.py @@ -32,10 +32,10 @@ def foo(a: uint256) -> uint256: c = get_contract(code) - value = (2 ** 256 - 1) // (10 ** multiplier) - assert c.foo(value) == value * (10 ** multiplier) + value = (2**256 - 1) // (10**multiplier) + assert c.foo(value) == value * (10**multiplier) - value = (2 ** 256 - 1) // (10 ** (multiplier - 1)) + value = (2**256 - 1) // (10 ** (multiplier - 1)) assert_tx_failed(lambda: c.foo(value)) @@ -48,9 +48,9 @@ def foo(a: int128) -> uint256: """ c = get_contract(code) - value = (2 ** 127 - 1) // (10 ** multiplier) + value = (2**127 - 1) // (10**multiplier) - assert c.foo(value) == value * (10 ** multiplier) + assert c.foo(value) == value * (10**multiplier) @pytest.mark.parametrize("denom,multiplier", wei_denoms.items()) @@ -62,12 +62,12 @@ def foo(a: decimal) -> uint256: """ c = get_contract(code) - value = Decimal((2 ** 127 - 1) / (10 ** multiplier)) + value = Decimal((2**127 - 1) / (10**multiplier)) - assert c.foo(value) == value * (10 ** multiplier) + assert c.foo(value) == value * (10**multiplier) -@pytest.mark.parametrize("value", (-1, -(2 ** 127))) +@pytest.mark.parametrize("value", (-1, -(2**127))) @pytest.mark.parametrize("data_type", ["decimal", "int128"]) def test_negative_value_reverts(get_contract, assert_tx_failed, value, data_type): code = f""" From 3c870c6adf67322e1c815aa24050a6a4ba8a4f1c Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Wed, 29 Mar 2023 11:57:36 +0800 Subject: [PATCH 07/14] fix flake8 lint --- vyper/codegen/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vyper/codegen/core.py b/vyper/codegen/core.py index ca161ddb8d..12004ec4a7 100644 --- a/vyper/codegen/core.py +++ b/vyper/codegen/core.py @@ -746,9 +746,9 @@ def FAIL(): # pragma: no cover else: if len(left.typ.member_types) != len(right.typ.member_types): FAIL() # pragma: notest - for l, r in zip(left.typ.member_types, right.typ.member_types): + for l_, r_ in zip(left.typ.member_types, right.typ.member_types): # TODO recurse into left, right if literals? - check_assign(dummy_node_for_type(l), dummy_node_for_type(r)) + check_assign(dummy_node_for_type(l_), dummy_node_for_type(r_)) # sanity check an assignment From e1dd29424ed60ef607eb19620c3249e5b1ede081 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Wed, 29 Mar 2023 12:04:06 +0800 Subject: [PATCH 08/14] update docs yaml --- .readthedocs.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 7bcb51e797..8fd6bd1c87 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -2,6 +2,11 @@ version: 2 +# Set the version of Python and other tools you might need +build: + tools: + python: "3.10" + # Build from the docs/ directory with Sphinx sphinx: configuration: docs/conf.py @@ -9,8 +14,7 @@ sphinx: formats: all -# Explicitly set the version of Python and its requirements +# Optionally declare the Python requirements required to build your docs python: - version: 3.10 install: - requirements: requirements-docs.txt From a2370a4f89263bfefcdb2a75d2eb85d692ea9e2c Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Wed, 29 Mar 2023 12:08:04 +0800 Subject: [PATCH 09/14] fix docs yaml --- .readthedocs.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 8fd6bd1c87..1ad9000f53 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -4,6 +4,9 @@ version: 2 # Set the version of Python and other tools you might need build: + # TODO: update to `latest` once supported + # https://github.com/readthedocs/readthedocs.org/issues/8861 + os: ubuntu-22.04 tools: python: "3.10" From f2f0c7eaddd177bafe107b401981511bda1054c5 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Thu, 30 Mar 2023 04:25:37 +0800 Subject: [PATCH 10/14] pin black to earlier version for power operator --- setup.py | 2 +- vyper/ast/folding.py | 6 ++-- vyper/ast/nodes.py | 4 +-- vyper/ast/validation.py | 2 +- vyper/builtins/_convert.py | 4 +-- vyper/builtins/functions.py | 38 +++++++++++----------- vyper/codegen/arithmetic.py | 26 +++++++-------- vyper/codegen/expr.py | 4 +-- vyper/codegen/ir_node.py | 2 +- vyper/compiler/output.py | 2 +- vyper/ir/compile_ir.py | 6 ++-- vyper/ir/optimizer.py | 4 +-- vyper/semantics/analysis/data_positions.py | 2 +- vyper/semantics/types/primitives.py | 6 ++-- vyper/semantics/types/subscriptable.py | 2 +- vyper/utils.py | 34 +++++++++---------- 16 files changed, 72 insertions(+), 72 deletions(-) diff --git a/setup.py b/setup.py index c3bb46ef72..28abb01695 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ "hypothesis[lark]>=5.37.1,<6.0", ], "lint": [ - "black==23.3.0", + "black==21.12b0", "flake8==3.9.2", "flake8-bugbear==20.1.4", "flake8-use-fstring==1.1", diff --git a/vyper/ast/folding.py b/vyper/ast/folding.py index fbd1dfc2f4..cd0fcc3c55 100644 --- a/vyper/ast/folding.py +++ b/vyper/ast/folding.py @@ -15,11 +15,11 @@ "empty(bytes32)", ), # NOQA: E501 "ZERO_ADDRESS": (vy_ast.Hex, "0x0000000000000000000000000000000000000000", "empty(address)"), - "MAX_INT128": (vy_ast.Int, 2**127 - 1, "max_value(int128)"), - "MIN_INT128": (vy_ast.Int, -(2**127), "min_value(int128)"), + "MAX_INT128": (vy_ast.Int, 2 ** 127 - 1, "max_value(int128)"), + "MIN_INT128": (vy_ast.Int, -(2 ** 127), "min_value(int128)"), "MAX_DECIMAL": (vy_ast.Decimal, SizeLimits.MAX_AST_DECIMAL, "max_value(decimal)"), "MIN_DECIMAL": (vy_ast.Decimal, SizeLimits.MIN_AST_DECIMAL, "min_value(decimal)"), - "MAX_UINT256": (vy_ast.Int, 2**256 - 1, "max_value(uint256)"), + "MAX_UINT256": (vy_ast.Int, 2 ** 256 - 1, "max_value(uint256)"), } diff --git a/vyper/ast/nodes.py b/vyper/ast/nodes.py index cbbd019337..39add6905b 100644 --- a/vyper/ast/nodes.py +++ b/vyper/ast/nodes.py @@ -939,7 +939,7 @@ class Invert(Operator): _pretty = "~" def _op(self, value): - return (2**256 - 1) ^ value + return (2 ** 256 - 1) ^ value class BinOp(ExprNode): @@ -1048,7 +1048,7 @@ def _op(self, left, right): raise TypeMismatch("Cannot perform exponentiation on decimal values.", self._parent) if right < 0: raise InvalidOperation("Cannot calculate a negative power", self._parent) - return int(left**right) + return int(left ** right) class BitAnd(Operator): diff --git a/vyper/ast/validation.py b/vyper/ast/validation.py index 7742d60c01..cd169178f6 100644 --- a/vyper/ast/validation.py +++ b/vyper/ast/validation.py @@ -45,7 +45,7 @@ def validate_call_args( # -1 is sentinel which means we have varargs. # set arg_count[1] to some large number that we # would never see in practice - arg_count = (arg_count[0], 2**64) + arg_count = (arg_count[0], 2 ** 64) if arg_count[0] == arg_count[1]: arg_count == arg_count[0] diff --git a/vyper/builtins/_convert.py b/vyper/builtins/_convert.py index 407a32f3e9..8921b9ebaa 100644 --- a/vyper/builtins/_convert.py +++ b/vyper/builtins/_convert.py @@ -109,7 +109,7 @@ def _clamp_numeric_convert(arg, arg_bounds, out_bounds, arg_is_signed): if arg_hi > out_hi: # out_hi must be smaller than MAX_UINT256, so clample makes sense. # add an assertion, just in case this assumption ever changes. - assert out_hi < 2**256 - 1, "bad assumption in numeric convert" + assert out_hi < 2 ** 256 - 1, "bad assumption in numeric convert" CLAMP_OP = "sle" if arg_is_signed else "le" arg = clamp(CLAMP_OP, arg, out_hi) @@ -357,7 +357,7 @@ def to_decimal(expr, arg, out_typ): elif arg.typ == BoolT(): # TODO: consider adding is_signed and bits to bool so we can use _int_to_fixed - arg = ["mul", arg, 10**out_typ.decimals] + arg = ["mul", arg, 10 ** out_typ.decimals] return IRnode.from_list(arg, typ=out_typ) else: raise CompilerPanic("unreachable") # pragma: notest diff --git a/vyper/builtins/functions.py b/vyper/builtins/functions.py index 6c00678d5c..626067bf5e 100644 --- a/vyper/builtins/functions.py +++ b/vyper/builtins/functions.py @@ -973,13 +973,13 @@ class AsWeiValue(BuiltinFunction): wei_denoms = { ("wei",): 1, - ("femtoether", "kwei", "babbage"): 10**3, - ("picoether", "mwei", "lovelace"): 10**6, - ("nanoether", "gwei", "shannon"): 10**9, - ("microether", "szabo"): 10**12, - ("milliether", "finney"): 10**15, - ("ether",): 10**18, - ("kether", "grand"): 10**21, + ("femtoether", "kwei", "babbage"): 10 ** 3, + ("picoether", "mwei", "lovelace"): 10 ** 6, + ("nanoether", "gwei", "shannon"): 10 ** 9, + ("microether", "szabo"): 10 ** 12, + ("milliether", "finney"): 10 ** 15, + ("ether",): 10 ** 18, + ("kether", "grand"): 10 ** 21, } def get_denomination(self, node): @@ -1007,7 +1007,7 @@ def evaluate(self, node): if value < 0: raise InvalidLiteral("Negative wei value not allowed", node.args[0]) - if isinstance(value, int) and value >= 2**256: + if isinstance(value, int) and value >= 2 ** 256: raise InvalidLiteral("Value out of range for uint256", node.args[0]) if isinstance(value, Decimal) and value > SizeLimits.MAX_AST_DECIMAL: raise InvalidLiteral("Value out of range for decimal", node.args[0]) @@ -1338,7 +1338,7 @@ def evaluate(self, node): for arg in node.args: if not isinstance(arg, vy_ast.Num): raise UnfoldableNode - if arg.value < 0 or arg.value >= 2**256: + if arg.value < 0 or arg.value >= 2 ** 256: raise InvalidLiteral("Value out of range for uint256", arg) value = node.args[0].value & node.args[1].value @@ -1364,7 +1364,7 @@ def evaluate(self, node): for arg in node.args: if not isinstance(arg, vy_ast.Num): raise UnfoldableNode - if arg.value < 0 or arg.value >= 2**256: + if arg.value < 0 or arg.value >= 2 ** 256: raise InvalidLiteral("Value out of range for uint256", arg) value = node.args[0].value | node.args[1].value @@ -1390,7 +1390,7 @@ def evaluate(self, node): for arg in node.args: if not isinstance(arg, vy_ast.Num): raise UnfoldableNode - if arg.value < 0 or arg.value >= 2**256: + if arg.value < 0 or arg.value >= 2 ** 256: raise InvalidLiteral("Value out of range for uint256", arg) value = node.args[0].value ^ node.args[1].value @@ -1417,10 +1417,10 @@ def evaluate(self, node): raise UnfoldableNode value = node.args[0].value - if value < 0 or value >= 2**256: + if value < 0 or value >= 2 ** 256: raise InvalidLiteral("Value out of range for uint256", node.args[0]) - value = (2**256 - 1) - value + value = (2 ** 256 - 1) - value return vy_ast.Int.from_node(node, value=value) @process_inputs @@ -1438,7 +1438,7 @@ def evaluate(self, node): if [i for i in node.args if not isinstance(i, vy_ast.Num)]: raise UnfoldableNode value, shift = [i.value for i in node.args] - if value < 0 or value >= 2**256: + if value < 0 or value >= 2 ** 256: raise InvalidLiteral("Value out of range for uint256", node.args[0]) if shift < -256 or shift > 256: # this validation is performed to prevent the compiler from hanging @@ -1449,7 +1449,7 @@ def evaluate(self, node): if shift < 0: value = value >> -shift else: - value = (value << shift) % (2**256) + value = (value << shift) % (2 ** 256) return vy_ast.Int.from_node(node, value=value) def fetch_call_return(self, node): @@ -1488,7 +1488,7 @@ def evaluate(self, node): for arg in node.args: if not isinstance(arg, vy_ast.Num): raise UnfoldableNode - if arg.value < 0 or arg.value >= 2**256: + if arg.value < 0 or arg.value >= 2 ** 256: raise InvalidLiteral("Value out of range for uint256", arg) value = self._eval_fn(node.args[0].value, node.args[1].value) % node.args[2].value @@ -1527,7 +1527,7 @@ def evaluate(self, node): if left.value < 0 or right.value < 0: raise UnfoldableNode - value = pow(left.value, right.value, 2**256) + value = pow(left.value, right.value, 2 ** 256) return vy_ast.Int.from_node(node, value=value) def build_IR(self, expr, context): @@ -1943,7 +1943,7 @@ def build_IR(self, expr, args, kwargs, context): else: # e.g. uint8 -> (mod (add x y) 256) # TODO mod_bound could be a really large literal - ret = ["mod", ret, 2**a.typ.bits] + ret = ["mod", ret, 2 ** a.typ.bits] return IRnode.from_list(ret, typ=otyp) @@ -2203,7 +2203,7 @@ def build_IR(self, expr, args, kwargs, context): ["seq", ["set", y, shr(16, y)], ["set", z, shl(8, z)]], ], ] - ret.append(["set", z, ["div", ["mul", z, ["add", y, 2**16]], 2**18]]) + ret.append(["set", z, ["div", ["mul", z, ["add", y, 2 ** 16]], 2 ** 18]]) for _ in range(7): ret.append(["set", z, ["div", ["add", ["div", x, z], z], 2]]) diff --git a/vyper/codegen/arithmetic.py b/vyper/codegen/arithmetic.py index 8f8a9f904b..b228a11998 100644 --- a/vyper/codegen/arithmetic.py +++ b/vyper/codegen/arithmetic.py @@ -41,9 +41,9 @@ def calculate_largest_power(a: int, num_bits: int, is_signed: bool) -> int: raise CompilerPanic("Exponential operation is useless!") value_bits = num_bits - (1 if is_signed else 0) - if a >= 2**value_bits: # pragma: no cover + if a >= 2 ** value_bits: # pragma: no cover raise TypeCheckFailure("Value is too large and will always throw") - if a < -(2**value_bits): # pragma: no cover + if a < -(2 ** value_bits): # pragma: no cover raise TypeCheckFailure("Value is too small and will always throw") a_is_negative = a < 0 @@ -65,11 +65,11 @@ def calculate_largest_power(a: int, num_bits: int, is_signed: bool) -> int: # x = ln(2**value_bits) / ln(a) num_iterations = 0 - while a ** (b + 1) < 2**value_bits: + while a ** (b + 1) < 2 ** value_bits: b += 1 num_iterations += 1 assert num_iterations < 10000 - while a**b >= 2**value_bits: + while a ** b >= 2 ** value_bits: b -= 1 num_iterations += 1 assert num_iterations < 10000 @@ -78,7 +78,7 @@ def calculate_largest_power(a: int, num_bits: int, is_signed: bool) -> int: # (-a) ** (b + 1) == -(2 ** value_bits) # we can squeak one more out of it because lower bound of signed ints # is slightly wider than upper bound - if a_is_negative and (-a) ** (b + 1) == -(2**value_bits): # NOTE: a = abs(a) + if a_is_negative and (-a) ** (b + 1) == -(2 ** value_bits): # NOTE: a = abs(a) return b + 1 else: return b # Exact @@ -132,11 +132,11 @@ def calculate_largest_base(b: int, num_bits: int, is_signed: bool) -> Tuple[int, a = math.ceil(2 ** (decimal.Decimal(value_bits) / decimal.Decimal(b))) # Do a bit of iteration to ensure we have the exact number num_iterations = 0 - while (a + 1) ** b < 2**value_bits: + while (a + 1) ** b < 2 ** value_bits: a += 1 num_iterations += 1 assert num_iterations < 10000 - while a**b >= 2**value_bits: + while a ** b >= 2 ** value_bits: a -= 1 num_iterations += 1 assert num_iterations < 10000 @@ -144,7 +144,7 @@ def calculate_largest_base(b: int, num_bits: int, is_signed: bool) -> Tuple[int, if not is_signed: return 0, a - if (a + 1) ** b == (2**value_bits): + if (a + 1) ** b == (2 ** value_bits): # edge case: lower bound is slightly wider than upper bound return -(a + 1), a else: @@ -246,7 +246,7 @@ def safe_mul(x, y): if version_check(begin="constantinople"): upper_bound = ["shl", 255, 1] else: - upper_bound = -(2**255) + upper_bound = -(2 ** 255) check_x = ["ne", x, upper_bound] check_y = ["ne", ["not", y], 0] @@ -256,7 +256,7 @@ def safe_mul(x, y): ok = ["and", ok, ["or", check_x, check_y]] # TODO push some of this constant folding into optimizer - elif x.is_literal and x.value == -(2**255): + elif x.is_literal and x.value == -(2 ** 255): ok = ["and", ok, check_y] elif y.is_literal and y.value == -1: ok = ["and", ok, check_x] @@ -290,7 +290,7 @@ def safe_div(x, y): if is_decimal_type(x.typ): lo, hi = typ.int_bounds - if max(abs(lo), abs(hi)) * typ.divisor > 2**256 - 1: + if max(abs(lo), abs(hi)) * typ.divisor > 2 ** 256 - 1: # stub to prevent us from adding fixed point numbers we don't know # how to deal with raise UnimplementedException("safe_mul for decimal{typ.bits}x{typ.decimals}") @@ -304,12 +304,12 @@ def safe_div(x, y): if version_check(begin="constantinople"): upper_bound = ["shl", 255, 1] else: - upper_bound = -(2**255) + upper_bound = -(2 ** 255) if not x.is_literal and not y.is_literal: ok = ["or", ["ne", y, ["not", 0]], ["ne", x, upper_bound]] # TODO push these rules into the optimizer - elif x.is_literal and x.value == -(2**255): + elif x.is_literal and x.value == -(2 ** 255): ok = ["ne", y, ["not", 0]] elif y.is_literal and y.value == -1: ok = ["ne", x, upper_bound] diff --git a/vyper/codegen/expr.py b/vyper/codegen/expr.py index 33c400941e..0eabf5b2a4 100644 --- a/vyper/codegen/expr.py +++ b/vyper/codegen/expr.py @@ -202,7 +202,7 @@ def parse_Attribute(self): ): # 0, 1, 2, .. 255 enum_id = typ._enum_members[self.expr.attr] - value = 2**enum_id # 0 => 0001, 1 => 0010, 2 => 0100, etc. + value = 2 ** enum_id # 0 => 0001, 1 => 0010, 2 => 0100, etc. return IRnode.from_list(value, typ=typ) # x.balance: balance of address x @@ -601,7 +601,7 @@ def parse_UnaryOp(self): # `operand`. `mask` could be a very large constant and # hurt codesize, but most user enums will likely have few # enough members that the mask will not be large. - mask = (2**n_members) - 1 + mask = (2 ** n_members) - 1 return IRnode.from_list(["xor", mask, operand], typ=operand.typ) if operand.typ == UINT256_T: diff --git a/vyper/codegen/ir_node.py b/vyper/codegen/ir_node.py index c2c127b9d5..8d5171dfb2 100644 --- a/vyper/codegen/ir_node.py +++ b/vyper/codegen/ir_node.py @@ -152,7 +152,7 @@ def _check(condition, err): _check(len(self.args) == 0, "int can't have arguments") # integers must be in the range (MIN_INT256, MAX_UINT256) - _check(-(2**255) <= self.value < 2**256, "out of range") + _check(-(2 ** 255) <= self.value < 2 ** 256, "out of range") self.valency = 1 self._gas = 5 diff --git a/vyper/compiler/output.py b/vyper/compiler/output.py index 82e583c160..d9c6d8de10 100644 --- a/vyper/compiler/output.py +++ b/vyper/compiler/output.py @@ -252,7 +252,7 @@ def build_blueprint_bytecode_output(compiler_data: CompilerData) -> str: # EIP-170. Ref: https://eips.ethereum.org/EIPS/eip-170 -EIP170_CONTRACT_SIZE_LIMIT: int = 2**14 + 2**13 +EIP170_CONTRACT_SIZE_LIMIT: int = 2 ** 14 + 2 ** 13 def build_bytecode_runtime_output(compiler_data: CompilerData) -> str: diff --git a/vyper/ir/compile_ir.py b/vyper/ir/compile_ir.py index c24b3a67a2..bc5e17fa40 100644 --- a/vyper/ir/compile_ir.py +++ b/vyper/ir/compile_ir.py @@ -256,11 +256,11 @@ def _height_of(witharg): # Numbers elif isinstance(code.value, int): - if code.value < -(2**255): + if code.value < -(2 ** 255): raise Exception(f"Value too low: {code.value}") - elif code.value >= 2**256: + elif code.value >= 2 ** 256: raise Exception(f"Value too high: {code.value}") - return PUSH(code.value % 2**256) + return PUSH(code.value % 2 ** 256) # Variables connected to with statements elif isinstance(code.value, str) and code.value in withargs: diff --git a/vyper/ir/optimizer.py b/vyper/ir/optimizer.py index f54b0e8115..4382c54eef 100644 --- a/vyper/ir/optimizer.py +++ b/vyper/ir/optimizer.py @@ -31,7 +31,7 @@ def _evm_int(node: IRnode, unsigned: bool = True) -> Optional[int]: if unsigned and ret < 0: return signed_to_unsigned(ret, 256, strict=True) - elif not unsigned and ret > 2**255 - 1: + elif not unsigned and ret > 2 ** 255 - 1: return unsigned_to_signed(ret, 256, strict=True) return ret @@ -97,7 +97,7 @@ def _shorten_annotation(annotation): def _wrap256(x, unsigned=UNSIGNED): - x %= 2**256 + x %= 2 ** 256 # wrap in a signed way. if not unsigned: x = unsigned_to_signed(x, 256, strict=True) diff --git a/vyper/semantics/analysis/data_positions.py b/vyper/semantics/analysis/data_positions.py index 5c1347d5a3..85e1436b69 100644 --- a/vyper/semantics/analysis/data_positions.py +++ b/vyper/semantics/analysis/data_positions.py @@ -53,7 +53,7 @@ def _reserve_slots(self, slots: List[int], var_name: str) -> None: self._reserve_slot(slot, var_name) def _reserve_slot(self, slot: int, var_name: str) -> None: - if slot < 0 or slot >= 2**256: + if slot < 0 or slot >= 2 ** 256: raise StorageLayoutException( f"Invalid storage slot for var {var_name}, out of bounds: {slot}" ) diff --git a/vyper/semantics/types/primitives.py b/vyper/semantics/types/primitives.py index 5b1ab5ab8e..72433fcb91 100644 --- a/vyper/semantics/types/primitives.py +++ b/vyper/semantics/types/primitives.py @@ -154,11 +154,11 @@ def validate_numeric_op( # TODO double check: this code seems duplicated with constant eval # constant folding ensures one of `(left, right)` is never a literal if isinstance(left, vy_ast.Int): - if left.value >= 2**value_bits: + if left.value >= 2 ** value_bits: raise OverflowException( "Base is too large, calculation will always overflow", left ) - elif left.value < -(2**value_bits): + elif left.value < -(2 ** value_bits): raise OverflowException( "Base is too small, calculation will always underflow", left ) @@ -284,7 +284,7 @@ def decimals(self) -> int: @cached_property def divisor(self) -> int: - return 10**self.decimals + return 10 ** self.decimals @cached_property def epsilon(self) -> Decimal: diff --git a/vyper/semantics/types/subscriptable.py b/vyper/semantics/types/subscriptable.py index fb4505fb20..f0f876a48d 100644 --- a/vyper/semantics/types/subscriptable.py +++ b/vyper/semantics/types/subscriptable.py @@ -100,7 +100,7 @@ class _SequenceT(_SubscriptableT): _is_array_type: bool = True def __init__(self, value_type: VyperType, length: int): - if not 0 < length < 2**256: + if not 0 < length < 2 ** 256: raise InvalidType("Array length is invalid") super().__init__(UINT256_T, value_type) diff --git a/vyper/utils.py b/vyper/utils.py index 2df78f1c2d..608a014f4e 100644 --- a/vyper/utils.py +++ b/vyper/utils.py @@ -45,7 +45,7 @@ def fourbytes_to_int(inp): # Converts an integer to four bytes def int_to_fourbytes(n: int) -> bytes: - assert n < 2**32 + assert n < 2 ** 32 return n.to_bytes(4, byteorder="big") @@ -60,7 +60,7 @@ def signed_to_unsigned(int_, bits, strict=False): lo, hi = int_bounds(signed=True, bits=bits) assert lo <= int_ <= hi if int_ < 0: - return int_ + 2**bits + return int_ + 2 ** bits return int_ @@ -75,7 +75,7 @@ def unsigned_to_signed(int_, bits, strict=False): lo, hi = int_bounds(signed=False, bits=bits) assert lo <= int_ <= hi if int_ > (2 ** (bits - 1)) - 1: - return int_ - (2**bits) + return int_ - (2 ** bits) return int_ @@ -188,7 +188,7 @@ def calc_mem_gas(memsize): # A decimal value can store multiples of 1/DECIMAL_DIVISOR MAX_DECIMAL_PLACES = 10 -DECIMAL_DIVISOR = 10**MAX_DECIMAL_PLACES +DECIMAL_DIVISOR = 10 ** MAX_DECIMAL_PLACES DECIMAL_EPSILON = decimal.Decimal(1) / DECIMAL_DIVISOR @@ -200,13 +200,13 @@ def int_bounds(signed, bits): """ if signed: return -(2 ** (bits - 1)), (2 ** (bits - 1)) - 1 - return 0, (2**bits) - 1 + return 0, (2 ** bits) - 1 # e.g. -1 -> -(2**256 - 1) def evm_twos_complement(x: int) -> int: # return ((o + 2 ** 255) % 2 ** 256) - 2 ** 255 - return ((2**256 - 1) ^ x) + 1 + return ((2 ** 256 - 1) ^ x) + 1 # EVM div semantics as a python function @@ -231,7 +231,7 @@ def evm_mod(x, y): # (which can generated, for ex. in the unevaluated branch of the Shift builtin) def evm_pow(x, y): assert x >= 0 and y >= 0 - return pow(x, y, 2**256) + return pow(x, y, 2 ** 256) # memory used for system purposes, not for variables @@ -243,18 +243,18 @@ class MemoryPositions: # Sizes of different data types. Used to clamp types. class SizeLimits: - MAX_INT128 = 2**127 - 1 - MIN_INT128 = -(2**127) - MAX_INT256 = 2**255 - 1 - MIN_INT256 = -(2**255) - MAXDECIMAL = 2**167 - 1 # maxdecimal as EVM value - MINDECIMAL = -(2**167) # mindecimal as EVM value + MAX_INT128 = 2 ** 127 - 1 + MIN_INT128 = -(2 ** 127) + MAX_INT256 = 2 ** 255 - 1 + MIN_INT256 = -(2 ** 255) + MAXDECIMAL = 2 ** 167 - 1 # maxdecimal as EVM value + MINDECIMAL = -(2 ** 167) # mindecimal as EVM value # min decimal allowed as Python value - MIN_AST_DECIMAL = -decimal.Decimal(2**167) / DECIMAL_DIVISOR + MIN_AST_DECIMAL = -decimal.Decimal(2 ** 167) / DECIMAL_DIVISOR # max decimal allowed as Python value - MAX_AST_DECIMAL = decimal.Decimal(2**167 - 1) / DECIMAL_DIVISOR - MAX_UINT8 = 2**8 - 1 - MAX_UINT256 = 2**256 - 1 + MAX_AST_DECIMAL = decimal.Decimal(2 ** 167 - 1) / DECIMAL_DIVISOR + MAX_UINT8 = 2 ** 8 - 1 + MAX_UINT256 = 2 ** 256 - 1 # Otherwise reserved words that are whitelisted for function declarations From 2b5dec66af55e99ea8539accae7df3530c9db523 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Thu, 30 Mar 2023 04:30:09 +0800 Subject: [PATCH 11/14] undo test lint --- .../ast/nodes/test_evaluate_binop_decimal.py | 4 +- tests/ast/nodes/test_evaluate_binop_int.py | 4 +- tests/base_conftest.py | 4 +- tests/builtins/folding/test_abs.py | 6 +- tests/builtins/folding/test_addmod_mulmod.py | 2 +- tests/builtins/folding/test_bitwise.py | 2 +- tests/builtins/folding/test_floor_ceil.py | 2 +- .../folding/test_fold_as_wei_value.py | 2 +- tests/builtins/folding/test_min_max.py | 4 +- tests/builtins/folding/test_powmod.py | 2 +- tests/compiler/ir/test_compile_ir.py | 4 +- tests/compiler/ir/test_optimize_ir.py | 110 +++++++++--------- .../auctions/test_simple_open_auction.py | 8 +- tests/examples/company/test_company.py | 4 +- .../test_on_chain_market_maker.py | 6 +- tests/examples/tokens/test_erc20.py | 2 +- tests/examples/tokens/test_erc4626.py | 30 ++--- tests/examples/wallet/test_wallet.py | 8 +- .../semantics/analysis/test_array_index.py | 2 +- .../analysis/test_potential_types.py | 4 +- tests/fuzzing/test_exponents.py | 72 ++++++------ .../features/decorators/test_payable.py | 4 +- .../external_contracts/test_erc20_abi.py | 4 +- .../test_external_contract_calls.py | 4 +- tests/parser/features/test_assert.py | 2 +- .../features/test_assert_unreachable.py | 2 +- tests/parser/features/test_bytes_map_keys.py | 2 +- tests/parser/features/test_clampers.py | 64 +++++----- tests/parser/features/test_constructor.py | 6 +- tests/parser/features/test_immutable.py | 8 +- tests/parser/functions/test_abi_decode.py | 4 +- tests/parser/functions/test_abi_encode.py | 16 +-- tests/parser/functions/test_bitwise.py | 6 +- tests/parser/functions/test_ceil.py | 4 +- tests/parser/functions/test_convert.py | 6 +- .../parser/functions/test_default_function.py | 6 +- .../functions/test_default_parameters.py | 4 +- tests/parser/functions/test_extract32.py | 2 +- tests/parser/functions/test_floor.py | 4 +- tests/parser/functions/test_interfaces.py | 6 +- tests/parser/functions/test_minmax.py | 18 +-- tests/parser/functions/test_mkstr.py | 4 +- tests/parser/functions/test_slice.py | 12 +- tests/parser/functions/test_tx.py | 2 +- tests/parser/functions/test_unary.py | 12 +- tests/parser/functions/test_unsafe_math.py | 2 +- tests/parser/syntax/test_msg_data.py | 4 +- tests/parser/types/numbers/test_constants.py | 20 ++-- tests/parser/types/numbers/test_isqrt.py | 2 +- .../parser/types/numbers/test_signed_ints.py | 6 +- .../types/numbers/test_unsigned_ints.py | 10 +- tests/parser/types/test_bytes.py | 2 +- tests/parser/types/test_bytes_zero_padding.py | 2 +- tests/parser/types/test_dynamic_array.py | 2 +- tests/parser/types/test_enum.py | 8 +- tests/parser/types/test_lists.py | 20 ++-- tests/parser/types/test_string.py | 2 +- tests/parser/types/value/test_as_wei_value.py | 16 +-- 58 files changed, 290 insertions(+), 290 deletions(-) diff --git a/tests/ast/nodes/test_evaluate_binop_decimal.py b/tests/ast/nodes/test_evaluate_binop_decimal.py index c6c69626b8..cfe23c87f6 100644 --- a/tests/ast/nodes/test_evaluate_binop_decimal.py +++ b/tests/ast/nodes/test_evaluate_binop_decimal.py @@ -8,7 +8,7 @@ from vyper.exceptions import OverflowException, TypeMismatch, ZeroDivisionException st_decimals = st.decimals( - min_value=-(2**32), max_value=2**32, allow_nan=False, allow_infinity=False, places=10 + min_value=-(2 ** 32), max_value=2 ** 32, allow_nan=False, allow_infinity=False, places=10 ) @@ -75,7 +75,7 @@ def foo({input_value}) -> decimal: try: vy_ast.folding.replace_literal_ops(vyper_ast) expected = vyper_ast.body[0].value.value - is_valid = -(2**127) <= expected < 2**127 + is_valid = -(2 ** 127) <= expected < 2 ** 127 except (OverflowException, ZeroDivisionException): # for overflow or division/modulus by 0, expect the contract call to revert is_valid = False diff --git a/tests/ast/nodes/test_evaluate_binop_int.py b/tests/ast/nodes/test_evaluate_binop_int.py index d632a95461..60be88eb5a 100644 --- a/tests/ast/nodes/test_evaluate_binop_int.py +++ b/tests/ast/nodes/test_evaluate_binop_int.py @@ -5,7 +5,7 @@ from vyper import ast as vy_ast from vyper.exceptions import ZeroDivisionException -st_int32 = st.integers(min_value=-(2**32), max_value=2**32) +st_int32 = st.integers(min_value=-(2 ** 32), max_value=2 ** 32) @pytest.mark.fuzzing @@ -38,7 +38,7 @@ def foo(a: int128, b: int128) -> int128: assert_tx_failed(lambda: contract.foo(left, right)) -st_uint64 = st.integers(min_value=0, max_value=2**64) +st_uint64 = st.integers(min_value=0, max_value=2 ** 64) @pytest.mark.fuzzing diff --git a/tests/base_conftest.py b/tests/base_conftest.py index 3263bad2b0..aa6ee55923 100644 --- a/tests/base_conftest.py +++ b/tests/base_conftest.py @@ -85,7 +85,7 @@ def _none_addr(datatype, data): def tester(): # set absurdly high gas limit so that london basefee never adjusts # (note: 2**63 - 1 is max that evm allows) - custom_genesis = PyEVMBackend._generate_genesis_params(overrides={"gas_limit": 10**10}) + custom_genesis = PyEVMBackend._generate_genesis_params(overrides={"gas_limit": 10 ** 10}) custom_genesis["base_fee_per_gas"] = 0 backend = PyEVMBackend(genesis_parameters=custom_genesis) return EthereumTester(backend=backend) @@ -114,7 +114,7 @@ def _get_contract(w3, source_code, no_optimize, *args, **kwargs): parse_vyper_source(source_code) # Test grammar. abi = out["abi"] bytecode = out["bytecode"] - value = kwargs.pop("value_in_eth", 0) * 10**18 # Handle deploying with an eth value. + value = kwargs.pop("value_in_eth", 0) * 10 ** 18 # Handle deploying with an eth value. c = w3.eth.contract(abi=abi, bytecode=bytecode) deploy_transaction = c.constructor(*args) tx_info = {"from": w3.eth.accounts[0], "value": value, "gasPrice": 0} diff --git a/tests/builtins/folding/test_abs.py b/tests/builtins/folding/test_abs.py index 58f861ed0c..058177b71c 100644 --- a/tests/builtins/folding/test_abs.py +++ b/tests/builtins/folding/test_abs.py @@ -9,7 +9,7 @@ @pytest.mark.fuzzing @settings(max_examples=50, deadline=1000) -@given(a=st.integers(min_value=-(2**255) + 1, max_value=2**255 - 1)) +@given(a=st.integers(min_value=-(2 ** 255) + 1, max_value=2 ** 255 - 1)) @example(a=0) def test_abs(get_contract, a): source = """ @@ -28,7 +28,7 @@ def foo(a: int256) -> int256: @pytest.mark.fuzzing @settings(max_examples=50, deadline=1000) -@given(a=st.integers(min_value=2**255, max_value=2**256 - 1)) +@given(a=st.integers(min_value=2 ** 255, max_value=2 ** 256 - 1)) def test_abs_upper_bound_folding(get_contract, a): source = f""" @external @@ -47,7 +47,7 @@ def foo(a: int256) -> int256: """ contract = get_contract(source) - assert_tx_failed(lambda: contract.foo(-(2**255))) + assert_tx_failed(lambda: contract.foo(-(2 ** 255))) def test_abs_lower_bound_folded(get_contract, assert_tx_failed): diff --git a/tests/builtins/folding/test_addmod_mulmod.py b/tests/builtins/folding/test_addmod_mulmod.py index 0514dea18a..c697cc6b2a 100644 --- a/tests/builtins/folding/test_addmod_mulmod.py +++ b/tests/builtins/folding/test_addmod_mulmod.py @@ -5,7 +5,7 @@ from vyper import ast as vy_ast from vyper.builtins import functions as vy_fn -st_uint256 = st.integers(min_value=0, max_value=2**256 - 1) +st_uint256 = st.integers(min_value=0, max_value=2 ** 256 - 1) @pytest.mark.fuzzing diff --git a/tests/builtins/folding/test_bitwise.py b/tests/builtins/folding/test_bitwise.py index 9be0b6817d..897f444e06 100644 --- a/tests/builtins/folding/test_bitwise.py +++ b/tests/builtins/folding/test_bitwise.py @@ -5,7 +5,7 @@ from vyper import ast as vy_ast from vyper.builtins import functions as vy_fn -st_uint256 = st.integers(min_value=0, max_value=2**256 - 1) +st_uint256 = st.integers(min_value=0, max_value=2 ** 256 - 1) @pytest.mark.fuzzing diff --git a/tests/builtins/folding/test_floor_ceil.py b/tests/builtins/folding/test_floor_ceil.py index 763f8fec63..1e834e4d6e 100644 --- a/tests/builtins/folding/test_floor_ceil.py +++ b/tests/builtins/folding/test_floor_ceil.py @@ -8,7 +8,7 @@ from vyper.builtins import functions as vy_fn st_decimals = st.decimals( - min_value=-(2**32), max_value=2**32, allow_nan=False, allow_infinity=False, places=10 + min_value=-(2 ** 32), max_value=2 ** 32, allow_nan=False, allow_infinity=False, places=10 ) diff --git a/tests/builtins/folding/test_fold_as_wei_value.py b/tests/builtins/folding/test_fold_as_wei_value.py index 11d23bd3bf..61818e291a 100644 --- a/tests/builtins/folding/test_fold_as_wei_value.py +++ b/tests/builtins/folding/test_fold_as_wei_value.py @@ -39,7 +39,7 @@ def foo(a: decimal) -> uint256: @pytest.mark.fuzzing @settings(max_examples=10, deadline=1000) -@given(value=st.integers(min_value=0, max_value=2**128)) +@given(value=st.integers(min_value=0, max_value=2 ** 128)) @pytest.mark.parametrize("denom", denoms) def test_integer(get_contract, value, denom): source = f""" diff --git a/tests/builtins/folding/test_min_max.py b/tests/builtins/folding/test_min_max.py index e2d33237ca..13f5dd0537 100644 --- a/tests/builtins/folding/test_min_max.py +++ b/tests/builtins/folding/test_min_max.py @@ -13,8 +13,8 @@ allow_infinity=False, places=10, ) -st_int128 = st.integers(min_value=-(2**127), max_value=2**127 - 1) -st_uint256 = st.integers(min_value=0, max_value=2**256 - 1) +st_int128 = st.integers(min_value=-(2 ** 127), max_value=2 ** 127 - 1) +st_uint256 = st.integers(min_value=0, max_value=2 ** 256 - 1) @pytest.mark.fuzzing diff --git a/tests/builtins/folding/test_powmod.py b/tests/builtins/folding/test_powmod.py index fdc0e300ab..3ea96bfbed 100644 --- a/tests/builtins/folding/test_powmod.py +++ b/tests/builtins/folding/test_powmod.py @@ -5,7 +5,7 @@ from vyper import ast as vy_ast from vyper.builtins import functions as vy_fn -st_uint256 = st.integers(min_value=0, max_value=2**256) +st_uint256 = st.integers(min_value=0, max_value=2 ** 256) @pytest.mark.fuzzing diff --git a/tests/compiler/ir/test_compile_ir.py b/tests/compiler/ir/test_compile_ir.py index 91007da33a..03c4f33095 100644 --- a/tests/compiler/ir/test_compile_ir.py +++ b/tests/compiler/ir/test_compile_ir.py @@ -5,8 +5,8 @@ from vyper.ir.s_expressions import parse_s_exp fail_list = [ - [-(2**255) - 3], - [2**256 + 3], + [-(2 ** 255) - 3], + [2 ** 256 + 3], ["set", "_poz"], [["set", "var_1", 0, 0]], ["with", "var_1", 0, ["set", 1, 1]], diff --git a/tests/compiler/ir/test_optimize_ir.py b/tests/compiler/ir/test_optimize_ir.py index bac0e18d65..6c4cf50fc1 100644 --- a/tests/compiler/ir/test_optimize_ir.py +++ b/tests/compiler/ir/test_optimize_ir.py @@ -34,23 +34,23 @@ # conditions (["ge", "x", 0], [1]), # x >= 0 == True (["ge", ["sload", 0], 0], None), # no-op - (["gt", "x", 2**256 - 1], [0]), # x >= MAX_UINT256 == False + (["gt", "x", 2 ** 256 - 1], [0]), # x >= MAX_UINT256 == False # (x > 0) => x == 0 (["iszero", ["gt", "x", 0]], ["iszero", ["iszero", ["iszero", "x"]]]), # !(x < MAX_UINT256) => x == MAX_UINT256 - (["iszero", ["lt", "x", 2**256 - 1]], ["iszero", ["iszero", ["iszero", ["not", "x"]]]]), + (["iszero", ["lt", "x", 2 ** 256 - 1]], ["iszero", ["iszero", ["iszero", ["not", "x"]]]]), # !(x < MAX_INT256) => x == MAX_INT256 ( - ["iszero", ["slt", "x", 2**255 - 1]], - ["iszero", ["iszero", ["iszero", ["xor", "x", 2**255 - 1]]]], + ["iszero", ["slt", "x", 2 ** 255 - 1]], + ["iszero", ["iszero", ["iszero", ["xor", "x", 2 ** 255 - 1]]]], ), # !(x > MIN_INT256) => x == MIN_INT256 ( - ["iszero", ["sgt", "x", -(2**255)]], - ["iszero", ["iszero", ["iszero", ["xor", "x", -(2**255)]]]], + ["iszero", ["sgt", "x", -(2 ** 255)]], + ["iszero", ["iszero", ["iszero", ["xor", "x", -(2 ** 255)]]]], ), - (["sgt", "x", 2**255 - 1], [0]), # signed x > MAX_INT256 == False - (["sge", "x", 2**255 - 1], ["eq", "x", 2**255 - 1]), + (["sgt", "x", 2 ** 255 - 1], [0]), # signed x > MAX_INT256 == False + (["sge", "x", 2 ** 255 - 1], ["eq", "x", 2 ** 255 - 1]), (["eq", -1, "x"], ["iszero", ["not", "x"]]), (["iszero", ["eq", -1, "x"]], ["iszero", ["iszero", ["not", "x"]]]), (["le", "x", 0], ["iszero", "x"]), @@ -58,10 +58,10 @@ (["le", 0, ["sload", 0]], None), # no-op (["ge", "x", 0], [1]), # boundary conditions - (["slt", "x", -(2**255)], [0]), - (["sle", "x", -(2**255)], ["eq", "x", -(2**255)]), - (["lt", "x", 2**256 - 1], None), - (["le", "x", 2**256 - 1], [1]), + (["slt", "x", -(2 ** 255)], [0]), + (["sle", "x", -(2 ** 255)], ["eq", "x", -(2 ** 255)]), + (["lt", "x", 2 ** 256 - 1], None), + (["le", "x", 2 ** 256 - 1], [1]), (["gt", "x", 0], ["iszero", ["iszero", "x"]]), # x < 0 => false (["lt", "x", 0], [0]), @@ -73,18 +73,18 @@ (["slt", "x", 1], None), (["gt", "x", 1], None), (["sgt", "x", 1], None), - (["gt", "x", 2**256 - 2], ["iszero", ["not", "x"]]), - (["lt", "x", 2**256 - 2], None), - (["slt", "x", 2**256 - 2], None), - (["sgt", "x", 2**256 - 2], None), - (["slt", "x", -(2**255) + 1], ["eq", "x", -(2**255)]), - (["sgt", "x", -(2**255) + 1], None), - (["lt", "x", -(2**255) + 1], None), - (["gt", "x", -(2**255) + 1], None), - (["sgt", "x", 2**255 - 2], ["eq", "x", 2**255 - 1]), - (["slt", "x", 2**255 - 2], None), - (["gt", "x", 2**255 - 2], None), - (["lt", "x", 2**255 - 2], None), + (["gt", "x", 2 ** 256 - 2], ["iszero", ["not", "x"]]), + (["lt", "x", 2 ** 256 - 2], None), + (["slt", "x", 2 ** 256 - 2], None), + (["sgt", "x", 2 ** 256 - 2], None), + (["slt", "x", -(2 ** 255) + 1], ["eq", "x", -(2 ** 255)]), + (["sgt", "x", -(2 ** 255) + 1], None), + (["lt", "x", -(2 ** 255) + 1], None), + (["gt", "x", -(2 ** 255) + 1], None), + (["sgt", "x", 2 ** 255 - 2], ["eq", "x", 2 ** 255 - 1]), + (["slt", "x", 2 ** 255 - 2], None), + (["gt", "x", 2 ** 255 - 2], None), + (["lt", "x", 2 ** 255 - 2], None), # 5 > x; x < 5; x <= 4 (["iszero", ["gt", 5, "x"]], ["iszero", ["le", "x", 4]]), (["iszero", ["ge", 5, "x"]], None), @@ -109,18 +109,18 @@ # 5 <= x; x >= 5; x > 4 (["sle", 5, "x"], ["sgt", "x", 4]), # tricky constant folds - (["sgt", 2**256 - 1, 0], [0]), # -1 > 0 - (["gt", 2**256 - 1, 0], [1]), # -1 > 0 - (["gt", 2**255, 0], [1]), # 0x80 > 0 - (["sgt", 2**255, 0], [0]), # 0x80 > 0 - (["sgt", 2**255, 2**255 - 1], [0]), # 0x80 > 0x81 - (["gt", -(2**255), 2**255 - 1], [1]), # 0x80 > 0x81 - (["slt", 2**255, 2**255 - 1], [1]), # 0x80 < 0x7f - (["lt", -(2**255), 2**255 - 1], [0]), # 0x80 < 0x7f - (["sle", -1, 2**256 - 1], [1]), # -1 <= -1 - (["sge", -(2**255), 2**255], [1]), # 0x80 >= 0x80 - (["sgt", -(2**255), 2**255], [0]), # 0x80 > 0x80 - (["slt", 2**255, -(2**255)], [0]), # 0x80 < 0x80 + (["sgt", 2 ** 256 - 1, 0], [0]), # -1 > 0 + (["gt", 2 ** 256 - 1, 0], [1]), # -1 > 0 + (["gt", 2 ** 255, 0], [1]), # 0x80 > 0 + (["sgt", 2 ** 255, 0], [0]), # 0x80 > 0 + (["sgt", 2 ** 255, 2 ** 255 - 1], [0]), # 0x80 > 0x81 + (["gt", -(2 ** 255), 2 ** 255 - 1], [1]), # 0x80 > 0x81 + (["slt", 2 ** 255, 2 ** 255 - 1], [1]), # 0x80 < 0x7f + (["lt", -(2 ** 255), 2 ** 255 - 1], [0]), # 0x80 < 0x7f + (["sle", -1, 2 ** 256 - 1], [1]), # -1 <= -1 + (["sge", -(2 ** 255), 2 ** 255], [1]), # 0x80 >= 0x80 + (["sgt", -(2 ** 255), 2 ** 255], [0]), # 0x80 > 0x80 + (["slt", 2 ** 255, -(2 ** 255)], [0]), # 0x80 < 0x80 # arithmetic (["ceil32", "x"], None), (["ceil32", 0], [0]), @@ -159,17 +159,17 @@ (["mod", "x", 128], ["and", "x", 127]), (["sdiv", "x", 64], None), (["smod", "x", 64], None), - (["exp", 3, 5], [3**5]), - (["exp", 3, 256], [(3**256) % (2**256)]), + (["exp", 3, 5], [3 ** 5]), + (["exp", 3, 256], [(3 ** 256) % (2 ** 256)]), (["exp", 2, 257], [0]), (["exp", "x", 0], [1]), (["exp", "x", 1], ["x"]), (["exp", 1, "x"], [1]), (["exp", 0, "x"], ["iszero", "x"]), # bitwise ops - (["xor", "x", 2**256 - 1], ["not", "x"]), - (["and", "x", 2**256 - 1], ["x"]), - (["or", "x", 2**256 - 1], [2**256 - 1]), + (["xor", "x", 2 ** 256 - 1], ["not", "x"]), + (["and", "x", 2 ** 256 - 1], ["x"]), + (["or", "x", 2 ** 256 - 1], [2 ** 256 - 1]), (["shr", 0, "x"], ["x"]), (["sar", 0, "x"], ["x"]), (["shl", 0, "x"], ["x"]), @@ -195,12 +195,12 @@ (["iszero", ["or", 1, ["sload", 0]]], None), # nested optimizations (["eq", 0, ["sub", 1, 1]], [1]), - (["eq", 0, ["add", 2**255, 2**255]], [1]), # test compile-time wrapping - (["eq", 0, ["add", 2**255, -(2**255)]], [1]), # test compile-time wrapping + (["eq", 0, ["add", 2 ** 255, 2 ** 255]], [1]), # test compile-time wrapping + (["eq", 0, ["add", 2 ** 255, -(2 ** 255)]], [1]), # test compile-time wrapping (["eq", -1, ["add", 0, -1]], [1]), # test compile-time wrapping - (["eq", -1, ["add", 2**255, 2**255 - 1]], [1]), # test compile-time wrapping - (["eq", -1, ["add", -(2**255), 2**255 - 1]], [1]), # test compile-time wrapping - (["eq", -2, ["add", 2**256 - 1, 2**256 - 1]], [1]), # test compile-time wrapping + (["eq", -1, ["add", 2 ** 255, 2 ** 255 - 1]], [1]), # test compile-time wrapping + (["eq", -1, ["add", -(2 ** 255), 2 ** 255 - 1]], [1]), # test compile-time wrapping + (["eq", -2, ["add", 2 ** 256 - 1, 2 ** 256 - 1]], [1]), # test compile-time wrapping (["eq", "x", "x"], [1]), (["eq", "callvalue", "callvalue"], None), (["ne", "x", "x"], [0]), @@ -229,23 +229,23 @@ def test_ir_optimizer(ir): ["assert", ["lt", 1, 1]], ["assert", ["lt", "x", 0]], # +x < 0 ["assert", ["le", 1, 0]], - ["assert", ["le", 2**256 - 1, 0]], + ["assert", ["le", 2 ** 256 - 1, 0]], ["assert", ["gt", 1, 2]], ["assert", ["gt", 1, 1]], - ["assert", ["gt", 0, 2**256 - 1]], - ["assert", ["gt", "x", 2**256 - 1]], + ["assert", ["gt", 0, 2 ** 256 - 1]], + ["assert", ["gt", "x", 2 ** 256 - 1]], ["assert", ["ge", 1, 2]], ["assert", ["ge", 1, 2]], ["assert", ["slt", 2, 1]], ["assert", ["slt", 1, 1]], - ["assert", ["slt", 0, 2**256 - 1]], # 0 < -1 - ["assert", ["slt", -(2**255), 2**255]], # 0x80 < 0x80 - ["assert", ["sle", 0, 2**255]], # 0 < 0x80 + ["assert", ["slt", 0, 2 ** 256 - 1]], # 0 < -1 + ["assert", ["slt", -(2 ** 255), 2 ** 255]], # 0x80 < 0x80 + ["assert", ["sle", 0, 2 ** 255]], # 0 < 0x80 ["assert", ["sgt", 1, 2]], ["assert", ["sgt", 1, 1]], - ["assert", ["sgt", 2**256 - 1, 0]], # -1 > 0 - ["assert", ["sgt", 2**255, -(2**255)]], # 0x80 > 0x80 - ["assert", ["sge", 2**255, 0]], # 0x80 > 0 + ["assert", ["sgt", 2 ** 256 - 1, 0]], # -1 > 0 + ["assert", ["sgt", 2 ** 255, -(2 ** 255)]], # 0x80 > 0x80 + ["assert", ["sge", 2 ** 255, 0]], # 0x80 > 0 ] diff --git a/tests/examples/auctions/test_simple_open_auction.py b/tests/examples/auctions/test_simple_open_auction.py index cf0bb8cc20..21aeb4d4a7 100644 --- a/tests/examples/auctions/test_simple_open_auction.py +++ b/tests/examples/auctions/test_simple_open_auction.py @@ -56,9 +56,9 @@ def test_bid(w3, tester, auction_contract, assert_tx_failed): # Check that highest bidder and highest bid have changed accordingly assert auction_contract.highestBidder() == k5 assert auction_contract.highestBid() == 5 - auction_contract.bid(transact={"value": 1 * 10**10, "from": k1}) + auction_contract.bid(transact={"value": 1 * 10 ** 10, "from": k1}) pending_return_before_outbid = auction_contract.pendingReturns(k1) - auction_contract.bid(transact={"value": 2 * 10**10, "from": k2}) + auction_contract.bid(transact={"value": 2 * 10 ** 10, "from": k2}) pending_return_after_outbid = auction_contract.pendingReturns(k1) # Account has a greater pending return balance after being outbid assert pending_return_after_outbid > pending_return_before_outbid @@ -76,7 +76,7 @@ def test_end_auction(w3, tester, auction_contract, assert_tx_failed): k1, k2, k3, k4, k5 = w3.eth.accounts[:5] # Fails if auction end time has not been reached assert_tx_failed(lambda: auction_contract.endAuction()) - auction_contract.bid(transact={"value": 1 * 10**10, "from": k2}) + auction_contract.bid(transact={"value": 1 * 10 ** 10, "from": k2}) # Move block timestamp foreward to reach auction end time # tester.time_travel(tester.get_block_by_number('latest')['timestamp'] + EXPIRY) w3.testing.mine(EXPIRY) @@ -84,7 +84,7 @@ def test_end_auction(w3, tester, auction_contract, assert_tx_failed): auction_contract.endAuction(transact={"from": k2}) balance_after_end = w3.eth.get_balance(k1) # Beneficiary receives the highest bid - assert balance_after_end == balance_before_end + 1 * 10**10 + assert balance_after_end == balance_before_end + 1 * 10 ** 10 # Bidder cannot bid after auction end time has been reached assert_tx_failed(lambda: auction_contract.bid(transact={"value": 10, "from": k1})) # Auction cannot be ended twice diff --git a/tests/examples/company/test_company.py b/tests/examples/company/test_company.py index 71141b8bb5..d281652e5a 100644 --- a/tests/examples/company/test_company.py +++ b/tests/examples/company/test_company.py @@ -5,7 +5,7 @@ def c(w3, get_contract): with open("examples/stock/company.vy") as f: contract_code = f.read() - contract = get_contract(contract_code, *[w3.eth.accounts[0], 1000, 10**6]) + contract = get_contract(contract_code, *[w3.eth.accounts[0], 1000, 10 ** 6]) return contract @@ -107,7 +107,7 @@ def test_logs(w3, c, get_logs): assert logs[0].args.value == 4 # Pay is logged - amount = 10**4 + amount = 10 ** 4 logs = get_logs(c.payBill(a3, amount, transact={}), c, "Pay") assert len(logs) == 1 assert logs[0].args.amount == amount diff --git a/tests/examples/market_maker/test_on_chain_market_maker.py b/tests/examples/market_maker/test_on_chain_market_maker.py index 546ecc15a8..fdbf59370f 100644 --- a/tests/examples/market_maker/test_on_chain_market_maker.py +++ b/tests/examples/market_maker/test_on_chain_market_maker.py @@ -11,8 +11,8 @@ def market_maker(get_contract): TOKEN_NAME = "Vypercoin" TOKEN_SYMBOL = "FANG" TOKEN_DECIMALS = 18 -TOKEN_INITIAL_SUPPLY = 21 * 10**6 -TOKEN_TOTAL_SUPPLY = TOKEN_INITIAL_SUPPLY * (10**TOKEN_DECIMALS) +TOKEN_INITIAL_SUPPLY = 21 * 10 ** 6 +TOKEN_TOTAL_SUPPLY = TOKEN_INITIAL_SUPPLY * (10 ** TOKEN_DECIMALS) @pytest.fixture @@ -39,7 +39,7 @@ def test_initiate(w3, market_maker, erc20, assert_tx_failed): ) assert market_maker.totalEthQty() == w3.toWei(2, "ether") assert market_maker.totalTokenQty() == w3.toWei(1, "ether") - assert market_maker.invariant() == 2 * 10**36 + assert market_maker.invariant() == 2 * 10 ** 36 assert market_maker.owner() == a0 assert erc20.name() == TOKEN_NAME assert erc20.decimals() == TOKEN_DECIMALS diff --git a/tests/examples/tokens/test_erc20.py b/tests/examples/tokens/test_erc20.py index cba7769bae..c693959309 100644 --- a/tests/examples/tokens/test_erc20.py +++ b/tests/examples/tokens/test_erc20.py @@ -5,7 +5,7 @@ from web3.exceptions import ValidationError ZERO_ADDRESS = "0x0000000000000000000000000000000000000000" -MAX_UINT256 = (2**256) - 1 # Max uint256 value +MAX_UINT256 = (2 ** 256) - 1 # Max uint256 value TOKEN_NAME = "Vypercoin" TOKEN_SYMBOL = "FANG" TOKEN_DECIMALS = 18 diff --git a/tests/examples/tokens/test_erc4626.py b/tests/examples/tokens/test_erc4626.py index 2469a7abd0..a8e57e7eff 100644 --- a/tests/examples/tokens/test_erc4626.py +++ b/tests/examples/tokens/test_erc4626.py @@ -1,6 +1,6 @@ import pytest -AMOUNT = 100 * 10**18 +AMOUNT = 100 * 10 ** 18 TOKEN_NAME = "Vypercoin" TOKEN_SYMBOL = "FANG" TOKEN_DECIMALS = 18 @@ -28,18 +28,18 @@ def test_asset(vault, token): def test_max_methods(w3, vault): a = w3.eth.accounts[0] - assert vault.maxDeposit(a) == 2**256 - 1 - assert vault.maxMint(a) == 2**256 - 1 - assert vault.maxWithdraw(a) == 2**256 - 1 - assert vault.maxRedeem(a) == 2**256 - 1 + assert vault.maxDeposit(a) == 2 ** 256 - 1 + assert vault.maxMint(a) == 2 ** 256 - 1 + assert vault.maxWithdraw(a) == 2 ** 256 - 1 + assert vault.maxRedeem(a) == 2 ** 256 - 1 def test_preview_methods(w3, token, vault): a = w3.eth.accounts[0] assert vault.totalAssets() == 0 - assert vault.convertToAssets(10**18) == 0 # no assets - assert vault.convertToShares(10**18) == 10**18 # 1:1 price + assert vault.convertToAssets(10 ** 18) == 0 # no assets + assert vault.convertToShares(10 ** 18) == 10 ** 18 # 1:1 price assert vault.previewDeposit(AMOUNT) == AMOUNT # 1:1 price assert vault.previewMint(AMOUNT) == AMOUNT # 1:1 price assert vault.previewWithdraw(AMOUNT) == 0 # but no assets @@ -50,8 +50,8 @@ def test_preview_methods(w3, token, vault): vault.deposit(AMOUNT, transact={"from": a}) assert vault.totalAssets() == AMOUNT - assert vault.convertToAssets(10**18) == 10**18 # 1:1 price - assert vault.convertToShares(10**18) == 10**18 # 1:1 price + assert vault.convertToAssets(10 ** 18) == 10 ** 18 # 1:1 price + assert vault.convertToShares(10 ** 18) == 10 ** 18 # 1:1 price assert vault.previewDeposit(AMOUNT) == AMOUNT # 1:1 price assert vault.previewMint(AMOUNT) == AMOUNT # 1:1 price assert vault.previewWithdraw(AMOUNT) == AMOUNT # 1:1 price @@ -60,8 +60,8 @@ def test_preview_methods(w3, token, vault): token.mint(vault.address, AMOUNT, transact={"from": a}) assert vault.totalAssets() == 2 * AMOUNT - assert vault.convertToAssets(10**18) == 2 * 10**18 # 2:1 price - assert vault.convertToShares(2 * 10**18) == 10**18 # 2:1 price + assert vault.convertToAssets(10 ** 18) == 2 * 10 ** 18 # 2:1 price + assert vault.convertToShares(2 * 10 ** 18) == 10 ** 18 # 2:1 price assert vault.previewDeposit(AMOUNT) == AMOUNT // 2 # 2:1 price assert vault.previewMint(AMOUNT // 2) == AMOUNT # 2:1 price assert vault.previewWithdraw(AMOUNT) == AMOUNT // 2 # 2:1 price @@ -70,8 +70,8 @@ def test_preview_methods(w3, token, vault): vault.DEBUG_steal_tokens(AMOUNT, transact={"from": a}) assert vault.totalAssets() == AMOUNT - assert vault.convertToAssets(10**18) == 10**18 # 1:1 price - assert vault.convertToShares(10**18) == 10**18 # 1:1 price + assert vault.convertToAssets(10 ** 18) == 10 ** 18 # 1:1 price + assert vault.convertToShares(10 ** 18) == 10 ** 18 # 1:1 price assert vault.previewDeposit(AMOUNT) == AMOUNT # 1:1 price assert vault.previewMint(AMOUNT) == AMOUNT # 1:1 price assert vault.previewWithdraw(AMOUNT) == AMOUNT # 1:1 price @@ -80,8 +80,8 @@ def test_preview_methods(w3, token, vault): vault.DEBUG_steal_tokens(AMOUNT // 2, transact={"from": a}) assert vault.totalAssets() == AMOUNT // 2 - assert vault.convertToAssets(10**18) == 10**18 // 2 # 1:2 price - assert vault.convertToShares(10**18 // 2) == 10**18 # 1:2 price + assert vault.convertToAssets(10 ** 18) == 10 ** 18 // 2 # 1:2 price + assert vault.convertToShares(10 ** 18 // 2) == 10 ** 18 # 1:2 price assert vault.previewDeposit(AMOUNT) == 2 * AMOUNT # 1:2 price assert vault.previewMint(2 * AMOUNT) == AMOUNT # 1:2 price assert vault.previewWithdraw(AMOUNT) == 2 * AMOUNT # 1:2 price diff --git a/tests/examples/wallet/test_wallet.py b/tests/examples/wallet/test_wallet.py index 8114006f28..c15f74ffe5 100644 --- a/tests/examples/wallet/test_wallet.py +++ b/tests/examples/wallet/test_wallet.py @@ -11,7 +11,7 @@ def c(w3, get_contract): code = f.read() # Sends wei to the contract for future transactions gas costs c = get_contract(code, *[[a1, a2, a3, a4, a5], 3]) - w3.eth.send_transaction({"to": c.address, "value": 10**17}) + w3.eth.send_transaction({"to": c.address, "value": 10 ** 17}) return c @@ -32,7 +32,7 @@ def test_approve(w3, c, tester, assert_tx_failed, sign): a0, a1, a2, a3, a4, a5, a6 = w3.eth.accounts[:7] k0, k1, k2, k3, k4, k5, k6, k7 = tester.backend.account_keys[:8] - to, value, data = b"\x35" * 20, 10**16, b"" + to, value, data = b"\x35" * 20, 10 ** 16, b"" to_address = w3.toChecksumAddress(to) def pack_and_sign(seq, *args): @@ -110,12 +110,12 @@ def test_javascript_signatures(w3, get_contract): owners = [w3.toChecksumAddress(x) for x in accounts + [a3, zero_address, zero_address]] x2 = get_contract(f.read(), *[owners, 2]) - w3.eth.send_transaction({"to": x2.address, "value": 10**17}) + w3.eth.send_transaction({"to": x2.address, "value": 10 ** 17}) # There's no need to pass in signatures because the owners are 0 addresses # causing them to default to valid signatures x2.approve( - 0, recipient, 25, b"", sigs + [[0, 0, 0]] * 3, call={"to": x2.address, "value": 10**17} + 0, recipient, 25, b"", sigs + [[0, 0, 0]] * 3, call={"to": x2.address, "value": 10 ** 17} ) print("Javascript signature tests passed") diff --git a/tests/functional/semantics/analysis/test_array_index.py b/tests/functional/semantics/analysis/test_array_index.py index 27c0634cf8..e025dde2f5 100644 --- a/tests/functional/semantics/analysis/test_array_index.py +++ b/tests/functional/semantics/analysis/test_array_index.py @@ -41,7 +41,7 @@ def foo(): validate_semantics(vyper_module, {}) -@pytest.mark.parametrize("value", [-1, 3, -(2**127), 2**127 - 1, 2**256 - 1]) +@pytest.mark.parametrize("value", [-1, 3, -(2 ** 127), 2 ** 127 - 1, 2 ** 256 - 1]) def test_out_of_bounds(namespace, value): code = f""" diff --git a/tests/functional/semantics/analysis/test_potential_types.py b/tests/functional/semantics/analysis/test_potential_types.py index 74cdc9ae0f..0fe44a1d41 100644 --- a/tests/functional/semantics/analysis/test_potential_types.py +++ b/tests/functional/semantics/analysis/test_potential_types.py @@ -13,7 +13,7 @@ from vyper.semantics.types import AddressT, BoolT, DArrayT, SArrayT from vyper.semantics.types.shortcuts import INT128_T -INTEGER_LITERALS = [(42, 31337), (-1, 1), (69, 2**128)] +INTEGER_LITERALS = [(42, 31337), (-1, 1), (69, 2 ** 128)] DECIMAL_LITERALS = [("4.2", "-1.337")] BOOL_LITERALS = [(True, False), (True, True), (False, False)] STRING_LITERALS = [("'hi'", "'there'"), ("'foo'", "'bar'"), ("'longer'", "'short'")] @@ -67,7 +67,7 @@ def test_binop(build_node, namespace, op, left, right): @pytest.mark.parametrize("op", "+-*/%") -@pytest.mark.parametrize("left,right", [(42, "2.3"), (-1, 2**255)]) +@pytest.mark.parametrize("left,right", [(42, "2.3"), (-1, 2 ** 255)]) def test_binop_type_mismatch(build_node, namespace, op, left, right): node = build_node(f"{left}{op}{right}") with namespace.enter_scope(): diff --git a/tests/fuzzing/test_exponents.py b/tests/fuzzing/test_exponents.py index 29c1f198ed..376acc0eaf 100644 --- a/tests/fuzzing/test_exponents.py +++ b/tests/fuzzing/test_exponents.py @@ -14,8 +14,8 @@ def foo(a: uint256) -> uint256: return a ** {power} """ _min_base, max_base = calculate_largest_base(power, 256, False) - assert max_base**power < 2**256 - assert (max_base + 1) ** power >= 2**256 + assert max_base ** power < 2 ** 256 + assert (max_base + 1) ** power >= 2 ** 256 c = get_contract(code) @@ -33,11 +33,11 @@ def foo(a: int128) -> int128: """ min_base, max_base = calculate_largest_base(power, 128, True) - assert -(2**127) <= max_base**power < 2**127 - assert -(2**127) <= min_base**power < 2**127 + assert -(2 ** 127) <= max_base ** power < 2 ** 127 + assert -(2 ** 127) <= min_base ** power < 2 ** 127 - assert not -(2**127) <= (max_base + 1) ** power < 2**127 - assert not -(2**127) <= (min_base - 1) ** power < 2**127 + assert not -(2 ** 127) <= (max_base + 1) ** power < 2 ** 127 + assert not -(2 ** 127) <= (min_base - 1) ** power < 2 ** 127 c = get_contract(code) @@ -58,11 +58,11 @@ def foo(a: int16) -> int16: """ min_base, max_base = calculate_largest_base(power, 16, True) - assert -(2**15) <= max_base**power < 2**15 - assert -(2**15) <= min_base**power < 2**15 + assert -(2 ** 15) <= max_base ** power < 2 ** 15 + assert -(2 ** 15) <= min_base ** power < 2 ** 15 - assert not -(2**15) <= (max_base + 1) ** power < 2**15 - assert not -(2**15) <= (min_base - 1) ** power < 2**15 + assert not -(2 ** 15) <= (max_base + 1) ** power < 2 ** 15 + assert not -(2 ** 15) <= (min_base - 1) ** power < 2 ** 15 c = get_contract(code) @@ -74,24 +74,24 @@ def foo(a: int16) -> int16: @pytest.mark.fuzzing -@given(a=st.integers(min_value=2, max_value=2**256 - 1)) +@given(a=st.integers(min_value=2, max_value=2 ** 256 - 1)) # 8 bits -@example(a=2**7) -@example(a=2**7 - 1) +@example(a=2 ** 7) +@example(a=2 ** 7 - 1) # 16 bits -@example(a=2**15) -@example(a=2**15 - 1) +@example(a=2 ** 15) +@example(a=2 ** 15 - 1) # 32 bits -@example(a=2**31) -@example(a=2**31 - 1) +@example(a=2 ** 31) +@example(a=2 ** 31 - 1) # 64 bits -@example(a=2**63) -@example(a=2**63 - 1) +@example(a=2 ** 63) +@example(a=2 ** 63 - 1) # 128 bits -@example(a=2**127) -@example(a=2**127 - 1) +@example(a=2 ** 127) +@example(a=2 ** 127 - 1) # 256 bits -@example(a=2**256 - 1) +@example(a=2 ** 256 - 1) @settings(max_examples=200, deadline=1000) def test_max_exp(get_contract, assert_tx_failed, a): code = f""" @@ -104,29 +104,29 @@ def foo(b: uint256) -> uint256: max_power = calculate_largest_power(a, 256, False) - assert a**max_power < 2**256 - assert a ** (max_power + 1) >= 2**256 + assert a ** max_power < 2 ** 256 + assert a ** (max_power + 1) >= 2 ** 256 c.foo(max_power) assert_tx_failed(lambda: c.foo(max_power + 1)) @pytest.mark.fuzzing -@given(a=st.integers(min_value=2, max_value=2**127 - 1)) +@given(a=st.integers(min_value=2, max_value=2 ** 127 - 1)) # 8 bits -@example(a=2**7) -@example(a=2**7 - 1) +@example(a=2 ** 7) +@example(a=2 ** 7 - 1) # 16 bits -@example(a=2**15) -@example(a=2**15 - 1) +@example(a=2 ** 15) +@example(a=2 ** 15 - 1) # 32 bits -@example(a=2**31) -@example(a=2**31 - 1) +@example(a=2 ** 31) +@example(a=2 ** 31 - 1) # 64 bits -@example(a=2**63) -@example(a=2**63 - 1) +@example(a=2 ** 63) +@example(a=2 ** 63 - 1) # 128 bits -@example(a=2**127 - 1) +@example(a=2 ** 127 - 1) @settings(max_examples=200, deadline=1000) def test_max_exp_int128(get_contract, assert_tx_failed, a): code = f""" @@ -139,8 +139,8 @@ def foo(b: int128) -> int128: max_power = calculate_largest_power(a, 128, True) - assert -(2**127) <= a**max_power < 2**127 - assert not -(2**127) <= a ** (max_power + 1) < 2**127 + assert -(2 ** 127) <= a ** max_power < 2 ** 127 + assert not -(2 ** 127) <= a ** (max_power + 1) < 2 ** 127 c.foo(max_power) assert_tx_failed(lambda: c.foo(max_power + 1)) diff --git a/tests/parser/features/decorators/test_payable.py b/tests/parser/features/decorators/test_payable.py index 420af1cad9..aabdfbdf37 100644 --- a/tests/parser/features/decorators/test_payable.py +++ b/tests/parser/features/decorators/test_payable.py @@ -181,7 +181,7 @@ def test_nonpayable_runtime_assertion(assert_tx_failed, get_contract, code): c = get_contract(code) c.foo(transact={"value": 0}) - assert_tx_failed(lambda: c.foo(transact={"value": 10**18})) + assert_tx_failed(lambda: c.foo(transact={"value": 10 ** 18})) payable_code = [ @@ -332,7 +332,7 @@ def bar() -> bool: def test_payable_runtime_assertion(get_contract, code): c = get_contract(code) - c.foo(transact={"value": 10**18}) + c.foo(transact={"value": 10 ** 18}) c.foo(transact={"value": 0}) diff --git a/tests/parser/features/external_contracts/test_erc20_abi.py b/tests/parser/features/external_contracts/test_erc20_abi.py index 4a09ce68fa..d054eeaee9 100644 --- a/tests/parser/features/external_contracts/test_erc20_abi.py +++ b/tests/parser/features/external_contracts/test_erc20_abi.py @@ -4,8 +4,8 @@ TOKEN_NAME = "Vypercoin" TOKEN_SYMBOL = "FANG" TOKEN_DECIMALS = 18 -TOKEN_INITIAL_SUPPLY = 21 * 10**6 -TOKEN_TOTAL_SUPPLY = TOKEN_INITIAL_SUPPLY * (10**TOKEN_DECIMALS) +TOKEN_INITIAL_SUPPLY = 21 * 10 ** 6 +TOKEN_TOTAL_SUPPLY = TOKEN_INITIAL_SUPPLY * (10 ** TOKEN_DECIMALS) @pytest.fixture diff --git a/tests/parser/features/external_contracts/test_external_contract_calls.py b/tests/parser/features/external_contracts/test_external_contract_calls.py index 524a0e958d..9fc20822e4 100644 --- a/tests/parser/features/external_contracts/test_external_contract_calls.py +++ b/tests/parser/features/external_contracts/test_external_contract_calls.py @@ -815,7 +815,7 @@ def bar(arg1: address) -> (address, Bytes[3], address): """ c2 = get_contract(contract_2) - assert c.foo() == [(2**160) - 1, b"dog", (2**160) - 2] + assert c.foo() == [(2 ** 160) - 1, b"dog", (2 ** 160) - 2] result = c2.bar(c.address) assert len(result) == 3 assert result[0].lower() == "0xffffffffffffffffffffffffffffffffffffffff" @@ -848,7 +848,7 @@ def bar(arg1: address) -> (address, Bytes[3], address): """ c2 = get_contract(contract_2) - assert c.foo() == [(2**160) - 1, b"dog", 2**160] + assert c.foo() == [(2 ** 160) - 1, b"dog", 2 ** 160] assert_tx_failed(lambda: c2.bar(c.address)) diff --git a/tests/parser/features/test_assert.py b/tests/parser/features/test_assert.py index 842b32d815..db521f556a 100644 --- a/tests/parser/features/test_assert.py +++ b/tests/parser/features/test_assert.py @@ -16,7 +16,7 @@ def foo(): """ c = get_contract_with_gas_estimation(code) a0 = w3.eth.accounts[0] - gas_sent = 10**6 + gas_sent = 10 ** 6 tx_hash = c.foo(transact={"from": a0, "gas": gas_sent, "gasPrice": 10}) # More info on receipt status: # https://github.com/ethereum/EIPs/blob/master/EIPS/eip-658.md#specification. diff --git a/tests/parser/features/test_assert_unreachable.py b/tests/parser/features/test_assert_unreachable.py index 90ed31a22e..79023a1e60 100644 --- a/tests/parser/features/test_assert_unreachable.py +++ b/tests/parser/features/test_assert_unreachable.py @@ -7,7 +7,7 @@ def foo(): c = get_contract(code) a0 = w3.eth.accounts[0] - gas_sent = 10**6 + gas_sent = 10 ** 6 tx_hash = c.foo(transact={"from": a0, "gas": gas_sent, "gasPrice": 10}) tx_receipt = w3.eth.get_transaction_receipt(tx_hash) diff --git a/tests/parser/features/test_bytes_map_keys.py b/tests/parser/features/test_bytes_map_keys.py index 4913182d52..9a648b762d 100644 --- a/tests/parser/features/test_bytes_map_keys.py +++ b/tests/parser/features/test_bytes_map_keys.py @@ -58,7 +58,7 @@ def get(k: Bytes[34]) -> int128: c = get_contract(code) - c.set(b"a" * 34, 6789, transact={"gas": 10**6}) + c.set(b"a" * 34, 6789, transact={"gas": 10 ** 6}) assert c.get(b"a" * 34) == 6789 diff --git a/tests/parser/features/test_clampers.py b/tests/parser/features/test_clampers.py index 006fb0b4e4..0df7e81c74 100644 --- a/tests/parser/features/test_clampers.py +++ b/tests/parser/features/test_clampers.py @@ -142,7 +142,7 @@ def foo(s: int{bits}) -> int{bits}: def test_sint_clamper_failing(w3, assert_tx_failed, get_contract, n, evm_version): bits = 8 * (n + 1) lo, hi = int_bounds(True, bits) - values = [-(2**255), 2**255 - 1, lo - 1, hi + 1] + values = [-(2 ** 255), 2 ** 255 - 1, lo - 1, hi + 1] code = f""" @external def foo(s: int{bits}) -> int{bits}: @@ -168,7 +168,7 @@ def foo(s: bool) -> bool: @pytest.mark.parametrize("evm_version", list(EVM_VERSIONS)) -@pytest.mark.parametrize("value", [2, 3, 4, 8, 16, 2**256 - 1]) +@pytest.mark.parametrize("value", [2, 3, 4, 8, 16, 2 ** 256 - 1]) def test_bool_clamper_failing(w3, assert_tx_failed, get_contract, value, evm_version): code = """ @external @@ -181,7 +181,7 @@ def foo(s: bool) -> bool: @pytest.mark.parametrize("evm_version", list(EVM_VERSIONS)) -@pytest.mark.parametrize("value", [0] + [2**i for i in range(5)]) +@pytest.mark.parametrize("value", [0] + [2 ** i for i in range(5)]) def test_enum_clamper_passing(w3, get_contract, value, evm_version): code = """ enum Roles: @@ -201,7 +201,7 @@ def foo(s: Roles) -> Roles: @pytest.mark.parametrize("evm_version", list(EVM_VERSIONS)) -@pytest.mark.parametrize("value", [2**i for i in range(5, 256)]) +@pytest.mark.parametrize("value", [2 ** i for i in range(5, 256)]) def test_enum_clamper_failing(w3, assert_tx_failed, get_contract, value, evm_version): code = """ enum Roles: @@ -224,7 +224,7 @@ def foo(s: Roles) -> Roles: @pytest.mark.parametrize("n", list(range(32))) def test_uint_clamper_passing(w3, get_contract, evm_version, n): bits = 8 * (n + 1) - values = [0, 1, 2**bits - 1] + values = [0, 1, 2 ** bits - 1] code = f""" @external def foo(s: uint{bits}) -> uint{bits}: @@ -240,7 +240,7 @@ def foo(s: uint{bits}) -> uint{bits}: @pytest.mark.parametrize("n", list(range(31))) # uint256 has no failing cases def test_uint_clamper_failing(w3, assert_tx_failed, get_contract, evm_version, n): bits = 8 * (n + 1) - values = [-1, -(2**255), 2**bits] + values = [-1, -(2 ** 255), 2 ** bits] code = f""" @external def foo(s: uint{bits}) -> uint{bits}: @@ -278,7 +278,7 @@ def foo(s: address) -> address: @pytest.mark.parametrize("evm_version", list(EVM_VERSIONS)) -@pytest.mark.parametrize("value", [2**160, 2**256 - 1]) +@pytest.mark.parametrize("value", [2 ** 160, 2 ** 256 - 1]) def test_address_clamper_failing(w3, assert_tx_failed, get_contract, value, evm_version): code = """ @external @@ -297,8 +297,8 @@ def foo(s: address) -> address: 0, 1, -1, - Decimal(2**167 - 1) / 10**10, - -Decimal(2**167) / 10**10, + Decimal(2 ** 167 - 1) / 10 ** 10, + -Decimal(2 ** 167) / 10 ** 10, "0.0", "1.0", "-1.0", @@ -326,8 +326,8 @@ def foo(s: decimal) -> decimal: @pytest.mark.parametrize( "value", [ - 2**167, - -(2**167 + 1), + 2 ** 167, + -(2 ** 167 + 1), 187072209578355573530071658587684226515959365500928, # 2 ** 167 -187072209578355573530071658587684226515959365500929, # - (2 ** 127 - 1e-10) ], @@ -344,7 +344,7 @@ def foo(s: decimal) -> decimal: assert_tx_failed(lambda: _make_tx(w3, c.address, "foo(fixed168x10)", [value])) -@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) def test_int128_array_clamper_passing(w3, get_contract, value): code = """ @external @@ -356,10 +356,10 @@ def foo(a: uint256, b: int128[5], c: uint256) -> int128[5]: # to ensure there are no off-by-one errors d = [value] * 5 c = get_contract(code) - assert c.foo(2**127, [value] * 5, 2**127) == d + assert c.foo(2 ** 127, [value] * 5, 2 ** 127) == d -@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) +@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) @pytest.mark.parametrize("idx", range(5)) def test_int128_array_clamper_failing(w3, assert_tx_failed, get_contract, bad_value, idx): # ensure the invalid value is detected at all locations in the array @@ -376,7 +376,7 @@ def foo(b: int128[5]) -> int128[5]: assert_tx_failed(lambda: _make_tx(w3, c.address, "foo(int128[5])", values)) -@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) def test_int128_array_looped_clamper_passing(w3, get_contract, value): # when an array is > 5 items, the arg clamper runs in a loop to reduce bytecode size code = """ @@ -387,10 +387,10 @@ def foo(a: uint256, b: int128[10], c: uint256) -> int128[10]: d = [value] * 10 c = get_contract(code) - assert c.foo(2**127, d, 2**127) == d + assert c.foo(2 ** 127, d, 2 ** 127) == d -@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) +@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) @pytest.mark.parametrize("idx", range(10)) def test_int128_array_looped_clamper_failing(w3, assert_tx_failed, get_contract, bad_value, idx): code = """ @@ -406,7 +406,7 @@ def foo(b: int128[10]) -> int128[10]: assert_tx_failed(lambda: _make_tx(w3, c.address, "foo(int128[10])", values)) -@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) def test_multidimension_array_clamper_passing(w3, get_contract, value): code = """ @external @@ -417,10 +417,10 @@ def foo(a: uint256, b: int128[6][3][1][8], c: uint256) -> int128[6][3][1][8]: # 6 * 3 * 1 * 8 = 144, the total number of values in our multidimensional array d = [[[[value] * 6] * 3] * 1] * 8 c = get_contract(code) - assert c.foo(2**127, d, 2**127, call={"gasPrice": 0}) == d + assert c.foo(2 ** 127, d, 2 ** 127, call={"gasPrice": 0}) == d -@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) +@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) @pytest.mark.parametrize("idx", range(12)) def test_multidimension_array_clamper_failing(w3, assert_tx_failed, get_contract, bad_value, idx): code = """ @@ -436,7 +436,7 @@ def foo(b: int128[6][1][2]) -> int128[6][1][2]: assert_tx_failed(lambda: _make_tx(w3, c.address, "foo(int128[6][1][2]])", values)) -@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) def test_int128_dynarray_clamper_passing(w3, get_contract, value): code = """ @external @@ -448,10 +448,10 @@ def foo(a: uint256, b: DynArray[int128, 5], c: uint256) -> DynArray[int128, 5]: # to ensure there are no off-by-one errors d = [value] * 5 c = get_contract(code) - assert c.foo(2**127, d, 2**127) == d + assert c.foo(2 ** 127, d, 2 ** 127) == d -@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) +@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) @pytest.mark.parametrize("idx", range(5)) def test_int128_dynarray_clamper_failing( w3, abi_encode, assert_tx_failed, get_contract, bad_value, idx @@ -473,7 +473,7 @@ def foo(b: int128[5]) -> int128[5]: assert_tx_failed(lambda: _make_invalid_dynarray_tx(w3, c.address, signature, data)) -@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) def test_int128_dynarray_looped_clamper_passing(w3, get_contract, value): # when an array is > 5 items, the arg clamper runs in a loop to reduce bytecode size code = """ @@ -483,10 +483,10 @@ def foo(a: uint256, b: DynArray[int128, 10], c: uint256) -> DynArray[int128, 10] """ d = [value] * 10 c = get_contract(code) - assert c.foo(2**127, d, 2**127) == d + assert c.foo(2 ** 127, d, 2 ** 127) == d -@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) +@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) @pytest.mark.parametrize("idx", range(10)) def test_int128_dynarray_looped_clamper_failing(w3, assert_tx_failed, get_contract, bad_value, idx): code = """ @@ -505,7 +505,7 @@ def foo(b: DynArray[int128, 10]) -> DynArray[int128, 10]: assert_tx_failed(lambda: _make_invalid_dynarray_tx(w3, c.address, signature, data)) -@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) def test_multidimension_dynarray_clamper_passing(w3, get_contract, value): code = """ @external @@ -519,10 +519,10 @@ def foo( # Out of gas exception if outermost length is 6 and greater d = [[[[value] * 5] * 6] * 7] * 8 c = get_contract(code) - assert c.foo(2**127, d, 2**127, call={"gasPrice": 0}) == d + assert c.foo(2 ** 127, d, 2 ** 127, call={"gasPrice": 0}) == d -@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) +@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) @pytest.mark.parametrize("idx", range(4)) def test_multidimension_dynarray_clamper_failing( w3, abi_encode, assert_tx_failed, get_contract, bad_value, idx @@ -549,7 +549,7 @@ def foo(b: DynArray[DynArray[int128, 2], 2]) -> DynArray[DynArray[int128, 2], 2] assert_tx_failed(lambda: _make_invalid_dynarray_tx(w3, c.address, signature, data)) -@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) def test_dynarray_list_clamper_passing(w3, abi_encode, get_contract, value): code = """ @external @@ -562,10 +562,10 @@ def foo( """ d = [[value] * 5] * 6 c = get_contract(code) - assert c.foo(2**127, d, 2**127) == d + assert c.foo(2 ** 127, d, 2 ** 127) == d -@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) +@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) @pytest.mark.parametrize("idx", range(10)) def test_dynarray_list_clamper_failing( w3, abi_encode, assert_tx_failed, get_contract, bad_value, idx diff --git a/tests/parser/features/test_constructor.py b/tests/parser/features/test_constructor.py index c9dfcfc5df..297e54d216 100644 --- a/tests/parser/features/test_constructor.py +++ b/tests/parser/features/test_constructor.py @@ -82,10 +82,10 @@ def foo(x: int128) -> int128: c = get_contract_with_gas_estimation(large_input_code) c.foo(1274124) - c.foo(2**120) + c.foo(2 ** 120) with pytest.raises(ValidationError): - c.foo(2**130) + c.foo(2 ** 130) def test_large_input_code_2(w3, get_contract_with_gas_estimation): @@ -102,7 +102,7 @@ def foo() -> int128: get_contract_with_gas_estimation(large_input_code_2, *[17]) with pytest.raises(TypeError): - get_contract_with_gas_estimation(large_input_code_2, *[2**130]) + get_contract_with_gas_estimation(large_input_code_2, *[2 ** 130]) print("Passed invalid input tests") diff --git a/tests/parser/features/test_immutable.py b/tests/parser/features/test_immutable.py index bb01b3fc07..4ce26ce459 100644 --- a/tests/parser/features/test_immutable.py +++ b/tests/parser/features/test_immutable.py @@ -5,8 +5,8 @@ "typ,value", [ ("uint256", 42), - ("int256", -(2**200)), - ("int128", -(2**126)), + ("int256", -(2 ** 200)), + ("int128", -(2 ** 126)), ("address", "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"), ("bytes32", b"deadbeef" * 4), ("bool", True), @@ -32,7 +32,7 @@ def get_value() -> {typ}: assert c.get_value() == value -@pytest.mark.parametrize("val", [0, 1, 2**256 - 1]) +@pytest.mark.parametrize("val", [0, 1, 2 ** 256 - 1]) def test_usage_in_constructor(get_contract, val): code = """ A: immutable(uint256) @@ -101,7 +101,7 @@ def __init__(_a: uint256, _b: uint256, _c: address, _d: int256): def get_my_struct() -> MyStruct: return my_struct """ - values = (100, 42, "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", -(2**200)) + values = (100, 42, "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", -(2 ** 200)) c = get_contract(code, *values) assert c.get_my_struct() == values diff --git a/tests/parser/functions/test_abi_decode.py b/tests/parser/functions/test_abi_decode.py index d3ffc339cf..8426b48658 100644 --- a/tests/parser/functions/test_abi_decode.py +++ b/tests/parser/functions/test_abi_decode.py @@ -284,7 +284,7 @@ def foo(bs: Bytes[160]) -> (uint256, DynArray[uint256, 3]): c = get_contract(code) bs = [1, 2, 3] encoded = abi_encode("(uint256[])", (bs,)) - assert c.foo(encoded) == [2**256 - 1, bs] + assert c.foo(encoded) == [2 ** 256 - 1, bs] def test_abi_decode_private_nested_dynarray(get_contract, abi_encode): @@ -308,7 +308,7 @@ def foo(bs: Bytes[1696]) -> (uint256, DynArray[DynArray[DynArray[uint256, 3], 3] [[19, 20, 21], [22, 23, 24], [25, 26, 27]], ] encoded = abi_encode("(uint256[][][])", (bs,)) - assert c.foo(encoded) == [2**256 - 1, bs] + assert c.foo(encoded) == [2 ** 256 - 1, bs] def test_abi_decode_return(get_contract, abi_encode): diff --git a/tests/parser/functions/test_abi_encode.py b/tests/parser/functions/test_abi_encode.py index 73227719d5..f1c2577797 100644 --- a/tests/parser/functions/test_abi_encode.py +++ b/tests/parser/functions/test_abi_encode.py @@ -82,7 +82,7 @@ def abi_encode3(x: uint256, ensure_tuple: bool, include_method_id: bool) -> Byte """ c = get_contract(code) - method_id = 0xDEADBEEF.to_bytes(4, "big") + method_id = 0xDEADBEEF .to_bytes(4, "big") # test each method once each with ensure_tuple set to True and False @@ -149,7 +149,7 @@ def abi_encode(d: DynArray[uint256, 3], ensure_tuple: bool, include_method_id: b """ c = get_contract(code) - method_id = 0xDEADBEEF.to_bytes(4, "big") + method_id = 0xDEADBEEF .to_bytes(4, "big") arg = [123, 456, 789] assert c.abi_encode(arg, False, False).hex() == abi_encode("uint256[]", arg).hex() @@ -193,7 +193,7 @@ def abi_encode( """ c = get_contract(code) - method_id = 0xDEADBEEF.to_bytes(4, "big") + method_id = 0xDEADBEEF .to_bytes(4, "big") assert c.abi_encode(args, False, False).hex() == abi_encode("uint256[][]", args).hex() assert c.abi_encode(args, True, False).hex() == abi_encode("(uint256[][])", (args,)).hex() @@ -244,7 +244,7 @@ def abi_encode( """ c = get_contract(code) - method_id = 0xDEADBEEF.to_bytes(4, "big") + method_id = 0xDEADBEEF .to_bytes(4, "big") assert c.abi_encode(args, False, False).hex() == abi_encode("uint256[][][]", args).hex() assert c.abi_encode(args, True, False).hex() == abi_encode("(uint256[][][])", (args,)).hex() @@ -285,7 +285,7 @@ def foo(addr: address) -> Bytes[164]: c2 = get_contract(contract_2) - method_id = 0xDEADBEEF.to_bytes(4, "big") + method_id = 0xDEADBEEF .to_bytes(4, "big") # call to get_counter() should be evaluated only once get_counter_encoded = abi_encode("((uint256,string))", ((1, "hello"),)) @@ -309,7 +309,7 @@ def foo(bs: Bytes[32]) -> (uint256, Bytes[96]): """ c = get_contract(code) bs = "0" * 32 - assert c.foo(bs) == [2**256 - 1, abi_encode("(bytes)", (bs,))] + assert c.foo(bs) == [2 ** 256 - 1, abi_encode("(bytes)", (bs,))] def test_abi_encode_private_dynarray(get_contract, abi_encode): @@ -326,7 +326,7 @@ def foo(bs: DynArray[uint256, 3]) -> (uint256, Bytes[160]): """ c = get_contract(code) bs = [1, 2, 3] - assert c.foo(bs) == [2**256 - 1, abi_encode("(uint256[])", (bs,))] + assert c.foo(bs) == [2 ** 256 - 1, abi_encode("(uint256[])", (bs,))] def test_abi_encode_private_nested_dynarray(get_contract, abi_encode): @@ -348,7 +348,7 @@ def foo(bs: DynArray[DynArray[DynArray[uint256, 3], 3], 3]) -> (uint256, Bytes[1 [[10, 11, 12], [13, 14, 15], [16, 17, 18]], [[19, 20, 21], [22, 23, 24], [25, 26, 27]], ] - assert c.foo(bs) == [2**256 - 1, abi_encode("(uint256[][][])", (bs,))] + assert c.foo(bs) == [2 ** 256 - 1, abi_encode("(uint256[][][])", (bs,))] @pytest.mark.parametrize("empty_literal", ('b""', '""', "empty(Bytes[1])", "empty(String[1])")) diff --git a/tests/parser/functions/test_bitwise.py b/tests/parser/functions/test_bitwise.py index 171ba7daeb..b807de2254 100644 --- a/tests/parser/functions/test_bitwise.py +++ b/tests/parser/functions/test_bitwise.py @@ -50,10 +50,10 @@ def test_test_bitwise(get_contract_with_gas_estimation, evm_version): assert c._bitwise_and(x, y) == (x & y) assert c._bitwise_or(x, y) == (x | y) assert c._bitwise_xor(x, y) == (x ^ y) - assert c._bitwise_not(x) == 2**256 - 1 - x + assert c._bitwise_not(x) == 2 ** 256 - 1 - x assert c._shift(x, 3) == x * 8 assert c._shift(x, 255) == 0 - assert c._shift(y, 255) == 2**255 + assert c._shift(y, 255) == 2 ** 255 assert c._shift(x, 256) == 0 assert c._shift(x, 0) == x assert c._shift(x, -1) == x // 2 @@ -61,7 +61,7 @@ def test_test_bitwise(get_contract_with_gas_estimation, evm_version): assert c._shift(x, -256) == 0 assert c._negatedShift(x, -3) == x * 8 assert c._negatedShift(x, -255) == 0 - assert c._negatedShift(y, -255) == 2**255 + assert c._negatedShift(y, -255) == 2 ** 255 assert c._negatedShift(x, -256) == 0 assert c._negatedShift(x, -0) == x assert c._negatedShift(x, 1) == x // 2 diff --git a/tests/parser/functions/test_ceil.py b/tests/parser/functions/test_ceil.py index c0bf45fd83..64e1f05c48 100644 --- a/tests/parser/functions/test_ceil.py +++ b/tests/parser/functions/test_ceil.py @@ -43,7 +43,7 @@ def fou() -> int256: assert c.x_ceil() == 505 assert c.foo() == 1 assert c.fop() == 1 - assert c.foq() == math.ceil(Decimal(2**167) / 10**10) + assert c.foq() == math.ceil(Decimal(2 ** 167) / 10 ** 10) assert c.fos() == 0 assert c.fou() == 4 @@ -100,7 +100,7 @@ def ceil_param(p: decimal) -> int256: assert c.fop() == -5 assert c.foq() == 0 assert c.fos() == -5472 - assert c.fot() == math.ceil(-(Decimal(2**167 - 1)) / 10**10) + assert c.fot() == math.ceil(-(Decimal(2 ** 167 - 1)) / 10 ** 10) assert c.fou() == -3 assert c.ceil_param(Decimal("-0.5")) == 0 assert c.ceil_param(Decimal("-7777777.7777777")) == -7777777 diff --git a/tests/parser/functions/test_convert.py b/tests/parser/functions/test_convert.py index 80271bb4a5..90e7f6c8ca 100644 --- a/tests/parser/functions/test_convert.py +++ b/tests/parser/functions/test_convert.py @@ -249,7 +249,7 @@ def _signextend(val_bytes, bits): as_sint = unsigned_to_signed(as_uint, bits) - return (as_sint % 2**256).to_bytes(32, byteorder="big") + return (as_sint % 2 ** 256).to_bytes(32, byteorder="big") def _convert_int_to_int(val, o_typ): @@ -472,7 +472,7 @@ def test_memory_variable_convert(x: {i_typ}) -> {o_typ}: @pytest.mark.parametrize("typ", ["uint8", "int128", "int256", "uint256"]) -@pytest.mark.parametrize("val", [1, 2, 2**128, 2**256 - 1, 2**256 - 2]) +@pytest.mark.parametrize("val", [1, 2, 2 ** 128, 2 ** 256 - 1, 2 ** 256 - 2]) def test_enum_conversion(get_contract_with_gas_estimation, assert_compile_failed, val, typ): roles = "\n ".join([f"ROLE_{i}" for i in range(256)]) contract = f""" @@ -496,7 +496,7 @@ def bar(a: uint256) -> Roles: @pytest.mark.parametrize("typ", ["uint8", "int128", "int256", "uint256"]) -@pytest.mark.parametrize("val", [1, 2, 3, 4, 2**128, 2**256 - 1, 2**256 - 2]) +@pytest.mark.parametrize("val", [1, 2, 3, 4, 2 ** 128, 2 ** 256 - 1, 2 ** 256 - 2]) def test_enum_conversion_2( get_contract_with_gas_estimation, assert_compile_failed, assert_tx_failed, val, typ ): diff --git a/tests/parser/functions/test_default_function.py b/tests/parser/functions/test_default_function.py index 35c2f7292c..6ec3ea0380 100644 --- a/tests/parser/functions/test_default_function.py +++ b/tests/parser/functions/test_default_function.py @@ -28,7 +28,7 @@ def __default__(): """ c = get_contract_with_gas_estimation(code) - logs = get_logs(w3.eth.send_transaction({"to": c.address, "value": 10**17}), c, "Sent") + logs = get_logs(w3.eth.send_transaction({"to": c.address, "value": 10 ** 17}), c, "Sent") assert w3.eth.accounts[0] == logs[0].args.sender assert w3.eth.get_balance(c.address) == w3.toWei(0.1, "ether") @@ -51,7 +51,7 @@ def __default__(): """ c = get_contract_with_gas_estimation(code) - logs = get_logs(w3.eth.send_transaction({"to": c.address, "value": 10**17}), c, "Sent") + logs = get_logs(w3.eth.send_transaction({"to": c.address, "value": 10 ** 17}), c, "Sent") assert w3.eth.accounts[0] == logs[0].args.sender assert w3.eth.get_balance(c.address) == w3.toWei(0.1, "ether") @@ -67,7 +67,7 @@ def __default__(): """ c = get_contract_with_gas_estimation(code) - assert_tx_failed(lambda: w3.eth.send_transaction({"to": c.address, "value": 10**17})) + assert_tx_failed(lambda: w3.eth.send_transaction({"to": c.address, "value": 10 ** 17})) def test_multi_arg_default(assert_compile_failed, get_contract_with_gas_estimation): diff --git a/tests/parser/functions/test_default_parameters.py b/tests/parser/functions/test_default_parameters.py index a90f5e6624..2e36c3f377 100644 --- a/tests/parser/functions/test_default_parameters.py +++ b/tests/parser/functions/test_default_parameters.py @@ -167,8 +167,8 @@ def validate_value(cls, value): monkeypatch.setattr("eth_abi.encoding.NumberEncoder.validate_value", validate_value) - assert c.bar(200, 2**127 - 1) == [200, 2**127 - 1] - assert_tx_failed(lambda: c.bar(200, 2**127)) + assert c.bar(200, 2 ** 127 - 1) == [200, 2 ** 127 - 1] + assert_tx_failed(lambda: c.bar(200, 2 ** 127)) def test_default_param_private(get_contract): diff --git a/tests/parser/functions/test_extract32.py b/tests/parser/functions/test_extract32.py index c1a333ae32..5e3b4e1984 100644 --- a/tests/parser/functions/test_extract32.py +++ b/tests/parser/functions/test_extract32.py @@ -74,7 +74,7 @@ def foq(inp: Bytes[32]) -> address: assert_tx_failed(lambda: c.foo(b"\x80" + b"\x00" * 30)) - assert c.bar(b"\x80" + b"\x00" * 31) == 2**255 + assert c.bar(b"\x80" + b"\x00" * 31) == 2 ** 255 assert c.baz(b"crow" * 8) == b"crow" * 8 assert c.fop(b"crow" * 8) == b"crow" * 8 diff --git a/tests/parser/functions/test_floor.py b/tests/parser/functions/test_floor.py index dc53545ac3..80957cb2ea 100644 --- a/tests/parser/functions/test_floor.py +++ b/tests/parser/functions/test_floor.py @@ -45,7 +45,7 @@ def fou() -> int256: assert c.x_floor() == 504 assert c.foo() == 1 assert c.fop() == 1 - assert c.foq() == math.floor(Decimal(2**167 - 1) / 10**10) + assert c.foq() == math.floor(Decimal(2 ** 167 - 1) / 10 ** 10) assert c.fos() == 0 assert c.fot() == 0 assert c.fou() == 3 @@ -104,7 +104,7 @@ def floor_param(p: decimal) -> int256: assert c.fop() == -27 assert c.foq() == -9001 assert c.fos() == -1 - assert c.fot() == math.floor(-Decimal(2**167) / 10**10) + assert c.fot() == math.floor(-Decimal(2 ** 167) / 10 ** 10) assert c.fou() == -4 assert c.floor_param(Decimal("-5.6")) == -6 assert c.floor_param(Decimal("-0.0000000001")) == -1 diff --git a/tests/parser/functions/test_interfaces.py b/tests/parser/functions/test_interfaces.py index fff2a6bda3..976d14f5d8 100644 --- a/tests/parser/functions/test_interfaces.py +++ b/tests/parser/functions/test_interfaces.py @@ -248,8 +248,8 @@ def test(): @pytest.mark.parametrize( "kwarg,typ,expected", [ - ("max_value(uint256)", "uint256", 2**256 - 1), - ("min_value(int128)", "int128", -(2**127)), + ("max_value(uint256)", "uint256", 2 ** 256 - 1), + ("min_value(int128)", "int128", -(2 ** 127)), ("empty(uint8[2])", "uint8[2]", [0, 0]), ('method_id("vyper()", output_type=bytes4)', "bytes4", b"\x82\xcbE\xfb"), ("epsilon(decimal)", "decimal", Decimal("1E-10")), @@ -371,7 +371,7 @@ def test_fail3() -> int256: interface_codes={"BadCode": {"type": "vyper", "code": external_contract}}, ) assert bad_c.ok() == 1 - assert bad_c.should_fail() == -(2**255) + assert bad_c.should_fail() == -(2 ** 255) assert c.test_ok() == 1 assert_tx_failed(lambda: c.test_fail()) diff --git a/tests/parser/functions/test_minmax.py b/tests/parser/functions/test_minmax.py index da939d605a..5c43886a08 100644 --- a/tests/parser/functions/test_minmax.py +++ b/tests/parser/functions/test_minmax.py @@ -104,11 +104,11 @@ def both_literals() -> uint256: return max(2 ** 200, 2) """ c = get_contract_with_gas_estimation(code) - assert c.foo() == 2**200 + 5 - assert c.goo() == 2**200 + 5 + assert c.foo() == 2 ** 200 + 5 + assert c.goo() == 2 ** 200 + 5 assert c.bar() == 5 + 5 assert c.baz() == 5 + 5 - assert c.both_literals() == 2**200 + assert c.both_literals() == 2 ** 200 def test_min_var_uint256_literal_int128(get_contract_with_gas_estimation): @@ -241,8 +241,8 @@ def foo4() -> uint256: c = get_contract_with_gas_estimation(code) assert c.foo1() == 0 assert c.foo2() == 0 - assert c.foo3() == 2**255 - assert c.foo4() == 2**255 + assert c.foo3() == 2 ** 255 + assert c.foo4() == 2 ** 255 def test_signed(get_contract_with_gas_estimation): @@ -265,7 +265,7 @@ def foo4() -> int128: """ c = get_contract_with_gas_estimation(code) - assert c.foo1() == -(2**127) - assert c.foo2() == -(2**127) - assert c.foo3() == 2**127 - 1 - assert c.foo4() == 2**127 - 1 + assert c.foo1() == -(2 ** 127) + assert c.foo2() == -(2 ** 127) + assert c.foo3() == 2 ** 127 - 1 + assert c.foo4() == 2 ** 127 - 1 diff --git a/tests/parser/functions/test_mkstr.py b/tests/parser/functions/test_mkstr.py index 9d2b7fe3f5..c3b998664d 100644 --- a/tests/parser/functions/test_mkstr.py +++ b/tests/parser/functions/test_mkstr.py @@ -15,7 +15,7 @@ def foo(inp: uint{bits}) -> String[{n_digits}]: """ c = get_contract_with_gas_estimation(code) - for i in [1, 2, 2**bits - 1, 0]: + for i in [1, 2, 2 ** bits - 1, 0]: assert c.foo(i) == str(i), (i, c.foo(i)) @@ -36,4 +36,4 @@ def foo(x: uint{bits}) -> uint256: return y """ c = get_contract(code) - assert c.foo(2**bits - 1) == 0, bits + assert c.foo(2 ** bits - 1) == 0, bits diff --git a/tests/parser/functions/test_slice.py b/tests/parser/functions/test_slice.py index 11d834bf42..37355f4ece 100644 --- a/tests/parser/functions/test_slice.py +++ b/tests/parser/functions/test_slice.py @@ -165,12 +165,12 @@ def foo(x: uint256, y: uint256) -> (uint256, String[12]): return dont_clobber_me, self.bytez """ c = get_contract(code) - assert c.foo(0, 12) == [2**256 - 1, "hello, world"] - assert c.foo(12, 0) == [2**256 - 1, ""] - assert c.foo(7, 5) == [2**256 - 1, "world"] - assert c.foo(0, 5) == [2**256 - 1, "hello"] - assert c.foo(0, 1) == [2**256 - 1, "h"] - assert c.foo(11, 1) == [2**256 - 1, "d"] + assert c.foo(0, 12) == [2 ** 256 - 1, "hello, world"] + assert c.foo(12, 0) == [2 ** 256 - 1, ""] + assert c.foo(7, 5) == [2 ** 256 - 1, "world"] + assert c.foo(0, 5) == [2 ** 256 - 1, "hello"] + assert c.foo(0, 1) == [2 ** 256 - 1, "h"] + assert c.foo(11, 1) == [2 ** 256 - 1, "d"] def test_slice_storage_bytes32(get_contract): diff --git a/tests/parser/functions/test_tx.py b/tests/parser/functions/test_tx.py index 3bc6ce2eff..ebec7ccdc7 100644 --- a/tests/parser/functions/test_tx.py +++ b/tests/parser/functions/test_tx.py @@ -6,4 +6,4 @@ def tx_gasprice() -> uint256: """ c = get_contract(code) for i in range(10): - assert c.tx_gasprice(call={"gasPrice": 10**i}) == 10**i + assert c.tx_gasprice(call={"gasPrice": 10 ** i}) == 10 ** i diff --git a/tests/parser/functions/test_unary.py b/tests/parser/functions/test_unary.py index da3823edfe..05c76629af 100644 --- a/tests/parser/functions/test_unary.py +++ b/tests/parser/functions/test_unary.py @@ -20,10 +20,10 @@ def negate(a: int128) -> int128: """ c = get_contract(code) # This test should revert on overflow condition - assert_tx_failed(lambda: c.negate(-(2**127))) + assert_tx_failed(lambda: c.negate(-(2 ** 127))) -@pytest.mark.parametrize("val", [-(2**127) + 1, 0, 2**127 - 1]) +@pytest.mark.parametrize("val", [-(2 ** 127) + 1, 0, 2 ** 127 - 1]) def test_unary_sub_int128_pass(get_contract, val): code = """@external def negate(a: int128) -> int128: @@ -33,8 +33,8 @@ def negate(a: int128) -> int128: assert c.negate(val) == -val -min_decimal = -(2**127) + 1 -max_decimal = 2**127 - 1 +min_decimal = -(2 ** 127) + 1 +max_decimal = 2 ** 127 - 1 @pytest.mark.parametrize("val", [min_decimal, 0, max_decimal]) @@ -79,5 +79,5 @@ def bar() -> int128: return -(a+1) """ c = get_contract(code) - assert c.foo() == -(2**127) - assert c.bar() == 2**127 - 1 + assert c.foo() == -(2 ** 127) + assert c.bar() == 2 ** 127 - 1 diff --git a/tests/parser/functions/test_unsafe_math.py b/tests/parser/functions/test_unsafe_math.py index da44000759..cafe424545 100644 --- a/tests/parser/functions/test_unsafe_math.py +++ b/tests/parser/functions/test_unsafe_math.py @@ -39,7 +39,7 @@ def foo(x: {typ}) -> {typ}: xs = [random.randrange(lo, hi) for _ in range(NUM_CASES)] ys = [random.randrange(lo, hi) for _ in range(NUM_CASES)] - mod_bound = 2**typ.bits + mod_bound = 2 ** typ.bits # poor man's fuzzing - hypothesis doesn't make it easy # with the parametrized strategy diff --git a/tests/parser/syntax/test_msg_data.py b/tests/parser/syntax/test_msg_data.py index 598b990bfc..a05184ff11 100644 --- a/tests/parser/syntax/test_msg_data.py +++ b/tests/parser/syntax/test_msg_data.py @@ -48,7 +48,7 @@ def foo(bar: uint256) -> Bytes[36]: assert contract.foo(42).hex() == expected_result -@pytest.mark.parametrize("bar", [0, 1, 42, 2**256 - 1]) +@pytest.mark.parametrize("bar", [0, 1, 42, 2 ** 256 - 1]) def test_calldata_private(get_contract, bar): code = """ @external @@ -73,7 +73,7 @@ def foo() -> (uint256, Bytes[4], uint256): """ contract = get_contract(code) - assert contract.foo() == [2**256 - 1, bytes(keccak(text="foo()")[:4]), 2**256 - 1] + assert contract.foo() == [2 ** 256 - 1, bytes(keccak(text="foo()")[:4]), 2 ** 256 - 1] def test_assignment_to_storage(w3, get_contract, keccak): diff --git a/tests/parser/types/numbers/test_constants.py b/tests/parser/types/numbers/test_constants.py index 0d5e386dad..ea56968d14 100644 --- a/tests/parser/types/numbers/test_constants.py +++ b/tests/parser/types/numbers/test_constants.py @@ -48,8 +48,8 @@ def test_arithmetic(a: int128) -> int128: assert c.test_zaddress("0x0000000000000000000000000000000000000000") is True assert c.test_zaddress("0x0000000000000000000000000000000000000012") is False - assert c.test_int128(2**127 - 1) == [True, False] - assert c.test_int128(-(2**127)) == [False, True] + assert c.test_int128(2 ** 127 - 1) == [True, False] + assert c.test_int128(-(2 ** 127)) == [False, True] assert c.test_int128(0) == [False, False] assert c.test_decimal(Decimal("18707220957835557353007165858768422651595.9365500927")) == [ @@ -62,9 +62,9 @@ def test_arithmetic(a: int128) -> int128: ] assert c.test_decimal(Decimal("0.1")) == [False, False] - assert c.test_uint256(2**256 - 1) is True + assert c.test_uint256(2 ** 256 - 1) is True - assert c.test_arithmetic(5000) == 2**127 - 1 - 5000 + assert c.test_arithmetic(5000) == 2 ** 127 - 1 - 5000 def test_builtin_constants_assignment(get_contract_with_gas_estimation): @@ -107,17 +107,17 @@ def zoo() -> uint256: c = get_contract_with_gas_estimation(code) - assert c.foo() == 2**127 - 1 - assert c.goo() == -(2**127) + assert c.foo() == 2 ** 127 - 1 + assert c.goo() == -(2 ** 127) assert c.hoo() == b"\x00" * 32 assert c.joo() is None - assert c.koo() == Decimal(2**167 - 1) / 10**10 - assert c.loo() == Decimal(-(2**167)) / 10**10 + assert c.koo() == Decimal(2 ** 167 - 1) / 10 ** 10 + assert c.loo() == Decimal(-(2 ** 167)) / 10 ** 10 - assert c.zoo() == 2**256 - 1 + assert c.zoo() == 2 ** 256 - 1 def test_custom_constants(get_contract): @@ -208,7 +208,7 @@ def test() -> uint256: ir = compile_code(code, ["ir"])["ir"] assert search_for_sublist( - ir, ["mstore", [MemoryPositions.RESERVED_MEMORY], [2**12 * some_prime]] + ir, ["mstore", [MemoryPositions.RESERVED_MEMORY], [2 ** 12 * some_prime]] ) diff --git a/tests/parser/types/numbers/test_isqrt.py b/tests/parser/types/numbers/test_isqrt.py index ce26d24d06..a98184c882 100644 --- a/tests/parser/types/numbers/test_isqrt.py +++ b/tests/parser/types/numbers/test_isqrt.py @@ -40,7 +40,7 @@ def test(a: uint256) -> uint256: val = 3333 assert c.test(val) == math.isqrt(val) - val = 10**17 + val = 10 ** 17 assert c.test(val) == math.isqrt(val) assert c.test(0) == 0 diff --git a/tests/parser/types/numbers/test_signed_ints.py b/tests/parser/types/numbers/test_signed_ints.py index 281aab429c..f0c9cfd567 100644 --- a/tests/parser/types/numbers/test_signed_ints.py +++ b/tests/parser/types/numbers/test_signed_ints.py @@ -86,7 +86,7 @@ def foo() -> int16: return y """ c = get_contract(code) - assert c.foo() == -(2**15) + assert c.foo() == -(2 ** 15) @pytest.mark.parametrize("base,power", itertools.product((-2, -1, 0, 1, 2), (0, 1))) @@ -99,7 +99,7 @@ def foo() -> int256: return x ** {power} """ c = get_contract(code) - assert c.foo() == base**power + assert c.foo() == base ** power @pytest.mark.parametrize("typ", types) @@ -118,7 +118,7 @@ def foo(x: {typ}) -> {typ}: if x * 2 >= typ.bits or x < 0: # out of bounds assert_tx_failed(lambda: c.foo(x)) else: - assert c.foo(x) == 4**x + assert c.foo(x) == 4 ** x @pytest.mark.parametrize("typ", types) diff --git a/tests/parser/types/numbers/test_unsigned_ints.py b/tests/parser/types/numbers/test_unsigned_ints.py index 97a4097923..bff9cc0ce7 100644 --- a/tests/parser/types/numbers/test_unsigned_ints.py +++ b/tests/parser/types/numbers/test_unsigned_ints.py @@ -127,7 +127,7 @@ def foo() -> {typ}: ys += [random.randrange(lo, hi) for _ in range(NUM_CASES)] # mirror signed integer tests - assert 2 ** (bits - 1) in xs and (2**bits) - 1 in ys + assert 2 ** (bits - 1) in xs and (2 ** bits) - 1 in ys for x, y in itertools.product(xs, ys): expected = fn(x, y) @@ -211,13 +211,13 @@ def _uint256_mulmod(x: uint256, y: uint256, z: uint256) -> uint256: assert c._uint256_addmod(1, 2, 2) == 1 assert c._uint256_addmod(32, 2, 32) == 2 - assert c._uint256_addmod((2**256) - 1, 0, 2) == 1 - assert c._uint256_addmod(2**255, 2**255, 6) == 4 + assert c._uint256_addmod((2 ** 256) - 1, 0, 2) == 1 + assert c._uint256_addmod(2 ** 255, 2 ** 255, 6) == 4 assert_tx_failed(lambda: c._uint256_addmod(1, 2, 0)) assert c._uint256_mulmod(3, 1, 2) == 1 assert c._uint256_mulmod(200, 3, 601) == 600 - assert c._uint256_mulmod(2**255, 1, 3) == 2 - assert c._uint256_mulmod(2**255, 2, 6) == 4 + assert c._uint256_mulmod(2 ** 255, 1, 3) == 2 + assert c._uint256_mulmod(2 ** 255, 2, 6) == 4 assert_tx_failed(lambda: c._uint256_mulmod(2, 2, 0)) diff --git a/tests/parser/types/test_bytes.py b/tests/parser/types/test_bytes.py index 555412a687..b3721af2f0 100644 --- a/tests/parser/types/test_bytes.py +++ b/tests/parser/types/test_bytes.py @@ -198,7 +198,7 @@ def testsome_storage(y: Bytes[1]) -> bool: assert c.getsome() == b"\x0e" assert c.testsome(b"a") assert c.testsome(b"\x61") - assert c.testsome(0b1100001.to_bytes(1, "big")) + assert c.testsome(0b1100001 .to_bytes(1, "big")) assert not c.testsome(b"b") assert c.testsome_storage(b"a") assert not c.testsome_storage(b"x") diff --git a/tests/parser/types/test_bytes_zero_padding.py b/tests/parser/types/test_bytes_zero_padding.py index 9bc774f12f..db9eddb615 100644 --- a/tests/parser/types/test_bytes_zero_padding.py +++ b/tests/parser/types/test_bytes_zero_padding.py @@ -26,7 +26,7 @@ def get_count(counter: uint256) -> Bytes[24]: @pytest.mark.fuzzing -@hypothesis.given(value=hypothesis.strategies.integers(min_value=0, max_value=2**64)) +@hypothesis.given(value=hypothesis.strategies.integers(min_value=0, max_value=2 ** 64)) @hypothesis.settings(deadline=400) def test_zero_pad_range(little_endian_contract, value): actual_bytes = value.to_bytes(8, byteorder="little") diff --git a/tests/parser/types/test_dynamic_array.py b/tests/parser/types/test_dynamic_array.py index 04c0688245..a2cf05aaf8 100644 --- a/tests/parser/types/test_dynamic_array.py +++ b/tests/parser/types/test_dynamic_array.py @@ -1093,7 +1093,7 @@ def foo() -> DynArray[{subtyp}, 3]: assert c.foo() == data -@pytest.mark.parametrize("subtyp,lit", [("uint8", 256), ("uint256", -1), ("int128", 2**127)]) +@pytest.mark.parametrize("subtyp,lit", [("uint8", 256), ("uint256", -1), ("int128", 2 ** 127)]) def test_append_invalid_literal(get_contract, assert_compile_failed, subtyp, lit): code = f""" @external diff --git a/tests/parser/types/test_enum.py b/tests/parser/types/test_enum.py index c66efff566..201d1ba9d0 100644 --- a/tests/parser/types/test_enum.py +++ b/tests/parser/types/test_enum.py @@ -67,11 +67,11 @@ def is_not_boss(a: Roles) -> bool: c = get_contract(code) for i in range(4): - assert c.is_boss(2**i) is False - assert c.is_not_boss(2**i) is True + assert c.is_boss(2 ** i) is False + assert c.is_not_boss(2 ** i) is True - assert c.is_boss(2**4) is True - assert c.is_not_boss(2**4) is False + assert c.is_boss(2 ** 4) is True + assert c.is_not_boss(2 ** 4) is False def test_bitwise(get_contract, assert_tx_failed): diff --git a/tests/parser/types/test_lists.py b/tests/parser/types/test_lists.py index 0715eb3870..fc17945167 100644 --- a/tests/parser/types/test_lists.py +++ b/tests/parser/types/test_lists.py @@ -652,12 +652,12 @@ def foo(x: Bar[2][2][2]) -> uint256: [ ("decimal", [5.0, 11.0, 17.0, 29.0, 37.0, 41.0]), ("uint8", [0, 1, 17, 250, 255, 2]), - ("int128", [0, -1, 1, -(2**127), 2**127 - 1, -50]), - ("int256", [0, -1, 1, -(2**255), 2**255 - 1, -50]), - ("uint256", [0, 1, 2**8, 2**255 + 1, 2**256 - 1, 100]), + ("int128", [0, -1, 1, -(2 ** 127), 2 ** 127 - 1, -50]), + ("int256", [0, -1, 1, -(2 ** 255), 2 ** 255 - 1, -50]), + ("uint256", [0, 1, 2 ** 8, 2 ** 255 + 1, 2 ** 256 - 1, 100]), ( "uint256", - [2**255 + 1, 2**255 + 2, 2**255 + 3, 2**255 + 4, 2**255 + 5, 2**255 + 6], + [2 ** 255 + 1, 2 ** 255 + 2, 2 ** 255 + 3, 2 ** 255 + 4, 2 ** 255 + 5, 2 ** 255 + 6], ), ("bool", [True, False, True, False, True, False]), ], @@ -750,15 +750,15 @@ def ix(i: uint256) -> address: [ ("decimal", [[5.0, 11.0], [17.0, 29.0], [37.0, 41.0]]), ("uint8", [[0, 1], [17, 250], [255, 2]]), - ("int128", [[0, -1], [1, -(2**127)], [2**127 - 1, -50]]), - ("int256", [[0, -1], [1, -(2**255)], [2**255 - 1, -50]]), - ("uint256", [[0, 1], [2**8, 2**255 + 1], [2**256 - 1, 100]]), + ("int128", [[0, -1], [1, -(2 ** 127)], [2 ** 127 - 1, -50]]), + ("int256", [[0, -1], [1, -(2 ** 255)], [2 ** 255 - 1, -50]]), + ("uint256", [[0, 1], [2 ** 8, 2 ** 255 + 1], [2 ** 256 - 1, 100]]), ( "uint256", [ - [2**255 + 1, 2**255 + 2], - [2**255 + 3, 2**255 + 4], - [2**255 + 5, 2**255 + 6], + [2 ** 255 + 1, 2 ** 255 + 2], + [2 ** 255 + 3, 2 ** 255 + 4], + [2 ** 255 + 5, 2 ** 255 + 6], ], ), ("bool", [[True, False], [True, False], [True, False]]), diff --git a/tests/parser/types/test_string.py b/tests/parser/types/test_string.py index 9193c5f69d..2f803837f4 100644 --- a/tests/parser/types/test_string.py +++ b/tests/parser/types/test_string.py @@ -56,7 +56,7 @@ def get(k: String[34]) -> int128: c = get_contract(code) - c.set(b"a" * 34, 6789, transact={"gas": 10**6}) + c.set(b"a" * 34, 6789, transact={"gas": 10 ** 6}) assert c.get(b"a" * 34) == 6789 diff --git a/tests/parser/types/value/test_as_wei_value.py b/tests/parser/types/value/test_as_wei_value.py index 249ac4b2ff..3fef80a967 100644 --- a/tests/parser/types/value/test_as_wei_value.py +++ b/tests/parser/types/value/test_as_wei_value.py @@ -32,10 +32,10 @@ def foo(a: uint256) -> uint256: c = get_contract(code) - value = (2**256 - 1) // (10**multiplier) - assert c.foo(value) == value * (10**multiplier) + value = (2 ** 256 - 1) // (10 ** multiplier) + assert c.foo(value) == value * (10 ** multiplier) - value = (2**256 - 1) // (10 ** (multiplier - 1)) + value = (2 ** 256 - 1) // (10 ** (multiplier - 1)) assert_tx_failed(lambda: c.foo(value)) @@ -48,9 +48,9 @@ def foo(a: int128) -> uint256: """ c = get_contract(code) - value = (2**127 - 1) // (10**multiplier) + value = (2 ** 127 - 1) // (10 ** multiplier) - assert c.foo(value) == value * (10**multiplier) + assert c.foo(value) == value * (10 ** multiplier) @pytest.mark.parametrize("denom,multiplier", wei_denoms.items()) @@ -62,12 +62,12 @@ def foo(a: decimal) -> uint256: """ c = get_contract(code) - value = Decimal((2**127 - 1) / (10**multiplier)) + value = Decimal((2 ** 127 - 1) / (10 ** multiplier)) - assert c.foo(value) == value * (10**multiplier) + assert c.foo(value) == value * (10 ** multiplier) -@pytest.mark.parametrize("value", (-1, -(2**127))) +@pytest.mark.parametrize("value", (-1, -(2 ** 127))) @pytest.mark.parametrize("data_type", ["decimal", "int128"]) def test_negative_value_reverts(get_contract, assert_tx_failed, value, data_type): code = f""" From c99bdd7107d6597f87d863dca34dc4de15fe4ba0 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Thu, 30 Mar 2023 04:59:19 +0800 Subject: [PATCH 12/14] bump black --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 1f59f035a5..39f4ab1de7 100644 --- a/setup.py +++ b/setup.py @@ -22,8 +22,7 @@ "hypothesis[lark]>=5.37.1,<6.0", ], "lint": [ - "black==21.9b0", - "click<8.1.0", # temporary pin - black21.9b0 fails with 8.1.0 + "black==23.3.0", "flake8==3.9.2", "flake8-bugbear==20.1.4", "flake8-use-fstring==1.1", From 27e7686bf46286d4ade0673db3cbef508c2d9cac Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Thu, 30 Mar 2023 04:59:28 +0800 Subject: [PATCH 13/14] fix lint --- .../ast/nodes/test_evaluate_binop_decimal.py | 4 +- tests/ast/nodes/test_evaluate_binop_int.py | 5 +- tests/ast/nodes/test_evaluate_boolop.py | 2 - tests/base_conftest.py | 4 +- tests/builtins/folding/test_abs.py | 6 +- tests/builtins/folding/test_addmod_mulmod.py | 2 +- tests/builtins/folding/test_bitwise.py | 5 +- tests/builtins/folding/test_floor_ceil.py | 2 +- .../folding/test_fold_as_wei_value.py | 2 +- tests/builtins/folding/test_keccak_sha.py | 1 - tests/builtins/folding/test_min_max.py | 4 +- tests/builtins/folding/test_powmod.py | 2 +- tests/compiler/ir/test_compile_ir.py | 4 +- tests/compiler/ir/test_optimize_ir.py | 110 +++++++++--------- tests/conftest.py | 1 - .../auctions/test_simple_open_auction.py | 8 +- tests/examples/company/test_company.py | 4 +- .../test_on_chain_market_maker.py | 6 +- .../test_safe_remote_purchase.py | 1 - tests/examples/tokens/test_erc20.py | 2 +- tests/examples/tokens/test_erc4626.py | 30 ++--- tests/examples/wallet/test_wallet.py | 8 +- .../semantics/analysis/test_array_index.py | 2 +- .../analysis/test_potential_types.py | 4 +- tests/fuzzing/test_exponents.py | 72 ++++++------ .../features/decorators/test_payable.py | 4 +- .../external_contracts/test_erc20_abi.py | 5 +- .../test_external_contract_calls.py | 7 +- tests/parser/features/test_assert.py | 2 +- .../features/test_assert_unreachable.py | 2 +- tests/parser/features/test_bytes_map_keys.py | 2 +- tests/parser/features/test_clampers.py | 64 +++++----- tests/parser/features/test_constructor.py | 6 +- tests/parser/features/test_immutable.py | 8 +- tests/parser/features/test_logging.py | 6 - tests/parser/functions/test_abi_decode.py | 4 +- tests/parser/functions/test_abi_encode.py | 16 +-- tests/parser/functions/test_bitwise.py | 6 +- tests/parser/functions/test_ceil.py | 4 +- tests/parser/functions/test_convert.py | 8 +- .../parser/functions/test_default_function.py | 6 +- .../functions/test_default_parameters.py | 4 +- tests/parser/functions/test_extract32.py | 2 +- tests/parser/functions/test_floor.py | 4 +- tests/parser/functions/test_interfaces.py | 7 +- tests/parser/functions/test_minmax.py | 18 +-- tests/parser/functions/test_mkstr.py | 4 +- tests/parser/functions/test_raw_call.py | 3 - tests/parser/functions/test_slice.py | 15 +-- tests/parser/functions/test_tx.py | 2 +- tests/parser/functions/test_unary.py | 12 +- tests/parser/functions/test_unsafe_math.py | 6 +- tests/parser/syntax/test_abi_encode.py | 1 - tests/parser/syntax/test_as_uint256.py | 1 - tests/parser/syntax/test_block.py | 1 - tests/parser/syntax/test_blockscope.py | 2 - tests/parser/syntax/test_bool.py | 1 - tests/parser/syntax/test_chainid.py | 1 - tests/parser/syntax/test_code_size.py | 1 - tests/parser/syntax/test_concat.py | 1 - tests/parser/syntax/test_extract32.py | 1 - tests/parser/syntax/test_functions_call.py | 1 - tests/parser/syntax/test_len.py | 1 - tests/parser/syntax/test_list.py | 1 - tests/parser/syntax/test_logging.py | 1 - tests/parser/syntax/test_minmax_value.py | 1 - tests/parser/syntax/test_msg_data.py | 4 +- tests/parser/syntax/test_raw_call.py | 1 - tests/parser/syntax/test_return_tuple.py | 1 - tests/parser/syntax/test_selfdestruct.py | 1 - tests/parser/syntax/test_slice.py | 1 - tests/parser/types/numbers/test_constants.py | 20 ++-- tests/parser/types/numbers/test_isqrt.py | 3 +- .../parser/types/numbers/test_signed_ints.py | 8 +- .../types/numbers/test_unsigned_ints.py | 12 +- tests/parser/types/test_bytes.py | 2 +- tests/parser/types/test_bytes_zero_padding.py | 2 +- tests/parser/types/test_dynamic_array.py | 3 +- tests/parser/types/test_enum.py | 8 +- tests/parser/types/test_lists.py | 20 ++-- tests/parser/types/test_node_types.py | 1 - tests/parser/types/test_string.py | 3 +- tests/parser/types/value/test_as_wei_value.py | 16 +-- vyper/__main__.py | 1 - vyper/ast/folding.py | 6 +- vyper/ast/natspec.py | 1 - vyper/ast/nodes.py | 4 +- vyper/ast/validation.py | 2 +- vyper/builtins/_convert.py | 6 +- vyper/builtins/_signatures.py | 1 - vyper/builtins/functions.py | 81 ++++--------- vyper/cli/vyper_compile.py | 2 - vyper/cli/vyper_json.py | 1 - vyper/cli/vyper_serve.py | 1 - vyper/codegen/abi_encoder.py | 1 - vyper/codegen/arithmetic.py | 28 +++-- vyper/codegen/core.py | 7 +- vyper/codegen/expr.py | 5 +- .../function_definitions/external_function.py | 1 - vyper/codegen/ir_node.py | 4 +- vyper/codegen/return_.py | 2 - vyper/compiler/output.py | 3 +- vyper/compiler/phases.py | 1 - vyper/ir/compile_ir.py | 6 +- vyper/ir/optimizer.py | 4 +- vyper/semantics/analysis/annotation.py | 2 - vyper/semantics/analysis/common.py | 1 - vyper/semantics/analysis/data_positions.py | 5 +- vyper/semantics/analysis/local.py | 2 - vyper/semantics/analysis/module.py | 2 - vyper/semantics/analysis/utils.py | 2 - vyper/semantics/types/function.py | 2 - vyper/semantics/types/primitives.py | 6 +- vyper/semantics/types/subscriptable.py | 3 +- vyper/semantics/types/user.py | 1 - vyper/utils.py | 34 +++--- 116 files changed, 368 insertions(+), 499 deletions(-) diff --git a/tests/ast/nodes/test_evaluate_binop_decimal.py b/tests/ast/nodes/test_evaluate_binop_decimal.py index cfe23c87f6..c6c69626b8 100644 --- a/tests/ast/nodes/test_evaluate_binop_decimal.py +++ b/tests/ast/nodes/test_evaluate_binop_decimal.py @@ -8,7 +8,7 @@ from vyper.exceptions import OverflowException, TypeMismatch, ZeroDivisionException st_decimals = st.decimals( - min_value=-(2 ** 32), max_value=2 ** 32, allow_nan=False, allow_infinity=False, places=10 + min_value=-(2**32), max_value=2**32, allow_nan=False, allow_infinity=False, places=10 ) @@ -75,7 +75,7 @@ def foo({input_value}) -> decimal: try: vy_ast.folding.replace_literal_ops(vyper_ast) expected = vyper_ast.body[0].value.value - is_valid = -(2 ** 127) <= expected < 2 ** 127 + is_valid = -(2**127) <= expected < 2**127 except (OverflowException, ZeroDivisionException): # for overflow or division/modulus by 0, expect the contract call to revert is_valid = False diff --git a/tests/ast/nodes/test_evaluate_binop_int.py b/tests/ast/nodes/test_evaluate_binop_int.py index a3f8c491f6..d632a95461 100644 --- a/tests/ast/nodes/test_evaluate_binop_int.py +++ b/tests/ast/nodes/test_evaluate_binop_int.py @@ -5,7 +5,7 @@ from vyper import ast as vy_ast from vyper.exceptions import ZeroDivisionException -st_int32 = st.integers(min_value=-(2 ** 32), max_value=2 ** 32) +st_int32 = st.integers(min_value=-(2**32), max_value=2**32) @pytest.mark.fuzzing @@ -38,7 +38,7 @@ def foo(a: int128, b: int128) -> int128: assert_tx_failed(lambda: contract.foo(left, right)) -st_uint64 = st.integers(min_value=0, max_value=2 ** 64) +st_uint64 = st.integers(min_value=0, max_value=2**64) @pytest.mark.fuzzing @@ -95,7 +95,6 @@ def foo(a: uint256, b: uint256) -> uint256: ops=st.lists(st.sampled_from("+-*/%"), min_size=11, max_size=11), ) def test_binop_nested(get_contract, assert_tx_failed, values, ops): - variables = "abcdefghij" input_value = ",".join(f"{i}: int128" for i in variables[: len(values)]) return_value = " ".join(f"{a} {b}" for a, b in zip(variables[: len(values)], ops)) diff --git a/tests/ast/nodes/test_evaluate_boolop.py b/tests/ast/nodes/test_evaluate_boolop.py index c28a706954..6bd9ecc6cb 100644 --- a/tests/ast/nodes/test_evaluate_boolop.py +++ b/tests/ast/nodes/test_evaluate_boolop.py @@ -12,7 +12,6 @@ @given(values=st.lists(st.booleans(), min_size=2, max_size=10)) @pytest.mark.parametrize("comparator", ["and", "or"]) def test_boolop_simple(get_contract, values, comparator): - input_value = ",".join(f"{i}: bool" for i in variables[: len(values)]) return_value = f" {comparator} ".join(variables[: len(values)]) @@ -39,7 +38,6 @@ def foo({input_value}) -> bool: comparators=st.lists(st.sampled_from(["and", "or"]), min_size=11, max_size=11), ) def test_boolop_nested(get_contract, values, comparators): - input_value = ",".join(f"{i}: bool" for i in variables[: len(values)]) return_value = " ".join(f"{a} {b}" for a, b in zip(variables[: len(values)], comparators)) return_value = return_value.rsplit(maxsplit=1)[0] diff --git a/tests/base_conftest.py b/tests/base_conftest.py index aa6ee55923..3263bad2b0 100644 --- a/tests/base_conftest.py +++ b/tests/base_conftest.py @@ -85,7 +85,7 @@ def _none_addr(datatype, data): def tester(): # set absurdly high gas limit so that london basefee never adjusts # (note: 2**63 - 1 is max that evm allows) - custom_genesis = PyEVMBackend._generate_genesis_params(overrides={"gas_limit": 10 ** 10}) + custom_genesis = PyEVMBackend._generate_genesis_params(overrides={"gas_limit": 10**10}) custom_genesis["base_fee_per_gas"] = 0 backend = PyEVMBackend(genesis_parameters=custom_genesis) return EthereumTester(backend=backend) @@ -114,7 +114,7 @@ def _get_contract(w3, source_code, no_optimize, *args, **kwargs): parse_vyper_source(source_code) # Test grammar. abi = out["abi"] bytecode = out["bytecode"] - value = kwargs.pop("value_in_eth", 0) * 10 ** 18 # Handle deploying with an eth value. + value = kwargs.pop("value_in_eth", 0) * 10**18 # Handle deploying with an eth value. c = w3.eth.contract(abi=abi, bytecode=bytecode) deploy_transaction = c.constructor(*args) tx_info = {"from": w3.eth.accounts[0], "value": value, "gasPrice": 0} diff --git a/tests/builtins/folding/test_abs.py b/tests/builtins/folding/test_abs.py index 058177b71c..58f861ed0c 100644 --- a/tests/builtins/folding/test_abs.py +++ b/tests/builtins/folding/test_abs.py @@ -9,7 +9,7 @@ @pytest.mark.fuzzing @settings(max_examples=50, deadline=1000) -@given(a=st.integers(min_value=-(2 ** 255) + 1, max_value=2 ** 255 - 1)) +@given(a=st.integers(min_value=-(2**255) + 1, max_value=2**255 - 1)) @example(a=0) def test_abs(get_contract, a): source = """ @@ -28,7 +28,7 @@ def foo(a: int256) -> int256: @pytest.mark.fuzzing @settings(max_examples=50, deadline=1000) -@given(a=st.integers(min_value=2 ** 255, max_value=2 ** 256 - 1)) +@given(a=st.integers(min_value=2**255, max_value=2**256 - 1)) def test_abs_upper_bound_folding(get_contract, a): source = f""" @external @@ -47,7 +47,7 @@ def foo(a: int256) -> int256: """ contract = get_contract(source) - assert_tx_failed(lambda: contract.foo(-(2 ** 255))) + assert_tx_failed(lambda: contract.foo(-(2**255))) def test_abs_lower_bound_folded(get_contract, assert_tx_failed): diff --git a/tests/builtins/folding/test_addmod_mulmod.py b/tests/builtins/folding/test_addmod_mulmod.py index c697cc6b2a..0514dea18a 100644 --- a/tests/builtins/folding/test_addmod_mulmod.py +++ b/tests/builtins/folding/test_addmod_mulmod.py @@ -5,7 +5,7 @@ from vyper import ast as vy_ast from vyper.builtins import functions as vy_fn -st_uint256 = st.integers(min_value=0, max_value=2 ** 256 - 1) +st_uint256 = st.integers(min_value=0, max_value=2**256 - 1) @pytest.mark.fuzzing diff --git a/tests/builtins/folding/test_bitwise.py b/tests/builtins/folding/test_bitwise.py index 7d3f85592f..9be0b6817d 100644 --- a/tests/builtins/folding/test_bitwise.py +++ b/tests/builtins/folding/test_bitwise.py @@ -5,7 +5,7 @@ from vyper import ast as vy_ast from vyper.builtins import functions as vy_fn -st_uint256 = st.integers(min_value=0, max_value=2 ** 256 - 1) +st_uint256 = st.integers(min_value=0, max_value=2**256 - 1) @pytest.mark.fuzzing @@ -13,7 +13,6 @@ @given(a=st_uint256, b=st_uint256) @pytest.mark.parametrize("op", ["&", "|", "^"]) def test_bitwise_and_or(get_contract, a, b, op): - source = f""" @external def foo(a: uint256, b: uint256) -> uint256: @@ -32,7 +31,6 @@ def foo(a: uint256, b: uint256) -> uint256: @settings(max_examples=50, deadline=1000) @given(value=st_uint256) def test_bitwise_not(get_contract, value): - source = """ @external def foo(a: uint256) -> uint256: @@ -51,7 +49,6 @@ def foo(a: uint256) -> uint256: @settings(max_examples=50, deadline=1000) @given(value=st_uint256, steps=st.integers(min_value=-256, max_value=256)) def test_shift(get_contract, value, steps): - source = """ @external def foo(a: uint256, b: int128) -> uint256: diff --git a/tests/builtins/folding/test_floor_ceil.py b/tests/builtins/folding/test_floor_ceil.py index 1e834e4d6e..763f8fec63 100644 --- a/tests/builtins/folding/test_floor_ceil.py +++ b/tests/builtins/folding/test_floor_ceil.py @@ -8,7 +8,7 @@ from vyper.builtins import functions as vy_fn st_decimals = st.decimals( - min_value=-(2 ** 32), max_value=2 ** 32, allow_nan=False, allow_infinity=False, places=10 + min_value=-(2**32), max_value=2**32, allow_nan=False, allow_infinity=False, places=10 ) diff --git a/tests/builtins/folding/test_fold_as_wei_value.py b/tests/builtins/folding/test_fold_as_wei_value.py index 61818e291a..11d23bd3bf 100644 --- a/tests/builtins/folding/test_fold_as_wei_value.py +++ b/tests/builtins/folding/test_fold_as_wei_value.py @@ -39,7 +39,7 @@ def foo(a: decimal) -> uint256: @pytest.mark.fuzzing @settings(max_examples=10, deadline=1000) -@given(value=st.integers(min_value=0, max_value=2 ** 128)) +@given(value=st.integers(min_value=0, max_value=2**128)) @pytest.mark.parametrize("denom", denoms) def test_integer(get_contract, value, denom): source = f""" diff --git a/tests/builtins/folding/test_keccak_sha.py b/tests/builtins/folding/test_keccak_sha.py index e6cf1d1581..8e283566de 100644 --- a/tests/builtins/folding/test_keccak_sha.py +++ b/tests/builtins/folding/test_keccak_sha.py @@ -13,7 +13,6 @@ @settings(max_examples=50, deadline=1000) @pytest.mark.parametrize("fn_name", ["keccak256", "sha256"]) def test_string(get_contract, value, fn_name): - source = f""" @external def foo(a: String[100]) -> bytes32: diff --git a/tests/builtins/folding/test_min_max.py b/tests/builtins/folding/test_min_max.py index 13f5dd0537..e2d33237ca 100644 --- a/tests/builtins/folding/test_min_max.py +++ b/tests/builtins/folding/test_min_max.py @@ -13,8 +13,8 @@ allow_infinity=False, places=10, ) -st_int128 = st.integers(min_value=-(2 ** 127), max_value=2 ** 127 - 1) -st_uint256 = st.integers(min_value=0, max_value=2 ** 256 - 1) +st_int128 = st.integers(min_value=-(2**127), max_value=2**127 - 1) +st_uint256 = st.integers(min_value=0, max_value=2**256 - 1) @pytest.mark.fuzzing diff --git a/tests/builtins/folding/test_powmod.py b/tests/builtins/folding/test_powmod.py index 3ea96bfbed..fdc0e300ab 100644 --- a/tests/builtins/folding/test_powmod.py +++ b/tests/builtins/folding/test_powmod.py @@ -5,7 +5,7 @@ from vyper import ast as vy_ast from vyper.builtins import functions as vy_fn -st_uint256 = st.integers(min_value=0, max_value=2 ** 256) +st_uint256 = st.integers(min_value=0, max_value=2**256) @pytest.mark.fuzzing diff --git a/tests/compiler/ir/test_compile_ir.py b/tests/compiler/ir/test_compile_ir.py index 03c4f33095..91007da33a 100644 --- a/tests/compiler/ir/test_compile_ir.py +++ b/tests/compiler/ir/test_compile_ir.py @@ -5,8 +5,8 @@ from vyper.ir.s_expressions import parse_s_exp fail_list = [ - [-(2 ** 255) - 3], - [2 ** 256 + 3], + [-(2**255) - 3], + [2**256 + 3], ["set", "_poz"], [["set", "var_1", 0, 0]], ["with", "var_1", 0, ["set", 1, 1]], diff --git a/tests/compiler/ir/test_optimize_ir.py b/tests/compiler/ir/test_optimize_ir.py index 6c4cf50fc1..bac0e18d65 100644 --- a/tests/compiler/ir/test_optimize_ir.py +++ b/tests/compiler/ir/test_optimize_ir.py @@ -34,23 +34,23 @@ # conditions (["ge", "x", 0], [1]), # x >= 0 == True (["ge", ["sload", 0], 0], None), # no-op - (["gt", "x", 2 ** 256 - 1], [0]), # x >= MAX_UINT256 == False + (["gt", "x", 2**256 - 1], [0]), # x >= MAX_UINT256 == False # (x > 0) => x == 0 (["iszero", ["gt", "x", 0]], ["iszero", ["iszero", ["iszero", "x"]]]), # !(x < MAX_UINT256) => x == MAX_UINT256 - (["iszero", ["lt", "x", 2 ** 256 - 1]], ["iszero", ["iszero", ["iszero", ["not", "x"]]]]), + (["iszero", ["lt", "x", 2**256 - 1]], ["iszero", ["iszero", ["iszero", ["not", "x"]]]]), # !(x < MAX_INT256) => x == MAX_INT256 ( - ["iszero", ["slt", "x", 2 ** 255 - 1]], - ["iszero", ["iszero", ["iszero", ["xor", "x", 2 ** 255 - 1]]]], + ["iszero", ["slt", "x", 2**255 - 1]], + ["iszero", ["iszero", ["iszero", ["xor", "x", 2**255 - 1]]]], ), # !(x > MIN_INT256) => x == MIN_INT256 ( - ["iszero", ["sgt", "x", -(2 ** 255)]], - ["iszero", ["iszero", ["iszero", ["xor", "x", -(2 ** 255)]]]], + ["iszero", ["sgt", "x", -(2**255)]], + ["iszero", ["iszero", ["iszero", ["xor", "x", -(2**255)]]]], ), - (["sgt", "x", 2 ** 255 - 1], [0]), # signed x > MAX_INT256 == False - (["sge", "x", 2 ** 255 - 1], ["eq", "x", 2 ** 255 - 1]), + (["sgt", "x", 2**255 - 1], [0]), # signed x > MAX_INT256 == False + (["sge", "x", 2**255 - 1], ["eq", "x", 2**255 - 1]), (["eq", -1, "x"], ["iszero", ["not", "x"]]), (["iszero", ["eq", -1, "x"]], ["iszero", ["iszero", ["not", "x"]]]), (["le", "x", 0], ["iszero", "x"]), @@ -58,10 +58,10 @@ (["le", 0, ["sload", 0]], None), # no-op (["ge", "x", 0], [1]), # boundary conditions - (["slt", "x", -(2 ** 255)], [0]), - (["sle", "x", -(2 ** 255)], ["eq", "x", -(2 ** 255)]), - (["lt", "x", 2 ** 256 - 1], None), - (["le", "x", 2 ** 256 - 1], [1]), + (["slt", "x", -(2**255)], [0]), + (["sle", "x", -(2**255)], ["eq", "x", -(2**255)]), + (["lt", "x", 2**256 - 1], None), + (["le", "x", 2**256 - 1], [1]), (["gt", "x", 0], ["iszero", ["iszero", "x"]]), # x < 0 => false (["lt", "x", 0], [0]), @@ -73,18 +73,18 @@ (["slt", "x", 1], None), (["gt", "x", 1], None), (["sgt", "x", 1], None), - (["gt", "x", 2 ** 256 - 2], ["iszero", ["not", "x"]]), - (["lt", "x", 2 ** 256 - 2], None), - (["slt", "x", 2 ** 256 - 2], None), - (["sgt", "x", 2 ** 256 - 2], None), - (["slt", "x", -(2 ** 255) + 1], ["eq", "x", -(2 ** 255)]), - (["sgt", "x", -(2 ** 255) + 1], None), - (["lt", "x", -(2 ** 255) + 1], None), - (["gt", "x", -(2 ** 255) + 1], None), - (["sgt", "x", 2 ** 255 - 2], ["eq", "x", 2 ** 255 - 1]), - (["slt", "x", 2 ** 255 - 2], None), - (["gt", "x", 2 ** 255 - 2], None), - (["lt", "x", 2 ** 255 - 2], None), + (["gt", "x", 2**256 - 2], ["iszero", ["not", "x"]]), + (["lt", "x", 2**256 - 2], None), + (["slt", "x", 2**256 - 2], None), + (["sgt", "x", 2**256 - 2], None), + (["slt", "x", -(2**255) + 1], ["eq", "x", -(2**255)]), + (["sgt", "x", -(2**255) + 1], None), + (["lt", "x", -(2**255) + 1], None), + (["gt", "x", -(2**255) + 1], None), + (["sgt", "x", 2**255 - 2], ["eq", "x", 2**255 - 1]), + (["slt", "x", 2**255 - 2], None), + (["gt", "x", 2**255 - 2], None), + (["lt", "x", 2**255 - 2], None), # 5 > x; x < 5; x <= 4 (["iszero", ["gt", 5, "x"]], ["iszero", ["le", "x", 4]]), (["iszero", ["ge", 5, "x"]], None), @@ -109,18 +109,18 @@ # 5 <= x; x >= 5; x > 4 (["sle", 5, "x"], ["sgt", "x", 4]), # tricky constant folds - (["sgt", 2 ** 256 - 1, 0], [0]), # -1 > 0 - (["gt", 2 ** 256 - 1, 0], [1]), # -1 > 0 - (["gt", 2 ** 255, 0], [1]), # 0x80 > 0 - (["sgt", 2 ** 255, 0], [0]), # 0x80 > 0 - (["sgt", 2 ** 255, 2 ** 255 - 1], [0]), # 0x80 > 0x81 - (["gt", -(2 ** 255), 2 ** 255 - 1], [1]), # 0x80 > 0x81 - (["slt", 2 ** 255, 2 ** 255 - 1], [1]), # 0x80 < 0x7f - (["lt", -(2 ** 255), 2 ** 255 - 1], [0]), # 0x80 < 0x7f - (["sle", -1, 2 ** 256 - 1], [1]), # -1 <= -1 - (["sge", -(2 ** 255), 2 ** 255], [1]), # 0x80 >= 0x80 - (["sgt", -(2 ** 255), 2 ** 255], [0]), # 0x80 > 0x80 - (["slt", 2 ** 255, -(2 ** 255)], [0]), # 0x80 < 0x80 + (["sgt", 2**256 - 1, 0], [0]), # -1 > 0 + (["gt", 2**256 - 1, 0], [1]), # -1 > 0 + (["gt", 2**255, 0], [1]), # 0x80 > 0 + (["sgt", 2**255, 0], [0]), # 0x80 > 0 + (["sgt", 2**255, 2**255 - 1], [0]), # 0x80 > 0x81 + (["gt", -(2**255), 2**255 - 1], [1]), # 0x80 > 0x81 + (["slt", 2**255, 2**255 - 1], [1]), # 0x80 < 0x7f + (["lt", -(2**255), 2**255 - 1], [0]), # 0x80 < 0x7f + (["sle", -1, 2**256 - 1], [1]), # -1 <= -1 + (["sge", -(2**255), 2**255], [1]), # 0x80 >= 0x80 + (["sgt", -(2**255), 2**255], [0]), # 0x80 > 0x80 + (["slt", 2**255, -(2**255)], [0]), # 0x80 < 0x80 # arithmetic (["ceil32", "x"], None), (["ceil32", 0], [0]), @@ -159,17 +159,17 @@ (["mod", "x", 128], ["and", "x", 127]), (["sdiv", "x", 64], None), (["smod", "x", 64], None), - (["exp", 3, 5], [3 ** 5]), - (["exp", 3, 256], [(3 ** 256) % (2 ** 256)]), + (["exp", 3, 5], [3**5]), + (["exp", 3, 256], [(3**256) % (2**256)]), (["exp", 2, 257], [0]), (["exp", "x", 0], [1]), (["exp", "x", 1], ["x"]), (["exp", 1, "x"], [1]), (["exp", 0, "x"], ["iszero", "x"]), # bitwise ops - (["xor", "x", 2 ** 256 - 1], ["not", "x"]), - (["and", "x", 2 ** 256 - 1], ["x"]), - (["or", "x", 2 ** 256 - 1], [2 ** 256 - 1]), + (["xor", "x", 2**256 - 1], ["not", "x"]), + (["and", "x", 2**256 - 1], ["x"]), + (["or", "x", 2**256 - 1], [2**256 - 1]), (["shr", 0, "x"], ["x"]), (["sar", 0, "x"], ["x"]), (["shl", 0, "x"], ["x"]), @@ -195,12 +195,12 @@ (["iszero", ["or", 1, ["sload", 0]]], None), # nested optimizations (["eq", 0, ["sub", 1, 1]], [1]), - (["eq", 0, ["add", 2 ** 255, 2 ** 255]], [1]), # test compile-time wrapping - (["eq", 0, ["add", 2 ** 255, -(2 ** 255)]], [1]), # test compile-time wrapping + (["eq", 0, ["add", 2**255, 2**255]], [1]), # test compile-time wrapping + (["eq", 0, ["add", 2**255, -(2**255)]], [1]), # test compile-time wrapping (["eq", -1, ["add", 0, -1]], [1]), # test compile-time wrapping - (["eq", -1, ["add", 2 ** 255, 2 ** 255 - 1]], [1]), # test compile-time wrapping - (["eq", -1, ["add", -(2 ** 255), 2 ** 255 - 1]], [1]), # test compile-time wrapping - (["eq", -2, ["add", 2 ** 256 - 1, 2 ** 256 - 1]], [1]), # test compile-time wrapping + (["eq", -1, ["add", 2**255, 2**255 - 1]], [1]), # test compile-time wrapping + (["eq", -1, ["add", -(2**255), 2**255 - 1]], [1]), # test compile-time wrapping + (["eq", -2, ["add", 2**256 - 1, 2**256 - 1]], [1]), # test compile-time wrapping (["eq", "x", "x"], [1]), (["eq", "callvalue", "callvalue"], None), (["ne", "x", "x"], [0]), @@ -229,23 +229,23 @@ def test_ir_optimizer(ir): ["assert", ["lt", 1, 1]], ["assert", ["lt", "x", 0]], # +x < 0 ["assert", ["le", 1, 0]], - ["assert", ["le", 2 ** 256 - 1, 0]], + ["assert", ["le", 2**256 - 1, 0]], ["assert", ["gt", 1, 2]], ["assert", ["gt", 1, 1]], - ["assert", ["gt", 0, 2 ** 256 - 1]], - ["assert", ["gt", "x", 2 ** 256 - 1]], + ["assert", ["gt", 0, 2**256 - 1]], + ["assert", ["gt", "x", 2**256 - 1]], ["assert", ["ge", 1, 2]], ["assert", ["ge", 1, 2]], ["assert", ["slt", 2, 1]], ["assert", ["slt", 1, 1]], - ["assert", ["slt", 0, 2 ** 256 - 1]], # 0 < -1 - ["assert", ["slt", -(2 ** 255), 2 ** 255]], # 0x80 < 0x80 - ["assert", ["sle", 0, 2 ** 255]], # 0 < 0x80 + ["assert", ["slt", 0, 2**256 - 1]], # 0 < -1 + ["assert", ["slt", -(2**255), 2**255]], # 0x80 < 0x80 + ["assert", ["sle", 0, 2**255]], # 0 < 0x80 ["assert", ["sgt", 1, 2]], ["assert", ["sgt", 1, 1]], - ["assert", ["sgt", 2 ** 256 - 1, 0]], # -1 > 0 - ["assert", ["sgt", 2 ** 255, -(2 ** 255)]], # 0x80 > 0x80 - ["assert", ["sge", 2 ** 255, 0]], # 0x80 > 0 + ["assert", ["sgt", 2**256 - 1, 0]], # -1 > 0 + ["assert", ["sgt", 2**255, -(2**255)]], # 0x80 > 0x80 + ["assert", ["sge", 2**255, 0]], # 0x80 > 0 ] diff --git a/tests/conftest.py b/tests/conftest.py index 881058aa36..a8d4005059 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -148,7 +148,6 @@ def set_decorator_to_contract_function(w3, tester, contract, source_code, func): @pytest.fixture def get_contract_with_gas_estimation(tester, w3, no_optimize): def get_contract_with_gas_estimation(source_code, *args, **kwargs): - contract = _get_contract(w3, source_code, no_optimize, *args, **kwargs) for abi in contract._classic_contract.functions.abi: if abi["type"] == "function": diff --git a/tests/examples/auctions/test_simple_open_auction.py b/tests/examples/auctions/test_simple_open_auction.py index 21aeb4d4a7..cf0bb8cc20 100644 --- a/tests/examples/auctions/test_simple_open_auction.py +++ b/tests/examples/auctions/test_simple_open_auction.py @@ -56,9 +56,9 @@ def test_bid(w3, tester, auction_contract, assert_tx_failed): # Check that highest bidder and highest bid have changed accordingly assert auction_contract.highestBidder() == k5 assert auction_contract.highestBid() == 5 - auction_contract.bid(transact={"value": 1 * 10 ** 10, "from": k1}) + auction_contract.bid(transact={"value": 1 * 10**10, "from": k1}) pending_return_before_outbid = auction_contract.pendingReturns(k1) - auction_contract.bid(transact={"value": 2 * 10 ** 10, "from": k2}) + auction_contract.bid(transact={"value": 2 * 10**10, "from": k2}) pending_return_after_outbid = auction_contract.pendingReturns(k1) # Account has a greater pending return balance after being outbid assert pending_return_after_outbid > pending_return_before_outbid @@ -76,7 +76,7 @@ def test_end_auction(w3, tester, auction_contract, assert_tx_failed): k1, k2, k3, k4, k5 = w3.eth.accounts[:5] # Fails if auction end time has not been reached assert_tx_failed(lambda: auction_contract.endAuction()) - auction_contract.bid(transact={"value": 1 * 10 ** 10, "from": k2}) + auction_contract.bid(transact={"value": 1 * 10**10, "from": k2}) # Move block timestamp foreward to reach auction end time # tester.time_travel(tester.get_block_by_number('latest')['timestamp'] + EXPIRY) w3.testing.mine(EXPIRY) @@ -84,7 +84,7 @@ def test_end_auction(w3, tester, auction_contract, assert_tx_failed): auction_contract.endAuction(transact={"from": k2}) balance_after_end = w3.eth.get_balance(k1) # Beneficiary receives the highest bid - assert balance_after_end == balance_before_end + 1 * 10 ** 10 + assert balance_after_end == balance_before_end + 1 * 10**10 # Bidder cannot bid after auction end time has been reached assert_tx_failed(lambda: auction_contract.bid(transact={"value": 10, "from": k1})) # Auction cannot be ended twice diff --git a/tests/examples/company/test_company.py b/tests/examples/company/test_company.py index d281652e5a..71141b8bb5 100644 --- a/tests/examples/company/test_company.py +++ b/tests/examples/company/test_company.py @@ -5,7 +5,7 @@ def c(w3, get_contract): with open("examples/stock/company.vy") as f: contract_code = f.read() - contract = get_contract(contract_code, *[w3.eth.accounts[0], 1000, 10 ** 6]) + contract = get_contract(contract_code, *[w3.eth.accounts[0], 1000, 10**6]) return contract @@ -107,7 +107,7 @@ def test_logs(w3, c, get_logs): assert logs[0].args.value == 4 # Pay is logged - amount = 10 ** 4 + amount = 10**4 logs = get_logs(c.payBill(a3, amount, transact={}), c, "Pay") assert len(logs) == 1 assert logs[0].args.amount == amount diff --git a/tests/examples/market_maker/test_on_chain_market_maker.py b/tests/examples/market_maker/test_on_chain_market_maker.py index fdbf59370f..546ecc15a8 100644 --- a/tests/examples/market_maker/test_on_chain_market_maker.py +++ b/tests/examples/market_maker/test_on_chain_market_maker.py @@ -11,8 +11,8 @@ def market_maker(get_contract): TOKEN_NAME = "Vypercoin" TOKEN_SYMBOL = "FANG" TOKEN_DECIMALS = 18 -TOKEN_INITIAL_SUPPLY = 21 * 10 ** 6 -TOKEN_TOTAL_SUPPLY = TOKEN_INITIAL_SUPPLY * (10 ** TOKEN_DECIMALS) +TOKEN_INITIAL_SUPPLY = 21 * 10**6 +TOKEN_TOTAL_SUPPLY = TOKEN_INITIAL_SUPPLY * (10**TOKEN_DECIMALS) @pytest.fixture @@ -39,7 +39,7 @@ def test_initiate(w3, market_maker, erc20, assert_tx_failed): ) assert market_maker.totalEthQty() == w3.toWei(2, "ether") assert market_maker.totalTokenQty() == w3.toWei(1, "ether") - assert market_maker.invariant() == 2 * 10 ** 36 + assert market_maker.invariant() == 2 * 10**36 assert market_maker.owner() == a0 assert erc20.name() == TOKEN_NAME assert erc20.decimals() == TOKEN_DECIMALS diff --git a/tests/examples/safe_remote_purchase/test_safe_remote_purchase.py b/tests/examples/safe_remote_purchase/test_safe_remote_purchase.py index 50aa873397..5cd80a989a 100644 --- a/tests/examples/safe_remote_purchase/test_safe_remote_purchase.py +++ b/tests/examples/safe_remote_purchase/test_safe_remote_purchase.py @@ -100,7 +100,6 @@ def test_received(w3, get_contract, assert_tx_failed, get_balance, contract_code def test_received_reentrancy(w3, get_contract, assert_tx_failed, get_balance, contract_code): - buyer_contract_code = """ interface PurchaseContract: diff --git a/tests/examples/tokens/test_erc20.py b/tests/examples/tokens/test_erc20.py index c693959309..cba7769bae 100644 --- a/tests/examples/tokens/test_erc20.py +++ b/tests/examples/tokens/test_erc20.py @@ -5,7 +5,7 @@ from web3.exceptions import ValidationError ZERO_ADDRESS = "0x0000000000000000000000000000000000000000" -MAX_UINT256 = (2 ** 256) - 1 # Max uint256 value +MAX_UINT256 = (2**256) - 1 # Max uint256 value TOKEN_NAME = "Vypercoin" TOKEN_SYMBOL = "FANG" TOKEN_DECIMALS = 18 diff --git a/tests/examples/tokens/test_erc4626.py b/tests/examples/tokens/test_erc4626.py index a8e57e7eff..2469a7abd0 100644 --- a/tests/examples/tokens/test_erc4626.py +++ b/tests/examples/tokens/test_erc4626.py @@ -1,6 +1,6 @@ import pytest -AMOUNT = 100 * 10 ** 18 +AMOUNT = 100 * 10**18 TOKEN_NAME = "Vypercoin" TOKEN_SYMBOL = "FANG" TOKEN_DECIMALS = 18 @@ -28,18 +28,18 @@ def test_asset(vault, token): def test_max_methods(w3, vault): a = w3.eth.accounts[0] - assert vault.maxDeposit(a) == 2 ** 256 - 1 - assert vault.maxMint(a) == 2 ** 256 - 1 - assert vault.maxWithdraw(a) == 2 ** 256 - 1 - assert vault.maxRedeem(a) == 2 ** 256 - 1 + assert vault.maxDeposit(a) == 2**256 - 1 + assert vault.maxMint(a) == 2**256 - 1 + assert vault.maxWithdraw(a) == 2**256 - 1 + assert vault.maxRedeem(a) == 2**256 - 1 def test_preview_methods(w3, token, vault): a = w3.eth.accounts[0] assert vault.totalAssets() == 0 - assert vault.convertToAssets(10 ** 18) == 0 # no assets - assert vault.convertToShares(10 ** 18) == 10 ** 18 # 1:1 price + assert vault.convertToAssets(10**18) == 0 # no assets + assert vault.convertToShares(10**18) == 10**18 # 1:1 price assert vault.previewDeposit(AMOUNT) == AMOUNT # 1:1 price assert vault.previewMint(AMOUNT) == AMOUNT # 1:1 price assert vault.previewWithdraw(AMOUNT) == 0 # but no assets @@ -50,8 +50,8 @@ def test_preview_methods(w3, token, vault): vault.deposit(AMOUNT, transact={"from": a}) assert vault.totalAssets() == AMOUNT - assert vault.convertToAssets(10 ** 18) == 10 ** 18 # 1:1 price - assert vault.convertToShares(10 ** 18) == 10 ** 18 # 1:1 price + assert vault.convertToAssets(10**18) == 10**18 # 1:1 price + assert vault.convertToShares(10**18) == 10**18 # 1:1 price assert vault.previewDeposit(AMOUNT) == AMOUNT # 1:1 price assert vault.previewMint(AMOUNT) == AMOUNT # 1:1 price assert vault.previewWithdraw(AMOUNT) == AMOUNT # 1:1 price @@ -60,8 +60,8 @@ def test_preview_methods(w3, token, vault): token.mint(vault.address, AMOUNT, transact={"from": a}) assert vault.totalAssets() == 2 * AMOUNT - assert vault.convertToAssets(10 ** 18) == 2 * 10 ** 18 # 2:1 price - assert vault.convertToShares(2 * 10 ** 18) == 10 ** 18 # 2:1 price + assert vault.convertToAssets(10**18) == 2 * 10**18 # 2:1 price + assert vault.convertToShares(2 * 10**18) == 10**18 # 2:1 price assert vault.previewDeposit(AMOUNT) == AMOUNT // 2 # 2:1 price assert vault.previewMint(AMOUNT // 2) == AMOUNT # 2:1 price assert vault.previewWithdraw(AMOUNT) == AMOUNT // 2 # 2:1 price @@ -70,8 +70,8 @@ def test_preview_methods(w3, token, vault): vault.DEBUG_steal_tokens(AMOUNT, transact={"from": a}) assert vault.totalAssets() == AMOUNT - assert vault.convertToAssets(10 ** 18) == 10 ** 18 # 1:1 price - assert vault.convertToShares(10 ** 18) == 10 ** 18 # 1:1 price + assert vault.convertToAssets(10**18) == 10**18 # 1:1 price + assert vault.convertToShares(10**18) == 10**18 # 1:1 price assert vault.previewDeposit(AMOUNT) == AMOUNT # 1:1 price assert vault.previewMint(AMOUNT) == AMOUNT # 1:1 price assert vault.previewWithdraw(AMOUNT) == AMOUNT # 1:1 price @@ -80,8 +80,8 @@ def test_preview_methods(w3, token, vault): vault.DEBUG_steal_tokens(AMOUNT // 2, transact={"from": a}) assert vault.totalAssets() == AMOUNT // 2 - assert vault.convertToAssets(10 ** 18) == 10 ** 18 // 2 # 1:2 price - assert vault.convertToShares(10 ** 18 // 2) == 10 ** 18 # 1:2 price + assert vault.convertToAssets(10**18) == 10**18 // 2 # 1:2 price + assert vault.convertToShares(10**18 // 2) == 10**18 # 1:2 price assert vault.previewDeposit(AMOUNT) == 2 * AMOUNT # 1:2 price assert vault.previewMint(2 * AMOUNT) == AMOUNT # 1:2 price assert vault.previewWithdraw(AMOUNT) == 2 * AMOUNT # 1:2 price diff --git a/tests/examples/wallet/test_wallet.py b/tests/examples/wallet/test_wallet.py index c15f74ffe5..8114006f28 100644 --- a/tests/examples/wallet/test_wallet.py +++ b/tests/examples/wallet/test_wallet.py @@ -11,7 +11,7 @@ def c(w3, get_contract): code = f.read() # Sends wei to the contract for future transactions gas costs c = get_contract(code, *[[a1, a2, a3, a4, a5], 3]) - w3.eth.send_transaction({"to": c.address, "value": 10 ** 17}) + w3.eth.send_transaction({"to": c.address, "value": 10**17}) return c @@ -32,7 +32,7 @@ def test_approve(w3, c, tester, assert_tx_failed, sign): a0, a1, a2, a3, a4, a5, a6 = w3.eth.accounts[:7] k0, k1, k2, k3, k4, k5, k6, k7 = tester.backend.account_keys[:8] - to, value, data = b"\x35" * 20, 10 ** 16, b"" + to, value, data = b"\x35" * 20, 10**16, b"" to_address = w3.toChecksumAddress(to) def pack_and_sign(seq, *args): @@ -110,12 +110,12 @@ def test_javascript_signatures(w3, get_contract): owners = [w3.toChecksumAddress(x) for x in accounts + [a3, zero_address, zero_address]] x2 = get_contract(f.read(), *[owners, 2]) - w3.eth.send_transaction({"to": x2.address, "value": 10 ** 17}) + w3.eth.send_transaction({"to": x2.address, "value": 10**17}) # There's no need to pass in signatures because the owners are 0 addresses # causing them to default to valid signatures x2.approve( - 0, recipient, 25, b"", sigs + [[0, 0, 0]] * 3, call={"to": x2.address, "value": 10 ** 17} + 0, recipient, 25, b"", sigs + [[0, 0, 0]] * 3, call={"to": x2.address, "value": 10**17} ) print("Javascript signature tests passed") diff --git a/tests/functional/semantics/analysis/test_array_index.py b/tests/functional/semantics/analysis/test_array_index.py index e025dde2f5..27c0634cf8 100644 --- a/tests/functional/semantics/analysis/test_array_index.py +++ b/tests/functional/semantics/analysis/test_array_index.py @@ -41,7 +41,7 @@ def foo(): validate_semantics(vyper_module, {}) -@pytest.mark.parametrize("value", [-1, 3, -(2 ** 127), 2 ** 127 - 1, 2 ** 256 - 1]) +@pytest.mark.parametrize("value", [-1, 3, -(2**127), 2**127 - 1, 2**256 - 1]) def test_out_of_bounds(namespace, value): code = f""" diff --git a/tests/functional/semantics/analysis/test_potential_types.py b/tests/functional/semantics/analysis/test_potential_types.py index 0fe44a1d41..74cdc9ae0f 100644 --- a/tests/functional/semantics/analysis/test_potential_types.py +++ b/tests/functional/semantics/analysis/test_potential_types.py @@ -13,7 +13,7 @@ from vyper.semantics.types import AddressT, BoolT, DArrayT, SArrayT from vyper.semantics.types.shortcuts import INT128_T -INTEGER_LITERALS = [(42, 31337), (-1, 1), (69, 2 ** 128)] +INTEGER_LITERALS = [(42, 31337), (-1, 1), (69, 2**128)] DECIMAL_LITERALS = [("4.2", "-1.337")] BOOL_LITERALS = [(True, False), (True, True), (False, False)] STRING_LITERALS = [("'hi'", "'there'"), ("'foo'", "'bar'"), ("'longer'", "'short'")] @@ -67,7 +67,7 @@ def test_binop(build_node, namespace, op, left, right): @pytest.mark.parametrize("op", "+-*/%") -@pytest.mark.parametrize("left,right", [(42, "2.3"), (-1, 2 ** 255)]) +@pytest.mark.parametrize("left,right", [(42, "2.3"), (-1, 2**255)]) def test_binop_type_mismatch(build_node, namespace, op, left, right): node = build_node(f"{left}{op}{right}") with namespace.enter_scope(): diff --git a/tests/fuzzing/test_exponents.py b/tests/fuzzing/test_exponents.py index 376acc0eaf..29c1f198ed 100644 --- a/tests/fuzzing/test_exponents.py +++ b/tests/fuzzing/test_exponents.py @@ -14,8 +14,8 @@ def foo(a: uint256) -> uint256: return a ** {power} """ _min_base, max_base = calculate_largest_base(power, 256, False) - assert max_base ** power < 2 ** 256 - assert (max_base + 1) ** power >= 2 ** 256 + assert max_base**power < 2**256 + assert (max_base + 1) ** power >= 2**256 c = get_contract(code) @@ -33,11 +33,11 @@ def foo(a: int128) -> int128: """ min_base, max_base = calculate_largest_base(power, 128, True) - assert -(2 ** 127) <= max_base ** power < 2 ** 127 - assert -(2 ** 127) <= min_base ** power < 2 ** 127 + assert -(2**127) <= max_base**power < 2**127 + assert -(2**127) <= min_base**power < 2**127 - assert not -(2 ** 127) <= (max_base + 1) ** power < 2 ** 127 - assert not -(2 ** 127) <= (min_base - 1) ** power < 2 ** 127 + assert not -(2**127) <= (max_base + 1) ** power < 2**127 + assert not -(2**127) <= (min_base - 1) ** power < 2**127 c = get_contract(code) @@ -58,11 +58,11 @@ def foo(a: int16) -> int16: """ min_base, max_base = calculate_largest_base(power, 16, True) - assert -(2 ** 15) <= max_base ** power < 2 ** 15 - assert -(2 ** 15) <= min_base ** power < 2 ** 15 + assert -(2**15) <= max_base**power < 2**15 + assert -(2**15) <= min_base**power < 2**15 - assert not -(2 ** 15) <= (max_base + 1) ** power < 2 ** 15 - assert not -(2 ** 15) <= (min_base - 1) ** power < 2 ** 15 + assert not -(2**15) <= (max_base + 1) ** power < 2**15 + assert not -(2**15) <= (min_base - 1) ** power < 2**15 c = get_contract(code) @@ -74,24 +74,24 @@ def foo(a: int16) -> int16: @pytest.mark.fuzzing -@given(a=st.integers(min_value=2, max_value=2 ** 256 - 1)) +@given(a=st.integers(min_value=2, max_value=2**256 - 1)) # 8 bits -@example(a=2 ** 7) -@example(a=2 ** 7 - 1) +@example(a=2**7) +@example(a=2**7 - 1) # 16 bits -@example(a=2 ** 15) -@example(a=2 ** 15 - 1) +@example(a=2**15) +@example(a=2**15 - 1) # 32 bits -@example(a=2 ** 31) -@example(a=2 ** 31 - 1) +@example(a=2**31) +@example(a=2**31 - 1) # 64 bits -@example(a=2 ** 63) -@example(a=2 ** 63 - 1) +@example(a=2**63) +@example(a=2**63 - 1) # 128 bits -@example(a=2 ** 127) -@example(a=2 ** 127 - 1) +@example(a=2**127) +@example(a=2**127 - 1) # 256 bits -@example(a=2 ** 256 - 1) +@example(a=2**256 - 1) @settings(max_examples=200, deadline=1000) def test_max_exp(get_contract, assert_tx_failed, a): code = f""" @@ -104,29 +104,29 @@ def foo(b: uint256) -> uint256: max_power = calculate_largest_power(a, 256, False) - assert a ** max_power < 2 ** 256 - assert a ** (max_power + 1) >= 2 ** 256 + assert a**max_power < 2**256 + assert a ** (max_power + 1) >= 2**256 c.foo(max_power) assert_tx_failed(lambda: c.foo(max_power + 1)) @pytest.mark.fuzzing -@given(a=st.integers(min_value=2, max_value=2 ** 127 - 1)) +@given(a=st.integers(min_value=2, max_value=2**127 - 1)) # 8 bits -@example(a=2 ** 7) -@example(a=2 ** 7 - 1) +@example(a=2**7) +@example(a=2**7 - 1) # 16 bits -@example(a=2 ** 15) -@example(a=2 ** 15 - 1) +@example(a=2**15) +@example(a=2**15 - 1) # 32 bits -@example(a=2 ** 31) -@example(a=2 ** 31 - 1) +@example(a=2**31) +@example(a=2**31 - 1) # 64 bits -@example(a=2 ** 63) -@example(a=2 ** 63 - 1) +@example(a=2**63) +@example(a=2**63 - 1) # 128 bits -@example(a=2 ** 127 - 1) +@example(a=2**127 - 1) @settings(max_examples=200, deadline=1000) def test_max_exp_int128(get_contract, assert_tx_failed, a): code = f""" @@ -139,8 +139,8 @@ def foo(b: int128) -> int128: max_power = calculate_largest_power(a, 128, True) - assert -(2 ** 127) <= a ** max_power < 2 ** 127 - assert not -(2 ** 127) <= a ** (max_power + 1) < 2 ** 127 + assert -(2**127) <= a**max_power < 2**127 + assert not -(2**127) <= a ** (max_power + 1) < 2**127 c.foo(max_power) assert_tx_failed(lambda: c.foo(max_power + 1)) diff --git a/tests/parser/features/decorators/test_payable.py b/tests/parser/features/decorators/test_payable.py index aabdfbdf37..420af1cad9 100644 --- a/tests/parser/features/decorators/test_payable.py +++ b/tests/parser/features/decorators/test_payable.py @@ -181,7 +181,7 @@ def test_nonpayable_runtime_assertion(assert_tx_failed, get_contract, code): c = get_contract(code) c.foo(transact={"value": 0}) - assert_tx_failed(lambda: c.foo(transact={"value": 10 ** 18})) + assert_tx_failed(lambda: c.foo(transact={"value": 10**18})) payable_code = [ @@ -332,7 +332,7 @@ def bar() -> bool: def test_payable_runtime_assertion(get_contract, code): c = get_contract(code) - c.foo(transact={"value": 10 ** 18}) + c.foo(transact={"value": 10**18}) c.foo(transact={"value": 0}) diff --git a/tests/parser/features/external_contracts/test_erc20_abi.py b/tests/parser/features/external_contracts/test_erc20_abi.py index ecc6edceb8..4a09ce68fa 100644 --- a/tests/parser/features/external_contracts/test_erc20_abi.py +++ b/tests/parser/features/external_contracts/test_erc20_abi.py @@ -4,8 +4,8 @@ TOKEN_NAME = "Vypercoin" TOKEN_SYMBOL = "FANG" TOKEN_DECIMALS = 18 -TOKEN_INITIAL_SUPPLY = 21 * 10 ** 6 -TOKEN_TOTAL_SUPPLY = TOKEN_INITIAL_SUPPLY * (10 ** TOKEN_DECIMALS) +TOKEN_INITIAL_SUPPLY = 21 * 10**6 +TOKEN_TOTAL_SUPPLY = TOKEN_INITIAL_SUPPLY * (10**TOKEN_DECIMALS) @pytest.fixture @@ -82,7 +82,6 @@ def test_initial_state(w3, erc20_caller): def test_call_transfer(w3, erc20, erc20_caller, assert_tx_failed): - # Basic transfer. erc20.transfer(erc20_caller.address, 10, transact={}) assert erc20.balanceOf(erc20_caller.address) == 10 diff --git a/tests/parser/features/external_contracts/test_external_contract_calls.py b/tests/parser/features/external_contracts/test_external_contract_calls.py index c51df0b9db..524a0e958d 100644 --- a/tests/parser/features/external_contracts/test_external_contract_calls.py +++ b/tests/parser/features/external_contracts/test_external_contract_calls.py @@ -815,7 +815,7 @@ def bar(arg1: address) -> (address, Bytes[3], address): """ c2 = get_contract(contract_2) - assert c.foo() == [(2 ** 160) - 1, b"dog", (2 ** 160) - 2] + assert c.foo() == [(2**160) - 1, b"dog", (2**160) - 2] result = c2.bar(c.address) assert len(result) == 3 assert result[0].lower() == "0xffffffffffffffffffffffffffffffffffffffff" @@ -848,7 +848,7 @@ def bar(arg1: address) -> (address, Bytes[3], address): """ c2 = get_contract(contract_2) - assert c.foo() == [(2 ** 160) - 1, b"dog", 2 ** 160] + assert c.foo() == [(2**160) - 1, b"dog", 2**160] assert_tx_failed(lambda: c2.bar(c.address)) @@ -1438,7 +1438,6 @@ def call_baz(): def test_invalid_keyword_on_call(assert_compile_failed, get_contract_with_gas_estimation): - contract_1 = """ interface Bar: def set_lucky(arg1: int128): nonpayable @@ -1455,7 +1454,6 @@ def get_lucky(amount_to_send: int128) -> int128: def test_invalid_contract_declaration(assert_compile_failed, get_contract_with_gas_estimation): - contract_1 = """ interface Bar: def set_lucky(arg1: int128): nonpayable @@ -1508,7 +1506,6 @@ def foo(a: address, x: uint256, y: uint256): @pytest.mark.parametrize("bad_code", FAILING_CONTRACTS_STRUCTURE_EXCEPTION) def test_bad_code_struct_exc(assert_compile_failed, get_contract_with_gas_estimation, bad_code): - assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), ArgumentException) diff --git a/tests/parser/features/test_assert.py b/tests/parser/features/test_assert.py index db521f556a..842b32d815 100644 --- a/tests/parser/features/test_assert.py +++ b/tests/parser/features/test_assert.py @@ -16,7 +16,7 @@ def foo(): """ c = get_contract_with_gas_estimation(code) a0 = w3.eth.accounts[0] - gas_sent = 10 ** 6 + gas_sent = 10**6 tx_hash = c.foo(transact={"from": a0, "gas": gas_sent, "gasPrice": 10}) # More info on receipt status: # https://github.com/ethereum/EIPs/blob/master/EIPS/eip-658.md#specification. diff --git a/tests/parser/features/test_assert_unreachable.py b/tests/parser/features/test_assert_unreachable.py index 79023a1e60..90ed31a22e 100644 --- a/tests/parser/features/test_assert_unreachable.py +++ b/tests/parser/features/test_assert_unreachable.py @@ -7,7 +7,7 @@ def foo(): c = get_contract(code) a0 = w3.eth.accounts[0] - gas_sent = 10 ** 6 + gas_sent = 10**6 tx_hash = c.foo(transact={"from": a0, "gas": gas_sent, "gasPrice": 10}) tx_receipt = w3.eth.get_transaction_receipt(tx_hash) diff --git a/tests/parser/features/test_bytes_map_keys.py b/tests/parser/features/test_bytes_map_keys.py index 9a648b762d..4913182d52 100644 --- a/tests/parser/features/test_bytes_map_keys.py +++ b/tests/parser/features/test_bytes_map_keys.py @@ -58,7 +58,7 @@ def get(k: Bytes[34]) -> int128: c = get_contract(code) - c.set(b"a" * 34, 6789, transact={"gas": 10 ** 6}) + c.set(b"a" * 34, 6789, transact={"gas": 10**6}) assert c.get(b"a" * 34) == 6789 diff --git a/tests/parser/features/test_clampers.py b/tests/parser/features/test_clampers.py index 0df7e81c74..006fb0b4e4 100644 --- a/tests/parser/features/test_clampers.py +++ b/tests/parser/features/test_clampers.py @@ -142,7 +142,7 @@ def foo(s: int{bits}) -> int{bits}: def test_sint_clamper_failing(w3, assert_tx_failed, get_contract, n, evm_version): bits = 8 * (n + 1) lo, hi = int_bounds(True, bits) - values = [-(2 ** 255), 2 ** 255 - 1, lo - 1, hi + 1] + values = [-(2**255), 2**255 - 1, lo - 1, hi + 1] code = f""" @external def foo(s: int{bits}) -> int{bits}: @@ -168,7 +168,7 @@ def foo(s: bool) -> bool: @pytest.mark.parametrize("evm_version", list(EVM_VERSIONS)) -@pytest.mark.parametrize("value", [2, 3, 4, 8, 16, 2 ** 256 - 1]) +@pytest.mark.parametrize("value", [2, 3, 4, 8, 16, 2**256 - 1]) def test_bool_clamper_failing(w3, assert_tx_failed, get_contract, value, evm_version): code = """ @external @@ -181,7 +181,7 @@ def foo(s: bool) -> bool: @pytest.mark.parametrize("evm_version", list(EVM_VERSIONS)) -@pytest.mark.parametrize("value", [0] + [2 ** i for i in range(5)]) +@pytest.mark.parametrize("value", [0] + [2**i for i in range(5)]) def test_enum_clamper_passing(w3, get_contract, value, evm_version): code = """ enum Roles: @@ -201,7 +201,7 @@ def foo(s: Roles) -> Roles: @pytest.mark.parametrize("evm_version", list(EVM_VERSIONS)) -@pytest.mark.parametrize("value", [2 ** i for i in range(5, 256)]) +@pytest.mark.parametrize("value", [2**i for i in range(5, 256)]) def test_enum_clamper_failing(w3, assert_tx_failed, get_contract, value, evm_version): code = """ enum Roles: @@ -224,7 +224,7 @@ def foo(s: Roles) -> Roles: @pytest.mark.parametrize("n", list(range(32))) def test_uint_clamper_passing(w3, get_contract, evm_version, n): bits = 8 * (n + 1) - values = [0, 1, 2 ** bits - 1] + values = [0, 1, 2**bits - 1] code = f""" @external def foo(s: uint{bits}) -> uint{bits}: @@ -240,7 +240,7 @@ def foo(s: uint{bits}) -> uint{bits}: @pytest.mark.parametrize("n", list(range(31))) # uint256 has no failing cases def test_uint_clamper_failing(w3, assert_tx_failed, get_contract, evm_version, n): bits = 8 * (n + 1) - values = [-1, -(2 ** 255), 2 ** bits] + values = [-1, -(2**255), 2**bits] code = f""" @external def foo(s: uint{bits}) -> uint{bits}: @@ -278,7 +278,7 @@ def foo(s: address) -> address: @pytest.mark.parametrize("evm_version", list(EVM_VERSIONS)) -@pytest.mark.parametrize("value", [2 ** 160, 2 ** 256 - 1]) +@pytest.mark.parametrize("value", [2**160, 2**256 - 1]) def test_address_clamper_failing(w3, assert_tx_failed, get_contract, value, evm_version): code = """ @external @@ -297,8 +297,8 @@ def foo(s: address) -> address: 0, 1, -1, - Decimal(2 ** 167 - 1) / 10 ** 10, - -Decimal(2 ** 167) / 10 ** 10, + Decimal(2**167 - 1) / 10**10, + -Decimal(2**167) / 10**10, "0.0", "1.0", "-1.0", @@ -326,8 +326,8 @@ def foo(s: decimal) -> decimal: @pytest.mark.parametrize( "value", [ - 2 ** 167, - -(2 ** 167 + 1), + 2**167, + -(2**167 + 1), 187072209578355573530071658587684226515959365500928, # 2 ** 167 -187072209578355573530071658587684226515959365500929, # - (2 ** 127 - 1e-10) ], @@ -344,7 +344,7 @@ def foo(s: decimal) -> decimal: assert_tx_failed(lambda: _make_tx(w3, c.address, "foo(fixed168x10)", [value])) -@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) def test_int128_array_clamper_passing(w3, get_contract, value): code = """ @external @@ -356,10 +356,10 @@ def foo(a: uint256, b: int128[5], c: uint256) -> int128[5]: # to ensure there are no off-by-one errors d = [value] * 5 c = get_contract(code) - assert c.foo(2 ** 127, [value] * 5, 2 ** 127) == d + assert c.foo(2**127, [value] * 5, 2**127) == d -@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) +@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) @pytest.mark.parametrize("idx", range(5)) def test_int128_array_clamper_failing(w3, assert_tx_failed, get_contract, bad_value, idx): # ensure the invalid value is detected at all locations in the array @@ -376,7 +376,7 @@ def foo(b: int128[5]) -> int128[5]: assert_tx_failed(lambda: _make_tx(w3, c.address, "foo(int128[5])", values)) -@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) def test_int128_array_looped_clamper_passing(w3, get_contract, value): # when an array is > 5 items, the arg clamper runs in a loop to reduce bytecode size code = """ @@ -387,10 +387,10 @@ def foo(a: uint256, b: int128[10], c: uint256) -> int128[10]: d = [value] * 10 c = get_contract(code) - assert c.foo(2 ** 127, d, 2 ** 127) == d + assert c.foo(2**127, d, 2**127) == d -@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) +@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) @pytest.mark.parametrize("idx", range(10)) def test_int128_array_looped_clamper_failing(w3, assert_tx_failed, get_contract, bad_value, idx): code = """ @@ -406,7 +406,7 @@ def foo(b: int128[10]) -> int128[10]: assert_tx_failed(lambda: _make_tx(w3, c.address, "foo(int128[10])", values)) -@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) def test_multidimension_array_clamper_passing(w3, get_contract, value): code = """ @external @@ -417,10 +417,10 @@ def foo(a: uint256, b: int128[6][3][1][8], c: uint256) -> int128[6][3][1][8]: # 6 * 3 * 1 * 8 = 144, the total number of values in our multidimensional array d = [[[[value] * 6] * 3] * 1] * 8 c = get_contract(code) - assert c.foo(2 ** 127, d, 2 ** 127, call={"gasPrice": 0}) == d + assert c.foo(2**127, d, 2**127, call={"gasPrice": 0}) == d -@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) +@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) @pytest.mark.parametrize("idx", range(12)) def test_multidimension_array_clamper_failing(w3, assert_tx_failed, get_contract, bad_value, idx): code = """ @@ -436,7 +436,7 @@ def foo(b: int128[6][1][2]) -> int128[6][1][2]: assert_tx_failed(lambda: _make_tx(w3, c.address, "foo(int128[6][1][2]])", values)) -@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) def test_int128_dynarray_clamper_passing(w3, get_contract, value): code = """ @external @@ -448,10 +448,10 @@ def foo(a: uint256, b: DynArray[int128, 5], c: uint256) -> DynArray[int128, 5]: # to ensure there are no off-by-one errors d = [value] * 5 c = get_contract(code) - assert c.foo(2 ** 127, d, 2 ** 127) == d + assert c.foo(2**127, d, 2**127) == d -@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) +@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) @pytest.mark.parametrize("idx", range(5)) def test_int128_dynarray_clamper_failing( w3, abi_encode, assert_tx_failed, get_contract, bad_value, idx @@ -473,7 +473,7 @@ def foo(b: int128[5]) -> int128[5]: assert_tx_failed(lambda: _make_invalid_dynarray_tx(w3, c.address, signature, data)) -@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) def test_int128_dynarray_looped_clamper_passing(w3, get_contract, value): # when an array is > 5 items, the arg clamper runs in a loop to reduce bytecode size code = """ @@ -483,10 +483,10 @@ def foo(a: uint256, b: DynArray[int128, 10], c: uint256) -> DynArray[int128, 10] """ d = [value] * 10 c = get_contract(code) - assert c.foo(2 ** 127, d, 2 ** 127) == d + assert c.foo(2**127, d, 2**127) == d -@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) +@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) @pytest.mark.parametrize("idx", range(10)) def test_int128_dynarray_looped_clamper_failing(w3, assert_tx_failed, get_contract, bad_value, idx): code = """ @@ -505,7 +505,7 @@ def foo(b: DynArray[int128, 10]) -> DynArray[int128, 10]: assert_tx_failed(lambda: _make_invalid_dynarray_tx(w3, c.address, signature, data)) -@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) def test_multidimension_dynarray_clamper_passing(w3, get_contract, value): code = """ @external @@ -519,10 +519,10 @@ def foo( # Out of gas exception if outermost length is 6 and greater d = [[[[value] * 5] * 6] * 7] * 8 c = get_contract(code) - assert c.foo(2 ** 127, d, 2 ** 127, call={"gasPrice": 0}) == d + assert c.foo(2**127, d, 2**127, call={"gasPrice": 0}) == d -@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) +@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) @pytest.mark.parametrize("idx", range(4)) def test_multidimension_dynarray_clamper_failing( w3, abi_encode, assert_tx_failed, get_contract, bad_value, idx @@ -549,7 +549,7 @@ def foo(b: DynArray[DynArray[int128, 2], 2]) -> DynArray[DynArray[int128, 2], 2] assert_tx_failed(lambda: _make_invalid_dynarray_tx(w3, c.address, signature, data)) -@pytest.mark.parametrize("value", [0, 1, -1, 2 ** 127 - 1, -(2 ** 127)]) +@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)]) def test_dynarray_list_clamper_passing(w3, abi_encode, get_contract, value): code = """ @external @@ -562,10 +562,10 @@ def foo( """ d = [[value] * 5] * 6 c = get_contract(code) - assert c.foo(2 ** 127, d, 2 ** 127) == d + assert c.foo(2**127, d, 2**127) == d -@pytest.mark.parametrize("bad_value", [2 ** 127, -(2 ** 127) - 1, 2 ** 255 - 1, -(2 ** 255)]) +@pytest.mark.parametrize("bad_value", [2**127, -(2**127) - 1, 2**255 - 1, -(2**255)]) @pytest.mark.parametrize("idx", range(10)) def test_dynarray_list_clamper_failing( w3, abi_encode, assert_tx_failed, get_contract, bad_value, idx diff --git a/tests/parser/features/test_constructor.py b/tests/parser/features/test_constructor.py index 297e54d216..c9dfcfc5df 100644 --- a/tests/parser/features/test_constructor.py +++ b/tests/parser/features/test_constructor.py @@ -82,10 +82,10 @@ def foo(x: int128) -> int128: c = get_contract_with_gas_estimation(large_input_code) c.foo(1274124) - c.foo(2 ** 120) + c.foo(2**120) with pytest.raises(ValidationError): - c.foo(2 ** 130) + c.foo(2**130) def test_large_input_code_2(w3, get_contract_with_gas_estimation): @@ -102,7 +102,7 @@ def foo() -> int128: get_contract_with_gas_estimation(large_input_code_2, *[17]) with pytest.raises(TypeError): - get_contract_with_gas_estimation(large_input_code_2, *[2 ** 130]) + get_contract_with_gas_estimation(large_input_code_2, *[2**130]) print("Passed invalid input tests") diff --git a/tests/parser/features/test_immutable.py b/tests/parser/features/test_immutable.py index 4ce26ce459..bb01b3fc07 100644 --- a/tests/parser/features/test_immutable.py +++ b/tests/parser/features/test_immutable.py @@ -5,8 +5,8 @@ "typ,value", [ ("uint256", 42), - ("int256", -(2 ** 200)), - ("int128", -(2 ** 126)), + ("int256", -(2**200)), + ("int128", -(2**126)), ("address", "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"), ("bytes32", b"deadbeef" * 4), ("bool", True), @@ -32,7 +32,7 @@ def get_value() -> {typ}: assert c.get_value() == value -@pytest.mark.parametrize("val", [0, 1, 2 ** 256 - 1]) +@pytest.mark.parametrize("val", [0, 1, 2**256 - 1]) def test_usage_in_constructor(get_contract, val): code = """ A: immutable(uint256) @@ -101,7 +101,7 @@ def __init__(_a: uint256, _b: uint256, _c: address, _d: int256): def get_my_struct() -> MyStruct: return my_struct """ - values = (100, 42, "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", -(2 ** 200)) + values = (100, 42, "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", -(2**200)) c = get_contract(code, *values) assert c.get_my_struct() == values diff --git a/tests/parser/features/test_logging.py b/tests/parser/features/test_logging.py index 71e61474e4..426402bf44 100644 --- a/tests/parser/features/test_logging.py +++ b/tests/parser/features/test_logging.py @@ -810,7 +810,6 @@ def foo(): def test_variable_list_packing(get_logs, get_contract_with_gas_estimation): - code = """ event Bar: _value: int128[4] @@ -828,7 +827,6 @@ def foo(): def test_literal_list_packing(get_logs, get_contract_with_gas_estimation): - code = """ event Bar: _value: int128[4] @@ -845,7 +843,6 @@ def foo(): def test_storage_list_packing(get_logs, bytes_helper, get_contract_with_gas_estimation): - code = """ event Bar: _value: int128[4] @@ -872,7 +869,6 @@ def set_list(): def test_passed_list_packing(get_logs, get_contract_with_gas_estimation): - code = """ event Bar: _value: int128[4] @@ -910,7 +906,6 @@ def foo(): def test_storage_byte_packing(get_logs, bytes_helper, get_contract_with_gas_estimation): - code = """ event MyLog: arg1: Bytes[29] @@ -937,7 +932,6 @@ def setbytez(): def test_storage_decimal_list_packing(get_logs, bytes_helper, get_contract_with_gas_estimation): - code = """ event Bar: _value: decimal[4] diff --git a/tests/parser/functions/test_abi_decode.py b/tests/parser/functions/test_abi_decode.py index 8426b48658..d3ffc339cf 100644 --- a/tests/parser/functions/test_abi_decode.py +++ b/tests/parser/functions/test_abi_decode.py @@ -284,7 +284,7 @@ def foo(bs: Bytes[160]) -> (uint256, DynArray[uint256, 3]): c = get_contract(code) bs = [1, 2, 3] encoded = abi_encode("(uint256[])", (bs,)) - assert c.foo(encoded) == [2 ** 256 - 1, bs] + assert c.foo(encoded) == [2**256 - 1, bs] def test_abi_decode_private_nested_dynarray(get_contract, abi_encode): @@ -308,7 +308,7 @@ def foo(bs: Bytes[1696]) -> (uint256, DynArray[DynArray[DynArray[uint256, 3], 3] [[19, 20, 21], [22, 23, 24], [25, 26, 27]], ] encoded = abi_encode("(uint256[][][])", (bs,)) - assert c.foo(encoded) == [2 ** 256 - 1, bs] + assert c.foo(encoded) == [2**256 - 1, bs] def test_abi_decode_return(get_contract, abi_encode): diff --git a/tests/parser/functions/test_abi_encode.py b/tests/parser/functions/test_abi_encode.py index f1c2577797..73227719d5 100644 --- a/tests/parser/functions/test_abi_encode.py +++ b/tests/parser/functions/test_abi_encode.py @@ -82,7 +82,7 @@ def abi_encode3(x: uint256, ensure_tuple: bool, include_method_id: bool) -> Byte """ c = get_contract(code) - method_id = 0xDEADBEEF .to_bytes(4, "big") + method_id = 0xDEADBEEF.to_bytes(4, "big") # test each method once each with ensure_tuple set to True and False @@ -149,7 +149,7 @@ def abi_encode(d: DynArray[uint256, 3], ensure_tuple: bool, include_method_id: b """ c = get_contract(code) - method_id = 0xDEADBEEF .to_bytes(4, "big") + method_id = 0xDEADBEEF.to_bytes(4, "big") arg = [123, 456, 789] assert c.abi_encode(arg, False, False).hex() == abi_encode("uint256[]", arg).hex() @@ -193,7 +193,7 @@ def abi_encode( """ c = get_contract(code) - method_id = 0xDEADBEEF .to_bytes(4, "big") + method_id = 0xDEADBEEF.to_bytes(4, "big") assert c.abi_encode(args, False, False).hex() == abi_encode("uint256[][]", args).hex() assert c.abi_encode(args, True, False).hex() == abi_encode("(uint256[][])", (args,)).hex() @@ -244,7 +244,7 @@ def abi_encode( """ c = get_contract(code) - method_id = 0xDEADBEEF .to_bytes(4, "big") + method_id = 0xDEADBEEF.to_bytes(4, "big") assert c.abi_encode(args, False, False).hex() == abi_encode("uint256[][][]", args).hex() assert c.abi_encode(args, True, False).hex() == abi_encode("(uint256[][][])", (args,)).hex() @@ -285,7 +285,7 @@ def foo(addr: address) -> Bytes[164]: c2 = get_contract(contract_2) - method_id = 0xDEADBEEF .to_bytes(4, "big") + method_id = 0xDEADBEEF.to_bytes(4, "big") # call to get_counter() should be evaluated only once get_counter_encoded = abi_encode("((uint256,string))", ((1, "hello"),)) @@ -309,7 +309,7 @@ def foo(bs: Bytes[32]) -> (uint256, Bytes[96]): """ c = get_contract(code) bs = "0" * 32 - assert c.foo(bs) == [2 ** 256 - 1, abi_encode("(bytes)", (bs,))] + assert c.foo(bs) == [2**256 - 1, abi_encode("(bytes)", (bs,))] def test_abi_encode_private_dynarray(get_contract, abi_encode): @@ -326,7 +326,7 @@ def foo(bs: DynArray[uint256, 3]) -> (uint256, Bytes[160]): """ c = get_contract(code) bs = [1, 2, 3] - assert c.foo(bs) == [2 ** 256 - 1, abi_encode("(uint256[])", (bs,))] + assert c.foo(bs) == [2**256 - 1, abi_encode("(uint256[])", (bs,))] def test_abi_encode_private_nested_dynarray(get_contract, abi_encode): @@ -348,7 +348,7 @@ def foo(bs: DynArray[DynArray[DynArray[uint256, 3], 3], 3]) -> (uint256, Bytes[1 [[10, 11, 12], [13, 14, 15], [16, 17, 18]], [[19, 20, 21], [22, 23, 24], [25, 26, 27]], ] - assert c.foo(bs) == [2 ** 256 - 1, abi_encode("(uint256[][][])", (bs,))] + assert c.foo(bs) == [2**256 - 1, abi_encode("(uint256[][][])", (bs,))] @pytest.mark.parametrize("empty_literal", ('b""', '""', "empty(Bytes[1])", "empty(String[1])")) diff --git a/tests/parser/functions/test_bitwise.py b/tests/parser/functions/test_bitwise.py index b807de2254..171ba7daeb 100644 --- a/tests/parser/functions/test_bitwise.py +++ b/tests/parser/functions/test_bitwise.py @@ -50,10 +50,10 @@ def test_test_bitwise(get_contract_with_gas_estimation, evm_version): assert c._bitwise_and(x, y) == (x & y) assert c._bitwise_or(x, y) == (x | y) assert c._bitwise_xor(x, y) == (x ^ y) - assert c._bitwise_not(x) == 2 ** 256 - 1 - x + assert c._bitwise_not(x) == 2**256 - 1 - x assert c._shift(x, 3) == x * 8 assert c._shift(x, 255) == 0 - assert c._shift(y, 255) == 2 ** 255 + assert c._shift(y, 255) == 2**255 assert c._shift(x, 256) == 0 assert c._shift(x, 0) == x assert c._shift(x, -1) == x // 2 @@ -61,7 +61,7 @@ def test_test_bitwise(get_contract_with_gas_estimation, evm_version): assert c._shift(x, -256) == 0 assert c._negatedShift(x, -3) == x * 8 assert c._negatedShift(x, -255) == 0 - assert c._negatedShift(y, -255) == 2 ** 255 + assert c._negatedShift(y, -255) == 2**255 assert c._negatedShift(x, -256) == 0 assert c._negatedShift(x, -0) == x assert c._negatedShift(x, 1) == x // 2 diff --git a/tests/parser/functions/test_ceil.py b/tests/parser/functions/test_ceil.py index 64e1f05c48..c0bf45fd83 100644 --- a/tests/parser/functions/test_ceil.py +++ b/tests/parser/functions/test_ceil.py @@ -43,7 +43,7 @@ def fou() -> int256: assert c.x_ceil() == 505 assert c.foo() == 1 assert c.fop() == 1 - assert c.foq() == math.ceil(Decimal(2 ** 167) / 10 ** 10) + assert c.foq() == math.ceil(Decimal(2**167) / 10**10) assert c.fos() == 0 assert c.fou() == 4 @@ -100,7 +100,7 @@ def ceil_param(p: decimal) -> int256: assert c.fop() == -5 assert c.foq() == 0 assert c.fos() == -5472 - assert c.fot() == math.ceil(-(Decimal(2 ** 167 - 1)) / 10 ** 10) + assert c.fot() == math.ceil(-(Decimal(2**167 - 1)) / 10**10) assert c.fou() == -3 assert c.ceil_param(Decimal("-0.5")) == 0 assert c.ceil_param(Decimal("-7777777.7777777")) == -7777777 diff --git a/tests/parser/functions/test_convert.py b/tests/parser/functions/test_convert.py index d0813f975a..80271bb4a5 100644 --- a/tests/parser/functions/test_convert.py +++ b/tests/parser/functions/test_convert.py @@ -249,7 +249,7 @@ def _signextend(val_bytes, bits): as_sint = unsigned_to_signed(as_uint, bits) - return (as_sint % 2 ** 256).to_bytes(32, byteorder="big") + return (as_sint % 2**256).to_bytes(32, byteorder="big") def _convert_int_to_int(val, o_typ): @@ -410,7 +410,6 @@ def _vyper_literal(val, typ): def test_convert_passing( get_contract_with_gas_estimation, assert_compile_failed, i_typ, o_typ, val ): - expected_val = _py_convert(val, i_typ, o_typ) if isinstance(o_typ, AddressT) and expected_val == "0x" + "00" * 20: # web3 has special formatter for zero address @@ -473,7 +472,7 @@ def test_memory_variable_convert(x: {i_typ}) -> {o_typ}: @pytest.mark.parametrize("typ", ["uint8", "int128", "int256", "uint256"]) -@pytest.mark.parametrize("val", [1, 2, 2 ** 128, 2 ** 256 - 1, 2 ** 256 - 2]) +@pytest.mark.parametrize("val", [1, 2, 2**128, 2**256 - 1, 2**256 - 2]) def test_enum_conversion(get_contract_with_gas_estimation, assert_compile_failed, val, typ): roles = "\n ".join([f"ROLE_{i}" for i in range(256)]) contract = f""" @@ -497,7 +496,7 @@ def bar(a: uint256) -> Roles: @pytest.mark.parametrize("typ", ["uint8", "int128", "int256", "uint256"]) -@pytest.mark.parametrize("val", [1, 2, 3, 4, 2 ** 128, 2 ** 256 - 1, 2 ** 256 - 2]) +@pytest.mark.parametrize("val", [1, 2, 3, 4, 2**128, 2**256 - 1, 2**256 - 2]) def test_enum_conversion_2( get_contract_with_gas_estimation, assert_compile_failed, assert_tx_failed, val, typ ): @@ -530,7 +529,6 @@ def foo(a: {typ}) -> Status: def test_convert_builtin_constant( get_contract_with_gas_estimation, builtin_constant, out_type, out_value ): - contract = f""" @external def convert_builtin_constant() -> {out_type}: diff --git a/tests/parser/functions/test_default_function.py b/tests/parser/functions/test_default_function.py index 6ec3ea0380..35c2f7292c 100644 --- a/tests/parser/functions/test_default_function.py +++ b/tests/parser/functions/test_default_function.py @@ -28,7 +28,7 @@ def __default__(): """ c = get_contract_with_gas_estimation(code) - logs = get_logs(w3.eth.send_transaction({"to": c.address, "value": 10 ** 17}), c, "Sent") + logs = get_logs(w3.eth.send_transaction({"to": c.address, "value": 10**17}), c, "Sent") assert w3.eth.accounts[0] == logs[0].args.sender assert w3.eth.get_balance(c.address) == w3.toWei(0.1, "ether") @@ -51,7 +51,7 @@ def __default__(): """ c = get_contract_with_gas_estimation(code) - logs = get_logs(w3.eth.send_transaction({"to": c.address, "value": 10 ** 17}), c, "Sent") + logs = get_logs(w3.eth.send_transaction({"to": c.address, "value": 10**17}), c, "Sent") assert w3.eth.accounts[0] == logs[0].args.sender assert w3.eth.get_balance(c.address) == w3.toWei(0.1, "ether") @@ -67,7 +67,7 @@ def __default__(): """ c = get_contract_with_gas_estimation(code) - assert_tx_failed(lambda: w3.eth.send_transaction({"to": c.address, "value": 10 ** 17})) + assert_tx_failed(lambda: w3.eth.send_transaction({"to": c.address, "value": 10**17})) def test_multi_arg_default(assert_compile_failed, get_contract_with_gas_estimation): diff --git a/tests/parser/functions/test_default_parameters.py b/tests/parser/functions/test_default_parameters.py index 2e36c3f377..a90f5e6624 100644 --- a/tests/parser/functions/test_default_parameters.py +++ b/tests/parser/functions/test_default_parameters.py @@ -167,8 +167,8 @@ def validate_value(cls, value): monkeypatch.setattr("eth_abi.encoding.NumberEncoder.validate_value", validate_value) - assert c.bar(200, 2 ** 127 - 1) == [200, 2 ** 127 - 1] - assert_tx_failed(lambda: c.bar(200, 2 ** 127)) + assert c.bar(200, 2**127 - 1) == [200, 2**127 - 1] + assert_tx_failed(lambda: c.bar(200, 2**127)) def test_default_param_private(get_contract): diff --git a/tests/parser/functions/test_extract32.py b/tests/parser/functions/test_extract32.py index 5e3b4e1984..c1a333ae32 100644 --- a/tests/parser/functions/test_extract32.py +++ b/tests/parser/functions/test_extract32.py @@ -74,7 +74,7 @@ def foq(inp: Bytes[32]) -> address: assert_tx_failed(lambda: c.foo(b"\x80" + b"\x00" * 30)) - assert c.bar(b"\x80" + b"\x00" * 31) == 2 ** 255 + assert c.bar(b"\x80" + b"\x00" * 31) == 2**255 assert c.baz(b"crow" * 8) == b"crow" * 8 assert c.fop(b"crow" * 8) == b"crow" * 8 diff --git a/tests/parser/functions/test_floor.py b/tests/parser/functions/test_floor.py index 80957cb2ea..dc53545ac3 100644 --- a/tests/parser/functions/test_floor.py +++ b/tests/parser/functions/test_floor.py @@ -45,7 +45,7 @@ def fou() -> int256: assert c.x_floor() == 504 assert c.foo() == 1 assert c.fop() == 1 - assert c.foq() == math.floor(Decimal(2 ** 167 - 1) / 10 ** 10) + assert c.foq() == math.floor(Decimal(2**167 - 1) / 10**10) assert c.fos() == 0 assert c.fot() == 0 assert c.fou() == 3 @@ -104,7 +104,7 @@ def floor_param(p: decimal) -> int256: assert c.fop() == -27 assert c.foq() == -9001 assert c.fos() == -1 - assert c.fot() == math.floor(-Decimal(2 ** 167) / 10 ** 10) + assert c.fot() == math.floor(-Decimal(2**167) / 10**10) assert c.fou() == -4 assert c.floor_param(Decimal("-5.6")) == -6 assert c.floor_param(Decimal("-0.0000000001")) == -1 diff --git a/tests/parser/functions/test_interfaces.py b/tests/parser/functions/test_interfaces.py index f0f6cf6d62..fff2a6bda3 100644 --- a/tests/parser/functions/test_interfaces.py +++ b/tests/parser/functions/test_interfaces.py @@ -187,7 +187,6 @@ def bar() -> uint256: @pytest.mark.parametrize("code", VALID_IMPORT_CODE) def test_extract_file_interface_imports(code): - assert extract_file_interface_imports(code[0]) == {"Foo": code[1]} @@ -249,8 +248,8 @@ def test(): @pytest.mark.parametrize( "kwarg,typ,expected", [ - ("max_value(uint256)", "uint256", 2 ** 256 - 1), - ("min_value(int128)", "int128", -(2 ** 127)), + ("max_value(uint256)", "uint256", 2**256 - 1), + ("min_value(int128)", "int128", -(2**127)), ("empty(uint8[2])", "uint8[2]", [0, 0]), ('method_id("vyper()", output_type=bytes4)', "bytes4", b"\x82\xcbE\xfb"), ("epsilon(decimal)", "decimal", Decimal("1E-10")), @@ -372,7 +371,7 @@ def test_fail3() -> int256: interface_codes={"BadCode": {"type": "vyper", "code": external_contract}}, ) assert bad_c.ok() == 1 - assert bad_c.should_fail() == -(2 ** 255) + assert bad_c.should_fail() == -(2**255) assert c.test_ok() == 1 assert_tx_failed(lambda: c.test_fail()) diff --git a/tests/parser/functions/test_minmax.py b/tests/parser/functions/test_minmax.py index 5c43886a08..da939d605a 100644 --- a/tests/parser/functions/test_minmax.py +++ b/tests/parser/functions/test_minmax.py @@ -104,11 +104,11 @@ def both_literals() -> uint256: return max(2 ** 200, 2) """ c = get_contract_with_gas_estimation(code) - assert c.foo() == 2 ** 200 + 5 - assert c.goo() == 2 ** 200 + 5 + assert c.foo() == 2**200 + 5 + assert c.goo() == 2**200 + 5 assert c.bar() == 5 + 5 assert c.baz() == 5 + 5 - assert c.both_literals() == 2 ** 200 + assert c.both_literals() == 2**200 def test_min_var_uint256_literal_int128(get_contract_with_gas_estimation): @@ -241,8 +241,8 @@ def foo4() -> uint256: c = get_contract_with_gas_estimation(code) assert c.foo1() == 0 assert c.foo2() == 0 - assert c.foo3() == 2 ** 255 - assert c.foo4() == 2 ** 255 + assert c.foo3() == 2**255 + assert c.foo4() == 2**255 def test_signed(get_contract_with_gas_estimation): @@ -265,7 +265,7 @@ def foo4() -> int128: """ c = get_contract_with_gas_estimation(code) - assert c.foo1() == -(2 ** 127) - assert c.foo2() == -(2 ** 127) - assert c.foo3() == 2 ** 127 - 1 - assert c.foo4() == 2 ** 127 - 1 + assert c.foo1() == -(2**127) + assert c.foo2() == -(2**127) + assert c.foo3() == 2**127 - 1 + assert c.foo4() == 2**127 - 1 diff --git a/tests/parser/functions/test_mkstr.py b/tests/parser/functions/test_mkstr.py index c3b998664d..9d2b7fe3f5 100644 --- a/tests/parser/functions/test_mkstr.py +++ b/tests/parser/functions/test_mkstr.py @@ -15,7 +15,7 @@ def foo(inp: uint{bits}) -> String[{n_digits}]: """ c = get_contract_with_gas_estimation(code) - for i in [1, 2, 2 ** bits - 1, 0]: + for i in [1, 2, 2**bits - 1, 0]: assert c.foo(i) == str(i), (i, c.foo(i)) @@ -36,4 +36,4 @@ def foo(x: uint{bits}) -> uint256: return y """ c = get_contract(code) - assert c.foo(2 ** bits - 1) == 0, bits + assert c.foo(2**bits - 1) == 0, bits diff --git a/tests/parser/functions/test_raw_call.py b/tests/parser/functions/test_raw_call.py index cef5bf5682..b9d1f92cd4 100644 --- a/tests/parser/functions/test_raw_call.py +++ b/tests/parser/functions/test_raw_call.py @@ -205,7 +205,6 @@ def foo_call(_addr: address): def test_static_call(get_contract): - target_source = """ @external @view @@ -262,7 +261,6 @@ def __default__(): def test_static_call_fails_nonpayable(get_contract, assert_tx_failed): - target_source = """ baz: int128 @@ -292,7 +290,6 @@ def foo(_addr: address) -> int128: def test_checkable_raw_call(get_contract, assert_tx_failed): - target_source = """ baz: int128 @external diff --git a/tests/parser/functions/test_slice.py b/tests/parser/functions/test_slice.py index b47e118e41..11d834bf42 100644 --- a/tests/parser/functions/test_slice.py +++ b/tests/parser/functions/test_slice.py @@ -165,12 +165,12 @@ def foo(x: uint256, y: uint256) -> (uint256, String[12]): return dont_clobber_me, self.bytez """ c = get_contract(code) - assert c.foo(0, 12) == [2 ** 256 - 1, "hello, world"] - assert c.foo(12, 0) == [2 ** 256 - 1, ""] - assert c.foo(7, 5) == [2 ** 256 - 1, "world"] - assert c.foo(0, 5) == [2 ** 256 - 1, "hello"] - assert c.foo(0, 1) == [2 ** 256 - 1, "h"] - assert c.foo(11, 1) == [2 ** 256 - 1, "d"] + assert c.foo(0, 12) == [2**256 - 1, "hello, world"] + assert c.foo(12, 0) == [2**256 - 1, ""] + assert c.foo(7, 5) == [2**256 - 1, "world"] + assert c.foo(0, 5) == [2**256 - 1, "hello"] + assert c.foo(0, 1) == [2**256 - 1, "h"] + assert c.foo(11, 1) == [2**256 - 1, "d"] def test_slice_storage_bytes32(get_contract): @@ -326,7 +326,6 @@ def bar() -> Bytes[32]: @pytest.mark.parametrize("code", code_bytes32) @pytest.mark.parametrize("start,length", _fun_bytes32_bounds) def test_slice_bytes32(get_contract, code, start, length): - c = get_contract(code.format(start=start, length=length)) assert c.bar() == _generate_bytes(32)[start : start + length] @@ -350,7 +349,6 @@ def bar(foo: bytes32) -> Bytes[32]: @pytest.mark.parametrize("code", code_bytes32_calldata) @pytest.mark.parametrize("start,length", _fun_bytes32_bounds) def test_slice_bytes32_calldata(get_contract, code, start, length): - c = get_contract(code.format(start=start, length=length)) assert c.bar(_generate_bytes(32)) == _generate_bytes(32)[start : start + length] @@ -393,7 +391,6 @@ def bar(a: uint256, foo: bytes32, b: uint256) -> Bytes[32]: @pytest.mark.parametrize("code,result", code_bytes32_calldata_extended) def test_slice_bytes32_calldata_extended(get_contract, code, result): - c = get_contract(code) assert ( c.bar(3, "0x0001020304050607080910111213141516171819202122232425262728293031", 5).hex() diff --git a/tests/parser/functions/test_tx.py b/tests/parser/functions/test_tx.py index ebec7ccdc7..3bc6ce2eff 100644 --- a/tests/parser/functions/test_tx.py +++ b/tests/parser/functions/test_tx.py @@ -6,4 +6,4 @@ def tx_gasprice() -> uint256: """ c = get_contract(code) for i in range(10): - assert c.tx_gasprice(call={"gasPrice": 10 ** i}) == 10 ** i + assert c.tx_gasprice(call={"gasPrice": 10**i}) == 10**i diff --git a/tests/parser/functions/test_unary.py b/tests/parser/functions/test_unary.py index 05c76629af..da3823edfe 100644 --- a/tests/parser/functions/test_unary.py +++ b/tests/parser/functions/test_unary.py @@ -20,10 +20,10 @@ def negate(a: int128) -> int128: """ c = get_contract(code) # This test should revert on overflow condition - assert_tx_failed(lambda: c.negate(-(2 ** 127))) + assert_tx_failed(lambda: c.negate(-(2**127))) -@pytest.mark.parametrize("val", [-(2 ** 127) + 1, 0, 2 ** 127 - 1]) +@pytest.mark.parametrize("val", [-(2**127) + 1, 0, 2**127 - 1]) def test_unary_sub_int128_pass(get_contract, val): code = """@external def negate(a: int128) -> int128: @@ -33,8 +33,8 @@ def negate(a: int128) -> int128: assert c.negate(val) == -val -min_decimal = -(2 ** 127) + 1 -max_decimal = 2 ** 127 - 1 +min_decimal = -(2**127) + 1 +max_decimal = 2**127 - 1 @pytest.mark.parametrize("val", [min_decimal, 0, max_decimal]) @@ -79,5 +79,5 @@ def bar() -> int128: return -(a+1) """ c = get_contract(code) - assert c.foo() == -(2 ** 127) - assert c.bar() == 2 ** 127 - 1 + assert c.foo() == -(2**127) + assert c.bar() == 2**127 - 1 diff --git a/tests/parser/functions/test_unsafe_math.py b/tests/parser/functions/test_unsafe_math.py index 84acdeefd7..da44000759 100644 --- a/tests/parser/functions/test_unsafe_math.py +++ b/tests/parser/functions/test_unsafe_math.py @@ -39,14 +39,14 @@ def foo(x: {typ}) -> {typ}: xs = [random.randrange(lo, hi) for _ in range(NUM_CASES)] ys = [random.randrange(lo, hi) for _ in range(NUM_CASES)] - mod_bound = 2 ** typ.bits + mod_bound = 2**typ.bits # poor man's fuzzing - hypothesis doesn't make it easy # with the parametrized strategy if typ.is_signed: xs += [lo, lo + 1, -1, 0, 1, hi - 1, hi] ys += [lo, lo + 1, -1, 0, 1, hi - 1, hi] - for (x, y) in itertools.product(xs, ys): + for x, y in itertools.product(xs, ys): expected = unsigned_to_signed(fn(x, y) % mod_bound, typ.bits) assert c1.foo(x, y) == expected @@ -60,7 +60,7 @@ def foo(x: {typ}) -> {typ}: fixed_pt = 2 ** (typ.bits - 1) xs += [0, 1, hi - 1, hi, fixed_pt] ys += [0, 1, hi - 1, hi, fixed_pt] - for (x, y) in itertools.product(xs, ys): + for x, y in itertools.product(xs, ys): expected = fn(x, y) % mod_bound assert c1.foo(x, y) == expected diff --git a/tests/parser/syntax/test_abi_encode.py b/tests/parser/syntax/test_abi_encode.py index 8e8a694070..37d15e7e56 100644 --- a/tests/parser/syntax/test_abi_encode.py +++ b/tests/parser/syntax/test_abi_encode.py @@ -51,7 +51,6 @@ def foo(x: uint256) -> Bytes[36]: @pytest.mark.parametrize("bad_code,exc", fail_list) def test_abi_encode_fail(bad_code, exc): - with pytest.raises(exc): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_as_uint256.py b/tests/parser/syntax/test_as_uint256.py index f76bdb751a..577cb69d33 100644 --- a/tests/parser/syntax/test_as_uint256.py +++ b/tests/parser/syntax/test_as_uint256.py @@ -37,6 +37,5 @@ def test(): @pytest.mark.parametrize("bad_code,exc", fail_list) def test_as_uint256_fail(bad_code, exc): - with pytest.raises(exc): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_block.py b/tests/parser/syntax/test_block.py index 07ee28816b..1e6bfcf0e2 100644 --- a/tests/parser/syntax/test_block.py +++ b/tests/parser/syntax/test_block.py @@ -85,7 +85,6 @@ def foo() -> int128: @pytest.mark.parametrize("bad_code", fail_list) def test_block_fail(bad_code): - if isinstance(bad_code, tuple): with raises(bad_code[1]): compiler.compile_code(bad_code[0]) diff --git a/tests/parser/syntax/test_blockscope.py b/tests/parser/syntax/test_blockscope.py index 7a70649a6e..942aa3fa68 100644 --- a/tests/parser/syntax/test_blockscope.py +++ b/tests/parser/syntax/test_blockscope.py @@ -50,7 +50,6 @@ def foo(choice: bool): @pytest.mark.parametrize("bad_code", fail_list) def test_fail_undeclared(bad_code): - with raises(UndeclaredDefinition): compiler.compile_code(bad_code) @@ -67,7 +66,6 @@ def foo(): @pytest.mark.parametrize("bad_code", fail_list_collision) def test_fail_collision(bad_code): - with raises(NamespaceCollision): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_bool.py b/tests/parser/syntax/test_bool.py index 91c60f1326..09f799d91c 100644 --- a/tests/parser/syntax/test_bool.py +++ b/tests/parser/syntax/test_bool.py @@ -77,7 +77,6 @@ def test(a: address) -> bool: @pytest.mark.parametrize("bad_code", fail_list) def test_bool_fail(bad_code): - if isinstance(bad_code, tuple): with raises(bad_code[1]): compiler.compile_code(bad_code[0]) diff --git a/tests/parser/syntax/test_chainid.py b/tests/parser/syntax/test_chainid.py index a418d54dbd..eb2ed36325 100644 --- a/tests/parser/syntax/test_chainid.py +++ b/tests/parser/syntax/test_chainid.py @@ -69,7 +69,6 @@ def foo(inp: Bytes[10]) -> Bytes[3]: @pytest.mark.parametrize("bad_code", fail_list) def test_chain_fail(bad_code): - if isinstance(bad_code, tuple): with pytest.raises(bad_code[1]): compiler.compile_code(bad_code[0], evm_version="istanbul") diff --git a/tests/parser/syntax/test_code_size.py b/tests/parser/syntax/test_code_size.py index 197468a57b..bc5511fafb 100644 --- a/tests/parser/syntax/test_code_size.py +++ b/tests/parser/syntax/test_code_size.py @@ -15,7 +15,6 @@ def foo() -> int128: @pytest.mark.parametrize("bad_code", fail_list) def test_block_fail(bad_code): - with pytest.raises(StructureException): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_concat.py b/tests/parser/syntax/test_concat.py index 0f4ce0a03c..e128e7c6ae 100644 --- a/tests/parser/syntax/test_concat.py +++ b/tests/parser/syntax/test_concat.py @@ -90,7 +90,6 @@ def large_output(a: String[33], b: String[33], reverse=True) -> String[64]: @pytest.mark.parametrize("bad_code,exc", fail_list) def test_block_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code, exc): - assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc) diff --git a/tests/parser/syntax/test_extract32.py b/tests/parser/syntax/test_extract32.py index a0de52c8ae..b04c8b8742 100644 --- a/tests/parser/syntax/test_extract32.py +++ b/tests/parser/syntax/test_extract32.py @@ -49,7 +49,6 @@ def foo(inp: Bytes[32]) -> bool: @pytest.mark.parametrize("bad_code,exc", fail_list) def test_extract32_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code, exc): - assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc) diff --git a/tests/parser/syntax/test_functions_call.py b/tests/parser/syntax/test_functions_call.py index 9aa836f22e..a1a23b6bc2 100644 --- a/tests/parser/syntax/test_functions_call.py +++ b/tests/parser/syntax/test_functions_call.py @@ -41,7 +41,6 @@ def burn(_value: uint256): @pytest.mark.parametrize("bad_code,exc", fail_list) def test_functions_call_fail(bad_code, exc): - with pytest.raises(exc): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_len.py b/tests/parser/syntax/test_len.py index aedbde6847..bbde7e4897 100644 --- a/tests/parser/syntax/test_len.py +++ b/tests/parser/syntax/test_len.py @@ -20,7 +20,6 @@ def foo(inp: int128) -> uint256: @pytest.mark.parametrize("bad_code", fail_list) def test_block_fail(bad_code): - if isinstance(bad_code, tuple): with raises(bad_code[1]): compiler.compile_code(bad_code[0]) diff --git a/tests/parser/syntax/test_list.py b/tests/parser/syntax/test_list.py index bd29b40d7c..6d941fa2df 100644 --- a/tests/parser/syntax/test_list.py +++ b/tests/parser/syntax/test_list.py @@ -231,7 +231,6 @@ def foo(x: int128[2][2]): @pytest.mark.parametrize("bad_code,exc", fail_list) def test_block_fail(bad_code, exc): - with pytest.raises(exc): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_logging.py b/tests/parser/syntax/test_logging.py index cf20c099d5..39573642c0 100644 --- a/tests/parser/syntax/test_logging.py +++ b/tests/parser/syntax/test_logging.py @@ -39,7 +39,6 @@ def test(): @pytest.mark.parametrize("bad_code", fail_list) def test_logging_fail(bad_code): - if isinstance(bad_code, tuple): with pytest.raises(bad_code[1]): compiler.compile_code(bad_code[0]) diff --git a/tests/parser/syntax/test_minmax_value.py b/tests/parser/syntax/test_minmax_value.py index f71dc92e40..e154cad23f 100644 --- a/tests/parser/syntax/test_minmax_value.py +++ b/tests/parser/syntax/test_minmax_value.py @@ -18,5 +18,4 @@ def foo(): @pytest.mark.parametrize("bad_code", fail_list) def test_block_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code): - assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), InvalidType) diff --git a/tests/parser/syntax/test_msg_data.py b/tests/parser/syntax/test_msg_data.py index a05184ff11..598b990bfc 100644 --- a/tests/parser/syntax/test_msg_data.py +++ b/tests/parser/syntax/test_msg_data.py @@ -48,7 +48,7 @@ def foo(bar: uint256) -> Bytes[36]: assert contract.foo(42).hex() == expected_result -@pytest.mark.parametrize("bar", [0, 1, 42, 2 ** 256 - 1]) +@pytest.mark.parametrize("bar", [0, 1, 42, 2**256 - 1]) def test_calldata_private(get_contract, bar): code = """ @external @@ -73,7 +73,7 @@ def foo() -> (uint256, Bytes[4], uint256): """ contract = get_contract(code) - assert contract.foo() == [2 ** 256 - 1, bytes(keccak(text="foo()")[:4]), 2 ** 256 - 1] + assert contract.foo() == [2**256 - 1, bytes(keccak(text="foo()")[:4]), 2**256 - 1] def test_assignment_to_storage(w3, get_contract, keccak): diff --git a/tests/parser/syntax/test_raw_call.py b/tests/parser/syntax/test_raw_call.py index dee1d1d50b..b1286e7a8e 100644 --- a/tests/parser/syntax/test_raw_call.py +++ b/tests/parser/syntax/test_raw_call.py @@ -38,7 +38,6 @@ def foo(): @pytest.mark.parametrize("bad_code,exc", fail_list) def test_raw_call_fail(bad_code, exc): - with pytest.raises(exc): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_return_tuple.py b/tests/parser/syntax/test_return_tuple.py index 6fa373f988..8ad2e37172 100644 --- a/tests/parser/syntax/test_return_tuple.py +++ b/tests/parser/syntax/test_return_tuple.py @@ -16,7 +16,6 @@ def unmatched_tupl_length() -> (Bytes[8], int128, Bytes[8]): @pytest.mark.parametrize("bad_code", fail_list) def test_tuple_return_fail(bad_code): - with pytest.raises(FunctionDeclarationException): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_selfdestruct.py b/tests/parser/syntax/test_selfdestruct.py index bd5b83ef99..8f80a56ce1 100644 --- a/tests/parser/syntax/test_selfdestruct.py +++ b/tests/parser/syntax/test_selfdestruct.py @@ -14,7 +14,6 @@ def foo(): @pytest.mark.parametrize("bad_code", fail_list) def test_block_fail(bad_code): - with pytest.raises(InvalidType): compiler.compile_code(bad_code) diff --git a/tests/parser/syntax/test_slice.py b/tests/parser/syntax/test_slice.py index 80bdbe9da2..8fe162fc2b 100644 --- a/tests/parser/syntax/test_slice.py +++ b/tests/parser/syntax/test_slice.py @@ -33,7 +33,6 @@ def foo(inp: Bytes[10]) -> Bytes[3]: @pytest.mark.parametrize("bad_code,exc", fail_list) def test_slice_fail(bad_code, exc): - with pytest.raises(exc): compiler.compile_code(bad_code) diff --git a/tests/parser/types/numbers/test_constants.py b/tests/parser/types/numbers/test_constants.py index ea56968d14..0d5e386dad 100644 --- a/tests/parser/types/numbers/test_constants.py +++ b/tests/parser/types/numbers/test_constants.py @@ -48,8 +48,8 @@ def test_arithmetic(a: int128) -> int128: assert c.test_zaddress("0x0000000000000000000000000000000000000000") is True assert c.test_zaddress("0x0000000000000000000000000000000000000012") is False - assert c.test_int128(2 ** 127 - 1) == [True, False] - assert c.test_int128(-(2 ** 127)) == [False, True] + assert c.test_int128(2**127 - 1) == [True, False] + assert c.test_int128(-(2**127)) == [False, True] assert c.test_int128(0) == [False, False] assert c.test_decimal(Decimal("18707220957835557353007165858768422651595.9365500927")) == [ @@ -62,9 +62,9 @@ def test_arithmetic(a: int128) -> int128: ] assert c.test_decimal(Decimal("0.1")) == [False, False] - assert c.test_uint256(2 ** 256 - 1) is True + assert c.test_uint256(2**256 - 1) is True - assert c.test_arithmetic(5000) == 2 ** 127 - 1 - 5000 + assert c.test_arithmetic(5000) == 2**127 - 1 - 5000 def test_builtin_constants_assignment(get_contract_with_gas_estimation): @@ -107,17 +107,17 @@ def zoo() -> uint256: c = get_contract_with_gas_estimation(code) - assert c.foo() == 2 ** 127 - 1 - assert c.goo() == -(2 ** 127) + assert c.foo() == 2**127 - 1 + assert c.goo() == -(2**127) assert c.hoo() == b"\x00" * 32 assert c.joo() is None - assert c.koo() == Decimal(2 ** 167 - 1) / 10 ** 10 - assert c.loo() == Decimal(-(2 ** 167)) / 10 ** 10 + assert c.koo() == Decimal(2**167 - 1) / 10**10 + assert c.loo() == Decimal(-(2**167)) / 10**10 - assert c.zoo() == 2 ** 256 - 1 + assert c.zoo() == 2**256 - 1 def test_custom_constants(get_contract): @@ -208,7 +208,7 @@ def test() -> uint256: ir = compile_code(code, ["ir"])["ir"] assert search_for_sublist( - ir, ["mstore", [MemoryPositions.RESERVED_MEMORY], [2 ** 12 * some_prime]] + ir, ["mstore", [MemoryPositions.RESERVED_MEMORY], [2**12 * some_prime]] ) diff --git a/tests/parser/types/numbers/test_isqrt.py b/tests/parser/types/numbers/test_isqrt.py index a8b0f79def..ce26d24d06 100644 --- a/tests/parser/types/numbers/test_isqrt.py +++ b/tests/parser/types/numbers/test_isqrt.py @@ -40,7 +40,7 @@ def test(a: uint256) -> uint256: val = 3333 assert c.test(val) == math.isqrt(val) - val = 10 ** 17 + val = 10**17 assert c.test(val) == math.isqrt(val) assert c.test(0) == 0 @@ -75,7 +75,6 @@ def test(a: uint256) -> uint256: def test_isqrt_storage_internal_variable(get_contract_with_gas_estimation): - val = 44444 code = f""" s_var: uint256 diff --git a/tests/parser/types/numbers/test_signed_ints.py b/tests/parser/types/numbers/test_signed_ints.py index 2e062c78b4..281aab429c 100644 --- a/tests/parser/types/numbers/test_signed_ints.py +++ b/tests/parser/types/numbers/test_signed_ints.py @@ -86,7 +86,7 @@ def foo() -> int16: return y """ c = get_contract(code) - assert c.foo() == -(2 ** 15) + assert c.foo() == -(2**15) @pytest.mark.parametrize("base,power", itertools.product((-2, -1, 0, 1, 2), (0, 1))) @@ -99,7 +99,7 @@ def foo() -> int256: return x ** {power} """ c = get_contract(code) - assert c.foo() == base ** power + assert c.foo() == base**power @pytest.mark.parametrize("typ", types) @@ -118,7 +118,7 @@ def foo(x: {typ}) -> {typ}: if x * 2 >= typ.bits or x < 0: # out of bounds assert_tx_failed(lambda: c.foo(x)) else: - assert c.foo(x) == 4 ** x + assert c.foo(x) == 4**x @pytest.mark.parametrize("typ", types) @@ -285,7 +285,7 @@ def foo() -> {typ}: # edge cases that are tricky to reason about and MUST be tested assert lo in xs and -1 in ys - for (x, y) in itertools.product(xs, ys): + for x, y in itertools.product(xs, ys): expected = fn(x, y) in_bounds = lo <= expected <= hi diff --git a/tests/parser/types/numbers/test_unsigned_ints.py b/tests/parser/types/numbers/test_unsigned_ints.py index 41be4909b0..97a4097923 100644 --- a/tests/parser/types/numbers/test_unsigned_ints.py +++ b/tests/parser/types/numbers/test_unsigned_ints.py @@ -127,9 +127,9 @@ def foo() -> {typ}: ys += [random.randrange(lo, hi) for _ in range(NUM_CASES)] # mirror signed integer tests - assert 2 ** (bits - 1) in xs and (2 ** bits) - 1 in ys + assert 2 ** (bits - 1) in xs and (2**bits) - 1 in ys - for (x, y) in itertools.product(xs, ys): + for x, y in itertools.product(xs, ys): expected = fn(x, y) in_bounds = lo <= expected <= hi @@ -211,13 +211,13 @@ def _uint256_mulmod(x: uint256, y: uint256, z: uint256) -> uint256: assert c._uint256_addmod(1, 2, 2) == 1 assert c._uint256_addmod(32, 2, 32) == 2 - assert c._uint256_addmod((2 ** 256) - 1, 0, 2) == 1 - assert c._uint256_addmod(2 ** 255, 2 ** 255, 6) == 4 + assert c._uint256_addmod((2**256) - 1, 0, 2) == 1 + assert c._uint256_addmod(2**255, 2**255, 6) == 4 assert_tx_failed(lambda: c._uint256_addmod(1, 2, 0)) assert c._uint256_mulmod(3, 1, 2) == 1 assert c._uint256_mulmod(200, 3, 601) == 600 - assert c._uint256_mulmod(2 ** 255, 1, 3) == 2 - assert c._uint256_mulmod(2 ** 255, 2, 6) == 4 + assert c._uint256_mulmod(2**255, 1, 3) == 2 + assert c._uint256_mulmod(2**255, 2, 6) == 4 assert_tx_failed(lambda: c._uint256_mulmod(2, 2, 0)) diff --git a/tests/parser/types/test_bytes.py b/tests/parser/types/test_bytes.py index b3721af2f0..555412a687 100644 --- a/tests/parser/types/test_bytes.py +++ b/tests/parser/types/test_bytes.py @@ -198,7 +198,7 @@ def testsome_storage(y: Bytes[1]) -> bool: assert c.getsome() == b"\x0e" assert c.testsome(b"a") assert c.testsome(b"\x61") - assert c.testsome(0b1100001 .to_bytes(1, "big")) + assert c.testsome(0b1100001.to_bytes(1, "big")) assert not c.testsome(b"b") assert c.testsome_storage(b"a") assert not c.testsome_storage(b"x") diff --git a/tests/parser/types/test_bytes_zero_padding.py b/tests/parser/types/test_bytes_zero_padding.py index db9eddb615..9bc774f12f 100644 --- a/tests/parser/types/test_bytes_zero_padding.py +++ b/tests/parser/types/test_bytes_zero_padding.py @@ -26,7 +26,7 @@ def get_count(counter: uint256) -> Bytes[24]: @pytest.mark.fuzzing -@hypothesis.given(value=hypothesis.strategies.integers(min_value=0, max_value=2 ** 64)) +@hypothesis.given(value=hypothesis.strategies.integers(min_value=0, max_value=2**64)) @hypothesis.settings(deadline=400) def test_zero_pad_range(little_endian_contract, value): actual_bytes = value.to_bytes(8, byteorder="little") diff --git a/tests/parser/types/test_dynamic_array.py b/tests/parser/types/test_dynamic_array.py index 4c83133f05..04c0688245 100644 --- a/tests/parser/types/test_dynamic_array.py +++ b/tests/parser/types/test_dynamic_array.py @@ -1093,7 +1093,7 @@ def foo() -> DynArray[{subtyp}, 3]: assert c.foo() == data -@pytest.mark.parametrize("subtyp,lit", [("uint8", 256), ("uint256", -1), ("int128", 2 ** 127)]) +@pytest.mark.parametrize("subtyp,lit", [("uint8", 256), ("uint256", -1), ("int128", 2**127)]) def test_append_invalid_literal(get_contract, assert_compile_failed, subtyp, lit): code = f""" @external @@ -1689,6 +1689,7 @@ def foo() -> {typ}: # TODO test negative public(DynArray) cases? + # CMC 2022-08-04 these are blocked due to typechecker bug; leaving as # negative tests so we know if/when the typechecker is fixed. # (don't consider it a high priority to fix since membership in diff --git a/tests/parser/types/test_enum.py b/tests/parser/types/test_enum.py index 201d1ba9d0..c66efff566 100644 --- a/tests/parser/types/test_enum.py +++ b/tests/parser/types/test_enum.py @@ -67,11 +67,11 @@ def is_not_boss(a: Roles) -> bool: c = get_contract(code) for i in range(4): - assert c.is_boss(2 ** i) is False - assert c.is_not_boss(2 ** i) is True + assert c.is_boss(2**i) is False + assert c.is_not_boss(2**i) is True - assert c.is_boss(2 ** 4) is True - assert c.is_not_boss(2 ** 4) is False + assert c.is_boss(2**4) is True + assert c.is_not_boss(2**4) is False def test_bitwise(get_contract, assert_tx_failed): diff --git a/tests/parser/types/test_lists.py b/tests/parser/types/test_lists.py index fc17945167..0715eb3870 100644 --- a/tests/parser/types/test_lists.py +++ b/tests/parser/types/test_lists.py @@ -652,12 +652,12 @@ def foo(x: Bar[2][2][2]) -> uint256: [ ("decimal", [5.0, 11.0, 17.0, 29.0, 37.0, 41.0]), ("uint8", [0, 1, 17, 250, 255, 2]), - ("int128", [0, -1, 1, -(2 ** 127), 2 ** 127 - 1, -50]), - ("int256", [0, -1, 1, -(2 ** 255), 2 ** 255 - 1, -50]), - ("uint256", [0, 1, 2 ** 8, 2 ** 255 + 1, 2 ** 256 - 1, 100]), + ("int128", [0, -1, 1, -(2**127), 2**127 - 1, -50]), + ("int256", [0, -1, 1, -(2**255), 2**255 - 1, -50]), + ("uint256", [0, 1, 2**8, 2**255 + 1, 2**256 - 1, 100]), ( "uint256", - [2 ** 255 + 1, 2 ** 255 + 2, 2 ** 255 + 3, 2 ** 255 + 4, 2 ** 255 + 5, 2 ** 255 + 6], + [2**255 + 1, 2**255 + 2, 2**255 + 3, 2**255 + 4, 2**255 + 5, 2**255 + 6], ), ("bool", [True, False, True, False, True, False]), ], @@ -750,15 +750,15 @@ def ix(i: uint256) -> address: [ ("decimal", [[5.0, 11.0], [17.0, 29.0], [37.0, 41.0]]), ("uint8", [[0, 1], [17, 250], [255, 2]]), - ("int128", [[0, -1], [1, -(2 ** 127)], [2 ** 127 - 1, -50]]), - ("int256", [[0, -1], [1, -(2 ** 255)], [2 ** 255 - 1, -50]]), - ("uint256", [[0, 1], [2 ** 8, 2 ** 255 + 1], [2 ** 256 - 1, 100]]), + ("int128", [[0, -1], [1, -(2**127)], [2**127 - 1, -50]]), + ("int256", [[0, -1], [1, -(2**255)], [2**255 - 1, -50]]), + ("uint256", [[0, 1], [2**8, 2**255 + 1], [2**256 - 1, 100]]), ( "uint256", [ - [2 ** 255 + 1, 2 ** 255 + 2], - [2 ** 255 + 3, 2 ** 255 + 4], - [2 ** 255 + 5, 2 ** 255 + 6], + [2**255 + 1, 2**255 + 2], + [2**255 + 3, 2**255 + 4], + [2**255 + 5, 2**255 + 6], ], ), ("bool", [[True, False], [True, False], [True, False]]), diff --git a/tests/parser/types/test_node_types.py b/tests/parser/types/test_node_types.py index 8689d51f8f..b6561ae8eb 100644 --- a/tests/parser/types/test_node_types.py +++ b/tests/parser/types/test_node_types.py @@ -15,7 +15,6 @@ def test_bytearray_node_type(): - node1 = BytesT(12) node2 = BytesT(12) diff --git a/tests/parser/types/test_string.py b/tests/parser/types/test_string.py index 560449a504..9193c5f69d 100644 --- a/tests/parser/types/test_string.py +++ b/tests/parser/types/test_string.py @@ -56,7 +56,7 @@ def get(k: String[34]) -> int128: c = get_contract(code) - c.set(b"a" * 34, 6789, transact={"gas": 10 ** 6}) + c.set(b"a" * 34, 6789, transact={"gas": 10**6}) assert c.get(b"a" * 34) == 6789 @@ -152,7 +152,6 @@ def test(addr: address) -> (int128, address, String[10]): def test_default_arg_string(get_contract_with_gas_estimation): - code = """ @external def test(a: uint256, b: String[50] = "foo") -> Bytes[100]: diff --git a/tests/parser/types/value/test_as_wei_value.py b/tests/parser/types/value/test_as_wei_value.py index 3fef80a967..249ac4b2ff 100644 --- a/tests/parser/types/value/test_as_wei_value.py +++ b/tests/parser/types/value/test_as_wei_value.py @@ -32,10 +32,10 @@ def foo(a: uint256) -> uint256: c = get_contract(code) - value = (2 ** 256 - 1) // (10 ** multiplier) - assert c.foo(value) == value * (10 ** multiplier) + value = (2**256 - 1) // (10**multiplier) + assert c.foo(value) == value * (10**multiplier) - value = (2 ** 256 - 1) // (10 ** (multiplier - 1)) + value = (2**256 - 1) // (10 ** (multiplier - 1)) assert_tx_failed(lambda: c.foo(value)) @@ -48,9 +48,9 @@ def foo(a: int128) -> uint256: """ c = get_contract(code) - value = (2 ** 127 - 1) // (10 ** multiplier) + value = (2**127 - 1) // (10**multiplier) - assert c.foo(value) == value * (10 ** multiplier) + assert c.foo(value) == value * (10**multiplier) @pytest.mark.parametrize("denom,multiplier", wei_denoms.items()) @@ -62,12 +62,12 @@ def foo(a: decimal) -> uint256: """ c = get_contract(code) - value = Decimal((2 ** 127 - 1) / (10 ** multiplier)) + value = Decimal((2**127 - 1) / (10**multiplier)) - assert c.foo(value) == value * (10 ** multiplier) + assert c.foo(value) == value * (10**multiplier) -@pytest.mark.parametrize("value", (-1, -(2 ** 127))) +@pytest.mark.parametrize("value", (-1, -(2**127))) @pytest.mark.parametrize("data_type", ["decimal", "int128"]) def test_negative_value_reverts(get_contract, assert_tx_failed, value, data_type): code = f""" diff --git a/vyper/__main__.py b/vyper/__main__.py index 5fe6f54cd6..371975c301 100644 --- a/vyper/__main__.py +++ b/vyper/__main__.py @@ -5,7 +5,6 @@ from vyper.cli import vyper_compile, vyper_ir, vyper_serve if __name__ == "__main__": - allowed_subcommands = ("--vyper-compile", "--vyper-ir", "--vyper-serve") if len(sys.argv) <= 1 or sys.argv[1] not in allowed_subcommands: diff --git a/vyper/ast/folding.py b/vyper/ast/folding.py index cd0fcc3c55..fbd1dfc2f4 100644 --- a/vyper/ast/folding.py +++ b/vyper/ast/folding.py @@ -15,11 +15,11 @@ "empty(bytes32)", ), # NOQA: E501 "ZERO_ADDRESS": (vy_ast.Hex, "0x0000000000000000000000000000000000000000", "empty(address)"), - "MAX_INT128": (vy_ast.Int, 2 ** 127 - 1, "max_value(int128)"), - "MIN_INT128": (vy_ast.Int, -(2 ** 127), "min_value(int128)"), + "MAX_INT128": (vy_ast.Int, 2**127 - 1, "max_value(int128)"), + "MIN_INT128": (vy_ast.Int, -(2**127), "min_value(int128)"), "MAX_DECIMAL": (vy_ast.Decimal, SizeLimits.MAX_AST_DECIMAL, "max_value(decimal)"), "MIN_DECIMAL": (vy_ast.Decimal, SizeLimits.MIN_AST_DECIMAL, "min_value(decimal)"), - "MAX_UINT256": (vy_ast.Int, 2 ** 256 - 1, "max_value(uint256)"), + "MAX_UINT256": (vy_ast.Int, 2**256 - 1, "max_value(uint256)"), } diff --git a/vyper/ast/natspec.py b/vyper/ast/natspec.py index f169c7695e..e6f0fcd00b 100644 --- a/vyper/ast/natspec.py +++ b/vyper/ast/natspec.py @@ -73,7 +73,6 @@ def _parse_docstring( params: Optional[Tuple] = None, return_length: int = 0, ) -> dict: - natspec: dict = {} if params is None: params = tuple() diff --git a/vyper/ast/nodes.py b/vyper/ast/nodes.py index 39add6905b..cbbd019337 100644 --- a/vyper/ast/nodes.py +++ b/vyper/ast/nodes.py @@ -939,7 +939,7 @@ class Invert(Operator): _pretty = "~" def _op(self, value): - return (2 ** 256 - 1) ^ value + return (2**256 - 1) ^ value class BinOp(ExprNode): @@ -1048,7 +1048,7 @@ def _op(self, left, right): raise TypeMismatch("Cannot perform exponentiation on decimal values.", self._parent) if right < 0: raise InvalidOperation("Cannot calculate a negative power", self._parent) - return int(left ** right) + return int(left**right) class BitAnd(Operator): diff --git a/vyper/ast/validation.py b/vyper/ast/validation.py index cd169178f6..7742d60c01 100644 --- a/vyper/ast/validation.py +++ b/vyper/ast/validation.py @@ -45,7 +45,7 @@ def validate_call_args( # -1 is sentinel which means we have varargs. # set arg_count[1] to some large number that we # would never see in practice - arg_count = (arg_count[0], 2 ** 64) + arg_count = (arg_count[0], 2**64) if arg_count[0] == arg_count[1]: arg_count == arg_count[0] diff --git a/vyper/builtins/_convert.py b/vyper/builtins/_convert.py index 08657c57d3..407a32f3e9 100644 --- a/vyper/builtins/_convert.py +++ b/vyper/builtins/_convert.py @@ -109,7 +109,7 @@ def _clamp_numeric_convert(arg, arg_bounds, out_bounds, arg_is_signed): if arg_hi > out_hi: # out_hi must be smaller than MAX_UINT256, so clample makes sense. # add an assertion, just in case this assumption ever changes. - assert out_hi < 2 ** 256 - 1, "bad assumption in numeric convert" + assert out_hi < 2**256 - 1, "bad assumption in numeric convert" CLAMP_OP = "sle" if arg_is_signed else "le" arg = clamp(CLAMP_OP, arg, out_hi) @@ -156,7 +156,6 @@ def _int_to_int(arg, out_typ): # _clamp_numeric_convert(arg, arg.typ.int_bounds, out_typ.int_bounds, arg.typ.is_signed) # but with better code size and gas. if arg.typ.is_signed and not out_typ.is_signed: - # e.g. (clample (clampge arg 0) (2**128 - 1)) # note that when out_typ.bits == 256, @@ -164,7 +163,6 @@ def _int_to_int(arg, out_typ): # see similar assertion in _clamp_numeric_convert. if out_typ.bits < arg.typ.bits: - assert out_typ.bits < 256, "unreachable" # note: because of the usage of signed=False, and the fact # that out_bits < 256 in this branch, below implies @@ -359,7 +357,7 @@ def to_decimal(expr, arg, out_typ): elif arg.typ == BoolT(): # TODO: consider adding is_signed and bits to bool so we can use _int_to_fixed - arg = ["mul", arg, 10 ** out_typ.decimals] + arg = ["mul", arg, 10**out_typ.decimals] return IRnode.from_list(arg, typ=out_typ) else: raise CompilerPanic("unreachable") # pragma: notest diff --git a/vyper/builtins/_signatures.py b/vyper/builtins/_signatures.py index 3ee379a806..d39a4a085f 100644 --- a/vyper/builtins/_signatures.py +++ b/vyper/builtins/_signatures.py @@ -75,7 +75,6 @@ def decorator_fn(self, node, context): class BuiltinFunction: - _has_varargs = False _kwargs: Dict[str, KwargSettings] = {} diff --git a/vyper/builtins/functions.py b/vyper/builtins/functions.py index 64452c39ac..6c00678d5c 100644 --- a/vyper/builtins/functions.py +++ b/vyper/builtins/functions.py @@ -133,7 +133,6 @@ def infer_arg_types(self, node): class Floor(BuiltinFunction): - _id = "floor" _inputs = [("value", DecimalT())] # TODO: maybe use int136? @@ -161,7 +160,6 @@ def build_IR(self, expr, args, kwargs, context): class Ceil(BuiltinFunction): - _id = "ceil" _inputs = [("value", DecimalT())] # TODO: maybe use int136? @@ -189,7 +187,6 @@ def build_IR(self, expr, args, kwargs, context): class Convert(BuiltinFunction): - _id = "convert" def fetch_call_return(self, node): @@ -283,7 +280,6 @@ def _build_adhoc_slice_node(sub: IRnode, start: IRnode, length: IRnode, context: # note: this and a lot of other builtins could be refactored to accept any uint type class Slice(BuiltinFunction): - _id = "slice" _inputs = [ ("b", (BYTES32_T, BytesT.any(), StringT.any())), @@ -344,7 +340,6 @@ def infer_arg_types(self, node): @process_inputs def build_IR(self, expr, args, kwargs, context): - src, start, length = args # Handle `msg.data`, `self.code`, and `
.code` @@ -362,7 +357,6 @@ def build_IR(self, expr, args, kwargs, context): b2, start, ), length.cache_when_complex("length") as (b3, length): - if is_bytes32: src_maxlen = 32 else: @@ -458,7 +452,6 @@ def build_IR(self, expr, args, kwargs, context): class Len(BuiltinFunction): - _id = "len" _inputs = [("b", (StringT.any(), BytesT.any(), DArrayT.any()))] _return_type = UINT256_T @@ -484,7 +477,6 @@ def build_IR(self, node, context): class Concat(BuiltinFunction): - _id = "concat" def fetch_call_return(self, node): @@ -557,7 +549,6 @@ def build_IR(self, expr, context): # TODO: optimize for the case where all lengths are statically known. for arg in args: - dst_data = add_ofst(bytes_data_ptr(dst), ofst) if isinstance(arg.typ, _BytestringT): @@ -569,7 +560,6 @@ def build_IR(self, expr, context): argdata = bytes_data_ptr(arg) with get_bytearray_length(arg).cache_when_complex("len") as (b2, arglen): - do_copy = [ "seq", copy_bytes(dst_data, argdata, arglen, arg.typ.maxlen), @@ -592,7 +582,6 @@ def build_IR(self, expr, context): class Keccak256(BuiltinFunction): - _id = "keccak256" # TODO allow any BytesM_T _inputs = [("value", (BytesT.any(), BYTES32_T, StringT.any()))] @@ -641,7 +630,6 @@ def _make_sha256_call(inp_start, inp_len, out_start, out_len): class Sha256(BuiltinFunction): - _id = "sha256" _inputs = [("value", (BYTES32_T, BytesT.any(), StringT.any()))] _return_type = BYTES32_T @@ -714,7 +702,6 @@ def build_IR(self, expr, args, kwargs, context): class MethodID(FoldedFunction): - _id = "method_id" def evaluate(self, node): @@ -755,7 +742,6 @@ def infer_kwarg_types(self, node): class ECRecover(BuiltinFunction): - _id = "ecrecover" _inputs = [ ("hash", BYTES32_T), @@ -805,7 +791,6 @@ def _getelem(arg, ind): class ECAdd(BuiltinFunction): - _id = "ecadd" _inputs = [("a", SArrayT(UINT256_T, 2)), ("b", SArrayT(UINT256_T, 2))] _return_type = SArrayT(UINT256_T, 2) @@ -832,7 +817,6 @@ def build_IR(self, expr, args, kwargs, context): class ECMul(BuiltinFunction): - _id = "ecmul" _inputs = [("point", SArrayT(UINT256_T, 2)), ("scalar", UINT256_T)] _return_type = SArrayT(UINT256_T, 2) @@ -871,7 +855,6 @@ def _storage_element_getter(index): class Extract32(BuiltinFunction): - _id = "extract32" _inputs = [("b", BytesT.any()), ("start", IntegerT.unsigneds())] # "TYPE_DEFINITION" is a placeholder value for a type definition string, and @@ -984,20 +967,19 @@ def build_IR(self, expr, args, kwargs, context): class AsWeiValue(BuiltinFunction): - _id = "as_wei_value" _inputs = [("value", (IntegerT.any(), DecimalT())), ("unit", StringT.any())] _return_type = UINT256_T wei_denoms = { ("wei",): 1, - ("femtoether", "kwei", "babbage"): 10 ** 3, - ("picoether", "mwei", "lovelace"): 10 ** 6, - ("nanoether", "gwei", "shannon"): 10 ** 9, - ("microether", "szabo"): 10 ** 12, - ("milliether", "finney"): 10 ** 15, - ("ether",): 10 ** 18, - ("kether", "grand"): 10 ** 21, + ("femtoether", "kwei", "babbage"): 10**3, + ("picoether", "mwei", "lovelace"): 10**6, + ("nanoether", "gwei", "shannon"): 10**9, + ("microether", "szabo"): 10**12, + ("milliether", "finney"): 10**15, + ("ether",): 10**18, + ("kether", "grand"): 10**21, } def get_denomination(self, node): @@ -1025,7 +1007,7 @@ def evaluate(self, node): if value < 0: raise InvalidLiteral("Negative wei value not allowed", node.args[0]) - if isinstance(value, int) and value >= 2 ** 256: + if isinstance(value, int) and value >= 2**256: raise InvalidLiteral("Value out of range for uint256", node.args[0]) if isinstance(value, Decimal) and value > SizeLimits.MAX_AST_DECIMAL: raise InvalidLiteral("Value out of range for decimal", node.args[0]) @@ -1083,7 +1065,6 @@ def build_IR(self, expr, args, kwargs, context): class RawCall(BuiltinFunction): - _id = "raw_call" _inputs = [("to", AddressT()), ("data", BytesT.any())] _kwargs = { @@ -1230,7 +1211,6 @@ def build_IR(self, expr, args, kwargs, context): class Send(BuiltinFunction): - _id = "send" _inputs = [("to", AddressT()), ("value", UINT256_T)] # default gas stipend is 0 @@ -1246,7 +1226,6 @@ def build_IR(self, expr, args, kwargs, context): class SelfDestruct(BuiltinFunction): - _id = "selfdestruct" _inputs = [("to", AddressT())] _return_type = None @@ -1261,7 +1240,6 @@ def build_IR(self, expr, args, kwargs, context): class BlockHash(BuiltinFunction): - _id = "blockhash" _inputs = [("block_num", UINT256_T)] _return_type = BYTES32_T @@ -1275,7 +1253,6 @@ def build_IR(self, expr, args, kwargs, contact): class RawRevert(BuiltinFunction): - _id = "raw_revert" _inputs = [("data", BytesT.any())] @@ -1296,7 +1273,6 @@ def build_IR(self, expr, args, kwargs, context): class RawLog(BuiltinFunction): - _id = "raw_log" _inputs = [("topics", DArrayT(BYTES32_T, 4)), ("data", (BYTES32_T, BytesT.any()))] @@ -1348,7 +1324,6 @@ def build_IR(self, expr, args, kwargs, context): class BitwiseAnd(BuiltinFunction): - _id = "bitwise_and" _inputs = [("x", UINT256_T), ("y", UINT256_T)] _return_type = UINT256_T @@ -1363,7 +1338,7 @@ def evaluate(self, node): for arg in node.args: if not isinstance(arg, vy_ast.Num): raise UnfoldableNode - if arg.value < 0 or arg.value >= 2 ** 256: + if arg.value < 0 or arg.value >= 2**256: raise InvalidLiteral("Value out of range for uint256", arg) value = node.args[0].value & node.args[1].value @@ -1375,7 +1350,6 @@ def build_IR(self, expr, args, kwargs, context): class BitwiseOr(BuiltinFunction): - _id = "bitwise_or" _inputs = [("x", UINT256_T), ("y", UINT256_T)] _return_type = UINT256_T @@ -1390,7 +1364,7 @@ def evaluate(self, node): for arg in node.args: if not isinstance(arg, vy_ast.Num): raise UnfoldableNode - if arg.value < 0 or arg.value >= 2 ** 256: + if arg.value < 0 or arg.value >= 2**256: raise InvalidLiteral("Value out of range for uint256", arg) value = node.args[0].value | node.args[1].value @@ -1402,7 +1376,6 @@ def build_IR(self, expr, args, kwargs, context): class BitwiseXor(BuiltinFunction): - _id = "bitwise_xor" _inputs = [("x", UINT256_T), ("y", UINT256_T)] _return_type = UINT256_T @@ -1417,7 +1390,7 @@ def evaluate(self, node): for arg in node.args: if not isinstance(arg, vy_ast.Num): raise UnfoldableNode - if arg.value < 0 or arg.value >= 2 ** 256: + if arg.value < 0 or arg.value >= 2**256: raise InvalidLiteral("Value out of range for uint256", arg) value = node.args[0].value ^ node.args[1].value @@ -1429,7 +1402,6 @@ def build_IR(self, expr, args, kwargs, context): class BitwiseNot(BuiltinFunction): - _id = "bitwise_not" _inputs = [("x", UINT256_T)] _return_type = UINT256_T @@ -1445,10 +1417,10 @@ def evaluate(self, node): raise UnfoldableNode value = node.args[0].value - if value < 0 or value >= 2 ** 256: + if value < 0 or value >= 2**256: raise InvalidLiteral("Value out of range for uint256", node.args[0]) - value = (2 ** 256 - 1) - value + value = (2**256 - 1) - value return vy_ast.Int.from_node(node, value=value) @process_inputs @@ -1457,7 +1429,6 @@ def build_IR(self, expr, args, kwargs, context): class Shift(BuiltinFunction): - _id = "shift" _inputs = [("x", (UINT256_T, INT256_T)), ("_shift", IntegerT.any())] _return_type = UINT256_T @@ -1467,7 +1438,7 @@ def evaluate(self, node): if [i for i in node.args if not isinstance(i, vy_ast.Num)]: raise UnfoldableNode value, shift = [i.value for i in node.args] - if value < 0 or value >= 2 ** 256: + if value < 0 or value >= 2**256: raise InvalidLiteral("Value out of range for uint256", node.args[0]) if shift < -256 or shift > 256: # this validation is performed to prevent the compiler from hanging @@ -1478,7 +1449,7 @@ def evaluate(self, node): if shift < 0: value = value >> -shift else: - value = (value << shift) % (2 ** 256) + value = (value << shift) % (2**256) return vy_ast.Int.from_node(node, value=value) def fetch_call_return(self, node): @@ -1507,7 +1478,6 @@ def build_IR(self, expr, args, kwargs, context): class _AddMulMod(BuiltinFunction): - _inputs = [("a", UINT256_T), ("b", UINT256_T), ("c", UINT256_T)] _return_type = UINT256_T @@ -1518,7 +1488,7 @@ def evaluate(self, node): for arg in node.args: if not isinstance(arg, vy_ast.Num): raise UnfoldableNode - if arg.value < 0 or arg.value >= 2 ** 256: + if arg.value < 0 or arg.value >= 2**256: raise InvalidLiteral("Value out of range for uint256", arg) value = self._eval_fn(node.args[0].value, node.args[1].value) % node.args[2].value @@ -1557,7 +1527,7 @@ def evaluate(self, node): if left.value < 0 or right.value < 0: raise UnfoldableNode - value = pow(left.value, right.value, 2 ** 256) + value = pow(left.value, right.value, 2**256) return vy_ast.Int.from_node(node, value=value) def build_IR(self, expr, context): @@ -1604,6 +1574,7 @@ def build_IR(self, expr, context): # CREATE* functions + # create helper functions # generates CREATE op sequence + zero check for result def _create_ir(value, buf, length, salt=None, checked=True): @@ -1686,7 +1657,6 @@ def eip1167_bytecode(): # returns the code starting from 0x0b with len `codesize`. # NOTE: it assumes codesize <= 2**24. def _create_preamble(codesize): - from vyper.ir.compile_ir import assembly_to_evm evm_len = 0x0B # 11 bytes @@ -1750,7 +1720,6 @@ def _add_gas_estimate(self, args, should_use_create2): return _create_addl_gas_estimate(bytecode_len, should_use_create2) def _build_create_IR(self, expr, args, context, value, salt): - target_address = args[0] buf = context.new_internal_variable(BytesT(96)) @@ -1794,7 +1763,6 @@ def build_IR(self, expr, context): class CreateCopyOf(_CreateBase): - _id = "create_copy_of" _inputs = [("target", AddressT())] @@ -1840,7 +1808,6 @@ def _build_create_IR(self, expr, args, context, value, salt): class CreateFromBlueprint(_CreateBase): - _id = "create_from_blueprint" _inputs = [("target", AddressT())] _kwargs = { @@ -1934,7 +1901,6 @@ def _build_create_IR(self, expr, args, context, value, salt, code_offset, raw_ar class _UnsafeMath(BuiltinFunction): - # TODO add unsafe math for `decimal`s _inputs = [("a", IntegerT.any()), ("b", IntegerT.any())] @@ -1977,7 +1943,7 @@ def build_IR(self, expr, args, kwargs, context): else: # e.g. uint8 -> (mod (add x y) 256) # TODO mod_bound could be a really large literal - ret = ["mod", ret, 2 ** a.typ.bits] + ret = ["mod", ret, 2**a.typ.bits] return IRnode.from_list(ret, typ=otyp) @@ -2001,7 +1967,6 @@ class UnsafeDiv(_UnsafeMath): class _MinMax(BuiltinFunction): - _inputs = [("a", (DecimalT(), IntegerT.any())), ("b", (DecimalT(), IntegerT.any()))] def evaluate(self, node): @@ -2051,7 +2016,6 @@ def build_IR(self, expr, args, kwargs, context): b2, right, ): - if left.typ == right.typ: if left.typ != UINT256_T: # if comparing like types that are not uint256, use SLT or SGT @@ -2105,7 +2069,6 @@ def build_IR(self, expr, args, kwargs, context): n_digits = return_t.maxlen with args[0].cache_when_complex("val") as (b1, val): - buf = context.new_internal_variable(return_t) i = IRnode.from_list(context.fresh_varname("uint2str_i"), typ=UINT256_T) @@ -2150,7 +2113,6 @@ def build_IR(self, expr, args, kwargs, context): class Sqrt(BuiltinFunction): - _id = "sqrt" _inputs = [("d", DecimalT())] _return_type = DecimalT() @@ -2207,7 +2169,6 @@ def build_IR(self, expr, args, kwargs, context): class ISqrt(BuiltinFunction): - _id = "isqrt" _inputs = [("d", UINT256_T)] _return_type = UINT256_T @@ -2242,7 +2203,7 @@ def build_IR(self, expr, args, kwargs, context): ["seq", ["set", y, shr(16, y)], ["set", z, shl(8, z)]], ], ] - ret.append(["set", z, ["div", ["mul", z, ["add", y, 2 ** 16]], 2 ** 18]]) + ret.append(["set", z, ["div", ["mul", z, ["add", y, 2**16]], 2**18]]) for _ in range(7): ret.append(["set", z, ["div", ["add", ["div", x, z], z], 2]]) @@ -2258,7 +2219,6 @@ def build_IR(self, expr, args, kwargs, context): class Empty(TypenameFoldedFunction): - _id = "empty" def fetch_call_return(self, node): @@ -2535,7 +2495,6 @@ def build_IR(self, expr, args, kwargs, context): data = ensure_in_memory(data, context) with data.cache_when_complex("to_decode") as (b1, data): - data_ptr = bytes_data_ptr(data) data_len = get_bytearray_length(data) diff --git a/vyper/cli/vyper_compile.py b/vyper/cli/vyper_compile.py index 40f87d860a..09ddd971ee 100755 --- a/vyper/cli/vyper_compile.py +++ b/vyper/cli/vyper_compile.py @@ -199,7 +199,6 @@ def get_interface_codes(root_path: Path, contract_sources: ContractCodes) -> Dic interface_codes = extract_file_interface_imports(code) for interface_name, interface_path in interface_codes.items(): - base_paths = [parent_path] if not interface_path.startswith(".") and root_path.joinpath(file_path).exists(): base_paths.append(root_path) @@ -257,7 +256,6 @@ def compile_files( storage_layout: Iterable[str] = None, no_bytecode_metadata: bool = False, ) -> OrderedDict: - root_path = Path(root_folder).resolve() if not root_path.exists(): raise FileNotFoundError(f"Invalid root path - '{root_path.as_posix()}' does not exist") diff --git a/vyper/cli/vyper_json.py b/vyper/cli/vyper_json.py index 0abefdebff..dcbf61740a 100755 --- a/vyper/cli/vyper_json.py +++ b/vyper/cli/vyper_json.py @@ -392,7 +392,6 @@ def compile_from_input_dict( def format_to_output_dict(compiler_data: Dict) -> Dict: output_dict: Dict = {"compiler": f"vyper-{vyper.__version__}", "contracts": {}, "sources": {}} for id_, (path, data) in enumerate(compiler_data.items()): - output_dict["sources"][path] = {"id": id_} if "ast_dict" in data: output_dict["sources"][path]["ast"] = data["ast_dict"]["ast"] diff --git a/vyper/cli/vyper_serve.py b/vyper/cli/vyper_serve.py index 564e0d0110..87fd3a3387 100755 --- a/vyper/cli/vyper_serve.py +++ b/vyper/cli/vyper_serve.py @@ -64,7 +64,6 @@ def do_GET(self): return def do_POST(self): - if self.path == "/compile": content_len = int(self.headers.get("content-length")) post_body = self.rfile.read(content_len) diff --git a/vyper/codegen/abi_encoder.py b/vyper/codegen/abi_encoder.py index 112385e992..e76fbf2f64 100644 --- a/vyper/codegen/abi_encoder.py +++ b/vyper/codegen/abi_encoder.py @@ -190,7 +190,6 @@ def abi_encode(dst, ir_node, context, bufsz, returns_len=False): with ir_node.cache_when_complex("to_encode") as (b1, ir_node), dst.cache_when_complex( "dst" ) as (b2, dst): - dyn_ofst = "dyn_ofst" # current offset in the dynamic section if ir_node.typ._is_prim_word: diff --git a/vyper/codegen/arithmetic.py b/vyper/codegen/arithmetic.py index c91d0ecc58..8f8a9f904b 100644 --- a/vyper/codegen/arithmetic.py +++ b/vyper/codegen/arithmetic.py @@ -41,9 +41,9 @@ def calculate_largest_power(a: int, num_bits: int, is_signed: bool) -> int: raise CompilerPanic("Exponential operation is useless!") value_bits = num_bits - (1 if is_signed else 0) - if a >= 2 ** value_bits: # pragma: no cover + if a >= 2**value_bits: # pragma: no cover raise TypeCheckFailure("Value is too large and will always throw") - if a < -(2 ** value_bits): # pragma: no cover + if a < -(2**value_bits): # pragma: no cover raise TypeCheckFailure("Value is too small and will always throw") a_is_negative = a < 0 @@ -65,11 +65,11 @@ def calculate_largest_power(a: int, num_bits: int, is_signed: bool) -> int: # x = ln(2**value_bits) / ln(a) num_iterations = 0 - while a ** (b + 1) < 2 ** value_bits: + while a ** (b + 1) < 2**value_bits: b += 1 num_iterations += 1 assert num_iterations < 10000 - while a ** b >= 2 ** value_bits: + while a**b >= 2**value_bits: b -= 1 num_iterations += 1 assert num_iterations < 10000 @@ -78,7 +78,7 @@ def calculate_largest_power(a: int, num_bits: int, is_signed: bool) -> int: # (-a) ** (b + 1) == -(2 ** value_bits) # we can squeak one more out of it because lower bound of signed ints # is slightly wider than upper bound - if a_is_negative and (-a) ** (b + 1) == -(2 ** value_bits): # NOTE: a = abs(a) + if a_is_negative and (-a) ** (b + 1) == -(2**value_bits): # NOTE: a = abs(a) return b + 1 else: return b # Exact @@ -132,11 +132,11 @@ def calculate_largest_base(b: int, num_bits: int, is_signed: bool) -> Tuple[int, a = math.ceil(2 ** (decimal.Decimal(value_bits) / decimal.Decimal(b))) # Do a bit of iteration to ensure we have the exact number num_iterations = 0 - while (a + 1) ** b < 2 ** value_bits: + while (a + 1) ** b < 2**value_bits: a += 1 num_iterations += 1 assert num_iterations < 10000 - while a ** b >= 2 ** value_bits: + while a**b >= 2**value_bits: a -= 1 num_iterations += 1 assert num_iterations < 10000 @@ -144,7 +144,7 @@ def calculate_largest_base(b: int, num_bits: int, is_signed: bool) -> Tuple[int, if not is_signed: return 0, a - if (a + 1) ** b == (2 ** value_bits): + if (a + 1) ** b == (2**value_bits): # edge case: lower bound is slightly wider than upper bound return -(a + 1), a else: @@ -231,7 +231,6 @@ def safe_mul(x, y): DIV = "sdiv" if typ.is_signed else "div" with res.cache_when_complex("ans") as (b1, res): - ok = [1] # True if typ.bits > 128: # check overflow mod 256 @@ -247,7 +246,7 @@ def safe_mul(x, y): if version_check(begin="constantinople"): upper_bound = ["shl", 255, 1] else: - upper_bound = -(2 ** 255) + upper_bound = -(2**255) check_x = ["ne", x, upper_bound] check_y = ["ne", ["not", y], 0] @@ -257,7 +256,7 @@ def safe_mul(x, y): ok = ["and", ok, ["or", check_x, check_y]] # TODO push some of this constant folding into optimizer - elif x.is_literal and x.value == -(2 ** 255): + elif x.is_literal and x.value == -(2**255): ok = ["and", ok, check_y] elif y.is_literal and y.value == -1: ok = ["and", ok, check_x] @@ -291,7 +290,7 @@ def safe_div(x, y): if is_decimal_type(x.typ): lo, hi = typ.int_bounds - if max(abs(lo), abs(hi)) * typ.divisor > 2 ** 256 - 1: + if max(abs(lo), abs(hi)) * typ.divisor > 2**256 - 1: # stub to prevent us from adding fixed point numbers we don't know # how to deal with raise UnimplementedException("safe_mul for decimal{typ.bits}x{typ.decimals}") @@ -300,18 +299,17 @@ def safe_div(x, y): DIV = "sdiv" if typ.is_signed else "div" res = IRnode.from_list([DIV, x, clamp("gt", y, 0)], typ=typ) with res.cache_when_complex("res") as (b1, res): - # TODO: refactor this condition / push some things into the optimizer if typ.is_signed and typ.bits == 256: if version_check(begin="constantinople"): upper_bound = ["shl", 255, 1] else: - upper_bound = -(2 ** 255) + upper_bound = -(2**255) if not x.is_literal and not y.is_literal: ok = ["or", ["ne", y, ["not", 0]], ["ne", x, upper_bound]] # TODO push these rules into the optimizer - elif x.is_literal and x.value == -(2 ** 255): + elif x.is_literal and x.value == -(2**255): ok = ["ne", y, ["not", 0]] elif y.is_literal and y.value == -1: ok = ["ne", x, upper_bound] diff --git a/vyper/codegen/core.py b/vyper/codegen/core.py index cde65adc9e..ca161ddb8d 100644 --- a/vyper/codegen/core.py +++ b/vyper/codegen/core.py @@ -114,7 +114,6 @@ def make_byte_array_copier(dst, src): with src.cache_when_complex("src") as (b1, src): with get_bytearray_length(src).cache_when_complex("len") as (b2, len_): - max_bytes = src.typ.maxlen ret = ["seq"] @@ -171,7 +170,6 @@ def _dynarray_make_setter(dst, src): return ret with src.cache_when_complex("darray_src") as (b1, src): - # for ABI-encoded dynamic data, we must loop to unpack, since # the layout does not match our memory layout should_loop = src.encoding == Encoding.ABI and src.typ.value_type.abi_type.is_dynamic() @@ -237,7 +235,6 @@ def copy_bytes(dst, src, length, length_bound): with src.cache_when_complex("src") as (b1, src), length.cache_when_complex( "copy_bytes_count" ) as (b2, length), dst.cache_when_complex("dst") as (b3, dst): - assert isinstance(length_bound, int) and length_bound >= 0 # correctness: do not clobber dst @@ -484,7 +481,6 @@ def has_length_word(typ): # TODO simplify this code, especially the ABI decoding def _get_element_ptr_array(parent, key, array_bounds_check): - assert is_array_like(parent.typ) if not is_integer_type(key.typ): @@ -750,7 +746,7 @@ def FAIL(): # pragma: no cover else: if len(left.typ.member_types) != len(right.typ.member_types): FAIL() # pragma: notest - for (l, r) in zip(left.typ.member_types, right.typ.member_types): + for l, r in zip(left.typ.member_types, right.typ.member_types): # TODO recurse into left, right if literals? check_assign(dummy_node_for_type(l), dummy_node_for_type(r)) @@ -886,7 +882,6 @@ def _complex_make_setter(left, right): # general case # TODO use copy_bytes when the generated code is above a certain size with left.cache_when_complex("_L") as (b1, left), right.cache_when_complex("_R") as (b2, right): - for k in keys: l_i = get_element_ptr(left, k, array_bounds_check=False) r_i = get_element_ptr(right, k, array_bounds_check=False) diff --git a/vyper/codegen/expr.py b/vyper/codegen/expr.py index e95bec884c..33c400941e 100644 --- a/vyper/codegen/expr.py +++ b/vyper/codegen/expr.py @@ -159,7 +159,6 @@ def parse_NameConstant(self): # Variable names def parse_Name(self): - if self.expr.id == "self": return IRnode.from_list(["address"], typ=AddressT()) elif self.expr.id in self.context.vars: @@ -203,7 +202,7 @@ def parse_Attribute(self): ): # 0, 1, 2, .. 255 enum_id = typ._enum_members[self.expr.attr] - value = 2 ** enum_id # 0 => 0001, 1 => 0010, 2 => 0100, etc. + value = 2**enum_id # 0 => 0001, 1 => 0010, 2 => 0100, etc. return IRnode.from_list(value, typ=typ) # x.balance: balance of address x @@ -602,7 +601,7 @@ def parse_UnaryOp(self): # `operand`. `mask` could be a very large constant and # hurt codesize, but most user enums will likely have few # enough members that the mask will not be large. - mask = (2 ** n_members) - 1 + mask = (2**n_members) - 1 return IRnode.from_list(["xor", mask, operand], typ=operand.typ) if operand.typ == UINT256_T: diff --git a/vyper/codegen/function_definitions/external_function.py b/vyper/codegen/function_definitions/external_function.py index 6de5bab16f..feb2973e2a 100644 --- a/vyper/codegen/function_definitions/external_function.py +++ b/vyper/codegen/function_definitions/external_function.py @@ -28,7 +28,6 @@ def _register_function_args(context: Context, sig: FunctionSignature) -> List[IR base_args_ofst = IRnode(4, location=CALLDATA, typ=base_args_t, encoding=Encoding.ABI) for i, arg in enumerate(sig.base_args): - arg_ir = get_element_ptr(base_args_ofst, i) if needs_clamp(arg.typ, Encoding.ABI): diff --git a/vyper/codegen/ir_node.py b/vyper/codegen/ir_node.py index 9bfe20abe7..c2c127b9d5 100644 --- a/vyper/codegen/ir_node.py +++ b/vyper/codegen/ir_node.py @@ -152,7 +152,7 @@ def _check(condition, err): _check(len(self.args) == 0, "int can't have arguments") # integers must be in the range (MIN_INT256, MAX_UINT256) - _check(-(2 ** 255) <= self.value < 2 ** 256, "out of range") + _check(-(2**255) <= self.value < 2**256, "out of range") self.valency = 1 self._gas = 5 @@ -442,9 +442,7 @@ def _colorise_keywords(val): return val def repr(self) -> str: - if not len(self.args): - if self.annotation: return f"{self.repr_value} " + OKLIGHTBLUE + f"<{self.annotation}>" + ENDC else: diff --git a/vyper/codegen/return_.py b/vyper/codegen/return_.py index 6f2250ddeb..1cd50075a1 100644 --- a/vyper/codegen/return_.py +++ b/vyper/codegen/return_.py @@ -19,7 +19,6 @@ # Generate code for return stmt def make_return_stmt(ir_val: IRnode, stmt: Any, context: Context) -> Optional[IRnode]: - sig = context.sig jump_to_exit = ["exit_to", f"_sym_{sig.exit_sequence_label}"] @@ -55,7 +54,6 @@ def finalize(fill_return_buffer): return finalize(fill_return_buffer) else: # return from external function - external_return_type = calculate_type_for_external_return(context.return_type) maxlen = external_return_type.abi_type.size_bound() diff --git a/vyper/compiler/output.py b/vyper/compiler/output.py index 3c2808d0e6..82e583c160 100644 --- a/vyper/compiler/output.py +++ b/vyper/compiler/output.py @@ -177,7 +177,6 @@ def _build_asm(asm_list): output_string = "" in_push = 0 for node in asm_list: - if isinstance(node, list): output_string += "{ " + _build_asm(node) + "} " continue @@ -253,7 +252,7 @@ def build_blueprint_bytecode_output(compiler_data: CompilerData) -> str: # EIP-170. Ref: https://eips.ethereum.org/EIPS/eip-170 -EIP170_CONTRACT_SIZE_LIMIT: int = 2 ** 14 + 2 ** 13 +EIP170_CONTRACT_SIZE_LIMIT: int = 2**14 + 2**13 def build_bytecode_runtime_output(compiler_data: CompilerData) -> str: diff --git a/vyper/compiler/phases.py b/vyper/compiler/phases.py index 5f9d8a7164..5d16517bc8 100644 --- a/vyper/compiler/phases.py +++ b/vyper/compiler/phases.py @@ -192,7 +192,6 @@ def generate_ast(source_code: str, source_id: int, contract_name: str) -> vy_ast def generate_unfolded_ast( vyper_module: vy_ast.Module, interface_codes: Optional[InterfaceImports] ) -> vy_ast.Module: - vy_ast.validation.validate_literal_nodes(vyper_module) vy_ast.folding.replace_builtin_constants(vyper_module) vy_ast.folding.replace_builtin_functions(vyper_module) diff --git a/vyper/ir/compile_ir.py b/vyper/ir/compile_ir.py index bc5e17fa40..c24b3a67a2 100644 --- a/vyper/ir/compile_ir.py +++ b/vyper/ir/compile_ir.py @@ -256,11 +256,11 @@ def _height_of(witharg): # Numbers elif isinstance(code.value, int): - if code.value < -(2 ** 255): + if code.value < -(2**255): raise Exception(f"Value too low: {code.value}") - elif code.value >= 2 ** 256: + elif code.value >= 2**256: raise Exception(f"Value too high: {code.value}") - return PUSH(code.value % 2 ** 256) + return PUSH(code.value % 2**256) # Variables connected to with statements elif isinstance(code.value, str) and code.value in withargs: diff --git a/vyper/ir/optimizer.py b/vyper/ir/optimizer.py index 4382c54eef..f54b0e8115 100644 --- a/vyper/ir/optimizer.py +++ b/vyper/ir/optimizer.py @@ -31,7 +31,7 @@ def _evm_int(node: IRnode, unsigned: bool = True) -> Optional[int]: if unsigned and ret < 0: return signed_to_unsigned(ret, 256, strict=True) - elif not unsigned and ret > 2 ** 255 - 1: + elif not unsigned and ret > 2**255 - 1: return unsigned_to_signed(ret, 256, strict=True) return ret @@ -97,7 +97,7 @@ def _shorten_annotation(annotation): def _wrap256(x, unsigned=UNSIGNED): - x %= 2 ** 256 + x %= 2**256 # wrap in a signed way. if not unsigned: x = unsigned_to_signed(x, 256, strict=True) diff --git a/vyper/semantics/analysis/annotation.py b/vyper/semantics/analysis/annotation.py index 40362bc553..3d2397f30d 100644 --- a/vyper/semantics/analysis/annotation.py +++ b/vyper/semantics/analysis/annotation.py @@ -36,7 +36,6 @@ def visit(self, node, *args): class StatementAnnotationVisitor(_AnnotationVisitorBase): - ignored_types = (vy_ast.Break, vy_ast.Continue, vy_ast.Pass, vy_ast.Raise) def __init__(self, fn_node: vy_ast.FunctionDef, namespace: dict) -> None: @@ -99,7 +98,6 @@ def visit_For(self, node): class ExpressionAnnotationVisitor(_AnnotationVisitorBase): - ignored_types = () def __init__(self, fn_node: ContractFunctionT): diff --git a/vyper/semantics/analysis/common.py b/vyper/semantics/analysis/common.py index eb3bde46e0..193d1892e1 100644 --- a/vyper/semantics/analysis/common.py +++ b/vyper/semantics/analysis/common.py @@ -4,7 +4,6 @@ class VyperNodeVisitorBase: - ignored_types: Tuple = () scope_name = "" diff --git a/vyper/semantics/analysis/data_positions.py b/vyper/semantics/analysis/data_positions.py index 0cfb350638..5c1347d5a3 100644 --- a/vyper/semantics/analysis/data_positions.py +++ b/vyper/semantics/analysis/data_positions.py @@ -53,7 +53,7 @@ def _reserve_slots(self, slots: List[int], var_name: str) -> None: self._reserve_slot(slot, var_name) def _reserve_slot(self, slot: int, var_name: str) -> None: - if slot < 0 or slot >= 2 ** 256: + if slot < 0 or slot >= 2**256: raise StorageLayoutException( f"Invalid storage slot for var {var_name}, out of bounds: {slot}" ) @@ -112,7 +112,6 @@ def set_storage_slots_with_overrides( # Iterate through variables for node in vyper_module.get_children(vy_ast.VariableDecl): - # Ignore immutable parameters if node.get("annotation.func.id") == "immutable": continue @@ -178,7 +177,6 @@ def set_storage_slots(vyper_module: vy_ast.Module) -> StorageLayout: storage_slot += 1 for node in vyper_module.get_children(vy_ast.VariableDecl): - # skip non-storage variables if node.is_constant or node.is_immutable: continue @@ -210,7 +208,6 @@ def set_memory_offsets(fn_node: vy_ast.FunctionDef) -> None: def set_code_offsets(vyper_module: vy_ast.Module) -> Dict: - ret = {} offset = 0 diff --git a/vyper/semantics/analysis/local.py b/vyper/semantics/analysis/local.py index e4e3a1b00d..56eaf33f70 100644 --- a/vyper/semantics/analysis/local.py +++ b/vyper/semantics/analysis/local.py @@ -49,7 +49,6 @@ def validate_functions(vy_module: vy_ast.Module) -> None: - """Analyzes a vyper ast and validates the function-level namespaces.""" err_list = ExceptionList() @@ -160,7 +159,6 @@ def _validate_msg_data_attribute(node: vy_ast.Attribute) -> None: class FunctionNodeVisitor(VyperNodeVisitorBase): - ignored_types = (vy_ast.Constant, vy_ast.Pass) scope_name = "function" diff --git a/vyper/semantics/analysis/module.py b/vyper/semantics/analysis/module.py index b1be5c29b4..a5c6a6e692 100644 --- a/vyper/semantics/analysis/module.py +++ b/vyper/semantics/analysis/module.py @@ -57,7 +57,6 @@ def _find_cyclic_call(fn_names: list, self_members: dict) -> Optional[list]: class ModuleAnalyzer(VyperNodeVisitorBase): - scope_name = "module" def __init__( @@ -124,7 +123,6 @@ def __init__( raise CallViolation(f"Function '{node.name}' calls into itself", self_node) for fn_name in sorted(function_names): - if fn_name not in self_members: # the referenced function does not exist - this is an issue, but we'll report # it later when parsing the function so we can give more meaningful output diff --git a/vyper/semantics/analysis/utils.py b/vyper/semantics/analysis/utils.py index 0329d6f4e4..342de27019 100644 --- a/vyper/semantics/analysis/utils.py +++ b/vyper/semantics/analysis/utils.py @@ -288,7 +288,6 @@ def types_from_Constant(self, node): raise InvalidLiteral(f"Could not determine type for literal value '{node.value}'", node) def types_from_List(self, node): - # literal array if _is_empty_list(node): # empty list literal `[]` @@ -455,7 +454,6 @@ def get_common_types(*nodes: vy_ast.VyperNode, filter_fn: Callable = None) -> Li # TODO push this into `ArrayT.validate_literal()` def _validate_literal_array(node, expected): - # validate that every item within an array has the same type if isinstance(expected, SArrayT): if len(node.elements) != expected.length: diff --git a/vyper/semantics/types/function.py b/vyper/semantics/types/function.py index 6910d1a2e0..568e843291 100644 --- a/vyper/semantics/types/function.py +++ b/vyper/semantics/types/function.py @@ -188,10 +188,8 @@ def from_FunctionDef( ) else: - # FunctionDef with decorators (normal functions) for decorator in node.decorator_list: - if isinstance(decorator, vy_ast.Call): if "nonreentrant" in kwargs: raise StructureException( diff --git a/vyper/semantics/types/primitives.py b/vyper/semantics/types/primitives.py index 72433fcb91..5b1ab5ab8e 100644 --- a/vyper/semantics/types/primitives.py +++ b/vyper/semantics/types/primitives.py @@ -154,11 +154,11 @@ def validate_numeric_op( # TODO double check: this code seems duplicated with constant eval # constant folding ensures one of `(left, right)` is never a literal if isinstance(left, vy_ast.Int): - if left.value >= 2 ** value_bits: + if left.value >= 2**value_bits: raise OverflowException( "Base is too large, calculation will always overflow", left ) - elif left.value < -(2 ** value_bits): + elif left.value < -(2**value_bits): raise OverflowException( "Base is too small, calculation will always underflow", left ) @@ -284,7 +284,7 @@ def decimals(self) -> int: @cached_property def divisor(self) -> int: - return 10 ** self.decimals + return 10**self.decimals @cached_property def epsilon(self) -> Decimal: diff --git a/vyper/semantics/types/subscriptable.py b/vyper/semantics/types/subscriptable.py index d6635d93cb..fb4505fb20 100644 --- a/vyper/semantics/types/subscriptable.py +++ b/vyper/semantics/types/subscriptable.py @@ -100,8 +100,7 @@ class _SequenceT(_SubscriptableT): _is_array_type: bool = True def __init__(self, value_type: VyperType, length: int): - - if not 0 < length < 2 ** 256: + if not 0 < length < 2**256: raise InvalidType("Array length is invalid") super().__init__(UINT256_T, value_type) diff --git a/vyper/semantics/types/user.py b/vyper/semantics/types/user.py index ac0eae2ef7..dda4dfc32f 100644 --- a/vyper/semantics/types/user.py +++ b/vyper/semantics/types/user.py @@ -261,7 +261,6 @@ def to_toplevel_abi_dict(self) -> List[Dict]: class InterfaceT(_UserType): - _type_members = {"address": AddressT()} _is_prim_word = True _as_array = True diff --git a/vyper/utils.py b/vyper/utils.py index 608a014f4e..2df78f1c2d 100644 --- a/vyper/utils.py +++ b/vyper/utils.py @@ -45,7 +45,7 @@ def fourbytes_to_int(inp): # Converts an integer to four bytes def int_to_fourbytes(n: int) -> bytes: - assert n < 2 ** 32 + assert n < 2**32 return n.to_bytes(4, byteorder="big") @@ -60,7 +60,7 @@ def signed_to_unsigned(int_, bits, strict=False): lo, hi = int_bounds(signed=True, bits=bits) assert lo <= int_ <= hi if int_ < 0: - return int_ + 2 ** bits + return int_ + 2**bits return int_ @@ -75,7 +75,7 @@ def unsigned_to_signed(int_, bits, strict=False): lo, hi = int_bounds(signed=False, bits=bits) assert lo <= int_ <= hi if int_ > (2 ** (bits - 1)) - 1: - return int_ - (2 ** bits) + return int_ - (2**bits) return int_ @@ -188,7 +188,7 @@ def calc_mem_gas(memsize): # A decimal value can store multiples of 1/DECIMAL_DIVISOR MAX_DECIMAL_PLACES = 10 -DECIMAL_DIVISOR = 10 ** MAX_DECIMAL_PLACES +DECIMAL_DIVISOR = 10**MAX_DECIMAL_PLACES DECIMAL_EPSILON = decimal.Decimal(1) / DECIMAL_DIVISOR @@ -200,13 +200,13 @@ def int_bounds(signed, bits): """ if signed: return -(2 ** (bits - 1)), (2 ** (bits - 1)) - 1 - return 0, (2 ** bits) - 1 + return 0, (2**bits) - 1 # e.g. -1 -> -(2**256 - 1) def evm_twos_complement(x: int) -> int: # return ((o + 2 ** 255) % 2 ** 256) - 2 ** 255 - return ((2 ** 256 - 1) ^ x) + 1 + return ((2**256 - 1) ^ x) + 1 # EVM div semantics as a python function @@ -231,7 +231,7 @@ def evm_mod(x, y): # (which can generated, for ex. in the unevaluated branch of the Shift builtin) def evm_pow(x, y): assert x >= 0 and y >= 0 - return pow(x, y, 2 ** 256) + return pow(x, y, 2**256) # memory used for system purposes, not for variables @@ -243,18 +243,18 @@ class MemoryPositions: # Sizes of different data types. Used to clamp types. class SizeLimits: - MAX_INT128 = 2 ** 127 - 1 - MIN_INT128 = -(2 ** 127) - MAX_INT256 = 2 ** 255 - 1 - MIN_INT256 = -(2 ** 255) - MAXDECIMAL = 2 ** 167 - 1 # maxdecimal as EVM value - MINDECIMAL = -(2 ** 167) # mindecimal as EVM value + MAX_INT128 = 2**127 - 1 + MIN_INT128 = -(2**127) + MAX_INT256 = 2**255 - 1 + MIN_INT256 = -(2**255) + MAXDECIMAL = 2**167 - 1 # maxdecimal as EVM value + MINDECIMAL = -(2**167) # mindecimal as EVM value # min decimal allowed as Python value - MIN_AST_DECIMAL = -decimal.Decimal(2 ** 167) / DECIMAL_DIVISOR + MIN_AST_DECIMAL = -decimal.Decimal(2**167) / DECIMAL_DIVISOR # max decimal allowed as Python value - MAX_AST_DECIMAL = decimal.Decimal(2 ** 167 - 1) / DECIMAL_DIVISOR - MAX_UINT8 = 2 ** 8 - 1 - MAX_UINT256 = 2 ** 256 - 1 + MAX_AST_DECIMAL = decimal.Decimal(2**167 - 1) / DECIMAL_DIVISOR + MAX_UINT8 = 2**8 - 1 + MAX_UINT256 = 2**256 - 1 # Otherwise reserved words that are whitelisted for function declarations From 853093f7ec50ff3e61b0408982d72f572e8b28c7 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Thu, 30 Mar 2023 05:05:46 +0800 Subject: [PATCH 14/14] fix lint --- vyper/codegen/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vyper/codegen/core.py b/vyper/codegen/core.py index ca161ddb8d..439478a4c4 100644 --- a/vyper/codegen/core.py +++ b/vyper/codegen/core.py @@ -746,9 +746,9 @@ def FAIL(): # pragma: no cover else: if len(left.typ.member_types) != len(right.typ.member_types): FAIL() # pragma: notest - for l, r in zip(left.typ.member_types, right.typ.member_types): + for left_, right_ in zip(left.typ.member_types, right.typ.member_types): # TODO recurse into left, right if literals? - check_assign(dummy_node_for_type(l), dummy_node_for_type(r)) + check_assign(dummy_node_for_type(left_), dummy_node_for_type(right_)) # sanity check an assignment