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

Commit 8cb5423

Browse files
committed
Added new tests to cover pre Horizon 1.0.0 type changes.
1 parent e689191 commit 8cb5423

13 files changed

+289
-7
lines changed

stellar-dotnet-sdk-test/responses/EffectDeserializerTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,28 @@ public void TestSerializeDeserializeTradeEffect()
602602
AssertTradeData(back);
603603
}
604604

605+
//Before Horizon 1.0.0 the OfferID in the json was a long.
606+
[TestMethod]
607+
public void TestDeserializeTradeEffectPre100()
608+
{
609+
var json = File.ReadAllText(Path.Combine("testdata", "effectTradePre100.json"));
610+
var instance = JsonSingleton.GetInstance<EffectResponse>(json);
611+
612+
AssertTradeData(instance);
613+
}
614+
615+
//Before Horizon 1.0.0 the OfferID in the json was a long.
616+
[TestMethod]
617+
public void TestSerializeDeserializeTradeEffectPre100()
618+
{
619+
var json = File.ReadAllText(Path.Combine("testdata", "effectTradePre100.json"));
620+
var instance = JsonSingleton.GetInstance<EffectResponse>(json);
621+
var serialized = JsonConvert.SerializeObject(instance);
622+
var back = JsonConvert.DeserializeObject<EffectResponse>(serialized);
623+
624+
AssertTradeData(back);
625+
}
626+
605627
private static void AssertTradeData(EffectResponse instance)
606628
{
607629
//There is a JsonConverter called OperationDeserializer that instantiates the type based on the json type_i element...

stellar-dotnet-sdk-test/responses/OfferPageDeserializerTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ public void TestSerializeDeserialize()
3030
AssertTestData(back);
3131
}
3232

33+
//Before Horizon 1.0.0 the ID in the json was a long.
34+
[TestMethod]
35+
public void TestDeserializePre100()
36+
{
37+
var json = File.ReadAllText(Path.Combine("testdata", "offerPagePre100.json"));
38+
var offerResponsePage = JsonSingleton.GetInstance<Page<OfferResponse>>(json);
39+
40+
AssertTestData(offerResponsePage);
41+
}
42+
43+
//Before Horizon 1.0.0 the ID in the json was a long.
44+
[TestMethod]
45+
public void TestSerializeDeserializePre100()
46+
{
47+
var json = File.ReadAllText(Path.Combine("testdata", "offerPagePre100.json"));
48+
var offerResponsePage = JsonSingleton.GetInstance<Page<OfferResponse>>(json);
49+
var serialized = JsonConvert.SerializeObject(offerResponsePage);
50+
var back = JsonConvert.DeserializeObject<Page<OfferResponse>>(serialized);
51+
52+
AssertTestData(back);
53+
}
54+
3355
public static void AssertTestData(Page<OfferResponse> offerResponsePage)
3456
{
3557
Assert.AreEqual(offerResponsePage.Records[0].Id, "241");

stellar-dotnet-sdk-test/responses/OperationDeserializerTest.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,35 @@ public void TestSerializeDeserializeManageBuyOfferOperation()
343343
AssertManageBuyOfferData(back);
344344
}
345345

