forked from adshao/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
withdraw_service_test.go
130 lines (116 loc) · 3.23 KB
/
withdraw_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
129
130
package binance
import (
"testing"
"github.com/stretchr/testify/suite"
)
type withdrawServiceTestSuite struct {
baseTestSuite
}
func TestWithdrawService(t *testing.T) {
suite.Run(t, new(withdrawServiceTestSuite))
}
func (s *withdrawServiceTestSuite) TestCreateWithdraw() {
data := []byte(`{
"msg": "success",
"success": true
}`)
s.mockDo(data, nil)
defer s.assertDo()
asset := "ETH"
address := "myaddress"
amount := "0.01"
name := "eth"
s.assertReq(func(r *request) {
e := newSignedRequest().setParams(params{
"asset": asset,
"address": address,
"amount": amount,
"name": name,
})
s.assertRequestEqual(e, r)
})
err := s.client.NewCreateWithdrawService().Asset(asset).
Address(address).Amount(amount).Name(name).Do(newContext())
s.r().NoError(err)
}
func (s *withdrawServiceTestSuite) TestListWithdraws() {
data := []byte(`{
"withdrawList": [
{
"amount": 1,
"address": "0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b",
"asset": "ETH",
"applyTime": 1508198532000,
"status": 4
},
{
"amount": 0.005,
"address": "0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b",
"txId": "0x80aaabed54bdab3f6de5868f89929a2371ad21d666f20f7393d1a3389fad95a1",
"asset": "ETH",
"applyTime": 1508198532000,
"status": 4
}
],
"success": true
}`)
s.mockDo(data, nil)
defer s.assertDo()
asset := "ETH"
status := 0
startTime := int64(1508198532000)
endTime := int64(1508198532001)
s.assertReq(func(r *request) {
e := newSignedRequest().setParams(params{
"asset": asset,
"status": status,
"startTime": startTime,
"endTime": endTime,
})
s.assertRequestEqual(e, r)
})
withdraws, err := s.client.NewListWithdrawsService().Asset(asset).
Status(status).StartTime(startTime).EndTime(endTime).
Do(newContext())
r := s.r()
r.NoError(err)
s.Len(withdraws, 2)
e1 := &Withdraw{
Amount: 1,
Address: "0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b",
Asset: "ETH",
ApplyTime: 1508198532000,
Status: 4,
}
e2 := &Withdraw{
Amount: 0.005,
Address: "0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b",
TxID: "0x80aaabed54bdab3f6de5868f89929a2371ad21d666f20f7393d1a3389fad95a1",
Asset: "ETH",
ApplyTime: 1508198532000,
Status: 4,
}
s.assertWithdrawEqual(e1, withdraws[0])
s.assertWithdrawEqual(e2, withdraws[1])
}
func (s *withdrawServiceTestSuite) assertWithdrawEqual(e, a *Withdraw) {
r := s.r()
r.InDelta(e.Amount, a.Amount, 0.0000001, "Amount")
r.Equal(e.Address, a.Address, "Address")
r.Equal(e.Asset, a.Asset, "Asset")
r.Equal(e.ApplyTime, a.ApplyTime, "ApplyTime")
r.Equal(e.Status, a.Status, "Status")
}
func (s *withdrawServiceTestSuite) TestGetWithdrawFee() {
data := []byte(`{"success": true,"withdrawFee": 0.00050}`)
s.mockDo(data, nil)
defer s.assertDo()
asset := "BTC"
s.assertReq(func(r *request) {
e := newSignedRequest().setParam("asset", asset)
s.assertRequestEqual(e, r)
})
res, err := s.client.NewGetWithdrawFeeService().Asset(asset).Do(newContext())
s.r().NoError(err)
s.r().Equal(res.Fee, 0.0005, "Fee")
}