Skip to content

Commit 8df689b

Browse files
committed
Chain tests
1 parent 2f8a45c commit 8df689b

6 files changed

Lines changed: 48 additions & 5 deletions

File tree

‎_data/invalid1‎

35.2 KB
Binary file not shown.
File renamed without changes.
File renamed without changes.

‎_data/valid3‎

14.4 KB
Binary file not shown.

‎_data/valid4‎

12.2 KB
Binary file not shown.

‎core/chain_manager_test.go‎

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@ import (
66
"path"
77
"reflect"
88
"runtime"
9+
"strconv"
910
"testing"
1011

1112
"github.com/ethereum/go-ethereum/core/types"
1213
"github.com/ethereum/go-ethereum/ethdb"
1314
"github.com/ethereum/go-ethereum/ethutil"
1415
"github.com/ethereum/go-ethereum/event"
1516
"github.com/ethereum/go-ethereum/rlp"
16-
//logpkg "github.com/ethereum/go-ethereum/logger"
1717
)
1818

1919
//var Logger logpkg.LogSystem
20+
2021
//var Log = logpkg.NewLogger("TEST")
2122

2223
func init() {
2324
runtime.GOMAXPROCS(runtime.NumCPU())
24-
//Logger = logpkg.NewStdLogSystem(os.Stdout, log.LstdFlags, logpkg.InfoLevel)
25+
//Logger = logpkg.NewStdLogSystem(os.Stdout, log.LstdFlags, logpkg.DebugLevel)
2526
//logpkg.AddLogSystem(Logger)
2627

2728
ethutil.ReadConfig("/tmp/ethtest", "/tmp/ethtest", "ETH")
@@ -50,21 +51,22 @@ func loadChain(fn string, t *testing.T) (types.Blocks, error) {
5051

5152
func insertChain(done chan bool, chainMan *ChainManager, chain types.Blocks, t *testing.T) {
5253
err := chainMan.InsertChain(chain)
54+
done <- true
5355
if err != nil {
5456
fmt.Println(err)
5557
t.FailNow()
5658
}
57-
done <- true
5859
}
5960

6061
func TestChainInsertions(t *testing.T) {
61-
chain1, err := loadChain("chain1", t)
62+
chain1, err := loadChain("valid1", t)
6263
if err != nil {
6364
fmt.Println(err)
6465
t.FailNow()
6566
}
67+
fmt.Println(len(chain1))
6668

67-
chain2, err := loadChain("chain2", t)
69+
chain2, err := loadChain("valid2", t)
6870
if err != nil {
6971
fmt.Println(err)
7072
t.FailNow()
@@ -94,3 +96,44 @@ func TestChainInsertions(t *testing.T) {
9496
t.Error("chain1 isn't canonical and should be")
9597
}
9698
}
99+
100+
func TestChainMultipleInsertions(t *testing.T) {
101+
const max = 4
102+
chains := make([]types.Blocks, max)
103+
var longest int
104+
for i := 0; i < max; i++ {
105+
var err error
106+
name := "valid" + strconv.Itoa(i+1)
107+
chains[i], err = loadChain(name, t)
108+
if len(chains[i]) >= len(chains[longest]) {
109+
longest = i
110+
}
111+
fmt.Println("loaded", name, "with a length of", len(chains[i]))
112+
if err != nil {
113+
fmt.Println(err)
114+
t.FailNow()
115+
}
116+
}
117+
118+
var eventMux event.TypeMux
119+
chainMan := NewChainManager(&eventMux)
120+
txPool := NewTxPool(chainMan, &eventMux)
121+
blockMan := NewBlockManager(txPool, chainMan, &eventMux)
122+
chainMan.SetProcessor(blockMan)
123+
done := make(chan bool, max)
124+
for i, chain := range chains {
125+
var i int = i
126+
go func() {
127+
insertChain(done, chainMan, chain, t)
128+
fmt.Println(i, "done")
129+
}()
130+
}
131+
132+
for i := 0; i < max; i++ {
133+
<-done
134+
}
135+
136+
if !reflect.DeepEqual(chains[longest][len(chains[longest])-1], chainMan.CurrentBlock()) {
137+
t.Error("Invalid canonical chain")
138+
}
139+
}

0 commit comments

Comments
 (0)