-
Notifications
You must be signed in to change notification settings - Fork 2
/
withdraw_service_test.go
169 lines (155 loc) · 4.46 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
package binance
import (
"testing"
"github.com/crypto-zero/go-binance/v2/common"
"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(`
{
"id":"7213fea8e94b4a5593d507237e5a555b"
}
`)
s.mockDo(data, nil)
defer s.assertDo()
coin := "USDT"
withdrawOrderID := "testID"
network := "ETH"
address := "myaddress"
addressTag := "xyz"
amount := "0.01"
transactionFeeFlag := true
name := "eth"
s.assertReq(func(r *common.Request) {
e := newSignedRequest().SetQueryParams(common.Params{
"coin": coin,
"withdrawOrderId": withdrawOrderID,
"network": network,
"address": address,
"addressTag": addressTag,
"amount": amount,
"transactionFeeFlag": transactionFeeFlag,
"name": name,
})
s.assertRequestEqual(e, r)
})
res, err := s.client.NewCreateWithdrawService().
Coin(coin).
WithdrawOrderID(withdrawOrderID).
Network(network).
Address(address).
AddressTag(addressTag).
Amount(amount).
TransactionFeeFlag(transactionFeeFlag).
Name(name).
Do(newContext())
r := s.r()
r.NoError(err)
r.Equal("7213fea8e94b4a5593d507237e5a555b", res.ID)
}
func (s *withdrawServiceTestSuite) TestListWithdraws() {
data := []byte(`[
{
"address": "0x94df8b352de7f46f64b01d3666bf6e936e44ce60",
"amount": "8.91000000",
"applyTime": "2019-10-12 11:12:02",
"coin": "USDT",
"id": "b6ae22b3aa844210a7041aee7589627c",
"withdrawOrderId": "WITHDRAWtest123",
"network": "ETH",
"transferType": 0,
"status": 6,
"transactionFee": "0.004",
"txId": "0xb5ef8c13b968a406cc62a93a8bd80f9e9a906ef1b3fcf20a2e48573c17659268"
},
{
"address": "1FZdVHtiBqMrWdjPyRPULCUceZPJ2WLCsB",
"amount": "0.00150000",
"applyTime": "2019-09-24 12:43:45",
"coin": "BTC",
"id": "156ec387f49b41df8724fa744fa82719",
"network": "BTC",
"status": 6,
"transactionFee": "0.004",
"transferType": 0,
"txId": "60fd9007ebfddc753455f95fafa808c4302c836e4d1eebc5a132c36c1d8ac354"
}
]
`)
s.mockDo(data, nil)
defer s.assertDo()
coin := "ETH"
status := 0
startTime := int64(1508198532000)
endTime := int64(1508198532001)
offset := 0
limit := 1000
s.assertReq(func(r *common.Request) {
e := newSignedRequest().SetQueryParams(common.Params{
"coin": coin,
"status": status,
"startTime": startTime,
"endTime": endTime,
"offset": offset,
"limit": limit,
})
s.assertRequestEqual(e, r)
})
withdraws, err := s.client.NewListWithdrawsService().
Coin(coin).
Status(status).
StartTime(startTime).
EndTime(endTime).
Offset(offset).
Limit(limit).
Do(newContext())
r := s.r()
r.NoError(err)
s.Len(withdraws, 2)
s.assertWithdrawEqual(&Withdraw{
Address: "0x94df8b352de7f46f64b01d3666bf6e936e44ce60",
Amount: "8.91000000",
ApplyTime: "2019-10-12 11:12:02",
Coin: "USDT",
ID: "b6ae22b3aa844210a7041aee7589627c",
WithdrawOrderID: "WITHDRAWtest123",
Network: "ETH",
TransferType: 0,
Status: 6,
TransactionFee: "0.004",
TxID: "0xb5ef8c13b968a406cc62a93a8bd80f9e9a906ef1b3fcf20a2e48573c17659268",
}, withdraws[0])
s.assertWithdrawEqual(&Withdraw{
Address: "1FZdVHtiBqMrWdjPyRPULCUceZPJ2WLCsB",
Amount: "0.00150000",
ApplyTime: "2019-09-24 12:43:45",
Coin: "BTC",
ID: "156ec387f49b41df8724fa744fa82719",
WithdrawOrderID: "",
Network: "BTC",
TransferType: 0,
Status: 6,
TransactionFee: "0.004",
TxID: "60fd9007ebfddc753455f95fafa808c4302c836e4d1eebc5a132c36c1d8ac354",
}, withdraws[1])
}
func (s *withdrawServiceTestSuite) assertWithdrawEqual(e, a *Withdraw) {
r := s.r()
r.Equal(e.Address, a.Address, "Address")
r.Equal(e.Amount, a.Amount, "Amount")
r.Equal(e.ApplyTime, a.ApplyTime, "ApplyTime")
r.Equal(e.Coin, a.Coin, "Coin")
r.Equal(e.ID, a.ID, "ID")
r.Equal(e.WithdrawOrderID, a.WithdrawOrderID, "WithdrawOrderID")
r.Equal(e.Network, a.Network, "Network")
r.Equal(e.TransferType, a.TransferType, "TransferType")
r.Equal(e.Status, a.Status, "Status")
r.Equal(e.TransactionFee, a.TransactionFee, "TransactionFee")
r.Equal(e.TxID, a.TxID, "TxID")
}