{"slug": "nine-green-tests-and-a-parser-that-never-worked-once", "title": "Nine green tests and a parser that never worked once", "summary": "A developer building adapters for a protocol indexer discovered that an end-to-end test with a tolerance for chain reverts was masking a parser bug, causing the suite to pass despite the parser failing on every real call. The test's if/else logic accepted both success and failure, so no input could make it fail. After removing the tolerance, the real issue surfaced: the parser used .find() to select a transfer leg, which returned the first match instead of requiring exactly one, leading to plausible but wrong results when multiple structurally identical transfers existed. The developer now advocates for probing conditional test branches, grepping for first-match selection, and proving assertions fail without the fix.", "body_md": "*This is a submission for DEV's Summer Bug Smash: Smash Stories powered by Sentry.*\n\nTwo bugs, one story. A parser that failed on every real call, plus the test that certified\n\nit as working for two review rounds. The second one is the one worth reading about.\n\nI was writing adapters for a protocol indexer. Each adapter has a Receipt parser: it\n\nreceives the on-chain state changes from one transaction and produces a structured\n\noutcome, \"this account swapped 100 of token A for 98 of token B\". Downstream consumers\n\ntrust that outcome. If the parser picks the wrong movement out of the transaction, the\n\nsystem reports a swap that never happened, with no error anywhere.\n\nThe tests ran against live mainnet, which is where this starts.\n\nThe end-to-end test for one adapter looked roughly like this:\n\n```\nif (halted) {\n  expect(index).toBe(1)          // the call reverted on chain, fine\n} else {\n  expect(result).toEqual(...)    // the call succeeded, check the payload\n}\n```\n\nThe reasoning was sensible. This is a live chain, the contract call might legitimately\n\nrevert depending on pool state, so the test tolerates a revert instead of failing the\n\nbuild on someone else's liquidity.\n\nRead it again. **There is no input that makes this test fail.** Success gets checked.\n\nFailure gets accepted. The assertion has no opinion.\n\nNine cases against Monad mainnet, all green, through two rounds of review. What they were\n\nactually reporting was my own parser throwing on every single call. The halt the test\n\ntolerated was never the chain rejecting anything. It was my code.\n\nThe reviewer did not catch it. I did not catch it. The suite was green, which is what\n\nwe both looked at.\n\nWith the tolerance removed the real bug surfaced immediately, a one-liner of\n\nthe worst kind:\n\n``` js\nconst leg = transfers.find(t => /* right endpoints, right amount, not our own token */)\n```\n\n`.find()`\n\nreturns the first match. The predicate described a shape that any ERC-20\n\ntransfer of the right size could satisfy. So in a transaction carrying two structurally\n\nidentical movements, the parser reported whichever came first in the log.\n\nTwo ways that goes wrong. I reproduced both:\n\nNeither raises anything. You get a plausible, wrong answer.\n\nThe fix is a rule rather than a patch: `filter`\n\nthe candidates, then require **exactly\none**. Zero keeps the existing missing-evidence error. Two or more throws and names the\n\nThe parser bug is ordinary. `.find()`\n\nwhere you meant \"the only one\" is a mistake every\n\ncodebase has. Once you see it you fix it in a minute.\n\nThe test bug is the interesting one, because **it consumed the evidence I was using to\njudge the parser.** A green suite is what I hand a reviewer. A branch in the assertion\n\nThree things I now do because of it.\n\n**Any if (failure) {...} else {...} in a test is unverified until probed.** So is any\n\n**Grep for first-match selection.** `.find(`\n\n, `[0]`\n\n, `.at(0)`\n\n, `.shift()`\n\n. For each one,\n\nask what stops a second, equally valid item from matching. If the predicate cannot name\n\nsomething fixed, it is guessing.\n\n**Prove the new assertion fails without the fix. Be careful how you undo it.** This\n\none bit me a second time. To show an assertion catches the bug you revert the source and\n\nrun the suite. I used `git checkout -- <file>`\n\nto undo the experiment, but that file also\n\nheld the round's real work, so my new assertions vanished and the next run went green for\n\nan entirely different reason. Caught by diffing the working tree, not by the suite. So:\n\ntoggle only the file the experiment needs, never one carrying the change, then capture the\n\nfailing output to a file the moment it fails, because you cannot reproduce it once the\n\nstate is restored.\n\nNeither of these was a crash. Nothing threw, nothing logged, no monitor fired. One\n\nproduced a wrong answer that looked like a right answer. The other produced a green\n\ntest that looked like a passing test.\n\nThat is the class of bug I have started looking for first, because it is the class that\n\nsurvives review. A crash gets fixed the day it happens. A confident wrong answer ships,\n\nand then it gets built on.\n\n*Written with AI assistance (Claude, Anthropic). The bugs, the reproductions and the\nreview history are from my own work on a real open source adapter. Both defects were\nreproduced from both directions, the decoy and the duplicate, before the fix was\nsubmitted. The corrected assertions were confirmed failing against the unpatched\nparser.*", "url": "https://wpnews.pro/news/nine-green-tests-and-a-parser-that-never-worked-once", "canonical_source": "https://dev.to/zkasuran/nine-green-tests-and-a-parser-that-never-worked-once-4m3i", "published_at": "2026-08-11 11:51:29+00:00", "updated_at": "2026-08-11 12:16:19.172220+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["Monad", "Sentry"], "alternates": {"html": "https://wpnews.pro/news/nine-green-tests-and-a-parser-that-never-worked-once", "markdown": "https://wpnews.pro/news/nine-green-tests-and-a-parser-that-never-worked-once.md", "text": "https://wpnews.pro/news/nine-green-tests-and-a-parser-that-never-worked-once.txt", "jsonld": "https://wpnews.pro/news/nine-green-tests-and-a-parser-that-never-worked-once.jsonld"}}