-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpos_test.go
188 lines (157 loc) · 3.46 KB
/
mpos_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package mpos
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"testing"
)
var (
pool *MiningPoolHub
mockFunc func(req *http.Request) (*http.Response, error)
mockResults map[string]json.RawMessage
)
type mockClient struct{}
func (m *mockClient) Do(req *http.Request) (*http.Response, error) {
if action := req.URL.Query().Get("action"); action != "" {
if val, ok := mockResults[action]; ok {
r := ioutil.NopCloser(bytes.NewReader(val))
return func(req *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: 200,
Body: r,
}, nil
}(req)
}
}
return mockFunc(req)
}
func init() {
// determine testing mode
if os.Getenv("MPOS_API") == "" {
client = &mockClient{}
} else {
client = &http.Client{}
}
pool = NewMiningPoolHub(os.Getenv("MPOS_API"), "BASE_URL")
// load mock results
b, err := os.ReadFile("responses.json")
if err != nil {
panic(err)
}
if err := json.NewDecoder(bytes.NewReader(b)).Decode(&mockResults); err != nil {
panic(err)
}
}
func TestAccount(t *testing.T) {
if _, err := pool.Account(); err != nil {
t.Error(err)
}
}
func TestBlockCount(t *testing.T) {
if _, err := pool.BlockCount(); err != nil {
t.Error(err)
}
}
func TestBlocksFound(t *testing.T) {
if _, err := pool.BlocksFound(); err != nil {
t.Error(err)
}
}
func TestBlockStats(t *testing.T) {
if _, err := pool.BlockStats(); err != nil {
t.Error(err)
}
}
func TestCurrentWorkers(t *testing.T) {
if _, err := pool.CurrentWorkers(); err != nil {
t.Error(err)
}
}
func TestDashboardData(t *testing.T) {
if _, err := pool.DashboardData(); err != nil {
t.Error(err)
}
}
func TestDifficulty(t *testing.T) {
if _, err := pool.Difficulty(); err != nil {
t.Error(err)
}
}
func TestEstimatedTime(t *testing.T) {
if _, err := pool.EstimatedTime(); err != nil {
t.Error(err)
}
}
func TestPoolHashrate(t *testing.T) {
if _, err := pool.PoolHashrate(); err != nil {
t.Error(err)
}
}
func TestPoolInfo(t *testing.T) {
if _, err := pool.PoolInfo(); err != nil {
t.Error(err)
}
}
func TestPoolStatus(t *testing.T) {
if _, err := pool.PoolStatus(); err != nil {
t.Error(err)
}
}
func TestTimeSinceLastBlock(t *testing.T) {
if _, err := pool.TimeSinceLastBlock(); err != nil {
t.Error(err)
}
}
func TestTopContributors(t *testing.T) {
if _, err := pool.TopContributors(); err != nil {
t.Error(err)
}
}
// TODO: handle live-testing non-admin user
func TestUserBalance(t *testing.T) {
if _, err := pool.User(1000).Balance(); err != nil {
t.Error(err)
}
}
func TestUserHashrate(t *testing.T) {
if _, err := pool.User(1000).Hashrate(); err != nil {
t.Error(err)
}
}
func TestUserShareRate(t *testing.T) {
if _, err := pool.User(1000).Sharerate(); err != nil {
t.Error(err)
}
}
func TestUserStatus(t *testing.T) {
if _, err := pool.User(1000).Status(); err != nil {
t.Error(err)
}
}
func TestUserTransactions(t *testing.T) {
if _, err := pool.User(1000).Transactions(); err != nil {
t.Error(err)
}
}
func TestUserWorkers(t *testing.T) {
if _, err := pool.User(1000).Workers(); err != nil {
t.Error(err)
}
}
func TestPublic(t *testing.T) {
if _, err := pool.Public(); err != nil {
t.Error(err)
}
}
func ExampleMiningPoolHub() {
pool := NewMiningPoolHub("API_KEY", "BASE_URL")
info, err := pool.PoolInfo()
if err != nil {
fmt.Println(err)
}
fmt.Printf("Pool is mining %v, with a %v%% fee\n", info.Coinname, info.Fees)
// Output: Pool is mining Ethereum, with a 0.9% fee
}