21#include <xrpl/protocol/jss.h>
38 args[jss::source_account] = source.
human();
39 args[jss::destination_account] = dest.
human();
41 args[jss::ledger_index] = ledger;
43 if (!credentials.empty())
46 for (
auto const& s : credentials)
59 BEAST_EXPECT(results[jss::deposit_authorized] ==
authorized);
60 BEAST_EXPECT(results[jss::status] == jss::success);
73 env.
fund(
XRP(1000), alice, becky, carol);
108 "deposit_authorized",
116 "deposit_authorized",
128 "deposit_authorized",
136 "deposit_authorized",
147 "deposit_authorized",
155 "deposit_authorized",
169 auto verifyErr = [
this](
172 char const* errorMsg) {
173 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
174 BEAST_EXPECT(result[jss::result][jss::error] == error);
175 BEAST_EXPECT(result[jss::result][jss::error_message] == errorMsg);
184 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
186 result,
"invalidParams",
"Missing field 'source_account'.");
191 args[jss::source_account] = 7.3;
193 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
197 "Invalid field 'source_account', not a string.");
202 args[jss::source_account] =
"rG1QQv2nh2gr7RCZ!P8YYcBUKCCN633jCn";
204 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
205 verifyErr(result,
"actMalformed",
"Account malformed.");
212 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
216 "Missing field 'destination_account'.");
221 args[jss::destination_account] = 7.3;
223 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
227 "Invalid field 'destination_account', not a string.");
232 args[jss::destination_account] =
233 "rP6P9ypfAmc!pw8SZHNwM4nvZHFXDraQas";
235 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
236 verifyErr(result,
"actMalformed",
"Account malformed.");
242 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
243 verifyErr(result,
"invalidParams",
"ledgerIndexMalformed");
249 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
250 verifyErr(result,
"lgrNotFound",
"ledgerNotFound");
255 args[jss::ledger_index] = 17;
257 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
258 verifyErr(result,
"lgrNotFound",
"ledgerNotFound");
264 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
265 verifyErr(result,
"srcActNotFound",
"Source account not found.");
273 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
275 result,
"dstActNotFound",
"Destination account not found.");
283 env.
rpc(
"json",
"deposit_authorized", args.toStyledString())};
298 result[jss::status] ==
authorized ? jss::success : jss::error);
299 if (result.
isMember(jss::deposit_authorized))
300 BEAST_EXPECT(result[jss::deposit_authorized] ==
authorized);
303 result.
isMember(jss::deposit_authorized) &&
304 (result[jss::deposit_authorized] ==
true));
306 BEAST_EXPECT(result.
isMember(jss::error) == !error.empty());
308 BEAST_EXPECT(result[jss::error].asString() == error);
312 BEAST_EXPECT(result[jss::source_account] == src.
human());
313 BEAST_EXPECT(result[jss::destination_account] == dst.
human());
315 for (
unsigned i = 0; i < credentialIDs.size(); ++i)
316 BEAST_EXPECT(result[jss::credentials][i] == credentialIDs[i]);
320 BEAST_EXPECT(result[jss::request].isObject());
322 auto const& request = result[jss::request];
323 BEAST_EXPECT(request[jss::command] == jss::deposit_authorized);
324 BEAST_EXPECT(request[jss::source_account] == src.
human());
325 BEAST_EXPECT(request[jss::destination_account] == dst.
human());
327 for (
unsigned i = 0; i < credentialIDs.size(); ++i)
328 BEAST_EXPECT(request[jss::credentials][i] == credentialIDs[i]);
337 const char credType[] =
"abcde";
345 env.
fund(
XRP(1000), alice, becky, carol, diana);
353 std::string const credIdx = jv[jss::result][jss::index].asString();
365 "deposit_authorized with credentials failed: empty array.");
371 env.
rpc(
"json",
"deposit_authorized", args.toStyledString());
373 jv[jss::result], alice, becky,
false, {},
"invalidParams");
378 "deposit_authorized with credentials failed: not a string "
383 args[jss::credentials].append(1);
384 args[jss::credentials].append(3);
387 env.
rpc(
"json",
"deposit_authorized", args.toStyledString());
389 jv[jss::result], alice, becky,
false, {},
"invalidParams");
394 "deposit_authorized with credentials failed: not a hex string "
399 args[jss::credentials].append(
"hello world");
402 env.
rpc(
"json",
"deposit_authorized", args.toStyledString());
414 "deposit_authorized with credentials failed: not a credential "
421 {
"0127AB8B4B29CCDBB61AA51C0799A8A6BB80B86A9899807C11ED576AF8516"
425 env.
rpc(
"json",
"deposit_authorized", args.toStyledString());
431 {
"0127AB8B4B29CCDBB61AA51C0799A8A6BB80B86A9899807C11ED576AF8516"
438 "deposit_authorized with credentials not authorized: "
439 "credential not accepted");
440 auto const jv = env.
rpc(
442 "deposit_authorized",
459 testcase(
"deposit_authorized with duplicates in credentials");
460 auto const jv = env.
rpc(
462 "deposit_authorized",
476 "18004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
478 "28004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
480 "38004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
482 "48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
484 "58004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
486 "68004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
488 "78004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
490 "88004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
492 "98004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
496 testcase(
"deposit_authorized too long credentials");
497 auto const jv = env.
rpc(
499 "deposit_authorized",
503 jv[jss::result], alice, becky,
false, credIds,
"invalidParams");
507 testcase(
"deposit_authorized with credentials");
508 auto const jv = env.
rpc(
510 "deposit_authorized",
514 jv[jss::result], alice, becky,
true, {credIdx});
527 jv[jss::result][jss::index].asString();
529 testcase(
"deposit_authorized account without preauth");
532 "deposit_authorized",
536 jv[jss::result], becky, alice,
true, {credBecky});
548 jv[jss::result][jss::index].asString();
553 "deposit_authorized",
566 testcase(
"deposit_authorized with expired credentials");
569 const char credType2[] =
"fghijk";
572 .parentCloseTime.time_since_epoch()
578 jv[sfExpiration.jsonName] = x;
584 std::string const credIdx2 = jv[jss::result][jss::index].asString();
598 "deposit_authorized",
602 jv[jss::result], alice, becky,
true, {credIdx2});
612 "deposit_authorized",
636BEAST_DEFINE_TESTSUITE(DepositAuthorized, app,
ripple);
Value removeMember(const char *key)
Remove and return the named member.
bool isMember(const char *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).
TER authorized(ApplyContext const &ctx, AccountID const &dst)
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.