Skip to content

Commit

Permalink
Test string/int types responses
Browse files Browse the repository at this point in the history
Update canonical names to comments and tests
  • Loading branch information
bnogalm committed Feb 2, 2020
1 parent 08e10ec commit b985e49
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/responses/operations/operationresponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ class OperationResponse : public Response
* <li>change_trust</li>
* <li>set_options</li>
* <li>account_merge</li>
* <li>manage_offer</li>
* <li>path_payment</li>
* <li>create_passive_offer</li>
* <li>manage_buy_offer</li>
* <li>path_payment_strict_receive</li>
* <li>manage_sell_offer</li>
* <li>create_passive_sell_offer</li>
* <li>inflation</li>
* <li>manage_data</li>
* </ul>
Expand Down
46 changes: 46 additions & 0 deletions test/responses/effectdeserializertest.h
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,54 @@ private slots:
QCOMPARE(effect.getLinks().getOperation().getHref(), QString("http://horizon-testnet.stellar.org/operations/33788507721730"));
QCOMPARE(effect.getLinks().getSucceeds().getHref(), QString("http://horizon-testnet.stellar.org/effects?order=desc&cursor=33788507721730-2"));
QCOMPARE(effect.getLinks().getPrecedes().getHref(), QString("http://horizon-testnet.stellar.org/effects?order=asc&cursor=33788507721730-2"));

}

void testDeserializeTradeEffectOfferIDString() {
QByteArray json = "{\n"
" \"_links\": {\n"
" \"operation\": {\n"
" \"href\": \"http://horizon-testnet.stellar.org/operations/33788507721730\"\n"
" },\n"
" \"succeeds\": {\n"
" \"href\": \"http://horizon-testnet.stellar.org/effects?order=desc\\u0026cursor=33788507721730-2\"\n"
" },\n"
" \"precedes\": {\n"
" \"href\": \"http://horizon-testnet.stellar.org/effects?order=asc\\u0026cursor=33788507721730-2\"\n"
" }\n"
" },\n"
" \"id\": \"0000033788507721730-0000000002\",\n"
" \"paging_token\": \"33788507721730-2\",\n"
" \"account\": \"GA6U5X6WOPNKKDKQULBR7IDHDBAQKOWPHYEC7WSXHZBFEYFD3XVZAKOO\",\n"
" \"type\": \"trade\",\n"
" \"type_i\": 33,\n"
" \"seller\": \"GCVHDLN6EHZBYW2M3BQIY32C23E4GPIRZZDBNF2Q73DAZ5VJDRGSMYRB\",\n"
" \"offer_id\": \"2\",\n"
" \"sold_amount\": \"1000.0\",\n"
" \"sold_asset_type\": \"credit_alphanum4\",\n"
" \"sold_asset_code\": \"EUR\",\n"
" \"sold_asset_issuer\": \"GCWVFBJ24754I5GXG4JOEB72GJCL3MKWC7VAEYWKGQHPVH3ENPNBSKWS\",\n"
" \"bought_amount\": \"60.0\",\n"
" \"bought_asset_type\": \"credit_alphanum12\",\n"
" \"bought_asset_code\": \"TESTTEST\",\n"
" \"bought_asset_issuer\": \"GAHXPUDP3AK6F2QQM4FIRBGPNGKLRDDSTQCVKEXXKKRHJZUUQ23D5BU7\"\n"
" }";

TradeEffectResponse effect;
effect.loadFromJson(json);
QCOMPARE(effect.getAccount().getAccountId(), QString("GA6U5X6WOPNKKDKQULBR7IDHDBAQKOWPHYEC7WSXHZBFEYFD3XVZAKOO"));
QCOMPARE(effect.getSeller().getAccountId(), QString("GCVHDLN6EHZBYW2M3BQIY32C23E4GPIRZZDBNF2Q73DAZ5VJDRGSMYRB"));
QCOMPARE(effect.getOfferId(), 2);
QCOMPARE(effect.getSoldAmount(), QString("1000.0"));
QVERIFY(effect.getSoldAsset()->equals(Asset::createNonNativeAsset("EUR", KeyPair::fromAccountId(QString("GCWVFBJ24754I5GXG4JOEB72GJCL3MKWC7VAEYWKGQHPVH3ENPNBSKWS")))));
QCOMPARE(effect.getBoughtAmount(), QString("60.0"));
QVERIFY(effect.getBoughtAsset()->equals(Asset::createNonNativeAsset("TESTTEST", KeyPair::fromAccountId(QString("GAHXPUDP3AK6F2QQM4FIRBGPNGKLRDDSTQCVKEXXKKRHJZUUQ23D5BU7")))));

QCOMPARE(effect.getLinks().getOperation().getHref(), QString("http://horizon-testnet.stellar.org/operations/33788507721730"));
QCOMPARE(effect.getLinks().getSucceeds().getHref(), QString("http://horizon-testnet.stellar.org/effects?order=desc&cursor=33788507721730-2"));
QCOMPARE(effect.getLinks().getPrecedes().getHref(), QString("http://horizon-testnet.stellar.org/effects?order=asc&cursor=33788507721730-2"));

}

