Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaireGuerreGiordano committed Nov 26, 2024
1 parent c41d245 commit 102b2b4
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
71 changes: 71 additions & 0 deletions tests/lint/resources/calldata-unused-definitions.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
}
18 changes: 17 additions & 1 deletion tests/lint/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"

0 comments on commit 102b2b4

Please sign in to comment.