good morning!!!!

Skip to content
Snippets Groups Projects
Commit 06c9d5cc authored by Ferran Borreguero's avatar Ferran Borreguero
Browse files

Test each event without for loop

parent 6ab75158
No related branches found
No related tags found
No related merge requests found
package core
import (
"fmt"
"math/big"
"testing"
"time"
......@@ -30,6 +31,9 @@ func TestChain2HeadEvent(t *testing.T) {
blockchain, _ := NewBlockChain(db, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil)
defer blockchain.Stop()
chain2HeadCh := make(chan Chain2HeadEvent, 64)
blockchain.SubscribeChain2HeadEvent(chain2HeadCh)
chain, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 3, func(i int, gen *BlockGen) {})
if _, err := blockchain.InsertChain(chain); err != nil {
t.Fatalf("failed to insert chain: %v", err)
......@@ -45,12 +49,42 @@ func TestChain2HeadEvent(t *testing.T) {
}
gen.AddTx(tx)
})
chain2HeadCh := make(chan Chain2HeadEvent, 64)
blockchain.SubscribeChain2HeadEvent(chain2HeadCh)
if _, err := blockchain.InsertChain(replacementBlocks); err != nil {
t.Fatalf("failed to insert chain: %v", err)
}
readEvent := func() *Chain2HeadEvent {
select {
case evnt := <-chain2HeadCh:
return &evnt
case <-time.After(2 * time.Second):
t.Fatal("timeout")
}
return nil
}
// head event
evnt := readEvent()
fmt.Println(evnt.Type)
// fork event
evnt = readEvent()
fmt.Println(evnt.Type)
// fork event
evnt = readEvent()
fmt.Println(evnt.Type)
// reorg event
evnt = readEvent()
fmt.Println(evnt.Type)
// head event
evnt = readEvent()
fmt.Println(evnt.Type)
return
// first two block of the secondary chain are for a brief moment considered
// side chains because up to that point the first one is considered the
// heavier chain.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment