aboutsummaryrefslogtreecommitdiffstats
path: root/consensus/ethash/ethash_test.go
diff options
context:
space:
mode:
authorgary rong <garyrong0905@gmail.com>2018-08-28 21:59:05 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-08-28 21:59:05 +0800
commitc1c003e4ff36c22d67662ca661fc78cde850d401 (patch)
treeb8bea54350fb6894cfd63ebc87a164acc3fba7e6 /consensus/ethash/ethash_test.go
parent63352bf4247f05d8ef255ff8c63290225c3bc671 (diff)
downloaddexon-c1c003e4ff36c22d67662ca661fc78cde850d401.tar
dexon-c1c003e4ff36c22d67662ca661fc78cde850d401.tar.gz
dexon-c1c003e4ff36c22d67662ca661fc78cde850d401.tar.bz2
dexon-c1c003e4ff36c22d67662ca661fc78cde850d401.tar.lz
dexon-c1c003e4ff36c22d67662ca661fc78cde850d401.tar.xz
dexon-c1c003e4ff36c22d67662ca661fc78cde850d401.tar.zst
dexon-c1c003e4ff36c22d67662ca661fc78cde850d401.zip
consensus, miner: stale block mining support (#17506)
* consensus, miner: stale block supporting * consensus, miner: refactor seal signature * cmd, consensus, eth: add miner noverify flag * cmd, consensus, miner: polish
Diffstat (limited to 'consensus/ethash/ethash_test.go')
-rw-r--r--consensus/ethash/ethash_test.go40
1 files changed, 19 insertions, 21 deletions
diff --git a/consensus/ethash/ethash_test.go b/consensus/ethash/ethash_test.go
index b190d63d6..8eded2ca8 100644
--- a/consensus/ethash/ethash_test.go
+++ b/consensus/ethash/ethash_test.go
@@ -34,17 +34,23 @@ import (
func TestTestMode(t *testing.T) {
header := &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(100)}
- ethash := NewTester(nil)
+ ethash := NewTester(nil, false)
defer ethash.Close()
- block, err := ethash.Seal(nil, types.NewBlockWithHeader(header), nil)
+ results := make(chan *types.Block)
+ err := ethash.Seal(nil, types.NewBlockWithHeader(header), results, nil)
if err != nil {
t.Fatalf("failed to seal block: %v", err)
}
- header.Nonce = types.EncodeNonce(block.Nonce())
- header.MixDigest = block.MixDigest()
- if err := ethash.VerifySeal(nil, header); err != nil {
- t.Fatalf("unexpected verification error: %v", err)
+ select {
+ case block := <-results:
+ header.Nonce = types.EncodeNonce(block.Nonce())
+ header.MixDigest = block.MixDigest()
+ if err := ethash.VerifySeal(nil, header); err != nil {
+ t.Fatalf("unexpected verification error: %v", err)
+ }
+ case <-time.NewTimer(time.Second).C:
+ t.Error("sealing result timeout")
}
}
@@ -56,7 +62,7 @@ func TestCacheFileEvict(t *testing.T) {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
- e := New(Config{CachesInMem: 3, CachesOnDisk: 10, CacheDir: tmpdir, PowMode: ModeTest}, nil)
+ e := New(Config{CachesInMem: 3, CachesOnDisk: 10, CacheDir: tmpdir, PowMode: ModeTest}, nil, false)
defer e.Close()
workers := 8
@@ -85,7 +91,7 @@ func verifyTest(wg *sync.WaitGroup, e *Ethash, workerIndex, epochs int) {
}
func TestRemoteSealer(t *testing.T) {
- ethash := NewTester(nil)
+ ethash := NewTester(nil, false)
defer ethash.Close()
api := &API{ethash}
@@ -97,7 +103,8 @@ func TestRemoteSealer(t *testing.T) {
sealhash := ethash.SealHash(header)
// Push new work.
- ethash.Seal(nil, block, nil)
+ results := make(chan *types.Block)
+ ethash.Seal(nil, block, results, nil)
var (
work [3]string
@@ -114,20 +121,11 @@ func TestRemoteSealer(t *testing.T) {
header = &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(1000)}
block = types.NewBlockWithHeader(header)
sealhash = ethash.SealHash(header)
- ethash.Seal(nil, block, nil)
+ ethash.Seal(nil, block, results, nil)
if work, err = api.GetWork(); err != nil || work[0] != sealhash.Hex() {
t.Error("expect to return the latest pushed work")
}
- // Push block with higher block number.
- newHead := &types.Header{Number: big.NewInt(2), Difficulty: big.NewInt(100)}
- newBlock := types.NewBlockWithHeader(newHead)
- newSealhash := ethash.SealHash(newHead)
- ethash.Seal(nil, newBlock, nil)
-
- if res := api.SubmitWork(types.BlockNonce{}, newSealhash, common.Hash{}); res {
- t.Error("expect to return false when submit a stale solution")
- }
}
func TestHashRate(t *testing.T) {
@@ -136,7 +134,7 @@ func TestHashRate(t *testing.T) {
expect uint64
ids = []common.Hash{common.HexToHash("a"), common.HexToHash("b"), common.HexToHash("c")}
)
- ethash := NewTester(nil)
+ ethash := NewTester(nil, false)
defer ethash.Close()
if tot := ethash.Hashrate(); tot != 0 {
@@ -156,7 +154,7 @@ func TestHashRate(t *testing.T) {
}
func TestClosedRemoteSealer(t *testing.T) {
- ethash := NewTester(nil)
+ ethash := NewTester(nil, false)
time.Sleep(1 * time.Second) // ensure exit channel is listening
ethash.Close()