core: ensure we produce correct blocks for tests

Blocks must have at least one transaction and we should check for correct
merkle root generation.
This commit is contained in:
Roman Khimov 2020-05-07 21:46:28 +03:00
parent e097e86bfa
commit 943d435cd2

View file

@ -59,6 +59,9 @@ func newBlock(cfg config.ProtocolConfiguration, index uint32, prev util.Uint256,
witness := transaction.Witness{ witness := transaction.Witness{
VerificationScript: valScript, VerificationScript: valScript,
} }
if len(txs) == 0 {
txs = []*transaction.Transaction{newMinerTX()}
}
b := &block.Block{ b := &block.Block{
Base: block.Base{ Base: block.Base{
Version: 0, Version: 0,
@ -71,7 +74,10 @@ func newBlock(cfg config.ProtocolConfiguration, index uint32, prev util.Uint256,
}, },
Transactions: txs, Transactions: txs,
} }
_ = b.RebuildMerkleRoot() err := b.RebuildMerkleRoot()
if err != nil {
panic(err)
}
invScript := make([]byte, 0) invScript := make([]byte, 0)
for _, wif := range privNetKeys { for _, wif := range privNetKeys {