Skip to content
This repository was archived by the owner on May 24, 2024. It is now read-only.

Added new tests to cover pre Horizon 1.0.0 type changes. #228

Merged
merged 1 commit into from
Jan 26, 2020
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
22 changes: 22 additions & 0 deletions stellar-dotnet-sdk-test/responses/EffectDeserializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,28 @@ public void TestSerializeDeserializeTradeEffect()
AssertTradeData(back);
}

//Before Horizon 1.0.0 the OfferID in the json was a long.
[TestMethod]
public void TestDeserializeTradeEffectPre100()
{
var json = File.ReadAllText(Path.Combine("testdata", "effectTradePre100.json"));
var instance = JsonSingleton.GetInstance<EffectResponse>(json);

AssertTradeData(instance);
}

//Before Horizon 1.0.0 the OfferID in the json was a long.
[TestMethod]
public void TestSerializeDeserializeTradeEffectPre100()
{
var json = File.ReadAllText(Path.Combine("testdata", "effectTradePre100.json"));
var instance = JsonSingleton.GetInstance<EffectResponse>(json);
var serialized = JsonConvert.SerializeObject(instance);
var back = JsonConvert.DeserializeObject<EffectResponse>(serialized);

AssertTradeData(back);
}

private static void AssertTradeData(EffectResponse instance)
{
//There is a JsonConverter called OperationDeserializer that instantiates the type based on the json type_i element...
Expand Down
22 changes: 22 additions & 0 deletions stellar-dotnet-sdk-test/responses/OfferPageDeserializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ public void TestSerializeDeserialize()
AssertTestData(back);
}

//Before Horizon 1.0.0 the ID in the json was a long.
[TestMethod]
public void TestDeserializePre100()
{
var json = File.ReadAllText(Path.Combine("testdata", "offerPagePre100.json"));
var offerResponsePage = JsonSingleton.GetInstance<Page<OfferResponse>>(json);

AssertTestData(offerResponsePage);
}

//Before Horizon 1.0.0 the ID in the json was a long.
[TestMethod]
public void TestSerializeDeserializePre100()
{
var json = File.ReadAllText(Path.Combine("testdata", "offerPagePre100.json"));
var offerResponsePage = JsonSingleton.GetInstance<Page<OfferResponse>>(json);
var serialized = JsonConvert.SerializeObject(offerResponsePage);
var back = JsonConvert.DeserializeObject<Page<OfferResponse>>(serialized);

AssertTestData(back);
}

public static void AssertTestData(Page<OfferResponse> offerResponsePage)
{
Assert.AreEqual(offerResponsePage.Records[0].Id, "241");
Expand Down
24 changes: 23 additions & 1 deletion stellar-dotnet-sdk-test/responses/OperationDeserializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,35 @@ public void TestSerializeDeserializeManageBuyOfferOperation()
AssertManageBuyOfferData(back);
}

//Before Horizon 1.0.0 the OfferID in the json was a long.
[TestMethod]
public void TestDeserializeManageBuyOfferOperationPre100()
{
var json = File.ReadAllText(Path.Combine("testdata", "operationManageBuyOfferPre100.json"));
var instance = JsonSingleton.GetInstance<OperationResponse>(json);

AssertManageBuyOfferData(instance);
}

//Before Horizon 1.0.0 the OfferID in the json was a long.
[TestMethod]
public void TestSerializeDeserializeManageBuyOfferOperationPre100()
{
var json = File.ReadAllText(Path.Combine("testdata", "operationManageBuyOfferPre100.json"));
var instance = JsonSingleton.GetInstance<OperationResponse>(json);
var serialized = JsonConvert.SerializeObject(instance);
var back = JsonConvert.DeserializeObject<OperationResponse>(serialized);

AssertManageBuyOfferData(back);
}

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

Assert.AreEqual(operation.OfferId, "0");
Assert.AreEqual(operation.OfferId, "1");
Assert.AreEqual(operation.Amount, "50000.0000000");
Assert.AreEqual(operation.Price, "0.0463000");
Assert.AreEqual(operation.BuyingAsset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ public void TestSerializeDeserialize()
AssertTestData(back);
}

//Before Horizon 1.0.0 the Timestamp and TradeCount in the json were a long.
[TestMethod]
public void TestDeserializePre100()
{
var json = File.ReadAllText(Path.Combine("testdata", "tradeAggregationsPagePre100.json"));
var tradeAggregationsPage = JsonSingleton.GetInstance<Page<TradeAggregationResponse>>(json);

AssertTestData(tradeAggregationsPage);
}

