2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/amount.h>
5#include <test/jtx/credentials.h>
6#include <test/jtx/deposit.h>
7#include <test/jtx/flags.h>
9#include <xrpl/beast/unit_test/suite.h>
10#include <xrpl/json/json_value.h>
11#include <xrpl/protocol/ErrorCodes.h>
12#include <xrpl/protocol/Protocol.h>
13#include <xrpl/protocol/SField.h>
14#include <xrpl/protocol/TxFlags.h>
15#include <xrpl/protocol/jss.h>
37 args[jss::source_account] = source.
human();
38 args[jss::destination_account] = dest.
human();
40 args[jss::ledger_index] = ledger;
58 BEAST_EXPECT(results[jss::deposit_authorized] ==
authorized);
59 BEAST_EXPECT(results[jss::status] == jss::success);
73 env.
fund(
XRP(1000), alice, becky, carol);
93 env(
fset(becky, asfDepositAuth));
105 "deposit_authorized",
113 "deposit_authorized",
125 "deposit_authorized",
131 env.
rpc(
"json",
"deposit_authorized",
depositAuthArgs(carol, becky).toStyledString()),
135 env(
fclear(becky, asfDepositAuth));
139 env.
rpc(
"json",
"deposit_authorized",
depositAuthArgs(carol, becky).toStyledString()),
144 env.
rpc(
"json",
"deposit_authorized",
depositAuthArgs(alice, becky).toStyledString()),
158 auto const verifyErr = [
this](
162 char const* errorMsg,
163 bool withLedgerFields =
false) {
164 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
165 BEAST_EXPECT(result[jss::result][jss::error] == error);
166 BEAST_EXPECT(result[jss::result][jss::error_code] == code);
167 BEAST_EXPECT(result[jss::result][jss::error_message] == errorMsg);
169 result[jss::result].isMember(jss::ledger_current_index) == withLedgerFields);
170 BEAST_EXPECT(result[jss::result].isMember(jss::validated) == withLedgerFields);
179 verifyErr(result,
"invalidParams",
RpcInvalidParams,
"Missing field 'source_account'.");
184 args[jss::source_account] = 7.3;
190 "Invalid field 'source_account', not a string.");
195 args[jss::source_account] =
"rG1QQv2nh2gr7RCZ!P8YYcBUKCCN633jCn";
197 verifyErr(result,
"actMalformed",
RpcActMalformed,
"Account malformed.");
205 result,
"invalidParams",
RpcInvalidParams,
"Missing field 'destination_account'.");
210 args[jss::destination_account] = 7.3;
216 "Invalid field 'destination_account', not a string.");
221 args[jss::destination_account] =
"rP6P9ypfAmc!pw8SZHNwM4nvZHFXDraQas";
223 verifyErr(result,
"actMalformed",
RpcActMalformed,
"Account malformed.");
233 "Invalid field 'ledger_index', not string or number.");
239 verifyErr(result,
"lgrNotFound",
RpcLgrNotFound,
"ledgerNotFound");
244 args[jss::ledger_index] = 17;
246 verifyErr(result,
"lgrNotFound",
RpcLgrNotFound,
"ledgerNotFound");
265 "Destination account not found.",
289 BEAST_EXPECT(result[jss::status] == (
authorized ? jss::success : jss::error));
290 if (result.
isMember(jss::deposit_authorized))
291 BEAST_EXPECT(result[jss::deposit_authorized] ==
authorized);
295 result.
isMember(jss::deposit_authorized) &&
296 (result[jss::deposit_authorized] ==
true));
302 BEAST_EXPECT(result[jss::error].asString() == error);
303 BEAST_EXPECT(result[jss::error_code] == code);
304 BEAST_EXPECT(result[jss::error_message].asString() == errorMessage);
306 bool const withLedgerFields = error ==
"badCredentials";
307 BEAST_EXPECT(result.
isMember(jss::ledger_hash) == withLedgerFields);
308 BEAST_EXPECT(result.
isMember(jss::ledger_index) == withLedgerFields);
309 BEAST_EXPECT(result.
isMember(jss::validated) == withLedgerFields);
314 BEAST_EXPECT(result[jss::source_account] == src.
human());
315 BEAST_EXPECT(result[jss::destination_account] == dst.
human());
317 for (
unsigned i = 0; i < credentialIDs.size(); ++i)
318 BEAST_EXPECT(result[jss::credentials][i] == credentialIDs[i]);
322 BEAST_EXPECT(result[jss::request].isObject());
324 auto const& request = result[jss::request];
325 BEAST_EXPECT(request[jss::command] == jss::deposit_authorized);
326 BEAST_EXPECT(request[jss::source_account] == src.
human());
327 BEAST_EXPECT(request[jss::destination_account] == dst.
human());
329 for (
unsigned i = 0; i < credentialIDs.size(); ++i)
330 BEAST_EXPECT(request[jss::credentials][i] == credentialIDs[i]);
341 char const credType[] =
"abcde";
349 env.
fund(
XRP(1000), alice, becky, carol, diana);
357 std::string const credIdx = jv[jss::result][jss::index].asString();
360 env(
fset(becky, asfDepositAuth));
368 testcase(
"deposit_authorized with credentials failure: empty array.");
382 "Invalid field 'credentials', not is non-empty array of CredentialID(hash256).");
387 "deposit_authorized with credentials failure: not a string "
392 args[jss::credentials].
append(1);
393 args[jss::credentials].
append(3);
404 "Invalid field 'credentials', not an array of CredentialID(hash256).");
409 "deposit_authorized with credentials failure: not a hex string "
414 args[jss::credentials].
append(
"hello world");
425 "Invalid field 'credentials', not an array of CredentialID(hash256).");
430 "deposit_authorized with credentials failure: not a credential "
438 "0127AB8B4B29CCDBB61AA51C0799A8A6BB80B86A9899807C11ED576AF8516"
449 "0127AB8B4B29CCDBB61AA51C0799A8A6BB80B86A9899807C11ED576AF8516"
454 "credentials don't exist");
459 "deposit_authorized with credentials failure: zero "
475 "credentials don't exist");
481 "deposit_authorized with credentials not authorized: "
482 "credential not accepted");
483 auto const jv = env.
rpc(
485 "deposit_authorized",
495 "credentials aren't accepted");
503 testcase(
"deposit_authorized with duplicates in credentials");
504 auto const jv = env.
rpc(
506 "deposit_authorized",
516 "duplicates in credentials");
521 "18004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288BE4",
522 "28004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288BE4",
523 "38004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288BE4",
524 "48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288BE4",
525 "58004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288BE4",
526 "68004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288BE4",
527 "78004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288BE4",
528 "88004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288BE4",
529 "98004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288BE4",
533 testcase(
"deposit_authorized too long credentials");
534 auto const jv = env.
rpc(
536 "deposit_authorized",
537 depositAuthArgs(alice, becky,
"validated", kCredIds).toStyledString());
546 "Invalid field 'credentials', not array too long.");
550 testcase(
"deposit_authorized with credentials");
551 auto const jv = env.
rpc(
553 "deposit_authorized",
567 std::string const credBecky = jv[jss::result][jss::index].asString();
569 testcase(
"deposit_authorized account without preauth");
572 "deposit_authorized",
585 std::string const credDiana = jv[jss::result][jss::index].asString();
590 "deposit_authorized",
600 "credentials doesn't belong to the root account");
604 testcase(
"deposit_authorized with expired credentials");
607 char const credType2[] =
"random";
609 env.
current()->header().parentCloseTime.time_since_epoch().count() + 40;
613 jv[sfExpiration.jsonName] = x;
619 std::string const credIdx2 = jv[jss::result][jss::index].asString();
622 env(
fset(becky, asfDepositAuth));
633 "deposit_authorized",
645 "deposit_authorized",
656 "credentials are expired");
TestcaseT testcase
Memberspace for declaring test cases.
Value removeMember(char const *key)
Remove and return the named member.
std::string toStyledString() const
Value & append(Value const &value)
Append value to array at the end.
bool isMember(char const *key) const
Return true if the object has a member named key.
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="", ErrorCodeI code=RpcSuccess, std::string_view errorMessage="")
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={})
void validateDepositAuthResult(json::Value const &result, bool authorized)
Immutable cryptographic account descriptor.
std::string const & human() const
Returns the human readable public key.
A transaction testing environment.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
@ Array
array value (ordered list)
@ Object
object value (collection of name/value pairs).
The api_version numbers this server serves.
json::Value accept(jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
json::Value create(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 authCredentials(jtx::Account const &account, std::vector< AuthorizeCredentials > const &auth)
json::Value auth(Account const &account, Account const &auth)
Preauthorize for deposit.
XrpT const XRP
Converts to XRP Issue or STAmount.
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.
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static bool authorized(Port const &port, std::map< std::string, std::string > const &h)
constexpr std::size_t kMaxCredentialsArraySize
The maximum number of credentials can be passed in array.