forked from adshao/go-binance
/
lending_purchase_service_test.go
84 lines (75 loc) · 1.87 KB
/
lending_purchase_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
package binance
import (
"context"
"testing"
"github.com/stretchr/testify/suite"
)
type lendingPurchaseServiceTestSuite struct {
baseTestSuite
}
func TestLendingPurchaseService(t *testing.T) {
suite.Run(t, new(lendingPurchaseServiceTestSuite))
}
func (s *lendingPurchaseServiceTestSuite) TestListLendingPurchaseService() {
data := []byte(`
[
{
"amount": "100.00000000",
"asset": "USDT",
"createTime": 1575018510000,
"lendingType": "DAILY",
"productName": "USDT",
"purchaseId": 26055,
"status": "SUCCESS"
}
]
`)
s.mockDo(data, nil)
defer s.assertDo()
asset := `USDT`
startTime := int64(1508198532000)
endTime := int64(1508198532001)
s.assertReq(func(r *request) {
e := newSignedRequest().setParams(params{
`asset`: asset,
`size`: 1,
`current`: 1,
`lendingType`: `DAILY`,
`startTime`: startTime,
`endTime`: endTime,
`recvWindow`: 60000,
})
s.assertRequestEqual(e, r)
})
results, err := s.client.NewListLendingPurchaseService().
Asset(asset).
Size(1).
Current(1).
LendingType(`DAILY`).
StartTime(startTime).
EndTime(endTime).
Do(context.Background())
r := s.r()
r.NoError(err)
resultArr := *results
s.Len(resultArr, 1)
s.assertPurchaseEqual(&LendingPurchaseResponse{
Amount: `100.00000000`,
Asset: `USDT`,
CreateTime: 1575018510000,
LendingType: `DAILY`,
ProductName: `USDT`,
PurchaseID: 26055,
Status: `SUCCESS`,
}, &resultArr[0])
}
func (s *lendingPurchaseServiceTestSuite) assertPurchaseEqual(e, a *LendingPurchaseResponse) {
r := s.r()
r.Equal(e.Amount, a.Amount, `Amount`)
r.Equal(e.Asset, a.Asset, `Asset`)
r.Equal(e.CreateTime, a.CreateTime, `CreateTime`)
r.Equal(e.LendingType, a.LendingType, `LendingType`)
r.Equal(e.ProductName, a.ProductName, `ProductName`)
r.Equal(e.PurchaseID, a.PurchaseID, `PurchaseID`)
r.Equal(e.Status, a.Status, `Status`)
}