346+
//Before Horizon 1.0.0 the OfferID in the json was a long.
347+
[TestMethod]
348+
public void TestDeserializeManageBuyOfferOperationPre100()
349+
{
350+
var json = File.ReadAllText(Path.Combine("testdata", "operationManageBuyOfferPre100.json"));
351+
var instance = JsonSingleton.GetInstance<OperationResponse>(json);
352+
353+
AssertManageBuyOfferData(instance);
354+
}
355+
356+
//Before Horizon 1.0.0 the OfferID in the json was a long.
357+
[TestMethod]
358+
public void TestSerializeDeserializeManageBuyOfferOperationPre100()
359+
{
360+
var json = File.ReadAllText(Path.Combine("testdata", "operationManageBuyOfferPre100.json"));
361+
var instance = JsonSingleton.GetInstance<OperationResponse>(json);
362+
var serialized = JsonConvert.SerializeObject(instance);
363+
var back = JsonConvert.DeserializeObject<OperationResponse>(serialized);
364+
365+
AssertManageBuyOfferData(back);
366+
}
367+
346368
private static void AssertManageBuyOfferData(OperationResponse instance)
347369
{
348370
//There is a JsonConverter called OperationDeserializer that instantiates the type based on the json type_i element...
349371
Assert.IsTrue(instance is ManageBuyOfferOperationResponse);
350372
var operation = (ManageBuyOfferOperationResponse) instance;
351373

352-
Assert.AreEqual(operation.OfferId, "0");
374+
Assert.AreEqual(operation.OfferId, "1");
353375
Assert.AreEqual(operation.Amount, "50000.0000000");
354376
Assert.AreEqual(operation.Price, "0.0463000");
355377
Assert.AreEqual(operation.BuyingAsset,

stellar-dotnet-sdk-test/responses/TradeAggregationsPageDeserializerTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ public void TestSerializeDeserialize()
2929
AssertTestData(back);
3030
}
3131

32+
//Before Horizon 1.0.0 the Timestamp and TradeCount in the json were a long.
33+
[TestMethod]
34+
public void TestDeserializePre100()
35+
{
36+
var json = File.ReadAllText(Path.Combine("testdata", "tradeAggregationsPagePre100.json"));
37+
var tradeAggregationsPage = JsonSingleton.GetInstance<Page<TradeAggregationResponse>>(json);
38+
39+
AssertTestData(tradeAggregationsPage);
40+
}
41+
42+
//Before Horizon 1.0.0 the Timestamp and TradeCount in the json were a long.
43+
[TestMethod]
44+
public void TestSerializeDeserializePre100()
45+
{
46+
var json = File.ReadAllText(Path.Combine("testdata", "tradeAggregationsPagePre100.json"));
47+
var tradeAggregationsPage = JsonSingleton.GetInstance<Page<TradeAggregationResponse>>(json);
48+
var serialized = JsonConvert.SerializeObject(tradeAggregationsPage);
49+
var back = JsonConvert.DeserializeObject<Page<TradeAggregationResponse>>(serialized);
50+
51+
AssertTestData(back);
52+
}
53+
3254
public static void AssertTestData(Page<TradeAggregationResponse> tradeAggregationsPage)
3355
{
3456
Assert.AreEqual(tradeAggregationsPage.Links.Next.Href,

stellar-dotnet-sdk-test/stellar-dotnet-sdk-test.csproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
<None Update="testdata\effectPage.json">
6969
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7070
</None>
71+
<None Update="testdata\effectTradePre100.json">
72+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
73+
</None>
7174
<None Update="testdata\effectTrade.json">
7275
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7376
</None>
@@ -134,6 +137,9 @@
134137
<None Update="testdata\ledgerPage.json">
135138
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
136139
</None>
140+
<None Update="testdata\offerPagePre100.json">
141+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
142+
</None>
137143
<None Update="testdata\offerPage.json">
138144
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
139145
</None>
@@ -155,6 +161,9 @@
155161
<None Update="testdata\operationInflation.json">
156162
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
157163
</None>
164+
<None Update="testdata\operationManageBuyOffer.json">
165+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
166+
</None>
158167
<None Update="testdata\operationManageData.json">
159168
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
160169
</None>
@@ -221,6 +230,9 @@
221230
<None Update="testdata\submitTransactionTransactionFailure.json">
222231
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
223232
</None>
233+
<None Update="testdata\tradeAggregationsPagePre100.json">
234+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
235+
</None>
224236
<None Update="testdata\tradeAggregationsPage.json">
225237
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
226238
</None>
@@ -236,7 +248,7 @@
236248
<None Update="testdata\transactionTransactionWithoutMemo.json">
237249
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
238250
</None>
239-
<None Update="testdata\operationManageBuyOffer.json">
251+
<None Update="testdata\operationManageBuyOfferPre100.json">
240252
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
241253
</None>
242254
<None Update="testdata\transactionTransactionPre020.json">

stellar-dotnet-sdk-test/testdata/effectTrade.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"type": "trade",
1717
"type_i": 33,
1818
"seller": "GCVHDLN6EHZBYW2M3BQIY32C23E4GPIRZZDBNF2Q73DAZ5VJDRGSMYRB",
19-
"offer_id": 1,
19+
"offer_id": "1",
2020
"sold_amount": "1000.0",
2121
"sold_asset_type": "credit_alphanum4",
2222
"sold_asset_code": "EUR",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"_links": {
3+
"operation": {
4+
"href": "http://horizon-testnet.stellar.org/operations/33788507721730"
5+
},
6+
"succeeds": {
7+
"href": "http://horizon-testnet.stellar.org/effects?order=desc&cursor=33788507721730-2"
8+
},
9+
"precedes": {
10+
"href": "http://horizon-testnet.stellar.org/effects?order=asc&cursor=33788507721730-2"
11+
}
12+
},
13+
"id": "0000033788507721730-0000000002",
14+
"paging_token": "33788507721730-2",
15+
"account": "GA6U5X6WOPNKKDKQULBR7IDHDBAQKOWPHYEC7WSXHZBFEYFD3XVZAKOO",
16+
"type": "trade",
17+
"type_i": 33,
18+
"seller": "GCVHDLN6EHZBYW2M3BQIY32C23E4GPIRZZDBNF2Q73DAZ5VJDRGSMYRB",
19+
"offer_id": 1,
20+
"sold_amount": "1000.0",
21+
"sold_asset_type": "credit_alphanum4",
22+
"sold_asset_code": "EUR",
23+
"sold_asset_issuer": "GCWVFBJ24754I5GXG4JOEB72GJCL3MKWC7VAEYWKGQHPVH3ENPNBSKWS",
24+
"bought_amount": "60.0",
25+
"bought_asset_type": "credit_alphanum12",
26+
"bought_asset_code": "TESTTEST",
27+
"bought_asset_issuer": "GAHXPUDP3AK6F2QQM4FIRBGPNGKLRDDSTQCVKEXXKKRHJZUUQ23D5BU7"
28+
}

stellar-dotnet-sdk-test/testdata/offerPage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"href": "https://horizon-testnet.stellar.org/accounts/GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD"
2222
}
2323
},
24-
"id": 241,
24+
"id": "241",
2525
"paging_token": "241",
2626
"seller": "GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD",
2727
"selling": {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"_links": {
3+
"self": {
4+
"href": "https://horizon-testnet.stellar.org/accounts/GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD/offers?order=asc&limit=10&cursor="
5+
},
6+
"next": {
7+
"href": "https://horizon-testnet.stellar.org/accounts/GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD/offers?order=asc&limit=10&cursor=241"
8+
},
9+
"prev": {
10+
"href": "https://horizon-testnet.stellar.org/accounts/GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD/offers?order=desc&limit=10&cursor=241"
11+
}
12+
},
13+
"_embedded": {
14+
"records": [
15+
{
16+
"_links": {
17+
"self": {
18+
"href": "https://horizon-testnet.stellar.org/offers/241"
19+
},
20+
"offer_maker": {
21+
"href": "https://horizon-testnet.stellar.org/accounts/GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD"
22+
}
23+
},
24+
"id": 241,
25+
"paging_token": "241",
26+
"seller": "GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD",
27+
"selling": {
28+
"asset_type": "credit_alphanum4",
29+
"asset_code": "INR",
30+
"asset_issuer": "GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD"
31+
},
32+
"buying": {
33+
"asset_type": "credit_alphanum4",
34+
"asset_code": "USD",
35+
"asset_issuer": "GA2IYMIZSAMDD6QQTTSIEL73H2BKDJQTA7ENDEEAHJ3LMVF7OYIZPXQD"
36+
},
37+
"amount": "10.0000000",
38+
"price_r": {
39+
"n": 10,
40+
"d": 1
41+
},
42+
"price": "11.0000000",
43+
"last_modified_ledger": 22200794,
44+
"last_modified_time": "2019-01-28T12:30:38Z"
45+
}
46+
]
47+
}
48+
}

