-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpubmine_test.go
84 lines (78 loc) · 1.69 KB
/
pubmine_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package pubmine_test
import (
"context"
"fmt"
"runtime"
"testing"
"time"
"github.com/tenkoh/go-pubmine"
)
func TestNewGenerator(t *testing.T) {
type args struct {
prefix string
maxWorkers int64
}
type test struct {
name string
args args
wantError bool
}
tests := []test{
{"success case", args{"n0str", 1}, false},
{"fail blank", args{"", 1}, true},
{"fail bad character", args{"nostr", 1}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := tt.args
_, err := pubmine.NewGenerator(a.prefix, a.maxWorkers)
hasError := err != nil
if hasError != tt.wantError {
t.Errorf("want %t, got %t", tt.wantError, hasError)
}
})
}
}
func TestMine(t *testing.T) {
// just test the logic is not broken
g, err := pubmine.NewGenerator("n0s", int64(runtime.NumCPU()))
if err != nil {
t.Fatal(err)
}
kp, err := g.Mine(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v\n", kp)
}
func TestSimpleMineWithCancel(t *testing.T) {
// just test the logic is not broken
g, err := pubmine.NewGenerator("n0str", 1)
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
defer cancel()
kp, err := g.SimpleMine(ctx)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v\n", kp)
}
func TestMineWithCancel(t *testing.T) {
// just test the logic is not broken
g, err := pubmine.NewGenerator("n0st", int64(runtime.NumCPU()))
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
defer cancel()
kp, err := g.Mine(ctx)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v\n", kp)
}