void testDeserializeDataCreatedEffect() {
QByteArray json = "{\n"
Expand Down
91 changes: 87 additions & 4 deletions test/responses/operationdeserializertest.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ private slots:
QCOMPARE(operation.getAccount().getAccountId(), QString("GD6GKRABNDVYDETEZJQEPS7IBQMERCN44R5RCI4LJNX6BMYQM2KPGGZ2"));
QCOMPARE(operation.getInto().getAccountId(), QString("GAZWSWPDQTBHFIPBY4FEDFW2J6E2LE7SZHJWGDZO6Q63W7DBSRICO2KN"));
}
void testDeserializeManageOfferOperation() {

void testDeserializeManageSellOfferOperation() {
QByteArray json = "{\n"
" \"_links\": {\n"
" \"self\": {\n"
Expand Down Expand Up @@ -477,6 +478,47 @@ private slots:
}


void testDeserializeManageSellOfferOperationOfferIDString() {
QByteArray json = "{\n"
" \"_links\": {\n"
" \"self\": {\n"
" \"href\": \"http://horizon-testnet.stellar.org/operations/3320426331639809\"\n"
" },\n"
" \"transaction\": {\n"
" \"href\": \"http://horizon-testnet.stellar.org/transactions/1f8fc03b26110e917d124381645d7dcf85927f17e46d8390d254a0bd99cfb0ad\"\n"
" },\n"
" \"effects\": {\n"
" \"href\": \"http://horizon-testnet.stellar.org/operations/3320426331639809/effects\"\n"
" },\n"
" \"succeeds\": {\n"
" \"href\": \"http://horizon-testnet.stellar.org/effects?order=desc\\u0026cursor=3320426331639809\"\n"
" },\n"
" \"precedes\": {\n"
" \"href\": \"http://horizon-testnet.stellar.org/effects?order=asc\\u0026cursor=3320426331639809\"\n"
" }\n"
" },\n"
" \"id\": \"3320426331639809\",\n"
" \"paging_token\": \"3320426331639809\",\n"
" \"source_account\": \"GCR6QXX7IRIJVIM5WA5ASQ6MWDOEJNBW3V6RTC5NJXEMOLVTUVKZ725X\",\n"
" \"type\": \"manage_offer\",\n"
" \"type_i\": 3,\n"
" \"offer_id\": \"10\",\n"
" \"amount\": \"100.0\",\n"
" \"buying_asset_type\": \"credit_alphanum4\",\n"
" \"buying_asset_code\": \"CNY\",\n"
" \"buying_asset_issuer\": \"GAZWSWPDQTBHFIPBY4FEDFW2J6E2LE7SZHJWGDZO6Q63W7DBSRICO2KN\",\n"
" \"selling_asset_type\": \"native\"\n"
" }";

ManageSellOfferOperationResponse operation;
operation.loadFromJson(json);

QCOMPARE(operation.getOfferId(), 10);
QCOMPARE(operation.getAmount(), QString("100.0"));
QVERIFY(operation.getBuyingAsset()->equals( Asset::createNonNativeAsset("CNY", KeyPair::fromAccountId(QString("GAZWSWPDQTBHFIPBY4FEDFW2J6E2LE7SZHJWGDZO6Q63W7DBSRICO2KN")))));
QVERIFY(operation.getSellingAsset()->equals( new AssetTypeNative()));
}

void testDeserializeManageBuyOfferOperation() {
QByteArray json = "{\n"
" \"_links\": {\n"
Expand Down Expand Up @@ -517,6 +559,47 @@ private slots:
QVERIFY(operation.getSellingAsset()->equals( new AssetTypeNative()));
}


void testDeserializeManageBuyOfferOperationOfferIDString() {
QByteArray json = "{\n"
" \"_links\": {\n"
" \"self\": {\n"
" \"href\": \"http://horizon-testnet.stellar.org/operations/3320426331639809\"\n"
" },\n"
" \"transaction\": {\n"
" \"href\": \"http://horizon-testnet.stellar.org/transactions/1f8fc03b26110e917d124381645d7dcf85927f17e46d8390d254a0bd99cfb0ad\"\n"
" },\n"
" \"effects\": {\n"
" \"href\": \"http://horizon-testnet.stellar.org/operations/3320426331639809/effects\"\n"
" },\n"
" \"succeeds\": {\n"
" \"href\": \"http://horizon-testnet.stellar.org/effects?order=desc\\u0026cursor=3320426331639809\"\n"
" },\n"
" \"precedes\": {\n"
" \"href\": \"http://horizon-testnet.stellar.org/effects?order=asc\\u0026cursor=3320426331639809\"\n"
" }\n"
" },\n"
" \"id\": \"3320426331639809\",\n"
" \"paging_token\": \"3320426331639809\",\n"
" \"source_account\": \"GCR6QXX7IRIJVIM5WA5ASQ6MWDOEJNBW3V6RTC5NJXEMOLVTUVKZ725X\",\n"
" \"type\": \"manage_buy_offer\",\n"
" \"type_i\": 12,\n"
" \"offer_id\": \"11\",\n"
" \"amount\": \"100.0\",\n"
" \"buying_asset_type\": \"credit_alphanum4\",\n"
" \"buying_asset_code\": \"CNY\",\n"
" \"buying_asset_issuer\": \"GAZWSWPDQTBHFIPBY4FEDFW2J6E2LE7SZHJWGDZO6Q63W7DBSRICO2KN\",\n"
" \"selling_asset_type\": \"native\"\n"
" }";

ManageBuyOfferOperationResponse operation;
operation.loadFromJson(json);
QCOMPARE(operation.getOfferId(), 11);
QCOMPARE(operation.getAmount(), QString("100.0"));
QVERIFY(operation.getBuyingAsset()->equals( Asset::createNonNativeAsset("CNY", KeyPair::fromAccountId(QString("GAZWSWPDQTBHFIPBY4FEDFW2J6E2LE7SZHJWGDZO6Q63W7DBSRICO2KN")))));
QVERIFY(operation.getSellingAsset()->equals( new AssetTypeNative()));
}

void testDeserializePathPaymentOperation() {
QByteArray json = "{\n"
" \"_links\": {\n"
Expand Down Expand Up @@ -550,7 +633,7 @@ private slots:
" \"source_max\": \"100.0\",\n"
" \"to\": \"GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2\",\n"
" \"type_i\": 2,\n"
" \"type\": \"path_payment\"\n"
" \"type\": \"path_payment_strict_receive\"\n"
"}";

PathPaymentOperationResponse operation;
Expand Down Expand Up @@ -585,7 +668,7 @@ private slots:
" \"id\": \"75252830662840321\",\n"
" \"paging_token\": \"75252830662840321\",\n"
" \"source_account\": \"GC45JH537XZD4DY4WTV5PCUJL4KPOIE4WMGX5OP5KSPS2OLGRUOVVIGD\",\n"
" \"type\": \"path_payment\",\n"
" \"type\": \"path_payment_strict_receive\",\n"
" \"type_i\": 2,\n"
" \"created_at\": \"2018-04-24T12:58:12Z\",\n"
" \"transaction_hash\": \"fb2f5655c70a459220ac09eb3d6870422b58dcf5c5ffb5e5b21817b4d248826e\",\n"
Expand Down Expand Up @@ -712,7 +795,7 @@ private slots:
" },\n"
" \"selling_asset_type\": \"native\",\n"
" \"type_i\": 4,\n"
" \"type\": \"create_passive_offer\"\n"
" \"type\": \"create_passive_sell_offer\"\n"
"}";

CreatePassiveSellOfferOperationResponse operation;
Expand Down
8 changes: 6 additions & 2 deletions test/responses/tradeaggregationspagedeserializertest.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ private slots:
QCOMPARE(page.get(0).getLow(), QString("0.0000124"));
QCOMPARE(page.get(0).getOpen(), QString("0.0000125"));
QCOMPARE(page.get(0).getClose(), QString("0.0000126"));

//support parse string timestamp and trade_count
QCOMPARE(page.get(1).getTimestamp(), (qint64)1512732300000);
QCOMPARE(page.get(1).getTradeCount(), (qint32)1);
}

QByteArray json = "{\n"
Expand All @@ -65,8 +69,8 @@ private slots:
" \"close\": \"0.0000126\"\n"
" },\n"
" {\n"
" \"timestamp\": 1512732300000,\n"
" \"trade_count\": 1,\n"
" \"timestamp\": \"1512732300000\",\n"
" \"trade_count\": \"1\",\n"
" \"base_volume\": \"233.6065573\",\n"
" \"counter_volume\": \"0.0028500\",\n"
" \"avg\": \"0.0000122\",\n"
Expand Down

0 comments on commit b985e49

Please sign in to comment.