forked from adshao/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deposit_service_test.go
128 lines (116 loc) · 3.18 KB
/
deposit_service_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
package binance
import (
"testing"
"github.com/stretchr/testify/suite"
)
type depositServiceTestSuite struct {
baseTestSuite
}
func TestDepositService(t *testing.T) {
suite.Run(t, new(depositServiceTestSuite))
}
func (s *depositServiceTestSuite) TestListDeposits() {
data := []byte(`
{
"depositList": [
{
"insertTime": 1508198532000,
"amount": 0.04670582,
"asset": "ETH",
"address": "0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b",
"txId": "0xdf33b22bdb2b28b1f75ccd201a4a4m6e7g83jy5fc5d5a9d1340961598cfcb0a1",
"status": 1
},
{
"insertTime": 1508298532000,
"amount": 1000,
"asset": "XMR",
"address": "463tWEBn5XZJSxLU34r6g7h8jtxuNcDbjLSjkn3XAXHCbLrTTErJrBWYgHJQyrCwkNgYvyV3z8zctJLPCZy24jvb3NiTcTJ",
"addressTag": "342341222",
"txId": "b3c6219639c8ae3f9cf010cdc24fw7f7yt8j1e063f9b4bd1a05cb44c4b6e2509",
"status": 1
}
],
"success": true
}
`)
s.mockDo(data, nil)
defer s.assertDo()
s.assertReq(func(r *request) {
e := newSignedRequest().setParams(params{
"asset": "BTC",
"status": 1,
"startTime": 1508198532000,
"endTime": 1508198532001,
})
s.assertRequestEqual(e, r)
})
deposits, err := s.client.NewListDepositsService().
Asset("BTC").
Status(1).
StartTime(1508198532000).
EndTime(1508198532001).
Do(newContext())
r := s.r()
r.NoError(err)
r.Len(deposits, 2)
s.assertDepositEqual(&Deposit{
InsertTime: 1508198532000,
Amount: 0.04670582,
Asset: "ETH",
Address: "0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b",
AddressTag: "",
TxID: "0xdf33b22bdb2b28b1f75ccd201a4a4m6e7g83jy5fc5d5a9d1340961598cfcb0a1",
Status: 1,
}, deposits[0])
s.assertDepositEqual(&Deposit{
InsertTime: 1508298532000,
Amount: 1000.0,
Asset: "XMR",
Address: "463tWEBn5XZJSxLU34r6g7h8jtxuNcDbjLSjkn3XAXHCbLrTTErJrBWYgHJQyrCwkNgYvyV3z8zctJLPCZy24jvb3NiTcTJ",
AddressTag: "342341222",
TxID: "b3c6219639c8ae3f9cf010cdc24fw7f7yt8j1e063f9b4bd1a05cb44c4b6e2509",
Status: 1,
}, deposits[1])
}
func (s *depositServiceTestSuite) assertDepositEqual(e, a *Deposit) {
r := s.r()
r.Equal(e.InsertTime, a.InsertTime, "InsertTime")
r.Equal(e.Asset, a.Asset, "Asset")
r.InDelta(e.Amount, a.Amount, 0.0000000001, "Amount")
r.Equal(e.Status, a.Status, "Status")
r.Equal(e.TxID, a.TxID, "TxID")
}
func (s *depositServiceTestSuite) TestGetDepositAddress() {
data := []byte(`
{
"address": "0xbf1f86b3c8ff4f8cbfc195e9713b6f0000000000",
"success": true,
"addressTag": "1231212",
"asset": "ETH",
"url": "https://etherscan.io/address/0xbf1f86b3c8ff4f8cbfc195e9713b6f0000000000"
}
`)
s.mockDo(data, nil)
defer s.assertDo()
asset := "ETH"
status := true
s.assertReq(func(r *request) {
e := newSignedRequest().setParams(params{
"asset": asset,
"status": status,
})
s.assertRequestEqual(e, r)
})
res, err := s.client.NewGetDepositAddressService().
Asset(asset).
Status(status).
Do(newContext())
r := s.r()
r.NoError(err)
r.True(res.Success)
r.Equal("0xbf1f86b3c8ff4f8cbfc195e9713b6f0000000000", res.Address)
r.Equal("1231212", res.AddressTag)
r.Equal("ETH", res.Asset)
r.Equal("https://etherscan.io/address/0xbf1f86b3c8ff4f8cbfc195e9713b6f0000000000", res.URL)
}