github.com/defanghe/fabric@v2.1.1+incompatible/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/hyperledger/fabric/common/flogging" 14 "github.com/hyperledger/fabric/protoutil" 15 "github.com/stretchr/testify/assert" 16 "go.uber.org/zap" 17 ) 18 19 func getSeedBlock() *cb.Block { 20 seedBlock := protoutil.NewBlock(0, []byte("firsthash")) 21 seedBlock.Data.Data = [][]byte{[]byte("somebytes")} 22 return seedBlock 23 } 24 25 func TestCreateNextBlock(t *testing.T) { 26 first := protoutil.NewBlock(0, []byte("firsthash")) 27 bc := &blockCreator{ 28 hash: protoutil.BlockHeaderHash(first.Header), 29 number: first.Header.Number, 30 logger: flogging.NewFabricLogger(zap.NewNop()), 31 } 32 33 second := bc.createNextBlock([]*cb.Envelope{{Payload: []byte("some other bytes")}}) 34 assert.Equal(t, first.Header.Number+1, second.Header.Number) 35 assert.Equal(t, protoutil.BlockDataHash(second.Data), second.Header.DataHash) 36 assert.Equal(t, protoutil.BlockHeaderHash(first.Header), second.Header.PreviousHash) 37 38 third := bc.createNextBlock([]*cb.Envelope{{Payload: []byte("some other bytes")}}) 39 assert.Equal(t, second.Header.Number+1, third.Header.Number) 40 assert.Equal(t, protoutil.BlockDataHash(third.Data), third.Header.DataHash) 41 assert.Equal(t, protoutil.BlockHeaderHash(second.Header), third.Header.PreviousHash) 42 }