chain: fix NewGenerator

This commit is contained in:
Łukasz Magiera 2019-07-26 14:19:27 +02:00 committed by whyrusleeping
parent 71baa5cbfe
commit 952cd288be
3 changed files with 12 additions and 3 deletions

View File

@ -8,8 +8,9 @@ import (
"github.com/filecoin-project/go-lotus/chain/types" "github.com/filecoin-project/go-lotus/chain/types"
"github.com/filecoin-project/go-lotus/chain/wallet" "github.com/filecoin-project/go-lotus/chain/wallet"
"github.com/filecoin-project/go-lotus/node/repo" "github.com/filecoin-project/go-lotus/node/repo"
block "github.com/ipfs/go-block-format" block "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
blockstore "github.com/ipfs/go-ipfs-blockstore" blockstore "github.com/ipfs/go-ipfs-blockstore"
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
) )
@ -93,6 +94,10 @@ func NewGenerator() (*ChainGen, error) {
genfb := &types.FullBlock{Header: genb.Genesis} genfb := &types.FullBlock{Header: genb.Genesis}
if err := cs.SetGenesis(genb.Genesis); err != nil {
return nil, err
}
gen := &ChainGen{ gen := &ChainGen{
bs: bs, bs: bs,
cs: cs, cs: cs,
@ -131,6 +136,10 @@ func (cg *ChainGen) NextBlock() (*types.FullBlock, error) {
return nil, err return nil, err
} }
if err := cg.cs.AddBlock(fblk.Header); err != nil {
return nil, err
}
cg.curBlock = fblk cg.curBlock = fblk
return fblk, nil return fblk, nil

View File

@ -13,7 +13,7 @@ func TestChainGeneration(t *testing.T) {
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
b, err := g.NextBlock() b, err := g.NextBlock()
if err != nil { if err != nil {
t.Fatal(err) t.Fatalf("error at H:%d, %s", i, err)
} }
if b.Header.Height != uint64(i+1) { if b.Header.Height != uint64(i+1) {
t.Fatal("wrong height") t.Fatal("wrong height")

View File

@ -42,7 +42,7 @@ func MinerCreateBlock(ctx context.Context, cs *store.ChainStore, miner address.A
Height: height, Height: height,
} }
fmt.Printf("adding %d messages to block...", len(msgs)) fmt.Printf("adding %d messages to block...\n", len(msgs))
var msgCids []cid.Cid var msgCids []cid.Cid
var blsSigs []types.Signature var blsSigs []types.Signature
var receipts []interface{} var receipts []interface{}