aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-x_data/chain1bin175331 -> 18036 bytes
-rwxr-xr-x_data/chain2bin28118 -> 6125 bytes
-rw-r--r--core/chain_manager_test.go47
-rw-r--r--core/helper_test.go6
-rw-r--r--core/types/block.go1
5 files changed, 37 insertions, 17 deletions
diff --git a/_data/chain1 b/_data/chain1
index ef392e001..809a55f1a 100755
--- a/_data/chain1
+++ b/_data/chain1
Binary files differ
diff --git a/_data/chain2 b/_data/chain2
index 48ed4d5ea..3e9d2971a 100755
--- a/_data/chain2
+++ b/_data/chain2
Binary files differ
diff --git a/core/chain_manager_test.go b/core/chain_manager_test.go
index 52be8b0ea..6e85bae9a 100644
--- a/core/chain_manager_test.go
+++ b/core/chain_manager_test.go
@@ -2,7 +2,9 @@ package core
import (
"fmt"
+ "os"
"path"
+ "reflect"
"runtime"
"testing"
@@ -10,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event"
+ "github.com/ethereum/go-ethereum/rlp"
//logpkg "github.com/ethereum/go-ethereum/logger"
)
@@ -30,20 +33,19 @@ func init() {
ethutil.Config.Db = db
}
-func loadChain(fn string, t *testing.T) types.Blocks {
- c1, err := ethutil.ReadAllFile(path.Join("..", "_data", fn))
+func loadChain(fn string, t *testing.T) (types.Blocks, error) {
+ fh, err := os.OpenFile(path.Join("..", "_data", fn), os.O_RDONLY, os.ModePerm)
if err != nil {
- fmt.Println(err)
- t.FailNow()
+ return nil, err
}
- value := ethutil.NewValueFromBytes([]byte(c1))
- blocks := make(types.Blocks, value.Len())
- it := value.NewIterator()
- for it.Next() {
- blocks[it.Idx()] = types.NewBlockFromRlpValue(it.Value())
+ defer fh.Close()
+
+ var chain types.Blocks
+ if err := rlp.Decode(fh, &chain); err != nil {
+ return nil, err
}
- return blocks
+ return chain, nil
}
func insertChain(done chan bool, chainMan *ChainManager, chain types.Blocks, t *testing.T) {
@@ -56,11 +58,21 @@ func insertChain(done chan bool, chainMan *ChainManager, chain types.Blocks, t *
}
func TestChainInsertions(t *testing.T) {
- chain1 := loadChain("chain1", t)
- chain2 := loadChain("chain2", t)
+ chain1, err := loadChain("chain1", t)
+ if err != nil {
+ fmt.Println(err)
+ t.FailNow()
+ }
+
+ chain2, err := loadChain("chain2", t)
+ if err != nil {
+ fmt.Println(err)
+ t.FailNow()
+ }
+
var eventMux event.TypeMux
chainMan := NewChainManager(&eventMux)
- txPool := NewTxPool(chainMan, nil, &eventMux)
+ txPool := NewTxPool(chainMan, &eventMux)
blockMan := NewBlockManager(txPool, chainMan, &eventMux)
chainMan.SetProcessor(blockMan)
@@ -73,5 +85,12 @@ func TestChainInsertions(t *testing.T) {
for i := 0; i < max; i++ {
<-done
}
- fmt.Println(chainMan.CurrentBlock())
+
+ if reflect.DeepEqual(chain2[len(chain2)-1], chainMan.CurrentBlock()) {
+ t.Error("chain2 is canonical and shouldn't be")
+ }
+
+ if !reflect.DeepEqual(chain1[len(chain1)-1], chainMan.CurrentBlock()) {
+ t.Error("chain1 isn't canonical and should be")
+ }
}
diff --git a/core/helper_test.go b/core/helper_test.go
index b340144fd..b8bf254d7 100644
--- a/core/helper_test.go
+++ b/core/helper_test.go
@@ -9,7 +9,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event"
- "github.com/ethereum/go-ethereum/wire"
+ "github.com/ethereum/go-ethereum/p2p"
)
// Implement our EthTest Manager
@@ -54,11 +54,11 @@ func (tm *TestManager) TxPool() *TxPool {
func (tm *TestManager) EventMux() *event.TypeMux {
return tm.eventMux
}
-func (tm *TestManager) Broadcast(msgType wire.MsgType, data []interface{}) {
+func (tm *TestManager) Broadcast(msgType p2p.Msg, data []interface{}) {
fmt.Println("Broadcast not implemented")
}
-func (tm *TestManager) ClientIdentity() wire.ClientIdentity {
+func (tm *TestManager) ClientIdentity() p2p.ClientIdentity {
return nil
}
func (tm *TestManager) KeyManager() *crypto.KeyManager {
diff --git a/core/types/block.go b/core/types/block.go
index 054767d67..7b4695f73 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -199,6 +199,7 @@ func (self *Block) Hash() []byte { return self.header.Hash() }
func (self *Block) Trie() *ptrie.Trie { return ptrie.New(self.header.Root, ethutil.Config.Db) }
func (self *Block) State() *state.StateDB { return state.New(self.Trie()) }
func (self *Block) Size() ethutil.StorageSize { return ethutil.StorageSize(len(ethutil.Encode(self))) }
+func (self *Block) SetRoot(root []byte) { self.header.Root = root }
// Implement block.Pow
func (self *Block) Difficulty() *big.Int { return self.header.Difficulty }