Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blockchain: move block validation rule tests into fullblocktests (2/x). #1095

Merged
merged 1 commit into from
Mar 1, 2018

Conversation

dnldd
Copy link
Member

@dnldd dnldd commented Feb 27, 2018

This PR moves the following block validation rule tests to
fullblocktests.

  • ErrBlockOneOutputs

    • Create a premine block with one premine output removed.
    • Create a premine block with a bad spend script.
    • Create a premine block with an incorrect pay to amount.
  • ErrVotesMismatch

    • Create block with a header that commits to more votes than the block
      actually contains.
  • ErrIncongruentVotebit

    • Attempt to add block with incorrect votebits set.
      • 4x Voters, 2x Nay 2x Yea, but block header says Yea
      • 3x Voters, 2x Nay 1x Yea, but block header says Yea
      • 3x Voters, 1x Nay 2x Yea, but block header says Nay
  • ErrSStxCommitment

    • Attempt to add block with a bad ticket purchase commitment.
  • ErrSSGenPayeeOuts

    • Attempt to add a block with a bad vote payee output.
    • Attempt to add a block with an incorrect vote payee output amount.
  • ErrBadCoinbaseFraudProof

    • Create block with an invalid coinbase transaction.
  • ErrFraudBlockIndex

    • Create block with an invalid transaction block height.
  • ErrFraudAmountIn

    • Create block with an invalid transaction amount.
  • ErrExpiredTx

    • Create block with an expired transaction.
  • ErrBadBlockHeight

    • Create block with an invalid block height.
  • ErrPoolSize

    • Create block with an invalid ticket pool size.
  • ErrInvalidFinalState

    • Create block with an invalid final state.
  • ErrScriptMalformed

    • Create block with a malformed spend script.

Work towards #1030.

Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

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

Just a quick comment. I'll need to dedicate some time to do a thorough review here.

@@ -484,11 +484,40 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
g.CreatePremineBlock("bpbad0", 1)
rejected(blockchain.ErrBadCoinbaseValue)

// Create a premine block with one premine output removed.
//
// genesis -> bp1
Copy link
Member

Choose a reason for hiding this comment

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

There are bad blocks. They shouldn't be depicted as being added at the tip of the best chain. Also, I'd suggest either keeping with the bpbad# naming, or change bpbad0 to just bp0 for consistency. I think bpbad is better so that the final good block can be bp and thus not need to change the rest of the comments later one.

//   genesis
//          \-> bp1

@davecgh
Copy link
Member

davecgh commented Feb 28, 2018

List of tests removed from validate_test.go which were not already covered by the existing full block tests and were ported:

- ErrBlockOneOutputs 2
- ErrBlockOneOutputs 3
- ErrBlockOneOutputs 4
- ErrBadCoinbaseFraudProof
- ErrVotesMismatch
- ErrIncongruentVotebit 5
- ErrIncongruentVotebit 6
- ErrIncongruentVotebit 7
- ErrSStxCommitment
- ErrSSGenPayeeOuts 1
- ErrSSGenPayeeOuts 2
- ErrInvalidFinalState
- ErrPoolSize
- ErrBadBlockHeight
- ErrExpiredTx
- ErrFraudAmountIn
- ErrFraudBlockHeight
- ErrFraudBlockIndex
- ErrScriptMalformed

Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

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

Nice job overall. I thoroughly reviewed every added test and logic wise, one of the tests is invalid, and one of them should be more explicit in the number chosen.

The rest of the requested changes are comment and position related.

@@ -1197,6 +1227,72 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
})
rejected(blockchain.ErrIncongruentVotebit)

// Create block with a header that commits to more votes
Copy link
Member

Choose a reason for hiding this comment

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

Comment does not match the test. The header is committing to less votes than the block actually contains.


// Attempt to add block with incorrect votebits set.
// 4x Voters
// 2x Nay 2x Yea, but block header says Yea
Copy link
Member

Choose a reason for hiding this comment

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

Please keep the Yes/No consistent for all tests.

