This repository has been archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add claimable balance endpoint
- Loading branch information
Showing
15 changed files
with
371 additions
and
61 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
stellar-dotnet-sdk-test/requests/ClaimableBalancesRequestBuilderTest.cs
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,68 @@ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using stellar_dotnet_sdk; | ||
using stellar_dotnet_sdk_test.responses; | ||
|
||
namespace stellar_dotnet_sdk_test.requests | ||
{ | ||
[TestClass] | ||
public class ClaimableBalancesRequestBuilderTest | ||
{ | ||
[TestMethod] | ||
public void TestForNativeAsset() | ||
{ | ||
var server = new Server("https://horizon-testnet.stellar.org"); | ||
var uri = server.ClaimableBalances.ForAsset(new AssetTypeNative()).BuildUri(); | ||
Assert.AreEqual("https://horizon-testnet.stellar.org/claimable_balances?asset=native", uri.ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void TestForCreditAsset() | ||
{ | ||
var asset = Asset.CreateNonNativeAsset("ABC", "GBM2LMVS2EG3GHJ5DKR7CKZ4TP6DQKCHRMDKCZK6WG2NGQVTLF35YE6O"); | ||
var server = new Server("https://horizon-testnet.stellar.org"); | ||
var uri = server.ClaimableBalances.ForAsset(asset).BuildUri(); | ||
Assert.AreEqual( | ||
"https://horizon-testnet.stellar.org/claimable_balances?asset=ABC:GBM2LMVS2EG3GHJ5DKR7CKZ4TP6DQKCHRMDKCZK6WG2NGQVTLF35YE6O", | ||
uri.ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void TestForClaimant() | ||
{ | ||
var claimant = KeyPair.FromAccountId("GBM2LMVS2EG3GHJ5DKR7CKZ4TP6DQKCHRMDKCZK6WG2NGQVTLF35YE6O"); | ||
var server = new Server("https://horizon-testnet.stellar.org"); | ||
var uri = server.ClaimableBalances.ForClaimant(claimant).BuildUri(); | ||
Assert.AreEqual( | ||
"https://horizon-testnet.stellar.org/claimable_balances?claimant=GBM2LMVS2EG3GHJ5DKR7CKZ4TP6DQKCHRMDKCZK6WG2NGQVTLF35YE6O", | ||
uri.ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void TestForSponsor() | ||
{ | ||
var sponsor = KeyPair.FromAccountId("GBM2LMVS2EG3GHJ5DKR7CKZ4TP6DQKCHRMDKCZK6WG2NGQVTLF35YE6O"); | ||
var server = new Server("https://horizon-testnet.stellar.org"); | ||
var uri = server.ClaimableBalances.ForSponsor(sponsor).BuildUri(); | ||
Assert.AreEqual( | ||
"https://horizon-testnet.stellar.org/claimable_balances?sponsor=GBM2LMVS2EG3GHJ5DKR7CKZ4TP6DQKCHRMDKCZK6WG2NGQVTLF35YE6O", | ||
uri.ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestClaimableBalance() | ||
{ | ||
var jsonResponse = File.ReadAllText(Path.Combine("testdata", "claimableBalance.json")); | ||
var fakeHttpClient = FakeHttpClient.CreateFakeHttpClient(jsonResponse); | ||
|
||
using (var server = new Server("https://horizon-testnet.stellar.org", fakeHttpClient)) | ||
{ | ||
var claimableBalance = | ||
await server.ClaimableBalances.ClaimableBalance( | ||
"00000000c582697b67cbec7f9ce64f4dc67bfb2bfd26318bb9f964f4d70e3f41f650b1e6"); | ||
ClaimableBalanceDeserializerTest.AssertTestData(claimableBalance); | ||
} | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
stellar-dotnet-sdk-test/responses/ClaimableBalanceDeserializerTest.cs
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,47 @@ | ||
using System.IO; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json; | ||
using stellar_dotnet_sdk.responses; | ||
|
||
namespace stellar_dotnet_sdk_test.responses | ||
{ | ||
[TestClass] | ||
public class ClaimableBalanceDeserializerTest | ||
{ | ||
[TestMethod] | ||
public void TestDeserialize() | ||
{ | ||
var json = File.ReadAllText(Path.Combine("testdata", "claimableBalance.json")); | ||
var claimableBalance = JsonSingleton.GetInstance<ClaimableBalanceResponse>(json); | ||
AssertTestData(claimableBalance); | ||
} | ||
|
||
[TestMethod] | ||
public void TestSerializeDeserialize() | ||
{ | ||
var json = File.ReadAllText(Path.Combine("testdata", "claimableBalance.json")); | ||
var claimableBalance = JsonConvert.DeserializeObject<ClaimableBalanceResponse>(json); | ||
|
||
var serialized = JsonConvert.SerializeObject(claimableBalance); | ||
var back = JsonConvert.DeserializeObject<ClaimableBalanceResponse>(serialized); | ||
|
||
Assert.AreEqual(claimableBalance.LastModifiedLedger, back.LastModifiedLedger); | ||
Assert.AreEqual(claimableBalance.Asset, back.Asset); | ||
Assert.AreEqual(claimableBalance.Sponsor, back.Sponsor); | ||
} | ||
|
||
public static void AssertTestData(ClaimableBalanceResponse claimableBalance) | ||
{ | ||
Assert.AreEqual("00000000c582697b67cbec7f9ce64f4dc67bfb2bfd26318bb9f964f4d70e3f41f650b1e6", claimableBalance.Id); | ||
Assert.AreEqual("native", claimableBalance.Asset); | ||
Assert.AreEqual("GB5N4275ETC6A77K4DTDL3EFAQMN66PC7UITDUZUBM7Y6LDJP7EYSGOB", claimableBalance.Sponsor); | ||
Assert.AreEqual(66835, claimableBalance.LastModifiedLedger); | ||
Assert.AreEqual("66835-00000000c582697b67cbec7f9ce64f4dc67bfb2bfd26318bb9f964f4d70e3f41f650b1e6", claimableBalance.PagingToken); | ||
|
||
Assert.AreEqual(1, claimableBalance.Claimants.Length); | ||
var claimant = claimableBalance.Claimants[0]; | ||
Assert.AreEqual("GD2I2F7SWUHBAD7XBIZTF7MBMWQYWJVEFMWTXK76NSYVOY52OJRYNTIY", claimant.Destination); | ||
Assert.AreEqual(true, claimant.Predicate.Unconditional); | ||
} | ||
} | ||
} |
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
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,21 @@ | ||
{ | ||
"_links": { | ||
"self": { | ||
"href": "https://horizon-protocol14.stellar.org/claimable_balances/00000000c582697b67cbec7f9ce64f4dc67bfb2bfd26318bb9f964f4d70e3f41f650b1e6" | ||
} | ||
}, | ||
"id": "00000000c582697b67cbec7f9ce64f4dc67bfb2bfd26318bb9f964f4d70e3f41f650b1e6", | ||
"asset": "native", | ||
"amount": "13.1200000", | ||
"sponsor": "GB5N4275ETC6A77K4DTDL3EFAQMN66PC7UITDUZUBM7Y6LDJP7EYSGOB", | ||
"last_modified_ledger": 66835, | ||
"claimants": [ | ||
{ | ||
"destination": "GD2I2F7SWUHBAD7XBIZTF7MBMWQYWJVEFMWTXK76NSYVOY52OJRYNTIY", | ||
"predicate": { | ||
"unconditional": true | ||
} | ||
} | ||
], | ||
"paging_token": "66835-00000000c582697b67cbec7f9ce64f4dc67bfb2bfd26318bb9f964f4d70e3f41f650b1e6" | ||
} |
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
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
Oops, something went wrong.