From d12af6f7f14b42bd4c53243f2772f0f2bd35a4f9 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 5 Feb 2019 10:20:17 -0800 Subject: [PATCH 1/6] misc: add arduino sketch path to config - this change also fixes the 'platformio_example' path --- library.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library.json b/library.json index 448c277f..b676b5b0 100644 --- a/library.json +++ b/library.json @@ -62,8 +62,9 @@ ] }, "examples": [ - "[Ee]xamples/platformio_example/*.ino", - "[Ee]xamples/platformio_example/*.cpp", - "[Ee]xamples/platformio_example/*.c" + "[Ee]xamples/arduino/*/*.ino", + "[Ee]xamples/platformio_example/*/*.ino", + "[Ee]xamples/platformio_example/*/*.cpp", + "[Ee]xamples/platformio_example/*/*.c" ] } From 7e952a5519e8e3835b0a8652aee9d552579c4a99 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 5 Feb 2019 10:24:54 -0800 Subject: [PATCH 2/6] Revert "misc: add arduino sketch path to config" This reverts commit d12af6f7f14b42bd4c53243f2772f0f2bd35a4f9. --- library.json | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/library.json b/library.json index b676b5b0..448c277f 100644 --- a/library.json +++ b/library.json @@ -62,9 +62,8 @@ ] }, "examples": [ - "[Ee]xamples/arduino/*/*.ino", - "[Ee]xamples/platformio_example/*/*.ino", - "[Ee]xamples/platformio_example/*/*.cpp", - "[Ee]xamples/platformio_example/*/*.c" + "[Ee]xamples/platformio_example/*.ino", + "[Ee]xamples/platformio_example/*.cpp", + "[Ee]xamples/platformio_example/*.c" ] } From c713649a1ebe2a9839437736795347c32455a8aa Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 5 Feb 2019 10:24:54 -0800 Subject: [PATCH 3/6] Revert "misc: add arduino sketch path to config" This reverts commit d12af6f7f14b42bd4c53243f2772f0f2bd35a4f9. --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index 27f9fddc..e60a392b 100644 --- a/library.json +++ b/library.json @@ -39,4 +39,4 @@ "-I src/include/cpp-client" ] } -} +} \ No newline at end of file From 14dbcf41f711b2954271d3c64c7e191998810141 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 9 May 2019 18:02:34 -0700 Subject: [PATCH 4/6] chore: update ArduinoJson version - update ArduinoJson v.5.13.2 >> v.6.10.1 - update ArduinoJson submodule. - updated PIO.ini ArduinoJson flags (enforce v.6.10.1). - update JSON use patterns in tests. - update Wallets::Top test case. - add ESP8266 & ESP32 WiFi option to test_main.cpp for IoT. - update documentation with changes. --- .gitmodules | 6 +- CHANGELOG.md | 1 + docs/INSTALL_ARDUINO.md | 2 +- docs/INSTALL_PLATFORMIO.md | 4 +- docs/cpp.md | 6 +- test/api/blocks.cpp | 118 ++++++++-------- test/api/delegates.cpp | 96 +++++++------ test/api/node.cpp | 37 ++--- test/api/peers.cpp | 28 ++-- test/api/transactions.cpp | 133 +++++++++--------- test/api/votes.cpp | 40 +++--- test/api/wallets.cpp | 269 +++++++++++++++++++++++-------------- test/http/http.cpp | 70 +++++----- test/iot/test_main.cpp | 35 ++++- test/lib/ArduinoJson | 2 +- test/platformio.ini | 2 +- 16 files changed, 496 insertions(+), 353 deletions(-) diff --git a/.gitmodules b/.gitmodules index 80f01793..3c745ed6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,7 @@ -[submodule "test/lib/ArduinoJson"] - path = test/lib/ArduinoJson - url = https://github.com/bblanchon/ArduinoJson [submodule "test/lib/googletest"] path = test/lib/googletest url = https://github.com/google/googletest.git +[submodule "test/lib/ArduinoJson"] + path = test/lib/ArduinoJson + url = https://github.com/bblanchon/ArduinoJson diff --git a/CHANGELOG.md b/CHANGELOG.md index edd3a622..9ddf5870 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +- update ArduinoJson 5.13.2 >> 6.10.1, usage patterns, and documentation/examples. - use "statusCode" '422' to test API Post response for empty Transactions objects. ## [1.2.0] - 2019-02-16 diff --git a/docs/INSTALL_ARDUINO.md b/docs/INSTALL_ARDUINO.md index bb7f48db..9a9d7172 100644 --- a/docs/INSTALL_ARDUINO.md +++ b/docs/INSTALL_ARDUINO.md @@ -15,7 +15,7 @@ Download and install the Arduino IDE (>=1.8.5) from the following link: Using the Arduino IDE's built in Library Manager, install the following Libraries -- ArduinoJson v5.13.2 +- ArduinoJson v6.10.1 - AUnit # diff --git a/docs/INSTALL_PLATFORMIO.md b/docs/INSTALL_PLATFORMIO.md index fced1874..5adc364a 100644 --- a/docs/INSTALL_PLATFORMIO.md +++ b/docs/INSTALL_PLATFORMIO.md @@ -18,8 +18,8 @@ or also install platformio dependencies: -> install ArduinoJson@5.13.2 AUnit (2778) -```platformio lib -g install 64@5.13.2 2778``` +> install ArduinoJson@6.10.1 AUnit (2778) +```platformio lib -g install 64@6.10.1 2778``` # diff --git a/docs/cpp.md b/docs/cpp.md index c6f5a581..cf4d176e 100644 --- a/docs/cpp.md +++ b/docs/cpp.md @@ -106,7 +106,7 @@ Download and install the Arduino IDE (>=1.8.5) from the following link: Using the Arduino IDE's built in Library Manager, install the following Libraries: -```ArduinoJson v5.13.2``` +```ArduinoJson v6.10.1``` ```AUnit``` #### Arduino Example using the Adafruit Feather ESP8266 @@ -161,9 +161,9 @@ or python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/develop/scripts/get-platformio.py)" -Install ArduinoJson@5.13.2 AUnit (2778) +Install ArduinoJson@6.10.1 AUnit (2778) - platformio lib -g install 64@5.13.2 2778 + platformio lib -g install 64@6.10.1 2778 #### Provide your WiFi info for your board to access the internet diff --git a/test/api/blocks.cpp b/test/api/blocks.cpp index 9d77bb77..157a0228 100644 --- a/test/api/blocks.cpp +++ b/test/api/blocks.cpp @@ -81,12 +81,13 @@ TEST(api, test_block) { // NOLINT const auto blockResponse = connection.api.blocks.get("58328125061111756"); - DynamicJsonBuffer jsonBuffer(blockResponse.size()); - JsonObject& root = jsonBuffer.parseObject(blockResponse); + DynamicJsonDocument doc(1244); + DeserializationError error = deserializeJson(doc, blockResponse); + if (error) { exit(0); } - JsonObject& data = root["data"]; + JsonObject data = doc["data"]; - const char* id = data["id"]; + const auto id = data["id"]; ASSERT_STREQ("58328125061111756", id); int version = data["version"]; @@ -95,7 +96,7 @@ TEST(api, test_block) { // NOLINT int height = data["height"]; ASSERT_EQ(3035362, height); - JsonObject& forged = data["forged"]; + JsonObject forged = data["forged"]; uint64_t reward = forged["reward"]; ASSERT_TRUE(reward == 200000000); @@ -106,35 +107,38 @@ TEST(api, test_block) { // NOLINT uint64_t total = forged["total"]; ASSERT_TRUE(total == 200000000); - JsonObject& payload = data["payload"]; + JsonObject payload = data["payload"]; - const char* hash = payload["hash"]; - ASSERT_STREQ("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", hash); + const auto hash = payload["hash"]; + ASSERT_STREQ( + "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + hash); int length = payload["length"]; ASSERT_EQ(0, length); - JsonObject& generator = data["generator"]; + JsonObject generator = data["generator"]; - const char* username = generator["username"]; + const auto username = generator["username"]; ASSERT_STREQ("genesis_6", username); - const char* address = generator["address"]; + const auto address = generator["address"]; ASSERT_STREQ("D5e2FzTPqdEHridjzpFZCCVyepAu6Vpmk4", address); - const char* publicKey = generator["publicKey"]; - ASSERT_STREQ("023e577a7b3362e0aba70e6911d230e86d729b4cb640f0e0b25637b812a3e38b53", publicKey); + const auto publicKey = generator["publicKey"]; + ASSERT_STREQ( + "023e577a7b3362e0aba70e6911d230e86d729b4cb640f0e0b25637b812a3e38b53", + publicKey); - const char* signature = data["signature"]; + const auto signature = data["signature"]; ASSERT_STREQ( - "3044022047aeb0c9cfbb5709aba4c177009bfdc7804ef597073fb9ca6cb614d7e3d1af2d02207234119d02ca26600ece045c59266945081b" - "4c8237370576aaad7c61a09fe0ad", + "3044022047aeb0c9cfbb5709aba4c177009bfdc7804ef597073fb9ca6cb614d7e3d1af2d02207234119d02ca26600ece045c59266945081b4c8237370576aaad7c61a09fe0ad", signature); int transactions = data["transactions"]; ASSERT_EQ(0, transactions); - JsonObject& timestamp = data["timestamp"]; + JsonObject timestamp = data["timestamp"]; int epoch = timestamp["epoch"]; ASSERT_EQ(32816544, epoch); @@ -142,7 +146,7 @@ TEST(api, test_block) { // NOLINT int timestampUnix = timestamp["unix"]; ASSERT_EQ(1522917744, timestampUnix); - const char* human = timestamp["human"]; + const auto human = timestamp["human"]; ASSERT_STREQ("2018-04-05T08:42:24Z", human); } @@ -221,11 +225,12 @@ TEST(api, test_block_transactions) { // NOLINT EXPECT_CALL(connection.api.blocks, transactions(_)).Times(1).WillOnce(Return(expected_response)); const auto blockTransactionsResponse = connection.api.blocks.transactions("14126007750611341900"); + + DynamicJsonDocument doc(1452); + DeserializationError error = deserializeJson(doc, blockTransactionsResponse); + if (error) { exit(0); } - DynamicJsonBuffer jsonBuffer(blockTransactionsResponse.size()); - JsonObject& root = jsonBuffer.parseObject(blockTransactionsResponse); - - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_EQ(1, count); @@ -236,12 +241,14 @@ TEST(api, test_block_transactions) { // NOLINT int totalCount = meta["totalCount"]; ASSERT_EQ(1, totalCount); - JsonObject& dataZero = root["data"][0]; + JsonObject dataZero = doc["data"][0]; - const char* id = dataZero["id"]; - ASSERT_STREQ("57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369", id); + const auto id = dataZero["id"]; + ASSERT_STREQ( + "57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369", + id); - const char* blockId = dataZero["blockId"]; + const auto blockId = dataZero["blockId"]; ASSERT_STREQ("14126007750611341900", blockId); int type = dataZero["type"]; @@ -253,19 +260,18 @@ TEST(api, test_block_transactions) { // NOLINT uint64_t fee = dataZero["fee"]; ASSERT_TRUE(fee == 10000000); - const char* sender = dataZero["sender"]; + const auto sender = dataZero["sender"]; ASSERT_STREQ("DGihocTkwDygiFvmg6aG8jThYTic47GzU9", sender); - const char* signature = dataZero["signature"]; + const auto signature = dataZero["signature"]; ASSERT_STREQ( - "3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1" - "c34df8a46afe655b021930b03e214e", + "3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1c34df8a46afe655b021930b03e214e", signature); int confirmations = dataZero["confirmations"]; ASSERT_EQ(3034848, confirmations); - JsonObject& timestamp = dataZero["timestamp"]; + JsonObject timestamp = dataZero["timestamp"]; int epoch = timestamp["epoch"]; ASSERT_EQ(3909196, epoch); @@ -273,7 +279,7 @@ TEST(api, test_block_transactions) { // NOLINT int timestampUnix = timestamp["unix"]; ASSERT_EQ(1494010396, timestampUnix); - const char* human = timestamp["human"]; + const auto human = timestamp["human"]; ASSERT_STREQ("2017-05-05T18:53:16Z", human); } @@ -374,10 +380,11 @@ TEST(api, test_blocks) { // NOLINT const auto blocksResponse = connection.api.blocks.all(5, 1); - DynamicJsonBuffer jsonBuffer(blocksResponse.size()); - JsonObject& root = jsonBuffer.parseObject(blocksResponse); + DynamicJsonDocument doc(1740); + DeserializationError error = deserializeJson(doc, blocksResponse); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_NE(0, count); @@ -388,7 +395,7 @@ TEST(api, test_blocks) { // NOLINT int totalCount = meta["totalCount"]; ASSERT_NE(0, totalCount); - JsonObject& dataZero = root["data"][0]; + JsonObject dataZero = doc["data"][0]; int version = dataZero["version"]; ASSERT_EQ(0, version); @@ -478,17 +485,19 @@ TEST(api, test_blocks_search) { // NOLINT ] })"; - const std::map body = { - {"id", "8337447655053578871"}, {"previousBlock", "6440284271011893973"}, {"version", "0"}}; - EXPECT_CALL(connection.api.blocks, search(_, _, _)).Times(1).WillOnce(Return(expected_response)); + const std::map body = { + { "id", "8337447655053578871" }, + { "previousBlock", "6440284271011893973" }, + { "version", "0" }}; const auto walletsSearch = connection.api.blocks.search(body, 5, 1); - DynamicJsonBuffer jsonBuffer(walletsSearch.size()); - JsonObject& root = jsonBuffer.parseObject(walletsSearch); + DynamicJsonDocument doc(1476); + DeserializationError error = deserializeJson(doc, walletsSearch); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_NE(0, count); @@ -499,12 +508,14 @@ TEST(api, test_blocks_search) { // NOLINT int totalCount = meta["totalCount"]; ASSERT_NE(0, totalCount); - JsonObject& dataZero = root["data"][0]; + JsonObject dataZero = doc["data"][0]; - const char* id = dataZero["id"]; - ASSERT_STREQ("57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369", id); + const auto id = dataZero["id"]; + ASSERT_STREQ( + "57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369", + id); - const char* blockId = dataZero["blockId"]; + const auto blockId = dataZero["blockId"]; ASSERT_STREQ("14126007750611341900", blockId); int type = dataZero["type"]; @@ -516,25 +527,24 @@ TEST(api, test_blocks_search) { // NOLINT uint64_t fee = dataZero["fee"]; ASSERT_TRUE(10000000ull == fee); - const char* sender = dataZero["sender"]; + const auto sender = dataZero["sender"]; ASSERT_STREQ("DGihocTkwDygiFvmg6aG8jThYTic47GzU9", sender); - const char* recipient = dataZero["recipient"]; + const auto recipient = dataZero["recipient"]; ASSERT_STREQ("DRac35wghMcmUSe5jDMLBDLWkVVjyKZFxK", recipient); - const char* signature = dataZero["signature"]; + const auto signature = dataZero["signature"]; ASSERT_STREQ( - "3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1" - "c34df8a46afe655b021930b03e214e", + "3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1c34df8a46afe655b021930b03e214e", signature); - const char* vendorField = dataZero["vendorField"]; + const auto vendorField = dataZero["vendorField"]; ASSERT_STREQ("yo", vendorField); int confirmations = dataZero["confirmations"]; ASSERT_EQ(3034848, confirmations); - JsonObject& timestamp = dataZero["timestamp"]; + JsonObject timestamp = dataZero["timestamp"]; uint64_t epoch = timestamp["epoch"]; ASSERT_TRUE(3909196ull == epoch); @@ -542,6 +552,6 @@ TEST(api, test_blocks_search) { // NOLINT uint64_t unix_timestamp = timestamp["unix"]; ASSERT_TRUE(1494010396ull == unix_timestamp); - const char* human = timestamp["human"]; + const auto human = timestamp["human"]; ASSERT_STREQ("2017-05-05T18:53:16Z", human); } diff --git a/test/api/delegates.cpp b/test/api/delegates.cpp index d7207d53..9b799d02 100644 --- a/test/api/delegates.cpp +++ b/test/api/delegates.cpp @@ -73,19 +73,22 @@ TEST(api, test_delegate) { // NOLINT const auto delegateResponse = connection.api.delegates.get("boldninja"); - DynamicJsonBuffer jsonBuffer(delegateResponse.size()); - JsonObject& root = jsonBuffer.parseObject(delegateResponse); + DynamicJsonDocument doc(876); + DeserializationError error = deserializeJson(doc, delegateResponse); + if (error) { exit(0); } - JsonObject& data = root["data"]; + JsonObject data = doc["data"]; - const char* username = data["username"]; + const auto username = data["username"]; ASSERT_STREQ("boldninja", username); - const char* address = data["address"]; + const auto address = data["address"]; ASSERT_STREQ("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", address); - const char* publicKey = data["publicKey"]; - ASSERT_STREQ("022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d", publicKey); + const auto publicKey = data["publicKey"]; + ASSERT_STREQ( + "022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d", + publicKey); uint64_t votes = data["votes"]; ASSERT_EQ(0, votes); @@ -93,7 +96,7 @@ TEST(api, test_delegate) { // NOLINT int rank = data["rank"]; ASSERT_EQ(29, rank); - JsonObject& blocks = data["blocks"]; + JsonObject blocks = data["blocks"]; int produced = blocks["produced"]; ASSERT_EQ(0, produced); @@ -101,12 +104,12 @@ TEST(api, test_delegate) { // NOLINT int missed = blocks["missed"]; ASSERT_EQ(0, missed); - JsonObject& last = blocks["last"]; + JsonObject last = blocks["last"]; - const char* last_id = last["id"]; + const auto last_id = last["id"]; ASSERT_STREQ("10652480998435361357", last_id); - JsonObject& timestamp = last["timestamp"]; + JsonObject timestamp = last["timestamp"]; uint64_t epoch = timestamp["epoch"]; ASSERT_TRUE(32816112ull == epoch); @@ -114,10 +117,10 @@ TEST(api, test_delegate) { // NOLINT uint64_t unix_timestamp = timestamp["unix"]; ASSERT_TRUE(1522917312ull == unix_timestamp); - const char* human = timestamp["human"]; + const auto human = timestamp["human"]; ASSERT_STREQ("2018-04-05T08:35:12Z", human); - JsonObject& production = data["production"]; + JsonObject production = data["production"]; double approval = production["approval"]; ASSERT_EQ(0.10, approval); @@ -228,12 +231,13 @@ TEST(api, test_delegate_blocks) { // NOLINT EXPECT_CALL(connection.api.delegates, blocks(_, _, _)).Times(1).WillOnce(Return(expected_response)); - const auto delegateBlocksResponse = connection.api.delegates.blocks("boldninja", 3, 1); + const auto delegateBlocksResponse = connection.api.delegates.blocks("boldninja", 2, 1); - DynamicJsonBuffer jsonBuffer(delegateBlocksResponse.size()); - JsonObject& root = jsonBuffer.parseObject(delegateBlocksResponse); + DynamicJsonDocument doc(1788); + DeserializationError error = deserializeJson(doc, delegateBlocksResponse); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_EQ(2, count); @@ -244,26 +248,32 @@ TEST(api, test_delegate_blocks) { // NOLINT int totalCount = meta["totalCount"]; ASSERT_EQ(59838, totalCount); - const char* id = root["data"][0]["id"]; + JsonObject dataZero = doc["data"][0]; + + const auto id = dataZero["id"]; ASSERT_STREQ("10652480998435361357", id); - int version = root["data"][0]["version"]; + int version = dataZero["version"]; ASSERT_EQ(0, version); - uint64_t height = root["data"][0]["height"]; + uint64_t height = dataZero["height"]; ASSERT_TRUE(3035318ull == height); - const char* previous = root["data"][0]["previous"]; + const auto previous = dataZero["previous"]; ASSERT_STREQ("12548322724277171379", previous); - const char* username = root["data"][0]["generator"]["username"]; + JsonObject generatorZero = dataZero["generator"]; + + const auto username = generatorZero["username"]; ASSERT_STREQ("boldninja", username); - const char* address = root["data"][0]["generator"]["address"]; + const auto address = generatorZero["address"]; ASSERT_STREQ("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", address); - const char* publicKey = root["data"][0]["generator"]["publicKey"]; - ASSERT_STREQ("022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d", publicKey); + const auto publicKey = generatorZero["publicKey"]; + ASSERT_STREQ( + "022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d", + publicKey); } /* test_delegates_delegate_voters @@ -322,10 +332,11 @@ TEST(api, test_delegate_voters) { // NOLINT const auto delegateVotersResponse = connection.api.delegates.voters("boldninja", 5, 1); - DynamicJsonBuffer jsonBuffer(delegateVotersResponse.size()); - JsonObject& root = jsonBuffer.parseObject(delegateVotersResponse); + DynamicJsonDocument doc(836); + DeserializationError error = deserializeJson(doc, delegateVotersResponse); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_NE(0, count); @@ -336,13 +347,15 @@ TEST(api, test_delegate_voters) { // NOLINT int totalCount = meta["totalCount"]; ASSERT_NE(0, totalCount); - JsonObject& dataZero = root["data"][0]; + JsonObject dataZero = doc["data"][0]; - const char* address = dataZero["address"]; + const auto address = dataZero["address"]; ASSERT_STREQ("D5mbS6mpP5UheuciNscpDLgC127kYjRtkK", address); - const char* publicKey = dataZero["publicKey"]; - ASSERT_STREQ("03f7e0b1ab14985990416f72ed0b206c20b9efa35156e4528c8ff749fa0eea5d5a", publicKey); + const auto publicKey = dataZero["publicKey"]; + ASSERT_STREQ( + "03f7e0b1ab14985990416f72ed0b206c20b9efa35156e4528c8ff749fa0eea5d5a", + publicKey); bool isDelegate = dataZero["isDelegate"]; ASSERT_FALSE(isDelegate); @@ -437,10 +450,11 @@ TEST(api, test_delegates) { // NOLINT const auto delegates = connection.api.delegates.all(5, 1); - DynamicJsonBuffer jsonBuffer(delegates.size()); - JsonObject& root = jsonBuffer.parseObject(delegates); + DynamicJsonDocument doc(1340); + DeserializationError error = deserializeJson(doc, delegates); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_NE(0, count); @@ -451,16 +465,18 @@ TEST(api, test_delegates) { // NOLINT int totalCount = meta["totalCount"]; ASSERT_NE(0, totalCount); - JsonObject& dataZero = root["data"][0]; + JsonObject dataZero = doc["data"][0]; - const char* username = dataZero["username"]; + const auto username = dataZero["username"]; ASSERT_STREQ("dark_jmc", username); - const char* address = dataZero["address"]; + const auto address = dataZero["address"]; ASSERT_STREQ("D5PXQVeJmchVrZFHL7cALZK8mWWzjCaVfz", address); - const char* publicKey = dataZero["publicKey"]; - ASSERT_STREQ("02a9a0ac34a94f9d27fd9b4b56eb3c565a9a3f61e660f269775fb456f7f3301586", publicKey); + const auto publicKey = dataZero["publicKey"]; + ASSERT_STREQ( + "02a9a0ac34a94f9d27fd9b4b56eb3c565a9a3f61e660f269775fb456f7f3301586", + publicKey); uint64_t votes = dataZero["votes"]; ASSERT_TRUE(0ull == votes); diff --git a/test/api/node.cpp b/test/api/node.cpp index 360ff594..667b35d2 100644 --- a/test/api/node.cpp +++ b/test/api/node.cpp @@ -158,27 +158,30 @@ TEST(api, test_node_configuration) { // NOLINT const auto nodeConfiguration = connection.api.node.configuration(); - DynamicJsonBuffer jsonBuffer(nodeConfiguration.size()); - JsonObject& root = jsonBuffer.parseObject(nodeConfiguration); + DynamicJsonDocument doc(1556); + DeserializationError error = deserializeJson(doc, nodeConfiguration); + if (error) { exit(0); } - JsonObject& data = root["data"]; + JsonObject data = doc["data"]; - const char* nethash = data["nethash"]; - ASSERT_STREQ("578e820911f24e039733b45e4882b73e301f813a0d2c31330dafda84534ffa23", nethash); + const auto nethash = data["nethash"]; + ASSERT_STREQ( + "578e820911f24e039733b45e4882b73e301f813a0d2c31330dafda84534ffa23", + nethash); - const char* token = data["token"]; + const auto token = data["token"]; ASSERT_STREQ("DARK", token); - const char* symbol = data["symbol"]; + const auto symbol = data["symbol"]; ASSERT_STREQ(u8"DѦ", symbol); - const char* explorer = data["explorer"]; + const auto explorer = data["explorer"]; ASSERT_STREQ("https://dexplorer.ark.io", explorer); int version = data["version"]; ASSERT_EQ(30, version); - JsonObject& ports = data["ports"]; + JsonObject ports = data["ports"]; int core_p2p = ports["@arkecosystem/core-p2p"]; ASSERT_EQ(4000, core_p2p); @@ -216,10 +219,11 @@ TEST(api, test_node_status) { // NOLINT const auto nodeStatus = connection.api.node.status(); - DynamicJsonBuffer jsonBuffer(nodeStatus.size()); - JsonObject& root = jsonBuffer.parseObject(nodeStatus); + DynamicJsonDocument doc(156); + DeserializationError error = deserializeJson(doc, nodeStatus); + if (error) { exit(0); } - JsonObject& data = root["data"]; + JsonObject data = doc["data"]; bool synced = data["synced"]; ASSERT_FALSE(synced); @@ -262,10 +266,11 @@ TEST(api, test_node_syncing) { // NOLINT const auto nodeSyncing = connection.api.node.syncing(); - DynamicJsonBuffer jsonBuffer(nodeSyncing.size()); - JsonObject& root = jsonBuffer.parseObject(nodeSyncing); + DynamicJsonDocument doc(212); + DeserializationError error = deserializeJson(doc, nodeSyncing); + if (error) { exit(0); } - JsonObject& data = root["data"]; + JsonObject data = doc["data"]; bool syncing = data["syncing"]; ASSERT_TRUE(syncing); @@ -276,6 +281,6 @@ TEST(api, test_node_syncing) { // NOLINT uint64_t height = data["height"]; ASSERT_TRUE(3034451ull == height); - const char* id = data["id"]; + const auto id = data["id"]; ASSERT_STREQ("5444078994968869529", id); } diff --git a/test/api/peers.cpp b/test/api/peers.cpp index b6a4439b..e9f5f9d5 100644 --- a/test/api/peers.cpp +++ b/test/api/peers.cpp @@ -45,24 +45,25 @@ TEST(api, test_peer) { // NOLINT const auto peer = connection.api.peers.get("167.114.29.49"); - DynamicJsonBuffer jsonBuffer(peer.size()); - JsonObject& root = jsonBuffer.parseObject(peer); + DynamicJsonDocument doc(292); + DeserializationError error = deserializeJson(doc, peer); + if (error) { exit(0); } - JsonObject& data = root["data"]; + JsonObject data = doc["data"]; - const char* ip = data["ip"]; + const auto ip = data["ip"]; ASSERT_STREQ("167.114.29.55", ip); int port = data["port"]; ASSERT_EQ(4002, port); - const char* version = data["version"]; + const auto version = data["version"]; ASSERT_STREQ("1.1.1", version); int status = data["status"]; ASSERT_EQ(200, status); - const char* os = data["os"]; + const auto os = data["os"]; ASSERT_STREQ("linux", os); int latency = data["latency"]; @@ -128,10 +129,11 @@ TEST(api, test_peers) { // NOLINT const auto peers = connection.api.peers.all(5, 1); - DynamicJsonBuffer jsonBuffer(peers.size()); - JsonObject& root = jsonBuffer.parseObject(peers); + DynamicJsonDocument doc(724); + DeserializationError error = deserializeJson(doc, peers); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_NE(0, count); @@ -142,21 +144,21 @@ TEST(api, test_peers) { // NOLINT int totalCount = meta["totalCount"]; ASSERT_NE(0, totalCount); - JsonObject& dataZero = root["data"][0]; + JsonObject dataZero = doc["data"][0]; - const char* ip = dataZero["ip"]; + const auto ip = dataZero["ip"]; ASSERT_STREQ("167.114.29.53", ip); int port = dataZero["port"]; ASSERT_EQ(4002, port); - const char* version = dataZero["version"]; + const auto version = dataZero["version"]; ASSERT_STREQ("1.1.1", version); int status = dataZero["status"]; ASSERT_EQ(200, status); - const char* os = dataZero["os"]; + const auto os = dataZero["os"]; ASSERT_STREQ("linux", os); int latency = dataZero["latency"]; diff --git a/test/api/transactions.cpp b/test/api/transactions.cpp index 8a1dc78b..1ed1a3e4 100644 --- a/test/api/transactions.cpp +++ b/test/api/transactions.cpp @@ -63,18 +63,21 @@ TEST(api, test_transaction) { // NOLINT EXPECT_CALL(connection.api.transactions, get(_)).Times(1).WillOnce(Return(response)); - const auto transaction = - connection.api.transactions.get("5c6ce775447a5acd22050d72e2615392494953bb1fb6287e9ffb3c33eaeb79aa"); + const auto transaction = connection.api.transactions.get( + "5c6ce775447a5acd22050d72e2615392494953bb1fb6287e9ffb3c33eaeb79aa"); - DynamicJsonBuffer jsonBuffer(transaction.size()); - JsonObject& root = jsonBuffer.parseObject(transaction); + DynamicJsonDocument doc(868); + DeserializationError error = deserializeJson(doc, transaction); + if (error) { exit(0); } - JsonObject& data = root["data"]; + JsonObject data = doc["data"]; - const char* id = data["id"]; - ASSERT_STREQ("5c6ce775447a5acd22050d72e2615392494953bb1fb6287e9ffb3c33eaeb79aa", id); + const auto id = data["id"]; + ASSERT_STREQ( + "5c6ce775447a5acd22050d72e2615392494953bb1fb6287e9ffb3c33eaeb79aa", + id); - const char* blockId = data["blockId"]; + const auto blockId = data["blockId"]; ASSERT_STREQ("4271682877946294396", blockId); int type = data["type"]; @@ -86,22 +89,21 @@ TEST(api, test_transaction) { // NOLINT uint64_t fee = data["fee"]; ASSERT_TRUE(fee == 10000000); - const char* sender = data["sender"]; + const auto sender = data["sender"]; ASSERT_STREQ("DDiTHZ4RETZhGxcyAi1VruCXZKxBFqXMeh", sender); - const char* recipient = data["recipient"]; + const auto recipient = data["recipient"]; ASSERT_STREQ("DQnQNoJuNCvpjYhxL7fsnGepHBqrumgsyP", recipient); - const char* signature = data["signature"]; + const auto signature = data["signature"]; ASSERT_STREQ( - "3044022047c39f6f45a46a87f91ca867f9551dbebf0035adcfcbdc1370222c7a1517fc0002206fb5ecc10460e0352a8b626a508e2fcc76e3" - "9e490b0a2581dd772ebc8079696e", + "3044022047c39f6f45a46a87f91ca867f9551dbebf0035adcfcbdc1370222c7a1517fc0002206fb5ecc10460e0352a8b626a508e2fcc76e39e490b0a2581dd772ebc8079696e", signature); int confirmations = data["confirmations"]; ASSERT_EQ(confirmations, 1928); - JsonObject& timestamp = data["timestamp"]; + JsonObject timestamp = data["timestamp"]; int epoch = timestamp["epoch"]; ASSERT_EQ(32794053, epoch); @@ -109,7 +111,7 @@ TEST(api, test_transaction) { // NOLINT int timestampUnix = timestamp["unix"]; ASSERT_EQ(1522895253, timestampUnix); - const char* human = timestamp["human"]; + const auto human = timestamp["human"]; ASSERT_STREQ("2018-04-05T02:27:33Z", human); } @@ -154,10 +156,11 @@ TEST(api, test_transaction_types) { // NOLINT const auto types = connection.api.transactions.types(); - DynamicJsonBuffer jsonBuffer(types.size()); - JsonObject& root = jsonBuffer.parseObject(types); + DynamicJsonDocument doc(444); + DeserializationError error = deserializeJson(doc, types); + if (error) { exit(0); } - JsonObject& data = root["data"]; + JsonObject data = doc["data"]; int Transfer = data["Transfer"]; ASSERT_EQ(0, Transfer); @@ -240,15 +243,16 @@ TEST(api, test_transaction_unconfirmed) { // NOLINT const auto transactionUnconfirmed = connection.api.transactions.getUnconfirmed("dummy"); - DynamicJsonBuffer jsonBuffer(transactionUnconfirmed.size()); - JsonObject& root = jsonBuffer.parseObject(transactionUnconfirmed); + DynamicJsonDocument doc(652); + DeserializationError error = deserializeJson(doc, transactionUnconfirmed); + if (error) { exit(0); } - JsonObject& data = root["data"]; + JsonObject data = doc["data"]; - const char* id = data["id"]; + const auto id = data["id"]; ASSERT_STREQ("dummy", id); - const char* blockId = data["blockId"]; + const auto blockId = data["blockId"]; ASSERT_STREQ("dummy", blockId); int type = data["type"]; @@ -260,22 +264,22 @@ TEST(api, test_transaction_unconfirmed) { // NOLINT uint64_t fee = data["fee"]; ASSERT_TRUE(10000000ull == fee); - const char* sender = data["sender"]; + const auto sender = data["sender"]; ASSERT_STREQ("dummy", sender); - const char* recipient = data["recipient"]; + const auto recipient = data["recipient"]; ASSERT_STREQ("dummy", recipient); - const char* signature = data["signature"]; + const auto signature = data["signature"]; ASSERT_STREQ("dummy", signature); - const char* vendorField = data["vendorField"]; + const auto vendorField = data["vendorField"]; ASSERT_STREQ("dummy", vendorField); int confirmations = data["confirmations"]; ASSERT_EQ(10, confirmations); - JsonObject& timestamp = data["timestamp"]; + JsonObject timestamp = data["timestamp"]; uint64_t epoch = timestamp["epoch"]; ASSERT_TRUE(40505460ull == epoch); @@ -283,7 +287,7 @@ TEST(api, test_transaction_unconfirmed) { // NOLINT uint64_t unix_timestamp = timestamp["unix"]; ASSERT_TRUE(1530606660ull == unix_timestamp); - const char* human = timestamp["human"]; + const auto human = timestamp["human"]; ASSERT_STREQ("2018-07-03T08:31:00Z", human); } @@ -364,10 +368,11 @@ TEST(api, test_transactions) { // NOLINT const auto transactions = connection.api.transactions.all(2, 1); - DynamicJsonBuffer jsonBuffer(transactions.size()); - JsonObject& root = jsonBuffer.parseObject(transactions); + DynamicJsonDocument doc(1348); + DeserializationError error = deserializeJson(doc, transactions); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_NE(0, count); @@ -378,7 +383,7 @@ TEST(api, test_transactions) { // NOLINT int totalCount = meta["totalCount"]; ASSERT_NE(0, totalCount); - JsonObject& dataZero = root["data"][0]; + JsonObject dataZero = doc["data"][0]; int type = dataZero["type"]; ASSERT_EQ(0, type); @@ -449,10 +454,11 @@ TEST(api, test_transactions_unconfirmed) { // NOLINT const auto transactionsUnconfirmed = connection.api.transactions.allUnconfirmed(5, 1); - DynamicJsonBuffer jsonBuffer(transactionsUnconfirmed.size()); - JsonObject& root = jsonBuffer.parseObject(transactionsUnconfirmed); + DynamicJsonDocument doc(1164); + DeserializationError error = deserializeJson(doc, transactionsUnconfirmed); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_TRUE(count >= 0); @@ -538,13 +544,15 @@ TEST(api, test_transactions_search) { // NOLINT EXPECT_CALL(connection.api.transactions, search(_, _, _)).Times(1).WillOnce(Return(response)); - const std::map body = {{"id", "dummy"}}; + const std::map body = { + { "id", "dummy" }}; const auto transactions = connection.api.transactions.search(body, 5, 1); - DynamicJsonBuffer jsonBuffer(transactions.size()); - JsonObject& root = jsonBuffer.parseObject(transactions); + DynamicJsonDocument doc(1148); + DeserializationError error = deserializeJson(doc, transactions); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_TRUE(count >= 0); @@ -555,24 +563,24 @@ TEST(api, test_transactions_search) { // NOLINT int totalCount = meta["totalCount"]; ASSERT_TRUE(totalCount >= 0); - JsonObject& data = root["data"][0]; + JsonObject data = doc["data"][0]; - const char* id = data["id"]; + const auto id = data["id"]; ASSERT_STREQ("dummy", id); - const char* blockId = data["blockId"]; + const auto blockId = data["blockId"]; ASSERT_STREQ("dummy", blockId); int type = data["type"]; ASSERT_EQ(0, type); - const char* sender = data["sender"]; + const auto sender = data["sender"]; ASSERT_STREQ("dummy", sender); - const char* recipient = data["recipient"]; + const auto recipient = data["recipient"]; ASSERT_STREQ("dummy", recipient); - const char* signature = data["signature"]; + const auto signature = data["signature"]; ASSERT_STREQ("dummy", signature); } @@ -615,27 +623,28 @@ TEST(api, test_transactions_send) { // NOLINT EXPECT_CALL(connection.api.transactions, send(_)).Times(1).WillOnce(Return(response)); - std::string jsonTransaction = "{\"transactions\":[{\"type\":0,\"amount\":1,\"fee\":10000000,\"id\":\"bc5bb5cd23521c041fca17b5f78d6f3621fc07ab8f6581aff1b6eb86fa4bafe2\",\"recipientId\":\"DNSrsDUq5injGBdNXPV7v7u1Qy9LZfWEdM\",\"senderPublicKey\":\"0216fa03d378b6ad01325e186ad2cbb9d18976d5b27d0ca74b4f92bb6bf9a6d4d9\",\"signature\":\"3044022014204515b82cdd47513377d3e80e6b5f4fd1ab0fb6b4c181e09a7a30428d542502205ba076a332997053e1d31b506777a99f93bcb11294cd678ebe2da313eb02cae2\",\"timestamp\":58351951,\"vendorField\":\"7ad0eeb302ee7d9b4e58cf52daa9ece7922ad92d14f0407e3881597bf3c9c1c6\"}]}"; - - const auto transaction = connection.api.transactions.send(jsonTransaction); + std::string jsonTransaction = "{\"transactions\":[{\"type\":0,\"amount\":1,\"fee\":10000000,\"id\":\"bc5bb5cd23521c041fca17b5f78d6f3621fc07ab8f6581aff1b6eb86fa4bafe2\",\"recipientId\":\"DNSrsDUq5injGBdNXPV7v7u1Qy9LZfWEdM\",\"senderPublicKey\":\"0216fa03d378b6ad01325e186ad2cbb9d18976d5b27d0ca74b4f92bb6bf9a6d4d9\",\"signature\":\"3044022014204515b82cdd47513377d3e80e6b5f4fd1ab0fb6b4c181e09a7a30428d542502205ba076a332997053e1d31b506777a99f93bcb11294cd678ebe2da313eb02cae2\",\"timestamp\":58351951,\"vendorField\":\"7ad0eeb302ee7d9b4e58cf52daa9ece7922ad92d14f0407e3881597bf3c9c1c6\"}]}"; + + const auto transaction = connection.api.transactions.send(jsonTransaction); - DynamicJsonBuffer jsonBuffer(transaction.size()); - JsonObject& root = jsonBuffer.parseObject(transaction); + DynamicJsonDocument doc(324); + DeserializationError error = deserializeJson(doc, transaction); + if (error) { exit(0); } - JsonObject& data = root["data"]; + JsonObject data = doc["data"]; - std::string accept = data["accept"]; - ASSERT_TRUE(accept.length() != 0); + std::string accept = data["accept"]; + ASSERT_NE(accept.length(), 0); - std::string broadcast = data["broadcast"]; - ASSERT_TRUE(broadcast.length() != 0); + std::string broadcast = data["broadcast"]; + ASSERT_NE(broadcast.length(), 0); - std::string excess = data["excess"]; - ASSERT_TRUE(excess.length() == 2); + std::string excess = data["excess"]; + ASSERT_EQ(excess.length(), 2); - std::string invalid = data["invalid"]; - ASSERT_TRUE(invalid.length() == 2); + std::string invalid = data["invalid"]; + ASSERT_EQ(invalid.length(), 2); - std::string errors = data["errors"]; - ASSERT_TRUE(errors.length() == 0 ); + std::string errors = data["errors"]; + ASSERT_EQ(errors.length(), 4); } diff --git a/test/api/votes.cpp b/test/api/votes.cpp index 9e74e79c..d4e97a49 100644 --- a/test/api/votes.cpp +++ b/test/api/votes.cpp @@ -68,17 +68,21 @@ TEST(api, test_vote) { // NOLINT EXPECT_CALL(connection.api.votes, get(_)).Times(1).WillOnce(Return(response)); - const auto vote = connection.api.votes.get("beb8dd43c640f562704090159154b2742afba7eacada9e8edee447e34e7675c6"); + const auto vote = connection.api.votes.get( + "beb8dd43c640f562704090159154b2742afba7eacada9e8edee447e34e7675c6"); - DynamicJsonBuffer jsonBuffer(vote.size()); - JsonObject& root = jsonBuffer.parseObject(vote); + DynamicJsonDocument doc(1044); + DeserializationError error = deserializeJson(doc, vote); + if (error) { exit(0); } - JsonObject& data = root["data"]; + JsonObject data = doc["data"]; - const char* id = data["id"]; - ASSERT_STREQ("beb8dd43c640f562704090159154b2742afba7eacada9e8edee447e34e7675c6", id); + const auto id = data["id"]; + ASSERT_STREQ( + "beb8dd43c640f562704090159154b2742afba7eacada9e8edee447e34e7675c6", + id); - const char* blockId = data["blockId"]; + const auto blockId = data["blockId"]; ASSERT_STREQ("13661015019049808045", blockId); int type = data["type"]; @@ -90,22 +94,21 @@ TEST(api, test_vote) { // NOLINT uint64_t fee = data["fee"]; ASSERT_TRUE(fee == 100000000); - const char* sender = data["sender"]; + const auto sender = data["sender"]; ASSERT_STREQ("DAp7JjULVgqzd4jLofkUyLRovHRPUTQwiZ", sender); - const char* recipient = data["recipient"]; + const auto recipient = data["recipient"]; ASSERT_STREQ("DAp7JjULVgqzd4jLofkUyLRovHRPUTQwiZ", recipient); - const char* signature = data["signature"]; + const auto signature = data["signature"]; ASSERT_STREQ( - "3045022100e9a743c5aa0df427f49af61d35fe617182479f7e8d368ce23b7ec43ab6d269c80220193aafd4ccb3eedbd76ded7ea99f316290" - "13dc3af60540029fe98b274d42d284", + "3045022100e9a743c5aa0df427f49af61d35fe617182479f7e8d368ce23b7ec43ab6d269c80220193aafd4ccb3eedbd76ded7ea99f31629013dc3af60540029fe98b274d42d284", signature); int confirmations = data["confirmations"]; ASSERT_EQ(48189, confirmations); - JsonObject& timestamp = data["timestamp"]; + JsonObject timestamp = data["timestamp"]; int epoch = timestamp["epoch"]; ASSERT_EQ(32338609, epoch); @@ -113,7 +116,7 @@ TEST(api, test_vote) { // NOLINT int timestampUnix = timestamp["unix"]; ASSERT_EQ(1522439809, timestampUnix); - const char* human = timestamp["human"]; + const auto human = timestamp["human"]; ASSERT_STREQ("2018-03-30T19:56:49Z", human); } @@ -202,10 +205,11 @@ TEST(api, test_votes) { // NOLINT const auto votes = connection.api.votes.all(5, 1); - DynamicJsonBuffer jsonBuffer(votes.size()); - JsonObject& root = jsonBuffer.parseObject(votes); + DynamicJsonDocument doc(1492); + DeserializationError error = deserializeJson(doc, votes); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_NE(0, count); @@ -216,7 +220,7 @@ TEST(api, test_votes) { // NOLINT int totalCount = meta["totalCount"]; ASSERT_NE(0, totalCount); - JsonObject& dataZero = root["data"][0]; + JsonObject dataZero = doc["data"][0]; int type = dataZero["type"]; ASSERT_EQ(3, type); diff --git a/test/api/wallets.cpp b/test/api/wallets.cpp index 468c1993..5e8d556b 100644 --- a/test/api/wallets.cpp +++ b/test/api/wallets.cpp @@ -41,16 +41,19 @@ TEST(api, test_wallet) { // NOLINT const auto wallet = connection.api.wallets.get("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN"); - DynamicJsonBuffer jsonBuffer(wallet.size()); - JsonObject& root = jsonBuffer.parseObject(wallet); + DynamicJsonDocument doc(300); + DeserializationError error = deserializeJson(doc, wallet); + if (error) { exit(0); } - JsonObject& data = root["data"]; + JsonObject data = doc["data"]; - const char* address = data["address"]; + const auto address = data["address"]; ASSERT_STREQ("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", address); - const char* publicKey = data["publicKey"]; - ASSERT_STREQ("022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d", publicKey); + const auto publicKey = data["publicKey"]; + ASSERT_STREQ( + "022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d", + publicKey); uint64_t balance = data["balance"]; ASSERT_TRUE(balance == 12534670000000); @@ -115,10 +118,11 @@ TEST(api, test_wallets) { // NOLINT const auto wallets = connection.api.wallets.all(5, 1); - DynamicJsonBuffer jsonBuffer(wallets.size()); - JsonObject& root = jsonBuffer.parseObject(wallets); + DynamicJsonDocument doc(764); + DeserializationError error = deserializeJson(doc, wallets); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_NE(0, count); @@ -129,13 +133,15 @@ TEST(api, test_wallets) { // NOLINT int totalCount = meta["totalCount"]; ASSERT_NE(0, totalCount); - JsonObject& dataZero = root["data"][0]; + JsonObject dataZero = doc["data"][0]; - const char* address = dataZero["address"]; + const auto address = dataZero["address"]; ASSERT_STREQ("D59NTfV92ca9QevUydvMiFMFdubbCaAVCV", address); - const char* publicKey = dataZero["publicKey"]; - ASSERT_STREQ("037d035f08b3bad0d5bb605232c7aa41555693c480044dbeb797270a44c339da5a", publicKey); + const auto publicKey = dataZero["publicKey"]; + ASSERT_STREQ( + "037d035f08b3bad0d5bb605232c7aa41555693c480044dbeb797270a44c339da5a", + publicKey); uint64_t balance = dataZero["balance"]; ASSERT_TRUE(balance >= 0); @@ -211,19 +217,19 @@ TEST(api, test_wallets_search) { // NOLINT ] })"; - const std::map body_parameters = { - {"username", "baldninja"}, - {"address", "DFJ5Z51F1euNNdRUQJKQVdG4h495LZkc6T"}, - {"publicKey", "03d3c6889608074b44155ad2e6577c3368e27e6e129c457418eb3e5ed029544e8d"}}; - EXPECT_CALL(connection.api.wallets, search(_, _, _)).Times(1).WillOnce(Return(response)); + const std::map body_parameters = { + { "username", "baldninja" }, + { "address", "DFJ5Z51F1euNNdRUQJKQVdG4h495LZkc6T" }, + { "publicKey", "03d3c6889608074b44155ad2e6577c3368e27e6e129c457418eb3e5ed029544e8d" }}; const auto walletsSearch = connection.api.wallets.search(body_parameters, 5, 1); - DynamicJsonBuffer jsonBuffer(walletsSearch.size()); - JsonObject& root = jsonBuffer.parseObject(walletsSearch); + DynamicJsonDocument doc(1524); + DeserializationError error = deserializeJson(doc, walletsSearch); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_NE(0, count); @@ -234,13 +240,14 @@ TEST(api, test_wallets_search) { // NOLINT int totalCount = meta["totalCount"]; ASSERT_NE(0, totalCount); - JsonObject& dataZero = root["data"][0]; - ; + JsonObject dataZero = doc["data"][0]; - const char* id = dataZero["id"]; - ASSERT_STREQ("08c6b23f9edd97b613f17153fb97a316a4fb83136e9842655dafc8262f363e0e", id); + const auto id = dataZero["id"]; + ASSERT_STREQ( + "08c6b23f9edd97b613f17153fb97a316a4fb83136e9842655dafc8262f363e0e", + id); - const char* blockId = dataZero["blockId"]; + const auto blockId = dataZero["blockId"]; ASSERT_STREQ("14847399772737279404", blockId); int type = dataZero["type"]; @@ -252,22 +259,21 @@ TEST(api, test_wallets_search) { // NOLINT uint64_t fee = dataZero["fee"]; ASSERT_TRUE(100000000ull == fee); - const char* sender = dataZero["sender"]; + const auto sender = dataZero["sender"]; ASSERT_STREQ("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", sender); - const char* recipient = dataZero["recipient"]; + const auto recipient = dataZero["recipient"]; ASSERT_STREQ("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", recipient); - const char* signature = dataZero["signature"]; + const auto signature = dataZero["signature"]; ASSERT_STREQ( - "304402207ba0e8aaee93695360081b7ce713f13d62b544038ac440bd46357398af86cae6022059ac74586738be1ef622e0baba992d0e417d" - "9aed7ab980f374eb0c9d53e25f8e", + "304402207ba0e8aaee93695360081b7ce713f13d62b544038ac440bd46357398af86cae6022059ac74586738be1ef622e0baba992d0e417d9aed7ab980f374eb0c9d53e25f8e", signature); int confirmations = dataZero["confirmations"]; ASSERT_EQ(1636029, confirmations); - JsonObject& timestamp = dataZero["timestamp"]; + JsonObject timestamp = dataZero["timestamp"]; int epoch = timestamp["epoch"]; ASSERT_EQ(17094358, epoch); @@ -275,7 +281,7 @@ TEST(api, test_wallets_search) { // NOLINT int timestampUnix = timestamp["unix"]; ASSERT_EQ(1507195558, timestampUnix); - const char* human = timestamp["human"]; + const auto human = timestamp["human"]; ASSERT_STREQ("2017-10-05T09:25:58Z", human); } @@ -311,40 +317,45 @@ TEST(api, test_wallets_top) { // NOLINT ASSERT_EQ(2, apiVersion); const std::string response = R"({ - "meta": { - "count": 2, - "pageCount": 1, - "totalCount": 2, - "next": "/api/v2/wallets/top?limit=5&page=1", - "previous": null, - "self": "/api/v2/wallets/top?limit=5&page=1", - "first": "/api/v2/wallets/top?limit=5&page=1", - "last": "/api/v2/wallets/top?limit=5&page=1" - }, - "data": [ - { - "address": "DGihocTkwDygiFvmg6aG8jThYTic47GzU9", - "publicKey": "024c8247388a02ecd1de2a3e3fd5b7c61ecc2797fa3776599d558333ef1802d231", - "balance": 11499593462120632, - "isDelegate": false - }, - { - "address": "DRac35wghMcmUSe5jDMLBDLWkVVjyKZFxK", - "publicKey": "0374e9a97611540a9ce4812b0980e62d3c5141ea964c2cab051f14a78284570dcd", - "balance": 554107676293547, - "isDelegate": false - }, - ] - })"; + "meta": { + "count": 2, + "pageCount": 1, + "totalCount": 2, + "next": "\/api\/v2\/wallets\/top?limit=5&page=1", + "previous": null, + "self": "\/api\/v2\/wallets\/top?limit=5&page=1", + "first": "\/api\/v2\/wallets\/top?limit=5&page=1", + "last": "\/api\/v2\/wallets\/top?limit=5&page=1" + }, + "data": [ + { + "address": "DGihocTkwDygiFvmg6aG8jThYTic47GzU9", + "publicKey": "024c8247388a02ecd1de2a3e3fd5b7c61ecc2797fa3776599d558333ef1802d231", + "balance": 1.1499593462121e+16, + "isDelegate": false + }, + { + "address": "DRac35wghMcmUSe5jDMLBDLWkVVjyKZFxK", + "publicKey": "0374e9a97611540a9ce4812b0980e62d3c5141ea964c2cab051f14a78284570dcd", + "balance": 5.5410767629355e+14, + "isDelegate": false + } + ] + })"; - EXPECT_CALL(connection.api.wallets, top(_, _)).Times(1).WillOnce(Return(response)); + EXPECT_CALL( + connection.api.wallets, + top(_, _)) + .Times(1) + .WillOnce(Return(response)); - const auto walletsTop = connection.api.wallets.top(5, 1); + const auto walletsTop = connection.api.wallets.top(2, 1); - DynamicJsonBuffer jsonBuffer(walletsTop.size()); - JsonObject& root = jsonBuffer.parseObject(walletsTop); + DynamicJsonDocument doc(1124); + DeserializationError error = deserializeJson(doc, walletsTop); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_NE(0, count); @@ -355,33 +366,44 @@ TEST(api, test_wallets_top) { // NOLINT int totalCount = meta["totalCount"]; ASSERT_NE(0, totalCount); - JsonObject& dataZero = root["data"][0]; + JsonObject dataZero = doc["data"][0]; - const char* address = dataZero["address"]; + const auto address = dataZero["address"]; ASSERT_STREQ("DGihocTkwDygiFvmg6aG8jThYTic47GzU9", address); - const char* publicKey = dataZero["publicKey"]; - ASSERT_STREQ("024c8247388a02ecd1de2a3e3fd5b7c61ecc2797fa3776599d558333ef1802d231", publicKey); - - uint64_t balance = dataZero["balance"]; - ASSERT_TRUE(balance == 11499593462120632ull); - + const auto publicKey = dataZero["publicKey"]; + ASSERT_STREQ( + "024c8247388a02ecd1de2a3e3fd5b7c61ecc2797fa3776599d558333ef1802d231", + publicKey); + + unsigned long long balance = dataZero["balance"].as(); +#if defined(ESP8266) || defined(ESP32) + ASSERT_EQ(balance, 11499590251446272ull); +#else + ASSERT_EQ(balance, 11499593462121000ull); +#endif bool isDelegate = dataZero["isDelegate"]; ASSERT_FALSE(isDelegate); - JsonObject& dataOne = root["data"][1]; - - address = dataOne["address"]; - ASSERT_STREQ("DRac35wghMcmUSe5jDMLBDLWkVVjyKZFxK", address); + JsonObject dataOne = doc["data"][1]; - publicKey = dataOne["publicKey"]; - ASSERT_STREQ("0374e9a97611540a9ce4812b0980e62d3c5141ea964c2cab051f14a78284570dcd", publicKey); + const auto addressOne = dataOne["address"]; + ASSERT_STREQ("DRac35wghMcmUSe5jDMLBDLWkVVjyKZFxK", addressOne); - balance = dataOne["balance"]; - ASSERT_TRUE(balance == 554107676293547ull); - - isDelegate = dataOne["isDelegate"]; - ASSERT_FALSE(isDelegate); + const auto publicKeyOne = dataOne["publicKey"]; + ASSERT_STREQ( + "0374e9a97611540a9ce4812b0980e62d3c5141ea964c2cab051f14a78284570dcd", + publicKeyOne); + + unsigned long long balanceOne = dataOne["balance"].as(); +#if defined(ESP8266) || defined(ESP32) + ASSERT_EQ(balanceOne, 554107588837376ull); +#else + ASSERT_EQ(balanceOne, 554107676293550ull); +#endif + + const auto isDelegateOne = dataOne["isDelegate"]; + ASSERT_FALSE(isDelegateOne); } /* test_wallets_transactions @@ -457,12 +479,15 @@ TEST(api, test_wallets_transactions) { // NOLINT EXPECT_CALL(connection.api.wallets, transactions(_, _, _)).Times(1).WillOnce(Return(response)); - const auto walletsTransactions = connection.api.wallets.transactions("DDiTHZ4RETZhGxcyAi1VruCXZKxBFqXMeh", 2, 1); + const auto walletsTransactions = connection.api.wallets.transactions( + "DDiTHZ4RETZhGxcyAi1VruCXZKxBFqXMeh", + 2, 1); - DynamicJsonBuffer jsonBuffer(walletsTransactions.size()); - JsonObject& root = jsonBuffer.parseObject(walletsTransactions); + DynamicJsonDocument doc(1420); + DeserializationError error = deserializeJson(doc, walletsTransactions); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_EQ(2, count); @@ -527,13 +552,15 @@ TEST(api, test_wallets_transactions_received) { // NOLINT EXPECT_CALL(connection.api.wallets, transactionsReceived(_, _, _)).Times(1).WillOnce(Return(response)); - const auto walletsTransactionsReceived = - connection.api.wallets.transactionsReceived("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", 2, 1); + const auto walletsTransactionsReceived = connection.api.wallets.transactionsReceived( + "DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", + 2, 1); - DynamicJsonBuffer jsonBuffer(walletsTransactionsReceived.size()); - JsonObject& root = jsonBuffer.parseObject(walletsTransactionsReceived); + DynamicJsonDocument doc(1532); + DeserializationError error = deserializeJson(doc, walletsTransactionsReceived); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_NE(0, count); @@ -608,13 +635,15 @@ TEST(api, test_wallets_transactions_sent) { // NOLINT EXPECT_CALL(connection.api.wallets, transactionsSent(_, _, _)).Times(1).WillOnce(Return(response)); - const auto walletsTransactionsSent = - connection.api.wallets.transactionsSent("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", 2, 1); + const auto walletsTransactionsSent = connection.api.wallets.transactionsSent( + "DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", + 2, 1); - DynamicJsonBuffer jsonBuffer(walletsTransactionsSent.size()); - JsonObject& root = jsonBuffer.parseObject(walletsTransactionsSent); + DynamicJsonDocument doc(1612); + DeserializationError error = deserializeJson(doc, walletsTransactionsSent); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_NE(0, count); @@ -624,6 +653,27 @@ TEST(api, test_wallets_transactions_sent) { // NOLINT int totalCount = meta["totalCount"]; ASSERT_NE(0, totalCount); + + JsonObject dataZero = doc["data"][0]; + + const auto id = dataZero["id"]; + ASSERT_STREQ( + "08c6b23f9edd97b613f17153fb97a316a4fb83136e9842655dafc8262f363e0e", + id); + + const auto blockId = dataZero["blockId"]; + ASSERT_STREQ("14847399772737279404", blockId); + + const auto sender = dataZero["sender"]; + ASSERT_STREQ("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", sender); + + const auto recipient = dataZero["recipient"]; + ASSERT_STREQ("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", recipient); + + const auto signature = dataZero["signature"]; + ASSERT_STREQ( + "304402207ba0e8aaee93695360081b7ce713f13d62b544038ac440bd46357398af86cae6022059ac74586738be1ef622e0baba992d0e417d9aed7ab980f374eb0c9d53e25f8e", + signature); } /* test_wallets_votes @@ -711,16 +761,33 @@ TEST(api, test_wallets_votes) { // NOLINT const auto walletsVotes = connection.api.wallets.votes("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", 1, 1); - DynamicJsonBuffer jsonBuffer(walletsVotes.size()); - JsonObject& root = jsonBuffer.parseObject(walletsVotes); + DynamicJsonDocument doc(1612); + DeserializationError error = deserializeJson(doc, walletsVotes); + if (error) { exit(0); } - JsonObject& meta = root["meta"]; + JsonObject meta = doc["meta"]; int count = meta["count"]; ASSERT_GT(count, 0); - JsonObject& data = root["data"][0]; + JsonObject dataZero = doc["data"][0]; - const char* sender = data["sender"]; + const auto id = dataZero["id"]; + ASSERT_STREQ( + "08c6b23f9edd97b613f17153fb97a316a4fb83136e9842655dafc8262f363e0e", + id); + + const auto blockId = dataZero["blockId"]; + ASSERT_STREQ("14847399772737279404", blockId); + + const auto sender = dataZero["sender"]; ASSERT_STREQ("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", sender); + + const auto recipient = dataZero["recipient"]; + ASSERT_STREQ("DARiJqhogp2Lu6bxufUFQQMuMyZbxjCydN", recipient); + + const auto signature = dataZero["signature"]; + ASSERT_STREQ( + "304402207ba0e8aaee93695360081b7ce713f13d62b544038ac440bd46357398af86cae6022059ac74586738be1ef622e0baba992d0e417d9aed7ab980f374eb0c9d53e25f8e", + signature); } diff --git a/test/http/http.cpp b/test/http/http.cpp index 24365ec1..1566d514 100644 --- a/test/http/http.cpp +++ b/test/http/http.cpp @@ -12,12 +12,13 @@ TEST(api, test_http_get) { // NOLINT const auto response = http->get("167.114.29.55:4003/api/node/status"); // Create a JSON object of the result - DynamicJsonBuffer jsonBuffer(response.length()); - JsonObject& obj = jsonBuffer.parseObject(response.c_str()); + DynamicJsonDocument doc(156); + DeserializationError error = deserializeJson(doc, response); + if (error) { exit(0); } - // Test JSON object for the "data" key. - // The correct response will include this key. - ASSERT_TRUE(obj.containsKey("data")); + // Test JSON object for the "data" key. + // The correct response will include this key. + ASSERT_TRUE(doc.containsKey("data")); } // Tests POSTing of HTTP body. @@ -32,13 +33,14 @@ TEST(api, test_http_post_body) { // NOLINT // Post the 'request' and 'body' for a response using HTTP const auto response = http->post(request, body); - // Create a JSON object of the result - DynamicJsonBuffer jsonBuffer(response.length()); - JsonObject& obj = jsonBuffer.parseObject(response.c_str()); + // Create a JSON object of the result + DynamicJsonDocument doc(956); + DeserializationError error = deserializeJson(doc, response); + if (error) { exit(0); } - // Test JSON object for the "meta" key. - // The correct response will include this key - ASSERT_TRUE(obj.containsKey("meta")); + // Test JSON object for the "meta" key. + // The correct response will include this key + ASSERT_TRUE(doc.containsKey("meta")); } // Tests POSTing of JSON. @@ -53,13 +55,14 @@ TEST(api, test_http_post_json) { // NOLINT // Post the 'request' and 'txJson' for a response using HTTP const auto response = http->post(request, txJson); - // Create a JSON object of the result - DynamicJsonBuffer jsonBuffer(response.length()); - JsonObject& obj = jsonBuffer.parseObject(response.c_str()); + // Create a JSON object of the result + DynamicJsonDocument doc(180); + DeserializationError error = deserializeJson(doc, response); + if (error) { exit(0); } - // Test JSON object for the "message" key. - // The correct response will include the following - ASSERT_EQ(422, obj["statusCode"]); + // Test JSON object for the "message" key. + // The correct response will include the following + ASSERT_EQ(422, doc["statusCode"]); } // This tests the use of "http://" in single-line HTTP requests. @@ -74,22 +77,23 @@ TEST(api, test_http_request_strings) { // NOLINT // Create the HTTP object const auto http = Ark::Client::makeHTTP(); - for (int i = 0; i < 3; ++i) { - // Get the response using HTTP - const auto response = http->get(requests[i]); - - // Create a JSON object of the result - DynamicJsonBuffer jsonBuffer(response.length()); - JsonObject& obj = jsonBuffer.parseObject(response.c_str()); - - // Test JSON object for the "data" key. - // HTTPS is NOT supported and should fail to parse. - if (std::string(requests[i]).find("https://") == 0) { - ASSERT_FALSE(obj.containsKey("data")); - } else { - ASSERT_TRUE(obj.containsKey("data")); - }; - } + for (int i = 0; i < 3; ++i) { + // Get the response using HTTP + const auto response = http->get(requests[i]); + + // Create a JSON object of the result + DynamicJsonDocument doc(156); + DeserializationError error = deserializeJson(doc, response); + + // Test JSON object for the "data" key. + // HTTPS is NOT supported and should fail to parse. + if (std::string(requests[i]).find("https://") != 0) { + if (error) { exit(0); } + ASSERT_TRUE(doc.containsKey("data")); + } else { + ASSERT_FALSE(doc.containsKey("data")); + }; + }; } TEST(api, test_http_version) { // NOLINT diff --git a/test/iot/test_main.cpp b/test/iot/test_main.cpp index 56f0fac0..ac56af1f 100644 --- a/test/iot/test_main.cpp +++ b/test/iot/test_main.cpp @@ -5,14 +5,39 @@ #include +// Connecting to WiFi is optional for testing. +#ifdef ESP8266 +#include +#endif +#ifdef ESP32 +#include +#endif +// This is the WiFi network you'd like your board to connect to. +const char* ssid = "yourSSID"; +const char* password = "yourWiFiPassword"; + +/**/ + void setup() { - Serial.begin(115200); - while (!Serial); // for the Arduino Leonardo/Micro only - delay(100); + Serial.begin(115200); + +#if defined(ESP8266) || defined(ESP32) + // if ssid and passwd set + if (strcmp(ssid, "yourSSID") != 0 && strcmp(password, "yourWiFiPassword") != 0) { + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + }; + Serial.println(); + Serial.println(WiFi.localIP()); + }; +#endif + testing::InitGoogleMock(); - delay(1000); - RUN_ALL_TESTS(); + auto __attribute__((unused)) run = RUN_ALL_TESTS(); } void loop() { diff --git a/test/lib/ArduinoJson b/test/lib/ArduinoJson index 0d4a9301..2af003e4 160000 --- a/test/lib/ArduinoJson +++ b/test/lib/ArduinoJson @@ -1 +1 @@ -Subproject commit 0d4a93018b061ce20238a9d81c17913cb0e7bfe4 +Subproject commit 2af003e4e23daae15b4156ea58a2ddba905b04e0 diff --git a/test/platformio.ini b/test/platformio.ini index 5dcfb969..0434a752 100644 --- a/test/platformio.ini +++ b/test/platformio.ini @@ -15,7 +15,7 @@ lib_dir = .. [common] lib_ldf_mode = deep -lib_deps = ArduinoJson, googletest +lib_deps = ArduinoJson@6.10.1, googletest # ignore the 'test' lib. This isn't real but the build system somehow thinks that the test directory is also a library and does some double compiling of files lib_ignore = test build_flags = -I../src -I../src/include/cpp-client -I./test -I. -I.. -DUNIT_TEST From 264ba38766ab8e162e7b3b7a65f61dd55c74765b Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 9 May 2019 18:06:51 -0700 Subject: [PATCH 5/6] fix: trailing empty line --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index e60a392b..27f9fddc 100644 --- a/library.json +++ b/library.json @@ -39,4 +39,4 @@ "-I src/include/cpp-client" ] } -} \ No newline at end of file +} From 4255ff0dbc871f20ad953671bff02d84c9391c47 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 9 May 2019 18:28:31 -0700 Subject: [PATCH 6/6] fix: ull testing for multiple-platforms - update wallet::top test case. - remove 'loop()' 'delay(x)'. --- test/api/wallets.cpp | 81 ++++++++++++++++++++---------------------- test/iot/test_main.cpp | 1 - 2 files changed, 38 insertions(+), 44 deletions(-) diff --git a/test/api/wallets.cpp b/test/api/wallets.cpp index 5e8d556b..c7e66376 100644 --- a/test/api/wallets.cpp +++ b/test/api/wallets.cpp @@ -317,31 +317,33 @@ TEST(api, test_wallets_top) { // NOLINT ASSERT_EQ(2, apiVersion); const std::string response = R"({ - "meta": { - "count": 2, - "pageCount": 1, - "totalCount": 2, - "next": "\/api\/v2\/wallets\/top?limit=5&page=1", - "previous": null, - "self": "\/api\/v2\/wallets\/top?limit=5&page=1", - "first": "\/api\/v2\/wallets\/top?limit=5&page=1", - "last": "\/api\/v2\/wallets\/top?limit=5&page=1" + "meta": { + "count": 2, + "pageCount": 97849, + "totalCount": 195698, + "next": "\/api\/v2\/wallets\/top?limit=2&page=2", + "previous": null, + "self": "\/api\/v2\/wallets\/top?limit=2&page=1", + "first": "\/api\/v2\/wallets\/top?limit=2&page=1", + "last": "\/api\/v2\/wallets\/top?limit=2&page=97849" + }, + "data": [ + { + "address": "D6Z26L69gdk9qYmTv5uzk3uGepigtHY4ax", + "publicKey": "03d3fdad9c5b25bf8880e6b519eb3611a5c0b31adebc8455f0e096175b28321aff", + "balance": 10105417471949050, + "isDelegate": false }, - "data": [ - { - "address": "DGihocTkwDygiFvmg6aG8jThYTic47GzU9", - "publicKey": "024c8247388a02ecd1de2a3e3fd5b7c61ecc2797fa3776599d558333ef1802d231", - "balance": 1.1499593462121e+16, - "isDelegate": false - }, - { - "address": "DRac35wghMcmUSe5jDMLBDLWkVVjyKZFxK", - "publicKey": "0374e9a97611540a9ce4812b0980e62d3c5141ea964c2cab051f14a78284570dcd", - "balance": 5.5410767629355e+14, - "isDelegate": false - } - ] - })"; + { + "address": "DEyaFhDuaoQyKbFH4gJtYZvKkB6umyrEUj", + "publicKey": "033c59dcdc36944cc28f68c1e4b47ac370fe326e53f9adf5f07764d3e8b74b1838", + "username": "whalessio", + "secondPublicKey": "03820f214bd49a09c636fa366b4b3c1a0dbd2953d14aac7e68a596e0636e662dfb", + "balance": 2000035929999638, + "isDelegate": true + } + ] +})"; EXPECT_CALL( connection.api.wallets, @@ -351,7 +353,7 @@ TEST(api, test_wallets_top) { // NOLINT const auto walletsTop = connection.api.wallets.top(2, 1); - DynamicJsonDocument doc(1124); + DynamicJsonDocument doc(1292); DeserializationError error = deserializeJson(doc, walletsTop); if (error) { exit(0); } @@ -369,41 +371,34 @@ TEST(api, test_wallets_top) { // NOLINT JsonObject dataZero = doc["data"][0]; const auto address = dataZero["address"]; - ASSERT_STREQ("DGihocTkwDygiFvmg6aG8jThYTic47GzU9", address); + ASSERT_STREQ("D6Z26L69gdk9qYmTv5uzk3uGepigtHY4ax", address); const auto publicKey = dataZero["publicKey"]; ASSERT_STREQ( - "024c8247388a02ecd1de2a3e3fd5b7c61ecc2797fa3776599d558333ef1802d231", + "03d3fdad9c5b25bf8880e6b519eb3611a5c0b31adebc8455f0e096175b28321aff", publicKey); - unsigned long long balance = dataZero["balance"].as(); -#if defined(ESP8266) || defined(ESP32) - ASSERT_EQ(balance, 11499590251446272ull); -#else - ASSERT_EQ(balance, 11499593462121000ull); -#endif + unsigned long long balance = dataZero["balance"]; + ASSERT_EQ(balance, 10105417471949050ull); + bool isDelegate = dataZero["isDelegate"]; ASSERT_FALSE(isDelegate); JsonObject dataOne = doc["data"][1]; const auto addressOne = dataOne["address"]; - ASSERT_STREQ("DRac35wghMcmUSe5jDMLBDLWkVVjyKZFxK", addressOne); + ASSERT_STREQ("DEyaFhDuaoQyKbFH4gJtYZvKkB6umyrEUj", addressOne); const auto publicKeyOne = dataOne["publicKey"]; ASSERT_STREQ( - "0374e9a97611540a9ce4812b0980e62d3c5141ea964c2cab051f14a78284570dcd", + "033c59dcdc36944cc28f68c1e4b47ac370fe326e53f9adf5f07764d3e8b74b1838", publicKeyOne); - unsigned long long balanceOne = dataOne["balance"].as(); -#if defined(ESP8266) || defined(ESP32) - ASSERT_EQ(balanceOne, 554107588837376ull); -#else - ASSERT_EQ(balanceOne, 554107676293550ull); -#endif + unsigned long long balanceOne = dataOne["balance"]; + ASSERT_EQ(balanceOne, 2000035929999638ull); - const auto isDelegateOne = dataOne["isDelegate"]; - ASSERT_FALSE(isDelegateOne); + const bool isDelegateOne = dataOne["isDelegate"]; + ASSERT_TRUE(isDelegateOne); } /* test_wallets_transactions diff --git a/test/iot/test_main.cpp b/test/iot/test_main.cpp index ac56af1f..a0933a71 100644 --- a/test/iot/test_main.cpp +++ b/test/iot/test_main.cpp @@ -42,7 +42,6 @@ void setup() { void loop() { // do nothing - delay(1000); } #endif