// ... -> bsl5(8)
// \-> bv15(9)
g.SetTip("bsl5")
g.NextBlock("bv15", outs[9], ticketOuts[9], g.ReplaceWithNVotes(3), func(b *wire.MsgBlock) {
Copy link
Member

Choose a reason for hiding this comment

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

Why replace with 3 votes?

// \-> bv15(9)
g.SetTip("bsl5")
g.NextBlock("bv15", outs[9], ticketOuts[9], g.ReplaceWithNVotes(3), func(b *wire.MsgBlock) {
b.STransactions[5].TxOut[1].PkScript = chaingen.VoteCommitmentScript(g.Tip().BlockHash(), 1)
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct. It's not a vote and the commitment is different for a ticket purchase. You should export purchaseCommitmentScript from chaingen and use that instead.

Also, this is way over 80 cols.

})
rejected(blockchain.ErrBadCoinbaseFraudProof)

// Create block with an invalid transaction block index.
Copy link
Member

Choose a reason for hiding this comment

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

with a regular transaction that commits to an invalid block index.

})
rejected(blockchain.ErrFraudBlockHeight)

// Create block with an invalid transaction amount.
Copy link
Member

Choose a reason for hiding this comment

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

with a regular transaction that commits to an invalid input amount.

g.NextBlock("bmf21", outs[15], ticketOuts[15], func(b *wire.MsgBlock) {
txOut := chaingen.MakeSpendableOut(b, 1, 0)
tx := g.CreateSpendTx(&txOut, lowFee)
tx.Expiry = 20
Copy link
Member

Choose a reason for hiding this comment

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

This should be 1 so it is the exact expiration period of the transaction itself to help detect off by ones in the code. There should also ideally be another test added that sets the expiry of b.Transactions[1] to exactly one more than the height at which it is included to ensure it is accepted. Obviously that would cause another accepted block and thus can't go here, but such a test should be added.

})
rejected(blockchain.ErrExpiredTx)

// Create block with an invalid block height.
Copy link
Member

Choose a reason for hiding this comment

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

that commits to an invalid height.

})
rejected(blockchain.ErrBadBlockHeight)

// Create block with an invalid ticket pool size.
Copy link
Member

Choose a reason for hiding this comment

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

that commits to an invalid ticket pool size.

})
rejected(blockchain.ErrPoolSize)

// Create block with an invalid final state.
Copy link
Member

Choose a reason for hiding this comment

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

that commits to an invalid final state.

})
rejected(blockchain.ErrBadBlockHeight)

// Create that commits to an invalid ticket pool size.
Copy link
Member

Choose a reason for hiding this comment

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

block

@dnldd dnldd force-pushed the fullblocktests-two-of-x branch 4 times, most recently from cdfb253 to d9d6f60 Compare March 1, 2018 00:50
This PR moves the following block validation rule tests to
fullblocktests.

- `ErrBlockOneOutputs`
  - Create a premine block with one premine output removed.
  - Create a premine block with a bad spend script.
  - Create a premine block with an incorrect pay to amount.

- `ErrVotesMismatch`
  - Create block with a header that commits to more votes than the block
actually contains.

- `ErrIncongruentVotebit`
  - Attempt to add block with incorrect votebits set.
    - 4x Voters, 2x Nay 2x Yea, but block header says Yea
    - 3x Voters, 2x Nay 1x Yea, but block header says Yea
    - 3x Voters, 1x Nay 2x Yea, but block header says Nay
- `ErrSStxCommitment`
  - Attempt to add block with a bad ticket purchase commitment.

- `ErrSSGenPayeeOuts`
  - Attempt to add a block with a bad vote payee output.
  - Attempt to add a block with an incorrect vote payee output amount.

- `ErrBadCoinbaseFraudProof`
  - Create block with an invalid coinbase transaction.

- `ErrFraudBlockIndex`
  - Create block with an invalid transaction block height.

- `ErrFraudAmountIn`
  - Create block with an invalid transaction amount.

- `ErrExpiredTx`
  - Create block with an expired transaction.

- `ErrBadBlockHeight`
  - Create block with an invalid block height.

- `ErrPoolSize`
  - Create block with an invalid ticket pool size.

- `ErrInvalidFinalState`
  - Create block with an invalid final state.

- `ErrScriptMalformed`
  - Create block with a malformed spend script.
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