Skip to content

Commit ecda959

Browse files
sleepdefic1tfaustbrian
authored andcommitted
test(chore): update ArduinoJson version (#87)
1 parent 735f820 commit ecda959

16 files changed

+488
-351
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
[submodule "test/lib/ArduinoJson"]
2-
path = test/lib/ArduinoJson
3-
url = https://github.com/bblanchon/ArduinoJson
41
[submodule "test/lib/googletest"]
52
path = test/lib/googletest
63
url = https://github.com/google/googletest.git
74

5+
[submodule "test/lib/ArduinoJson"]
6+
path = test/lib/ArduinoJson
7+
url = https://github.com/bblanchon/ArduinoJson

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## Unreleased
99

10+
- update ArduinoJson 5.13.2 >> 6.10.1, usage patterns, and documentation/examples.
1011
- use "statusCode" '422' to test API Post response for empty Transactions objects.
1112

1213
## [1.2.0] - 2019-02-16

docs/INSTALL_ARDUINO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Download and install the Arduino IDE (>=1.8.5) from the following link:
1515

1616
Using the Arduino IDE's built in Library Manager,
1717
install the following Libraries
18-
- ArduinoJson v5.13.2
18+
- ArduinoJson v6.10.1
1919
- AUnit
2020

2121
#

docs/INSTALL_PLATFORMIO.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ or
1818

1919

2020
also install platformio dependencies:
21-
> install ArduinoJson@5.13.2 AUnit (2778)
22-
```platformio lib -g install 64@5.13.2 2778```
21+
> install ArduinoJson@6.10.1 AUnit (2778)
22+
```platformio lib -g install 64@6.10.1 2778```
2323

2424
#
2525

docs/cpp.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Download and install the Arduino IDE (>=1.8.5) from the following link:
106106
107107
Using the Arduino IDE's built in Library Manager,
108108
install the following Libraries:
109-
```ArduinoJson v5.13.2```
109+
```ArduinoJson v6.10.1```
110110
```AUnit```
111111
112112
#### Arduino Example using the Adafruit Feather ESP8266
@@ -161,9 +161,9 @@ or
161161

162162
python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/develop/scripts/get-platformio.py)"
163163

164-
Install ArduinoJson@5.13.2 AUnit (2778)
164+
Install ArduinoJson@6.10.1 AUnit (2778)
165165

166-
platformio lib -g install 64@5.13.2 2778
166+
platformio lib -g install 64@6.10.1 2778
167167

168168
#### Provide your WiFi info for your board to access the internet
169169

