Skip to content

Commit

Permalink
Merge ca65f30 into fd32992
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirbyrawr committed Mar 1, 2020
2 parents fd32992 + ca65f30 commit d636695
Show file tree
Hide file tree
Showing 7 changed files with 402 additions and 154 deletions.
91 changes: 74 additions & 17 deletions stellar-dotnet-sdk-test/responses/OperationDeserializerTest.cs
Expand Up @@ -380,38 +380,95 @@ private static void AssertManageBuyOfferData(OperationResponse instance)
}

[TestMethod]
public void TestDeserializePathPaymentOperation()
public void TestDeserializePathPaymentStrictReceiveOperation()
{
var json = File.ReadAllText(Path.Combine("testdata", "operationPathPayment.json"));
var json = File.ReadAllText(Path.Combine("testdata", "operationPathPaymentStrictReceive.json"));
var instance = JsonSingleton.GetInstance<OperationResponse>(json);

AssertPathPaymentData(instance);
AssertPathPaymentStrictReceiveData(instance);
}

[TestMethod]
public void TestSerializeDeserializePathPaymentOperation()
public void TestSerializeDeserializePathPaymentStrictReceiveOperation()
{
var json = File.ReadAllText(Path.Combine("testdata", "operationPathPayment.json"));
var json = File.ReadAllText(Path.Combine("testdata", "operationPathPaymentStrictReceive.json"));
var instance = JsonSingleton.GetInstance<OperationResponse>(json);
var serialized = JsonConvert.SerializeObject(instance);
var back = JsonConvert.DeserializeObject<OperationResponse>(serialized);

AssertPathPaymentData(back);
AssertPathPaymentStrictReceiveData(back);
}

private static void AssertPathPaymentData(OperationResponse instance)
private static void AssertPathPaymentStrictReceiveData(OperationResponse instance)
{
//There is a JsonConverter called OperationDeserializer that instantiates the type based on the json type_i element...
Assert.IsTrue(instance is PathPaymentOperationResponse);
var operation = (PathPaymentOperationResponse) instance;

Assert.AreEqual(operation.From, "GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU");
Assert.AreEqual(operation.To, "GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2");
Assert.AreEqual(operation.Amount, "10.0");
Assert.AreEqual(operation.SourceAmount, "1.173");
Assert.AreEqual(operation.SourceMax, "100.0");
Assert.AreEqual(operation.Asset, Asset.CreateNonNativeAsset("EUR", "GCQPYGH4K57XBDENKKX55KDTWOTK5WDWRQOH2LHEDX3EKVIQRLMESGBG"));
Assert.AreEqual(operation.SendAsset, Asset.CreateNonNativeAsset("USD", "GC23QF2HUE52AMXUFUH3AYJAXXGXXV2VHXYYR6EYXETPKDXZSAW67XO4"));
Assert.IsTrue(instance is PathPaymentStrictReceiveOperationResponse);
var operation = (PathPaymentStrictReceiveOperationResponse) instance;

PathPaymentStrictReceiveOperationResponse operationTest = new PathPaymentStrictReceiveOperationResponse(
"GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU",
"GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2",
"credit_alphanum4", "EUR", "GCQPYGH4K57XBDENKKX55KDTWOTK5WDWRQOH2LHEDX3EKVIQRLMESGBG",
"10.0",
"credit_alphanum4", "USD", "GC23QF2HUE52AMXUFUH3AYJAXXGXXV2VHXYYR6EYXETPKDXZSAW67XO4",
"10.0",
"10.0",
new Asset[] { }
);

Assert.AreEqual(operation.From, operationTest.From);
Assert.AreEqual(operation.To, operationTest.To);
Assert.AreEqual(operation.Amount, operationTest.Amount);
Assert.AreEqual(operation.SourceMax, operationTest.SourceMax);
Assert.AreEqual(operation.SourceAmount, operationTest.SourceAmount);
Assert.AreEqual(operation.DestinationAsset, Asset.CreateNonNativeAsset(operationTest.AssetType, operation.AssetIssuer, operationTest.AssetCode));
Assert.AreEqual(operation.SourceAsset, Asset.CreateNonNativeAsset(operationTest.SourceAssetType, operation.SourceAssetIssuer, operationTest.SourceAssetCode));
}

[TestMethod]
public void TestDeserializePathPaymentStrictSendOperation()
{
var json = File.ReadAllText(Path.Combine("testdata", "operationPathPaymentStrictSend.json"));
var instance = JsonSingleton.GetInstance<OperationResponse>(json);

AssertPathPaymentStrictSendData(instance);
}

[TestMethod]
public void TestSerializeDeserializePathPaymentStrictSendOperation()
{
var json = File.ReadAllText(Path.Combine("testdata", "operationPathPaymentStrictSend.json"));
var instance = JsonSingleton.GetInstance<OperationResponse>(json);
var serialized = JsonConvert.SerializeObject(instance);
var back = JsonConvert.DeserializeObject<OperationResponse>(serialized);

AssertPathPaymentStrictSendData(back);
}

