|
@@ -32,17 +32,18 @@ import (
|
|
|
|
|
|
|
|
// Tests that ethash works correctly in test mode.
|
|
// Tests that ethash works correctly in test mode.
|
|
|
func TestTestMode(t *testing.T) {
|
|
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()
|
|
defer ethash.Close()
|
|
|
- block, err := ethash.Seal(nil, types.NewBlockWithHeader(head), nil)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ block, err := ethash.Seal(nil, types.NewBlockWithHeader(header), nil)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("failed to seal block: %v", err)
|
|
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)
|
|
t.Fatalf("unexpected verification error: %v", err)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -55,7 +56,7 @@ func TestCacheFileEvict(t *testing.T) {
|
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
|
}
|
|
}
|
|
|
defer os.RemoveAll(tmpdir)
|
|
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()
|
|
defer e.Close()
|
|
|
|
|
|
|
|
workers := 8
|
|
workers := 8
|
|
@@ -78,21 +79,21 @@ func verifyTest(wg *sync.WaitGroup, e *Ethash, workerIndex, epochs int) {
|
|
|
if block < 0 {
|
|
if block < 0 {
|
|
|
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) {
|
|
func TestRemoteSealer(t *testing.T) {
|
|
|
- ethash := NewTester()
|
|
|
|
|
|
|
+ ethash := NewTester(nil)
|
|
|
defer ethash.Close()
|
|
defer ethash.Close()
|
|
|
|
|
+
|
|
|
api := &API{ethash}
|
|
api := &API{ethash}
|
|
|
if _, err := api.GetWork(); err != errNoMiningWork {
|
|
if _, err := api.GetWork(); err != errNoMiningWork {
|
|
|
t.Error("expect to return an error indicate there is no mining work")
|
|
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.
|
|
// Push new work.
|
|
|
ethash.Seal(nil, block, nil)
|
|
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 {
|
|
if res := api.SubmitWork(types.BlockNonce{}, block.HashNoNonce(), common.Hash{}); res {
|
|
|
t.Error("expect to return false when submit a fake solution")
|
|
t.Error("expect to return false when submit a fake solution")
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// Push new block with same block number to replace the original one.
|
|
// 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)
|
|
ethash.Seal(nil, block, nil)
|
|
|
|
|
|
|
|
if work, err = api.GetWork(); err != nil || work[0] != block.HashNoNonce().Hex() {
|
|
if work, err = api.GetWork(); err != nil || work[0] != block.HashNoNonce().Hex() {
|
|
|
t.Error("expect to return the latest pushed work")
|
|
t.Error("expect to return the latest pushed work")
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// Push block with higher block number.
|
|
// Push block with higher block number.
|
|
|
newHead := &types.Header{Number: big.NewInt(2), Difficulty: big.NewInt(100)}
|
|
newHead := &types.Header{Number: big.NewInt(2), Difficulty: big.NewInt(100)}
|
|
|
newBlock := types.NewBlockWithHeader(newHead)
|
|
newBlock := types.NewBlockWithHeader(newHead)
|
|
@@ -130,19 +129,18 @@ func TestRemoteSealer(t *testing.T) {
|
|
|
|
|
|
|
|
func TestHashRate(t *testing.T) {
|
|
func TestHashRate(t *testing.T) {
|
|
|
var (
|
|
var (
|
|
|
- ethash = NewTester()
|
|
|
|
|
- api = &API{ethash}
|
|
|
|
|
hashrate = []hexutil.Uint64{100, 200, 300}
|
|
hashrate = []hexutil.Uint64{100, 200, 300}
|
|
|
expect uint64
|
|
expect uint64
|
|
|
ids = []common.Hash{common.HexToHash("a"), common.HexToHash("b"), common.HexToHash("c")}
|
|
ids = []common.Hash{common.HexToHash("a"), common.HexToHash("b"), common.HexToHash("c")}
|
|
|
)
|
|
)
|
|
|
-
|
|
|
|
|
|
|
+ ethash := NewTester(nil)
|
|
|
defer ethash.Close()
|
|
defer ethash.Close()
|
|
|
|
|
|
|
|
if tot := ethash.Hashrate(); tot != 0 {
|
|
if tot := ethash.Hashrate(); tot != 0 {
|
|
|
t.Error("expect the result should be zero")
|
|
t.Error("expect the result should be zero")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ api := &API{ethash}
|
|
|
for i := 0; i < len(hashrate); i += 1 {
|
|
for i := 0; i < len(hashrate); i += 1 {
|
|
|
if res := api.SubmitHashRate(hashrate[i], ids[i]); !res {
|
|
if res := api.SubmitHashRate(hashrate[i], ids[i]); !res {
|
|
|
t.Error("remote miner submit hashrate failed")
|
|
t.Error("remote miner submit hashrate failed")
|
|
@@ -155,9 +153,8 @@ func TestHashRate(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func TestClosedRemoteSealer(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()
|
|
ethash.Close()
|
|
|
|
|
|
|
|
api := &API{ethash}
|
|
api := &API{ethash}
|