|
|
@ -80,7 +80,8 @@ func (bc *testBlockChain) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestMiner(t *testing.T) { |
|
|
|
func TestMiner(t *testing.T) { |
|
|
|
miner, mux := createMiner(t) |
|
|
|
miner, mux, cleanup := createMiner(t) |
|
|
|
|
|
|
|
defer cleanup(false) |
|
|
|
miner.Start(common.HexToAddress("0x12345")) |
|
|
|
miner.Start(common.HexToAddress("0x12345")) |
|
|
|
waitForMiningState(t, miner, true) |
|
|
|
waitForMiningState(t, miner, true) |
|
|
|
// Start the downloader
|
|
|
|
// Start the downloader
|
|
|
@ -107,7 +108,8 @@ func TestMiner(t *testing.T) { |
|
|
|
// An initial FailedEvent should allow mining to stop on a subsequent
|
|
|
|
// An initial FailedEvent should allow mining to stop on a subsequent
|
|
|
|
// downloader StartEvent.
|
|
|
|
// downloader StartEvent.
|
|
|
|
func TestMinerDownloaderFirstFails(t *testing.T) { |
|
|
|
func TestMinerDownloaderFirstFails(t *testing.T) { |
|
|
|
miner, mux := createMiner(t) |
|
|
|
miner, mux, cleanup := createMiner(t) |
|
|
|
|
|
|
|
defer cleanup(false) |
|
|
|
miner.Start(common.HexToAddress("0x12345")) |
|
|
|
miner.Start(common.HexToAddress("0x12345")) |
|
|
|
waitForMiningState(t, miner, true) |
|
|
|
waitForMiningState(t, miner, true) |
|
|
|
// Start the downloader
|
|
|
|
// Start the downloader
|
|
|
@ -138,8 +140,8 @@ func TestMinerDownloaderFirstFails(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestMinerStartStopAfterDownloaderEvents(t *testing.T) { |
|
|
|
func TestMinerStartStopAfterDownloaderEvents(t *testing.T) { |
|
|
|
miner, mux := createMiner(t) |
|
|
|
miner, mux, cleanup := createMiner(t) |
|
|
|
|
|
|
|
defer cleanup(false) |
|
|
|
miner.Start(common.HexToAddress("0x12345")) |
|
|
|
miner.Start(common.HexToAddress("0x12345")) |
|
|
|
waitForMiningState(t, miner, true) |
|
|
|
waitForMiningState(t, miner, true) |
|
|
|
// Start the downloader
|
|
|
|
// Start the downloader
|
|
|
@ -161,7 +163,8 @@ func TestMinerStartStopAfterDownloaderEvents(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestStartWhileDownload(t *testing.T) { |
|
|
|
func TestStartWhileDownload(t *testing.T) { |
|
|
|
miner, mux := createMiner(t) |
|
|
|
miner, mux, cleanup := createMiner(t) |
|
|
|
|
|
|
|
defer cleanup(false) |
|
|
|
waitForMiningState(t, miner, false) |
|
|
|
waitForMiningState(t, miner, false) |
|
|
|
miner.Start(common.HexToAddress("0x12345")) |
|
|
|
miner.Start(common.HexToAddress("0x12345")) |
|
|
|
waitForMiningState(t, miner, true) |
|
|
|
waitForMiningState(t, miner, true) |
|
|
@ -174,16 +177,19 @@ func TestStartWhileDownload(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestStartStopMiner(t *testing.T) { |
|
|
|
func TestStartStopMiner(t *testing.T) { |
|
|
|
miner, _ := createMiner(t) |
|
|
|
miner, _, cleanup := createMiner(t) |
|
|
|
|
|
|
|
defer cleanup(false) |
|
|
|
waitForMiningState(t, miner, false) |
|
|
|
waitForMiningState(t, miner, false) |
|
|
|
miner.Start(common.HexToAddress("0x12345")) |
|
|
|
miner.Start(common.HexToAddress("0x12345")) |
|
|
|
waitForMiningState(t, miner, true) |
|
|
|
waitForMiningState(t, miner, true) |
|
|
|
miner.Stop() |
|
|
|
miner.Stop() |
|
|
|
waitForMiningState(t, miner, false) |
|
|
|
waitForMiningState(t, miner, false) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestCloseMiner(t *testing.T) { |
|
|
|
func TestCloseMiner(t *testing.T) { |
|
|
|
miner, _ := createMiner(t) |
|
|
|
miner, _, cleanup := createMiner(t) |
|
|
|
|
|
|
|
defer cleanup(true) |
|
|
|
waitForMiningState(t, miner, false) |
|
|
|
waitForMiningState(t, miner, false) |
|
|
|
miner.Start(common.HexToAddress("0x12345")) |
|
|
|
miner.Start(common.HexToAddress("0x12345")) |
|
|
|
waitForMiningState(t, miner, true) |
|
|
|
waitForMiningState(t, miner, true) |
|
|
@ -195,7 +201,8 @@ func TestCloseMiner(t *testing.T) { |
|
|
|
// TestMinerSetEtherbase checks that etherbase becomes set even if mining isn't
|
|
|
|
// TestMinerSetEtherbase checks that etherbase becomes set even if mining isn't
|
|
|
|
// possible at the moment
|
|
|
|
// possible at the moment
|
|
|
|
func TestMinerSetEtherbase(t *testing.T) { |
|
|
|
func TestMinerSetEtherbase(t *testing.T) { |
|
|
|
miner, mux := createMiner(t) |
|
|
|
miner, mux, cleanup := createMiner(t) |
|
|
|
|
|
|
|
defer cleanup(false) |
|
|
|
// Start with a 'bad' mining address
|
|
|
|
// Start with a 'bad' mining address
|
|
|
|
miner.Start(common.HexToAddress("0xdead")) |
|
|
|
miner.Start(common.HexToAddress("0xdead")) |
|
|
|
waitForMiningState(t, miner, true) |
|
|
|
waitForMiningState(t, miner, true) |
|
|
@ -230,7 +237,7 @@ func waitForMiningState(t *testing.T, m *Miner, mining bool) { |
|
|
|
t.Fatalf("Mining() == %t, want %t", state, mining) |
|
|
|
t.Fatalf("Mining() == %t, want %t", state, mining) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func createMiner(t *testing.T) (*Miner, *event.TypeMux) { |
|
|
|
func createMiner(t *testing.T) (*Miner, *event.TypeMux, func(skipMiner bool)) { |
|
|
|
// Create Ethash config
|
|
|
|
// Create Ethash config
|
|
|
|
config := Config{ |
|
|
|
config := Config{ |
|
|
|
Etherbase: common.HexToAddress("123456789"), |
|
|
|
Etherbase: common.HexToAddress("123456789"), |
|
|
@ -259,5 +266,14 @@ func createMiner(t *testing.T) (*Miner, *event.TypeMux) { |
|
|
|
// Create event Mux
|
|
|
|
// Create event Mux
|
|
|
|
mux := new(event.TypeMux) |
|
|
|
mux := new(event.TypeMux) |
|
|
|
// Create Miner
|
|
|
|
// Create Miner
|
|
|
|
return New(backend, &config, chainConfig, mux, engine, nil, merger), mux |
|
|
|
miner := New(backend, &config, chainConfig, mux, engine, nil, merger) |
|
|
|
|
|
|
|
cleanup := func(skipMiner bool) { |
|
|
|
|
|
|
|
bc.Stop() |
|
|
|
|
|
|
|
engine.Close() |
|
|
|
|
|
|
|
pool.Stop() |
|
|
|
|
|
|
|
if !skipMiner { |
|
|
|
|
|
|
|
miner.Close() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return miner, mux, cleanup |
|
|
|
} |
|
|
|
} |
|
|
|