Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into release-0.30.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sreuland committed Jan 3, 2022
2 parents d328dd6 + 4067ab7 commit 13e4e86
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ As this project is pre 1.0, breaking changes may happen for minor version bumps.

* Fix missing Liquidity Pool ID in AccountResponse Balance ([#379](https://github.com/stellar/java-stellar-sdk/pull/379)).
* Fix null pointer when calling ChangeTrustOperationResponse.getAsset() for LiquidityPool trust line ([#378](https://github.com/stellar/java-stellar-sdk/pull/378)).
* Changed the access modifiers of the inner static classes of `AccountResponse` to public ([#390](https://github.com/stellar/java-stellar-sdk/pull/390))
* Changed the access modifiers of the inner static classes of `AccountResponse` to public ([#390](https://github.com/stellar/java-stellar-sdk/pull/390)).
* Use the new ClaimableBalance Predicate AbsBeforeEpoch field to avoid parsing errors on potential large dates in AbsBefore ([#394](https://github.com/stellar/java-stellar-sdk/pull/394)).

### Breaking changes
* Changed offer ids to be represented in requests and response models as long data type. ([#386](https://github.com/stellar/java-stellar-sdk/pull/386)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public Predicate deserialize(JsonElement json, Type typeOfT, JsonDeserialization
return new Predicate.Or(inner);
}

if (obj.has("abs_before")) {
// backwards compatible for abs before, uses the newer abs_before_epoch if available from server
// otherwise if abs_before_epoch is absent, it will fall back to original attempt to parse abs_before date string
if (obj.has("abs_before_epoch")) {
return new Predicate.AbsBefore(obj.get("abs_before_epoch").getAsLong());
} else if (obj.has("abs_before")) {
String formattedDate = obj.get("abs_before").getAsString();
return new Predicate.AbsBefore(Instant.parse(formattedDate).getEpochSecond());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.stellar.sdk.Asset;
import org.stellar.sdk.AssetAmount;
import org.stellar.sdk.AssetTypeNative;
import org.stellar.sdk.Predicate;
import org.stellar.sdk.responses.effects.*;
import org.stellar.sdk.xdr.LiquidityPoolType;

Expand Down Expand Up @@ -245,6 +246,83 @@ public void testDeserializeAccountFlagsUpdatedEffect() {
assertEquals(effect.getLinks().getPrecedes().getHref(), "http://horizon-testnet.stellar.org/effects?order=asc&cursor=18970870550529-1");
}

@Test
public void testDeserializeClaimableBalanceClaimantCreatedEffect() {
String json = "{\n" +
" \"_links\": {\n" +
" \"operation\": {\n" +
" \"href\": \"https://horizon.stellar.org/operations/158104892991700993\"\n" +
" },\n" +
" \"succeeds\": {\n" +
" \"href\": \"https://horizon.stellar.org/effects?order=desc&cursor=158104892991700993-2\"\n" +
" },\n" +
" \"precedes\": {\n" +
" \"href\": \"https://horizon.stellar.org/effects?order=asc&cursor=158104892991700993-2\"\n" +
" }\n" +
" },\n" +
" \"id\": \"0158104892991700993-0000000002\",\n" +
" \"paging_token\": \"158104892991700993-2\",\n" +
" \"account\": \"GBQECQVAS2FJ7DLCUXDASZAJQLWPXNTCR2DGBPKQDO3QS66TJXLRHFIK\",\n" +
" \"type\": \"claimable_balance_claimant_created\",\n" +
" \"type_i\": 51,\n" +
" \"created_at\": \"2021-08-11T16:16:32Z\",\n" +
" \"asset\": \"KES:GA2MSSZKJOU6RNL3EJKH3S5TB5CDYTFQFWRYFGUJVIN5I6AOIRTLUHTO\",\n" +
" \"balance_id\": \"0000000071d3336fa6b6cf81fcbeda85a503ccfabc786ab1066594716f3f9551ea4b89ca\",\n" +
" \"amount\": \"0.0012200\",\n" +
" \"predicate\": {\n" +
" \"abs_before\": \"+39121901036-03-29T15:30:22Z\",\n" +
" \"abs_before_epoch\": \"1234567890982222222\"\n" +
" }\n" +
" }\n";

ClaimableBalanceClaimantCreatedEffectResponse effect = (ClaimableBalanceClaimantCreatedEffectResponse) GsonSingleton.getInstance().fromJson(json, EffectResponse.class);

assertEquals(effect.getAccount(), "GBQECQVAS2FJ7DLCUXDASZAJQLWPXNTCR2DGBPKQDO3QS66TJXLRHFIK");
assertEquals(effect.getCreatedAt(), "2021-08-11T16:16:32Z");
assertEquals(effect.getBalanceId(), "0000000071d3336fa6b6cf81fcbeda85a503ccfabc786ab1066594716f3f9551ea4b89ca");
assertEquals(effect.getType(), "claimable_balance_claimant_created");
assertSame(effect.getPredicate().getClass(), Predicate.AbsBefore.class);
assertEquals(((Predicate.AbsBefore)effect.getPredicate()).getTimestampSeconds(), 1234567890982222222L);
}

@Test
public void testBackwardsCompatAbsBeforeEpoch() {
String json = "{\n" +
" \"_links\": {\n" +
" \"operation\": {\n" +
" \"href\": \"https://horizon.stellar.org/operations/158104892991700993\"\n" +
" },\n" +
" \"succeeds\": {\n" +
" \"href\": \"https://horizon.stellar.org/effects?order=desc&cursor=158104892991700993-2\"\n" +
" },\n" +
" \"precedes\": {\n" +
" \"href\": \"https://horizon.stellar.org/effects?order=asc&cursor=158104892991700993-2\"\n" +
" }\n" +
" },\n" +
" \"id\": \"0158104892991700993-0000000002\",\n" +
" \"paging_token\": \"158104892991700993-2\",\n" +
" \"account\": \"GBQECQVAS2FJ7DLCUXDASZAJQLWPXNTCR2DGBPKQDO3QS66TJXLRHFIK\",\n" +
" \"type\": \"claimable_balance_claimant_created\",\n" +
" \"type_i\": 51,\n" +
" \"created_at\": \"2021-08-11T16:16:32Z\",\n" +
" \"asset\": \"KES:GA2MSSZKJOU6RNL3EJKH3S5TB5CDYTFQFWRYFGUJVIN5I6AOIRTLUHTO\",\n" +
" \"balance_id\": \"0000000071d3336fa6b6cf81fcbeda85a503ccfabc786ab1066594716f3f9551ea4b89ca\",\n" +
" \"amount\": \"0.0012200\",\n" +
" \"predicate\": {\n" +
" \"abs_before\": \"2021-11-21T07:24:10Z\"\n" +
" }\n" +
" }\n";

ClaimableBalanceClaimantCreatedEffectResponse effect = (ClaimableBalanceClaimantCreatedEffectResponse) GsonSingleton.getInstance().fromJson(json, EffectResponse.class);

assertEquals(effect.getAccount(), "GBQECQVAS2FJ7DLCUXDASZAJQLWPXNTCR2DGBPKQDO3QS66TJXLRHFIK");
assertEquals(effect.getCreatedAt(), "2021-08-11T16:16:32Z");
assertEquals(effect.getBalanceId(), "0000000071d3336fa6b6cf81fcbeda85a503ccfabc786ab1066594716f3f9551ea4b89ca");
assertEquals(effect.getType(), "claimable_balance_claimant_created");
assertSame(effect.getPredicate().getClass(), Predicate.AbsBefore.class);
assertEquals(((Predicate.AbsBefore)effect.getPredicate()).getTimestampSeconds(), 1637479450L);
}

@Test
public void testDeserializeAccountInflationDestinationUpdatedEffect() {
String json = "{\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1527,4 +1527,48 @@ public void testDeserializeLiquidityPoolWithdrawOperation() {
}
));
}

@Test
public void testDeserializeCreateClaimableBalanceOperation() {
String json = "{\n" +
" \n" +
" \"id\": \"158104892991700993\",\n" +
" \"paging_token\": \"158104892991700993\",\n" +
" \"transaction_successful\": true,\n" +
" \"source_account\": \"GAKFBRS24U3PEN6XDMEX4JEV5NGBARS2ZFF5O4CF3JL464SQSD4MDCPF\",\n" +
" \"type\": \"create_claimable_balance\",\n" +
" \"type_i\": 14,\n" +
" \"created_at\": \"2021-08-11T16:16:32Z\",\n" +
" \"transaction_hash\": \"c78e86007a0ee0bb0c717b02f5e306e524b4913b892e9983e7db4664a0c29841\",\n" +
" \"sponsor\": \"GAKFBRS24U3PEN6XDMEX4JEV5NGBARS2ZFF5O4CF3JL464SQSD4MDCPF\",\n" +
" \"asset\": \"KES:GA2MSSZKJOU6RNL3EJKH3S5TB5CDYTFQFWRYFGUJVIN5I6AOIRTLUHTO\",\n" +
" \"amount\": \"0.0012200\",\n" +
" \"claimants\": [\n" +
" {\n" +
" \"destination\": \"GBQECQVAS2FJ7DLCUXDASZAJQLWPXNTCR2DGBPKQDO3QS66TJXLRHFIK\",\n" +
" \"predicate\": {\n" +
" \"abs_before\": \"+39121901036-03-29T15:30:22Z\",\n" +
" \"abs_before_epoch\": \"1234567890982222222\"\n" +
" }\n" +
" },\n" +
" {\n" +
" \"destination\": \"GAKFBRS24U3PEN6XDMEX4JEV5NGBARS2ZFF5O4CF3JL464SQSD4MDCPF\",\n" +
" \"predicate\": {\n" +
" \"unconditional\": true\n" +
" }\n" +
" }\n" +
" ]\n" +
"}";

CreateClaimableBalanceOperationResponse operation = (CreateClaimableBalanceOperationResponse) GsonSingleton.getInstance().fromJson(json, OperationResponse.class);

assertEquals(operation.getId().longValue(), 158104892991700993L);
assertEquals(operation.getClaimants().size(), 2);
assertEquals(operation.getClaimants().get(0).getDestination(), "GBQECQVAS2FJ7DLCUXDASZAJQLWPXNTCR2DGBPKQDO3QS66TJXLRHFIK");
assertSame(operation.getClaimants().get(0).getPredicate().getClass(), Predicate.AbsBefore.class);
assertEquals(((Predicate.AbsBefore)operation.getClaimants().get(0).getPredicate()).getTimestampSeconds(), 1234567890982222222L);
assertEquals(operation.getClaimants().get(1).getDestination(), "GAKFBRS24U3PEN6XDMEX4JEV5NGBARS2ZFF5O4CF3JL464SQSD4MDCPF");
assertSame(operation.getClaimants().get(1).getPredicate().getClass(), Predicate.Unconditional.class);
assertEquals(operation.getType(), "create_claimable_balance");
}
}

0 comments on commit 13e4e86

Please sign in to comment.