diff --git a/pkg/core/block.go b/pkg/core/block.go index 97fdeabce..fddb06eba 100644 --- a/pkg/core/block.go +++ b/pkg/core/block.go @@ -46,6 +46,10 @@ func (b *Block) rebuildMerkleRoot() error { // Verify the integrity of the block. func (b *Block) Verify(full bool) bool { + // There has to be some transaction inside. + if len(b.Transactions) == 0 { + return false + } // The first TX has to be a miner transaction. if b.Transactions[0].Type != transaction.MinerType { return false diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index 1943d1610..8dab93802 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -6,6 +6,7 @@ import ( "github.com/CityOfZion/neo-go/config" "github.com/CityOfZion/neo-go/pkg/core/storage" + "github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/io" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -38,9 +39,9 @@ func TestAddHeaders(t *testing.T) { func TestAddBlock(t *testing.T) { bc := newTestChain(t) blocks := []*Block{ - newBlock(1), - newBlock(2), - newBlock(3), + newBlock(1, newTX(transaction.MinerType)), + newBlock(2, newTX(transaction.MinerType)), + newBlock(3, newTX(transaction.MinerType)), } for i := 0; i < len(blocks); i++ { @@ -69,7 +70,7 @@ func TestAddBlock(t *testing.T) { func TestGetHeader(t *testing.T) { bc := newTestChain(t) - block := newBlock(1) + block := newBlock(1, newTX(transaction.MinerType)) err := bc.AddBlock(block) assert.Nil(t, err)