-
Notifications
You must be signed in to change notification settings - Fork 1
/
requests_test.go
156 lines (144 loc) · 4.83 KB
/
requests_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
package gocko
import (
"github.com/stretchr/testify/require"
"strings"
"testing"
)
var client = NewClient()
func TestClient_Ping(t *testing.T) {
p, err := client.Ping()
require.NoError(t, err)
require.True(t, strings.Contains(p.GeckoSays, "To the Moon!"))
}
func TestClient_SupportedVsCurrencies(t *testing.T) {
scs, err := client.SimpleSupportedVsCurrencies()
require.NoError(t, err)
require.NotEmpty(t, len(scs))
require.NotEmpty(t, len(scs[0]))
}
func TestClient_SimplePrice(t *testing.T) {
res, err := client.SimplePrice(SimplePriceParams{
Ids: []string{"polkadot", "solana", "chainlink", "kusama"},
VsCurrencies: []string{"usd", "aud"},
})
require.NoError(t, err)
require.Equal(t, 4, len(res.Prices))
require.Equal(t, 2, len(res.vsCurrencies))
require.NotNil(t, res.Prices["polkadot"])
require.NotNil(t, res.Prices["solana"])
require.NotNil(t, res.Prices["chainlink"])
require.NotNil(t, res.Prices["kusama"])
}
func TestClient_Coins(t *testing.T) {
cs, err := client.CoinsList(CoinsParams{})
require.NoError(t, err)
require.NotEmpty(t, cs)
require.NotEmpty(t, cs[0].Id)
require.NotEmpty(t, cs[0].Symbol)
require.NotEmpty(t, cs[0].Name)
}
func TestClient_CoinsMarkets(t *testing.T) {
t.Run("Default", func(t *testing.T) {
ms, err := client.CoinsMarkets(CoinsMarketsParams{
VsCurrency: "usd",
PerPage: 42,
Sparkline: true,
PriceChangePercentage: "1h,24h,7d",
})
require.NoError(t, err)
require.Equal(t, 42, len(ms))
first := ms[0]
require.Equal(t, 168, len(first.SparklineIn7D.Price))
require.NotNil(t, first.PriceChangePercentage1HInCurrency)
require.NotNil(t, first.PriceChangePercentage24HInCurrency)
require.NotNil(t, first.PriceChangePercentage7DInCurrency)
for _, v := range ms {
require.NotEmpty(t, v.Id)
require.NotEmpty(t, v.Symbol)
require.NotEmpty(t, v.Name)
require.NotEmpty(t, v.Image)
require.NotEmpty(t, v.CurrentPrice)
require.NotEmpty(t, v.MarketCap)
//require.NotEmpty(t, v.TotalVolume)
//require.NotEmpty(t, v.CirculatingSupply)
//require.NotEmpty(t, v.TotalSupply)
//require.NotEmpty(t, v.MaxSupply)
require.NotNil(t, v.SparklineIn7D)
}
})
t.Run("Ids", func(t *testing.T) {
ms, err := client.CoinsMarkets(CoinsMarketsParams{VsCurrency: "usd", Ids: []string{"polkadot", "solana"}})
require.NoError(t, err)
require.Equal(t, 2, len(ms))
})
}
func TestClient_CoinsCharts(t *testing.T) {
tsIntegrity := func(ccs Charts) {
for i, v := range ccs.Prices {
require.Equal(t, v[0], ccs.MarketCaps[i][0])
require.Equal(t, v[0], ccs.TotalVolumes[i][0])
}
}
t.Run("Minutely", func(t *testing.T) {
ccs, err := client.CoinsMarketCharts(CoinsChartsParams{Id: "polkadot", VsCurrency: "usd", Days: "1"})
require.NoError(t, err)
require.Equal(t, 12*24+1, len(ccs.Prices))
require.Equal(t, 12*24+1, len(ccs.TotalVolumes))
require.Equal(t, 12*24+1, len(ccs.MarketCaps))
tsIntegrity(ccs)
})
t.Run("Hourly", func(t *testing.T) {
ccs, err := client.CoinsMarketCharts(CoinsChartsParams{Id: "polkadot", VsCurrency: "usd", Days: "7"})
require.NoError(t, err)
require.Equal(t, 7*24+1, len(ccs.Prices))
require.Equal(t, 7*24+1, len(ccs.TotalVolumes))
require.Equal(t, 7*24+1, len(ccs.MarketCaps))
tsIntegrity(ccs)
})
t.Run("Daily", func(t *testing.T) {
ccs, err := client.CoinsMarketCharts(CoinsChartsParams{Id: "polkadot", VsCurrency: "usd", Days: "100"})
require.NoError(t, err)
require.Equal(t, 100+1, len(ccs.Prices))
require.Equal(t, 100+1, len(ccs.TotalVolumes))
require.Equal(t, 100+1, len(ccs.MarketCaps))
tsIntegrity(ccs)
})
}
func TestClient_CoinsData(t *testing.T) {
cd, err := client.CoinsID(CoinsDataParams{Id: "solana"})
require.NoError(t, err)
require.Equal(t, "solana", cd.Id)
require.Equal(t, "sol", cd.Symbol)
require.Equal(t, "Solana", cd.Name)
}
func TestClient_CoinsOHLC(t *testing.T) {
t.Run("Minutely", func(t *testing.T) {
ohlc, err := client.CoinsOHLC(CoinsOHLCParams{Id: "polkadot", VsCurrency: "usd", Days: "1"})
require.NoError(t, err)
require.LessOrEqual(t, 48, len(ohlc))
})
t.Run("Hourly", func(t *testing.T) {
ohlc, err := client.CoinsOHLC(CoinsOHLCParams{Id: "polkadot", VsCurrency: "usd", Days: "7"})
require.NoError(t, err)
require.LessOrEqual(t, 6*7, len(ohlc))
})
t.Run("Daily", func(t *testing.T) {
ohlc, err := client.CoinsOHLC(CoinsOHLCParams{Id: "polkadot", VsCurrency: "usd", Days: "90"})
require.NoError(t, err)
require.LessOrEqual(t, 90/4, len(ohlc))
})
}
func TestClient_ExchangesList(t *testing.T) {
el, err := client.ExchangesList()
require.NoError(t, err)
require.NotEmpty(t, el)
require.NotEmpty(t, el[0].Id)
require.NotEmpty(t, el[0].Name)
}
func TestClient_Exchanges(t *testing.T) {
es, err := client.Exchanges(ExchangesParams{})
require.NoError(t, err)
require.NotEmpty(t, es)
require.NotEmpty(t, es[0].Id)
require.NotEmpty(t, es[0].Name)
}