Skip to content

Commit

Permalink
[WIP] Find everywhere Json is written to the log
Browse files Browse the repository at this point in the history
* Get rid of operator<<(std::ostream&, const Value& root), and
  fix everything that breaks.
  • Loading branch information
ximinez committed Feb 7, 2025
1 parent 02387fd commit 678eb3d
Show file tree
Hide file tree
Showing 33 changed files with 299 additions and 232 deletions.
4 changes: 2 additions & 2 deletions include/xrpl/json/json_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ valueToQuotedString(const char* value);

/// \brief Output using the StyledStreamWriter.
/// \see Json::operator>>()
std::ostream&
operator<<(std::ostream&, const Value& root);
// std::ostream&
// operator<<(std::ostream&, const Value& root);

//------------------------------------------------------------------------------

Expand Down
6 changes: 3 additions & 3 deletions include/xrpl/json/to_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ to_string(Value const&);
std::string
pretty(Value const&);

/** Output using the StyledStreamWriter. @see Json::operator>>(). */
std::ostream&
operator<<(std::ostream&, const Value& root);
///** Output using the StyledStreamWriter. @see Json::operator>>(). */
// std::ostream&
// operator<<(std::ostream&, const Value& root);

} // namespace Json

Expand Down
3 changes: 2 additions & 1 deletion include/xrpl/protocol/STBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ class STBase
virtual std::string
getText() const;

virtual Json::Value getJson(JsonOptions /*options*/) const;
virtual Json::Value getJson(
JsonOptions = JsonOptions::none /*options*/) const;

virtual void
add(Serializer& s) const;
Expand Down
3 changes: 2 additions & 1 deletion include/xrpl/protocol/STValidation.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <xrpl/basics/Log.h>
#include <xrpl/beast/utility/instrumentation.h>
#include <xrpl/json/to_string.h>
#include <xrpl/protocol/FeeUnits.h>
#include <xrpl/protocol/PublicKey.h>
#include <xrpl/protocol/STObject.h>
Expand Down Expand Up @@ -172,7 +173,7 @@ STValidation::STValidation(
if (checkSignature && !isValid())
{
JLOG(debugLog().error()) << "Invalid signature in validation: "
<< getJson(JsonOptions::none);
<< to_string(getJson(JsonOptions::none));
Throw<std::runtime_error>("Invalid signature in validation");
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/app/NFTokenBurn_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ class NFTokenBurnBaseUtil_test : public beast::unit_test::suite
Json::Value jrr = env.rpc(
"json",
"ledger_data",
boost::lexical_cast<std::string>(jvParams));
boost::lexical_cast<std::string>(to_string(jvParams)));

Json::Value& state = jrr[jss::result][jss::state];

Expand Down Expand Up @@ -461,7 +461,7 @@ class NFTokenBurnBaseUtil_test : public beast::unit_test::suite
Json::Value jrr = env.rpc(
"json",
"ledger_data",
boost::lexical_cast<std::string>(jvParams));
boost::lexical_cast<std::string>(to_string(jvParams)));

Json::Value& state = jrr[jss::result][jss::state];

Expand Down
2 changes: 1 addition & 1 deletion src/test/app/NFTokenDir_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class NFTokenDir_test : public beast::unit_test::suite
Json::Value jrr = env.rpc(
"json",
"ledger_data",
boost::lexical_cast<std::string>(jvParams));
boost::lexical_cast<std::string>(to_string(jvParams)));

