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

Function TestCPUMiner_HashBlock

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

Source from the content-addressed store, hash-verified

23)
24
25func TestCPUMiner_HashBlock(t *testing.T) {
26 miner := NewCPUMiner(make(chan struct{}))
27 nonceCh := make(chan NonceInfo)
28 stop := make(chan struct{})
29 diffWanted := 20
30 data := []byte{
31 0x79, 0xa6, 0x1a, 0xdb, 0xc6, 0xe5, 0xa2, 0xe1,
32 0x39, 0xd2, 0x71, 0x3a, 0x54, 0x6e, 0xc7, 0xc8,
33 0x75, 0x63, 0x2e, 0x75, 0xf1, 0xdf, 0x9c, 0x3f,
34 0xa6, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
35 }
36 block := MiningBlock{
37 Data: data,
38 NonceChan: nonceCh,
39 Stop: stop,
40 }
41 var (
42 err error
43 )
44 var wg sync.WaitGroup
45 wg.Add(1)
46 go func() {
47 err = miner.ComputeBlockNonce(block, Uint256{}, diffWanted)
48 wg.Done()
49 }()
50 nonceFromCh := <-nonceCh
51 wg.Wait()
52 hash := HashBlock(data, nonceFromCh.Nonce)
53 //hash := hash.THashH(append(data, nonceFromCh.NonceInfo.Bytes()...))
54 if err != nil || nonceFromCh.Difficulty < diffWanted || hash.Difficulty() < diffWanted {
55 t.Errorf("ComputeBlockNonce got %v, difficulty %d, nonce %v",
56 err, nonceFromCh.Difficulty, nonceFromCh.Nonce)
57 }
58 t.Logf("Difficulty: %d, Hash: %s", nonceFromCh.Difficulty, hash.String())
59}
60
61func TestCPUMiner_HashBlock_stop(t *testing.T) {
62 minerQuit := make(chan struct{})

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected