-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clients/horizonclient: fix multi-parameter url for claimable balance …
- Loading branch information
1 parent
463d2b9
commit 489c091
Showing
3 changed files
with
67 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package horizonclient | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestClaimableBalanceBuildUrl(t *testing.T) { | ||
|
||
cbr := ClaimableBalanceRequest{ | ||
ID: "1235", | ||
} | ||
url, err := cbr.BuildURL() | ||
assert.Equal(t, "claimable_balances/1235", url) | ||
assert.NoError(t, err) | ||
|
||
//if the ID is included, you cannot include another parameter | ||
cbr = ClaimableBalanceRequest{ | ||
ID: "1235", | ||
Claimant: "CLAIMANTADDRESS", | ||
} | ||
_, err = cbr.BuildURL() | ||
assert.EqualError(t, err, "invalid request: too many parameters") | ||
|
||
//if you have two parameters, and neither of them are ID, it must use both in the URL | ||
cbr = ClaimableBalanceRequest{ | ||
Claimant: "CLAIMANTADDRESS", | ||
Asset: "TEST:ISSUERADDRESS", | ||
} | ||
url, err = cbr.BuildURL() | ||
assert.NoError(t, err) | ||
assert.Equal(t, "claimable_balances?asset=TEST%3AISSUERADDRESS&claimant=CLAIMANTADDRESS", url) | ||
|
||
//check limit | ||
cbr = ClaimableBalanceRequest{ | ||
Claimant: "CLAIMANTADDRESS", | ||
Asset: "TEST:ISSUERADDRESS", | ||
Limit: 200, | ||
} | ||
url, err = cbr.BuildURL() | ||
assert.NoError(t, err) | ||
assert.Equal(t, "claimable_balances?asset=TEST%3AISSUERADDRESS&claimant=CLAIMANTADDRESS&limit=200", url) | ||
|
||
cbr = ClaimableBalanceRequest{ | ||
Claimant: "CLAIMANTADDRESS", | ||
Asset: "TEST:ISSUERADDRESS", | ||
Limit: 201, | ||
} | ||
_, err = cbr.BuildURL() | ||
assert.EqualError(t, err, "invalid request: limit 201 is greater than limit max of 200") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters