Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic implementation of liquidity_pools?account #426

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
public class LiquidityPoolsRequestBuilder extends RequestBuilder {
private static final String RESERVES_PARAMETER_NAME = "reserves";
private static final String ACCOUNT_PARAMETER_NAME = "account";

public LiquidityPoolsRequestBuilder(OkHttpClient httpClient, HttpUrl serverURI) {
super(httpClient, serverURI, "liquidity_pools");
Expand Down Expand Up @@ -69,6 +70,18 @@ public LiquidityPoolsRequestBuilder forReserves(String... reserves) {
uriBuilder.setQueryParameter(RESERVES_PARAMETER_NAME, String.join(",", reserves));
return this;
}

/**
* Returns all liquidity pools the specified account is participating in.
*
* @param account Account ID to filter liquidity pools
* @return current {@link LiquidityPoolsRequestBuilder} instance
* @see <a href="https://developers.stellar.org/api/resources/liquiditypools/list/">LiquidityPools</a>
*/
public LiquidityPoolsRequestBuilder forAccount(String account) {
uriBuilder.setQueryParameter(ACCOUNT_PARAMETER_NAME, account);
return this;
}

/**
* Requests specific <code>uri</code> and returns {@link Page} of {@link LiquidityPoolResponse}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,23 @@ public void testForReserves() {
.buildUri();
assertEquals("https://horizon-testnet.stellar.org/liquidity_pools?reserves=EURT%3AGAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S%2CPHP%3AGAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S", uri.toString());
}

@Test
public void testForAccount() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's not established here yet on other tests, but might be worthwhile to include coverage of an additional test for clearing the parameter from the builder, i.e.LiquidityPoolsRequestBuilder.forAccount(null) is valid, what would be the expected url if that is called or called in succession after first doing .forAccount("xyz")an allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do that. I tried with forReserves(String...) but of course there is a NPE on forReserves(null).
Does a pass is required on this kind of method call?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forReserves(String ...)interface prevents null parameter, might be worth a bit more coverage to assert a second call with different values for any of these builder methods, and verify if result is supposed to append or reset, It depends on okhttp3.HttpUrl.Builder, then can merge, as the PR looks good.

Server server = new Server("https://horizon-testnet.stellar.org");
HttpUrl uri = server.liquidityPools()
.forAccount("GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S")
.buildUri();
assertEquals("https://horizon-testnet.stellar.org/liquidity_pools?account=GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S", uri.toString());
}

@Test
public void testForAccountClear() {
Server server = new Server("https://horizon-testnet.stellar.org");
HttpUrl uri = server.liquidityPools()
.forAccount("GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S")
.forAccount(null)
.buildUri();
assertEquals("https://horizon-testnet.stellar.org/liquidity_pools?account", uri.toString());
}
}