aboutsummaryrefslogtreecommitdiffstats
path: root/consensus/ethash/ethash_test.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-08-08 17:15:08 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-08-10 14:06:59 +0800
commitf0998415ba9a73f0add32f9b5aed2aec98b9a7f3 (patch)
treef85ad72f6213fc953b3174378d7c7443cc1d1dd5 /consensus/ethash/ethash_test.go
parent00e6da9704b2cd7ddcc1cd31ed3f6bbaa8e1e284 (diff)
downloadgo-tangerine-f0998415ba9a73f0add32f9b5aed2aec98b9a7f3.tar
go-tangerine-f0998415ba9a73f0add32f9b5aed2aec98b9a7f3.tar.gz
go-tangerine-f0998415ba9a73f0add32f9b5aed2aec98b9a7f3.tar.bz2
go-tangerine-f0998415ba9a73f0add32f9b5aed2aec98b9a7f3.tar.lz
go-tangerine-f0998415ba9a73f0add32f9b5aed2aec98b9a7f3.tar.xz
go-tangerine-f0998415ba9a73f0add32f9b5aed2aec98b9a7f3.tar.zst
go-tangerine-f0998415ba9a73f0add32f9b5aed2aec98b9a7f3.zip
cmd, consensus/ethash, eth: miner push notifications
Diffstat (limited to 'consensus/ethash/ethash_test.go')
-rw-r--r--consensus/ethash/ethash_test.go43
1 files changed, 20 insertions, 23 deletions
diff --git a/consensus/ethash/ethash_test.go b/consensus/ethash/ethash_test.go
index ccdd30fb0..87ac17c2b 100644
--- a/consensus/ethash/ethash_test.go
+++ b/consensus/ethash/ethash_test.go
@@ -32,17 +32,18 @@ import (
// Tests that ethash works correctly in test mode.
func TestTestMode(t *testing.T) {
- head := &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(100)}
+ header := &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(100)}
- ethash := NewTester()
+ ethash := NewTester(nil)
defer ethash.Close()
- block, err := ethash.Seal(nil, types.NewBlockWithHeader(head), nil)
+
+ block, err := ethash.Seal(nil, types.NewBlockWithHeader(header), nil)
if err != nil {
t.Fatalf("failed to seal block: %v", err)
}
- head.Nonce = types.EncodeNonce(block.Nonce())
- head.MixDigest = block.MixDigest()
- if err := ethash.VerifySeal(nil, head); err != nil {
+ 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)
}
}
@@ -55,7 +56,7 @@ func TestCacheFileEvict(t *testing.T) {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
- e := New(Config{CachesInMem: 3, CachesOnDisk: 10, CacheDir: tmpdir, PowMode: ModeTest})
+ e := New(Config{CachesInMem: 3, CachesOnDisk: 10, CacheDir: tmpdir, PowMode: ModeTest}, nil)
defer e.Close()
workers := 8
@@ -78,21 +79,21 @@ func verifyTest(wg *sync.WaitGroup, e *Ethash, workerIndex, epochs int) {
if block < 0 {
block = 0
}
- head := &types.Header{Number: big.NewInt(block), Difficulty: big.NewInt(100)}
- e.VerifySeal(nil, head)
+ header := &types.Header{Number: big.NewInt(block), Difficulty: big.NewInt(100)}
+ e.VerifySeal(nil, header)
}
}
func TestRemoteSealer(t *testing.T) {
- ethash := NewTester()
+ ethash := NewTester(nil)
defer ethash.Close()
+
api := &API{ethash}
if _, err := api.GetWork(); err != errNoMiningWork {
t.Error("expect to return an error indicate there is no mining work")
}
-
- head := &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(100)}
- block := types.NewBlockWithHeader(head)
+ header := &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(100)}
+ block := types.NewBlockWithHeader(header)
// Push new work.
ethash.Seal(nil, block, nil)
@@ -108,16 +109,14 @@ func TestRemoteSealer(t *testing.T) {
if res := api.SubmitWork(types.BlockNonce{}, block.HashNoNonce(), common.Hash{}); res {
t.Error("expect to return false when submit a fake solution")
}
-
// Push new block with same block number to replace the original one.
- head = &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(1000)}
- block = types.NewBlockWithHeader(head)
+ header = &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(1000)}
+ block = types.NewBlockWithHeader(header)
ethash.Seal(nil, block, nil)
if work, err = api.GetWork(); err != nil || work[0] != block.HashNoNonce().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)
@@ -130,19 +129,18 @@ func TestRemoteSealer(t *testing.T) {
func TestHashRate(t *testing.T) {
var (
- ethash = NewTester()
- api = &API{ethash}
hashrate = []hexutil.Uint64{100, 200, 300}
expect uint64
ids = []common.Hash{common.HexToHash("a"), common.HexToHash("b"), common.HexToHash("c")}
)
-
+ ethash := NewTester(nil)
defer ethash.Close()
if tot := ethash.Hashrate(); tot != 0 {
t.Error("expect the result should be zero")
}
+ api := &API{ethash}
for i := 0; i < len(hashrate); i += 1 {
if res := api.SubmitHashRate(hashrate[i], ids[i]); !res {
t.Error("remote miner submit hashrate failed")
@@ -155,9 +153,8 @@ func TestHashRate(t *testing.T) {
}
func TestClosedRemoteSealer(t *testing.T) {
- ethash := NewTester()
- // Make sure exit channel has been listened
- time.Sleep(1 * time.Second)
+ ethash := NewTester(nil)
+ time.Sleep(1 * time.Second) // ensure exit channel is listening
ethash.Close()
api := &API{ethash}