@@ -81,12 +81,13 @@ TEST(api, test_block) { // NOLINT
81
81
82
82
const auto blockResponse = connection.api .blocks .get (" 58328125061111756" );
83
83
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 ); }
86
87
87
- JsonObject& data = root [" data" ];
88
+ JsonObject data = doc [" data" ];
88
89
89
- const char * id = data[" id" ];
90
+ const auto id = data[" id" ];
90
91
ASSERT_STREQ (" 58328125061111756" , id);
91
92
92
93
int version = data[" version" ];
@@ -95,7 +96,7 @@ TEST(api, test_block) { // NOLINT
95
96
int height = data[" height" ];
96
97
ASSERT_EQ (3035362 , height);
97
98
98
- JsonObject& forged = data[" forged" ];
99
+ JsonObject forged = data[" forged" ];
99
100
100
101
uint64_t reward = forged[" reward" ];
101
102
ASSERT_TRUE (reward == 200000000 );
@@ -106,43 +107,46 @@ TEST(api, test_block) { // NOLINT
106
107
uint64_t total = forged[" total" ];
107
108
ASSERT_TRUE (total == 200000000 );
108
109
109
- JsonObject& payload = data[" payload" ];
110
+ JsonObject payload = data[" payload" ];
110
111
111
- const char * hash = payload[" hash" ];
112
- ASSERT_STREQ (" e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" , hash);
112
+ const auto hash = payload[" hash" ];
113
+ ASSERT_STREQ (
114
+ " e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
115
+ hash);
113
116
114
117
int length = payload[" length" ];
115
118
ASSERT_EQ (0 , length);
116
119
117
- JsonObject& generator = data[" generator" ];
120
+ JsonObject generator = data[" generator" ];
118
121
119
- const char * username = generator[" username" ];
122
+ const auto username = generator[" username" ];
120
123
ASSERT_STREQ (" genesis_6" , username);
121
124
122
- const char * address = generator[" address" ];
125
+ const auto address = generator[" address" ];
123
126
ASSERT_STREQ (" D5e2FzTPqdEHridjzpFZCCVyepAu6Vpmk4" , address);
124
127
125
- const char * publicKey = generator[" publicKey" ];
126
- ASSERT_STREQ (" 023e577a7b3362e0aba70e6911d230e86d729b4cb640f0e0b25637b812a3e38b53" , publicKey);
128
+ const auto publicKey = generator[" publicKey" ];
129
+ ASSERT_STREQ (
130
+ " 023e577a7b3362e0aba70e6911d230e86d729b4cb640f0e0b25637b812a3e38b53" ,
131
+ publicKey);
127
132
128
- const char * signature = data[" signature" ];
133
+ const auto signature = data[" signature" ];
129
134
ASSERT_STREQ (
130
- " 3044022047aeb0c9cfbb5709aba4c177009bfdc7804ef597073fb9ca6cb614d7e3d1af2d02207234119d02ca26600ece045c59266945081b"
131
- " 4c8237370576aaad7c61a09fe0ad" ,
135
+ " 3044022047aeb0c9cfbb5709aba4c177009bfdc7804ef597073fb9ca6cb614d7e3d1af2d02207234119d02ca26600ece045c59266945081b4c8237370576aaad7c61a09fe0ad" ,
132
136
signature);
133
137
134
138
int transactions = data[" transactions" ];
135
139
ASSERT_EQ (0 , transactions);
136
140
137
- JsonObject& timestamp = data[" timestamp" ];
141
+ JsonObject timestamp = data[" timestamp" ];
138
142
139
143
int epoch = timestamp[" epoch" ];
140
144
ASSERT_EQ (32816544 , epoch);
141
145
142
146
int timestampUnix = timestamp[" unix" ];
143
147
ASSERT_EQ (1522917744 , timestampUnix);
144
148
145
- const char * human = timestamp[" human" ];
149
+ const auto human = timestamp[" human" ];
146
150
ASSERT_STREQ (" 2018-04-05T08:42:24Z" , human);
147
151
}
148
152
@@ -221,11 +225,12 @@ TEST(api, test_block_transactions) { // NOLINT
221
225
EXPECT_CALL (connection.api .blocks , transactions (_)).Times (1 ).WillOnce (Return (expected_response));
222
226
223
227
const auto blockTransactionsResponse = connection.api .blocks .transactions (" 14126007750611341900" );
228
+
229
+ DynamicJsonDocument doc (1452 );
230
+ DeserializationError error = deserializeJson (doc, blockTransactionsResponse);
231
+ if (error) { exit (0 ); }
224
232
225
- DynamicJsonBuffer jsonBuffer (blockTransactionsResponse.size ());
226
- JsonObject& root = jsonBuffer.parseObject (blockTransactionsResponse);
227
-
228
- JsonObject& meta = root[" meta" ];
233
+ JsonObject meta = doc[" meta" ];
229
234
230
235
int count = meta[" count" ];
231
236
ASSERT_EQ (1 , count);
@@ -236,12 +241,14 @@ TEST(api, test_block_transactions) { // NOLINT
236
241
int totalCount = meta[" totalCount" ];
237
242
ASSERT_EQ (1 , totalCount);
238
243
239
- JsonObject& dataZero = root [" data" ][0 ];
244
+ JsonObject dataZero = doc [" data" ][0 ];
240
245
241
- const char * id = dataZero[" id" ];
242
- ASSERT_STREQ (" 57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369" , id);
246
+ const auto id = dataZero[" id" ];
247
+ ASSERT_STREQ (
248
+ " 57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369" ,
249
+ id);
243
250
244
- const char * blockId = dataZero[" blockId" ];
251
+ const auto blockId = dataZero[" blockId" ];
245
252
ASSERT_STREQ (" 14126007750611341900" , blockId);
246
253
247
254
int type = dataZero[" type" ];
@@ -253,27 +260,26 @@ TEST(api, test_block_transactions) { // NOLINT
253
260
uint64_t fee = dataZero[" fee" ];
254
261
ASSERT_TRUE (fee == 10000000 );
255
262
256
- const char * sender = dataZero[" sender" ];
263
+ const auto sender = dataZero[" sender" ];
257
264
ASSERT_STREQ (" DGihocTkwDygiFvmg6aG8jThYTic47GzU9" , sender);
258
265
259
- const char * signature = dataZero[" signature" ];
266
+ const auto signature = dataZero[" signature" ];
260
267
ASSERT_STREQ (
261
- " 3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1"
262
- " c34df8a46afe655b021930b03e214e" ,
268
+ " 3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1c34df8a46afe655b021930b03e214e" ,
263
269
signature);
264
270
265
271
int confirmations = dataZero[" confirmations" ];
266
272
ASSERT_EQ (3034848 , confirmations);
267
273
268
- JsonObject& timestamp = dataZero[" timestamp" ];
274
+ JsonObject timestamp = dataZero[" timestamp" ];
269
275
270
276
int epoch = timestamp[" epoch" ];
271
277
ASSERT_EQ (3909196 , epoch);
272
278
273
279
int timestampUnix = timestamp[" unix" ];
274
280
ASSERT_EQ (1494010396 , timestampUnix);
275
281
276
- const char * human = timestamp[" human" ];
282
+ const auto human = timestamp[" human" ];
277
283
ASSERT_STREQ (" 2017-05-05T18:53:16Z" , human);
278
284
}
279
285
@@ -374,10 +380,11 @@ TEST(api, test_blocks) { // NOLINT
374
380
375
381
const auto blocksResponse = connection.api .blocks .all (5 , 1 );
376
382
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 ); }
379
386
380
- JsonObject& meta = root [" meta" ];
387
+ JsonObject meta = doc [" meta" ];
381
388
382
389
int count = meta[" count" ];
383
390
ASSERT_NE (0 , count);
@@ -388,7 +395,7 @@ TEST(api, test_blocks) { // NOLINT
388
395
int totalCount = meta[" totalCount" ];
389
396
ASSERT_NE (0 , totalCount);
390
397
391
- JsonObject& dataZero = root [" data" ][0 ];
398
+ JsonObject dataZero = doc [" data" ][0 ];
392
399
393
400
int version = dataZero[" version" ];
394
401
ASSERT_EQ (0 , version);
@@ -478,17 +485,19 @@ TEST(api, test_blocks_search) { // NOLINT
478
485
]
479
486
})" ;
480
487
481
- const std::map<std::string, std::string> body = {
482
- {" id" , " 8337447655053578871" }, {" previousBlock" , " 6440284271011893973" }, {" version" , " 0" }};
483
-
484
488
EXPECT_CALL (connection.api .blocks , search (_, _, _)).Times (1 ).WillOnce (Return (expected_response));
485
489
490
+ const std::map<std::string, std::string> body = {
491
+ { " id" , " 8337447655053578871" },
492
+ { " previousBlock" , " 6440284271011893973" },
493
+ { " version" , " 0" }};
486
494
const auto walletsSearch = connection.api .blocks .search (body, 5 , 1 );
487
495
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 ); }
490
499
491
- JsonObject& meta = root [" meta" ];
500
+ JsonObject meta = doc [" meta" ];
492
501
493
502
int count = meta[" count" ];
494
503
ASSERT_NE (0 , count);
@@ -499,12 +508,14 @@ TEST(api, test_blocks_search) { // NOLINT
499
508
int totalCount = meta[" totalCount" ];
500
509
ASSERT_NE (0 , totalCount);
501
510
502
- JsonObject& dataZero = root [" data" ][0 ];
511
+ JsonObject dataZero = doc [" data" ][0 ];
503
512
504
- const char * id = dataZero[" id" ];
505
- ASSERT_STREQ (" 57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369" , id);
513
+ const auto id = dataZero[" id" ];
514
+ ASSERT_STREQ (
515
+ " 57415c61e6e7f10a6f9820d5124b3916f3c3a036b360f4802f0eb484f86f3369" ,
516
+ id);
506
517
507
- const char * blockId = dataZero[" blockId" ];
518
+ const auto blockId = dataZero[" blockId" ];
508
519
ASSERT_STREQ (" 14126007750611341900" , blockId);
509
520
510
521
int type = dataZero[" type" ];
@@ -516,32 +527,31 @@ TEST(api, test_blocks_search) { // NOLINT
516
527
uint64_t fee = dataZero[" fee" ];
517
528
ASSERT_TRUE (10000000ull == fee);
518
529
519
- const char * sender = dataZero[" sender" ];
530
+ const auto sender = dataZero[" sender" ];
520
531
ASSERT_STREQ (" DGihocTkwDygiFvmg6aG8jThYTic47GzU9" , sender);
521
532
522
- const char * recipient = dataZero[" recipient" ];
533
+ const auto recipient = dataZero[" recipient" ];
523
534
ASSERT_STREQ (" DRac35wghMcmUSe5jDMLBDLWkVVjyKZFxK" , recipient);
524
535
525
- const char * signature = dataZero[" signature" ];
536
+ const auto signature = dataZero[" signature" ];
526
537
ASSERT_STREQ (
527
- " 3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1"
528
- " c34df8a46afe655b021930b03e214e" ,
538
+ " 3045022100878335a71ab6769f3c1e2895041ad24d6c58cdcfe1151c639e65289e5287b0a8022010800bcfdc3223a9c59a6b014e8adf72f1c34df8a46afe655b021930b03e214e" ,
529
539
signature);
530
540
531
- const char * vendorField = dataZero[" vendorField" ];
541
+ const auto vendorField = dataZero[" vendorField" ];
532
542
ASSERT_STREQ (" yo" , vendorField);
533
543
534
544
int confirmations = dataZero[" confirmations" ];
535
545
ASSERT_EQ (3034848 , confirmations);
536
546
537
- JsonObject& timestamp = dataZero[" timestamp" ];
547
+ JsonObject timestamp = dataZero[" timestamp" ];
538
548
539
549
uint64_t epoch = timestamp[" epoch" ];
540
550
ASSERT_TRUE (3909196ull == epoch);
541
551
542
552
uint64_t unix_timestamp = timestamp[" unix" ];
543
553
ASSERT_TRUE (1494010396ull == unix_timestamp);
544
554
545
- const char * human = timestamp[" human" ];
555
+ const auto human = timestamp[" human" ];
546
556
ASSERT_STREQ (" 2017-05-05T18:53:16Z" , human);
547
557
}
0 commit comments