// Iterate the state and print all NFTokenPages.
if (!jrr.isMember(jss::result) ||
Expand Down
7 changes: 3 additions & 4 deletions src/test/app/Oracle_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//==============================================================================

#include <test/jtx/Oracle.h>
#include <xrpl/json/to_string.h>
#include <xrpl/protocol/jss.h>

namespace ripple {
Expand Down Expand Up @@ -482,10 +483,8 @@ struct Oracle_test : public beast::unit_test::suite
jvParams[field] = value;
jvParams[jss::binary] = false;
jvParams[jss::type] = jss::oracle;
Json::Value jrr = env.rpc(
"json",
"ledger_data",
boost::lexical_cast<std::string>(jvParams));
Json::Value jrr =
env.rpc("json", "ledger_data", to_string(jvParams));
BEAST_EXPECT(jrr[jss::result][jss::state].size() == 2);
};
verifyLedgerData(jss::ledger_index, index);
Expand Down
4 changes: 3 additions & 1 deletion src/test/json/json_value_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <xrpl/json/json_reader.h>
#include <xrpl/json/json_value.h>
#include <xrpl/json/json_writer.h>
#include <xrpl/json/to_string.h>

#include <algorithm>
#include <regex>
Expand Down Expand Up @@ -834,7 +835,8 @@ struct json_value_test : beast::unit_test::suite
BEAST_EXPECT(r.parse(s, j));
{
std::stringstream ss;
ss << j;
// UNDO
ss << pretty(j);
BEAST_EXPECT(countLines(ss.str()) > 1);
}
{
Expand Down
1 change: 1 addition & 0 deletions src/test/jtx/TestSuite.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define RIPPLE_BASICS_TESTSUITE_H_INCLUDED

#include <xrpl/beast/unit_test.h>
#include <xrpl/json/to_string.h>
#include <string>

namespace ripple {
Expand Down
2 changes: 1 addition & 1 deletion src/test/jtx/impl/Env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ Env::sign_and_submit(JTx const& jt, Json::Value params)
if (params.isNull())
{
// Use the command line interface
auto const jv = boost::lexical_cast<std::string>(jt.jv);
auto const jv = boost::lexical_cast<std::string>(to_string(jt.jv));
jr = rpc("submit", passphrase, jv);
}
else
Expand Down
6 changes: 4 additions & 2 deletions src/test/protocol/STObject_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,10 @@ class STObject_test : public beast::unit_test::suite

if (object1.getSerializer() == object2.getSerializer())
{
log << "O1: " << object1.getJson(JsonOptions::none) << '\n'
<< "O2: " << object2.getJson(JsonOptions::none) << std::endl;
log << "O1: " << to_string(object1.getJson(JsonOptions::none))
<< '\n'
<< "O2: " << to_string(object2.getJson(JsonOptions::none))
<< std::endl;
fail("STObject error 4");
}
else
Expand Down
10 changes: 6 additions & 4 deletions src/test/protocol/STTx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1645,8 +1645,9 @@ class STTx_test : public beast::unit_test::suite

if (copy != j)
{
log << "j=" << j.getJson(JsonOptions::none) << '\n'
<< "copy=" << copy.getJson(JsonOptions::none) << std::endl;
log << "j=" << to_string(j.getJson(JsonOptions::none)) << '\n'
<< "copy=" << to_string(copy.getJson(JsonOptions::none))
<< std::endl;
fail("Transaction fails serialize/deserialize test");
}
else
Expand All @@ -1660,8 +1661,9 @@ class STTx_test : public beast::unit_test::suite

if (STObject(j) != parsed.object)
{
log << "ORIG: " << j.getJson(JsonOptions::none) << '\n'
<< "BUILT " << parsed.object->getJson(JsonOptions::none)
log << "ORIG: " << to_string(j.getJson(JsonOptions::none)) << '\n'
<< "BUILT "
<< to_string(parsed.object->getJson(JsonOptions::none))
<< std::endl;
fail("Built a different transaction");
}
Expand Down
22 changes: 13 additions & 9 deletions src/test/rpc/AccountCurrencies_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class AccountCurrencies_test : public beast::unit_test::suite
auto const result = env.rpc(
"json",
"account_currencies",
boost::lexical_cast<std::string>(params))[jss::result];
boost::lexical_cast<std::string>(
to_string(params)))[jss::result];
BEAST_EXPECT(result[jss::error] == "invalidParams");
BEAST_EXPECT(result[jss::error_message] == "ledgerHashNotString");
}
Expand Down Expand Up @@ -108,7 +109,8 @@ class AccountCurrencies_test : public beast::unit_test::suite
auto const result = env.rpc(
"json",
"account_currencies",
boost::lexical_cast<std::string>(params))[jss::result];
boost::lexical_cast<std::string>(
to_string(params)))[jss::result];
BEAST_EXPECT(result[jss::error] == "actMalformed");
BEAST_EXPECT(result[jss::error_message] == "Account malformed.");
}
Expand All @@ -120,7 +122,8 @@ class AccountCurrencies_test : public beast::unit_test::suite
auto const result = env.rpc(
"json",
"account_currencies",
boost::lexical_cast<std::string>(params))[jss::result];
boost::lexical_cast<std::string>(
to_string(params)))[jss::result];
BEAST_EXPECT(result[jss::error] == "actMalformed");
BEAST_EXPECT(result[jss::error_message] == "Account malformed.");
}
Expand All @@ -131,7 +134,8 @@ class AccountCurrencies_test : public beast::unit_test::suite
auto const result = env.rpc(
"json",
"account_currencies",
boost::lexical_cast<std::string>(params))[jss::result];
boost::lexical_cast<std::string>(
to_string(params)))[jss::result];
BEAST_EXPECT(result[jss::error] == "actNotFound");
BEAST_EXPECT(result[jss::error_message] == "Account not found.");
}
Expand Down Expand Up @@ -162,7 +166,7 @@ class AccountCurrencies_test : public beast::unit_test::suite
auto result = env.rpc(
"json",
"account_currencies",
boost::lexical_cast<std::string>(params))[jss::result];
boost::lexical_cast<std::string>(to_string(params)))[jss::result];

auto arrayCheck =
[&result](
Expand Down Expand Up @@ -190,7 +194,7 @@ class AccountCurrencies_test : public beast::unit_test::suite
result = env.rpc(
"json",
"account_currencies",
boost::lexical_cast<std::string>(params))[jss::result];
boost::lexical_cast<std::string>(to_string(params)))[jss::result];
BEAST_EXPECT(arrayCheck(jss::receive_currencies, gwCurrencies));
BEAST_EXPECT(arrayCheck(jss::send_currencies, gwCurrencies));

