26
26
#include < xrpld/app/misc/TxQ.h>
27
27
#include < xrpl/basics/StringUtilities.h>
28
28
#include < xrpl/beast/unit_test.h>
29
+ #include < xrpl/json/json_value.h>
29
30
#include < xrpl/protocol/AccountID.h>
30
31
#include < xrpl/protocol/ErrorCodes.h>
31
32
#include < xrpl/protocol/STXChainBridge.h>
@@ -1207,6 +1208,42 @@ class LedgerRPC_test : public beast::unit_test::suite
1207
1208
checkErrorValue (jrr[jss::result], " malformedRequest" , " " );
1208
1209
}
1209
1210
1211
+ {
1212
+ // Failed, authorized_credentials contains string data
1213
+ Json::Value jvParams;
1214
+ jvParams[jss::ledger_index] = jss::validated;
1215
+ jvParams[jss::deposit_preauth][jss::owner] = bob.human ();
1216
+ jvParams[jss::deposit_preauth][jss::authorized_credentials] =
1217
+ Json::arrayValue;
1218
+ auto & arr (
1219
+ jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1220
+ arr.append (" foobar" );
1221
+
1222
+ auto const jrr =
1223
+ env.rpc (" json" , " ledger_entry" , to_string (jvParams));
1224
+ checkErrorValue (
1225
+ jrr[jss::result], " malformedAuthorizedCredentials" , " " );
1226
+ }
1227
+
1228
+ {
1229
+ // Failed, authorized_credentials contains arrays
1230
+ Json::Value jvParams;
1231
+ jvParams[jss::ledger_index] = jss::validated;
1232
+ jvParams[jss::deposit_preauth][jss::owner] = bob.human ();
1233
+ jvParams[jss::deposit_preauth][jss::authorized_credentials] =
1234
+ Json::arrayValue;
1235
+ auto & arr (
1236
+ jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1237
+ Json::Value payload = Json::arrayValue;
1238
+ payload.append (42 );
1239
+ arr.append (std::move (payload));
1240
+
1241
+ auto const jrr =
1242
+ env.rpc (" json" , " ledger_entry" , to_string (jvParams));
1243
+ checkErrorValue (
1244
+ jrr[jss::result], " malformedAuthorizedCredentials" , " " );
1245
+ }
1246
+
1210
1247
{
1211
1248
// Failed, authorized_credentials is empty array
1212
1249
Json::Value jvParams;
@@ -1263,6 +1300,27 @@ class LedgerRPC_test : public beast::unit_test::suite
1263
1300
jrr[jss::result], " malformedAuthorizedCredentials" , " " );
1264
1301
}
1265
1302
1303
+ {
1304
+ // Failed, issuer is not set
1305
+ Json::Value jvParams;
1306
+ jvParams[jss::ledger_index] = jss::validated;
1307
+ jvParams[jss::deposit_preauth][jss::owner] = bob.human ();
1308
+
1309
+ jvParams[jss::deposit_preauth][jss::authorized_credentials] =
1310
+ Json::arrayValue;
1311
+ auto & arr (
1312
+ jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1313
+
1314
+ Json::Value jo;
1315
+ jo[jss::credential_type] = strHex (std::string_view (credType));
1316
+ arr.append (std::move (jo));
1317
+
1318
+ auto const jrr =
1319
+ env.rpc (" json" , " ledger_entry" , to_string (jvParams));
1320
+ checkErrorValue (
1321
+ jrr[jss::result], " malformedAuthorizedCredentials" , " " );
1322
+ }
1323
+
1266
1324
{
1267
1325
// Failed, issuer isn't string
1268
1326
Json::Value jvParams;
@@ -1285,6 +1343,30 @@ class LedgerRPC_test : public beast::unit_test::suite
1285
1343
jrr[jss::result], " malformedAuthorizedCredentials" , " " );
1286
1344
}
1287
1345
1346
+ {
1347
+ // Failed, issuer is an array
1348
+ Json::Value jvParams;
1349
+ jvParams[jss::ledger_index] = jss::validated;
1350
+ jvParams[jss::deposit_preauth][jss::owner] = bob.human ();
1351
+
1352
+ jvParams[jss::deposit_preauth][jss::authorized_credentials] =
1353
+ Json::arrayValue;
1354
+ auto & arr (
1355
+ jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1356
+
1357
+ Json::Value jo;
1358
+ Json::Value payload = Json::arrayValue;
1359
+ payload.append (42 );
1360
+ jo[jss::issuer] = std::move (payload);
1361
+ jo[jss::credential_type] = strHex (std::string_view (credType));
1362
+ arr.append (std::move (jo));
1363
+
1364
+ auto const jrr =
1365
+ env.rpc (" json" , " ledger_entry" , to_string (jvParams));
1366
+ checkErrorValue (
1367
+ jrr[jss::result], " malformedAuthorizedCredentials" , " " );
1368
+ }
1369
+
1288
1370
{
1289
1371
// Failed, issuer isn't valid encoded account
1290
1372
Json::Value jvParams;
@@ -1307,12 +1389,32 @@ class LedgerRPC_test : public beast::unit_test::suite
1307
1389
jrr[jss::result], " malformedAuthorizedCredentials" , " " );
1308
1390
}
1309
1391
1392
+ {
1393
+ // Failed, credential_type is not set
1394
+ Json::Value jvParams;
1395
+ jvParams[jss::ledger_index] = jss::validated;
1396
+ jvParams[jss::deposit_preauth][jss::owner] = bob.human ();
1397
+
1398
+ jvParams[jss::deposit_preauth][jss::authorized_credentials] =
1399
+ Json::arrayValue;
1400
+ auto & arr (
1401
+ jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1402
+
1403
+ Json::Value jo;
1404
+ jo[jss::issuer] = issuer.human ();
1405
+ arr.append (std::move (jo));
1406
+
1407
+ auto const jrr =
1408
+ env.rpc (" json" , " ledger_entry" , to_string (jvParams));
1409
+ checkErrorValue (
1410
+ jrr[jss::result], " malformedAuthorizedCredentials" , " " );
1411
+ }
1412
+
1310
1413
{
1311
1414
// Failed, credential_type isn't string
1312
1415
Json::Value jvParams;
1313
1416
jvParams[jss::ledger_index] = jss::validated;
1314
1417
jvParams[jss::deposit_preauth][jss::owner] = bob.human ();
1315
- jvParams[jss::deposit_preauth][jss::authorized] = alice.human ();
1316
1418
1317
1419
jvParams[jss::deposit_preauth][jss::authorized_credentials] =
1318
1420
Json::arrayValue;
@@ -1326,15 +1428,39 @@ class LedgerRPC_test : public beast::unit_test::suite
1326
1428
1327
1429
auto const jrr =
1328
1430
env.rpc (" json" , " ledger_entry" , to_string (jvParams));
1329
- checkErrorValue (jrr[jss::result], " malformedRequest" , " " );
1431
+ checkErrorValue (
1432
+ jrr[jss::result], " malformedAuthorizedCredentials" , " " );
1433
+ }
1434
+
1435
+ {
1436
+ // Failed, credential_type is an array
1437
+ Json::Value jvParams;
1438
+ jvParams[jss::ledger_index] = jss::validated;
1439
+ jvParams[jss::deposit_preauth][jss::owner] = bob.human ();
1440
+
1441
+ jvParams[jss::deposit_preauth][jss::authorized_credentials] =
1442
+ Json::arrayValue;
1443
+ auto & arr (
1444
+ jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1445
+
1446
+ Json::Value jo;
1447
+ jo[jss::issuer] = issuer.human ();
1448
+ Json::Value payload = Json::arrayValue;
1449
+ payload.append (42 );
1450
+ jo[jss::credential_type] = std::move (payload);
1451
+ arr.append (std::move (jo));
1452
+
1453
+ auto const jrr =
1454
+ env.rpc (" json" , " ledger_entry" , to_string (jvParams));
1455
+ checkErrorValue (
1456
+ jrr[jss::result], " malformedAuthorizedCredentials" , " " );
1330
1457
}
1331
1458
1332
1459
{
1333
1460
// Failed, credential_type isn't hex encoded
1334
1461
Json::Value jvParams;
1335
1462
jvParams[jss::ledger_index] = jss::validated;
1336
1463
jvParams[jss::deposit_preauth][jss::owner] = bob.human ();
1337
- jvParams[jss::deposit_preauth][jss::authorized] = alice.human ();
1338
1464
1339
1465
jvParams[jss::deposit_preauth][jss::authorized_credentials] =
1340
1466
Json::arrayValue;
@@ -1348,7 +1474,8 @@ class LedgerRPC_test : public beast::unit_test::suite
1348
1474
1349
1475
auto const jrr =
1350
1476
env.rpc (" json" , " ledger_entry" , to_string (jvParams));
1351
- checkErrorValue (jrr[jss::result], " malformedRequest" , " " );
1477
+ checkErrorValue (
1478
+ jrr[jss::result], " malformedAuthorizedCredentials" , " " );
1352
1479
}
1353
1480
}
1354
1481
0 commit comments