mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Format first-party source according to .clang-format
This commit is contained in:
committed by
manojsdoshi
parent
65dfc5d19e
commit
50760c6935
@@ -27,214 +27,257 @@ class DepositAuthorized_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
// Helper function that builds arguments for a deposit_authorized command.
|
||||
static Json::Value depositAuthArgs (
|
||||
static Json::Value
|
||||
depositAuthArgs(
|
||||
jtx::Account const& source,
|
||||
jtx::Account const& dest, std::string const& ledger = "")
|
||||
jtx::Account const& dest,
|
||||
std::string const& ledger = "")
|
||||
{
|
||||
Json::Value args {Json::objectValue};
|
||||
Json::Value args{Json::objectValue};
|
||||
args[jss::source_account] = source.human();
|
||||
args[jss::destination_account] = dest.human();
|
||||
if (! ledger.empty())
|
||||
if (!ledger.empty())
|
||||
args[jss::ledger_index] = ledger;
|
||||
return args;
|
||||
}
|
||||
|
||||
// Helper function that verifies a deposit_authorized request was
|
||||
// successful and returned the expected value.
|
||||
void validateDepositAuthResult (Json::Value const& result, bool authorized)
|
||||
void
|
||||
validateDepositAuthResult(Json::Value const& result, bool authorized)
|
||||
{
|
||||
Json::Value const& results {result[jss::result]};
|
||||
BEAST_EXPECT (results[jss::deposit_authorized] == authorized);
|
||||
BEAST_EXPECT (results[jss::status] == jss::success);
|
||||
Json::Value const& results{result[jss::result]};
|
||||
BEAST_EXPECT(results[jss::deposit_authorized] == authorized);
|
||||
BEAST_EXPECT(results[jss::status] == jss::success);
|
||||
}
|
||||
|
||||
// Test a variety of non-malformed cases.
|
||||
void testValid()
|
||||
void
|
||||
testValid()
|
||||
{
|
||||
using namespace jtx;
|
||||
Account const alice {"alice"};
|
||||
Account const becky {"becky"};
|
||||
Account const carol {"carol"};
|
||||
Account const alice{"alice"};
|
||||
Account const becky{"becky"};
|
||||
Account const carol{"carol"};
|
||||
|
||||
Env env(*this);
|
||||
env.fund(XRP(1000), alice, becky, carol);
|
||||
env.close();
|
||||
|
||||
// becky is authorized to deposit to herself.
|
||||
validateDepositAuthResult (env.rpc ("json", "deposit_authorized",
|
||||
depositAuthArgs (
|
||||
becky, becky, "validated").toStyledString()), true);
|
||||
validateDepositAuthResult(
|
||||
env.rpc(
|
||||
"json",
|
||||
"deposit_authorized",
|
||||
depositAuthArgs(becky, becky, "validated").toStyledString()),
|
||||
true);
|
||||
|
||||
// alice should currently be authorized to deposit to becky.
|
||||
validateDepositAuthResult (env.rpc ("json", "deposit_authorized",
|
||||
depositAuthArgs (
|
||||
alice, becky, "validated").toStyledString()), true);
|
||||
validateDepositAuthResult(
|
||||
env.rpc(
|
||||
"json",
|
||||
"deposit_authorized",
|
||||
depositAuthArgs(alice, becky, "validated").toStyledString()),
|
||||
true);
|
||||
|
||||
// becky sets the DepositAuth flag in the current ledger.
|
||||
env (fset (becky, asfDepositAuth));
|
||||
env(fset(becky, asfDepositAuth));
|
||||
|
||||
// alice is no longer authorized to deposit to becky in current ledger.
|
||||
validateDepositAuthResult (env.rpc ("json", "deposit_authorized",
|
||||
depositAuthArgs (alice, becky).toStyledString()), false);
|
||||
validateDepositAuthResult(
|
||||
env.rpc(
|
||||
"json",
|
||||
"deposit_authorized",
|
||||
depositAuthArgs(alice, becky).toStyledString()),
|
||||
false);
|
||||
env.close();
|
||||
|
||||
// becky is still authorized to deposit to herself.
|
||||
validateDepositAuthResult (env.rpc ("json", "deposit_authorized",
|
||||
depositAuthArgs (
|
||||
becky, becky, "validated").toStyledString()), true);
|
||||
validateDepositAuthResult(
|
||||
env.rpc(
|
||||
"json",
|
||||
"deposit_authorized",
|
||||
depositAuthArgs(becky, becky, "validated").toStyledString()),
|
||||
true);
|
||||
|
||||
// It's not a reciprocal arrangement. becky can deposit to alice.
|
||||
validateDepositAuthResult (env.rpc ("json", "deposit_authorized",
|
||||
depositAuthArgs (
|
||||
becky, alice, "current").toStyledString()), true);
|
||||
validateDepositAuthResult(
|
||||
env.rpc(
|
||||
"json",
|
||||
"deposit_authorized",
|
||||
depositAuthArgs(becky, alice, "current").toStyledString()),
|
||||
true);
|
||||
|
||||
// becky creates a deposit authorization for alice.
|
||||
env (deposit::auth (becky, alice));
|
||||
env(deposit::auth(becky, alice));
|
||||
env.close();
|
||||
|
||||
// alice is now authorized to deposit to becky.
|
||||
validateDepositAuthResult (env.rpc ("json", "deposit_authorized",
|
||||
depositAuthArgs (alice, becky, "closed").toStyledString()), true);
|
||||
validateDepositAuthResult(
|
||||
env.rpc(
|
||||
"json",
|
||||
"deposit_authorized",
|
||||
depositAuthArgs(alice, becky, "closed").toStyledString()),
|
||||
true);
|
||||
|
||||
// carol is still not authorized to deposit to becky.
|
||||
validateDepositAuthResult (env.rpc ("json", "deposit_authorized",
|
||||
depositAuthArgs (carol, becky).toStyledString()), false);
|
||||
validateDepositAuthResult(
|
||||
env.rpc(
|
||||
"json",
|
||||
"deposit_authorized",
|
||||
depositAuthArgs(carol, becky).toStyledString()),
|
||||
false);
|
||||
|
||||
// becky clears the the DepositAuth flag so carol becomes authorized.
|
||||
env (fclear (becky, asfDepositAuth));
|
||||
env(fclear(becky, asfDepositAuth));
|
||||
env.close();
|
||||
|
||||
validateDepositAuthResult (env.rpc ("json", "deposit_authorized",
|
||||
depositAuthArgs (carol, becky).toStyledString()), true);
|
||||
validateDepositAuthResult(
|
||||
env.rpc(
|
||||
"json",
|
||||
"deposit_authorized",
|
||||
depositAuthArgs(carol, becky).toStyledString()),
|
||||
true);
|
||||
|
||||
// alice is still authorized to deposit to becky.
|
||||
validateDepositAuthResult (env.rpc ("json", "deposit_authorized",
|
||||
depositAuthArgs (alice, becky).toStyledString()), true);
|
||||
validateDepositAuthResult(
|
||||
env.rpc(
|
||||
"json",
|
||||
"deposit_authorized",
|
||||
depositAuthArgs(alice, becky).toStyledString()),
|
||||
true);
|
||||
}
|
||||
|
||||
// Test malformed cases.
|
||||
void testErrors()
|
||||
void
|
||||
testErrors()
|
||||
{
|
||||
using namespace jtx;
|
||||
Account const alice {"alice"};
|
||||
Account const becky {"becky"};
|
||||
Account const alice{"alice"};
|
||||
Account const becky{"becky"};
|
||||
|
||||
// Lambda that checks the (error) result of deposit_authorized.
|
||||
auto verifyErr = [this] (
|
||||
Json::Value const& result, char const* error, char const* errorMsg)
|
||||
{
|
||||
BEAST_EXPECT (result[jss::result][jss::status] == jss::error);
|
||||
BEAST_EXPECT (result[jss::result][jss::error] == error);
|
||||
BEAST_EXPECT (result[jss::result][jss::error_message] == errorMsg);
|
||||
auto verifyErr = [this](
|
||||
Json::Value const& result,
|
||||
char const* error,
|
||||
char const* errorMsg) {
|
||||
BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
|
||||
BEAST_EXPECT(result[jss::result][jss::error] == error);
|
||||
BEAST_EXPECT(result[jss::result][jss::error_message] == errorMsg);
|
||||
};
|
||||
|
||||
Env env(*this);
|
||||
{
|
||||
// Missing source_account field.
|
||||
Json::Value args {depositAuthArgs (alice, becky)};
|
||||
args.removeMember (jss::source_account);
|
||||
Json::Value const result {env.rpc (
|
||||
"json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr (result, "invalidParams",
|
||||
"Missing field 'source_account'.");
|
||||
Json::Value args{depositAuthArgs(alice, becky)};
|
||||
args.removeMember(jss::source_account);
|
||||
Json::Value const result{
|
||||
env.rpc("json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr(
|
||||
result, "invalidParams", "Missing field 'source_account'.");
|
||||
}
|
||||
{
|
||||
// Non-string source_account field.
|
||||
Json::Value args {depositAuthArgs (alice, becky)};
|
||||
Json::Value args{depositAuthArgs(alice, becky)};
|
||||
args[jss::source_account] = 7.3;
|
||||
Json::Value const result {env.rpc (
|
||||
"json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr (result, "invalidParams",
|
||||
Json::Value const result{
|
||||
env.rpc("json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr(
|
||||
result,
|
||||
"invalidParams",
|
||||
"Invalid field 'source_account', not a string.");
|
||||
}
|
||||
{
|
||||
// Corrupt source_account field.
|
||||
Json::Value args {depositAuthArgs (alice, becky)};
|
||||
Json::Value args{depositAuthArgs(alice, becky)};
|
||||
args[jss::source_account] = "rG1QQv2nh2gr7RCZ!P8YYcBUKCCN633jCn";
|
||||
Json::Value const result {env.rpc (
|
||||
"json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr (result, "actMalformed", "Account malformed.");
|
||||
Json::Value const result{
|
||||
env.rpc("json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr(result, "actMalformed", "Account malformed.");
|
||||
}
|
||||
{
|
||||
// Missing destination_account field.
|
||||
Json::Value args {depositAuthArgs (alice, becky)};
|
||||
args.removeMember (jss::destination_account);
|
||||
Json::Value const result {env.rpc (
|
||||
"json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr (result, "invalidParams",
|
||||
Json::Value args{depositAuthArgs(alice, becky)};
|
||||
args.removeMember(jss::destination_account);
|
||||
Json::Value const result{
|
||||
env.rpc("json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr(
|
||||
result,
|
||||
"invalidParams",
|
||||
"Missing field 'destination_account'.");
|
||||
}
|
||||
{
|
||||
// Non-string destination_account field.
|
||||
Json::Value args {depositAuthArgs (alice, becky)};
|
||||
Json::Value args{depositAuthArgs(alice, becky)};
|
||||
args[jss::destination_account] = 7.3;
|
||||
Json::Value const result {env.rpc (
|
||||
"json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr (result, "invalidParams",
|
||||
Json::Value const result{
|
||||
env.rpc("json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr(
|
||||
result,
|
||||
"invalidParams",
|
||||
"Invalid field 'destination_account', not a string.");
|
||||
}
|
||||
{
|
||||
// Corrupt destination_account field.
|
||||
Json::Value args {depositAuthArgs (alice, becky)};
|
||||
Json::Value args{depositAuthArgs(alice, becky)};
|
||||
args[jss::destination_account] =
|
||||
"rP6P9ypfAmc!pw8SZHNwM4nvZHFXDraQas";
|
||||
Json::Value const result {env.rpc (
|
||||
"json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr (result, "actMalformed", "Account malformed.");
|
||||
Json::Value const result{
|
||||
env.rpc("json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr(result, "actMalformed", "Account malformed.");
|
||||
}
|
||||
{
|
||||
// Request an invalid ledger.
|
||||
Json::Value args {depositAuthArgs (alice, becky, "17")};
|
||||
Json::Value const result {env.rpc (
|
||||
"json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr (result, "invalidParams", "ledgerIndexMalformed");
|
||||
Json::Value args{depositAuthArgs(alice, becky, "17")};
|
||||
Json::Value const result{
|
||||
env.rpc("json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr(result, "invalidParams", "ledgerIndexMalformed");
|
||||
}
|
||||
{
|
||||
// Request a ledger that doesn't exist yet.
|
||||
Json::Value args {depositAuthArgs (alice, becky)};
|
||||
Json::Value args{depositAuthArgs(alice, becky)};
|
||||
args[jss::ledger_index] = 17;
|
||||
Json::Value const result {env.rpc (
|
||||
"json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr (result, "lgrNotFound", "ledgerNotFound");
|
||||
Json::Value const result{
|
||||
env.rpc("json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr(result, "lgrNotFound", "ledgerNotFound");
|
||||
}
|
||||
{
|
||||
// alice is not yet funded.
|
||||
Json::Value args {depositAuthArgs (alice, becky)};
|
||||
Json::Value const result {env.rpc (
|
||||
"json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr (result, "srcActNotFound",
|
||||
"Source account not found.");
|
||||
Json::Value args{depositAuthArgs(alice, becky)};
|
||||
Json::Value const result{
|
||||
env.rpc("json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr(result, "srcActNotFound", "Source account not found.");
|
||||
}
|
||||
env.fund(XRP(1000), alice);
|
||||
env.close();
|
||||
{
|
||||
// becky is not yet funded.
|
||||
Json::Value args {depositAuthArgs (alice, becky)};
|
||||
Json::Value const result {env.rpc (
|
||||
"json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr (result, "dstActNotFound",
|
||||
"Destination account not found.");
|
||||
Json::Value args{depositAuthArgs(alice, becky)};
|
||||
Json::Value const result{
|
||||
env.rpc("json", "deposit_authorized", args.toStyledString())};
|
||||
verifyErr(
|
||||
result, "dstActNotFound", "Destination account not found.");
|
||||
}
|
||||
env.fund(XRP(1000), becky);
|
||||
env.close();
|
||||
{
|
||||
// Once becky is funded try it again and see it succeed.
|
||||
Json::Value args {depositAuthArgs (alice, becky)};
|
||||
Json::Value const result {env.rpc (
|
||||
"json", "deposit_authorized", args.toStyledString())};
|
||||
validateDepositAuthResult (result, true);
|
||||
Json::Value args{depositAuthArgs(alice, becky)};
|
||||
Json::Value const result{
|
||||
env.rpc("json", "deposit_authorized", args.toStyledString())};
|
||||
validateDepositAuthResult(result, true);
|
||||
}
|
||||
}
|
||||
|
||||
void run() override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testValid();
|
||||
testErrors();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(DepositAuthorized,app,ripple);
|
||||
|
||||
}
|
||||
}
|
||||
BEAST_DEFINE_TESTSUITE(DepositAuthorized, app, ripple);
|
||||
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
Reference in New Issue
Block a user