-
Notifications
You must be signed in to change notification settings - Fork 34
/
endpoint_api_test.go
151 lines (136 loc) · 3.88 KB
/
endpoint_api_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
package coinbase
import (
"fmt"
"log"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
// Initialize the client without mock mode enabled on rpc.
// All calls hit the coinbase API and tests focus on checking
// format of the response and validity of sent requests
func initClient() Client {
return ApiKeyClient(os.Getenv("COINBASE_KEY"), os.Getenv("COINBASE_SECRET"))
}
// About Endpoint Tests:
//All Endpoint Tests actually call the Coinbase API and check the return values
// with type assertions. This was done because of the varying specific values
// returned depending on the API Key and Secret pair used when running the tests.
// Endpoint tests do not include tests that could be run an arbitrary amount of times
// i.e buy, sell, etc...
func TestEndpointGetBalance(t *testing.T) {
c := initClient()
amount, err := c.GetBalance()
if err != nil {
log.Fatal(err)
}
assert.IsType(t, 1.1, amount)
}
func TestEndpointGetReceiveAddress(t *testing.T) {
t.Skip("Skipping GetReceiveAddressEndpoint in order not to create excessive amounts of receive addresses during testing.")
c := initClient()
params := &AddressParams{
CallbackUrl: "http://www.wealthlift.com",
Label: "My Test Address",
}
address, err := c.GenerateReceiveAddress(params)
if err != nil {
log.Fatal(err)
}
assert.IsType(t, "string", address)
}
func TestEndpointGetAllAddresses(t *testing.T) {
c := initClient()
params := &AddressesParams{
Page: 1,
Limit: 5,
}
addresses, err := c.GetAllAddresses(params)
if err != nil {
log.Fatal(err)
}
assert.IsType(t, "string", addresses.Addresses[0].CreatedAt)
assert.IsType(t, "string", addresses.Addresses[0].Address)
}
func TestEndpointCreateButton(t *testing.T) {
c := initClient()
params := &Button{
Name: "test",
Type: "buy_now",
Subscription: false,
PriceString: "1.23",
PriceCurrencyIso: "USD",
Custom: "Order123",
CallbackUrl: "http://www.example.com/my_custom_button_callback",
Description: "Sample Description",
Style: "custom_large",
IncludeEmail: true,
}
data, err := c.CreateButton(params)
if err != nil {
if fmt.Sprint(err) != "You have not filled out your merchant profile. Please enter your information in the Profile section. in CreateButton()" {
log.Fatal(err)
}
t.Skip("Skip this test since user hasn't filled out their merchant profile yet.")
}
assert.IsType(t, "string", data.EmbedHtml)
assert.IsType(t, "string", data.Type)
}
func TestEndpointGetCurrencies(t *testing.T) {
c := initClient()
data, err := c.GetCurrencies()
if err != nil {
log.Fatal()
}
assert.IsType(t, "string", data[0].Name)
}
func TestEndpointGetExchangeRates(t *testing.T) {
c := initClient()
data, err := c.GetExchangeRates()
if err != nil {
log.Fatal(err)
}
assert.IsType(t, "string", data["btc_to_usd"])
}
func TestEndpointGetExchangeRate(t *testing.T) {
c := initClient()
data, err := c.GetExchangeRate("btc", "usd")
if err != nil {
log.Fatal(err)
}
assert.IsType(t, 0.0, data)
}
func TestEndpointGetTransactions(t *testing.T) {
c := initClient()
data, err := c.GetTransactions(1)
if err != nil {
log.Fatal(err)
}
assert.IsType(t, int64(1), data.TotalCount)
assert.IsType(t, "string", data.Transactions[0].Hsh)
}
func TestEndpointGetBuyPrice(t *testing.T) {
c := initClient()
data, err := c.GetBuyPrice(1)
if err != nil {
log.Fatal(err)
}
assert.IsType(t, "string", data.Subtotal.Currency)
assert.IsType(t, "string", data.Total.Amount)
}
func TestEndpointGetSellPrice(t *testing.T) {
c := initClient()
data, err := c.GetSellPrice(1)
if err != nil {
log.Fatal(err)
}
assert.IsType(t, "string", data.Subtotal.Currency)
assert.IsType(t, "string", data.Total.Amount)
}
func TestEndpointGetTransaction(t *testing.T) {
c := initClient()
_, err := c.GetTransaction("5446968682a19ab940000004")
if err != nil {
assert.IsType(t, "string", err.Error())
}
}