Skip to content

fullblocktests: Add ErrTicketInputScript tests. - #3796

Merged
davecgh merged 3 commits into
decred:masterfrom
matthawkins90:fullblocktests_ticket_input_script
Sep 14, 2026
Merged

davecgh merged 3 commits into
decred:masterfrom
matthawkins90:fullblocktests_ticket_input_script

Conversation

@matthawkins90

Copy link
Copy Markdown
Contributor

This is work towards #1182.

This adds full block test coverage for ErrTicketInputScript (previously named ErrSStxInScrType before #1468).

The old comment used to say:

// ErrSStxInScrType
// The testbed blockchain doesn't have any non-P2PKH or non-P2SH outputs
// so we can't test this. Independently tested and verified, but should
// eventually get its own unit test.

This new Ticket input script tests section creates those outputs. bti2 covers the script form and bti3 covers the script version of checkTicketPurchaseInputs.

Notes:

  • The mutation must target the output a ticket spends. bmf37 changes the ticket's own first output, which strips the OP_SSTX tag, so that block is rejected as a regular transaction with a stake output (ErrRegTxCreateStakeOut). The first commit fixes its comment to say so.
  • bti2 and bti3 pass nil coinbase spends. outs has no spare entry at that height and both blocks are rejected.

The old comment said the block contains "scripts that do not involve
p2pkh or p2sh addresses for a ticket purchase."  That wording implies
the block is testing the scripts a ticket purchase spends, but that's
not what it's doing.  The block replaces the script of the first output
so it is no longer tagged OP_SSTX (no longer a ticket at all) and is
thus rejected as a regular transaction that creates a stake output.
This adds a test which ensures the chain rejects a block when a ticket
purchase spends an output whose script is neither p2pkh nor p2sh.

The first block in the section pays a regular transaction output to a
bare OP_TRUE script.  The second block buys a ticket with that output.
The ticket is otherwise valid, so the input script check is what rejects
the block.

The following large reorg test builds on the new accepted block so it
still extends the best chain tip.
This adds a test which ensures the chain rejects a block when a ticket
purchase spends an output whose script version != 0.

The setup block now pays a second output to a p2sh script with script
version 1.  The new block buys a ticket with that output.  The script
form is allowed, so the version check is what rejects the block.

@davecgh davecgh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The additional tests look good and are nice additions.

I'm approving it regardless since the updated comment is more explicit and a good improvement, but I will note that the framing of the first commit isn't really correct. The existing comment was actually correct too.

The point there is that, in the stake tree, p2pkh and p2sh addresses must be prefixed by an OP_SSTX in order for them to be recognized as such. Therefore, providing a regular script that is of that type without the required prefix does result in a block with "scripts that do not involve p2pkh or p2sh addresses" because, from the viewpoint of the stake tree, they are in fact not a p2pkh or p2sh address.

@davecgh davecgh added this to the 2.2.0 milestone Sep 14, 2026
@davecgh
davecgh merged commit 90accde into decred:master Sep 14, 2026
32 checks passed
@matthawkins90
matthawkins90 deleted the fullblocktests_ticket_input_script branch September 14, 2026 20:42
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