forked from adshao/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_service_test.go
87 lines (80 loc) · 2.18 KB
/
account_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
package binance
import (
"testing"
"github.com/stretchr/testify/suite"
)
type accountServiceTestSuite struct {
baseTestSuite
}
func TestAccountService(t *testing.T) {
suite.Run(t, new(accountServiceTestSuite))
}
func (s *accountServiceTestSuite) TestGetAccount() {
data := []byte(`{
"makerCommission": 15,
"takerCommission": 15,
"buyerCommission": 0,
"sellerCommission": 0,
"canTrade": true,
"canWithdraw": true,
"canDeposit": true,
"balances": [
{
"asset": "BTC",
"free": "4723846.89208129",
"locked": "0.00000000"
},
{
"asset": "LTC",
"free": "4763368.68006011",
"locked": "0.00000000"
}
]
}`)
s.mockDo(data, nil)
defer s.assertDo()
s.assertReq(func(r *request) {
e := newSignedRequest()
s.assertRequestEqual(e, r)
})
res, err := s.client.NewGetAccountService().Do(newContext())
s.r().NoError(err)
e := &Account{
MakerCommission: 15,
TakerCommission: 15,
BuyerCommission: 0,
SellerCommission: 0,
CanTrade: true,
CanWithdraw: true,
CanDeposit: true,
Balances: []Balance{
{
Asset: "BTC",
Free: "4723846.89208129",
Locked: "0.00000000",
},
{
Asset: "LTC",
Free: "4763368.68006011",
Locked: "0.00000000",
},
},
}
s.assertAccountEqual(e, res)
}
func (s *accountServiceTestSuite) assertAccountEqual(e, a *Account) {
r := s.r()
r.Equal(e.MakerCommission, a.MakerCommission, "MakerCommission")
r.Equal(e.TakerCommission, a.TakerCommission, "TakerCommission")
r.Equal(e.BuyerCommission, a.BuyerCommission, "BuyerCommission")
r.Equal(e.SellerCommission, a.SellerCommission, "SellerCommission")
r.Equal(e.CanTrade, a.CanTrade, "CanTrade")
r.Equal(e.CanWithdraw, a.CanWithdraw, "CanWithdraw")
r.Equal(e.CanDeposit, a.CanDeposit, "CanDeposit")
r.Len(a.Balances, len(e.Balances))
for i := 0; i < len(a.Balances); i++ {
r.Equal(e.Balances[i].Asset, a.Balances[i].Asset, "Asset")
r.Equal(e.Balances[i].Free, a.Balances[i].Free, "Free")
r.Equal(e.Balances[i].Locked, a.Balances[i].Locked, "Locked")
}
}