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
152 changes: 151 additions & 1 deletion StellarDotnetSdk.Tests/Requests/EffectsRequestBuilderTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System.IO;
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StellarDotnetSdk.Assets;
using StellarDotnetSdk.LiquidityPool;
using StellarDotnetSdk.Requests;
using StellarDotnetSdk.Responses.Effects;
using StellarDotnetSdk.Tests.Responses.Effects;
using XDR = StellarDotnetSdk.Xdr;

namespace StellarDotnetSdk.Tests.Requests;

Expand Down Expand Up @@ -168,4 +172,150 @@ public async Task Stream_WithCursor_SetsLastEventIdAndCursorInUri()
Assert.AreEqual(eventId, streamableTest.LastEventId);
Assert.AreEqual("https://horizon-testnet.stellar.org/test?cursor=65571265847297-1", streamableTest.Uri);
}

/// <summary>
/// Verifies that EffectsRequestBuilder.ForAccount throws ArgumentNullException when account is null.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ForAccount_WithNullAccount_ThrowsArgumentNullException()
Comment thread
cuongph87 marked this conversation as resolved.
{
// Arrange
using var server = new Server("https://horizon-testnet.stellar.org");

// Act & Assert
_ = server.Effects.ForAccount(null!);
}

/// <summary>
/// Verifies that EffectsRequestBuilder.ForAccount throws ArgumentException when account is empty.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ForAccount_WithEmptyAccount_ThrowsArgumentException()
{
// Arrange
using var server = new Server("https://horizon-testnet.stellar.org");

// Act & Assert
_ = server.Effects.ForAccount("");
}

/// <summary>
/// Verifies that EffectsRequestBuilder.ForAccount throws ArgumentException when account ID is invalid.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ForAccount_WithInvalidAccountId_ThrowsArgumentException()
{
// Arrange
using var server = new Server("https://horizon-testnet.stellar.org");

// Act & Assert
_ = server.Effects.ForAccount("INVALID_ACCOUNT_ID");
}

/// <summary>
/// Verifies that EffectsRequestBuilder.ForTransaction throws ArgumentNullException when transactionId is null.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ForTransaction_WithNullTransactionId_ThrowsArgumentNullException()
{
// Arrange
using var server = new Server("https://horizon-testnet.stellar.org");

// Act & Assert
_ = server.Effects.ForTransaction(null!);
}

/// <summary>
/// Verifies that EffectsRequestBuilder.ForTransaction throws ArgumentException when transaction ID is empty.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ForTransaction_WithEmptyTransactionId_ThrowsArgumentException()
{
// Arrange
using var server = new Server("https://horizon-testnet.stellar.org");

// Act & Assert
_ = server.Effects.ForTransaction("");
}

/// <summary>
/// Verifies that EffectsRequestBuilder.ForLiquidityPool correctly constructs URI for liquidity pool effects with LiquidityPoolId.
/// </summary>
[TestMethod]
public void ForLiquidityPool_WithLiquidityPoolId_BuildsCorrectUri()
{
// Arrange
using var server = new Server("https://horizon-testnet.stellar.org");
var assetA = Asset.Create("native");
var assetB = Asset.CreateNonNativeAsset("ABC", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3");
var liquidityPoolId = new LiquidityPoolId(
XDR.LiquidityPoolType.LiquidityPoolTypeEnum.LIQUIDITY_POOL_CONSTANT_PRODUCT, assetA, assetB,
LiquidityPoolParameters.Fee);

// Act
var uri = server.Effects
.ForLiquidityPool(liquidityPoolId)
.BuildUri();

// Assert
Assert.AreEqual(
$"https://horizon-testnet.stellar.org/liquidity_pools/{liquidityPoolId}/effects",
uri.ToString());
}

/// <summary>
/// Verifies that EffectsRequestBuilder.ForLiquidityPool correctly constructs URI for liquidity pool effects with string ID.
/// </summary>
[TestMethod]
public void ForLiquidityPool_WithStringId_BuildsCorrectUri()
{
// Arrange
using var server = new Server("https://horizon-testnet.stellar.org");
const string poolId = "cc22414997d7e3d9a9ac3b1d65ca9cc3e5f35ce33e0bd6a885648b11aaa3b72d";

// Act
var uri = server.Effects
.ForLiquidityPool(poolId)
.Limit(50)
.Order(OrderDirection.ASC)
.BuildUri();

// Assert
Assert.AreEqual(
$"https://horizon-testnet.stellar.org/liquidity_pools/{poolId}/effects?limit=50&order=asc",
uri.ToString());
}

/// <summary>
/// Verifies that EffectsRequestBuilder.ForLiquidityPool throws ArgumentNullException when pool ID is null.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ForLiquidityPool_WithNullPoolId_ThrowsArgumentNullException()
{
// Arrange
using var server = new Server("https://horizon-testnet.stellar.org");

// Act & Assert
_ = server.Effects.ForLiquidityPool((string)null!);
}

/// <summary>
/// Verifies that EffectsRequestBuilder.ForLiquidityPool throws ArgumentException when pool ID is empty.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ForLiquidityPool_WithEmptyPoolId_ThrowsArgumentException()
{
// Arrange
using var server = new Server("https://horizon-testnet.stellar.org");

// Act & Assert
_ = server.Effects.ForLiquidityPool("");
}
}
189 changes: 189 additions & 0 deletions StellarDotnetSdk.Tests/Requests/OperationsRequestBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,193 @@ public async Task Stream_WithValidJson_StreamsOperationEvents()
CreateAccountOperationResponseTest.AssertCreateAccountOperationData);
await streamableTest.Run();
}