test/api/blocks.cpp

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ TEST(api, test_block) { // NOLINT
8181

8282
const auto blockResponse = connection.api.blocks.get("58328125061111756");
8383

84-
DynamicJsonBuffer jsonBuffer(blockResponse.size());
85-
JsonObject& root = jsonBuffer.parseObject(blockResponse);
84+
DynamicJsonDocument doc(1244);
85+
DeserializationError error = deserializeJson(doc, blockResponse);
86+
if (error) { exit(0); }
8687

87-
JsonObject& data = root["data"];
88+
JsonObject data = doc["data"];
8889

89-
const char* id = data["id"];
90+
const auto id = data["id"];
9091
ASSERT_STREQ("58328125061111756", id);
9192

9293
int version = data["version"];
@@ -95,7 +96,7 @@ TEST(api, test_block) { // NOLINT
9596
int height = data["height"];
9697
ASSERT_EQ(3035362, height);
9798

98-
JsonObject& forged = data["forged"];
99+
JsonObject forged = data["forged"];
99100

100101
uint64_t reward = forged["reward"];
101102
ASSERT_TRUE(reward == 200000000);
@@ -106,43 +107,46 @@ TEST(api, test_block) { // NOLINT
106107
uint64_t total = forged["total"];
107108
ASSERT_TRUE(total == 200000000);
108109

109-
JsonObject& payload = data["payload"];
110+
JsonObject payload = data["payload"];
110111

111-
const char* hash = payload["hash"];
112-
ASSERT_STREQ("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", hash);
112+
const auto hash = payload["hash"];
113+
ASSERT_STREQ(
114+
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
115+
hash);
113116

114117
int length = payload["length"];
115118
ASSERT_EQ(0, length);
116119

117-
JsonObject& generator = data["generator"];
120+
JsonObject generator = data["generator"];
118121

119-
const char* username = generator["username"];
122+
const auto username = generator["username"];
120123
ASSERT_STREQ("genesis_6", username);
121124

122-
const char* address = generator["address"];
125+
const auto address = generator["address"];
123126
ASSERT_STREQ("D5e2FzTPqdEHridjzpFZCCVyepAu6Vpmk4", address);
124127

125-
const char* publicKey = generator["publicKey"];
126-
ASSERT_STREQ("023e577a7b3362e0aba70e6911d230e86d729b4cb640f0e0b25637b812a3e38b53", publicKey);
128+
const auto publicKey = generator["publicKey"];
129+
ASSERT_STREQ(
130+
"023e577a7b3362e0aba70e6911d230e86d729b4cb640f0e0b25637b812a3e38b53",
131+
publicKey);
127132

128-
const char* signature = data["signature"];
133+
const auto signature = data["signature"];
129134
ASSERT_STREQ(
130-
"3044022047aeb0c9cfbb5709aba4c177009bfdc7804ef597073fb9ca6cb614d7e3d1af2d02207234119d02ca26600ece045c59266945081b"
131-
"4c8237370576aaad7c61a09fe0ad",
135+
"3044022047aeb0c9cfbb5709aba4c177009bfdc7804ef597073fb9ca6cb614d7e3d1af2d02207234119d02ca26600ece045c59266945081b4c8237370576aaad7c61a09fe0ad",
132136
signature);
133137

134138
int transactions = data["transactions"];
135139
ASSERT_EQ(0, transactions);
136140

137-
JsonObject& timestamp = data["timestamp"];
141+
JsonObject timestamp = data["timestamp"];
138142

139143
int epoch = timestamp["epoch"];
140144
ASSERT_EQ(32816544, epoch);
141145

142146
int timestampUnix = timestamp["unix"];
143147
ASSERT_EQ(1522917744, timestampUnix);
144148

145-
const char* human = timestamp["human"];
149+
const auto human = timestamp["human"];
146150
ASSERT_STREQ("2018-04-05T08:42:24Z", human);
147151
}
148152

@@ -221,11 +225,12 @@ TEST(api, test_block_transactions) { // NOLINT
221225
EXPECT_CALL(connection.api.blocks, transactions(_)).Times(1).WillOnce(Return(expected_response));
222226

223227
const auto blockTransactionsResponse = connection.api.blocks.transactions("14126007750611341900");
228+
229+
DynamicJsonDocument doc(1452);
230+
DeserializationError error = deserializeJson(doc, blockTransactionsResponse);
231+
if (error) { exit(0); }
224232

225-
DynamicJsonBuffer jsonBuffer(blockTransactionsResponse.size());
226-
JsonObject& root = jsonBuffer.parseObject(blockTransactionsResponse);
227-
228-
JsonObject& meta = root["meta"];
233+
JsonObject meta = doc["meta"];
229234

230235
int count = meta["count"];
231236
ASSERT_EQ(1, count);
@@ -236,12 +241,14 @@ TEST(api, test_block_transactions) { // NOLINT
236241
int totalCount = meta["totalCount"];
237242
ASSERT_EQ(1, totalCount);
238243

239-
JsonObject& dataZero = root["data"][0];
244+
JsonObject dataZero = doc["data"][0];
240245

241-
const char* id = dataZero["id"];
242-
ASSERT_STREQ("57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369", id);
246+
const auto id = dataZero["id"];
247+
ASSERT_STREQ(
248+
"57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369",
249+
id);
243250

244-
const char* blockId = dataZero["blockId"];
251+
const auto blockId = dataZero["blockId"];
245252
ASSERT_STREQ("14126007750611341900", blockId);
246253

247254
int type = dataZero["type"];
@@ -253,27 +260,26 @@ TEST(api, test_block_transactions) { // NOLINT
253260
uint64_t fee = dataZero["fee"];
254261
ASSERT_TRUE(fee == 10000000);
255262

256-
const char* sender = dataZero["sender"];
263+
const auto sender = dataZero["sender"];
257264
ASSERT_STREQ("DGihocTkwDygiFvmg6aG8jThYTic47GzU9", sender);
258265

259-
const char* signature = dataZero["signature"];
266+
const auto signature = dataZero["signature"];
260267
ASSERT_STREQ(
261-
"3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1"
262-
"c34df8a46afe655b021930b03e214e",
268+
"3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1c34df8a46afe655b021930b03e214e",
263269
signature);
264270

265271
int confirmations = dataZero["confirmations"];
266272
ASSERT_EQ(3034848, confirmations);
267273

268-
JsonObject& timestamp = dataZero["timestamp"];
274+
JsonObject timestamp = dataZero["timestamp"];
269275

270276
int epoch = timestamp["epoch"];
271277
ASSERT_EQ(3909196, epoch);
272278

273279
int timestampUnix = timestamp["unix"];
274280
ASSERT_EQ(1494010396, timestampUnix);
275281

276-
const char* human = timestamp["human"];
282+
const auto human = timestamp["human"];
277283
ASSERT_STREQ("2017-05-05T18:53:16Z", human);
278284
}
279285

@@ -374,10 +380,11 @@ TEST(api, test_blocks) { // NOLINT
374380

375381
const auto blocksResponse = connection.api.blocks.all(5, 1);
376382

377-
DynamicJsonBuffer jsonBuffer(blocksResponse.size());
378-
JsonObject& root = jsonBuffer.parseObject(blocksResponse);
383+
DynamicJsonDocument doc(1740);
384+
DeserializationError error = deserializeJson(doc, blocksResponse);
385+
if (error) { exit(0); }
379386

380-
JsonObject& meta = root["meta"];
387+
JsonObject meta = doc["meta"];
381388

382389
int count = meta["count"];
383390
ASSERT_NE(0, count);
@@ -388,7 +395,7 @@ TEST(api, test_blocks) { // NOLINT
388395
int totalCount = meta["totalCount"];
389396
ASSERT_NE(0, totalCount);
390397

391-
JsonObject& dataZero = root["data"][0];
398+
JsonObject dataZero = doc["data"][0];
392399

393400
int version = dataZero["version"];
394401
ASSERT_EQ(0, version);
@@ -478,17 +485,19 @@ TEST(api, test_blocks_search) { // NOLINT
478485
]
479486
})";
480487

481-
const std::map<std::string, std::string> body = {
482-
{"id", "8337447655053578871"}, {"previousBlock", "6440284271011893973"}, {"version", "0"}};
483-
484488
EXPECT_CALL(connection.api.blocks, search(_, _, _)).Times(1).WillOnce(Return(expected_response));
485489

490+
const std::map<std::string, std::string> body = {
491+
{ "id", "8337447655053578871" },
492+
{ "previousBlock", "6440284271011893973" },
493+
{ "version", "0" }};
486494
const auto walletsSearch = connection.api.blocks.search(body, 5, 1);
487495

488-
DynamicJsonBuffer jsonBuffer(walletsSearch.size());
489-
JsonObject& root = jsonBuffer.parseObject(walletsSearch);
496+
DynamicJsonDocument doc(1476);
497+
DeserializationError error = deserializeJson(doc, walletsSearch);
498+
if (error) { exit(0); }
490499

491-
JsonObject& meta = root["meta"];
500+
JsonObject meta = doc["meta"];
492501

493502
int count = meta["count"];
494503
ASSERT_NE(0, count);
@@ -499,12 +508,14 @@ TEST(api, test_blocks_search) { // NOLINT
499508
int totalCount = meta["totalCount"];
500509
ASSERT_NE(0, totalCount);
501510

502-
JsonObject& dataZero = root["data"][0];
511+
JsonObject dataZero = doc["data"][0];
503512

504-
const char* id = dataZero["id"];
505-
ASSERT_STREQ("57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369", id);
513+
const auto id = dataZero["id"];
514+
ASSERT_STREQ(
515+
"57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369",
516+
id);
506517

507-
const char* blockId = dataZero["blockId"];
518+
const auto blockId = dataZero["blockId"];
508519
ASSERT_STREQ("14126007750611341900", blockId);
509520

510521
int type = dataZero["type"];
@@ -516,32 +527,31 @@ TEST(api, test_blocks_search) { // NOLINT
516527
uint64_t fee = dataZero["fee"];
517528
ASSERT_TRUE(10000000ull == fee);
518529

519-
const char* sender = dataZero["sender"];
530+
const auto sender = dataZero["sender"];
520531
ASSERT_STREQ("DGihocTkwDygiFvmg6aG8jThYTic47GzU9", sender);
521532

522-
const char* recipient = dataZero["recipient"];
533+
const auto recipient = dataZero["recipient"];
523534
ASSERT_STREQ("DRac35wghMcmUSe5jDMLBDLWkVVjyKZFxK", recipient);
524535

525-
const char* signature = dataZero["signature"];
536+
const auto signature = dataZero["signature"];
526537
ASSERT_STREQ(
527-
"3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1"
528-
"c34df8a46afe655b021930b03e214e",
538+
"3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1c34df8a46afe655b021930b03e214e",
529539
signature);
530540

531-
const char* vendorField = dataZero["vendorField"];
541+
const auto vendorField = dataZero["vendorField"];
532542
ASSERT_STREQ("yo", vendorField);
533543

534544
int confirmations = dataZero["confirmations"];
535545
ASSERT_EQ(3034848, confirmations);
536546

537-
JsonObject& timestamp = dataZero["timestamp"];
547+
JsonObject timestamp = dataZero["timestamp"];
538548

539549
uint64_t epoch = timestamp["epoch"];
540550
ASSERT_TRUE(3909196ull == epoch);
541551

542552
uint64_t unix_timestamp = timestamp["unix"];
543553
ASSERT_TRUE(1494010396ull == unix_timestamp);
544554

545-
const char* human = timestamp["human"];
555+
const auto human = timestamp["human"];
546556
ASSERT_STREQ("2017-05-05T18:53:16Z", human);
547557
}

0 commit comments

Comments
 (0)