From 280dac79458a1c8c6059346dcc5ad274f89c34d6 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Fri, 2 Aug 2019 16:14:58 -0700 Subject: [PATCH] make 'mineNewBlock' testhelper --- chain/sync_test.go | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/chain/sync_test.go b/chain/sync_test.go index 146df11fb..54fcae46f 100644 --- a/chain/sync_test.go +++ b/chain/sync_test.go @@ -83,6 +83,28 @@ func prepSyncTest(t *testing.T, h int) *syncTestUtil { return tu } +func (tu *syncTestUtil) mineNewBlock(src int) { + fblk, err := tu.g.NextBlock() + require.NoError(tu.t, err) + + for _, msg := range fblk.Messages { + require.NoError(tu.t, tu.nds[src].MpoolPush(context.TODO(), msg)) + } + + require.NoError(tu.t, tu.nds[src].ChainSubmitBlock(context.TODO(), fblkToBlkMsg(fblk))) +} + +func fblkToBlkMsg(fb *types.FullBlock) *chain.BlockMsg { + out := &chain.BlockMsg{ + Header: fb.Header, + } + + for _, msg := range fb.Messages { + out.Messages = append(out.Messages, msg.Cid()) + } + return out +} + func (tu *syncTestUtil) addSourceNode(gen int) { if tu.genesis != nil { tu.t.Fatal("source node already exists") @@ -215,27 +237,11 @@ func TestSyncMining(t *testing.T) { tu.compareSourceState(client) - fblk, err := tu.g.NextBlock() - require.NoError(t, err) - - for _, msg := range fblk.Messages { - require.NoError(t, tu.nds[0].MpoolPush(context.TODO(), msg)) + for i := 0; i < 5; i++ { + tu.mineNewBlock(0) + time.Sleep(time.Second / 2) + tu.compareSourceState(client) } - - require.NoError(t, tu.nds[0].ChainSubmitBlock(context.TODO(), fblkToBlkMsg(fblk))) - - time.Sleep(time.Second) -} - -func fblkToBlkMsg(fb *types.FullBlock) *chain.BlockMsg { - out := &chain.BlockMsg{ - Header: fb.Header, - } - - for _, msg := range fb.Messages { - out.Messages = append(out.Messages, msg.Cid()) - } - return out } /*