Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(chore): update ArduinoJson version #87

Merged
merged 13 commits into from May 10, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .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
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/INSTALL_ARDUINO.md
Expand Up @@ -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

#
Expand Down
4 changes: 2 additions & 2 deletions docs/INSTALL_PLATFORMIO.md
Expand Up @@ -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```

#

Expand Down
6 changes: 3 additions & 3 deletions docs/cpp.md
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
118 changes: 64 additions & 54 deletions test/api/blocks.cpp
Expand Up @@ -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"];
Expand All @@ -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);
Expand All @@ -106,43 +107,46 @@ 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);

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);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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"];
Expand All @@ -253,27 +260,26 @@ 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);

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);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -478,17 +485,19 @@ TEST(api, test_blocks_search) { // NOLINT
]
})";

const std::map<std::string, std::string> body = {
{"id", "8337447655053578871"}, {"previousBlock", "6440284271011893973"}, {"version", "0"}};

EXPECT_CALL(connection.api.blocks, search(_, _, _)).Times(1).WillOnce(Return(expected_response));

const std::map<std::string, std::string> 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);
Expand All @@ -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"];
Expand All @@ -516,32 +527,31 @@ 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);

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);
}