TestGenerateBlockAndImportEthash¶
| Source (upstream pre-purge) | Current | |
|---|---|---|
| File | miner/worker_test.go |
worker_pow_test.go |
| Symbol | TestGenerateBlockAndImportEthash |
TestGenerateBlockAndImportEthash |
| Ref | dde2da0ef~1 |
etc/v1.17.3-full-node |
Revived mining + import end-to-end test (with ethash.NewFaker), plus an uncle-selection test (TestGatherUnclesEthash), built on the shared payload_building_test.go helpers. Tests that depend on machinery not transplanted to the delegating worker (pre-seal empty block, getSealingBlock, resubmit feedback) are intentionally not revived.
3-way merge — purge → getc ← upstream¶
pre-purgefork-only
↗func TestGenerateBlockAndImportEthash(t *testing.T) {
var (
engine = ethash.NewFaker()
db = rawdb.NewMemoryDatabase()
)
w, b := newTestPowWorker(t, ethashChainConfig, engine, db, 0)
defer w.close()
// This test chain imports the mined blocks.
chain, _ := core.NewBlockChain(rawdb.NewMemoryDatabase(), b.genesis, engine, &core.BlockChainConfig{ArchiveMode: true})
defer chain.Stop()
// Ignore empty commits here for less noise.
w.skipSealHook = func(task *task) bool {
return len(task.receipts) == 0
}
// Wait for mined blocks.
sub := w.mux.Subscribe(core.NewMinedBlockEvent{})
defer sub.Unsubscribe()
// Start mining!
w.start()
for i := 0; i < 5; i++ {
b.txPool.Add([]*types.Transaction{b.newRandomTx(true)}, true)
b.txPool.Add([]*types.Transaction{b.newRandomTx(false)}, true)
select {
case ev := <-sub.Chan():
block := ev.Data.(core.NewMinedBlockEvent).Block
if _, err := chain.InsertChain([]*types.Block{block}); err != nil {
t.Fatalf("failed to insert new mined block %d: %v", block.NumberU64(), err)
}
case <-time.After(3 * time.Second): // Worker needs 1s to include new changes.
t.Fatalf("timeout")
}
}
↗}
core-geth validation — +37 -1
| | | |---|---| | File | [`worker_test.go`](https://github.com/etclabscore/core-geth/blob/v1.12.20/miner/worker_test.go) | | Symbol | `TestGenerateBlockAndImportEthash` | | Ref | `v1.12.20` |--- a/core-geth/miner/worker_test.go
+++ b/etc/miner/worker_pow_test.go
@@ -1,3 +1,39 @@
func TestGenerateBlockAndImportEthash(t *testing.T) {
- testGenerateBlockAndImport(t, false)
+ var (
+ engine = ethash.NewFaker()
+ db = rawdb.NewMemoryDatabase()
+ )
+ w, b := newTestPowWorker(t, ethashChainConfig, engine, db, 0)
+ defer w.close()
+
+ // This test chain imports the mined blocks.
+ chain, _ := core.NewBlockChain(rawdb.NewMemoryDatabase(), b.genesis, engine, &core.BlockChainConfig{ArchiveMode: true})
+ defer chain.Stop()
+
+ // Ignore empty commits here for less noise.
+ w.skipSealHook = func(task *task) bool {
+ return len(task.receipts) == 0
+ }
+
+ // Wait for mined blocks.
+ sub := w.mux.Subscribe(core.NewMinedBlockEvent{})
+ defer sub.Unsubscribe()
+
+ // Start mining!
+ w.start()
+
+ for i := 0; i < 5; i++ {
+ b.txPool.Add([]*types.Transaction{b.newRandomTx(true)}, true)
+ b.txPool.Add([]*types.Transaction{b.newRandomTx(false)}, true)
+
+ select {
+ case ev := <-sub.Chan():
+ block := ev.Data.(core.NewMinedBlockEvent).Block
+ if _, err := chain.InsertChain([]*types.Block{block}); err != nil {
+ t.Fatalf("failed to insert new mined block %d: %v", block.NumberU64(), err)
+ }
+ case <-time.After(3 * time.Second): // Worker needs 1s to include new changes.
+ t.Fatalf("timeout")
+ }
+ }
}