diff --git a/tests/lint/resources/calldata-unused-definitions.json b/tests/lint/resources/calldata-unused-definitions.json new file mode 100644 index 0000000..2371d46 --- /dev/null +++ b/tests/lint/resources/calldata-unused-definitions.json @@ -0,0 +1,71 @@ +{ + "context": { + "$id": "AugustusSwapper", + "contract" : { + "abi": "https://github.com/LedgerHQ/ledger-asset-dapps/blob/main/ethereum/paraswap/abis/0x1bd435f3c054b6e901b7b108a0ab7617c808677b.abi.json", + "deployments": [ + { + "chainId": 1, + "address": "0x1bd435f3c054b6e901b7b108a0ab7617c808677b" + }, + { + "chainId": 1, + "address": "0xdef171fe48cf0115b1d80b88dc8eab59176fee57" + }, + { + "chainId": 56, + "address": "0x55a0e3b6579972055faa983482aceb4b251dcf15" + }, + { + "chainId": 56, + "address": "0xdef171fe48cf0115b1d80b88dc8eab59176fee57" + }, + { + "chainId": 137, + "address": "0x90249ed4d69d70e709ffcd8bee2c5a566f65dade" + }, + { + "chainId": 137, + "address": "0xdef171fe48cf0115b1d80b88dc8eab59176fee57" + } + ] + } + }, + + "metadata": { + "owner": "Paraswap" + }, + + "display": { + "definitions": { + "amountIn": { + "label": "Income Amount", + "format": "amount" + }, + "amountOut": { + "label": "Outcome Amount", + "format": "amount" + }, + "amountOutIn": { + "label": "Outcome/Income Amount", + "format": "amount" + } + }, + "formats": { + "0xcfc0afeb" : { + "$id": "swapOnZeroXv2", + "fields": [ + { + "path": "amountIn", + "$ref": "$.display.definitions.amountIn" + }, + { + "path": "amountOut", + "$ref": "$.display.definitions.amountOut" + } + ], + "required": ["amountIn", "amountOut"] + } + } + } +} diff --git a/tests/lint/test_lint.py b/tests/lint/test_lint.py index db198b2..532a609 100644 --- a/tests/lint/test_lint.py +++ b/tests/lint/test_lint.py @@ -2,10 +2,13 @@ import pytest -from erc7730.lint.lint import lint_all_and_print_errors +from erc7730.common.output import SetOutputAdder +from erc7730.lint.lint import lint_all, lint_all_and_print_errors from tests.cases import path_id from tests.files import ERC7730_DESCRIPTORS +UNUSED_DEF_INPUT = Path(__file__).resolve().parent / "resources" / "unused_definitions.json" + @pytest.mark.parametrize("input_file", ERC7730_DESCRIPTORS, ids=path_id) def test_registry_files(input_file: Path) -> None: @@ -18,3 +21,16 @@ def test_registry_files(input_file: Path) -> None: pytest.skip("Descriptor uses literal constants instead of token paths, which is not supported yet") assert lint_all_and_print_errors([input_file]) + + +def test_unused_definition_detected_by_linter() -> None: + """ + Test unused field definition is detected within an ERC-7730 file + """ + output_adder = SetOutputAdder() + + lint_all([UNUSED_DEF_INPUT], output_adder) + + assert output_adder.has_errors is True + + assert output_adder.outputs.pop().message == "Unused field definition"