make 'mineNewBlock' testhelper

This commit is contained in:
whyrusleeping 2019-08-02 16:14:58 -07:00
parent b35b801bfa
commit 280dac7945

View File

@ -83,6 +83,28 @@ func prepSyncTest(t *testing.T, h int) *syncTestUtil {
return tu 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) { func (tu *syncTestUtil) addSourceNode(gen int) {
if tu.genesis != nil { if tu.genesis != nil {
tu.t.Fatal("source node already exists") tu.t.Fatal("source node already exists")
@ -215,27 +237,11 @@ func TestSyncMining(t *testing.T) {
tu.compareSourceState(client) tu.compareSourceState(client)
fblk, err := tu.g.NextBlock() for i := 0; i < 5; i++ {
require.NoError(t, err) tu.mineNewBlock(0)
time.Sleep(time.Second / 2)
for _, msg := range fblk.Messages { tu.compareSourceState(client)
require.NoError(t, tu.nds[0].MpoolPush(context.TODO(), msg))
} }
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
} }
/* /*