From 71bd99ab7919b00d22b7cefc59703fb8fd0a0cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 22 Oct 2020 15:58:22 +0200 Subject: [PATCH] chain: Add more robust test for ChainExport --- chain/store/store_test.go | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/chain/store/store_test.go b/chain/store/store_test.go index 326899f90b6..2a81ae641b2 100644 --- a/chain/store/store_test.go +++ b/chain/store/store_test.go @@ -3,6 +3,7 @@ package store_test import ( "bytes" "context" + "github.com/filecoin-project/lotus/chain/stmgr" "testing" datastore "github.com/ipfs/go-datastore" @@ -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) + } + } +}