-
Notifications
You must be signed in to change notification settings - Fork 16
/
btcvanity_test.go
59 lines (49 loc) · 929 Bytes
/
btcvanity_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package btcvanity
import (
"strings"
"testing"
"time"
)
func TestBTCVanity(t *testing.T) {
b := New(&Config{
Buffer: 5,
})
wallet, err := b.Find("ab")
if err != nil {
t.Error(err)
return
}
pubKey := strings.ToLower(wallet.PublicKey())
expected := "1ab"
hasPrefix := strings.HasPrefix(pubKey, expected)
if !hasPrefix {
t.Errorf("Wrong generated wallet, got %v expected %v\n", pubKey, expected)
}
t.Logf("Generated address %v\n", pubKey)
done := make(chan bool)
// this is going to take billion of years
go func() {
wallet, err = b.Find("helloworld")
if err != nil {
t.Error(err)
t.Fail()
}
if wallet != nil {
t.Error("We got generated wallet! Should not happen")
t.Fail()
}
done <- true
}()
// wait and stop the process
loop:
for {
select {
case <-done:
t.Log("Process stopped")
break loop
case <-time.After(2 * time.Second):
b.Stop()
break
}
}
}