From e62a21858bcd56fba4bc562897451bb569c85f96 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Mon, 17 Jun 2019 21:26:39 -0500 Subject: [PATCH] fullblocktests: Add coinbase nulldata tests. This adds two new consensus tests to the full block tests for the coinbase nulldata height commitment. The first new test ensures coinbase transactions with the wrong script version are rejected and the second test ensures data pushes that exceed the maximum allowed number of bytes for the coinbase nulldata push are rejected. --- blockchain/fullblocktests/generate.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/blockchain/fullblocktests/generate.go b/blockchain/fullblocktests/generate.go index 4a18e123..68df3379 100644 --- a/blockchain/fullblocktests/generate.go +++ b/blockchain/fullblocktests/generate.go @@ -2477,10 +2477,21 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { }) rejected(blockchain.ErrFirstTxNotCoinbase) + // Create block with an invalid script version in the coinbase block + // commitment output. + // + // ... -> bsb2(18) + // \-> bcb2a(19) + g.SetTip("bsb2") + g.NextBlock("bcb2a", outs[19], ticketOuts[19], func(b *wire.MsgBlock) { + b.Transactions[0].TxOut[1].Version = ^uint16(0) + }) + rejected(blockchain.ErrFirstTxNotCoinbase) + // Create block with too few bytes for the coinbase height commitment. // // ... -> bsb2(18) - // \-> bcb2(19) + // \-> bcb3(19) g.SetTip("bsb2") g.NextBlock("bcb3", outs[19], ticketOuts[19], func(b *wire.MsgBlock) { script := opReturnScript(repeatOpcode(0x00, 3)) @@ -2488,6 +2499,17 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { }) rejected(blockchain.ErrFirstTxNotCoinbase) + // Create block with too many bytes for the coinbase height commitment. + // + // ... -> bsb2(18) + // \-> bcb3a(19) + g.SetTip("bsb2") + g.NextBlock("bcb3a", outs[19], ticketOuts[19], func(b *wire.MsgBlock) { + script := opReturnScript(repeatOpcode(0x00, 257)) + b.Transactions[0].TxOut[1].PkScript = script + }) + rejected(blockchain.ErrFirstTxNotCoinbase) + // Create block with invalid block height in the coinbase commitment. // // ... -> bsb2(18)