-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain_test.go
184 lines (154 loc) · 3.75 KB
/
main_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
package glassnode
import (
"context"
"os"
"testing"
)
func Test_tvconv(t *testing.T) {
a := `
[
{
"t":1604361600,
"o":{
"ma128":7.671518382631376e+22,
"ma14":8.49032655528302e+22,
"ma200":7.285316967299924e+22,
"ma25":8.449559630140737e+22,
"ma40":8.390750464697435e+22,
"ma60":8.150679497286024e+22,
"ma9":8.435624413591933e+22,
"ma90":7.893158075608794e+22
}
}
]
`
b, err := UnmarshalJSON([]byte(a))
if err != nil {
t.Logf("Failed Unmarshalling mock json object: %s", err.Error())
t.FailNow()
}
c := b.([]TimeOptions)
if c[0].Time != 1604361600 {
t.Logf("Options element parsing failed: Time %d doesnt match the mock value", c[0].Time)
t.Fail()
}
if c[0].Options["ma9"] < 100 {
t.Logf("Options element parsing failed: MA9 %f should be a large number", c[0].Options["ma9"])
t.Fail()
}
}
func Test_toconv(t *testing.T) {
a := `
[
{
"t": 1586217600,
"v": 0.04205656140305256
},
{
"t": 1586304000,
"v": 0.04161501005133026
},
{
"t": 1586908800,
"v": 0.02936962662277417
},
{
"t": 1586995200,
"v": 0.028548190409882022
}
]
`
b, err := UnmarshalJSON([]byte(a))
if err != nil {
t.Logf("Failed Unmarshalling mock json object: %s", err.Error())
t.FailNow()
}
c := b.([]TimeValue)
if c[0].Time != 1586217600 {
t.Logf("TimeValue element parsing failed: Time %d doesnt match the mock value", c[0].Time)
t.Fail()
}
if c[0].Value < 0.042 {
t.Logf("TimeValue element parsing failed: Value %f should be larger than .042", c[0].Value)
t.Fail()
}
}
func Test_liveintegration(t *testing.T) {
apik := os.Getenv("GLASSNODE_API_KEY")
if apik == "" {
t.Log("live API Key is required for this test")
t.SkipNow()
}
apisample := NewClient(apik)
yesterday := YesterdayTimestamp()
opts := APIOptionsList{
Asset: "BTC", // or "ETH"
Metric: "sopr", // or "nupl"
Since: yesterday, // UNIX timestamp, 0 means all
Until: 0, // UNIX timestamp, 0 means all
Frequency: "", // 1h, 24h.. default is 24h
Category: "indicators", // either indicators, market, mining etc
}
d, err := GetMetricData(context.Background(), *apisample, &opts)
if err != nil {
t.Log(err.Error())
t.FailNow()
}
e := d.([]TimeValue)
if e[0].Value > 2 || e[0].Value < 0 {
t.Log("SOPR should be between 0 and 2")
t.Fail()
}
}
func Test_liveintegration_directmappings(t *testing.T) {
apik := os.Getenv("GLASSNODE_API_KEY")
if apik == "" {
t.Log("live API Key is required for this test")
t.SkipNow()
}
apisample := NewClient(apik)
opts := APIOptionsList{
Asset: "BTC", // or "ETH"
Category: "indicators", // either indicators, market, mining etc
Metric: "difficulty_ribbon", // or "nupl"
DirectMapping: map[string]string{
"s": "1586280246",
"u": "1587144246",
},
}
d, err := GetMetricData(context.Background(), *apisample, &opts)
if err != nil {
t.Log(err.Error())
t.FailNow()
}
e := d.([]TimeOptions)
if e[0].Time != 1586217600 {
t.Logf("First record time should be %d but is %d", 1586217600, e[0].Time)
t.Fail()
}
if e[0].Options["ma9"] < 100 {
t.Logf("ma9 val should be greater than %f but is %f", 100.0, e[0].Options["ma9"])
t.Fail()
}
}
func Test_constructURL(t *testing.T) {
apisample := NewClient("x")
opts := APIOptionsList{
Asset: "BTC",
Category: "indicators",
Metric: "difficulty_ribbon",
DirectMapping: map[string]string{
"s": "123",
"u": "456",
},
}
expectation := "https://api.glassnode.com/v1/metrics/indicators/difficulty_ribbon?a=BTC&api_key=x&s=123&u=456"
result, err := constructURL(*apisample, &opts)
if err != nil {
t.Fail()
}
if expectation != result {
t.Logf("Result: %s didn't match expectation: %s", result, expectation)
t.Fail()
}
}