From ba73f583965cf097e5c4cb35826fdeb91cd2ed22 Mon Sep 17 00:00:00 2001 From: Leo Arias Date: Mon, 11 Oct 2021 17:51:38 +0000 Subject: [PATCH] Run precommit --- mev_inspect/decode.py | 6 +++-- mev_inspect/schemas/abi.py | 6 +++-- tests/test_decode.py | 54 ++++++++++++++++++++++---------------- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/mev_inspect/decode.py b/mev_inspect/decode.py index 79f97e4..19121a5 100644 --- a/mev_inspect/decode.py +++ b/mev_inspect/decode.py @@ -1,6 +1,7 @@ -import eth_utils.abi from typing import Dict, Optional +import eth_utils.abi + from hexbytes import HexBytes from eth_abi import decode_abi from eth_abi.exceptions import InsufficientDataBytes, NonEmptyPaddingBytes @@ -28,7 +29,8 @@ class ABIDecoder: names = [input.name for input in func.inputs] types = [ - input.type if input.type != 'tuple' + input.type + if input.type != "tuple" else eth_utils.abi.collapse_if_tuple(input.dict()) for input in func.inputs ] diff --git a/mev_inspect/schemas/abi.py b/mev_inspect/schemas/abi.py index 0f38776..9cb16e4 100644 --- a/mev_inspect/schemas/abi.py +++ b/mev_inspect/schemas/abi.py @@ -48,9 +48,11 @@ class ABIFunctionDescription(BaseModel): def get_signature(self) -> str: joined_input_types = ",".join( - input.type if input.type != "tuple" + input.type + if input.type != "tuple" else eth_utils.abi.collapse_if_tuple(input.dict()) - for input in self.inputs) + for input in self.inputs + ) return f"{self.name}({joined_input_types})" diff --git a/tests/test_decode.py b/tests/test_decode.py index e1cc4bf..a83e3bc 100644 --- a/tests/test_decode.py +++ b/tests/test_decode.py @@ -7,14 +7,16 @@ from mev_inspect.schemas import abi def test_decode_function_with_simple_argument(): test_function_name = "testFunction" test_parameter_name = "testParameter" - test_abi = pydantic.parse_obj_as(abi.ABI, [{ - "name": test_function_name, - "type": "function", - "inputs": [{ - "name": test_parameter_name, - "type": "uint256" - }] - }]) + test_abi = pydantic.parse_obj_as( + abi.ABI, + [ + { + "name": test_function_name, + "type": "function", + "inputs": [{"name": test_parameter_name, "type": "uint256"}], + } + ], + ) # 4byte signature of the test function. # https://www.4byte.directory/signatures/?bytes4_signature=0x350c530b test_function_selector = "350c530b" @@ -23,7 +25,8 @@ def test_decode_function_with_simple_argument(): ) abi_decoder = decode.ABIDecoder(test_abi) call_data = abi_decoder.decode( - "0x" + test_function_selector + test_function_argument) + "0x" + test_function_selector + test_function_argument + ) assert call_data.function_name == test_function_name assert call_data.function_signature == "testFunction(uint256)" assert call_data.inputs == {test_parameter_name: 1} @@ -33,18 +36,24 @@ def test_decode_function_with_tuple_argument(): test_function_name = "testFunction" test_tuple_name = "testTuple" test_parameter_name = "testParameter" - test_abi = pydantic.parse_obj_as(abi.ABI, [{ - "name": test_function_name, - "type": "function", - "inputs": [{ - "name": test_tuple_name, - "type": "tuple", - "components": [{ - "name": test_parameter_name, - "type": "uint256" - }] - }] - }]) + test_abi = pydantic.parse_obj_as( + abi.ABI, + [ + { + "name": test_function_name, + "type": "function", + "inputs": [ + { + "name": test_tuple_name, + "type": "tuple", + "components": [ + {"name": test_parameter_name, "type": "uint256"} + ], + } + ], + } + ], + ) # 4byte signature of the test function. # https://www.4byte.directory/signatures/?bytes4_signature=0x98568079 test_function_selector = "98568079" @@ -53,7 +62,8 @@ def test_decode_function_with_tuple_argument(): ) abi_decoder = decode.ABIDecoder(test_abi) call_data = abi_decoder.decode( - "0x" + test_function_selector + test_function_argument) + "0x" + test_function_selector + test_function_argument + ) assert call_data.function_name == test_function_name assert call_data.function_signature == "testFunction((uint256))" assert call_data.inputs == {test_tuple_name: (1,)}