(t *testing.T)
| 95 | } |
| 96 | |
| 97 | func TestCPUMiner_HashBlock_quit(t *testing.T) { |
| 98 | minerQuit := make(chan struct{}) |
| 99 | miner := NewCPUMiner(minerQuit) |
| 100 | nonceCh := make(chan NonceInfo) |
| 101 | stop := make(chan struct{}) |
| 102 | diffWanted := 256 |
| 103 | data := []byte{ |
| 104 | 0x79, 0xa6, |
| 105 | } |
| 106 | block := MiningBlock{ |
| 107 | Data: data, |
| 108 | NonceChan: nonceCh, |
| 109 | Stop: stop, |
| 110 | } |
| 111 | var ( |
| 112 | err error |
| 113 | ) |
| 114 | go func() { |
| 115 | err = miner.ComputeBlockNonce(block, Uint256{}, diffWanted) |
| 116 | }() |
| 117 | // stop miner |
| 118 | time.Sleep(1 * time.Second) |
| 119 | //block.Stop <- struct{}{} |
| 120 | miner.quit <- struct{}{} |
| 121 | |
| 122 | nonceFromCh := <-block.NonceChan |
| 123 | |
| 124 | hasha := HashBlock(data, nonceFromCh.Nonce) |
| 125 | //hasha := hash.THashH(append(data, nonceFromCh.NonceInfo.Bytes()...)) |
| 126 | if nonceFromCh.Difficulty < 1 || hasha.Difficulty() != nonceFromCh.Difficulty { |
| 127 | t.Errorf("ComputeBlockNonce got %v, difficulty %d, nonce %v, hash %s", |
| 128 | err, nonceFromCh.Difficulty, nonceFromCh.Nonce, hasha.String()) |
| 129 | } |
| 130 | t.Logf("Difficulty: %d, Hash: %s", nonceFromCh.Difficulty, hasha.String()) |
| 131 | } |
nothing calls this directly
no test coverage detected