22#include <xrpl/protocol/jss.h>
39 args[jss::source_account] = source.
human();
40 args[jss::destination_account] = dest.
human();
42 args[jss::ledger_index] = ledger;
44 if (!credentials.empty())
47 for (
auto const& s : credentials)
60 BEAST_EXPECT(results[jss::deposit_authorized] ==
authorized);
61 BEAST_EXPECT(results[jss::status] == jss::success);
75 env.
fund(
XRP(1000), alice, becky, carol);
101 "deposit_authorized",
110 "deposit_authorized",
118 "deposit_authorized",
130 "deposit_authorized",
138 "deposit_authorized",
149 "deposit_authorized",
157 "deposit_authorized",
172 auto verifyErr = [
this](
175 char const* errorMsg) {
176 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
177 BEAST_EXPECT(result[jss::result][jss::error] == error);
178 BEAST_EXPECT(result[jss::result][jss::error_message] == errorMsg);
187 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
189 result,
"invalidParams",
"Missing field 'source_account'.");
194 args[jss::source_account] = 7.3;
196 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
200 "Invalid field 'source_account', not a string.");
205 args[jss::source_account] =
"rG1QQv2nh2gr7RCZ!P8YYcBUKCCN633jCn";
207 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
208 verifyErr(result,
"actMalformed",
"Account malformed.");
215 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
219 "Missing field 'destination_account'.");
224 args[jss::destination_account] = 7.3;
226 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
230 "Invalid field 'destination_account', not a string.");
235 args[jss::destination_account] =
236 "rP6P9ypfAmc!pw8SZHNwM4nvZHFXDraQas";
238 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
239 verifyErr(result,
"actMalformed",
"Account malformed.");
245 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
246 verifyErr(result,
"invalidParams",
"ledgerIndexMalformed");
252 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
253 verifyErr(result,
"lgrNotFound",
"ledgerNotFound");
258 args[jss::ledger_index] = 17;
260 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
261 verifyErr(result,
"lgrNotFound",
"ledgerNotFound");
267 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
268 verifyErr(result,
"srcActNotFound",
"Source account not found.");
276 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
278 result,
"dstActNotFound",
"Destination account not found.");
286 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
301 result[jss::status] ==
authorized ? jss::success : jss::error);
302 if (result.
isMember(jss::deposit_authorized))
303 BEAST_EXPECT(result[jss::deposit_authorized] ==
authorized);
306 result.
isMember(jss::deposit_authorized) &&
307 (result[jss::deposit_authorized] ==
true));
309 BEAST_EXPECT(result.
isMember(jss::error) == !error.empty());
311 BEAST_EXPECT(result[jss::error].asString() == error);
315 BEAST_EXPECT(result[jss::source_account] == src.
human());
316 BEAST_EXPECT(result[jss::destination_account] == dst.
human());
318 for (
unsigned i = 0; i < credentialIDs.size(); ++i)
319 BEAST_EXPECT(result[jss::credentials][i] == credentialIDs[i]);
323 BEAST_EXPECT(result[jss::request].isObject());
325 auto const& request = result[jss::request];
326 BEAST_EXPECT(request[jss::command] == jss::deposit_authorized);
327 BEAST_EXPECT(request[jss::source_account] == src.
human());
328 BEAST_EXPECT(request[jss::destination_account] == dst.
human());
330 for (
unsigned i = 0; i < credentialIDs.size(); ++i)
331 BEAST_EXPECT(request[jss::credentials][i] == credentialIDs[i]);
342 char const credType[] =
"abcde";
350 env.
fund(
XRP(1000), alice, becky, carol, diana);
358 std::string const credIdx = jv[jss::result][jss::index].asString();
370 "deposit_authorized with credentials failure: empty array.");
376 env.
rpc(
"json",
"deposit_authorized", args.toStyledString());
378 jv[jss::result], alice, becky,
false, {},
"invalidParams");
383 "deposit_authorized with credentials failure: not a string "
388 args[jss::credentials].append(1);
389 args[jss::credentials].append(3);
392 env.
rpc(
"json",
"deposit_authorized", args.toStyledString());
394 jv[jss::result], alice, becky,
false, {},
"invalidParams");
399 "deposit_authorized with credentials failure: not a hex string "
404 args[jss::credentials].append(
"hello world");
407 env.
rpc(
"json",
"deposit_authorized", args.toStyledString());
419 "deposit_authorized with credentials failure: not a credential "
426 {
"0127AB8B4B29CCDBB61AA51C0799A8A6BB80B86A9899807C11ED576AF8516"
430 env.
rpc(
"json",
"deposit_authorized", args.toStyledString());
436 {
"0127AB8B4B29CCDBB61AA51C0799A8A6BB80B86A9899807C11ED576AF8516"
443 "deposit_authorized with credentials not authorized: "
444 "credential not accepted");
445 auto const jv = env.
rpc(
447 "deposit_authorized",
464 testcase(
"deposit_authorized with duplicates in credentials");
465 auto const jv = env.
rpc(
467 "deposit_authorized",
481 "18004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
483 "28004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
485 "38004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
487 "48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
489 "58004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
491 "68004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
493 "78004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
495 "88004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
497 "98004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
501 testcase(
"deposit_authorized too long credentials");
502 auto const jv = env.
rpc(
504 "deposit_authorized",
508 jv[jss::result], alice, becky,
false, credIds,
"invalidParams");
512 testcase(
"deposit_authorized with credentials");
513 auto const jv = env.
rpc(
515 "deposit_authorized",
519 jv[jss::result], alice, becky,
true, {credIdx});
532 jv[jss::result][jss::index].asString();
534 testcase(
"deposit_authorized account without preauth");
537 "deposit_authorized",
541 jv[jss::result], becky, alice,
true, {credBecky});
553 jv[jss::result][jss::index].asString();
558 "deposit_authorized",
571 testcase(
"deposit_authorized with expired credentials");
574 char const credType2[] =
"fghijk";
577 .parentCloseTime.time_since_epoch()
583 jv[sfExpiration.jsonName] = x;
589 std::string const credIdx2 = jv[jss::result][jss::index].asString();
603 "deposit_authorized",
607 jv[jss::result], alice, becky,
true, {credIdx2});
617 "deposit_authorized",
641BEAST_DEFINE_TESTSUITE(DepositAuthorized, app,
ripple);
Value removeMember(char const *key)
Remove and return the named member.
bool isMember(char const *key) const
Return true if the object has a member named key.
testcase_t testcase
Memberspace for declaring test cases.
void validateDepositAuthResult(Json::Value const &result, bool authorized)
void checkCredentialsResponse(Json::Value const &result, jtx::Account const &src, jtx::Account const &dst, bool authorized, std::vector< std::string > credentialIDs={}, std::string_view error="")
void run() override
Runs the suite.
static Json::Value depositAuthArgs(jtx::Account const &source, jtx::Account const &dest, std::string const &ledger="", std::vector< std::string > const &credentials={})
Immutable cryptographic account descriptor.
std::string const & human() const
Returns the human readable public key.
A transaction testing environment.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
@ arrayValue
array value (ordered list)
@ objectValue
object value (collection of name/value pairs).
Json::Value create(jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Json::Value accept(jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Json::Value ledgerEntry(jtx::Env &env, jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Json::Value auth(Account const &account, Account const &auth)
Preauthorize for deposit.
Json::Value authCredentials(jtx::Account const &account, std::vector< AuthorizeCredentials > const &auth)
Json::Value fclear(Account const &account, std::uint32_t off)
Remove account flag.
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
XRP_t const XRP
Converts to XRP Issue or STAmount.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::uint32_t asfDepositAuth
std::size_t constexpr maxCredentialsArraySize
The maximum number of credentials can be passed in array.
static bool authorized(Port const &port, std::map< std::string, std::string > const &h)