Skip to content

Commit

Permalink
Backward-compatibility changes for Protocol 22
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongph87 authored Nov 12, 2024
1 parent db5e9a9 commit 84786f9
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 25 deletions.
25 changes: 23 additions & 2 deletions StellarDotnetSdk.Tests/ServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,34 @@ public async Task TestSubmitTransactionAsyncTryAgainLater()
}

[TestMethod]
public async Task TestSubmitTransactionAsyncError()
public async Task TestSubmitTransactionAsyncErrorPriorToProtocol22()
{
const string json =
"""
{
"tx_status": "ERROR",
"hash": "9f8e7d6c5b4a3210fedcba9876543210abcdef0123456789abcdef0123456789",
"errorResultXdr": "AAAAAAAAAGT////7AAAAAA=="
}
""";
using var server = Utils.CreateTestServerWithContent(json);
var response = await server.SubmitTransactionAsync(
BuildTransaction(), new SubmitTransactionOptions { SkipMemoRequiredCheck = true });
Assert.IsNotNull(response);
Assert.AreEqual(SubmitTransactionAsyncResponse.TransactionStatus.ERROR, response.TxStatus);
Assert.AreEqual(response.Hash, "9f8e7d6c5b4a3210fedcba9876543210abcdef0123456789abcdef0123456789");
Assert.IsNotNull(response.ErrorResult);
}

[TestMethod]
public async Task TestSubmitTransactionAsyncErrorProtocol22()
{
const string json =
"""
{
"tx_status": "ERROR",
"hash": "9f8e7d6c5b4a3210fedcba9876543210abcdef0123456789abcdef0123456789",
"errorResultXdr": "AAAAAAAAAGT////7AAAAAA==",
"error_result_xdr": "AAAAAAAAAGT////7AAAAAA=="
}
""";
Expand All @@ -447,7 +468,7 @@ public async Task TestSubmitTransactionAsyncError()
Assert.AreEqual(response.Hash, "9f8e7d6c5b4a3210fedcba9876543210abcdef0123456789abcdef0123456789");
Assert.IsNotNull(response.ErrorResult);
}

[TestMethod]
public async Task TestSubmitTransactionAsyncObjectNoSkipMemoRequiredCheck()
{
Expand Down
57 changes: 47 additions & 10 deletions StellarDotnetSdk.Tests/SorobanServerTest.cs

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions StellarDotnetSdk.Tests/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,18 @@ public static async Task CheckAndCreateAccountOnTestnet(string accountId)
}
}

