forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
liquidity_pools_request_test.go
110 lines (95 loc) · 3.23 KB
/
liquidity_pools_request_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
package horizonclient
import (
"testing"
hProtocol "github.com/stellar/go/protocols/horizon"
"github.com/stellar/go/support/http/httptest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLiquidityPoolsRequestBuildUrl(t *testing.T) {
// It should return valid liquidity_pools endpoint and no errors
endpoint, err := LiquidityPoolsRequest{}.BuildURL()
require.NoError(t, err)
assert.Equal(t, "liquidity_pools", endpoint)
// It should return valid liquidity_pools endpoint and no errors
endpoint, err = LiquidityPoolsRequest{Order: OrderDesc}.BuildURL()
require.NoError(t, err)
assert.Equal(t, "liquidity_pools?order=desc", endpoint)
// It should return valid liquidity_pools endpoint and no errors
endpoint, err = LiquidityPoolsRequest{Reserves: []string{
"EURT:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S",
"PHP:GBUQWP3BOUZX34TOND2QV7QQ7K7VJTG6VSE7WMLBTMDJLLAW7YKGU6EP",
}}.BuildURL()
require.NoError(t, err)
assert.Equal(t, "liquidity_pools?reserves=EURT%3AGAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S%2CPHP%3AGBUQWP3BOUZX34TOND2QV7QQ7K7VJTG6VSE7WMLBTMDJLLAW7YKGU6EP", endpoint)
}
func TestLiquidityPoolsRequest(t *testing.T) {
hmock := httptest.NewClient()
client := &Client{
HorizonURL: "https://localhost/",
HTTP: hmock,
}
request := LiquidityPoolsRequest{}
hmock.On(
"GET",
"https://localhost/liquidity_pools",
).ReturnString(200, liquidityPoolsResponse)
response, err := client.LiquidityPools(request)
if assert.NoError(t, err) {
assert.IsType(t, response, hProtocol.LiquidityPoolsPage{})
links := response.Links
assert.Equal(t, links.Self.Href, "https://horizon.stellar.org/liquidity_pools?limit=200\u0026order=asc")
assert.Equal(t, links.Next.Href, "https://horizon.stellar.org/liquidity_pools?limit=200\u0026order=asc")
record := response.Embedded.Records[0]
assert.IsType(t, record, hProtocol.LiquidityPool{})
assert.Equal(t, "abcdef", record.ID)
assert.Equal(t, uint32(30), record.FeeBP)
assert.Equal(t, uint64(300), record.TotalTrustlines)
assert.Equal(t, "5000.0000000", record.TotalShares)
}
// failure response
request = LiquidityPoolsRequest{}
hmock.On(
"GET",
"https://localhost/liquidity_pools",
).ReturnString(400, badRequestResponse)
_, err = client.LiquidityPools(request)
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "horizon error")
horizonError, ok := err.(*Error)
assert.Equal(t, ok, true)
assert.Equal(t, horizonError.Problem.Title, "Bad Request")
}
}
var liquidityPoolsResponse = `{
"_links": {
"self": {
"href": "https://horizon.stellar.org/liquidity_pools?limit=200\u0026order=asc"
},
"next": {
"href": "https://horizon.stellar.org/liquidity_pools?limit=200\u0026order=asc"
}
},
"_embedded": {
"records": [
{
"id": "abcdef",
"paging_token": "abcdef",
"fee_bp": 30,
"type": "constant_product",
"total_trustlines": "300",
"total_shares": "5000.0000000",
"reserves": [
{
"amount": "1000.0000005",
"asset": "EURT:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S"
},
{
"amount": "2000.0000000",
"asset": "PHP:GBUQWP3BOUZX34TOND2QV7QQ7K7VJTG6VSE7WMLBTMDJLLAW7YKGU6EP"
}
]
}
]
}
}`