forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strict_send_paths_request_test.go
117 lines (98 loc) · 4.37 KB
/
strict_send_paths_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
111
112
113
114
115
116
117
package horizonclient
import (
"testing"
"github.com/stellar/go/support/http/httptest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestStrictSendPathsRequestBuildUrl(t *testing.T) {
pr := StrictSendPathsRequest{}
endpoint, err := pr.BuildURL()
// It should return no errors and paths endpoint
// Horizon will return an error though because there are no parameters
require.NoError(t, err)
assert.Equal(t, "paths/strict-send", endpoint)
pr = StrictSendPathsRequest{
SourceAmount: "100",
SourceAssetCode: "NGN",
SourceAssetIssuer: "GDZST3XVCDTUJ76ZAV2HA72KYQODXXZ5PTMAPZGDHZ6CS7RO7MGG3DBM",
SourceAssetType: AssetType4,
DestinationAccount: "GDZST3XVCDTUJ76ZAV2HA72KYQODXXZ5PTMAPZGDHZ6CS7RO7MGG3DBM",
}
endpoint, err = pr.BuildURL()
// It should return a valid endpoint and no errors
require.NoError(t, err)
assert.Equal(
t,
"paths/strict-send?destination_account=GDZST3XVCDTUJ76ZAV2HA72KYQODXXZ5PTMAPZGDHZ6CS7RO7MGG3DBM&source_amount=100&source_asset_code=NGN&source_asset_issuer=GDZST3XVCDTUJ76ZAV2HA72KYQODXXZ5PTMAPZGDHZ6CS7RO7MGG3DBM&source_asset_type=credit_alphanum4",
endpoint,
)
pr = StrictSendPathsRequest{
SourceAmount: "100",
SourceAssetCode: "USD",
SourceAssetIssuer: "GDUKMGUGDZQK6YHYA5Z6AY2G4XDSZPSZ3SW5UN3ARVMO6QSRDWP5YLEX",
SourceAssetType: AssetType4,
DestinationAssets: "EURT:GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S,native",
}
endpoint, err = pr.BuildURL()
require.NoError(t, err)
assert.Equal(
t,
"paths/strict-send?destination_assets=EURT%3AGAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S%2Cnative&source_amount=100&source_asset_code=USD&source_asset_issuer=GDUKMGUGDZQK6YHYA5Z6AY2G4XDSZPSZ3SW5UN3ARVMO6QSRDWP5YLEX&source_asset_type=credit_alphanum4",
endpoint,
)
}
func TestStrictSendPathsRequest(t *testing.T) {
hmock := httptest.NewClient()
client := &Client{
HorizonURL: "https://localhost/",
HTTP: hmock,
}
pr := StrictSendPathsRequest{
SourceAmount: "20",
SourceAssetCode: "USD",
SourceAssetIssuer: "GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN",
SourceAssetType: AssetType4,
DestinationAccount: "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU",
}
hmock.On(
"GET",
"https://localhost/paths/strict-send?destination_account=GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU&source_amount=20&source_asset_code=USD&source_asset_issuer=GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN&source_asset_type=credit_alphanum4",
).ReturnString(200, pathsResponse)
paths, err := client.StrictSendPaths(pr)
assert.NoError(t, err)
assert.Len(t, paths.Embedded.Records, 3)
pr = StrictSendPathsRequest{
SourceAmount: "20",
SourceAssetCode: "USD",
SourceAssetIssuer: "GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN",
SourceAssetType: AssetType4,
DestinationAssets: "EUR:GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN",
}
hmock.On(
"GET",
"https://localhost/paths/strict-send?destination_assets=EUR%3AGDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN&source_amount=20&source_asset_code=USD&source_asset_issuer=GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN&source_asset_type=credit_alphanum4",
).ReturnString(200, pathsResponse)
paths, err = client.StrictSendPaths(pr)
assert.NoError(t, err)
assert.Len(t, paths.Embedded.Records, 3)
pr = StrictSendPathsRequest{
SourceAmount: "20",
SourceAssetCode: "USD",
SourceAssetIssuer: "GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN",
SourceAssetType: AssetType4,
DestinationAssets: "EUR:GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN",
DestinationAccount: "GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN",
}
hmock.On(
"GET",
"https://localhost/paths/strict-send?destination_account=GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN&destination_assets=EUR%3AGDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN&source_amount=20&source_asset_code=USD&source_asset_issuer=GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN&source_asset_type=credit_alphanum4",
).ReturnString(400, badRequestResponse)
_, err = client.StrictSendPaths(pr)
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")
}
}