public static Server CreateTestServerWithContent(string? content, HttpStatusCode statusCode = HttpStatusCode.OK,
public static Server CreateTestServerWithContent(
string? content,
HttpStatusCode statusCode = HttpStatusCode.OK,
string uri = "https://horizon-testnet.stellar.org")
{
Network.UseTestNetwork();
var httpClient = CreateFakeHttpClient(content, statusCode);
return new Server(uri, httpClient);
}

public static SorobanServer CreateTestSorobanServerWithContent(string? content,
public static SorobanServer CreateTestSorobanServerWithContent(
string? content,
HttpStatusCode statusCode = HttpStatusCode.OK,
string uri = "https://soroban-testnet.stellar.org")
{
Expand All @@ -132,7 +135,8 @@ public static SorobanServer CreateTestSorobanServerWithContent(string? content,
return new SorobanServer(uri, httpClient);
}

public static Server CreateTestServerWithHeaders(Dictionary<string, IEnumerable<string>> headers,
public static Server CreateTestServerWithHeaders(
Dictionary<string, IEnumerable<string>> headers,
HttpStatusCode statusCode = HttpStatusCode.OK,
string uri = "https://horizon-testnet.stellar.org")
{
Expand All @@ -141,15 +145,19 @@ public static Server CreateTestServerWithHeaders(Dictionary<string, IEnumerable<
return new Server(uri, httpClient);
}

public static async Task<Server> CreateTestServerWithJson(string pathToJson,
HttpStatusCode statusCode = HttpStatusCode.OK, string uri = "https://horizon-testnet.stellar.org")
public static async Task<Server> CreateTestServerWithJson(
string pathToJson,
HttpStatusCode statusCode = HttpStatusCode.OK,
string uri = "https://horizon-testnet.stellar.org")
{
var jsonPath = GetTestDataPath(pathToJson);
var content = await File.ReadAllTextAsync(jsonPath);
return CreateTestServerWithContent(content, statusCode, uri);
}

public static HttpClient CreateFakeHttpClient(string? content, HttpStatusCode statusCode = HttpStatusCode.OK,
public static HttpClient CreateFakeHttpClient(
string? content,
HttpStatusCode statusCode = HttpStatusCode.OK,
IDictionary<string, IEnumerable<string>>? headers = null)
{
var mockFakeHttpMessageHandler = new Mock<FakeHttpMessageHandler> { CallBase = true };
Expand Down
12 changes: 11 additions & 1 deletion StellarDotnetSdk/Responses/SorobanRpc/GetEventsResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System;
using Newtonsoft.Json;
using StellarDotnetSdk.Soroban;

namespace StellarDotnetSdk.Responses.SorobanRpc;
Expand Down Expand Up @@ -35,6 +36,7 @@ public EventInfo(
bool inSuccessfulContractCall,
int ledger,
string ledgerClosedAt,
string pagingToken,
string[] topics,
string type,
string value,
Expand All @@ -45,6 +47,7 @@ public EventInfo(
InSuccessfulContractCall = inSuccessfulContractCall;
Ledger = ledger;
LedgerClosedAt = ledgerClosedAt;
PagingToken = pagingToken;
Topics = topics;
Type = type;
Value = value;
Expand Down Expand Up @@ -77,6 +80,13 @@ public EventInfo(
/// </summary>
public string LedgerClosedAt { get; }

/// <summary>
/// Duplicate of <c>id</c> field, but in the standard place for pagination tokens.
/// Use <see cref="GetEventsResponse.Cursor"/> instead.
/// </summary>
[Obsolete("This property is deprecated, use GetEventsResponse.Cursor instead. In a future release of this SDK this field can be removed.")]
public string PagingToken { get; }

/// <summary>
/// A list containing the topics, each is a base-64 encoded XDR string of an <see cref="Xdr.SCVal">xdr.SCVal</see>
/// object, this event was emitted with.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public GetTransactionResponse(
long oldestLedger,
long oldestLedgerCloseTime,
long ledger,
string createdAt,
long createdAt,
int applicationOrder,
bool feeBump,
string? envelopeXdr,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace StellarDotnetSdk.Responses.SorobanRpc;
using Newtonsoft.Json;

namespace StellarDotnetSdk.Responses.SorobanRpc;

/// <summary>
/// Version information about the RPC and Captive core. RPC manages its own, pared-down version of Stellar Core
Expand All @@ -23,21 +25,25 @@ public GetVersionInfoResponse(
/// <summary>
/// The build timestamp of the RPC server.
/// </summary>
[JsonProperty(PropertyName = "build_timestamp")]
public string BuildTimeStamp { get; }

/// <summary>
/// The version of the Captive Core.
/// </summary>
[JsonProperty(PropertyName = "captive_core_version")]
public string CaptiveCoreVersion { get; }

/// <summary>
/// The commit hash of the RPC server.
/// </summary>
[JsonProperty(PropertyName = "commit_hash")]
public string CommitHash { get; }

/// <summary>
/// The protocol version.
/// </summary>
[JsonProperty(PropertyName = "protocol_version")]
public int ProtocolVersion { get; }

/// <summary>
Expand Down
7 changes: 4 additions & 3 deletions StellarDotnetSdk/Responses/SorobanRpc/TransactionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ public enum TransactionStatus
FAILED,
}

public TransactionInfo(TransactionStatus status,
public TransactionInfo(
TransactionStatus status,
long? ledger,
string? createdAt,
long? createdAt,
int? applicationOrder,
bool? feeBump,
string? envelopeXdr,
Expand Down Expand Up @@ -55,7 +56,7 @@ public TransactionInfo(TransactionStatus status,
/// (optional) The unix timestamp of when the transaction was included in the ledger. This field is only present if
/// status is SUCCESS or FAILED.
/// </summary>
public string? CreatedAt { get; }
public long? CreatedAt { get; }

/// <summary>
/// (optional) The index of the transaction among all transactions included in the ledger. This field is only present
Expand Down
3 changes: 2 additions & 1 deletion StellarDotnetSdk/Responses/SubmitTransactionAsyncResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public enum TransactionStatus
ERROR,
}

[JsonProperty(PropertyName = "error_result_xdr")]
// TODO: Change to "error_result_xdr" when Horizon is updated to v22.0.0
[JsonProperty(PropertyName = "errorResultXdr")]
private string? _errorResultXdr;

[JsonProperty(PropertyName = "hash")] public string? Hash { get; init; }
Expand Down

0 comments on commit 84786f9

Please sign in to comment.