|
|
|
@ -9,11 +9,13 @@ import ( |
|
|
|
|
"strconv" |
|
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
"github.com/ethereum/ethash" |
|
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
|
"github.com/ethereum/go-ethereum/core/state" |
|
|
|
|
"github.com/ethereum/go-ethereum/core/types" |
|
|
|
|
"github.com/ethereum/go-ethereum/ethdb" |
|
|
|
|
"github.com/ethereum/go-ethereum/event" |
|
|
|
|
"github.com/ethereum/go-ethereum/pow" |
|
|
|
|
"github.com/ethereum/go-ethereum/rlp" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -21,6 +23,11 @@ func init() { |
|
|
|
|
runtime.GOMAXPROCS(runtime.NumCPU()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func thePow() pow.PoW { |
|
|
|
|
pow, _ := ethash.NewForTesting() |
|
|
|
|
return pow |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 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)) { |
|
|
|
|
// switch databases to process the new chain
|
|
|
|
@ -259,7 +266,7 @@ func TestChainInsertions(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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) }) |
|
|
|
|
blockMan := NewBlockProcessor(db, db, nil, txPool, chainMan, &eventMux) |
|
|
|
|
chainMan.SetProcessor(blockMan) |
|
|
|
@ -305,7 +312,7 @@ func TestChainMultipleInsertions(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
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) }) |
|
|
|
|
blockMan := NewBlockProcessor(db, db, nil, txPool, chainMan, &eventMux) |
|
|
|
|
chainMan.SetProcessor(blockMan) |
|
|
|
@ -334,7 +341,7 @@ func TestGetAncestors(t *testing.T) { |
|
|
|
|
|
|
|
|
|
db, _ := ethdb.NewMemDatabase() |
|
|
|
|
var eventMux event.TypeMux |
|
|
|
|
chainMan := NewChainManager(db, db, &eventMux) |
|
|
|
|
chainMan := NewChainManager(db, db, thePow(), &eventMux) |
|
|
|
|
chain, err := loadChain("valid1", t) |
|
|
|
|
if err != nil { |
|
|
|
|
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 { |
|
|
|
|
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.futureBlocks = NewBlockCache(100) |
|
|
|
|
bc.processor = bproc{} |
|
|
|
|