core: fixed tests
This commit is contained in:
parent
59c0d01418
commit
40717465bc
|
@ -14,7 +14,7 @@ func proc() (*BlockProcessor, *ChainManager) {
|
||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
var mux event.TypeMux
|
var mux event.TypeMux
|
||||||
|
|
||||||
chainMan := NewChainManager(db, db, &mux)
|
chainMan := NewChainManager(db, db, thePow(), &mux)
|
||||||
return NewBlockProcessor(db, db, ezp.New(), nil, chainMan, &mux), chainMan
|
return NewBlockProcessor(db, db, ezp.New(), nil, chainMan, &mux), chainMan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,13 +24,13 @@ func TestNumber(t *testing.T) {
|
||||||
block1.Header().Number = big.NewInt(3)
|
block1.Header().Number = big.NewInt(3)
|
||||||
block1.Header().Time--
|
block1.Header().Time--
|
||||||
|
|
||||||
err := bp.ValidateHeader(block1.Header(), chain.Genesis().Header())
|
err := bp.ValidateHeader(block1.Header(), chain.Genesis().Header(), false)
|
||||||
if err != BlockNumberErr {
|
if err != BlockNumberErr {
|
||||||
t.Errorf("expected block number error %v", err)
|
t.Errorf("expected block number error %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
block1 = chain.NewBlock(common.Address{})
|
block1 = chain.NewBlock(common.Address{})
|
||||||
err = bp.ValidateHeader(block1.Header(), chain.Genesis().Header())
|
err = bp.ValidateHeader(block1.Header(), chain.Genesis().Header(), false)
|
||||||
if err == BlockNumberErr {
|
if err == BlockNumberErr {
|
||||||
t.Errorf("didn't expect block number error")
|
t.Errorf("didn't expect block number error")
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ func makeChain(bman *BlockProcessor, parent *types.Block, max int, db common.Dat
|
||||||
// Effectively a fork factory
|
// Effectively a fork factory
|
||||||
func newChainManager(block *types.Block, eventMux *event.TypeMux, db common.Database) *ChainManager {
|
func newChainManager(block *types.Block, eventMux *event.TypeMux, db common.Database) *ChainManager {
|
||||||
genesis := GenesisBlock(db)
|
genesis := GenesisBlock(db)
|
||||||
bc := &ChainManager{blockDb: db, stateDb: db, genesisBlock: genesis, eventMux: eventMux}
|
bc := &ChainManager{blockDb: db, stateDb: db, genesisBlock: genesis, eventMux: eventMux, pow: FakePow{}}
|
||||||
bc.txState = state.ManageState(state.New(genesis.Root(), db))
|
bc.txState = state.ManageState(state.New(genesis.Root(), db))
|
||||||
bc.futureBlocks = NewBlockCache(1000)
|
bc.futureBlocks = NewBlockCache(1000)
|
||||||
if block == nil {
|
if block == nil {
|
||||||
|
|
|
@ -9,11 +9,13 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/ethereum/ethash"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,6 +23,11 @@ func init() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func thePow() pow.PoW {
|
||||||
|
pow, _ := ethash.NewForTesting()
|
||||||
|
return pow
|
||||||
|
}
|
||||||
|
|
||||||
// Test fork of length N starting from block i
|
// Test fork of length N starting from block i
|
||||||
func testFork(t *testing.T, bman *BlockProcessor, i, N int, f func(td1, td2 *big.Int)) {
|
func testFork(t *testing.T, bman *BlockProcessor, i, N int, f func(td1, td2 *big.Int)) {
|
||||||
// switch databases to process the new chain
|
// switch databases to process the new chain
|
||||||
|
@ -259,7 +266,7 @@ func TestChainInsertions(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var eventMux event.TypeMux
|
var eventMux event.TypeMux
|
||||||
chainMan := NewChainManager(db, db, &eventMux)
|
chainMan := NewChainManager(db, db, thePow(), &eventMux)
|
||||||
txPool := NewTxPool(&eventMux, chainMan.State, func() *big.Int { return big.NewInt(100000000) })
|
txPool := NewTxPool(&eventMux, chainMan.State, func() *big.Int { return big.NewInt(100000000) })
|
||||||
blockMan := NewBlockProcessor(db, db, nil, txPool, chainMan, &eventMux)
|
blockMan := NewBlockProcessor(db, db, nil, txPool, chainMan, &eventMux)
|
||||||
chainMan.SetProcessor(blockMan)
|
chainMan.SetProcessor(blockMan)
|
||||||
|
@ -305,7 +312,7 @@ func TestChainMultipleInsertions(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var eventMux event.TypeMux
|
var eventMux event.TypeMux
|
||||||
chainMan := NewChainManager(db, db, &eventMux)
|
chainMan := NewChainManager(db, db, thePow(), &eventMux)
|
||||||
txPool := NewTxPool(&eventMux, chainMan.State, func() *big.Int { return big.NewInt(100000000) })
|
txPool := NewTxPool(&eventMux, chainMan.State, func() *big.Int { return big.NewInt(100000000) })
|
||||||
blockMan := NewBlockProcessor(db, db, nil, txPool, chainMan, &eventMux)
|
blockMan := NewBlockProcessor(db, db, nil, txPool, chainMan, &eventMux)
|
||||||
chainMan.SetProcessor(blockMan)
|
chainMan.SetProcessor(blockMan)
|
||||||
|
@ -334,7 +341,7 @@ func TestGetAncestors(t *testing.T) {
|
||||||
|
|
||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
var eventMux event.TypeMux
|
var eventMux event.TypeMux
|
||||||
chainMan := NewChainManager(db, db, &eventMux)
|
chainMan := NewChainManager(db, db, thePow(), &eventMux)
|
||||||
chain, err := loadChain("valid1", t)
|
chain, err := loadChain("valid1", t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -372,7 +379,7 @@ func makeChainWithDiff(genesis *types.Block, d []int, seed byte) []*types.Block
|
||||||
|
|
||||||
func chm(genesis *types.Block, db common.Database) *ChainManager {
|
func chm(genesis *types.Block, db common.Database) *ChainManager {
|
||||||
var eventMux event.TypeMux
|
var eventMux event.TypeMux
|
||||||
bc := &ChainManager{blockDb: db, stateDb: db, genesisBlock: genesis, eventMux: &eventMux}
|
bc := &ChainManager{blockDb: db, stateDb: db, genesisBlock: genesis, eventMux: &eventMux, pow: FakePow{}}
|
||||||
bc.cache = NewBlockCache(100)
|
bc.cache = NewBlockCache(100)
|
||||||
bc.futureBlocks = NewBlockCache(100)
|
bc.futureBlocks = NewBlockCache(100)
|
||||||
bc.processor = bproc{}
|
bc.processor = bproc{}
|
||||||
|
|
Loading…
Reference in New Issue