Skip to content

Tests: Regression test for change output detection in _parse_outputs() - #936

Closed
nkatha23 wants to merge 1 commit into
SeedSigner:devfrom
nkatha23:tests/psbt-parser-duplicate-sc-data-check
Closed

nkatha23 wants to merge 1 commit into
SeedSigner:devfrom
nkatha23:tests/psbt-parser-duplicate-sc-data-check

Conversation

@nkatha23

@nkatha23 nkatha23 commented Jun 3, 2026

Copy link
Copy Markdown

_parse_outputs() in psbt_parser.py contains a structural defect in its if/elif chain. For multisig output types (p2wsh, p2sh-p2wsh, legacy p2sh), the branches set sc but never assign is_change = True internally. A trailing unconditional check after the entire chain is the sole path through which multisig outputs are ever classified as change. For single-sig types (pkh, p2tr), is_change is set inside the branch and then the trailing check fires again redundantly. This code path had no test pinning it, a future refactor could remove or restructure the trailing check and silently break multisig change detection.

Added test_parse_outputs_trailing_sc_data_check to TestPSBTParser. The test builds a single-output PSBT for each of the seven supported script types (three multisig, four single-sig) and asserts num_change_outputs == 1. The docstring explicitly names the trailing check, explains why it is load-bearing for multisig and redundant for single-sig, and describes what a correct post-fix refactor would look like.

The trailing `if sc.data == vout.script_pubkey.data` check at the end of
_parse_outputs() is the sole path that sets is_change = True for multisig
types (p2wsh, p2sh-p2wsh, legacy p2sh). Those branches set `sc` but
contain no is_change assignment of their own. Removing this check would
silently break multisig change detection.

For single-sig types (pkh, p2tr), is_change is already set inside the
elif branch — the trailing check fires redundantly and arrives at the
same result.

Pins current behavior across all seven script types. A future refactor
that unifies the if/elif chain and moves is_change into each branch must
keep this test passing. Part of SeedSigner#931.
@nkatha23
nkatha23 force-pushed the tests/psbt-parser-duplicate-sc-data-check branch from 207d925 to 9e056be Compare June 5, 2026 08:14
@nkatha23 nkatha23 changed the title tests: pin trailing sc.data check in _parse_outputs() Tests: Regression test for change output detection in _parse_outputs() Jun 5, 2026
@newtonick

Copy link
Copy Markdown
Collaborator

PRs #1013 and #1032 made structural changes to psbt_parser and added tests for change output detection. I don't believe it makes sense to review and merge this PR at this point.

@newtonick newtonick closed this Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants