(t *testing.T, lastBlock *types.Block, lgr *ledger.Ledger)
| 40 | } |
| 41 | |
| 42 | func buildTestBlock(t *testing.T, lastBlock *types.Block, lgr *ledger.Ledger) (*Block, error) { |
| 43 | timestamp := uint32(time.Now().Unix()) |
| 44 | if timestamp <= lastBlock.Header.Timestamp { |
| 45 | timestamp = lastBlock.Header.Timestamp + 1 |
| 46 | } |
| 47 | txs := []*types.Transaction{} |
| 48 | txHash := []common.Uint256{} |
| 49 | txRoot := common.ComputeMerkleRoot(txHash) |
| 50 | blockRoot := lgr.GetBlockRootWithNewTxRoots(lastBlock.Header.Height, []common.Uint256{lastBlock.Header.TransactionsRoot, txRoot}) |
| 51 | |
| 52 | consensusPayload, err := json.Marshal(&vconfig.VbftBlockInfo{}) |
| 53 | if err != nil { |
| 54 | t.Fatalf("failed to build consensus payload: %s", err) |
| 55 | } |
| 56 | |
| 57 | blkHeader := &types.Header{ |
| 58 | PrevBlockHash: lastBlock.Header.Hash(), |
| 59 | TransactionsRoot: txRoot, |
| 60 | BlockRoot: blockRoot, |
| 61 | Timestamp: timestamp, |
| 62 | Height: lastBlock.Header.Height + 1, |
| 63 | ConsensusData: common.GetNonce(), |
| 64 | ConsensusPayload: consensusPayload, |
| 65 | Bookkeepers: make([]keypair.PublicKey, 0), |
| 66 | SigData: make([][]byte, 0), |
| 67 | } |
| 68 | |
| 69 | // add sigs |
| 70 | hash := blkHeader.Hash() |
| 71 | for i := 0; i < 5; i++ { |
| 72 | acc := testBookkeeperAccounts[i] |
| 73 | sig, err := signature.Sign(acc, hash[:]) |
| 74 | if err != nil { |
| 75 | t.Fatalf("bookkeeper %d sign block: %s", i, err) |
| 76 | } |
| 77 | blkHeader.Bookkeepers = append(blkHeader.Bookkeepers, acc.PublicKey) |
| 78 | blkHeader.SigData = append(blkHeader.SigData, sig) |
| 79 | } |
| 80 | |
| 81 | blk := &types.Block{ |
| 82 | Header: blkHeader, |
| 83 | Transactions: txs, |
| 84 | } |
| 85 | block := &Block{ |
| 86 | Block: blk, |
| 87 | } |
| 88 | return block, nil |
| 89 | } |
| 90 | func TestAddBlock(t *testing.T) { |
| 91 | blockpool, err := buildTestBlockPool(t) |
| 92 | if err != nil { |
no test coverage detected