MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestCPUMiner_HashBlock_stop

Function TestCPUMiner_HashBlock_stop

pow/cpuminer/miner_test.go:61–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func 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
97func TestCPUMiner_HashBlock_quit(t *testing.T) {
98 minerQuit := make(chan struct{})

Callers

nothing calls this directly

Calls 6

ComputeBlockNonceMethod · 0.95
NewCPUMinerFunction · 0.85
HashBlockFunction · 0.85
ErrorfMethod · 0.80
DifficultyMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected