Skip to content

Commit

Permalink
chain: Add more robust test for ChainExport
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Oct 22, 2020
1 parent 40872e9 commit 71bd99a
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions chain/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package store_test
import (
"bytes"
"context"
"github.com/filecoin-project/lotus/chain/stmgr"
"testing"

datastore "github.com/ipfs/go-datastore"
Expand Down Expand Up @@ -107,3 +108,60 @@ func TestChainExportImport(t *testing.T) {
t.Fatal("imported chain differed from exported chain")
}
}

func TestChainExportImportFull(t *testing.T) {
cg, err := gen.NewGenerator()
if err != nil {
t.Fatal(err)
}

var last *types.TipSet
for i := 0; i < 100; i++ {
ts, err := cg.NextTipSet()
if err != nil {
t.Fatal(err)
}

last = ts.TipSet.TipSet()
}

buf := new(bytes.Buffer)
if err := cg.ChainStore().Export(context.TODO(), last, 100, false, buf); err != nil {
t.Fatal(err)
}

nbs := blockstore.NewTemporary()
cs := store.NewChainStore(nbs, datastore.NewMapDatastore(), nil, nil)
root, err := cs.Import(buf)
if err != nil {
t.Fatal(err)
}

err = cs.SetHead(last)
if err != nil {
t.Fatal(err)
}

if !root.Equals(last) {
t.Fatal("imported chain differed from exported chain")
}

sm := stmgr.NewStateManager(cs)
for i := 0; i < 100; i++ {
ts, err := cs.GetTipsetByHeight(context.TODO(), abi.ChainEpoch(i), nil, false)
if err != nil {
t.Fatal(err)
}

st, err := sm.ParentState(ts)
if err != nil {
t.Fatal(err)
}

// touches a bunch of actors
_, err = sm.GetCirculatingSupply(context.TODO(), abi.ChainEpoch(i), st)
if err != nil {
t.Fatal(err)
}
}
}

0 comments on commit 71bd99a

Please sign in to comment.