bitbucket.org/number571/tendermint@v0.8.14/state/test/factory/block.go (about) 1 package factory 2 3 import ( 4 "time" 5 6 "bitbucket.org/number571/tendermint/internal/test/factory" 7 sm "bitbucket.org/number571/tendermint/state" 8 "bitbucket.org/number571/tendermint/types" 9 ) 10 11 func MakeBlocks(n int, state *sm.State, privVal types.PrivValidator) []*types.Block { 12 blocks := make([]*types.Block, 0) 13 14 var ( 15 prevBlock *types.Block 16 prevBlockMeta *types.BlockMeta 17 ) 18 19 appHeight := byte(0x01) 20 for i := 0; i < n; i++ { 21 height := int64(i + 1) 22 23 block, parts := makeBlockAndPartSet(*state, prevBlock, prevBlockMeta, privVal, height) 24 blocks = append(blocks, block) 25 26 prevBlock = block 27 prevBlockMeta = types.NewBlockMeta(block, parts) 28 29 // update state 30 state.AppHash = []byte{appHeight} 31 appHeight++ 32 state.LastBlockHeight = height 33 } 34 35 return blocks 36 } 37 38 func MakeBlock(state sm.State, height int64, c *types.Commit) *types.Block { 39 block, _ := state.MakeBlock( 40 height, 41 factory.MakeTenTxs(state.LastBlockHeight), 42 c, 43 nil, 44 state.Validators.GetProposer().Address, 45 ) 46 return block 47 } 48 49 func makeBlockAndPartSet(state sm.State, lastBlock *types.Block, lastBlockMeta *types.BlockMeta, 50 privVal types.PrivValidator, height int64) (*types.Block, *types.PartSet) { 51 52 lastCommit := types.NewCommit(height-1, 0, types.BlockID{}, nil) 53 if height > 1 { 54 vote, _ := factory.MakeVote( 55 privVal, 56 lastBlock.Header.ChainID, 57 1, lastBlock.Header.Height, 0, 2, 58 lastBlockMeta.BlockID, 59 time.Now()) 60 lastCommit = types.NewCommit(vote.Height, vote.Round, 61 lastBlockMeta.BlockID, []types.CommitSig{vote.CommitSig()}) 62 } 63 64 return state.MakeBlock(height, []types.Tx{}, lastCommit, nil, state.Validators.GetProposer().Address) 65 }