private static void AssertPathPaymentStrictSendData(OperationResponse instance)
{
//There is a JsonConverter called OperationDeserializer that instantiates the type based on the json type_i element...
Assert.IsTrue(instance is PathPaymentStrictSendOperationResponse);
var operation = (PathPaymentStrictSendOperationResponse)instance;

PathPaymentStrictSendOperationResponse operationTest = new PathPaymentStrictSendOperationResponse(
"GCXVEEBWI4YMRK6AFJQSEUBYDQL4PZ24ECAPJE2ZIAPIQZLZIBAX3LIF",
"GCXVEEBWI4YMRK6AFJQSEUBYDQL4PZ24ECAPJE2ZIAPIQZLZIBAX3LIF",
"native", "", "",
"0.0859000",
"credit_alphanum4", "KIN", "GBDEVU63Y6NTHJQQZIKVTC23NWLQVP3WJ2RI2OTSJTNYOIGICST6DUXR",
"1000.0000000",
"0.0859000",
new Asset[] { }
);

Assert.AreEqual(operation.From, operationTest.From);
Assert.AreEqual(operation.To, operationTest.To);
Assert.AreEqual(operation.Amount, operationTest.Amount);
Assert.AreEqual(operation.SourceAmount, operationTest.SourceAmount);
Assert.AreEqual(operation.DestinationMin, operationTest.DestinationMin);
Assert.AreEqual(operation.DestinationAsset, Asset.Create(operationTest.AssetType, "", ""));
Assert.AreEqual(operation.SourceAsset, Asset.CreateNonNativeAsset(operationTest.SourceAssetType, operationTest.SourceAssetIssuer, operationTest.SourceAssetCode));
}

[TestMethod]
Expand Down
5 changes: 4 additions & 1 deletion stellar-dotnet-sdk-test/stellar-dotnet-sdk-test.csproj
Expand Up @@ -182,7 +182,10 @@
<None Update="testdata\operationFeeStats.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testdata\operationPathPayment.json">
<None Update="testdata\operationPathPaymentStrictSend.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testdata\operationPathPaymentStrictReceive.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testdata\operationPayment.json">
Expand Down
Expand Up @@ -5,13 +5,13 @@
"templated": true
},
"precedes": {
"href": "/operations?cursor=25769807873&order=asc"
"href": "/operations?cursor=25769807873\u0026order=asc"
},
"self": {
"href": "/operations/25769807873"
},
"succeeds": {
"href": "/operations?cursor=25769807873&order=desc"
"href": "/operations?cursor=25769807873\u0026order=desc"
},
"transaction": {
"href": "/transactions/25769807872"
Expand All @@ -22,14 +22,15 @@
"asset_issuer": "GCQPYGH4K57XBDENKKX55KDTWOTK5WDWRQOH2LHEDX3EKVIQRLMESGBG",
"asset_type": "credit_alphanum4",
"from": "GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU",
"id": 25769807873,
"id": "25769807873",
"paging_token": "25769807873",
"send_asset_code": "USD",
"send_asset_issuer": "GC23QF2HUE52AMXUFUH3AYJAXXGXXV2VHXYYR6EYXETPKDXZSAW67XO4",
"send_asset_type": "credit_alphanum4",
"source_amount": "1.173",
"source_max": "100.0",
"source_asset_code": "USD",
"source_asset_issuer": "GC23QF2HUE52AMXUFUH3AYJAXXGXXV2VHXYYR6EYXETPKDXZSAW67XO4",
"source_asset_type": "credit_alphanum4",
"source_amount": "10.0",
"source_max": "10.0",
"to": "GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2",
"transaction_successful": true,
"type_i": 2,
"type": "path_payment"
"type": "path_payment_strict_receive"
}
@@ -0,0 +1,39 @@
{
"_links": {
"self": {
"href": "/operations/120903307907612673"
},
"transaction": {
"href": "/transactions/f60f32eff7f1dd0649cfe2986955d12f6ff45288357fe1526600642ea1b418aa"
},
"effects": {
"href": "/operations/120903307907612673/effects"
},
"succeeds": {
"href": "/effects?order=desc&cursor=120903307907612673"
},
"precedes": {
"href": "/effects?order=asc&cursor=120903307907612673"
}
},
"id": "120903307907612673",
"paging_token": "120903307907612673",
"transaction_successful": true,
"source_account": "GCXVEEBWI4YMRK6AFJQSEUBYDQL4PZ24ECAPJE2ZIAPIQZLZIBAX3LIF",
"type": "path_payment_strict_send",
"type_i": 13,
"created_at": "2020-02-09T20:32:53Z",
"transaction_hash": "f60f32eff7f1dd0649cfe2986955d12f6ff45288357fe1526600642ea1b418aa",
"asset_type": "native",
"from": "GCXVEEBWI4YMRK6AFJQSEUBYDQL4PZ24ECAPJE2ZIAPIQZLZIBAX3LIF",
"to": "GCXVEEBWI4YMRK6AFJQSEUBYDQL4PZ24ECAPJE2ZIAPIQZLZIBAX3LIF",
"amount": "0.0859000",
"path": [

],
"source_amount": "1000.0000000",
"destination_min": "0.0859000",
"source_asset_type": "credit_alphanum4",
"source_asset_code": "KIN",
"source_asset_issuer": "GBDEVU63Y6NTHJQQZIKVTC23NWLQVP3WJ2RI2OTSJTNYOIGICST6DUXR"
}
4 changes: 3 additions & 1 deletion stellar-dotnet-sdk/responses/OperationDeserializer.cs
Expand Up @@ -34,7 +34,7 @@ private static OperationResponse CreateResponse(int type)
case 1:
return new PaymentOperationResponse();
case 2:
return new PathPaymentOperationResponse();
return new PathPaymentStrictReceiveOperationResponse();
case 3:
return new ManageSellOfferOperationResponse();
case 4:
Expand All @@ -55,6 +55,8 @@ private static OperationResponse CreateResponse(int type)
return new BumpSequenceOperationResponse();
case 12:
return new ManageBuyOfferOperationResponse();
case 13:
return new PathPaymentStrictSendOperationResponse();
default:
throw new JsonSerializationException($"Invalid operation 'type_i'='{type}'");
}
Expand Down

0 comments on commit d636695

Please sign in to comment.