/// <summary>
/// Verifies that OperationsRequestBuilder.Operation correctly retrieves and deserializes operation data from URI.
/// </summary>
[TestMethod]
public async Task Operation_WithValidUri_ReturnsDeserializedOperation()
{
// Arrange
using var server = await Utils.CreateTestServerWithJson("Responses/Operations/createAccount.json");
var uri = new Uri("https://horizon-testnet.stellar.org/operations/100000");

// Act
var operation = await server.Operations.Operation(uri);

// Assert
CreateAccountOperationResponseTest.AssertCreateAccountOperationData(operation);
}

/// <summary>
/// Verifies that OperationsRequestBuilder.ForAccount throws ArgumentException when account ID is invalid.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ForAccount_WithInvalidAccountId_ThrowsArgumentException()
{
// Arrange
using var server = Utils.CreateTestServerWithContent("");

// Act & Assert
_ = server.Operations.ForAccount("INVALID_ACCOUNT_ID");
}

/// <summary>
/// Verifies that OperationsRequestBuilder.ForAccount throws ArgumentNullException when account is null.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ForAccount_WithNullAccount_ThrowsArgumentNullException()
{
// Arrange
using var server = Utils.CreateTestServerWithContent("");

// Act & Assert
_ = server.Operations.ForAccount(null!);
}

/// <summary>
/// Verifies that OperationsRequestBuilder.ForAccount throws ArgumentException when account is empty.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ForAccount_WithEmptyAccount_ThrowsArgumentException()
{
// Arrange
using var server = Utils.CreateTestServerWithContent("");

// Act & Assert
_ = server.Operations.ForAccount("");
}

/// <summary>
/// Verifies that OperationsRequestBuilder.ForClaimableBalance throws ArgumentNullException when balance ID is null.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ForClaimableBalance_WithNullBalanceId_ThrowsArgumentNullException()
{
// Arrange
using var server = Utils.CreateTestServerWithContent("");

// Act & Assert
_ = server.Operations.ForClaimableBalance(null!);
}

/// <summary>
/// Verifies that OperationsRequestBuilder.ForClaimableBalance throws ArgumentException when balance ID format is invalid.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ForClaimableBalance_WithInvalidFormat_ThrowsArgumentException()
{
// Arrange
using var server = Utils.CreateTestServerWithContent("");

// Act & Assert
_ = server.Operations.ForClaimableBalance("invalid_format");
}

/// <summary>
/// Verifies that OperationsRequestBuilder.ForTransaction throws ArgumentNullException when transaction ID is null.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ForTransaction_WithNullTransactionId_ThrowsArgumentNullException()
{
// Arrange
using var server = Utils.CreateTestServerWithContent("");

// Act & Assert
_ = server.Operations.ForTransaction(null!);
}

/// <summary>
/// Verifies that OperationsRequestBuilder.ForTransaction throws ArgumentException when transaction ID is empty.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ForTransaction_WithEmptyTransactionId_ThrowsArgumentException()
{
// Arrange
using var server = Utils.CreateTestServerWithContent("");

// Act & Assert
_ = server.Operations.ForTransaction("");
}

/// <summary>
/// Verifies that OperationsRequestBuilder.ForLiquidityPool correctly constructs URI for liquidity pool operations.
/// </summary>
[TestMethod]
public void ForLiquidityPool_WithValidPoolId_BuildsCorrectUri()
{
// Arrange
using var server = Utils.CreateTestServerWithContent("");
const string poolId = "cc22414997d7e3d9a9ac3b1d65ca9cc3e5f35ce33e0bd6a885648b11aaa3b72d";

// Act
var uri = server.Operations
.ForLiquidityPool(poolId)
.Limit(50)
.Order(OrderDirection.ASC)
.BuildUri();

// Assert
Assert.AreEqual(
$"https://horizon-testnet.stellar.org/liquidity_pools/{poolId}/operations?limit=50&order=asc",
uri.ToString());
}

/// <summary>
/// Verifies that OperationsRequestBuilder.ForLiquidityPool throws ArgumentNullException when pool ID is null.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ForLiquidityPool_WithNullPoolId_ThrowsArgumentNullException()
{
// Arrange
using var server = Utils.CreateTestServerWithContent("");

// Act & Assert
_ = server.Operations.ForLiquidityPool(null!);
}

/// <summary>
/// Verifies that OperationsRequestBuilder.ForLiquidityPool throws ArgumentException when pool ID is empty.
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ForLiquidityPool_WithEmptyPoolId_ThrowsArgumentException()
{
// Arrange
using var server = Utils.CreateTestServerWithContent("");

// Act & Assert
_ = server.Operations.ForLiquidityPool("");
}

/// <summary>
/// Verifies that OperationsRequestBuilder.IncludeFailed correctly adds include_failed parameter with false value.
/// </summary>
[TestMethod]
public void IncludeFailed_WithFalseValue_AddsIncludeFailedParameter()
{
// Arrange
using var server = Utils.CreateTestServerWithContent("");

// Act
var uri = server.Operations
.ForLedger(200000000000L)
.IncludeFailed(false)
.Limit(50)
.Order(OrderDirection.ASC)
.BuildUri();

// Assert
Assert.AreEqual(
"https://horizon-testnet.stellar.org/ledgers/200000000000/operations?include_failed=false&limit=50&order=asc",
uri.ToString());
}
}
Loading
Loading