From 1cdb2022cbe778fbe7d0a021a0f1241aceb11c14 Mon Sep 17 00:00:00 2001 From: Judy Wu Date: Thu, 5 Oct 2023 22:54:10 -0400 Subject: [PATCH 1/3] address issue #2127 and allow function parameter name to be empty when casting to string --- slither/core/variables/variable.py | 1 - .../test_contract_data/test_contract_data.sol | 5 +++++ tests/e2e/compilation/test_resolution.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/e2e/compilation/test_data/test_contract_data/test_contract_data.sol diff --git a/slither/core/variables/variable.py b/slither/core/variables/variable.py index 2b777e6723..1afcc47575 100644 --- a/slither/core/variables/variable.py +++ b/slither/core/variables/variable.py @@ -179,5 +179,4 @@ def solidity_signature(self) -> str: return f'{name}({",".join(parameters)})' def __str__(self) -> str: - assert self._name return self._name diff --git a/tests/e2e/compilation/test_data/test_contract_data/test_contract_data.sol b/tests/e2e/compilation/test_data/test_contract_data/test_contract_data.sol new file mode 100644 index 0000000000..a99001da34 --- /dev/null +++ b/tests/e2e/compilation/test_data/test_contract_data/test_contract_data.sol @@ -0,0 +1,5 @@ +contract TestSlither { + function testFunction(uint256 param1, uint256, address param3) public { + + } +} \ No newline at end of file diff --git a/tests/e2e/compilation/test_resolution.py b/tests/e2e/compilation/test_resolution.py index 71edaa143f..479e87d4a1 100644 --- a/tests/e2e/compilation/test_resolution.py +++ b/tests/e2e/compilation/test_resolution.py @@ -43,3 +43,18 @@ def test_cycle(solc_binary_path) -> None: solc_path = solc_binary_path("0.8.0") slither = Slither(Path(TEST_DATA_DIR, "test_cyclic_import", "a.sol").as_posix(), solc=solc_path) _run_all_detectors(slither) + + +def test_contract_function_parameter(solc_binary_path) -> None: + solc_path = solc_binary_path("0.8.0") + standard_json = SolcStandardJson() + standard_json.add_source_file( + Path(TEST_DATA_DIR, "test_contract_data", "test_contract_data.sol").as_posix() + ) + compilation = CryticCompile(standard_json, solc=solc_path) + slither = Slither(compilation) + contract = slither.contracts[0] + + for function in contract.functions: + for parameter in function.parameters: + str(parameter) From 8feb4943d9a5e8bba3435544e4e2277fa63a9809 Mon Sep 17 00:00:00 2001 From: Judy Wu Date: Fri, 6 Oct 2023 10:43:15 -0400 Subject: [PATCH 2/3] Update test to assert expected parameter names --- tests/e2e/compilation/test_resolution.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/e2e/compilation/test_resolution.py b/tests/e2e/compilation/test_resolution.py index 479e87d4a1..af7cbe2c77 100644 --- a/tests/e2e/compilation/test_resolution.py +++ b/tests/e2e/compilation/test_resolution.py @@ -54,7 +54,9 @@ def test_contract_function_parameter(solc_binary_path) -> None: compilation = CryticCompile(standard_json, solc=solc_path) slither = Slither(compilation) contract = slither.contracts[0] + function = contract.functions[0] + parameters = function.parameters - for function in contract.functions: - for parameter in function.parameters: - str(parameter) + assert (parameters[0].name == 'param1') + assert (parameters[1].name == '') + assert (parameters[2].name == 'param3') From 98da04fb06bd3018995bce6136440919354a4140 Mon Sep 17 00:00:00 2001 From: Feist Josselin Date: Thu, 12 Oct 2023 16:01:19 +0200 Subject: [PATCH 3/3] Minor --- slither/core/variables/variable.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/slither/core/variables/variable.py b/slither/core/variables/variable.py index 1afcc47575..f9ef190246 100644 --- a/slither/core/variables/variable.py +++ b/slither/core/variables/variable.py @@ -179,4 +179,6 @@ def solidity_signature(self) -> str: return f'{name}({",".join(parameters)})' def __str__(self) -> str: + if self._name is None: + return "" return self._name