|
|
@@ -215,12 +215,16 @@ func testGenerateBlockAndImport(t *testing.T, isClique bool) {
|
|
|
chain, _ := core.NewBlockChain(db2, nil, b.chain.Config(), engine, vm.Config{}, nil)
|
|
|
defer chain.Stop()
|
|
|
|
|
|
- loopErr := make(chan error)
|
|
|
- newBlock := make(chan struct{})
|
|
|
+ var (
|
|
|
+ loopErr = make(chan error)
|
|
|
+ newBlock = make(chan struct{})
|
|
|
+ subscribe = make(chan struct{})
|
|
|
+ )
|
|
|
listenNewBlock := func() {
|
|
|
sub := w.mux.Subscribe(core.NewMinedBlockEvent{})
|
|
|
defer sub.Unsubscribe()
|
|
|
|
|
|
+ subscribe <- struct{}{}
|
|
|
for item := range sub.Chan() {
|
|
|
block := item.Data.(core.NewMinedBlockEvent).Block
|
|
|
_, err := chain.InsertChain([]*types.Block{block})
|
|
|
@@ -234,9 +238,11 @@ func testGenerateBlockAndImport(t *testing.T, isClique bool) {
|
|
|
w.skipSealHook = func(task *task) bool {
|
|
|
return len(task.receipts) == 0
|
|
|
}
|
|
|
- w.start() // Start mining!
|
|
|
go listenNewBlock()
|
|
|
|
|
|
+ <-subscribe // Ensure the subscription is created
|
|
|
+ w.start() // Start mining!
|
|
|
+
|
|
|
for i := 0; i < 5; i++ {
|
|
|
b.txPool.AddLocal(b.newRandomTx(true))
|
|
|
b.txPool.AddLocal(b.newRandomTx(false))
|