-
Notifications
You must be signed in to change notification settings - Fork 159
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
LiquidityPoolIDDeserializer is missing from the PageDeserializer. #422
Merged
sreuland
merged 2 commits into
lightsail-network:master
from
vinamogit:fix-lp-id-deserialization-in-page
May 3, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package org.stellar.sdk.responses; | ||
|
||
import org.junit.Test; | ||
import org.stellar.sdk.LiquidityPoolID; | ||
|
||
import com.google.common.base.Optional; | ||
import com.google.gson.reflect.TypeToken; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import org.junit.Test; | ||
|
||
public class AccountsPageDeserializerTest extends TestCase { | ||
@Test | ||
public void testDeserialize() { | ||
|
@@ -17,6 +19,15 @@ public void testDeserialize() { | |
assertEquals(accountsPage.getLinks().getPrev().getHref(), "/accounts?order=desc&limit=10&cursor=1"); | ||
assertEquals(accountsPage.getLinks().getSelf().getHref(), "/accounts?order=asc&limit=10&cursor="); | ||
} | ||
|
||
@Test | ||
public void testDeserializeWithLiquidityPoolBalance() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great test coverage, do you think also worth adding one more check on regression aspect, i.e.:
style-wise, good to remove the extra lines. |
||
Page<AccountResponse> accountsPage = GsonSingleton.getInstance().fromJson(jsonLiquidityPool, new TypeToken<Page<AccountResponse>>() {}.getType()); | ||
|
||
assertEquals(accountsPage.getRecords().get(0).getAccountId(), "GDZZYLIIJ24HWAVWAQ2PJVNKHUJLJVVLFY2SSLYINBHDY5KZTLPTEST"); | ||
assertEquals(accountsPage.getRecords().get(0).getBalances()[0].getLiquidityPoolID(), Optional.of(new LiquidityPoolID("a468d41d8e9b8f3c7209651608b74b7db7ac9952dcae0cdf24871d1d9c7b0088"))); | ||
assertEquals(accountsPage.getRecords().get(0).getBalances()[1].getLiquidityPoolID(), Optional.absent()); | ||
} | ||
|
||
String json = "{\n" + | ||
" \"_embedded\": {\n" + | ||
|
@@ -85,4 +96,116 @@ public void testDeserialize() { | |
" }\n" + | ||
" }\n" + | ||
"}"; | ||
|
||
String jsonLiquidityPool = "{\n" + | ||
" \"_links\": {\n" + | ||
" \"self\": {\n" + | ||
" \"href\": \"https://horizon.publicnode.org/accounts/?asset=USDC%3AGA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN&cursor=&limit=1&order=desc\"\n" + | ||
" },\n" + | ||
" \"next\": {\n" + | ||
" \"href\": \"https://horizon.publicnode.org/accounts/?asset=USDC%3AGA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN&cursor=GDZZYLIIJ24HWAVWAQ2PJVNKHUJLJVVLFY2SSLYINBHDY5KZTLPTEST&limit=1&order=desc\"\n" + | ||
" },\n" + | ||
" \"prev\": {\n" + | ||
" \"href\": \"https://horizon.publicnode.org/accounts/?asset=USDC%3AGA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN&cursor=GDZZYLIIJ24HWAVWAQ2PJVNKHUJLJVVLFY2SSLYINBHDY5KZTLPTEST&limit=1&order=asc\"\n" + | ||
" }\n" + | ||
" },\n" + | ||
" \"_embedded\": {\n" + | ||
" \"records\": [\n" + | ||
" {\n" + | ||
" \"_links\": {\n" + | ||
" \"self\": {\n" + | ||
" \"href\": \"https://horizon.publicnode.org/accounts/GDZZYLIIJ24HWAVWAQ2PJVNKHUJLJVVLFY2SSLYINBHDY5KZTLPTEST\"\n" + | ||
" },\n" + | ||
" \"transactions\": {\n" + | ||
" \"href\": \"https://horizon.publicnode.org/accounts/GDZZYLIIJ24HWAVWAQ2PJVNKHUJLJVVLFY2SSLYINBHDY5KZTLPTEST/transactions{?cursor,limit,order}\",\n" + | ||
" \"templated\": true\n" + | ||
" },\n" + | ||
" \"operations\": {\n" + | ||
" \"href\": \"https://horizon.publicnode.org/accounts/GDZZYLIIJ24HWAVWAQ2PJVNKHUJLJVVLFY2SSLYINBHDY5KZTLPTEST/operations{?cursor,limit,order}\",\n" + | ||
" \"templated\": true\n" + | ||
" },\n" + | ||
" \"payments\": {\n" + | ||
" \"href\": \"https://horizon.publicnode.org/accounts/GDZZYLIIJ24HWAVWAQ2PJVNKHUJLJVVLFY2SSLYINBHDY5KZTLPTEST/payments{?cursor,limit,order}\",\n" + | ||
" \"templated\": true\n" + | ||
" },\n" + | ||
" \"effects\": {\n" + | ||
" \"href\": \"https://horizon.publicnode.org/accounts/GDZZYLIIJ24HWAVWAQ2PJVNKHUJLJVVLFY2SSLYINBHDY5KZTLPTEST/effects{?cursor,limit,order}\",\n" + | ||
" \"templated\": true\n" + | ||
" },\n" + | ||
" \"offers\": {\n" + | ||
" \"href\": \"https://horizon.publicnode.org/accounts/GDZZYLIIJ24HWAVWAQ2PJVNKHUJLJVVLFY2SSLYINBHDY5KZTLPTEST/offers{?cursor,limit,order}\",\n" + | ||
" \"templated\": true\n" + | ||
" },\n" + | ||
" \"trades\": {\n" + | ||
" \"href\": \"https://horizon.publicnode.org/accounts/GDZZYLIIJ24HWAVWAQ2PJVNKHUJLJVVLFY2SSLYINBHDY5KZTLPTEST/trades{?cursor,limit,order}\",\n" + | ||
" \"templated\": true\n" + | ||
" },\n" + | ||
" \"data\": {\n" + | ||
" \"href\": \"https://horizon.publicnode.org/accounts/GDZZYLIIJ24HWAVWAQ2PJVNKHUJLJVVLFY2SSLYINBHDY5KZTLPTEST/data/{key}\",\n" + | ||
" \"templated\": true\n" + | ||
" }\n" + | ||
" },\n" + | ||
" \"id\": \"GDZZYLIIJ24HWAVWAQ2PJVNKHUJLJVVLFY2SSLYINBHDY5KZTLPTEST\",\n" + | ||
" \"account_id\": \"GDZZYLIIJ24HWAVWAQ2PJVNKHUJLJVVLFY2SSLYINBHDY5KZTLPTEST\",\n" + | ||
" \"sequence\": \"166506652181200896\",\n" + | ||
" \"subentry_count\": 5,\n" + | ||
" \"last_modified_ledger\": 38767851,\n" + | ||
" \"last_modified_time\": \"2021-12-17T20:22:00Z\",\n" + | ||
" \"thresholds\": {\n" + | ||
" \"low_threshold\": 20,\n" + | ||
" \"med_threshold\": 20,\n" + | ||
" \"high_threshold\": 20\n" + | ||
" },\n" + | ||
" \"flags\": {\n" + | ||
" \"auth_required\": false,\n" + | ||
" \"auth_revocable\": false,\n" + | ||
" \"auth_immutable\": false,\n" + | ||
" \"auth_clawback_enabled\": false\n" + | ||
" },\n" + | ||
" \"balances\": [\n" + | ||
" {\n" + | ||
" \"balance\": \"974462.6017340\",\n" + | ||
" \"liquidity_pool_id\": \"a468d41d8e9b8f3c7209651608b74b7db7ac9952dcae0cdf24871d1d9c7b0088\",\n" + | ||
" \"limit\": \"922337203685.4775807\",\n" + | ||
" \"last_modified_ledger\": 38809512,\n" + | ||
" \"is_authorized\": false,\n" + | ||
" \"is_authorized_to_maintain_liabilities\": false,\n" + | ||
" \"asset_type\": \"liquidity_pool_shares\"\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \"balance\": \"0.0000000\",\n" + | ||
" \"limit\": \"922337203685.4775807\",\n" + | ||
" \"buying_liabilities\": \"0.0000000\",\n" + | ||
" \"selling_liabilities\": \"0.0000000\",\n" + | ||
" \"sponsor\": \"GCZGSFPITKVJPJERJIVLCQK5YIHYTDXCY45ZHU3IRPBP53SXSCALTEST\",\n" + | ||
" \"last_modified_ledger\": 38767851,\n" + | ||
" \"is_authorized\": true,\n" + | ||
" \"is_authorized_to_maintain_liabilities\": true,\n" + | ||
" \"asset_type\": \"credit_alphanum4\",\n" + | ||
" \"asset_code\": \"USDC\",\n" + | ||
" \"asset_issuer\": \"GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN\"\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \"balance\": \"0.0000000\",\n" + | ||
" \"buying_liabilities\": \"0.0000000\",\n" + | ||
" \"selling_liabilities\": \"0.0000000\",\n" + | ||
" \"asset_type\": \"native\"\n" + | ||
" }\n" + | ||
" ],\n" + | ||
" \"signers\": [\n" + | ||
" {\n" + | ||
" \"weight\": 10,\n" + | ||
" \"key\": \"GDZZYLIIJ24HWAVWAQ2PJVNKHUJLJVVLFY2SSLYINBHDY5KZTLPTEST\",\n" + | ||
" \"type\": \"ed25519_public_key\"\n" + | ||
" }\n" + | ||
" ],\n" + | ||
" \"data\": {},\n" + | ||
" \"num_sponsoring\": 0,\n" + | ||
" \"num_sponsored\": 7,\n" + | ||
" \"sponsor\": \"GCZGSFPITKVJPJERJIVLCQK5YIHYTDXCY45ZHU3IRPBP53SXSCALTEST\",\n" + | ||
" \"paging_token\": \"GDZZYLIIJ24HWAVWAQ2PJVNKHUJLJVVLFY2SSLYINBHDY5KZTLPTEST\"\n" + | ||
" }\n" + | ||
" ]\n" + | ||
" }\n" + | ||
"}"; | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I see the same type adapter registration for LiquidityPoolID done up at the main gson instance used by all response handlers:
https://github.com/vinamogit/java-stellar-sdk/blob/fix-lp-id-deserialization-in-page/src/main/java/org/stellar/sdk/responses/GsonSingleton.java#L39
Do you know why this is not getting used by gson to resolve the LiquidityPoolID in
TradeResponse
during unmarshaling? It looks TradesRequestBuilder.execute uses the ResponseHandler which in turn uses that gson instance which includes the type registration. If re-registering here at page deser is needed, so be it, nice find!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know anything about Gson, my guess is that it's either because of generic type or because a new Gsonbuilder is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is that there are several Gson instances, each need to know the deserializers.
We could avoid the double maintenance between GsonSingleton and PageDeserializer by using the JsonAdapter annotation on all the types which are not Page.
The only type that would need to be registered with both GsonBuilders will be the TransactionDeserializer since it uses a third instance of Gson to reconciliate the memo with its memo_type.
I published a branch for comparison:
vinamogit@fe9c9de