stellar-dotnet-sdk-test/testdata/operationManageBuyOffer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@
3434
"buying_asset_code": "RMT",
3535
"buying_asset_issuer": "GDEGOXPCHXWFYY234D2YZSPEJ24BX42ESJNVHY5H7TWWQSYRN5ZKZE3N",
3636
"selling_asset_type": "native",
37-
"offer_id": 0
37+
"offer_id": "1"
3838
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"_links": {
3+
"self": {
4+
"href": "https://horizon.stellar.org/operations/105020235379187713"
5+
},
6+
"transaction": {
7+
"href": "https://horizon.stellar.org/transactions/35b08c8e7fc739ab07fd8eeb9564c59b4f1e85099aa2d3b1d37ed86a6cb5c438"
8+
},
9+
"effects": {
10+
"href": "https://horizon.stellar.org/operations/105020235379187713/effects"
11+
},
12+
"succeeds": {
13+
"href": "https://horizon.stellar.org/effects?order=desc&cursor=105020235379187713"
14+
},
15+
"precedes": {
16+
"href": "https://horizon.stellar.org/effects?order=asc&cursor=105020235379187713"
17+
}
18+
},
19+
"id": "105020235379187713",
20+
"paging_token": "105020235379187713",
21+
"transaction_successful": true,
22+
"source_account": "GDID4M4PAN3C2JO4PJPCZ4Z6PSYUTW2I32E5EBORECQYIJDGTIZO3N5D",
23+
"type": "manage_buy_offer",
24+
"type_i": 12,
25+
"created_at": "2019-06-21T08:24:48Z",
26+
"transaction_hash": "35b08c8e7fc739ab07fd8eeb9564c59b4f1e85099aa2d3b1d37ed86a6cb5c438",
27+
"amount": "50000.0000000",
28+
"price": "0.0463000",
29+
"price_r": {
30+
"n": 463,
31+
"d": 10000
32+
},
33+
"buying_asset_type": "credit_alphanum4",
34+
"buying_asset_code": "RMT",
35+
"buying_asset_issuer": "GDEGOXPCHXWFYY234D2YZSPEJ24BX42ESJNVHY5H7TWWQSYRN5ZKZE3N",
36+
"selling_asset_type": "native",
37+
"offer_id": 1
38+
}