Expand All @@ -204,7 +208,7 @@ class AccountCurrencies_test : public beast::unit_test::suite
result = env.rpc(
"json",
"account_currencies",
boost::lexical_cast<std::string>(params))[jss::result];
boost::lexical_cast<std::string>(to_string(params)))[jss::result];
BEAST_EXPECT(arrayCheck(jss::receive_currencies, gwCurrencies));
BEAST_EXPECT(arrayCheck(jss::send_currencies, gwCurrencies));
// clear the freeze
Expand All @@ -216,7 +220,7 @@ class AccountCurrencies_test : public beast::unit_test::suite
result = env.rpc(
"json",
"account_currencies",
boost::lexical_cast<std::string>(params))[jss::result];
boost::lexical_cast<std::string>(to_string(params)))[jss::result];
decltype(gwCurrencies) gwCurrenciesNoUSA(
gwCurrencies.begin() + 1, gwCurrencies.end());
BEAST_EXPECT(arrayCheck(jss::receive_currencies, gwCurrenciesNoUSA));
Expand All @@ -229,7 +233,7 @@ class AccountCurrencies_test : public beast::unit_test::suite
result = env.rpc(
"json",
"account_currencies",
boost::lexical_cast<std::string>(params))[jss::result];
boost::lexical_cast<std::string>(to_string(params)))[jss::result];
BEAST_EXPECT(arrayCheck(jss::receive_currencies, gwCurrencies));
BEAST_EXPECT(arrayCheck(jss::send_currencies, gwCurrenciesNoUSA));
}
Expand Down
18 changes: 6 additions & 12 deletions src/test/rpc/Feature_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,8 @@ class Feature_test : public beast::unit_test::suite
params[jss::feature] =
"1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCD"
"EF";
auto const result = env.rpc(
"json",
"feature",
boost::lexical_cast<std::string>(params))[jss::result];
auto const result =
env.rpc("json", "feature", to_string(params))[jss::result];
BEAST_EXPECTS(
result[jss::error] == "badFeature", result.toStyledString());
BEAST_EXPECT(
Expand All @@ -323,10 +321,8 @@ class Feature_test : public beast::unit_test::suite
"A7";
// invalid param
params[jss::vetoed] = true;
auto const result = env.rpc(
"json",
"feature",
boost::lexical_cast<std::string>(params))[jss::result];
auto const result =
env.rpc("json", "feature", to_string(params))[jss::result];
BEAST_EXPECTS(
result[jss::error] == "noPermission",
result[jss::error].asString());
Expand All @@ -341,10 +337,8 @@ class Feature_test : public beast::unit_test::suite
"37";
Json::Value params;
params[jss::feature] = feature;
auto const result = env.rpc(
"json",
"feature",
boost::lexical_cast<std::string>(params))[jss::result];
auto const result =
env.rpc("json", "feature", to_string(params))[jss::result];
BEAST_EXPECT(result.isMember(feature));
auto const amendmentResult = result[feature];
BEAST_EXPECT(amendmentResult[jss::enabled].asBool() == false);
Expand Down
19 changes: 10 additions & 9 deletions src/test/rpc/KeyGeneration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class WalletPropose_test : public ripple::TestSuite
BEAST_EXPECT(result.isMember(jss::key_type));

expectEquals(
result[jss::key_type],
params.isMember(jss::key_type) ? params[jss::key_type]
to_string(result[jss::key_type]),
params.isMember(jss::key_type) ? to_string(params[jss::key_type])
: "secp256k1");
BEAST_EXPECT(!result.isMember(jss::warning));

Expand All @@ -130,14 +130,15 @@ class WalletPropose_test : public ripple::TestSuite
Json::Value result = walletPropose(params);

BEAST_EXPECT(!contains_error(result));
expectEquals(result[jss::account_id], s.account_id);
expectEquals(result[jss::master_seed], s.master_seed);
expectEquals(result[jss::master_seed_hex], s.master_seed_hex);
expectEquals(result[jss::public_key], s.public_key);
expectEquals(result[jss::public_key_hex], s.public_key_hex);
expectEquals(to_string(result[jss::account_id]), s.account_id);
expectEquals(to_string(result[jss::master_seed]), s.master_seed);
expectEquals(
result[jss::key_type],
params.isMember(jss::key_type) ? params[jss::key_type]
to_string(result[jss::master_seed_hex]), s.master_seed_hex);
expectEquals(to_string(result[jss::public_key]), s.public_key);
expectEquals(to_string(result[jss::public_key_hex]), s.public_key_hex);
expectEquals(
to_string(result[jss::key_type]),
params.isMember(jss::key_type) ? to_string(params[jss::key_type])
: "secp256k1");
return result;
}
Expand Down
Loading

0 comments on commit 678eb3d

Please sign in to comment.