//Before Horizon 1.0.0 the Timestamp and TradeCount in the json were a long.
[TestMethod]
public void TestSerializeDeserializePre100()
{
var json = File.ReadAllText(Path.Combine("testdata", "tradeAggregationsPagePre100.json"));
var tradeAggregationsPage = JsonSingleton.GetInstance<Page<TradeAggregationResponse>>(json);
var serialized = JsonConvert.SerializeObject(tradeAggregationsPage);
var back = JsonConvert.DeserializeObject<Page<TradeAggregationResponse>>(serialized);

AssertTestData(back);
}

public static void AssertTestData(Page<TradeAggregationResponse> tradeAggregationsPage)
{
Assert.AreEqual(tradeAggregationsPage.Links.Next.Href,
Expand Down
14 changes: 13 additions & 1 deletion stellar-dotnet-sdk-test/stellar-dotnet-sdk-test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<None Update="testdata\effectPage.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testdata\effectTradePre100.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testdata\effectTrade.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -134,6 +137,9 @@
<None Update="testdata\ledgerPage.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testdata\offerPagePre100.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testdata\offerPage.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -155,6 +161,9 @@
<None Update="testdata\operationInflation.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testdata\operationManageBuyOffer.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testdata\operationManageData.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -221,6 +230,9 @@
<None Update="testdata\submitTransactionTransactionFailure.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testdata\tradeAggregationsPagePre100.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testdata\tradeAggregationsPage.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -236,7 +248,7 @@
<None Update="testdata\transactionTransactionWithoutMemo.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testdata\operationManageBuyOffer.json">
<None Update="testdata\operationManageBuyOfferPre100.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testdata\transactionTransactionPre020.json">
Expand Down
2 changes: 1 addition & 1 deletion stellar-dotnet-sdk-test/testdata/effectTrade.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"type": "trade",
"type_i": 33,
"seller": "GCVHDLN6EHZBYW2M3BQIY32C23E4GPIRZZDBNF2Q73DAZ5VJDRGSMYRB",
"offer_id": 1,
"offer_id": "1",
"sold_amount": "1000.0",
"sold_asset_type": "credit_alphanum4",
"sold_asset_code": "EUR",
Expand Down
28 changes: 28 additions & 0 deletions stellar-dotnet-sdk-test/testdata/effectTradePre100.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"_links": {
"operation": {
"href": "http://horizon-testnet.stellar.org/operations/33788507721730"
},
"succeeds": {
"href": "http://horizon-testnet.stellar.org/effects?order=desc&cursor=33788507721730-2"
},
"precedes": {
"href": "http://horizon-testnet.stellar.org/effects?order=asc&cursor=33788507721730-2"
}
},
"id": "0000033788507721730-0000000002",
"paging_token": "33788507721730-2",
"account": "GA6U5X6WOPNKKDKQULBR7IDHDBAQKOWPHYEC7WSXHZBFEYFD3XVZAKOO",
"type": "trade",
"type_i": 33,
"seller": "GCVHDLN6EHZBYW2M3BQIY32C23E4GPIRZZDBNF2Q73DAZ5VJDRGSMYRB",
"offer_id": 1,
"sold_amount": "1000.0",
"sold_asset_type": "credit_alphanum4",
"sold_asset_code": "EUR",
"sold_asset_issuer": "GCWVFBJ24754I5GXG4JOEB72GJCL3MKWC7VAEYWKGQHPVH3ENPNBSKWS",
"bought_amount": "60.0",
"bought_asset_type": "credit_alphanum12",
"bought_asset_code": "TESTTEST",
"bought_asset_issuer": "GAHXPUDP3AK6F2QQM4FIRBGPNGKLRDDSTQCVKEXXKKRHJZUUQ23D5BU7"
}
2 changes: 1 addition & 1 deletion stellar-dotnet-sdk-test/testdata/offerPage.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"href": "https://horizon-testnet.stellar.org/accounts/GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD"
}
},
"id": 241,
"id": "241",
"paging_token": "241",
"seller": "GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD",
"selling": {
Expand Down
48 changes: 48 additions & 0 deletions stellar-dotnet-sdk-test/testdata/offerPagePre100.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"_links": {
"self": {
"href": "https://horizon-testnet.stellar.org/accounts/GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD/offers?order=asc&limit=10&cursor="
},
"next": {
"href": "https://horizon-testnet.stellar.org/accounts/GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD/offers?order=asc&limit=10&cursor=241"
},
"prev": {
"href": "https://horizon-testnet.stellar.org/accounts/GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD/offers?order=desc&limit=10&cursor=241"
}
},
"_embedded": {
"records": [
{
"_links": {
"self": {
"href": "https://horizon-testnet.stellar.org/offers/241"
},
"offer_maker": {
"href": "https://horizon-testnet.stellar.org/accounts/GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD"
}
},
"id": 241,
"paging_token": "241",
"seller": "GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD",
"selling": {
"asset_type": "credit_alphanum4",
"asset_code": "INR",
"asset_issuer": "GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD"
},
"buying": {
"asset_type": "credit_alphanum4",
"asset_code": "USD",
"asset_issuer": "GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD"
},
"amount": "10.0000000",
"price_r": {
"n": 10,
"d": 1
},
"price": "11.0000000",
"last_modified_ledger": 22200794,
"last_modified_time": "2019-01-28T12:30:38Z"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
"buying_asset_code": "RMT",
"buying_asset_issuer": "GDEGOXPCHXWFYY234D2YZSPEJ24BX42ESJNVHY5H7TWWQSYRN5ZKZE3N",
"selling_asset_type": "native",
"offer_id": 0
"offer_id": "1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"_links": {
"self": {
"href": "https://horizon.stellar.org/operations/105020235379187713"
},
"transaction": {
"href": "https://horizon.stellar.org/transactions/35b08c8e7fc739ab07fd8eeb9564c59b4f1e85099aa2d3b1d37ed86a6cb5c438"
},
"effects": {
"href": "https://horizon.stellar.org/operations/105020235379187713/effects"
},
"succeeds": {
"href": "https://horizon.stellar.org/effects?order=desc&cursor=105020235379187713"
},
"precedes": {
"href": "https://horizon.stellar.org/effects?order=asc&cursor=105020235379187713"
}
},
"id": "105020235379187713",
"paging_token": "105020235379187713",
"transaction_successful": true,
"source_account": "GDID4M4PAN3C2JO4PJPCZ4Z6PSYUTW2I32E5EBORECQYIJDGTIZO3N5D",
"type": "manage_buy_offer",
"type_i": 12,
"created_at": "2019-06-21T08:24:48Z",
"transaction_hash": "35b08c8e7fc739ab07fd8eeb9564c59b4f1e85099aa2d3b1d37ed86a6cb5c438",
"amount": "50000.0000000",
"price": "0.0463000",
"price_r": {
"n": 463,
"d": 10000
},
"buying_asset_type": "credit_alphanum4",
"buying_asset_code": "RMT",
"buying_asset_issuer": "GDEGOXPCHXWFYY234D2YZSPEJ24BX42ESJNVHY5H7TWWQSYRN5ZKZE3N",
"selling_asset_type": "native",
"offer_id": 1
}
4 changes: 2 additions & 2 deletions stellar-dotnet-sdk-test/testdata/tradeAggregationsPage.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"_embedded": {
"records": [
{
"timestamp": 1517522400000,
"trade_count": 26,
"timestamp": "1517522400000",
"trade_count": "26",
"base_volume": "27575.0201596",
"counter_volume": "5085.6410385",
"avg": "0.1844293",
Expand Down
68 changes: 68 additions & 0 deletions stellar-dotnet-sdk-test/testdata/tradeAggregationsPagePre100.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"_links": {
"self": {
"href": "https://horizon.stellar.org/trade_aggregations?base_asset_type=native&counter_asset_code=SLT&counter_asset_issuer=GCKA6K5PCQ6PNF5RQBF7PQDJWRHO6UOGFMRLK3DYHDOI244V47XKQ4GP&counter_asset_type=credit_alphanum4&limit=200&order=asc&resolution=3600000&start_time=1517521726000&end_time=1517532526000"
},
"next": {
"href": "https://horizon.stellar.org/trade_aggregations?base_asset_type=native&counter_asset_code=SLT&counter_asset_issuer=GCKA6K5PCQ6PNF5RQBF7PQDJWRHO6UOGFMRLK3DYHDOI244V47XKQ4GP&counter_asset_type=credit_alphanum4&end_time=1517532526000&limit=200&order=asc&resolution=3600000&start_time=1517529600000"
}
},
"_embedded": {
"records": [
{
"timestamp": 1517522400000,
"trade_count": 26,
"base_volume": "27575.0201596",
"counter_volume": "5085.6410385",
"avg": "0.1844293",
"high": "0.1915709",
"high_r": {
"N": 50,
"D": 261
},
"low": "0.1506024",
"low_r": {
"N": 25,
"D": 166
},
"open": "0.1724138",
"open_r": {
"N": 5,
"D": 29
},
"close": "0.1506024",
"close_r": {
"N": 25,
"D": 166
}
},
{
"timestamp": 1517526000000,
"trade_count": 15,
"base_volume": "3913.8224543",
"counter_volume": "719.4993608",
"avg": "0.1838355",
"high": "0.1960784",
"high_r": {
"N": 10,
"D": 51
},
"low": "0.1506024",
"low_r": {
"N": 25,
"D": 166
},
"open": "0.1869159",
"open_r": {
"N": 20,
"D": 107
},
"close": "0.1515152",
"close_r": {
"N": 5,
"D": 33
}
}
]
}
}