stellar-dotnet-sdk-test/testdata/tradeAggregationsPage.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"_embedded": {
1111
"records": [
1212
{
13-
"timestamp": 1517522400000,
14-
"trade_count": 26,
13+
"timestamp": "1517522400000",
14+
"trade_count": "26",
1515
"base_volume": "27575.0201596",
1616
"counter_volume": "5085.6410385",
1717
"avg": "0.1844293",
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"_links": {
3+
"self": {
4+
"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"
5+
},
6+
"next": {
7+
"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"
8+
}
9+
},
10+
"_embedded": {
11+
"records": [
12+
{
13+
"timestamp": 1517522400000,
14+
"trade_count": 26,
15+
"base_volume": "27575.0201596",
16+
"counter_volume": "5085.6410385",
17+
"avg": "0.1844293",
18+
"high": "0.1915709",
19+
"high_r": {
20+
"N": 50,
21+
"D": 261
22+
},
23+
"low": "0.1506024",
24+
"low_r": {
25+
"N": 25,
26+
"D": 166
27+
},
28+
"open": "0.1724138",
29+
"open_r": {
30+
"N": 5,
31+
"D": 29
32+
},
33+
"close": "0.1506024",
34+
"close_r": {
35+
"N": 25,
36+
"D": 166
37+
}
38+
},
39+
{
40+
"timestamp": 1517526000000,
41+
"trade_count": 15,
42+
"base_volume": "3913.8224543",
43+
"counter_volume": "719.4993608",
44+
"avg": "0.1838355",
45+
"high": "0.1960784",
46+
"high_r": {
47+
"N": 10,
48+
"D": 51
49+
},
50+
"low": "0.1506024",
51+
"low_r": {
52+
"N": 25,
53+
"D": 166
54+
},
55+
"open": "0.1869159",
56+
"open_r": {
57+
"N": 20,
58+
"D": 107
59+
},
60+
"close": "0.1515152",
61+
"close_r": {
62+
"N": 5,
63+
"D": 33
64+
}
65+
}
66+
]
67+
}
68+
}

0 commit comments

Comments
 (0)