From fc868356597fc7a2caf89fde5963a6560fddc8e1 Mon Sep 17 00:00:00 2001 From: Lawrence Forman Date: Tue, 2 Jun 2020 00:56:57 -0400 Subject: [PATCH] `@0x/abi-gen`: Update python wrappers generation to work with leading underscores in identifiers.' --- packages/abi-gen/CHANGELOG.json | 9 + packages/abi-gen/src/index.ts | 11 +- .../abi-gen/src/python_handlebars_helpers.ts | 13 +- packages/abi-gen/src/utils.ts | 11 +- .../Python/partials/method_class.handlebars | 2 +- .../output/python/abi_gen_dummy/__init__.py | 989 +++++------------- .../output/python/lib_dummy/__init__.py | 15 +- .../output/python/test_lib_dummy/__init__.py | 78 +- 8 files changed, 301 insertions(+), 827 deletions(-) diff --git a/packages/abi-gen/CHANGELOG.json b/packages/abi-gen/CHANGELOG.json index a05ef6f9a3..62cb5095b7 100644 --- a/packages/abi-gen/CHANGELOG.json +++ b/packages/abi-gen/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "5.3.0", + "changes": [ + { + "note": "Allow identifiers with leading underscores in python wrappers", + "pr": 2591 + } + ] + }, { "version": "5.2.2", "changes": [ diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts index be65fa6475..8d89354072 100644 --- a/packages/abi-gen/src/index.ts +++ b/packages/abi-gen/src/index.ts @@ -146,7 +146,16 @@ if (args.language === 'TypeScript') { registerPartials(); function makeLanguageSpecificName(methodName: string): string { - return args.language === 'Python' ? changeCase.snake(methodName) : methodName; + if (args.language === 'Python') { + let snakeCased = changeCase.snake(methodName); + // Move leading underscores to the end. + const m = /^(_*).+?(_*)$/.exec(methodName); + if (m) { + snakeCased = `${snakeCased}${m[1] || m[2]}`; + } + return snakeCased; + } + return methodName; } if (_.isEmpty(abiFileNames)) { diff --git a/packages/abi-gen/src/python_handlebars_helpers.ts b/packages/abi-gen/src/python_handlebars_helpers.ts index f98cd9b62e..b64164bfc1 100644 --- a/packages/abi-gen/src/python_handlebars_helpers.ts +++ b/packages/abi-gen/src/python_handlebars_helpers.ts @@ -153,10 +153,15 @@ export function registerPythonHelpers(): void { } return ''; }); - Handlebars.registerHelper( - 'toPythonClassname', - (sourceName: string) => new Handlebars.SafeString(changeCase.pascal(sourceName)), - ); + Handlebars.registerHelper('toPythonClassname', (sourceName: string) => { + let pascalCased = changeCase.pascal(sourceName); + // Retain trailing underscores. + const m = /^.+?(_*)$/.exec(sourceName); + if (m) { + pascalCased = `${pascalCased}${m[1]}`; + } + return new Handlebars.SafeString(pascalCased); + }); Handlebars.registerHelper( 'makeOutputsValue', /** diff --git a/packages/abi-gen/src/utils.ts b/packages/abi-gen/src/utils.ts index de82de8b90..b5623014c9 100644 --- a/packages/abi-gen/src/utils.ts +++ b/packages/abi-gen/src/utils.ts @@ -331,13 +331,14 @@ export const utils = { 'max', 'round', ]; - if ( - pythonReservedWords.includes(snakeCased) || - pythonBuiltins.includes(snakeCased) || - /*changeCase strips leading underscores :(*/ input[0] === '_' - ) { + if (pythonReservedWords.includes(snakeCased) || pythonBuiltins.includes(snakeCased)) { snakeCased = `_${snakeCased}`; } + // Retain trailing underscores. + const m = /^.+?(_*)$/.exec(input); + if (m) { + snakeCased = `${snakeCased}${m[1]}`; + } return snakeCased; }, /** diff --git a/packages/abi-gen/templates/Python/partials/method_class.handlebars b/packages/abi-gen/templates/Python/partials/method_class.handlebars index 945009edb3..9bdf47c61f 100644 --- a/packages/abi-gen/templates/Python/partials/method_class.handlebars +++ b/packages/abi-gen/templates/Python/partials/method_class.handlebars @@ -1,5 +1,5 @@ -class {{toPythonClassname this.languageSpecificName}}Method(ContractMethod): +class {{toPythonClassname this.languageSpecificName}}Method(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the {{this.name}} method.""" def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction{{#if inputs}}, validator: Validator=None{{/if}}): diff --git a/packages/abi-gen/test-cli/output/python/abi_gen_dummy/__init__.py b/packages/abi-gen/test-cli/output/python/abi_gen_dummy/__init__.py index 866128d746..9d4fb33393 100644 --- a/packages/abi-gen/test-cli/output/python/abi_gen_dummy/__init__.py +++ b/packages/abi-gen/test-cli/output/python/abi_gen_dummy/__init__.py @@ -178,16 +178,10 @@ class AbiGenDummyNestedStruct(TypedDict): description: str -class AcceptsAnArrayOfBytesMethod(ContractMethod): +class AcceptsAnArrayOfBytesMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the acceptsAnArrayOfBytes method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function @@ -195,15 +189,13 @@ def __init__( def validate_and_normalize_inputs(self, a: List[Union[bytes, str]]): """Validate the inputs to the acceptsAnArrayOfBytes method.""" self.validator.assert_valid( - method_name="acceptsAnArrayOfBytes", - parameter_name="a", + method_name='acceptsAnArrayOfBytes', + parameter_name='a', argument_value=a, ) - return a + return (a) - def call( - self, a: List[Union[bytes, str]], tx_params: Optional[TxParams] = None - ) -> None: + def call(self, a: List[Union[bytes, str]], tx_params: Optional[TxParams] = None) -> None: """Execute underlying contract method via eth_call. a method that accepts an array of bytes @@ -216,25 +208,16 @@ def call( tx_params = super().normalize_tx_params(tx_params) self._underlying_method(a).call(tx_params.as_dict()) - def estimate_gas( - self, a: List[Union[bytes, str]], tx_params: Optional[TxParams] = None - ) -> int: + def estimate_gas(self, a: List[Union[bytes, str]], tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (a) = self.validate_and_normalize_inputs(a) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(a).estimateGas(tx_params.as_dict()) - -class AcceptsBytesMethod(ContractMethod): +class AcceptsBytesMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the acceptsBytes method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function @@ -242,13 +225,13 @@ def __init__( def validate_and_normalize_inputs(self, a: Union[bytes, str]): """Validate the inputs to the acceptsBytes method.""" self.validator.assert_valid( - method_name="acceptsBytes", parameter_name="a", argument_value=a, + method_name='acceptsBytes', + parameter_name='a', + argument_value=a, ) - return a + return (a) - def call( - self, a: Union[bytes, str], tx_params: Optional[TxParams] = None - ) -> None: + def call(self, a: Union[bytes, str], tx_params: Optional[TxParams] = None) -> None: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters @@ -258,45 +241,30 @@ def call( tx_params = super().normalize_tx_params(tx_params) self._underlying_method(a).call(tx_params.as_dict()) - def estimate_gas( - self, a: Union[bytes, str], tx_params: Optional[TxParams] = None - ) -> int: + def estimate_gas(self, a: Union[bytes, str], tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (a) = self.validate_and_normalize_inputs(a) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(a).estimateGas(tx_params.as_dict()) - -class ComplexInputComplexOutputMethod(ContractMethod): +class ComplexInputComplexOutputMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the complexInputComplexOutput method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function - def validate_and_normalize_inputs( - self, complex_input: AbiGenDummyComplexInput - ): + def validate_and_normalize_inputs(self, complex_input: AbiGenDummyComplexInput): """Validate the inputs to the complexInputComplexOutput method.""" self.validator.assert_valid( - method_name="complexInputComplexOutput", - parameter_name="complexInput", + method_name='complexInputComplexOutput', + parameter_name='complexInput', argument_value=complex_input, ) - return complex_input + return (complex_input) - def call( - self, - complex_input: AbiGenDummyComplexInput, - tx_params: Optional[TxParams] = None, - ) -> AbiGenDummyComplexOutput: + def call(self, complex_input: AbiGenDummyComplexInput, tx_params: Optional[TxParams] = None) -> AbiGenDummyComplexOutput: """Execute underlying contract method via eth_call. Tests decoding when the input and output are complex. @@ -306,75 +274,48 @@ def call( """ (complex_input) = self.validate_and_normalize_inputs(complex_input) tx_params = super().normalize_tx_params(tx_params) - returned = self._underlying_method(complex_input).call( - tx_params.as_dict() - ) - return AbiGenDummyComplexOutput( - input=returned[0], - lorem=returned[1], - ipsum=returned[2], - dolor=returned[3], - ) + returned = self._underlying_method(complex_input).call(tx_params.as_dict()) + return AbiGenDummyComplexOutput(input=returned[0],lorem=returned[1],ipsum=returned[2],dolor=returned[3],) - def estimate_gas( - self, - complex_input: AbiGenDummyComplexInput, - tx_params: Optional[TxParams] = None, - ) -> int: + def estimate_gas(self, complex_input: AbiGenDummyComplexInput, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (complex_input) = self.validate_and_normalize_inputs(complex_input) tx_params = super().normalize_tx_params(tx_params) - return self._underlying_method(complex_input).estimateGas( - tx_params.as_dict() - ) - + return self._underlying_method(complex_input).estimateGas(tx_params.as_dict()) -class EcrecoverFnMethod(ContractMethod): +class EcrecoverFnMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the ecrecoverFn method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function - def validate_and_normalize_inputs( - self, - _hash: Union[bytes, str], - v: int, - r: Union[bytes, str], - s: Union[bytes, str], - ): + def validate_and_normalize_inputs(self, _hash: Union[bytes, str], v: int, r: Union[bytes, str], s: Union[bytes, str]): """Validate the inputs to the ecrecoverFn method.""" self.validator.assert_valid( - method_name="ecrecoverFn", - parameter_name="hash", + method_name='ecrecoverFn', + parameter_name='hash', argument_value=_hash, ) self.validator.assert_valid( - method_name="ecrecoverFn", parameter_name="v", argument_value=v, + method_name='ecrecoverFn', + parameter_name='v', + argument_value=v, ) self.validator.assert_valid( - method_name="ecrecoverFn", parameter_name="r", argument_value=r, + method_name='ecrecoverFn', + parameter_name='r', + argument_value=r, ) self.validator.assert_valid( - method_name="ecrecoverFn", parameter_name="s", argument_value=s, + method_name='ecrecoverFn', + parameter_name='s', + argument_value=s, ) return (_hash, v, r, s) - def call( - self, - _hash: Union[bytes, str], - v: int, - r: Union[bytes, str], - s: Union[bytes, str], - tx_params: Optional[TxParams] = None, - ) -> str: + def call(self, _hash: Union[bytes, str], v: int, r: Union[bytes, str], s: Union[bytes, str], tx_params: Optional[TxParams] = None) -> str: """Execute underlying contract method via eth_call. test that devdocs will be generated and that multiline devdocs will @@ -393,36 +334,19 @@ def call( """ (_hash, v, r, s) = self.validate_and_normalize_inputs(_hash, v, r, s) tx_params = super().normalize_tx_params(tx_params) - returned = self._underlying_method(_hash, v, r, s).call( - tx_params.as_dict() - ) + returned = self._underlying_method(_hash, v, r, s).call(tx_params.as_dict()) return str(returned) - def estimate_gas( - self, - _hash: Union[bytes, str], - v: int, - r: Union[bytes, str], - s: Union[bytes, str], - tx_params: Optional[TxParams] = None, - ) -> int: + def estimate_gas(self, _hash: Union[bytes, str], v: int, r: Union[bytes, str], s: Union[bytes, str], tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (_hash, v, r, s) = self.validate_and_normalize_inputs(_hash, v, r, s) tx_params = super().normalize_tx_params(tx_params) - return self._underlying_method(_hash, v, r, s).estimateGas( - tx_params.as_dict() - ) - + return self._underlying_method(_hash, v, r, s).estimateGas(tx_params.as_dict()) -class EmitSimpleEventMethod(ContractMethod): +class EmitSimpleEventMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the emitSimpleEvent method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function @@ -436,9 +360,7 @@ def call(self, tx_params: Optional[TxParams] = None) -> None: tx_params = super().normalize_tx_params(tx_params) self._underlying_method().call(tx_params.as_dict()) - def send_transaction( - self, tx_params: Optional[TxParams] = None - ) -> Union[HexBytes, bytes]: + def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters @@ -456,37 +378,24 @@ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class MethodAcceptingArrayOfArrayOfStructsMethod(ContractMethod): +class MethodAcceptingArrayOfArrayOfStructsMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the methodAcceptingArrayOfArrayOfStructs method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function - def validate_and_normalize_inputs( - self, index_0: List[List[AbiGenDummyStruct]] - ): + def validate_and_normalize_inputs(self, index_0: List[List[AbiGenDummyStruct]]): """Validate the inputs to the methodAcceptingArrayOfArrayOfStructs method.""" self.validator.assert_valid( - method_name="methodAcceptingArrayOfArrayOfStructs", - parameter_name="index_0", + method_name='methodAcceptingArrayOfArrayOfStructs', + parameter_name='index_0', argument_value=index_0, ) - return index_0 + return (index_0) - def call( - self, - index_0: List[List[AbiGenDummyStruct]], - tx_params: Optional[TxParams] = None, - ) -> None: + def call(self, index_0: List[List[AbiGenDummyStruct]], tx_params: Optional[TxParams] = None) -> None: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters @@ -496,29 +405,16 @@ def call( tx_params = super().normalize_tx_params(tx_params) self._underlying_method(index_0).call(tx_params.as_dict()) - def estimate_gas( - self, - index_0: List[List[AbiGenDummyStruct]], - tx_params: Optional[TxParams] = None, - ) -> int: + def estimate_gas(self, index_0: List[List[AbiGenDummyStruct]], tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (index_0) = self.validate_and_normalize_inputs(index_0) tx_params = super().normalize_tx_params(tx_params) - return self._underlying_method(index_0).estimateGas( - tx_params.as_dict() - ) + return self._underlying_method(index_0).estimateGas(tx_params.as_dict()) - -class MethodAcceptingArrayOfStructsMethod(ContractMethod): +class MethodAcceptingArrayOfStructsMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the methodAcceptingArrayOfStructs method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function @@ -526,17 +422,13 @@ def __init__( def validate_and_normalize_inputs(self, index_0: List[AbiGenDummyStruct]): """Validate the inputs to the methodAcceptingArrayOfStructs method.""" self.validator.assert_valid( - method_name="methodAcceptingArrayOfStructs", - parameter_name="index_0", + method_name='methodAcceptingArrayOfStructs', + parameter_name='index_0', argument_value=index_0, ) - return index_0 + return (index_0) - def call( - self, - index_0: List[AbiGenDummyStruct], - tx_params: Optional[TxParams] = None, - ) -> None: + def call(self, index_0: List[AbiGenDummyStruct], tx_params: Optional[TxParams] = None) -> None: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters @@ -546,35 +438,21 @@ def call( tx_params = super().normalize_tx_params(tx_params) self._underlying_method(index_0).call(tx_params.as_dict()) - def estimate_gas( - self, - index_0: List[AbiGenDummyStruct], - tx_params: Optional[TxParams] = None, - ) -> int: + def estimate_gas(self, index_0: List[AbiGenDummyStruct], tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (index_0) = self.validate_and_normalize_inputs(index_0) tx_params = super().normalize_tx_params(tx_params) - return self._underlying_method(index_0).estimateGas( - tx_params.as_dict() - ) + return self._underlying_method(index_0).estimateGas(tx_params.as_dict()) - -class MethodReturningArrayOfStructsMethod(ContractMethod): +class MethodReturningArrayOfStructsMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the methodReturningArrayOfStructs method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function - def call( - self, tx_params: Optional[TxParams] = None - ) -> List[AbiGenDummyStruct]: + def call(self, tx_params: Optional[TxParams] = None) -> List[AbiGenDummyStruct]: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters @@ -582,31 +460,17 @@ def call( """ tx_params = super().normalize_tx_params(tx_params) returned = self._underlying_method().call(tx_params.as_dict()) - return [ - AbiGenDummyStruct( - someBytes=element[0], - anInteger=element[1], - aDynamicArrayOfBytes=element[2], - aString=element[3], - ) - for element in returned - ] + return [AbiGenDummyStruct(someBytes=element[0],anInteger=element[1],aDynamicArrayOfBytes=element[2],aString=element[3],) for element in returned] def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class MethodReturningMultipleValuesMethod(ContractMethod): +class MethodReturningMultipleValuesMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the methodReturningMultipleValues method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function @@ -619,35 +483,22 @@ def call(self, tx_params: Optional[TxParams] = None) -> Tuple[int, str]: """ tx_params = super().normalize_tx_params(tx_params) returned = self._underlying_method().call(tx_params.as_dict()) - return ( - returned[0], - returned[1], - ) + return (returned[0],returned[1],) def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class MethodUsingNestedStructWithInnerStructNotUsedElsewhereMethod( - ContractMethod -): +class MethodUsingNestedStructWithInnerStructNotUsedElsewhereMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the methodUsingNestedStructWithInnerStructNotUsedElsewhere method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function - def call( - self, tx_params: Optional[TxParams] = None - ) -> AbiGenDummyNestedStructWithInnerStructNotUsedElsewhere: + def call(self, tx_params: Optional[TxParams] = None) -> AbiGenDummyNestedStructWithInnerStructNotUsedElsewhere: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters @@ -655,60 +506,43 @@ def call( """ tx_params = super().normalize_tx_params(tx_params) returned = self._underlying_method().call(tx_params.as_dict()) - return AbiGenDummyNestedStructWithInnerStructNotUsedElsewhere( - innerStruct=returned[0], - ) + return AbiGenDummyNestedStructWithInnerStructNotUsedElsewhere(innerStruct=returned[0],) def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class MultiInputMultiOutputMethod(ContractMethod): +class MultiInputMultiOutputMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the multiInputMultiOutput method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function - def validate_and_normalize_inputs( - self, index_0: int, index_1: Union[bytes, str], index_2: str - ): + def validate_and_normalize_inputs(self, index_0: int, index_1: Union[bytes, str], index_2: str): """Validate the inputs to the multiInputMultiOutput method.""" self.validator.assert_valid( - method_name="multiInputMultiOutput", - parameter_name="index_0", + method_name='multiInputMultiOutput', + parameter_name='index_0', argument_value=index_0, ) # safeguard against fractional inputs index_0 = int(index_0) self.validator.assert_valid( - method_name="multiInputMultiOutput", - parameter_name="index_1", + method_name='multiInputMultiOutput', + parameter_name='index_1', argument_value=index_1, ) self.validator.assert_valid( - method_name="multiInputMultiOutput", - parameter_name="index_2", + method_name='multiInputMultiOutput', + parameter_name='index_2', argument_value=index_2, ) return (index_0, index_1, index_2) - def call( - self, - index_0: int, - index_1: Union[bytes, str], - index_2: str, - tx_params: Optional[TxParams] = None, - ) -> Tuple[Union[bytes, str], Union[bytes, str], str]: + def call(self, index_0: int, index_1: Union[bytes, str], index_2: str, tx_params: Optional[TxParams] = None) -> Tuple[Union[bytes, str], Union[bytes, str], str]: """Execute underlying contract method via eth_call. Tests decoding when the input and output are complex and have more than @@ -717,46 +551,21 @@ def call( :param tx_params: transaction parameters """ - (index_0, index_1, index_2) = self.validate_and_normalize_inputs( - index_0, index_1, index_2 - ) + (index_0, index_1, index_2) = self.validate_and_normalize_inputs(index_0, index_1, index_2) tx_params = super().normalize_tx_params(tx_params) - returned = self._underlying_method(index_0, index_1, index_2).call( - tx_params.as_dict() - ) - return ( - returned[0], - returned[1], - returned[2], - ) + returned = self._underlying_method(index_0, index_1, index_2).call(tx_params.as_dict()) + return (returned[0],returned[1],returned[2],) - def estimate_gas( - self, - index_0: int, - index_1: Union[bytes, str], - index_2: str, - tx_params: Optional[TxParams] = None, - ) -> int: + def estimate_gas(self, index_0: int, index_1: Union[bytes, str], index_2: str, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" - (index_0, index_1, index_2) = self.validate_and_normalize_inputs( - index_0, index_1, index_2 - ) + (index_0, index_1, index_2) = self.validate_and_normalize_inputs(index_0, index_1, index_2) tx_params = super().normalize_tx_params(tx_params) - return self._underlying_method(index_0, index_1, index_2).estimateGas( - tx_params.as_dict() - ) - + return self._underlying_method(index_0, index_1, index_2).estimateGas(tx_params.as_dict()) -class NestedStructInputMethod(ContractMethod): +class NestedStructInputMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the nestedStructInput method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function @@ -764,15 +573,13 @@ def __init__( def validate_and_normalize_inputs(self, n: AbiGenDummyNestedStruct): """Validate the inputs to the nestedStructInput method.""" self.validator.assert_valid( - method_name="nestedStructInput", - parameter_name="n", + method_name='nestedStructInput', + parameter_name='n', argument_value=n, ) - return n + return (n) - def call( - self, n: AbiGenDummyNestedStruct, tx_params: Optional[TxParams] = None - ) -> None: + def call(self, n: AbiGenDummyNestedStruct, tx_params: Optional[TxParams] = None) -> None: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters @@ -782,31 +589,21 @@ def call( tx_params = super().normalize_tx_params(tx_params) self._underlying_method(n).call(tx_params.as_dict()) - def estimate_gas( - self, n: AbiGenDummyNestedStruct, tx_params: Optional[TxParams] = None - ) -> int: + def estimate_gas(self, n: AbiGenDummyNestedStruct, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (n) = self.validate_and_normalize_inputs(n) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(n).estimateGas(tx_params.as_dict()) - -class NestedStructOutputMethod(ContractMethod): +class NestedStructOutputMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the nestedStructOutput method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function - def call( - self, tx_params: Optional[TxParams] = None - ) -> AbiGenDummyNestedStruct: + def call(self, tx_params: Optional[TxParams] = None) -> AbiGenDummyNestedStruct: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters @@ -814,25 +611,17 @@ def call( """ tx_params = super().normalize_tx_params(tx_params) returned = self._underlying_method().call(tx_params.as_dict()) - return AbiGenDummyNestedStruct( - innerStruct=returned[0], description=returned[1], - ) + return AbiGenDummyNestedStruct(innerStruct=returned[0],description=returned[1],) def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class NoInputNoOutputMethod(ContractMethod): +class NoInputNoOutputMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the noInputNoOutput method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function @@ -853,16 +642,10 @@ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class NoInputSimpleOutputMethod(ContractMethod): +class NoInputSimpleOutputMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the noInputSimpleOutput method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function @@ -884,16 +667,10 @@ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class NonPureMethodMethod(ContractMethod): +class NonPureMethodMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the nonPureMethod method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function @@ -908,9 +685,7 @@ def call(self, tx_params: Optional[TxParams] = None) -> int: returned = self._underlying_method().call(tx_params.as_dict()) return int(returned) - def send_transaction( - self, tx_params: Optional[TxParams] = None - ) -> Union[HexBytes, bytes]: + def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters @@ -928,16 +703,10 @@ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class NonPureMethodThatReturnsNothingMethod(ContractMethod): +class NonPureMethodThatReturnsNothingMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the nonPureMethodThatReturnsNothing method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function @@ -951,9 +720,7 @@ def call(self, tx_params: Optional[TxParams] = None) -> None: tx_params = super().normalize_tx_params(tx_params) self._underlying_method().call(tx_params.as_dict()) - def send_transaction( - self, tx_params: Optional[TxParams] = None - ) -> Union[HexBytes, bytes]: + def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters @@ -971,17 +738,10 @@ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class OverloadedMethod2Method(ContractMethod): +class OverloadedMethod2Method(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the overloadedMethod method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function @@ -989,11 +749,11 @@ def __init__( def validate_and_normalize_inputs(self, a: str): """Validate the inputs to the overloadedMethod method.""" self.validator.assert_valid( - method_name="overloadedMethod", - parameter_name="a", + method_name='overloadedMethod', + parameter_name='a', argument_value=a, ) - return a + return (a) def call(self, a: str, tx_params: Optional[TxParams] = None) -> None: """Execute underlying contract method via eth_call. @@ -1005,25 +765,16 @@ def call(self, a: str, tx_params: Optional[TxParams] = None) -> None: tx_params = super().normalize_tx_params(tx_params) self._underlying_method(a).call(tx_params.as_dict()) - def estimate_gas( - self, a: str, tx_params: Optional[TxParams] = None - ) -> int: + def estimate_gas(self, a: str, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (a) = self.validate_and_normalize_inputs(a) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(a).estimateGas(tx_params.as_dict()) - -class OverloadedMethod1Method(ContractMethod): +class OverloadedMethod1Method(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the overloadedMethod method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function @@ -1031,11 +782,11 @@ def __init__( def validate_and_normalize_inputs(self, a: int): """Validate the inputs to the overloadedMethod method.""" self.validator.assert_valid( - method_name="overloadedMethod", - parameter_name="a", + method_name='overloadedMethod', + parameter_name='a', argument_value=a, ) - return a + return (a) def call(self, a: int, tx_params: Optional[TxParams] = None) -> None: """Execute underlying contract method via eth_call. @@ -1047,24 +798,16 @@ def call(self, a: int, tx_params: Optional[TxParams] = None) -> None: tx_params = super().normalize_tx_params(tx_params) self._underlying_method(a).call(tx_params.as_dict()) - def estimate_gas( - self, a: int, tx_params: Optional[TxParams] = None - ) -> int: + def estimate_gas(self, a: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (a) = self.validate_and_normalize_inputs(a) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(a).estimateGas(tx_params.as_dict()) - -class PureFunctionWithConstantMethod(ContractMethod): +class PureFunctionWithConstantMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the pureFunctionWithConstant method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function @@ -1084,16 +827,10 @@ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class RequireWithConstantMethod(ContractMethod): +class RequireWithConstantMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the requireWithConstant method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function @@ -1112,16 +849,10 @@ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class RevertWithConstantMethod(ContractMethod): +class RevertWithConstantMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the revertWithConstant method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function @@ -1140,17 +871,10 @@ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class SimpleInputNoOutputMethod(ContractMethod): +class SimpleInputNoOutputMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the simpleInputNoOutput method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function @@ -1158,13 +882,13 @@ def __init__( def validate_and_normalize_inputs(self, index_0: int): """Validate the inputs to the simpleInputNoOutput method.""" self.validator.assert_valid( - method_name="simpleInputNoOutput", - parameter_name="index_0", + method_name='simpleInputNoOutput', + parameter_name='index_0', argument_value=index_0, ) # safeguard against fractional inputs index_0 = int(index_0) - return index_0 + return (index_0) def call(self, index_0: int, tx_params: Optional[TxParams] = None) -> None: """Execute underlying contract method via eth_call. @@ -1178,27 +902,16 @@ def call(self, index_0: int, tx_params: Optional[TxParams] = None) -> None: tx_params = super().normalize_tx_params(tx_params) self._underlying_method(index_0).call(tx_params.as_dict()) - def estimate_gas( - self, index_0: int, tx_params: Optional[TxParams] = None - ) -> int: + def estimate_gas(self, index_0: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (index_0) = self.validate_and_normalize_inputs(index_0) tx_params = super().normalize_tx_params(tx_params) - return self._underlying_method(index_0).estimateGas( - tx_params.as_dict() - ) + return self._underlying_method(index_0).estimateGas(tx_params.as_dict()) - -class SimpleInputSimpleOutputMethod(ContractMethod): +class SimpleInputSimpleOutputMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the simpleInputSimpleOutput method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function @@ -1206,13 +919,13 @@ def __init__( def validate_and_normalize_inputs(self, index_0: int): """Validate the inputs to the simpleInputSimpleOutput method.""" self.validator.assert_valid( - method_name="simpleInputSimpleOutput", - parameter_name="index_0", + method_name='simpleInputSimpleOutput', + parameter_name='index_0', argument_value=index_0, ) # safeguard against fractional inputs index_0 = int(index_0) - return index_0 + return (index_0) def call(self, index_0: int, tx_params: Optional[TxParams] = None) -> int: """Execute underlying contract method via eth_call. @@ -1227,26 +940,16 @@ def call(self, index_0: int, tx_params: Optional[TxParams] = None) -> int: returned = self._underlying_method(index_0).call(tx_params.as_dict()) return int(returned) - def estimate_gas( - self, index_0: int, tx_params: Optional[TxParams] = None - ) -> int: + def estimate_gas(self, index_0: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (index_0) = self.validate_and_normalize_inputs(index_0) tx_params = super().normalize_tx_params(tx_params) - return self._underlying_method(index_0).estimateGas( - tx_params.as_dict() - ) + return self._underlying_method(index_0).estimateGas(tx_params.as_dict()) - -class SimplePureFunctionMethod(ContractMethod): +class SimplePureFunctionMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the simplePureFunction method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function @@ -1266,17 +969,10 @@ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class SimplePureFunctionWithInputMethod(ContractMethod): +class SimplePureFunctionWithInputMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the simplePureFunctionWithInput method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function @@ -1284,13 +980,13 @@ def __init__( def validate_and_normalize_inputs(self, x: int): """Validate the inputs to the simplePureFunctionWithInput method.""" self.validator.assert_valid( - method_name="simplePureFunctionWithInput", - parameter_name="x", + method_name='simplePureFunctionWithInput', + parameter_name='x', argument_value=x, ) # safeguard against fractional inputs x = int(x) - return x + return (x) def call(self, x: int, tx_params: Optional[TxParams] = None) -> int: """Execute underlying contract method via eth_call. @@ -1303,24 +999,16 @@ def call(self, x: int, tx_params: Optional[TxParams] = None) -> int: returned = self._underlying_method(x).call(tx_params.as_dict()) return int(returned) - def estimate_gas( - self, x: int, tx_params: Optional[TxParams] = None - ) -> int: + def estimate_gas(self, x: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (x) = self.validate_and_normalize_inputs(x) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(x).estimateGas(tx_params.as_dict()) - -class SimpleRequireMethod(ContractMethod): +class SimpleRequireMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the simpleRequire method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function @@ -1339,16 +1027,10 @@ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class SimpleRevertMethod(ContractMethod): +class SimpleRevertMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the simpleRevert method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function @@ -1367,17 +1049,10 @@ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class StructInputMethod(ContractMethod): +class StructInputMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the structInput method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function @@ -1385,13 +1060,13 @@ def __init__( def validate_and_normalize_inputs(self, s: AbiGenDummyStruct): """Validate the inputs to the structInput method.""" self.validator.assert_valid( - method_name="structInput", parameter_name="s", argument_value=s, + method_name='structInput', + parameter_name='s', + argument_value=s, ) - return s + return (s) - def call( - self, s: AbiGenDummyStruct, tx_params: Optional[TxParams] = None - ) -> None: + def call(self, s: AbiGenDummyStruct, tx_params: Optional[TxParams] = None) -> None: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters @@ -1401,24 +1076,16 @@ def call( tx_params = super().normalize_tx_params(tx_params) self._underlying_method(s).call(tx_params.as_dict()) - def estimate_gas( - self, s: AbiGenDummyStruct, tx_params: Optional[TxParams] = None - ) -> int: + def estimate_gas(self, s: AbiGenDummyStruct, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (s) = self.validate_and_normalize_inputs(s) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(s).estimateGas(tx_params.as_dict()) - -class StructOutputMethod(ContractMethod): +class StructOutputMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the structOutput method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(web3_or_provider, contract_address) self._underlying_method = contract_function @@ -1433,81 +1100,59 @@ def call(self, tx_params: Optional[TxParams] = None) -> AbiGenDummyStruct: """ tx_params = super().normalize_tx_params(tx_params) returned = self._underlying_method().call(tx_params.as_dict()) - return AbiGenDummyStruct( - someBytes=returned[0], - anInteger=returned[1], - aDynamicArrayOfBytes=returned[2], - aString=returned[3], - ) + return AbiGenDummyStruct(someBytes=returned[0],anInteger=returned[1],aDynamicArrayOfBytes=returned[2],aString=returned[3],) def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict()) - -class WithAddressInputMethod(ContractMethod): +class WithAddressInputMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the withAddressInput method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function - def validate_and_normalize_inputs( - self, x: str, a: int, b: int, y: str, c: int - ): + def validate_and_normalize_inputs(self, x: str, a: int, b: int, y: str, c: int): """Validate the inputs to the withAddressInput method.""" self.validator.assert_valid( - method_name="withAddressInput", - parameter_name="x", + method_name='withAddressInput', + parameter_name='x', argument_value=x, ) x = self.validate_and_checksum_address(x) self.validator.assert_valid( - method_name="withAddressInput", - parameter_name="a", + method_name='withAddressInput', + parameter_name='a', argument_value=a, ) # safeguard against fractional inputs a = int(a) self.validator.assert_valid( - method_name="withAddressInput", - parameter_name="b", + method_name='withAddressInput', + parameter_name='b', argument_value=b, ) # safeguard against fractional inputs b = int(b) self.validator.assert_valid( - method_name="withAddressInput", - parameter_name="y", + method_name='withAddressInput', + parameter_name='y', argument_value=y, ) y = self.validate_and_checksum_address(y) self.validator.assert_valid( - method_name="withAddressInput", - parameter_name="c", + method_name='withAddressInput', + parameter_name='c', argument_value=c, ) # safeguard against fractional inputs c = int(c) return (x, a, b, y, c) - def call( - self, - x: str, - a: int, - b: int, - y: str, - c: int, - tx_params: Optional[TxParams] = None, - ) -> str: + def call(self, x: str, a: int, b: int, y: str, c: int, tx_params: Optional[TxParams] = None) -> str: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters @@ -1515,38 +1160,19 @@ def call( """ (x, a, b, y, c) = self.validate_and_normalize_inputs(x, a, b, y, c) tx_params = super().normalize_tx_params(tx_params) - returned = self._underlying_method(x, a, b, y, c).call( - tx_params.as_dict() - ) + returned = self._underlying_method(x, a, b, y, c).call(tx_params.as_dict()) return str(returned) - def estimate_gas( - self, - x: str, - a: int, - b: int, - y: str, - c: int, - tx_params: Optional[TxParams] = None, - ) -> int: + def estimate_gas(self, x: str, a: int, b: int, y: str, c: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (x, a, b, y, c) = self.validate_and_normalize_inputs(x, a, b, y, c) tx_params = super().normalize_tx_params(tx_params) - return self._underlying_method(x, a, b, y, c).estimateGas( - tx_params.as_dict() - ) - + return self._underlying_method(x, a, b, y, c).estimateGas(tx_params.as_dict()) -class WithdrawMethod(ContractMethod): +class WithdrawMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the withdraw method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function @@ -1554,11 +1180,13 @@ def __init__( def validate_and_normalize_inputs(self, wad: int): """Validate the inputs to the withdraw method.""" self.validator.assert_valid( - method_name="withdraw", parameter_name="wad", argument_value=wad, + method_name='withdraw', + parameter_name='wad', + argument_value=wad, ) # safeguard against fractional inputs wad = int(wad) - return wad + return (wad) def call(self, wad: int, tx_params: Optional[TxParams] = None) -> None: """Execute underlying contract method via eth_call. @@ -1570,9 +1198,7 @@ def call(self, wad: int, tx_params: Optional[TxParams] = None) -> None: tx_params = super().normalize_tx_params(tx_params) self._underlying_method(wad).call(tx_params.as_dict()) - def send_transaction( - self, wad: int, tx_params: Optional[TxParams] = None - ) -> Union[HexBytes, bytes]: + def send_transaction(self, wad: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters @@ -1581,25 +1207,18 @@ def send_transaction( tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(wad).transact(tx_params.as_dict()) - def build_transaction( - self, wad: int, tx_params: Optional[TxParams] = None - ) -> dict: + def build_transaction(self, wad: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (wad) = self.validate_and_normalize_inputs(wad) tx_params = super().normalize_tx_params(tx_params) - return self._underlying_method(wad).buildTransaction( - tx_params.as_dict() - ) + return self._underlying_method(wad).buildTransaction(tx_params.as_dict()) - def estimate_gas( - self, wad: int, tx_params: Optional[TxParams] = None - ) -> int: + def estimate_gas(self, wad: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (wad) = self.validate_and_normalize_inputs(wad) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(wad).estimateGas(tx_params.as_dict()) - # pylint: disable=too-many-public-methods,too-many-instance-attributes class AbiGenDummy: """Wrapper class for AbiGenDummy Solidity contract. @@ -1607,7 +1226,6 @@ class AbiGenDummy: All method parameters of type `bytes`:code: should be encoded as UTF-8, which can be accomplished via `str.encode("utf_8")`:code:. """ - accepts_an_array_of_bytes: AcceptsAnArrayOfBytesMethod """Constructor-initialized instance of :class:`AcceptsAnArrayOfBytesMethod`. @@ -1768,6 +1386,7 @@ class AbiGenDummy: :class:`WithdrawMethod`. """ + def __init__( self, web3_or_provider: Union[Web3, BaseProvider], @@ -1786,9 +1405,7 @@ def __init__( self.contract_address = contract_address if not validator: - validator = AbiGenDummyValidator( - web3_or_provider, contract_address - ) + validator = AbiGenDummyValidator(web3_or_provider, contract_address) web3 = None if isinstance(web3_or_provider, BaseProvider): @@ -1810,203 +1427,79 @@ def __init__( try: for middleware in MIDDLEWARE: web3.middleware_onion.inject( - middleware["function"], layer=middleware["layer"], + middleware['function'], layer=middleware['layer'], ) except ValueError as value_error: - if value_error.args == ( - "You can't add the same un-named instance twice", - ): + if value_error.args == ("You can't add the same un-named instance twice",): pass self._web3_eth = web3.eth - functions = self._web3_eth.contract( - address=to_checksum_address(contract_address), - abi=AbiGenDummy.abi(), - ).functions + functions = self._web3_eth.contract(address=to_checksum_address(contract_address), abi=AbiGenDummy.abi()).functions - self.accepts_an_array_of_bytes = AcceptsAnArrayOfBytesMethod( - web3_or_provider, - contract_address, - functions.acceptsAnArrayOfBytes, - validator, - ) + self.accepts_an_array_of_bytes = AcceptsAnArrayOfBytesMethod(web3_or_provider, contract_address, functions.acceptsAnArrayOfBytes, validator) - self.accepts_bytes = AcceptsBytesMethod( - web3_or_provider, - contract_address, - functions.acceptsBytes, - validator, - ) + self.accepts_bytes = AcceptsBytesMethod(web3_or_provider, contract_address, functions.acceptsBytes, validator) - self.complex_input_complex_output = ComplexInputComplexOutputMethod( - web3_or_provider, - contract_address, - functions.complexInputComplexOutput, - validator, - ) + self.complex_input_complex_output = ComplexInputComplexOutputMethod(web3_or_provider, contract_address, functions.complexInputComplexOutput, validator) - self.ecrecover_fn = EcrecoverFnMethod( - web3_or_provider, - contract_address, - functions.ecrecoverFn, - validator, - ) + self.ecrecover_fn = EcrecoverFnMethod(web3_or_provider, contract_address, functions.ecrecoverFn, validator) - self.emit_simple_event = EmitSimpleEventMethod( - web3_or_provider, contract_address, functions.emitSimpleEvent - ) + self.emit_simple_event = EmitSimpleEventMethod(web3_or_provider, contract_address, functions.emitSimpleEvent) - self.method_accepting_array_of_array_of_structs = MethodAcceptingArrayOfArrayOfStructsMethod( - web3_or_provider, - contract_address, - functions.methodAcceptingArrayOfArrayOfStructs, - validator, - ) + self.method_accepting_array_of_array_of_structs = MethodAcceptingArrayOfArrayOfStructsMethod(web3_or_provider, contract_address, functions.methodAcceptingArrayOfArrayOfStructs, validator) - self.method_accepting_array_of_structs = MethodAcceptingArrayOfStructsMethod( - web3_or_provider, - contract_address, - functions.methodAcceptingArrayOfStructs, - validator, - ) + self.method_accepting_array_of_structs = MethodAcceptingArrayOfStructsMethod(web3_or_provider, contract_address, functions.methodAcceptingArrayOfStructs, validator) - self.method_returning_array_of_structs = MethodReturningArrayOfStructsMethod( - web3_or_provider, - contract_address, - functions.methodReturningArrayOfStructs, - ) + self.method_returning_array_of_structs = MethodReturningArrayOfStructsMethod(web3_or_provider, contract_address, functions.methodReturningArrayOfStructs) - self.method_returning_multiple_values = MethodReturningMultipleValuesMethod( - web3_or_provider, - contract_address, - functions.methodReturningMultipleValues, - ) + self.method_returning_multiple_values = MethodReturningMultipleValuesMethod(web3_or_provider, contract_address, functions.methodReturningMultipleValues) - self.method_using_nested_struct_with_inner_struct_not_used_elsewhere = MethodUsingNestedStructWithInnerStructNotUsedElsewhereMethod( - web3_or_provider, - contract_address, - functions.methodUsingNestedStructWithInnerStructNotUsedElsewhere, - ) + self.method_using_nested_struct_with_inner_struct_not_used_elsewhere = MethodUsingNestedStructWithInnerStructNotUsedElsewhereMethod(web3_or_provider, contract_address, functions.methodUsingNestedStructWithInnerStructNotUsedElsewhere) - self.multi_input_multi_output = MultiInputMultiOutputMethod( - web3_or_provider, - contract_address, - functions.multiInputMultiOutput, - validator, - ) + self.multi_input_multi_output = MultiInputMultiOutputMethod(web3_or_provider, contract_address, functions.multiInputMultiOutput, validator) - self.nested_struct_input = NestedStructInputMethod( - web3_or_provider, - contract_address, - functions.nestedStructInput, - validator, - ) + self.nested_struct_input = NestedStructInputMethod(web3_or_provider, contract_address, functions.nestedStructInput, validator) - self.nested_struct_output = NestedStructOutputMethod( - web3_or_provider, contract_address, functions.nestedStructOutput - ) + self.nested_struct_output = NestedStructOutputMethod(web3_or_provider, contract_address, functions.nestedStructOutput) - self.no_input_no_output = NoInputNoOutputMethod( - web3_or_provider, contract_address, functions.noInputNoOutput - ) + self.no_input_no_output = NoInputNoOutputMethod(web3_or_provider, contract_address, functions.noInputNoOutput) - self.no_input_simple_output = NoInputSimpleOutputMethod( - web3_or_provider, contract_address, functions.noInputSimpleOutput - ) + self.no_input_simple_output = NoInputSimpleOutputMethod(web3_or_provider, contract_address, functions.noInputSimpleOutput) - self.non_pure_method = NonPureMethodMethod( - web3_or_provider, contract_address, functions.nonPureMethod - ) + self.non_pure_method = NonPureMethodMethod(web3_or_provider, contract_address, functions.nonPureMethod) - self.non_pure_method_that_returns_nothing = NonPureMethodThatReturnsNothingMethod( - web3_or_provider, - contract_address, - functions.nonPureMethodThatReturnsNothing, - ) + self.non_pure_method_that_returns_nothing = NonPureMethodThatReturnsNothingMethod(web3_or_provider, contract_address, functions.nonPureMethodThatReturnsNothing) - self.overloaded_method2 = OverloadedMethod2Method( - web3_or_provider, - contract_address, - functions.overloadedMethod, - validator, - ) + self.overloaded_method2 = OverloadedMethod2Method(web3_or_provider, contract_address, functions.overloadedMethod, validator) - self.overloaded_method1 = OverloadedMethod1Method( - web3_or_provider, - contract_address, - functions.overloadedMethod, - validator, - ) + self.overloaded_method1 = OverloadedMethod1Method(web3_or_provider, contract_address, functions.overloadedMethod, validator) - self.pure_function_with_constant = PureFunctionWithConstantMethod( - web3_or_provider, - contract_address, - functions.pureFunctionWithConstant, - ) + self.pure_function_with_constant = PureFunctionWithConstantMethod(web3_or_provider, contract_address, functions.pureFunctionWithConstant) - self.require_with_constant = RequireWithConstantMethod( - web3_or_provider, contract_address, functions.requireWithConstant - ) + self.require_with_constant = RequireWithConstantMethod(web3_or_provider, contract_address, functions.requireWithConstant) - self.revert_with_constant = RevertWithConstantMethod( - web3_or_provider, contract_address, functions.revertWithConstant - ) + self.revert_with_constant = RevertWithConstantMethod(web3_or_provider, contract_address, functions.revertWithConstant) - self.simple_input_no_output = SimpleInputNoOutputMethod( - web3_or_provider, - contract_address, - functions.simpleInputNoOutput, - validator, - ) + self.simple_input_no_output = SimpleInputNoOutputMethod(web3_or_provider, contract_address, functions.simpleInputNoOutput, validator) - self.simple_input_simple_output = SimpleInputSimpleOutputMethod( - web3_or_provider, - contract_address, - functions.simpleInputSimpleOutput, - validator, - ) + self.simple_input_simple_output = SimpleInputSimpleOutputMethod(web3_or_provider, contract_address, functions.simpleInputSimpleOutput, validator) - self.simple_pure_function = SimplePureFunctionMethod( - web3_or_provider, contract_address, functions.simplePureFunction - ) + self.simple_pure_function = SimplePureFunctionMethod(web3_or_provider, contract_address, functions.simplePureFunction) - self.simple_pure_function_with_input = SimplePureFunctionWithInputMethod( - web3_or_provider, - contract_address, - functions.simplePureFunctionWithInput, - validator, - ) + self.simple_pure_function_with_input = SimplePureFunctionWithInputMethod(web3_or_provider, contract_address, functions.simplePureFunctionWithInput, validator) - self.simple_require = SimpleRequireMethod( - web3_or_provider, contract_address, functions.simpleRequire - ) + self.simple_require = SimpleRequireMethod(web3_or_provider, contract_address, functions.simpleRequire) - self.simple_revert = SimpleRevertMethod( - web3_or_provider, contract_address, functions.simpleRevert - ) + self.simple_revert = SimpleRevertMethod(web3_or_provider, contract_address, functions.simpleRevert) - self.struct_input = StructInputMethod( - web3_or_provider, - contract_address, - functions.structInput, - validator, - ) + self.struct_input = StructInputMethod(web3_or_provider, contract_address, functions.structInput, validator) - self.struct_output = StructOutputMethod( - web3_or_provider, contract_address, functions.structOutput - ) + self.struct_output = StructOutputMethod(web3_or_provider, contract_address, functions.structOutput) - self.with_address_input = WithAddressInputMethod( - web3_or_provider, - contract_address, - functions.withAddressInput, - validator, - ) + self.with_address_input = WithAddressInputMethod(web3_or_provider, contract_address, functions.withAddressInput, validator) - self.withdraw = WithdrawMethod( - web3_or_provider, contract_address, functions.withdraw, validator - ) + self.withdraw = WithdrawMethod(web3_or_provider, contract_address, functions.withdraw, validator) def get_simple_event_event( self, tx_hash: Union[HexBytes, bytes] @@ -2016,15 +1509,7 @@ def get_simple_event_event( :param tx_hash: hash of transaction emitting SimpleEvent event """ tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) - return ( - self._web3_eth.contract( - address=to_checksum_address(self.contract_address), - abi=AbiGenDummy.abi(), - ) - .events.SimpleEvent() - .processReceipt(tx_receipt) - ) - + return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=AbiGenDummy.abi()).events.SimpleEvent().processReceipt(tx_receipt) def get_withdrawal_event( self, tx_hash: Union[HexBytes, bytes] ) -> Tuple[AttributeDict]: @@ -2033,14 +1518,7 @@ def get_withdrawal_event( :param tx_hash: hash of transaction emitting Withdrawal event """ tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) - return ( - self._web3_eth.contract( - address=to_checksum_address(self.contract_address), - abi=AbiGenDummy.abi(), - ) - .events.Withdrawal() - .processReceipt(tx_receipt) - ) + return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=AbiGenDummy.abi()).events.Withdrawal().processReceipt(tx_receipt) @staticmethod def abi(): @@ -2049,5 +1527,4 @@ def abi(): '[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"someBytes","type":"bytes"},{"indexed":false,"internalType":"string","name":"someString","type":"string"}],"name":"SimpleEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Withdrawal","type":"event"},{"constant":true,"inputs":[{"internalType":"bytes[]","name":"a","type":"bytes[]"}],"name":"acceptsAnArrayOfBytes","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes","name":"a","type":"bytes"}],"name":"acceptsBytes","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"components":[{"internalType":"uint256","name":"foo","type":"uint256"},{"internalType":"bytes","name":"bar","type":"bytes"},{"internalType":"string","name":"car","type":"string"}],"internalType":"struct AbiGenDummy.ComplexInput","name":"complexInput","type":"tuple"}],"name":"complexInputComplexOutput","outputs":[{"components":[{"components":[{"internalType":"uint256","name":"foo","type":"uint256"},{"internalType":"bytes","name":"bar","type":"bytes"},{"internalType":"string","name":"car","type":"string"}],"internalType":"struct AbiGenDummy.ComplexInput","name":"input","type":"tuple"},{"internalType":"bytes","name":"lorem","type":"bytes"},{"internalType":"bytes","name":"ipsum","type":"bytes"},{"internalType":"string","name":"dolor","type":"string"}],"internalType":"struct AbiGenDummy.ComplexOutput","name":"","type":"tuple"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"hash","type":"bytes32"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"ecrecoverFn","outputs":[{"internalType":"address","name":"signerAddress","type":"address"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":false,"inputs":[],"name":"emitSimpleEvent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"components":[{"internalType":"bytes","name":"someBytes","type":"bytes"},{"internalType":"uint32","name":"anInteger","type":"uint32"},{"internalType":"bytes[]","name":"aDynamicArrayOfBytes","type":"bytes[]"},{"internalType":"string","name":"aString","type":"string"}],"internalType":"struct AbiGenDummy.Struct[][]","name":"index_0","type":"tuple[][]"}],"name":"methodAcceptingArrayOfArrayOfStructs","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"components":[{"internalType":"bytes","name":"someBytes","type":"bytes"},{"internalType":"uint32","name":"anInteger","type":"uint32"},{"internalType":"bytes[]","name":"aDynamicArrayOfBytes","type":"bytes[]"},{"internalType":"string","name":"aString","type":"string"}],"internalType":"struct AbiGenDummy.Struct[]","name":"index_0","type":"tuple[]"}],"name":"methodAcceptingArrayOfStructs","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"methodReturningArrayOfStructs","outputs":[{"components":[{"internalType":"bytes","name":"someBytes","type":"bytes"},{"internalType":"uint32","name":"anInteger","type":"uint32"},{"internalType":"bytes[]","name":"aDynamicArrayOfBytes","type":"bytes[]"},{"internalType":"string","name":"aString","type":"string"}],"internalType":"struct AbiGenDummy.Struct[]","name":"","type":"tuple[]"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"methodReturningMultipleValues","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"methodUsingNestedStructWithInnerStructNotUsedElsewhere","outputs":[{"components":[{"components":[{"internalType":"uint256","name":"aField","type":"uint256"}],"internalType":"struct AbiGenDummy.StructNotDirectlyUsedAnywhere","name":"innerStruct","type":"tuple"}],"internalType":"struct AbiGenDummy.NestedStructWithInnerStructNotUsedElsewhere","name":"","type":"tuple"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"index_0","type":"uint256"},{"internalType":"bytes","name":"index_1","type":"bytes"},{"internalType":"string","name":"index_2","type":"string"}],"name":"multiInputMultiOutput","outputs":[{"internalType":"bytes","name":"","type":"bytes"},{"internalType":"bytes","name":"","type":"bytes"},{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"components":[{"components":[{"internalType":"bytes","name":"someBytes","type":"bytes"},{"internalType":"uint32","name":"anInteger","type":"uint32"},{"internalType":"bytes[]","name":"aDynamicArrayOfBytes","type":"bytes[]"},{"internalType":"string","name":"aString","type":"string"}],"internalType":"struct AbiGenDummy.Struct","name":"innerStruct","type":"tuple"},{"internalType":"string","name":"description","type":"string"}],"internalType":"struct AbiGenDummy.NestedStruct","name":"n","type":"tuple"}],"name":"nestedStructInput","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"nestedStructOutput","outputs":[{"components":[{"components":[{"internalType":"bytes","name":"someBytes","type":"bytes"},{"internalType":"uint32","name":"anInteger","type":"uint32"},{"internalType":"bytes[]","name":"aDynamicArrayOfBytes","type":"bytes[]"},{"internalType":"string","name":"aString","type":"string"}],"internalType":"struct AbiGenDummy.Struct","name":"innerStruct","type":"tuple"},{"internalType":"string","name":"description","type":"string"}],"internalType":"struct AbiGenDummy.NestedStruct","name":"","type":"tuple"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"noInputNoOutput","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"noInputSimpleOutput","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":false,"inputs":[],"name":"nonPureMethod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"nonPureMethodThatReturnsNothing","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"string","name":"a","type":"string"}],"name":"overloadedMethod","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"internalType":"int256","name":"a","type":"int256"}],"name":"overloadedMethod","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"pureFunctionWithConstant","outputs":[{"internalType":"uint256","name":"someConstant","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"requireWithConstant","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"revertWithConstant","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"index_0","type":"uint256"}],"name":"simpleInputNoOutput","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"index_0","type":"uint256"}],"name":"simpleInputSimpleOutput","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"simplePureFunction","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"simplePureFunctionWithInput","outputs":[{"internalType":"uint256","name":"sum","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"simpleRequire","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"simpleRevert","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"components":[{"internalType":"bytes","name":"someBytes","type":"bytes"},{"internalType":"uint32","name":"anInteger","type":"uint32"},{"internalType":"bytes[]","name":"aDynamicArrayOfBytes","type":"bytes[]"},{"internalType":"string","name":"aString","type":"string"}],"internalType":"struct AbiGenDummy.Struct","name":"s","type":"tuple"}],"name":"structInput","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"structOutput","outputs":[{"components":[{"internalType":"bytes","name":"someBytes","type":"bytes"},{"internalType":"uint32","name":"anInteger","type":"uint32"},{"internalType":"bytes[]","name":"aDynamicArrayOfBytes","type":"bytes[]"},{"internalType":"string","name":"aString","type":"string"}],"internalType":"struct AbiGenDummy.Struct","name":"s","type":"tuple"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"x","type":"address"},{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"uint256","name":"b","type":"uint256"},{"internalType":"address","name":"y","type":"address"},{"internalType":"uint256","name":"c","type":"uint256"}],"name":"withAddressInput","outputs":[{"internalType":"address","name":"z","type":"address"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]' # noqa: E501 (line-too-long) ) - # pylint: disable=too-many-lines diff --git a/packages/abi-gen/test-cli/output/python/lib_dummy/__init__.py b/packages/abi-gen/test-cli/output/python/lib_dummy/__init__.py index 6c1375710e..9bd2525fa7 100644 --- a/packages/abi-gen/test-cli/output/python/lib_dummy/__init__.py +++ b/packages/abi-gen/test-cli/output/python/lib_dummy/__init__.py @@ -46,6 +46,9 @@ class LibDummyValidator( # type: ignore pass + + + # pylint: disable=too-many-public-methods,too-many-instance-attributes class LibDummy: """Wrapper class for LibDummy Solidity contract.""" @@ -90,20 +93,20 @@ def __init__( try: for middleware in MIDDLEWARE: web3.middleware_onion.inject( - middleware["function"], layer=middleware["layer"] + middleware['function'], layer=middleware['layer'], ) except ValueError as value_error: - if value_error.args == ( - "You can't add the same un-named instance twice", - ): + if value_error.args == ("You can't add the same un-named instance twice",): pass self._web3_eth = web3.eth + @staticmethod def abi(): """Return the ABI to the underlying contract.""" - return json.loads("[]") # noqa: E501 (line-too-long) - + return json.loads( + '[]' # noqa: E501 (line-too-long) + ) # pylint: disable=too-many-lines diff --git a/packages/abi-gen/test-cli/output/python/test_lib_dummy/__init__.py b/packages/abi-gen/test-cli/output/python/test_lib_dummy/__init__.py index 11c40fa5d5..65daeaea75 100644 --- a/packages/abi-gen/test-cli/output/python/test_lib_dummy/__init__.py +++ b/packages/abi-gen/test-cli/output/python/test_lib_dummy/__init__.py @@ -46,16 +46,13 @@ class TestLibDummyValidator( # type: ignore pass -class PublicAddConstantMethod(ContractMethod): + + + +class PublicAddConstantMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the publicAddConstant method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function @@ -63,13 +60,13 @@ def __init__( def validate_and_normalize_inputs(self, x: int): """Validate the inputs to the publicAddConstant method.""" self.validator.assert_valid( - method_name="publicAddConstant", - parameter_name="x", + method_name='publicAddConstant', + parameter_name='x', argument_value=x, ) # safeguard against fractional inputs x = int(x) - return x + return (x) def call(self, x: int, tx_params: Optional[TxParams] = None) -> int: """Execute underlying contract method via eth_call. @@ -82,25 +79,16 @@ def call(self, x: int, tx_params: Optional[TxParams] = None) -> int: returned = self._underlying_method(x).call(tx_params.as_dict()) return int(returned) - def estimate_gas( - self, x: int, tx_params: Optional[TxParams] = None - ) -> int: + def estimate_gas(self, x: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (x) = self.validate_and_normalize_inputs(x) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(x).estimateGas(tx_params.as_dict()) - -class PublicAddOneMethod(ContractMethod): +class PublicAddOneMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the publicAddOne method.""" - def __init__( - self, - web3_or_provider: Union[Web3, BaseProvider], - contract_address: str, - contract_function: ContractFunction, - validator: Validator = None, - ): + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): """Persist instance data.""" super().__init__(web3_or_provider, contract_address, validator) self._underlying_method = contract_function @@ -108,11 +96,13 @@ def __init__( def validate_and_normalize_inputs(self, x: int): """Validate the inputs to the publicAddOne method.""" self.validator.assert_valid( - method_name="publicAddOne", parameter_name="x", argument_value=x, + method_name='publicAddOne', + parameter_name='x', + argument_value=x, ) # safeguard against fractional inputs x = int(x) - return x + return (x) def call(self, x: int, tx_params: Optional[TxParams] = None) -> int: """Execute underlying contract method via eth_call. @@ -125,19 +115,15 @@ def call(self, x: int, tx_params: Optional[TxParams] = None) -> int: returned = self._underlying_method(x).call(tx_params.as_dict()) return int(returned) - def estimate_gas( - self, x: int, tx_params: Optional[TxParams] = None - ) -> int: + def estimate_gas(self, x: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (x) = self.validate_and_normalize_inputs(x) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(x).estimateGas(tx_params.as_dict()) - # pylint: disable=too-many-public-methods,too-many-instance-attributes class TestLibDummy: """Wrapper class for TestLibDummy Solidity contract.""" - public_add_constant: PublicAddConstantMethod """Constructor-initialized instance of :class:`PublicAddConstantMethod`. @@ -148,6 +134,7 @@ class TestLibDummy: :class:`PublicAddOneMethod`. """ + def __init__( self, web3_or_provider: Union[Web3, BaseProvider], @@ -166,9 +153,7 @@ def __init__( self.contract_address = contract_address if not validator: - validator = TestLibDummyValidator( - web3_or_provider, contract_address - ) + validator = TestLibDummyValidator(web3_or_provider, contract_address) web3 = None if isinstance(web3_or_provider, BaseProvider): @@ -190,34 +175,20 @@ def __init__( try: for middleware in MIDDLEWARE: web3.middleware_onion.inject( - middleware["function"], layer=middleware["layer"], + middleware['function'], layer=middleware['layer'], ) except ValueError as value_error: - if value_error.args == ( - "You can't add the same un-named instance twice", - ): + if value_error.args == ("You can't add the same un-named instance twice",): pass self._web3_eth = web3.eth - functions = self._web3_eth.contract( - address=to_checksum_address(contract_address), - abi=TestLibDummy.abi(), - ).functions + functions = self._web3_eth.contract(address=to_checksum_address(contract_address), abi=TestLibDummy.abi()).functions - self.public_add_constant = PublicAddConstantMethod( - web3_or_provider, - contract_address, - functions.publicAddConstant, - validator, - ) + self.public_add_constant = PublicAddConstantMethod(web3_or_provider, contract_address, functions.publicAddConstant, validator) + + self.public_add_one = PublicAddOneMethod(web3_or_provider, contract_address, functions.publicAddOne, validator) - self.public_add_one = PublicAddOneMethod( - web3_or_provider, - contract_address, - functions.publicAddOne, - validator, - ) @staticmethod def abi(): @@ -226,5 +197,4 @@ def abi(): '[{"constant":true,"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"publicAddConstant","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"publicAddOne","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"}]' # noqa: E501 (line-too-long) ) - # pylint: disable=too-many-lines