Skip to content

Commit

Permalink
chore(ruff): changes to tests/byzantium/.
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-tb committed Dec 7, 2024
1 parent 60fec2b commit 9cc1445
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
4 changes: 1 addition & 3 deletions tests/byzantium/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
"""
Test cases for EVM functionality introduced in Byzantium.
"""
"""Test cases for EVM functionality introduced in Byzantium."""
4 changes: 1 addition & 3 deletions tests/byzantium/eip198_modexp_precompile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
"""
Test for precompiles introduced in Byzantium.
"""
"""Test for precompiles introduced in Byzantium."""
43 changes: 18 additions & 25 deletions tests/byzantium/eip198_modexp_precompile/test_modexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Tests the MODEXP precompile, located at address 0x0000..0005. Test cases from the EIP are
labelled with `EIP-198-caseX` in the test id.
"""

from dataclasses import dataclass

import pytest
Expand Down Expand Up @@ -34,6 +35,7 @@ class ModExpInput(TestParameterGroup):
modulus (str): The modulus value for the MODEXP precompile.
extra_data (str): Defines extra padded data to be added at the end of the calldata
to the precompile. Defaults to an empty string.
"""

base: str
Expand All @@ -42,9 +44,7 @@ class ModExpInput(TestParameterGroup):
extra_data: str = ""

def create_modexp_tx_data(self):
"""
Generates input for the MODEXP precompile.
"""
"""Generate input for the MODEXP precompile."""
return (
"0x"
+ f"{int(len(self.base)/2):x}".zfill(64)
Expand All @@ -59,16 +59,12 @@ def create_modexp_tx_data(self):

@dataclass(kw_only=True, frozen=True, repr=False)
class ModExpRawInput(TestParameterGroup):
"""
Helper class to directly define a raw input to the MODEXP precompile.
"""
"""Helper class to directly define a raw input to the MODEXP precompile."""

raw_input: str

def create_modexp_tx_data(self):
"""
The raw input is already the MODEXP precompile input.
"""
"""Raw input is already the MODEXP precompile input."""
return self.raw_input


Expand All @@ -81,6 +77,7 @@ class ExpectedOutput(TestParameterGroup):
call_return_code (str): The return_code from CALL, 0 indicates unsuccessful call
(out-of-gas), 1 indicates call succeeded.
returned_data (str): The output returnData is the expected output of the call
"""

call_return_code: str
Expand All @@ -89,7 +86,7 @@ class ExpectedOutput(TestParameterGroup):

@pytest.mark.valid_from("Byzantium")
@pytest.mark.parametrize(
["input", "output"],
["mod_exp_input", "output"],
[
(
ModExpInput(base="", exponent="", modulus="02"),
Expand Down Expand Up @@ -206,11 +203,9 @@ class ExpectedOutput(TestParameterGroup):
ids=lambda param: param.__repr__(), # only required to remove parameter names (input/output)
)
def test_modexp(
state_test: StateTestFiller, input: ModExpInput, output: ExpectedOutput, pre: Alloc
state_test: StateTestFiller, mod_exp_input: ModExpInput, output: ExpectedOutput, pre: Alloc
):
"""
Test the MODEXP precompile
"""
"""Test the MODEXP precompile."""
env = Environment()
sender = pre.fund_eoa()

Expand All @@ -228,16 +223,14 @@ def test_modexp(
+ Op.MSTORE(
0,
(
(
# Need to `ljust` this PUSH32 in order to ensure the code starts
# in memory at offset 0 (memory right-aligns stack items which are not
# 32 bytes)
Op.PUSH32(
bytes(
Op.CODECOPY(0, 16, Op.SUB(Op.CODESIZE(), 16))
+ Op.RETURN(0, Op.SUB(Op.CODESIZE, 16))
).ljust(32, bytes(1))
)
# Need to `ljust` this PUSH32 in order to ensure the code starts
# in memory at offset 0 (memory right-aligns stack items which are not
# 32 bytes)
Op.PUSH32(
bytes(
Op.CODECOPY(0, 16, Op.SUB(Op.CODESIZE(), 16))
+ Op.RETURN(0, Op.SUB(Op.CODESIZE, 16))
).ljust(32, bytes(1))
)
),
)
Expand All @@ -252,7 +245,7 @@ def test_modexp(
tx = Transaction(
ty=0x0,
to=account,
data=input.create_modexp_tx_data(),
data=mod_exp_input.create_modexp_tx_data(),
gas_limit=500000,
gas_price=10,
protected=True,
Expand Down

0 comments on commit 9cc1445

Please sign in to comment.