-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathratesClient_test.go
119 lines (92 loc) · 2.19 KB
/
ratesClient_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
package ptcpayclient
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"testing"
px "github.com/Ulbora/GoProxy"
"github.com/btcsuite/btcd/btcec"
)
const (
testStore = "TestStore"
testToken = "AEgrxE3CwVAEWixX2gevGR58WuX9yGp9zP3BE6tJBAQHwq"
)
func TestBTCPayClient_GetRates(t *testing.T) {
var pkh = "31eb31ecf1a640cd91e0a1105501f36235f8c7d51d67dcf74ccc968d74cb6b25"
var cryt Cryptography
cc := cryt.New()
kp := cc.LoadKeyPair(pkh, btcec.S256())
// kp := cc.GenerateKeyPair(btcec.S256())
var ptc BTCPayClient
var head Headers
ptc.SetHeader(head)
ptc.crypto = cc
//ptc.tokens.Token = testToken
//---mock out the call
var gp px.MockGoProxy
var mres http.Response
mres.Body = ioutil.NopCloser(bytes.NewBufferString(`{
"data": [
{
"name": "US Dollar",
"cryptoCode": "BTC",
"currencyPair": "BTC_USD",
"code": "USD",
"rate": 51826.723
}
]
}`))
gp.MockResp = &mres
gp.MockDoSuccess1 = true
gp.MockRespCode = 200
c := ptc.New(testBaseURL, kp, testToken)
ptc.OverrideProxy(&gp)
fmt.Println("new client: ", ptc)
var cur = []string{"LTC_USD", "BTC_USD"}
resp := c.GetRates(cur, testStore)
fmt.Println("resp: ", resp)
if resp.Data[0].CryptoCode != "BTC" {
t.Fail()
}
// t.Fail()
}
func TestBTCPayClient_GetRatesFail(t *testing.T) {
var pkh = "31eb31ecf1a640cd91e0a1105501f36235f8c7d51d67dcf74ccc968d74cb6b25"
var cryt Cryptography
cc := cryt.New()
kp := cc.LoadKeyPair(pkh, btcec.S256())
// kp := cc.GenerateKeyPair(btcec.S256())
var ptc BTCPayClient
var head Headers
ptc.SetHeader(head)
//ptc.crypto = cc
ptc.tokens.Token = testToken
//---mock out the call
var gp px.MockGoProxy
var mres http.Response
mres.Body = ioutil.NopCloser(bytes.NewBufferString(`{
"data": [
{
"name": "US Dollar",
"cryptoCode": "BTC",
"currencyPair": "BTC_USD",
"code": "USD",
"rate": 51826.723
}
]
}`))
gp.MockResp = &mres
gp.MockDoSuccess1 = true
gp.MockRespCode = 401
c := ptc.New(testBaseURL, kp, testToken)
ptc.OverrideProxy(&gp)
fmt.Println("new client: ", ptc)
var cur = []string{"LTC_USD", "BTC_USD"}
resp := c.GetRates(cur, testStore)
fmt.Println("resp: ", resp)
if resp.Data[0].CryptoCode != "BTC" {
t.Fail()
}
//t.Fail()
}