-
Notifications
You must be signed in to change notification settings - Fork 291
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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
List of tests removed from
|
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
e8dfb10
to
282f233
Compare
}) | ||
rejected(blockchain.ErrBadBlockHeight) | ||
|
||
// Create that commits to an invalid ticket pool size. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
block
cdfb253
to
d9d6f60
Compare
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.
d9d6f60
to
84820a0
Compare
This PR moves the following block validation rule tests to
fullblocktests.
ErrBlockOneOutputs
ErrVotesMismatch
actually contains.
ErrIncongruentVotebit
ErrSStxCommitment
ErrSSGenPayeeOuts
ErrBadCoinbaseFraudProof
ErrFraudBlockIndex
ErrFraudAmountIn
ErrExpiredTx
ErrBadBlockHeight
ErrPoolSize
ErrInvalidFinalState
ErrScriptMalformed
Work towards #1030.