(t *testing.T)
| 59 | } |
| 60 | |
| 61 | func TestCPUMiner_HashBlock_stop(t *testing.T) { |
| 62 | minerQuit := make(chan struct{}) |
| 63 | miner := NewCPUMiner(minerQuit) |
| 64 | nonceCh := make(chan NonceInfo) |
| 65 | stop := make(chan struct{}) |
| 66 | diffWanted := 256 |
| 67 | data := []byte{ |
| 68 | 0x79, 0xa6, |
| 69 | } |
| 70 | block := MiningBlock{ |
| 71 | Data: data, |
| 72 | NonceChan: nonceCh, |
| 73 | Stop: stop, |
| 74 | } |
| 75 | var ( |
| 76 | err error |
| 77 | ) |
| 78 | go func() { |
| 79 | err = miner.ComputeBlockNonce(block, Uint256{}, diffWanted) |
| 80 | }() |
| 81 | // stop miner |
| 82 | time.Sleep(2 * time.Second) |
| 83 | block.Stop <- struct{}{} |
| 84 | //miner.quit <- struct{}{} |
| 85 | |
| 86 | nonceFromCh := <-block.NonceChan |
| 87 | |
| 88 | hasha := HashBlock(data, nonceFromCh.Nonce) |
| 89 | //hasha := hash.THashH(append(data, nonceFromCh.NonceInfo.Bytes()...)) |
| 90 | if nonceFromCh.Difficulty < 1 || hasha.Difficulty() != nonceFromCh.Difficulty { |
| 91 | t.Errorf("ComputeBlockNonce got %v, difficulty %d, nonce %v, hash %s", |
| 92 | err, nonceFromCh.Difficulty, nonceFromCh.Nonce, hasha.String()) |
| 93 | } |
| 94 | t.Logf("Difficulty: %d, Hash: %s", nonceFromCh.Difficulty, hasha.String()) |
| 95 | } |
| 96 | |
| 97 | func TestCPUMiner_HashBlock_quit(t *testing.T) { |
| 98 | minerQuit := make(chan struct{}) |
nothing calls this directly
no test coverage detected