github.com/osdi23p228/fabric@v0.0.0-20221218062954-77808885f5db/orderer/consensus/etcdraft/blockcreator_test.go (about)

     1  /*
     2  Copyright IBM Corp. 2017 All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package etcdraft
     8  
     9  import (
    10  	"testing"
    11  
    12  	cb "github.com/hyperledger/fabric-protos-go/common"
    13  	"github.com/osdi23p228/fabric/common/flogging"
    14  	"github.com/osdi23p228/fabric/protoutil"
    15  	"github.com/stretchr/testify/assert"
    16  	"go.uber.org/zap"
    17  )
    18  
    19  func TestCreateNextBlock(t *testing.T) {
    20  	first := protoutil.NewBlock(0, []byte("firsthash"))
    21  	bc := &blockCreator{
    22  		hash:   protoutil.BlockHeaderHash(first.Header),
    23  		number: first.Header.Number,
    24  		logger: flogging.NewFabricLogger(zap.NewNop()),
    25  	}
    26  
    27  	second := bc.createNextBlock([]*cb.Envelope{{Payload: []byte("some other bytes")}})
    28  	assert.Equal(t, first.Header.Number+1, second.Header.Number)
    29  	assert.Equal(t, protoutil.BlockDataHash(second.Data), second.Header.DataHash)
    30  	assert.Equal(t, protoutil.BlockHeaderHash(first.Header), second.Header.PreviousHash)
    31  
    32  	third := bc.createNextBlock([]*cb.Envelope{{Payload: []byte("some other bytes")}})
    33  	assert.Equal(t, second.Header.Number+1, third.Header.Number)
    34  	assert.Equal(t, protoutil.BlockDataHash(third.Data), third.Header.DataHash)
    35  	assert.Equal(t, protoutil.BlockHeaderHash(second.Header), third.Header.PreviousHash)
    36  }