Skip to content
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
71 changes: 62 additions & 9 deletions StellarDotnetSdk.Tests/Responses/RootDeserializerTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Text.Json;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StellarDotnetSdk.Converters;
Expand Down Expand Up @@ -35,13 +36,65 @@ public void TestSerializeDeserialize()

private static void AssertTestData(RootResponse root)
{
Assert.AreEqual(root.HorizonVersion, "snapshot-c5fe0ff");
Assert.AreEqual(root.StellarCoreVersion, "stellar-core 9.2.0 (7561c1d53366ec79b908de533726269e08474f77)");
Assert.AreEqual(root.HistoryLatestLedger, 18369116);
Assert.AreEqual(root.HistoryElderLedger, 1);
Assert.AreEqual(root.CoreLatestLedger, 18369117);
Assert.AreEqual(root.NetworkPassphrase, "Public Global Stellar Network ; September 2015");
Assert.AreEqual(root.CurrentProtocolVersion, 10);
Assert.AreEqual(root.CoreSupportedProtocolVersion, 11);
Assert.AreEqual("24.0.0-479385ffcbf959dad6463bb17917766f5cb4d43f", root.HorizonVersion);
Assert.AreEqual("stellar-core 24.1.0 (5a7035d49201b88db95e024b343fb866c2185043)", root.StellarCoreVersion);
Assert.AreEqual(18369116L, root.HistoryLatestLedger);
Assert.AreEqual(new DateTimeOffset(2025, 12, 1, 4, 30, 48, TimeSpan.Zero),
root.HistoryLatestLedgerClosedAt);
Assert.AreEqual(53789041L, root.HistoryElderLedger);
Assert.AreEqual(18369117L, root.CoreLatestLedger);
Assert.AreEqual("Public Global Stellar Network ; September 2015", root.NetworkPassphrase);
Assert.AreEqual(24, root.CurrentProtocolVersion);
Assert.AreEqual(24, root.CoreSupportedProtocolVersion);
Assert.AreEqual(24, root.SupportedProtocolVersion);

// Assert links
Assert.IsNotNull(root.Links);
Assert.AreEqual("https://horizon-testnet.stellar.org/accounts/{account_id}", root.Links.Account.Href);
Assert.AreEqual(
"https://horizon-testnet.stellar.org/accounts{?signer,sponsor,asset,liquidity_pool,cursor,limit,order}",
root.Links.Accounts.Href);
Assert.AreEqual("https://horizon-testnet.stellar.org/accounts/{account_id}/transactions{?cursor,limit,order}",
root.Links.AccountTransactions.Href);
Assert.AreEqual("https://horizon-testnet.stellar.org/assets{?asset_code,asset_issuer,cursor,limit,order}",
root.Links.Assets.Href);
Assert.AreEqual(
"https://horizon-testnet.stellar.org/claimable_balances{?asset,sponsor,claimant,cursor,limit,order}",
root.Links.ClaimableBalances.Href);
Assert.AreEqual("https://horizon-testnet.stellar.org/effects{?cursor,limit,order}", root.Links.Effects.Href);
Assert.AreEqual("https://horizon-testnet.stellar.org/fee_stats", root.Links.FeeStats.Href);
Assert.IsNotNull(root.Links.Friendbot);
Assert.AreEqual("https://friendbot.stellar.org/{?addr}", root.Links.Friendbot.Href);
Assert.AreEqual("https://horizon-testnet.stellar.org/ledgers/{sequence}", root.Links.Ledger.Href);
Assert.AreEqual("https://horizon-testnet.stellar.org/ledgers{?cursor,limit,order}", root.Links.Ledgers.Href);
Assert.AreEqual("https://horizon-testnet.stellar.org/liquidity_pools{?reserves,account,cursor,limit,order}",
root.Links.LiquidityPools.Href);
Assert.AreEqual("https://horizon-testnet.stellar.org/offers/{offer_id}", root.Links.Offer.Href);
Assert.AreEqual("https://horizon-testnet.stellar.org/offers{?selling,buying,seller,sponsor,cursor,limit,order}",
root.Links.Offers.Href);
Assert.AreEqual("https://horizon-testnet.stellar.org/operations/{id}", root.Links.Operation.Href);
Assert.AreEqual("https://horizon-testnet.stellar.org/operations{?cursor,limit,order,include_failed}",
root.Links.Operations.Href);
Assert.AreEqual(
"https://horizon-testnet.stellar.org/order_book{?selling_asset_type,selling_asset_code,selling_asset_issuer,buying_asset_type,buying_asset_code,buying_asset_issuer,limit}",
root.Links.OrderBook.Href);
Assert.AreEqual("https://horizon-testnet.stellar.org/payments{?cursor,limit,order,include_failed}",
root.Links.Payments.Href);
Assert.AreEqual("https://horizon-testnet.stellar.org/", root.Links.Self.Href);
Assert.AreEqual(
"https://horizon-testnet.stellar.org/paths/strict-receive{?source_assets,source_account,destination_account,destination_asset_type,destination_asset_issuer,destination_asset_code,destination_amount}",
root.Links.StrictReceivePaths.Href);
Assert.AreEqual(
"https://horizon-testnet.stellar.org/paths/strict-send{?destination_account,destination_assets,source_asset_type,source_asset_issuer,source_asset_code,source_amount}",
root.Links.StrictSendPaths.Href);
Assert.AreEqual(
"https://horizon-testnet.stellar.org/trade_aggregations?base_asset_type={base_asset_type}&base_asset_code={base_asset_code}&base_asset_issuer={base_asset_issuer}&counter_asset_type={counter_asset_type}&counter_asset_code={counter_asset_code}&counter_asset_issuer={counter_asset_issuer}",
root.Links.TradeAggregations.Href);
Assert.AreEqual(
"https://horizon-testnet.stellar.org/trades?base_asset_type={base_asset_type}&base_asset_code={base_asset_code}&base_asset_issuer={base_asset_issuer}&counter_asset_type={counter_asset_type}&counter_asset_code={counter_asset_code}&counter_asset_issuer={counter_asset_issuer}",
root.Links.Trades.Href);
Assert.AreEqual("https://horizon-testnet.stellar.org/transactions/{hash}", root.Links.Transaction.Href);
Assert.AreEqual("https://horizon-testnet.stellar.org/transactions{?cursor,limit,order}",
root.Links.Transactions.Href);
}
}
94 changes: 78 additions & 16 deletions StellarDotnetSdk.Tests/TestData/Responses/root.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,108 @@
{
{
"_links": {
"account": {
"href": "https://horizon.stellar.org/accounts/{account_id}",
"href": "https://horizon-testnet.stellar.org/accounts/{account_id}",
"templated": true
},
"accounts": {
"href": "https://horizon-testnet.stellar.org/accounts{?signer,sponsor,asset,liquidity_pool,cursor,limit,order}",
"templated": true
},
"account_transactions": {
"href": "https://horizon.stellar.org/accounts/{account_id}/transactions{?cursor,limit,order}",
"href": "https://horizon-testnet.stellar.org/accounts/{account_id}/transactions{?cursor,limit,order}",
"templated": true
},
"claimable_balances": {
"href": "https://horizon-testnet.stellar.org/claimable_balances{?asset,sponsor,claimant,cursor,limit,order}",
"templated": true
},
"assets": {
"href": "https://horizon.stellar.org/assets{?asset_code,asset_issuer,cursor,limit,order}",
"href": "https://horizon-testnet.stellar.org/assets{?asset_code,asset_issuer,cursor,limit,order}",
"templated": true
},
"effects": {
"href": "https://horizon-testnet.stellar.org/effects{?cursor,limit,order}",
"templated": true
},
"fee_stats": {
"href": "https://horizon-testnet.stellar.org/fee_stats"
},
"friendbot": {
"href": "https://horizon.stellar.org/friendbot{?addr}",
"href": "https://friendbot.stellar.org/{?addr}",
"templated": true
},
"ledger": {
"href": "https://horizon-testnet.stellar.org/ledgers/{sequence}",
"templated": true
},
"ledgers": {
"href": "https://horizon-testnet.stellar.org/ledgers{?cursor,limit,order}",
"templated": true
},
"liquidity_pools": {
"href": "https://horizon-testnet.stellar.org/liquidity_pools{?reserves,account,cursor,limit,order}",
"templated": true
},
"offer": {
"href": "https://horizon-testnet.stellar.org/offers/{offer_id}",
"templated": true
},
"metrics": {
"href": "https://horizon.stellar.org/metrics"
"offers": {
"href": "https://horizon-testnet.stellar.org/offers{?selling,buying,seller,sponsor,cursor,limit,order}",
"templated": true
},
"operation": {
"href": "https://horizon-testnet.stellar.org/operations/{id}",
"templated": true
},
"operations": {
"href": "https://horizon-testnet.stellar.org/operations{?cursor,limit,order,include_failed}",
"templated": true
},
"order_book": {
"href": "https://horizon.stellar.org/order_book{?selling_asset_type,selling_asset_code,selling_issuer,buying_asset_type,buying_asset_code,buying_issuer,limit}",
"href": "https://horizon-testnet.stellar.org/order_book{?selling_asset_type,selling_asset_code,selling_asset_issuer,buying_asset_type,buying_asset_code,buying_asset_issuer,limit}",
"templated": true
},
"payments": {
"href": "https://horizon-testnet.stellar.org/payments{?cursor,limit,order,include_failed}",
"templated": true
},
"self": {
"href": "https://horizon.stellar.org/"
"href": "https://horizon-testnet.stellar.org/"
},
"strict_receive_paths": {
"href": "https://horizon-testnet.stellar.org/paths/strict-receive{?source_assets,source_account,destination_account,destination_asset_type,destination_asset_issuer,destination_asset_code,destination_amount}",
"templated": true
},
"strict_send_paths": {
"href": "https://horizon-testnet.stellar.org/paths/strict-send{?destination_account,destination_assets,source_asset_type,source_asset_issuer,source_asset_code,source_amount}",
"templated": true
},
"trade_aggregations": {
"href": "https://horizon-testnet.stellar.org/trade_aggregations?base_asset_type={base_asset_type}&base_asset_code={base_asset_code}&base_asset_issuer={base_asset_issuer}&counter_asset_type={counter_asset_type}&counter_asset_code={counter_asset_code}&counter_asset_issuer={counter_asset_issuer}",
"templated": true
},
"trades": {
"href": "https://horizon-testnet.stellar.org/trades?base_asset_type={base_asset_type}&base_asset_code={base_asset_code}&base_asset_issuer={base_asset_issuer}&counter_asset_type={counter_asset_type}&counter_asset_code={counter_asset_code}&counter_asset_issuer={counter_asset_issuer}",
"templated": true
},
"transaction": {
"href": "https://horizon.stellar.org/transactions/{hash}",
"href": "https://horizon-testnet.stellar.org/transactions/{hash}",
"templated": true
},
"transactions": {
"href": "https://horizon.stellar.org/transactions{?cursor,limit,order}",
"href": "https://horizon-testnet.stellar.org/transactions{?cursor,limit,order}",
"templated": true
}
},
"horizon_version": "snapshot-c5fe0ff",
"core_version": "stellar-core 9.2.0 (7561c1d53366ec79b908de533726269e08474f77)",
"horizon_version": "24.0.0-479385ffcbf959dad6463bb17917766f5cb4d43f",
"core_version": "stellar-core 24.1.0 (5a7035d49201b88db95e024b343fb866c2185043)",
"history_latest_ledger": 18369116,
"history_elder_ledger": 1,
"history_latest_ledger_closed_at": "2025-12-01T04:30:48Z",
"history_elder_ledger": 53789041,
"core_latest_ledger": 18369117,
"network_passphrase": "Public Global Stellar Network ; September 2015",
"current_protocol_version": 10,
"core_supported_protocol_version": 11
"current_protocol_version": 24,
"core_supported_protocol_version": 24,
"supported_protocol_version": 24
}
2 changes: 1 addition & 1 deletion StellarDotnetSdk/Responses/FriendBotResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace StellarDotnetSdk.Responses;
#nullable disable

public class FriendBotResponse
public class FriendBotResponse : Response
{
[JsonPropertyName("_links")]
public FriendBotResponseLinks Links { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion StellarDotnetSdk/Responses/OrderBookResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace StellarDotnetSdk.Responses;
#nullable disable

public class OrderBookResponse
public class OrderBookResponse : Response
{
[JsonPropertyName("base")]
[JsonConverter(typeof(AssetJsonConverter))]
Expand Down
70 changes: 59 additions & 11 deletions StellarDotnetSdk/Responses/RootResponse.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,79 @@
using System.Text.Json.Serialization;
using System;
using System.Text.Json.Serialization;

namespace StellarDotnetSdk.Responses;
#nullable disable

public class RootResponse : Response
/// <summary>
/// Represents the root endpoint response from a Horizon server.
/// Contains version and network information about the Horizon instance.
/// </summary>
public sealed class RootResponse : Response
{
/// <summary>
/// Links to related resources and endpoints.
/// </summary>
[JsonPropertyName("_links")]
public required RootResponseLinks Links { get; init; }

/// <summary>
/// The version of the Horizon server software.
/// </summary>
[JsonPropertyName("horizon_version")]
public string HorizonVersion { get; init; }
public required string HorizonVersion { get; init; }

/// <summary>
/// The version of Stellar Core connected to this Horizon instance.
/// </summary>
[JsonPropertyName("core_version")]
public string StellarCoreVersion { get; init; }
public required string StellarCoreVersion { get; init; }

/// <summary>
/// The sequence number of the latest ledger stored in Horizon's history database.
/// </summary>
[JsonPropertyName("history_latest_ledger")]
public int HistoryLatestLedger { get; init; }
public required long HistoryLatestLedger { get; init; }

/// <summary>
/// The time the latest ledger was closed.
/// </summary>
[JsonPropertyName("history_latest_ledger_closed_at")]
public required DateTimeOffset HistoryLatestLedgerClosedAt { get; init; }

/// <summary>
/// The sequence number of the oldest ledger stored in Horizon's history database.
/// </summary>
[JsonPropertyName("history_elder_ledger")]
public int HistoryElderLedger { get; init; }
public required long HistoryElderLedger { get; init; }

/// <summary>
/// The sequence number of the latest ledger known to Stellar Core.
/// </summary>
[JsonPropertyName("core_latest_ledger")]
public int CoreLatestLedger { get; init; }
public required long CoreLatestLedger { get; init; }

/// <summary>
/// The network passphrase that identifies which Stellar network this Horizon is connected to.
/// Common values are "Public Global Stellar Network ; September 2015" for mainnet
/// and "Test SDF Network ; September 2015" for testnet.
/// </summary>
[JsonPropertyName("network_passphrase")]
public string NetworkPassphrase { get; init; }
public required string NetworkPassphrase { get; init; }

/// <summary>
/// The current protocol version in use on the network.
/// </summary>
[JsonPropertyName("current_protocol_version")]
public int CurrentProtocolVersion { get; init; }
public required int CurrentProtocolVersion { get; init; }

/// <summary>
/// The maximum protocol version supported by the connected Stellar Core.
/// </summary>
[JsonPropertyName("core_supported_protocol_version")]
public int CoreSupportedProtocolVersion { get; init; }
public required int CoreSupportedProtocolVersion { get; init; }

/// <summary>
/// The maximum protocol version supported by the connected Stellar.
Comment thread
jopmiddelkamp marked this conversation as resolved.
/// </summary>
[JsonPropertyName("supported_protocol_version")]
public required int SupportedProtocolVersion { get; init; }
}
Loading
Loading