-
Notifications
You must be signed in to change notification settings - Fork 3
/
wallet_service_test.go
188 lines (176 loc) · 5.69 KB
/
wallet_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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package phemex
import (
"testing"
"github.com/stretchr/testify/suite"
)
type walletServiceTestSuite struct {
baseTestSuite
}
func TestWalletService(t *testing.T) {
suite.Run(t, new(walletServiceTestSuite))
}
func (s *walletServiceTestSuite) TestUserWalletService() {
data := []byte(`{
"code": 0,
"msg": "OK",
"data": [{
"userId": 123123,
"email": "x**@**.com",
"nickName": "nickName",
"passwordState": 1,
"clientCnt": 0,
"totp": 1,
"logon": 0,
"parentId": 0,
"parentEmail": null,
"status": 1,
"wallet": {
"totalBalance": "989.25471319",
"totalBalanceEv": 98925471319,
"availBalance": "989.05471319",
"availBalanceEv": 98905471319,
"freezeBalance": "0.20000000",
"freezeBalanceEv": 20000000,
"currency": "BTC",
"currencyCode": 1
},
"userMarginVo": [{
"currency": "BTC",
"accountBalance": "3.90032508",
"totalUsedBalance": "0.00015666",
"accountBalanceEv": 390032508,
"totalUsedBalanceEv": 15666,
"bonusBalanceEv": 0,
"bonusBalance": "0"
},{
"currency": "USD",
"accountBalance": "38050.35000000",
"totalUsedBalance": "0.00000000",
"accountBalanceEv": 380503500,
"totalUsedBalanceEv": 0,
"bonusBalanceEv": 0,
"bonusBalance": "0"
}]
}]
}`)
s.mockDo(data, nil)
defer s.assertDo()
s.assertReq(func(r *request) {
e := newSignedRequest()
s.assertRequestEqual(e, r)
})
res, err := s.client.NewGetUserWalletService().Do(newContext())
s.r().NoError(err)
e := []*UserWallet{{
UserID: 123123,
Email: "x**@**.com",
NickName: "nickName",
PasswordState: 1,
ClientCnt: 0,
Totp: 1,
Logon: 0,
ParentID: 0,
ParentEmail: "",
Status: 1,
Wallet: &WalletUserWallet{
TotalBalance: "989.25471319",
TotalBalanceEv: 98925471319,
AvailBalance: "989.05471319",
AvailBalanceEv: 98905471319,
FreezeBalance: "0.20000000",
FreezeBalanceEv: 20000000,
Currency: "BTC",
CurrencyCode: 1,
},
UserMarginVo: []*UserMarginUserWalletVo{{
Currency: "BTC",
AccountBalance: "3.90032508",
TotalUsedBalance: "0.00015666",
AccountBalanceEv: 390032508,
TotalUsedBalanceEv: 15666,
BonusBalanceEv: 0,
BonusBalance: "0",
}},
}}
s.assertAccountEqual(e, res)
}
func (s *walletServiceTestSuite) assertAccountEqual(e, a []*UserWallet) {
r := s.r()
for i := 0; i < len(a); i++ {
r.Equal(e[i].UserID, a[i].UserID, "UserID")
r.Equal(e[i].Email, a[i].Email, "Email")
r.Equal(e[i].NickName, a[i].NickName, "NickName")
r.Equal(e[i].PasswordState, a[i].PasswordState, "PasswordState")
r.Equal(e[i].ClientCnt, a[i].ClientCnt, "ClientCnt")
r.Equal(e[i].Totp, a[i].Totp, "Totp")
r.Equal(e[i].Logon, a[i].Logon, "Logon")
r.Equal(e[i].ParentID, a[i].ParentID, "ParentID")
r.Equal(e[i].ParentEmail, a[i].ParentEmail, "ParentEmail")
r.Equal(e[i].Status, a[i].Status, "Status")
r.Equal(e[i].Wallet.TotalBalance, a[i].Wallet.TotalBalance, "TotalBalance")
r.Equal(e[i].Wallet.TotalBalanceEv, a[i].Wallet.TotalBalanceEv, "TotalBalanceEv")
r.Equal(e[i].Wallet.AvailBalance, a[i].Wallet.AvailBalance, "AvailBalance")
r.Equal(e[i].Wallet.AvailBalanceEv, a[i].Wallet.AvailBalanceEv, "AvailBalanceEv")
r.Equal(e[i].Wallet.FreezeBalance, a[i].Wallet.FreezeBalance, "FreezeBalance")
r.Equal(e[i].Wallet.FreezeBalanceEv, a[i].Wallet.FreezeBalanceEv, "FreezeBalanceEv")
r.Equal(e[i].Wallet.Currency, a[i].Wallet.Currency, "Currency")
r.Equal(e[i].Wallet.CurrencyCode, a[i].Wallet.CurrencyCode, "CurrencyCode")
for j := 0; j < len(a); j++ {
r.Equal(e[i].UserMarginVo[j].Currency, a[i].UserMarginVo[j].Currency, "Currency")
r.Equal(e[i].UserMarginVo[j].AccountBalance, a[i].UserMarginVo[j].AccountBalance, "AccountBalance")
r.Equal(e[i].UserMarginVo[j].TotalUsedBalance, a[i].UserMarginVo[j].TotalUsedBalance, "TotalUsedBalance")
r.Equal(e[i].UserMarginVo[j].AccountBalanceEv, a[i].UserMarginVo[j].AccountBalanceEv, "AccountBalanceEv")
r.Equal(e[i].UserMarginVo[j].TotalUsedBalanceEv, a[i].UserMarginVo[j].TotalUsedBalanceEv, "TotalUsedBalanceEv")
r.Equal(e[i].UserMarginVo[j].BonusBalanceEv, a[i].UserMarginVo[j].BonusBalanceEv, "BonusBalanceEv")
r.Equal(e[i].UserMarginVo[j].BonusBalance, a[i].UserMarginVo[j].BonusBalance, "BonusBalance")
}
}
}
func (s *walletServiceTestSuite) TestExchangeMarginService() {
data := []byte(`{
"code": 0,
"msg": "OK",
"data": {
"moveOp": 0,
"fromCurrencyName": "BTC",
"toCurrencyName": "BTC",
"fromAmount": "0.10000000",
"toAmount": "0.10000000",
"linkKey": "2431ca9b-2dd4-44b8-91f3-2539bb62db2d",
"status": 10
}
}`)
s.mockDo(data, nil)
defer s.assertDo()
moveOp := float64(0)
btcAmount := float64(10)
s.assertReq(func(r *request) {
e := newSignedRequest().setFormParams(params{
"moveOp": moveOp,
"btcAmount": btcAmount,
})
s.assertRequestEqual(e, r)
})
res, err := s.client.NewExchangeMarginService().MoveOp(0).BtcAmount(btcAmount).Do(newContext())
s.r().NoError(err)
e := &ExchangeMargin{
MoveOp: 0,
FromCurrencyName: "BTC",
ToCurrencyName: "BTC",
FromAmount: "0.10000000",
ToAmount: "0.10000000",
LinkKey: "2431ca9b-2dd4-44b8-91f3-2539bb62db2d",
Status: 10,
}
s.assertExchangeMarginEquals(e, res)
}
func (s *walletServiceTestSuite) assertExchangeMarginEquals(e, a *ExchangeMargin) {
r := s.r()
r.Equal(e.MoveOp, a.MoveOp, "MoveOp")
r.Equal(e.FromCurrencyName, a.FromCurrencyName, "FromCurrencyName")
r.Equal(e.ToCurrencyName, a.ToCurrencyName, "ToCurrencyName")
r.Equal(e.FromAmount, a.FromAmount, "FromAmount")
r.Equal(e.ToAmount, a.ToAmount, "ToAmount")
r.Equal(e.LinkKey, a.LinkKey, "LinkKey")
r.Equal(e.Status, a.Status, "Status")
}