aboutsummaryrefslogtreecommitdiffstats
path: root/miner/worker_test.go
diff options
context:
space:
mode:
authorgary rong <garyrong0905@gmail.com>2018-08-16 19:14:33 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-08-16 19:14:33 +0800
commit54216811a05a78c6aef4d9f5d401eeb0ebac6a84 (patch)
treec6e13e48b88cd4baffc60ee752b2715c68720a34 /miner/worker_test.go
parent5952d962dc6852fe62f0d363317dae2f224063bd (diff)
downloaddexon-54216811a05a78c6aef4d9f5d401eeb0ebac6a84.tar
dexon-54216811a05a78c6aef4d9f5d401eeb0ebac6a84.tar.gz
dexon-54216811a05a78c6aef4d9f5d401eeb0ebac6a84.tar.bz2
dexon-54216811a05a78c6aef4d9f5d401eeb0ebac6a84.tar.lz
dexon-54216811a05a78c6aef4d9f5d401eeb0ebac6a84.tar.xz
dexon-54216811a05a78c6aef4d9f5d401eeb0ebac6a84.tar.zst
dexon-54216811a05a78c6aef4d9f5d401eeb0ebac6a84.zip
miner: regenerate mining work every 3 seconds (#17413)
* miner: regenerate mining work every 3 seconds * miner: polish
Diffstat (limited to 'miner/worker_test.go')
-rw-r--r--miner/worker_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/miner/worker_test.go b/miner/worker_test.go
index 408c47e3b..34bb7f5f3 100644
--- a/miner/worker_test.go
+++ b/miner/worker_test.go
@@ -270,3 +270,68 @@ func TestStreamUncleBlock(t *testing.T) {
t.Error("new task timeout")
}
}
+
+func TestRegenerateMiningBlockEthash(t *testing.T) {
+ testRegenerateMiningBlock(t, ethashChainConfig, ethash.NewFaker())
+}
+
+func TestRegenerateMiningBlockClique(t *testing.T) {
+ testRegenerateMiningBlock(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, ethdb.NewMemDatabase()))
+}
+
+func testRegenerateMiningBlock(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) {
+ defer engine.Close()
+
+ w, b := newTestWorker(t, chainConfig, engine)
+ defer w.close()
+
+ var taskCh = make(chan struct{})
+
+ taskIndex := 0
+ w.newTaskHook = func(task *task) {
+ if task.block.NumberU64() == 1 {
+ if taskIndex == 2 {
+ receiptLen, balance := 2, big.NewInt(2000)
+ if len(task.receipts) != receiptLen {
+ t.Errorf("receipt number mismatch has %d, want %d", len(task.receipts), receiptLen)
+ }
+ if task.state.GetBalance(acc1Addr).Cmp(balance) != 0 {
+ t.Errorf("account balance mismatch has %d, want %d", task.state.GetBalance(acc1Addr), balance)
+ }
+ }
+ taskCh <- struct{}{}
+ taskIndex += 1
+ }
+ }
+ w.skipSealHook = func(task *task) bool {
+ return true
+ }
+ w.fullTaskHook = func() {
+ time.Sleep(100 * time.Millisecond)
+ }
+ // Ensure worker has finished initialization
+ for {
+ b := w.pendingBlock()
+ if b != nil && b.NumberU64() == 1 {
+ break
+ }
+ }
+
+ w.start()
+ // Ignore the first two works
+ for i := 0; i < 2; i += 1 {
+ select {
+ case <-taskCh:
+ case <-time.NewTimer(time.Second).C:
+ t.Error("new task timeout")
+ }
+ }
+ b.txPool.AddLocals(newTxs)
+ time.Sleep(3 * time.Second)
+
+ select {
+ case <-taskCh:
+ case <-time.NewTimer(time.Second).C:
+ t.Error("new task timeout")
+ }
+}