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
@@ -17,48 +17,52 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/protocol/UintTypes.h>
|
||||
#include <test/jtx/Account.h>
|
||||
#include <test/jtx/amount.h>
|
||||
#include <ripple/protocol/UintTypes.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
namespace jtx {
|
||||
|
||||
std::unordered_map<
|
||||
std::pair<std::string, KeyType>,
|
||||
Account, beast::uhash<>> Account::cache_;
|
||||
std::unordered_map<std::pair<std::string, KeyType>, Account, beast::uhash<>>
|
||||
Account::cache_;
|
||||
|
||||
Account const Account::master("master",
|
||||
generateKeyPair(KeyType::secp256k1,
|
||||
generateSeed("masterpassphrase")), Account::privateCtorTag{});
|
||||
Account const Account::master(
|
||||
"master",
|
||||
generateKeyPair(KeyType::secp256k1, generateSeed("masterpassphrase")),
|
||||
Account::privateCtorTag{});
|
||||
|
||||
Account::Account(std::string name,
|
||||
std::pair<PublicKey, SecretKey> const& keys, Account::privateCtorTag)
|
||||
Account::Account(
|
||||
std::string name,
|
||||
std::pair<PublicKey, SecretKey> const& keys,
|
||||
Account::privateCtorTag)
|
||||
: name_(std::move(name))
|
||||
, pk_ (keys.first)
|
||||
, sk_ (keys.second)
|
||||
, id_ (calcAccountID(pk_))
|
||||
, human_ (toBase58(id_))
|
||||
, pk_(keys.first)
|
||||
, sk_(keys.second)
|
||||
, id_(calcAccountID(pk_))
|
||||
, human_(toBase58(id_))
|
||||
{
|
||||
}
|
||||
|
||||
Account Account::fromCache(std::string name, KeyType type)
|
||||
Account
|
||||
Account::fromCache(std::string name, KeyType type)
|
||||
{
|
||||
auto const p = std::make_pair (name, type);
|
||||
auto const iter = cache_.find (p);
|
||||
if (iter != cache_.end ())
|
||||
auto const p = std::make_pair(name, type);
|
||||
auto const iter = cache_.find(p);
|
||||
if (iter != cache_.end())
|
||||
return iter->second;
|
||||
|
||||
auto const keys = generateKeyPair (type, generateSeed (name));
|
||||
auto r = cache_.emplace (std::piecewise_construct,
|
||||
std::forward_as_tuple (std::move (p)),
|
||||
std::forward_as_tuple (std::move (name), keys, privateCtorTag{}));
|
||||
auto const keys = generateKeyPair(type, generateSeed(name));
|
||||
auto r = cache_.emplace(
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(std::move(p)),
|
||||
std::forward_as_tuple(std::move(name), keys, privateCtorTag{}));
|
||||
return r.first->second;
|
||||
}
|
||||
|
||||
Account::Account (std::string name, KeyType type)
|
||||
: Account (fromCache (std::move (name), type))
|
||||
Account::Account(std::string name, KeyType type)
|
||||
: Account(fromCache(std::move(name), type))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -70,6 +74,6 @@ Account::operator[](std::string const& s) const
|
||||
return IOU(*this, currency);
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,23 +17,12 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/balance.h>
|
||||
#include <test/jtx/Env.h>
|
||||
#include <test/jtx/fee.h>
|
||||
#include <test/jtx/flags.h>
|
||||
#include <test/jtx/pay.h>
|
||||
#include <test/jtx/trust.h>
|
||||
#include <test/jtx/require.h>
|
||||
#include <test/jtx/seq.h>
|
||||
#include <test/jtx/sig.h>
|
||||
#include <test/jtx/utility.h>
|
||||
#include <test/jtx/JSONRPCClient.h>
|
||||
#include <ripple/app/ledger/LedgerMaster.h>
|
||||
#include <ripple/consensus/LedgerTiming.h>
|
||||
#include <ripple/app/misc/NetworkOPs.h>
|
||||
#include <ripple/app/misc/TxQ.h>
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/basics/Slice.h>
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/consensus/LedgerTiming.h>
|
||||
#include <ripple/json/to_string.h>
|
||||
#include <ripple/net/HTTPClient.h>
|
||||
#include <ripple/net/RPCCall.h>
|
||||
@@ -41,14 +30,25 @@
|
||||
#include <ripple/protocol/Feature.h>
|
||||
#include <ripple/protocol/HashPrefix.h>
|
||||
#include <ripple/protocol/Indexes.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/protocol/LedgerFormats.h>
|
||||
#include <ripple/protocol/Serializer.h>
|
||||
#include <ripple/protocol/SystemParameters.h>
|
||||
#include <ripple/protocol/TER.h>
|
||||
#include <ripple/protocol/TxFlags.h>
|
||||
#include <ripple/protocol/UintTypes.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <memory>
|
||||
#include <test/jtx/Env.h>
|
||||
#include <test/jtx/JSONRPCClient.h>
|
||||
#include <test/jtx/balance.h>
|
||||
#include <test/jtx/fee.h>
|
||||
#include <test/jtx/flags.h>
|
||||
#include <test/jtx/pay.h>
|
||||
#include <test/jtx/require.h>
|
||||
#include <test/jtx/seq.h>
|
||||
#include <test/jtx/sig.h>
|
||||
#include <test/jtx/trust.h>
|
||||
#include <test/jtx/utility.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -56,31 +56,28 @@ namespace jtx {
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Env::AppBundle::AppBundle(beast::unit_test::suite& suite,
|
||||
Env::AppBundle::AppBundle(
|
||||
beast::unit_test::suite& suite,
|
||||
std::unique_ptr<Config> config,
|
||||
std::unique_ptr<Logs> logs)
|
||||
: AppBundle()
|
||||
{
|
||||
using namespace beast::severities;
|
||||
// Use kFatal threshold to reduce noise from STObject.
|
||||
setDebugLogSink (std::make_unique<SuiteJournalSink>(
|
||||
"Debug", kFatal, suite));
|
||||
auto timeKeeper_ =
|
||||
std::make_unique<ManualTimeKeeper>();
|
||||
setDebugLogSink(std::make_unique<SuiteJournalSink>("Debug", kFatal, suite));
|
||||
auto timeKeeper_ = std::make_unique<ManualTimeKeeper>();
|
||||
timeKeeper = timeKeeper_.get();
|
||||
// Hack so we don't have to call Config::setup
|
||||
HTTPClient::initializeSSLContext(*config, debugLog());
|
||||
owned = make_Application(std::move(config),
|
||||
std::move(logs), std::move(timeKeeper_));
|
||||
owned = make_Application(
|
||||
std::move(config), std::move(logs), std::move(timeKeeper_));
|
||||
app = owned.get();
|
||||
app->logs().threshold(kError);
|
||||
if(! app->setup())
|
||||
Throw<std::runtime_error> ("Env::AppBundle: setup failed");
|
||||
timeKeeper->set(
|
||||
app->getLedgerMaster().getClosedLedger()->info().closeTime);
|
||||
if (!app->setup())
|
||||
Throw<std::runtime_error>("Env::AppBundle: setup failed");
|
||||
timeKeeper->set(app->getLedgerMaster().getClosedLedger()->info().closeTime);
|
||||
app->doStart(false /*don't start timers*/);
|
||||
thread = std::thread(
|
||||
[&](){ app->run(); });
|
||||
thread = std::thread([&]() { app->run(); });
|
||||
|
||||
client = makeJSONRPCClient(app->config());
|
||||
}
|
||||
@@ -99,7 +96,7 @@ Env::AppBundle::~AppBundle()
|
||||
thread.join();
|
||||
|
||||
// Remove the debugLogSink before the suite goes out of scope.
|
||||
setDebugLogSink (nullptr);
|
||||
setDebugLogSink(nullptr);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -111,7 +108,8 @@ Env::closed()
|
||||
}
|
||||
|
||||
void
|
||||
Env::close(NetClock::time_point closeTime,
|
||||
Env::close(
|
||||
NetClock::time_point closeTime,
|
||||
boost::optional<std::chrono::milliseconds> consensusDelay)
|
||||
{
|
||||
// Round up to next distinguishable value
|
||||
@@ -127,134 +125,123 @@ Env::close(NetClock::time_point closeTime,
|
||||
rpc("ledger_accept");
|
||||
// VFALCO No error check?
|
||||
}
|
||||
timeKeeper().set(
|
||||
closed()->info().closeTime);
|
||||
timeKeeper().set(closed()->info().closeTime);
|
||||
}
|
||||
|
||||
void
|
||||
Env::memoize (Account const& account)
|
||||
Env::memoize(Account const& account)
|
||||
{
|
||||
map_.emplace(account.id(), account);
|
||||
}
|
||||
|
||||
Account const&
|
||||
Env::lookup (AccountID const& id) const
|
||||
Env::lookup(AccountID const& id) const
|
||||
{
|
||||
auto const iter = map_.find(id);
|
||||
if (iter == map_.end())
|
||||
Throw<std::runtime_error> (
|
||||
"Env::lookup:: unknown account ID");
|
||||
Throw<std::runtime_error>("Env::lookup:: unknown account ID");
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
Account const&
|
||||
Env::lookup (std::string const& base58ID) const
|
||||
Env::lookup(std::string const& base58ID) const
|
||||
{
|
||||
auto const account =
|
||||
parseBase58<AccountID>(base58ID);
|
||||
if (! account)
|
||||
Throw<std::runtime_error>(
|
||||
"Env::lookup: invalid account ID");
|
||||
auto const account = parseBase58<AccountID>(base58ID);
|
||||
if (!account)
|
||||
Throw<std::runtime_error>("Env::lookup: invalid account ID");
|
||||
return lookup(*account);
|
||||
}
|
||||
|
||||
PrettyAmount
|
||||
Env::balance (Account const& account) const
|
||||
Env::balance(Account const& account) const
|
||||
{
|
||||
auto const sle = le(account);
|
||||
if (! sle)
|
||||
if (!sle)
|
||||
return XRP(0);
|
||||
return {
|
||||
sle->getFieldAmount(sfBalance),
|
||||
"" };
|
||||
return {sle->getFieldAmount(sfBalance), ""};
|
||||
}
|
||||
|
||||
PrettyAmount
|
||||
Env::balance (Account const& account,
|
||||
Issue const& issue) const
|
||||
Env::balance(Account const& account, Issue const& issue) const
|
||||
{
|
||||
if (isXRP(issue.currency))
|
||||
return balance(account);
|
||||
auto const sle = le(keylet::line(
|
||||
account.id(), issue));
|
||||
if (! sle)
|
||||
return { STAmount( issue, 0 ),
|
||||
account.name() };
|
||||
auto const sle = le(keylet::line(account.id(), issue));
|
||||
if (!sle)
|
||||
return {STAmount(issue, 0), account.name()};
|
||||
auto amount = sle->getFieldAmount(sfBalance);
|
||||
amount.setIssuer(issue.account);
|
||||
if (account.id() > issue.account)
|
||||
amount.negate();
|
||||
return { amount,
|
||||
lookup(issue.account).name() };
|
||||
return {amount, lookup(issue.account).name()};
|
||||
}
|
||||
|
||||
std::uint32_t
|
||||
Env::seq (Account const& account) const
|
||||
Env::seq(Account const& account) const
|
||||
{
|
||||
auto const sle = le(account);
|
||||
if (! sle)
|
||||
Throw<std::runtime_error> (
|
||||
"missing account root");
|
||||
if (!sle)
|
||||
Throw<std::runtime_error>("missing account root");
|
||||
return sle->getFieldU32(sfSequence);
|
||||
}
|
||||
|
||||
std::shared_ptr<SLE const>
|
||||
Env::le (Account const& account) const
|
||||
Env::le(Account const& account) const
|
||||
{
|
||||
return le(keylet::account(account.id()));
|
||||
}
|
||||
|
||||
std::shared_ptr<SLE const>
|
||||
Env::le (Keylet const& k) const
|
||||
Env::le(Keylet const& k) const
|
||||
{
|
||||
return current()->read(k);
|
||||
}
|
||||
|
||||
void
|
||||
Env::fund (bool setDefaultRipple,
|
||||
STAmount const& amount,
|
||||
Account const& account)
|
||||
Env::fund(bool setDefaultRipple, STAmount const& amount, Account const& account)
|
||||
{
|
||||
memoize(account);
|
||||
if (setDefaultRipple)
|
||||
{
|
||||
// VFALCO NOTE Is the fee formula correct?
|
||||
apply(pay(master, account, amount +
|
||||
drops(current()->fees().base)),
|
||||
jtx::seq(jtx::autofill),
|
||||
fee(jtx::autofill),
|
||||
sig(jtx::autofill));
|
||||
apply(fset(account, asfDefaultRipple),
|
||||
apply(
|
||||
pay(master, account, amount + drops(current()->fees().base)),
|
||||
jtx::seq(jtx::autofill),
|
||||
fee(jtx::autofill),
|
||||
sig(jtx::autofill));
|
||||
fee(jtx::autofill),
|
||||
sig(jtx::autofill));
|
||||
apply(
|
||||
fset(account, asfDefaultRipple),
|
||||
jtx::seq(jtx::autofill),
|
||||
fee(jtx::autofill),
|
||||
sig(jtx::autofill));
|
||||
require(flags(account, asfDefaultRipple));
|
||||
}
|
||||
else
|
||||
{
|
||||
apply(pay(master, account, amount),
|
||||
apply(
|
||||
pay(master, account, amount),
|
||||
jtx::seq(jtx::autofill),
|
||||
fee(jtx::autofill),
|
||||
sig(jtx::autofill));
|
||||
fee(jtx::autofill),
|
||||
sig(jtx::autofill));
|
||||
require(nflags(account, asfDefaultRipple));
|
||||
}
|
||||
require(jtx::balance(account, amount));
|
||||
}
|
||||
|
||||
void
|
||||
Env::trust (STAmount const& amount,
|
||||
Account const& account)
|
||||
Env::trust(STAmount const& amount, Account const& account)
|
||||
{
|
||||
auto const start = balance(account);
|
||||
apply(jtx::trust(account, amount),
|
||||
apply(
|
||||
jtx::trust(account, amount),
|
||||
jtx::seq(jtx::autofill),
|
||||
fee(jtx::autofill),
|
||||
sig(jtx::autofill));
|
||||
apply(pay(master, account,
|
||||
drops(current()->fees().base)),
|
||||
jtx::seq(jtx::autofill),
|
||||
fee(jtx::autofill),
|
||||
sig(jtx::autofill));
|
||||
fee(jtx::autofill),
|
||||
sig(jtx::autofill));
|
||||
apply(
|
||||
pay(master, account, drops(current()->fees().base)),
|
||||
jtx::seq(jtx::autofill),
|
||||
fee(jtx::autofill),
|
||||
sig(jtx::autofill));
|
||||
test.expect(balance(account) == start);
|
||||
}
|
||||
|
||||
@@ -264,15 +251,14 @@ Env::parseResult(Json::Value const& jr)
|
||||
TER ter;
|
||||
if (jr.isObject() && jr.isMember(jss::result) &&
|
||||
jr[jss::result].isMember(jss::engine_result_code))
|
||||
ter = TER::fromInt (jr[jss::result][jss::engine_result_code].asInt());
|
||||
ter = TER::fromInt(jr[jss::result][jss::engine_result_code].asInt());
|
||||
else
|
||||
ter = temINVALID;
|
||||
return std::make_pair(ter,
|
||||
isTesSuccess(ter) || isTecClaim(ter));
|
||||
return std::make_pair(ter, isTesSuccess(ter) || isTecClaim(ter));
|
||||
}
|
||||
|
||||
void
|
||||
Env::submit (JTx const& jt)
|
||||
Env::submit(JTx const& jt)
|
||||
{
|
||||
bool didApply;
|
||||
if (jt.stx)
|
||||
@@ -299,8 +285,7 @@ Env::sign_and_submit(JTx const& jt, Json::Value params)
|
||||
{
|
||||
bool didApply;
|
||||
|
||||
auto const account =
|
||||
lookup(jt.jv[jss::Account].asString());
|
||||
auto const account = lookup(jt.jv[jss::Account].asString());
|
||||
auto const& passphrase = account.name();
|
||||
|
||||
Json::Value jr;
|
||||
@@ -315,10 +300,8 @@ Env::sign_and_submit(JTx const& jt, Json::Value params)
|
||||
// Use the provided parameters, and go straight
|
||||
// to the (RPC) client.
|
||||
assert(params.isObject());
|
||||
if (!params.isMember(jss::secret) &&
|
||||
!params.isMember(jss::key_type) &&
|
||||
!params.isMember(jss::seed) &&
|
||||
!params.isMember(jss::seed_hex) &&
|
||||
if (!params.isMember(jss::secret) && !params.isMember(jss::key_type) &&
|
||||
!params.isMember(jss::seed) && !params.isMember(jss::seed_hex) &&
|
||||
!params.isMember(jss::passphrase))
|
||||
{
|
||||
params[jss::secret] = passphrase;
|
||||
@@ -326,8 +309,7 @@ Env::sign_and_submit(JTx const& jt, Json::Value params)
|
||||
params[jss::tx_json] = jt.jv;
|
||||
jr = client().invoke("submit", params);
|
||||
}
|
||||
txid_.SetHex(
|
||||
jr[jss::result][jss::tx_json][jss::hash].asString());
|
||||
txid_.SetHex(jr[jss::result][jss::tx_json][jss::hash].asString());
|
||||
|
||||
std::tie(ter_, didApply) = parseResult(jr);
|
||||
|
||||
@@ -337,11 +319,11 @@ Env::sign_and_submit(JTx const& jt, Json::Value params)
|
||||
void
|
||||
Env::postconditions(JTx const& jt, TER ter, bool didApply)
|
||||
{
|
||||
if (jt.ter && ! test.expect(ter == *jt.ter,
|
||||
"apply: " + transToken(ter) +
|
||||
" (" + transHuman(ter) + ") != " +
|
||||
transToken(*jt.ter) + " (" +
|
||||
transHuman(*jt.ter) + ")"))
|
||||
if (jt.ter &&
|
||||
!test.expect(
|
||||
ter == *jt.ter,
|
||||
"apply: " + transToken(ter) + " (" + transHuman(ter) + ") != " +
|
||||
transToken(*jt.ter) + " (" + transHuman(*jt.ter) + ")"))
|
||||
{
|
||||
test.log << pretty(jt.jv) << std::endl;
|
||||
// Don't check postconditions if
|
||||
@@ -373,38 +355,35 @@ Env::tx() const
|
||||
}
|
||||
|
||||
void
|
||||
Env::autofill_sig (JTx& jt)
|
||||
Env::autofill_sig(JTx& jt)
|
||||
{
|
||||
auto& jv = jt.jv;
|
||||
if (jt.signer)
|
||||
return jt.signer(*this, jt);
|
||||
if (! jt.fill_sig)
|
||||
if (!jt.fill_sig)
|
||||
return;
|
||||
auto const account =
|
||||
lookup(jv[jss::Account].asString());
|
||||
auto const account = lookup(jv[jss::Account].asString());
|
||||
if (!app().checkSigs())
|
||||
{
|
||||
jv[jss::SigningPubKey] =
|
||||
strHex(account.pk().slice());
|
||||
jv[jss::SigningPubKey] = strHex(account.pk().slice());
|
||||
// dummy sig otherwise STTx is invalid
|
||||
jv[jss::TxnSignature] = "00";
|
||||
return;
|
||||
}
|
||||
auto const ar = le(account);
|
||||
if (ar && ar->isFieldPresent(sfRegularKey))
|
||||
jtx::sign(jv, lookup(
|
||||
ar->getAccountID(sfRegularKey)));
|
||||
jtx::sign(jv, lookup(ar->getAccountID(sfRegularKey)));
|
||||
else
|
||||
jtx::sign(jv, account);
|
||||
}
|
||||
|
||||
void
|
||||
Env::autofill (JTx& jt)
|
||||
Env::autofill(JTx& jt)
|
||||
{
|
||||
auto& jv = jt.jv;
|
||||
if(jt.fill_fee)
|
||||
if (jt.fill_fee)
|
||||
jtx::fill_fee(jv, *current());
|
||||
if(jt.fill_seq)
|
||||
if (jt.fill_seq)
|
||||
jtx::fill_seq(jv, *current());
|
||||
// Must come last
|
||||
try
|
||||
@@ -413,14 +392,13 @@ Env::autofill (JTx& jt)
|
||||
}
|
||||
catch (parse_error const&)
|
||||
{
|
||||
test.log << "parse failed:\n" <<
|
||||
pretty(jv) << std::endl;
|
||||
test.log << "parse failed:\n" << pretty(jv) << std::endl;
|
||||
Rethrow();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<STTx const>
|
||||
Env::st (JTx const& jt)
|
||||
Env::st(JTx const& jt)
|
||||
{
|
||||
// The parse must succeed, since we
|
||||
// generated the JSON ourselves.
|
||||
@@ -429,10 +407,9 @@ Env::st (JTx const& jt)
|
||||
{
|
||||
obj = jtx::parse(jt.jv);
|
||||
}
|
||||
catch(jtx::parse_error const&)
|
||||
catch (jtx::parse_error const&)
|
||||
{
|
||||
test.log << "Exception: parse_error\n" <<
|
||||
pretty(jt.jv) << std::endl;
|
||||
test.log << "Exception: parse_error\n" << pretty(jt.jv) << std::endl;
|
||||
Rethrow();
|
||||
}
|
||||
|
||||
@@ -440,14 +417,15 @@ Env::st (JTx const& jt)
|
||||
{
|
||||
return sterilize(STTx{std::move(*obj)});
|
||||
}
|
||||
catch(std::exception const&)
|
||||
catch (std::exception const&)
|
||||
{
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Json::Value
|
||||
Env::do_rpc(std::vector<std::string> const& args,
|
||||
Env::do_rpc(
|
||||
std::vector<std::string> const& args,
|
||||
std::unordered_map<std::string, std::string> const& headers)
|
||||
{
|
||||
return rpcClient(args, app().config(), app().logs(), headers).second;
|
||||
@@ -461,7 +439,7 @@ Env::enableFeature(uint256 const feature)
|
||||
app().config().features.insert(feature);
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // namespace jtx
|
||||
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -16,52 +16,51 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
#include <test/jtx/JSONRPCClient.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <ripple/json/to_string.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/server/Port.h>
|
||||
#include <boost/beast/http/message.hpp>
|
||||
#include <boost/beast/http/dynamic_body.hpp>
|
||||
#include <boost/beast/http/string_body.hpp>
|
||||
#include <boost/beast/http/read.hpp>
|
||||
#include <boost/beast/http/write.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/beast/http/dynamic_body.hpp>
|
||||
#include <boost/beast/http/message.hpp>
|
||||
#include <boost/beast/http/read.hpp>
|
||||
#include <boost/beast/http/string_body.hpp>
|
||||
#include <boost/beast/http/write.hpp>
|
||||
#include <string>
|
||||
#include <test/jtx/JSONRPCClient.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
|
||||
class JSONRPCClient : public AbstractClient
|
||||
{
|
||||
static
|
||||
boost::asio::ip::tcp::endpoint
|
||||
static boost::asio::ip::tcp::endpoint
|
||||
getEndpoint(BasicConfig const& cfg)
|
||||
{
|
||||
auto& log = std::cerr;
|
||||
ParsedPort common;
|
||||
parse_Port (common, cfg["server"], log);
|
||||
parse_Port(common, cfg["server"], log);
|
||||
for (auto const& name : cfg.section("server").values())
|
||||
{
|
||||
if (! cfg.exists(name))
|
||||
if (!cfg.exists(name))
|
||||
continue;
|
||||
ParsedPort pp;
|
||||
parse_Port(pp, cfg[name], log);
|
||||
if(pp.protocol.count("http") == 0)
|
||||
if (pp.protocol.count("http") == 0)
|
||||
continue;
|
||||
using namespace boost::asio::ip;
|
||||
if(pp.ip && pp.ip->is_unspecified())
|
||||
*pp.ip = pp.ip->is_v6() ? address{address_v6::loopback()} : address{address_v4::loopback()};
|
||||
return { *pp.ip, *pp.port };
|
||||
if (pp.ip && pp.ip->is_unspecified())
|
||||
*pp.ip = pp.ip->is_v6() ? address{address_v6::loopback()}
|
||||
: address{address_v4::loopback()};
|
||||
return {*pp.ip, *pp.port};
|
||||
}
|
||||
Throw<std::runtime_error>("Missing HTTP port");
|
||||
return {}; // Silence compiler control paths return value warning
|
||||
return {}; // Silence compiler control paths return value warning
|
||||
}
|
||||
|
||||
template <class ConstBufferSequence>
|
||||
static
|
||||
std::string
|
||||
buffer_string (ConstBufferSequence const& b)
|
||||
static std::string
|
||||
buffer_string(ConstBufferSequence const& b)
|
||||
{
|
||||
using namespace boost::asio;
|
||||
std::string s;
|
||||
@@ -78,19 +77,16 @@ class JSONRPCClient : public AbstractClient
|
||||
unsigned rpc_version_;
|
||||
|
||||
public:
|
||||
explicit
|
||||
JSONRPCClient(Config const& cfg, unsigned rpc_version)
|
||||
: ep_(getEndpoint(cfg))
|
||||
, stream_(ios_)
|
||||
, rpc_version_(rpc_version)
|
||||
explicit JSONRPCClient(Config const& cfg, unsigned rpc_version)
|
||||
: ep_(getEndpoint(cfg)), stream_(ios_), rpc_version_(rpc_version)
|
||||
{
|
||||
stream_.connect(ep_);
|
||||
}
|
||||
|
||||
~JSONRPCClient() override
|
||||
{
|
||||
//stream_.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
|
||||
//stream_.close();
|
||||
// stream_.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
|
||||
// stream_.close();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -100,8 +96,7 @@ public:
|
||||
result
|
||||
*/
|
||||
Json::Value
|
||||
invoke(std::string const& cmd,
|
||||
Json::Value const& params) override
|
||||
invoke(std::string const& cmd, Json::Value const& params) override
|
||||
{
|
||||
using namespace boost::beast::http;
|
||||
using namespace boost::asio;
|
||||
@@ -122,7 +117,7 @@ public:
|
||||
jr[jss::ripplerpc] = "2.0";
|
||||
jr[jss::id] = 5;
|
||||
}
|
||||
if(params)
|
||||
if (params)
|
||||
{
|
||||
Json::Value& ja = jr[jss::params] = Json::arrayValue;
|
||||
ja.append(params);
|
||||
@@ -138,14 +133,15 @@ public:
|
||||
Json::Reader jr;
|
||||
Json::Value jv;
|
||||
jr.parse(buffer_string(res.body().data()), jv);
|
||||
if(jv["result"].isMember("error"))
|
||||
if (jv["result"].isMember("error"))
|
||||
jv["error"] = jv["result"]["error"];
|
||||
if(jv["result"].isMember("status"))
|
||||
if (jv["result"].isMember("status"))
|
||||
jv["status"] = jv["result"]["status"];
|
||||
return jv;
|
||||
}
|
||||
|
||||
unsigned version() const override
|
||||
unsigned
|
||||
version() const override
|
||||
{
|
||||
return rpc_version_;
|
||||
}
|
||||
@@ -157,5 +153,5 @@ makeJSONRPCClient(Config const& cfg, unsigned rpc_version)
|
||||
return std::make_unique<JSONRPCClient>(cfg, rpc_version);
|
||||
}
|
||||
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -24,36 +24,31 @@ namespace test {
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
ManualTimeKeeper::ManualTimeKeeper()
|
||||
: closeOffset_ {}
|
||||
, now_ (0s)
|
||||
ManualTimeKeeper::ManualTimeKeeper() : closeOffset_{}, now_(0s)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ManualTimeKeeper::run (std::vector<std::string> const& servers)
|
||||
ManualTimeKeeper::run(std::vector<std::string> const& servers)
|
||||
{
|
||||
}
|
||||
|
||||
auto
|
||||
ManualTimeKeeper::now() const ->
|
||||
time_point
|
||||
ManualTimeKeeper::now() const -> time_point
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
return now_;
|
||||
}
|
||||
|
||||
|
||||
auto
|
||||
ManualTimeKeeper::closeTime() const ->
|
||||
time_point
|
||||
ManualTimeKeeper::closeTime() const -> time_point
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
return now_ + closeOffset_;
|
||||
}
|
||||
|
||||
void
|
||||
ManualTimeKeeper::adjustCloseTime(
|
||||
std::chrono::duration<std::int32_t> amount)
|
||||
ManualTimeKeeper::adjustCloseTime(std::chrono::duration<std::int32_t> amount)
|
||||
{
|
||||
// Copied from TimeKeeper::adjustCloseTime
|
||||
using namespace std::chrono;
|
||||
@@ -83,21 +78,18 @@ ManualTimeKeeper::closeOffset() const
|
||||
}
|
||||
|
||||
void
|
||||
ManualTimeKeeper::set (time_point now)
|
||||
ManualTimeKeeper::set(time_point now)
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
now_ = now;
|
||||
}
|
||||
|
||||
auto
|
||||
ManualTimeKeeper::adjust(
|
||||
std::chrono::system_clock::time_point when) ->
|
||||
time_point
|
||||
ManualTimeKeeper::adjust(std::chrono::system_clock::time_point when)
|
||||
-> time_point
|
||||
{
|
||||
return time_point(
|
||||
std::chrono::duration_cast<duration>(
|
||||
when.time_since_epoch() -
|
||||
days(10957)));
|
||||
return time_point(std::chrono::duration_cast<duration>(
|
||||
when.time_since_epoch() - days(10957)));
|
||||
}
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/WSClient.h>
|
||||
#include <test/jtx.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <ripple/json/to_string.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/server/Port.h>
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
#include <test/jtx.h>
|
||||
#include <test/jtx/WSClient.h>
|
||||
|
||||
#include <condition_variable>
|
||||
#include <string>
|
||||
@@ -45,42 +45,39 @@ class WSClientImpl : public WSClient
|
||||
{
|
||||
Json::Value jv;
|
||||
|
||||
explicit
|
||||
msg(Json::Value&& jv_)
|
||||
: jv(jv_)
|
||||
explicit msg(Json::Value&& jv_) : jv(jv_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
static
|
||||
boost::asio::ip::tcp::endpoint
|
||||
static boost::asio::ip::tcp::endpoint
|
||||
getEndpoint(BasicConfig const& cfg, bool v2)
|
||||
{
|
||||
auto& log = std::cerr;
|
||||
ParsedPort common;
|
||||
parse_Port (common, cfg["server"], log);
|
||||
parse_Port(common, cfg["server"], log);
|
||||
auto const ps = v2 ? "ws2" : "ws";
|
||||
for (auto const& name : cfg.section("server").values())
|
||||
{
|
||||
if (! cfg.exists(name))
|
||||
if (!cfg.exists(name))
|
||||
continue;
|
||||
ParsedPort pp;
|
||||
parse_Port(pp, cfg[name], log);
|
||||
if(pp.protocol.count(ps) == 0)
|
||||
if (pp.protocol.count(ps) == 0)
|
||||
continue;
|
||||
using namespace boost::asio::ip;
|
||||
if(pp.ip && pp.ip->is_unspecified())
|
||||
*pp.ip = pp.ip->is_v6() ? address{address_v6::loopback()} : address{address_v4::loopback()};
|
||||
return { *pp.ip, *pp.port };
|
||||
if (pp.ip && pp.ip->is_unspecified())
|
||||
*pp.ip = pp.ip->is_v6() ? address{address_v6::loopback()}
|
||||
: address{address_v4::loopback()};
|
||||
return {*pp.ip, *pp.port};
|
||||
}
|
||||
Throw<std::runtime_error>("Missing WebSocket port");
|
||||
return {}; // Silence compiler control paths return value warning
|
||||
return {}; // Silence compiler control paths return value warning
|
||||
}
|
||||
|
||||
template <class ConstBuffers>
|
||||
static
|
||||
std::string
|
||||
buffer_string (ConstBuffers const& b)
|
||||
static std::string
|
||||
buffer_string(ConstBuffers const& b)
|
||||
{
|
||||
using boost::asio::buffer;
|
||||
using boost::asio::buffer_size;
|
||||
@@ -91,8 +88,7 @@ class WSClientImpl : public WSClient
|
||||
}
|
||||
|
||||
boost::asio::io_service ios_;
|
||||
boost::optional<
|
||||
boost::asio::io_service::work> work_;
|
||||
boost::optional<boost::asio::io_service::work> work_;
|
||||
boost::asio::io_service::strand strand_;
|
||||
std::thread thread_;
|
||||
boost::asio::ip::tcp::socket stream_;
|
||||
@@ -129,11 +125,14 @@ class WSClientImpl : public WSClient
|
||||
}
|
||||
|
||||
public:
|
||||
WSClientImpl(Config const& cfg, bool v2, unsigned rpc_version,
|
||||
WSClientImpl(
|
||||
Config const& cfg,
|
||||
bool v2,
|
||||
unsigned rpc_version,
|
||||
std::unordered_map<std::string, std::string> const& headers = {})
|
||||
: work_(ios_)
|
||||
, strand_(ios_)
|
||||
, thread_([&]{ ios_.run(); })
|
||||
, thread_([&] { ios_.run(); })
|
||||
, stream_(ios_)
|
||||
, ws_(stream_)
|
||||
, rpc_version_(rpc_version)
|
||||
@@ -142,18 +141,19 @@ public:
|
||||
{
|
||||
auto const ep = getEndpoint(cfg, v2);
|
||||
stream_.connect(ep);
|
||||
ws_.handshake_ex(ep.address().to_string() +
|
||||
":" + std::to_string(ep.port()), "/",
|
||||
[&](boost::beast::websocket::request_type &req)
|
||||
{
|
||||
ws_.handshake_ex(
|
||||
ep.address().to_string() + ":" + std::to_string(ep.port()),
|
||||
"/",
|
||||
[&](boost::beast::websocket::request_type& req) {
|
||||
for (auto const& h : headers)
|
||||
req.set(h.first, h.second);
|
||||
});
|
||||
ws_.async_read(rb_,
|
||||
strand_.wrap(std::bind(&WSClientImpl::on_read_msg,
|
||||
this, std::placeholders::_1)));
|
||||
ws_.async_read(
|
||||
rb_,
|
||||
strand_.wrap(std::bind(
|
||||
&WSClientImpl::on_read_msg, this, std::placeholders::_1)));
|
||||
}
|
||||
catch(std::exception&)
|
||||
catch (std::exception&)
|
||||
{
|
||||
cleanup();
|
||||
Rethrow();
|
||||
@@ -166,16 +166,15 @@ public:
|
||||
}
|
||||
|
||||
Json::Value
|
||||
invoke(std::string const& cmd,
|
||||
Json::Value const& params) override
|
||||
invoke(std::string const& cmd, Json::Value const& params) override
|
||||
{
|
||||
using boost::asio::buffer;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
{
|
||||
Json::Value jp;
|
||||
if(params)
|
||||
jp = params;
|
||||
if (params)
|
||||
jp = params;
|
||||
if (rpc_version_ == 2)
|
||||
{
|
||||
jp[jss::method] = cmd;
|
||||
@@ -189,17 +188,14 @@ public:
|
||||
ws_.write_some(true, buffer(s));
|
||||
}
|
||||
|
||||
auto jv = findMsg(5s,
|
||||
[&](Json::Value const& jval)
|
||||
{
|
||||
return jval[jss::type] == jss::response;
|
||||
});
|
||||
auto jv = findMsg(5s, [&](Json::Value const& jval) {
|
||||
return jval[jss::type] == jss::response;
|
||||
});
|
||||
if (jv)
|
||||
{
|
||||
// Normalize JSON output
|
||||
jv->removeMember(jss::type);
|
||||
if ((*jv).isMember(jss::status) &&
|
||||
(*jv)[jss::status] == jss::error)
|
||||
if ((*jv).isMember(jss::status) && (*jv)[jss::status] == jss::error)
|
||||
{
|
||||
Json::Value ret;
|
||||
ret[jss::result] = *jv;
|
||||
@@ -208,10 +204,8 @@ public:
|
||||
ret[jss::status] = jss::error;
|
||||
return ret;
|
||||
}
|
||||
if ((*jv).isMember(jss::status) &&
|
||||
(*jv).isMember(jss::result))
|
||||
(*jv)[jss::result][jss::status] =
|
||||
(*jv)[jss::status];
|
||||
if ((*jv).isMember(jss::status) && (*jv).isMember(jss::result))
|
||||
(*jv)[jss::result][jss::status] = (*jv)[jss::status];
|
||||
return *jv;
|
||||
}
|
||||
return {};
|
||||
@@ -223,8 +217,7 @@ public:
|
||||
std::shared_ptr<msg> m;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_);
|
||||
if(! cv_.wait_for(lock, timeout,
|
||||
[&]{ return ! msgs_.empty(); }))
|
||||
if (!cv_.wait_for(lock, timeout, [&] { return !msgs_.empty(); }))
|
||||
return boost::none;
|
||||
m = std::move(msgs_.back());
|
||||
msgs_.pop_back();
|
||||
@@ -233,17 +226,15 @@ public:
|
||||
}
|
||||
|
||||
boost::optional<Json::Value>
|
||||
findMsg(std::chrono::milliseconds const& timeout,
|
||||
findMsg(
|
||||
std::chrono::milliseconds const& timeout,
|
||||
std::function<bool(Json::Value const&)> pred) override
|
||||
{
|
||||
std::shared_ptr<msg> m;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_);
|
||||
if(! cv_.wait_for(lock, timeout,
|
||||
[&]
|
||||
{
|
||||
for (auto it = msgs_.begin();
|
||||
it != msgs_.end(); ++it)
|
||||
if (!cv_.wait_for(lock, timeout, [&] {
|
||||
for (auto it = msgs_.begin(); it != msgs_.end(); ++it)
|
||||
{
|
||||
if (pred((*it)->jv))
|
||||
{
|
||||
@@ -261,7 +252,8 @@ public:
|
||||
return std::move(m->jv);
|
||||
}
|
||||
|
||||
unsigned version() const override
|
||||
unsigned
|
||||
version() const override
|
||||
{
|
||||
return rpc_version_;
|
||||
}
|
||||
@@ -270,10 +262,10 @@ private:
|
||||
void
|
||||
on_read_msg(error_code const& ec)
|
||||
{
|
||||
if(ec)
|
||||
if (ec)
|
||||
{
|
||||
if(ec == boost::beast::websocket::error::closed)
|
||||
peerClosed_ = true;
|
||||
if (ec == boost::beast::websocket::error::closed)
|
||||
peerClosed_ = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -281,16 +273,16 @@ private:
|
||||
Json::Reader jr;
|
||||
jr.parse(buffer_string(rb_.data()), jv);
|
||||
rb_.consume(rb_.size());
|
||||
auto m = std::make_shared<msg>(
|
||||
std::move(jv));
|
||||
auto m = std::make_shared<msg>(std::move(jv));
|
||||
{
|
||||
std::lock_guard lock(m_);
|
||||
msgs_.push_front(m);
|
||||
cv_.notify_all();
|
||||
}
|
||||
ws_.async_read(rb_, strand_.wrap(
|
||||
std::bind(&WSClientImpl::on_read_msg,
|
||||
this, std::placeholders::_1)));
|
||||
ws_.async_read(
|
||||
rb_,
|
||||
strand_.wrap(std::bind(
|
||||
&WSClientImpl::on_read_msg, this, std::placeholders::_1)));
|
||||
}
|
||||
|
||||
// Called when the read op terminates
|
||||
@@ -304,11 +296,14 @@ private:
|
||||
};
|
||||
|
||||
std::unique_ptr<WSClient>
|
||||
makeWSClient(Config const& cfg, bool v2, unsigned rpc_version,
|
||||
makeWSClient(
|
||||
Config const& cfg,
|
||||
bool v2,
|
||||
unsigned rpc_version,
|
||||
std::unordered_map<std::string, std::string> const& headers)
|
||||
{
|
||||
return std::make_unique<WSClientImpl>(cfg, v2, rpc_version, headers);
|
||||
}
|
||||
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -30,6 +30,6 @@ account_txn_id::operator()(Env&, JTx& jt) const
|
||||
jt["AccountTxnID"] = strHex(hash_);
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/acctdelete.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/acctdelete.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -26,7 +26,7 @@ namespace jtx {
|
||||
|
||||
// Delete account. If successful transfer remaining XRP to dest.
|
||||
Json::Value
|
||||
acctdelete (jtx::Account const& account, jtx::Account const& dest)
|
||||
acctdelete(jtx::Account const& account, jtx::Account const& dest)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[sfAccount.jsonName] = account.human();
|
||||
@@ -35,6 +35,6 @@ acctdelete (jtx::Account const& account, jtx::Account const& dest)
|
||||
return jv;
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/basics/safe_cast.h>
|
||||
#include <test/jtx/Account.h>
|
||||
#include <test/jtx/amount.h>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <test/jtx/Account.h>
|
||||
#include <test/jtx/amount.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -49,12 +49,11 @@ operator<<(std::ostream&& os,
|
||||
|
||||
PrettyAmount::operator AnyAmount() const
|
||||
{
|
||||
return { amount_ };
|
||||
return {amount_};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static
|
||||
std::string
|
||||
static std::string
|
||||
to_places(const T d, std::uint8_t places)
|
||||
{
|
||||
assert(places <= std::numeric_limits<T>::digits10);
|
||||
@@ -71,15 +70,14 @@ to_places(const T d, std::uint8_t places)
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<< (std::ostream& os,
|
||||
PrettyAmount const& amount)
|
||||
operator<<(std::ostream& os, PrettyAmount const& amount)
|
||||
{
|
||||
if (amount.value().native())
|
||||
{
|
||||
// measure in hundredths
|
||||
auto const c = dropsPerXRP.drops() / 100;
|
||||
auto const n = amount.value().mantissa();
|
||||
if(n < c)
|
||||
if (n < c)
|
||||
{
|
||||
if (amount.value().negative())
|
||||
os << "-" << n << " drops";
|
||||
@@ -87,8 +85,7 @@ operator<< (std::ostream& os,
|
||||
os << n << " drops";
|
||||
return os;
|
||||
}
|
||||
auto const d = double(n) /
|
||||
dropsPerXRP.drops();
|
||||
auto const d = double(n) / dropsPerXRP.drops();
|
||||
if (amount.value().negative())
|
||||
os << "-";
|
||||
|
||||
@@ -96,45 +93,38 @@ operator<< (std::ostream& os,
|
||||
}
|
||||
else
|
||||
{
|
||||
os <<
|
||||
amount.value().getText() << "/" <<
|
||||
to_string(amount.value().issue().currency) <<
|
||||
"(" << amount.name() << ")";
|
||||
os << amount.value().getText() << "/"
|
||||
<< to_string(amount.value().issue().currency) << "(" << amount.name()
|
||||
<< ")";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
XRP_t const XRP {};
|
||||
XRP_t const XRP{};
|
||||
|
||||
PrettyAmount
|
||||
IOU::operator()(epsilon_t) const
|
||||
PrettyAmount IOU::operator()(epsilon_t) const
|
||||
{
|
||||
return { STAmount(issue(), 1, -81),
|
||||
account.name() };
|
||||
return {STAmount(issue(), 1, -81), account.name()};
|
||||
}
|
||||
|
||||
PrettyAmount
|
||||
IOU::operator()(detail::epsilon_multiple m) const
|
||||
{
|
||||
return { STAmount(issue(),
|
||||
safe_cast<std::uint64_t>(m.n), -81),
|
||||
account.name() };
|
||||
return {
|
||||
STAmount(issue(), safe_cast<std::uint64_t>(m.n), -81), account.name()};
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os,
|
||||
IOU const& iou)
|
||||
operator<<(std::ostream& os, IOU const& iou)
|
||||
{
|
||||
os <<
|
||||
to_string(iou.issue().currency) <<
|
||||
"(" << iou.account.name() << ")";
|
||||
os << to_string(iou.issue().currency) << "(" << iou.account.name() << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
any_t const any { };
|
||||
any_t const any{};
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -31,36 +31,31 @@ balance::operator()(Env& env) const
|
||||
auto const sle = env.le(account_);
|
||||
if (none_)
|
||||
{
|
||||
env.test.expect(! sle);
|
||||
env.test.expect(!sle);
|
||||
}
|
||||
else if (env.test.expect(sle))
|
||||
{
|
||||
env.test.expect(sle->getFieldAmount(
|
||||
sfBalance) == value_);
|
||||
env.test.expect(sle->getFieldAmount(sfBalance) == value_);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto const sle = env.le(keylet::line(
|
||||
account_.id(), value_.issue()));
|
||||
auto const sle = env.le(keylet::line(account_.id(), value_.issue()));
|
||||
if (none_)
|
||||
{
|
||||
env.test.expect(! sle);
|
||||
env.test.expect(!sle);
|
||||
}
|
||||
else if (env.test.expect(sle))
|
||||
{
|
||||
auto amount =
|
||||
sle->getFieldAmount(sfBalance);
|
||||
amount.setIssuer(
|
||||
value_.issue().account);
|
||||
if (account_.id() >
|
||||
value_.issue().account)
|
||||
auto amount = sle->getFieldAmount(sfBalance);
|
||||
amount.setIssuer(value_.issue().account);
|
||||
if (account_.id() > value_.issue().account)
|
||||
amount.negate();
|
||||
env.test.expect(amount == value_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/check.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/protocol/TxFlags.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/check.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -29,8 +29,10 @@ namespace check {
|
||||
|
||||
// Create a check.
|
||||
Json::Value
|
||||
create (jtx::Account const& account,
|
||||
jtx::Account const& dest, STAmount const& sendMax)
|
||||
create(
|
||||
jtx::Account const& account,
|
||||
jtx::Account const& dest,
|
||||
STAmount const& sendMax)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[sfAccount.jsonName] = account.human();
|
||||
@@ -43,13 +45,12 @@ create (jtx::Account const& account,
|
||||
|
||||
// Cash a check requiring that a specific amount be delivered.
|
||||
Json::Value
|
||||
cash (jtx::Account const& dest,
|
||||
uint256 const& checkId, STAmount const& amount)
|
||||
cash(jtx::Account const& dest, uint256 const& checkId, STAmount const& amount)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[sfAccount.jsonName] = dest.human();
|
||||
jv[sfAmount.jsonName] = amount.getJson(JsonOptions::none);
|
||||
jv[sfCheckID.jsonName] = to_string (checkId);
|
||||
jv[sfAmount.jsonName] = amount.getJson(JsonOptions::none);
|
||||
jv[sfCheckID.jsonName] = to_string(checkId);
|
||||
jv[sfTransactionType.jsonName] = jss::CheckCash;
|
||||
jv[sfFlags.jsonName] = tfUniversal;
|
||||
return jv;
|
||||
@@ -57,13 +58,15 @@ cash (jtx::Account const& dest,
|
||||
|
||||
// Cash a check requiring that at least a minimum amount be delivered.
|
||||
Json::Value
|
||||
cash (jtx::Account const& dest,
|
||||
uint256 const& checkId, DeliverMin const& atLeast)
|
||||
cash(
|
||||
jtx::Account const& dest,
|
||||
uint256 const& checkId,
|
||||
DeliverMin const& atLeast)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[sfAccount.jsonName] = dest.human();
|
||||
jv[sfDeliverMin.jsonName] = atLeast.value.getJson(JsonOptions::none);
|
||||
jv[sfCheckID.jsonName] = to_string (checkId);
|
||||
jv[sfDeliverMin.jsonName] = atLeast.value.getJson(JsonOptions::none);
|
||||
jv[sfCheckID.jsonName] = to_string(checkId);
|
||||
jv[sfTransactionType.jsonName] = jss::CheckCash;
|
||||
jv[sfFlags.jsonName] = tfUniversal;
|
||||
return jv;
|
||||
@@ -71,18 +74,18 @@ cash (jtx::Account const& dest,
|
||||
|
||||
// Cancel a check.
|
||||
Json::Value
|
||||
cancel (jtx::Account const& dest, uint256 const& checkId)
|
||||
cancel(jtx::Account const& dest, uint256 const& checkId)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[sfAccount.jsonName] = dest.human();
|
||||
jv[sfCheckID.jsonName] = to_string (checkId);
|
||||
jv[sfCheckID.jsonName] = to_string(checkId);
|
||||
jv[sfTransactionType.jsonName] = jss::CheckCancel;
|
||||
jv[sfFlags.jsonName] = tfUniversal;
|
||||
return jv;
|
||||
}
|
||||
|
||||
} // check
|
||||
} // namespace check
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/delivermin.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/delivermin.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -30,6 +30,6 @@ delivermin::operator()(Env& env, JTx& jt) const
|
||||
jt.jv[jss::DeliverMin] = amount_.getJson(JsonOptions::none);
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/deposit.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/deposit.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -28,7 +28,7 @@ namespace deposit {
|
||||
|
||||
// Add DepositPreauth.
|
||||
Json::Value
|
||||
auth (jtx::Account const& account, jtx::Account const& auth)
|
||||
auth(jtx::Account const& account, jtx::Account const& auth)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[sfAccount.jsonName] = account.human();
|
||||
@@ -39,7 +39,7 @@ auth (jtx::Account const& account, jtx::Account const& auth)
|
||||
|
||||
// Remove DepositPreauth.
|
||||
Json::Value
|
||||
unauth (jtx::Account const& account, jtx::Account const& unauth)
|
||||
unauth(jtx::Account const& account, jtx::Account const& unauth)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[sfAccount.jsonName] = account.human();
|
||||
@@ -48,8 +48,8 @@ unauth (jtx::Account const& account, jtx::Account const& unauth)
|
||||
return jv;
|
||||
}
|
||||
|
||||
} // deposit
|
||||
} // namespace deposit
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,31 +17,32 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/envconfig.h>
|
||||
#include <test/jtx/Env.h>
|
||||
#include <ripple/core/ConfigSections.h>
|
||||
#include <test/jtx/Env.h>
|
||||
#include <test/jtx/envconfig.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
|
||||
int port_base = 8000;
|
||||
void incPorts()
|
||||
void
|
||||
incPorts()
|
||||
{
|
||||
port_base += 3;
|
||||
}
|
||||
|
||||
std::atomic<bool> envUseIPv4 {false};
|
||||
std::atomic<bool> envUseIPv4{false};
|
||||
|
||||
void
|
||||
setupConfigForUnitTests (Config& cfg)
|
||||
setupConfigForUnitTests(Config& cfg)
|
||||
{
|
||||
std::string const port_peer = std::to_string(port_base);
|
||||
std::string port_rpc = std::to_string(port_base + 1);
|
||||
std::string port_ws = std::to_string(port_base + 2);
|
||||
|
||||
cfg.overwrite (ConfigSection::nodeDatabase (), "type", "memory");
|
||||
cfg.overwrite (ConfigSection::nodeDatabase (), "path", "main");
|
||||
cfg.deprecatedClearSection (ConfigSection::importNodeDatabase ());
|
||||
cfg.overwrite(ConfigSection::nodeDatabase(), "type", "memory");
|
||||
cfg.overwrite(ConfigSection::nodeDatabase(), "path", "main");
|
||||
cfg.deprecatedClearSection(ConfigSection::importNodeDatabase());
|
||||
cfg.legacy("database_path", "");
|
||||
cfg.setupControl(true, true, true);
|
||||
cfg["server"].append("port_peer");
|
||||
@@ -68,8 +69,8 @@ namespace jtx {
|
||||
std::unique_ptr<Config>
|
||||
no_admin(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
(*cfg)["port_rpc"].set("admin","");
|
||||
(*cfg)["port_ws"].set("admin","");
|
||||
(*cfg)["port_rpc"].set("admin", "");
|
||||
(*cfg)["port_ws"].set("admin", "");
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@@ -77,7 +78,7 @@ std::unique_ptr<Config>
|
||||
secure_gateway(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
(*cfg)["port_rpc"].set("admin", "");
|
||||
(*cfg)["port_ws"].set("admin","");
|
||||
(*cfg)["port_ws"].set("admin", "");
|
||||
(*cfg)["port_rpc"].set("secure_gateway", getEnvLocalhostAddr());
|
||||
return cfg;
|
||||
}
|
||||
@@ -88,8 +89,8 @@ std::unique_ptr<Config>
|
||||
validator(std::unique_ptr<Config> cfg, std::string const& seed)
|
||||
{
|
||||
// If the config has valid validation keys then we run as a validator.
|
||||
cfg->section(SECTION_VALIDATION_SEED).append(
|
||||
std::vector<std::string>{seed.empty() ? defaultseed : seed});
|
||||
cfg->section(SECTION_VALIDATION_SEED)
|
||||
.append(std::vector<std::string>{seed.empty() ? defaultseed : seed});
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@@ -102,7 +103,7 @@ port_increment(std::unique_ptr<Config> cfg, int increment)
|
||||
auto const port = s.get<std::int32_t>("port");
|
||||
if (port)
|
||||
{
|
||||
s.set ("port", std::to_string(*port + increment));
|
||||
s.set("port", std::to_string(*port + increment));
|
||||
}
|
||||
}
|
||||
return cfg;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/fee.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/fee.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -27,14 +27,13 @@ namespace jtx {
|
||||
void
|
||||
fee::operator()(Env&, JTx& jt) const
|
||||
{
|
||||
if (! manual_)
|
||||
if (!manual_)
|
||||
return;
|
||||
jt.fill_fee = false;
|
||||
if (amount_)
|
||||
jt[jss::Fee] =
|
||||
amount_->getJson(JsonOptions::none);
|
||||
jt[jss::Fee] = amount_->getJson(JsonOptions::none);
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,16 +17,15 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/flags.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/flags.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
namespace jtx {
|
||||
|
||||
Json::Value
|
||||
fset (Account const& account,
|
||||
std::uint32_t on, std::uint32_t off)
|
||||
fset(Account const& account, std::uint32_t on, std::uint32_t off)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[jss::Account] = account.human();
|
||||
@@ -43,8 +42,7 @@ flags::operator()(Env& env) const
|
||||
{
|
||||
auto const sle = env.le(account_);
|
||||
if (sle->isFieldPresent(sfFlags))
|
||||
env.test.expect((sle->getFieldU32(sfFlags) &
|
||||
mask_) == mask_);
|
||||
env.test.expect((sle->getFieldU32(sfFlags) & mask_) == mask_);
|
||||
else
|
||||
env.test.expect(mask_ == 0);
|
||||
}
|
||||
@@ -54,12 +52,11 @@ nflags::operator()(Env& env) const
|
||||
{
|
||||
auto const sle = env.le(account_);
|
||||
if (sle->isFieldPresent(sfFlags))
|
||||
env.test.expect((sle->getFieldU32(sfFlags) &
|
||||
mask_) == 0);
|
||||
env.test.expect((sle->getFieldU32(sfFlags) & mask_) == 0);
|
||||
else
|
||||
env.test.pass();
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -31,6 +31,6 @@ invoice_id::operator()(Env&, JTx& jt) const
|
||||
jt["InvoiceID"] = strHex(hash_);
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <test/jtx/jtx_json.h>
|
||||
#include <test/jtx/utility.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <ripple/basics/contract.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -28,16 +28,15 @@ namespace jtx {
|
||||
|
||||
json::json(std::string const& s)
|
||||
{
|
||||
if (! Json::Reader().parse(s, jv_))
|
||||
Throw<parse_error> ("bad json");
|
||||
|
||||
if (!Json::Reader().parse(s, jv_))
|
||||
Throw<parse_error>("bad json");
|
||||
}
|
||||
|
||||
json::json (char const* s)
|
||||
: json(std::string(s)){}
|
||||
json::json(char const* s) : json(std::string(s))
|
||||
{
|
||||
}
|
||||
|
||||
json::json (Json::Value jv)
|
||||
: jv_ (std::move (jv))
|
||||
json::json(Json::Value jv) : jv_(std::move(jv))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -45,11 +44,10 @@ void
|
||||
json::operator()(Env&, JTx& jt) const
|
||||
{
|
||||
auto& jv = jt.jv;
|
||||
for (auto iter = jv_.begin();
|
||||
iter != jv_.end(); ++iter)
|
||||
for (auto iter = jv_.begin(); iter != jv_.end(); ++iter)
|
||||
jv[iter.key().asString()] = *iter;
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,21 +17,19 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/last_ledger_sequence.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/last_ledger_sequence.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
namespace jtx {
|
||||
|
||||
|
||||
void
|
||||
last_ledger_seq::operator()(Env&, JTx& jt) const
|
||||
{
|
||||
jt["LastLedgerSequence"] = num_;
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/memo.h>
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/memo.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -100,7 +100,6 @@ memontype::operator()(Env&, JTx& jt) const
|
||||
m["MemoFormat"] = strHex(format_);
|
||||
}
|
||||
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,29 +17,30 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/multisign.h>
|
||||
#include <test/jtx/utility.h>
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/protocol/HashPrefix.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/protocol/Sign.h>
|
||||
#include <ripple/protocol/UintTypes.h>
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/multisign.h>
|
||||
#include <test/jtx/utility.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
namespace jtx {
|
||||
|
||||
Json::Value
|
||||
signers (Account const& account,
|
||||
signers(
|
||||
Account const& account,
|
||||
std::uint32_t quorum,
|
||||
std::vector<signer> const& v)
|
||||
std::vector<signer> const& v)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[jss::Account] = account.human();
|
||||
jv[jss::TransactionType] = jss::SignerListSet;
|
||||
jv[sfSignerQuorum.getJsonName()] = quorum;
|
||||
auto& ja = jv[sfSignerEntries.getJsonName()];
|
||||
for(std::size_t i = 0; i < v.size(); ++i)
|
||||
for (std::size_t i = 0; i < v.size(); ++i)
|
||||
{
|
||||
auto const& e = v[i];
|
||||
auto& je = ja[i][sfSignerEntry.getJsonName()];
|
||||
@@ -50,7 +51,7 @@ signers (Account const& account,
|
||||
}
|
||||
|
||||
Json::Value
|
||||
signers (Account const& account, none_t)
|
||||
signers(Account const& account, none_t)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[jss::Account] = account.human();
|
||||
@@ -61,13 +62,13 @@ signers (Account const& account, none_t)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
msig::msig (std::vector<msig::Reg> signers_)
|
||||
: signers(std::move(signers_))
|
||||
msig::msig(std::vector<msig::Reg> signers_) : signers(std::move(signers_))
|
||||
{
|
||||
// Signatures must be applied in sorted order.
|
||||
std::sort(signers.begin(), signers.end(),
|
||||
[](msig::Reg const& lhs, msig::Reg const& rhs)
|
||||
{
|
||||
std::sort(
|
||||
signers.begin(),
|
||||
signers.end(),
|
||||
[](msig::Reg const& lhs, msig::Reg const& rhs) {
|
||||
return lhs.acct.id() < rhs.acct.id();
|
||||
});
|
||||
}
|
||||
@@ -76,36 +77,35 @@ void
|
||||
msig::operator()(Env& env, JTx& jt) const
|
||||
{
|
||||
auto const mySigners = signers;
|
||||
jt.signer = [mySigners, &env](Env&, JTx& jtx)
|
||||
{
|
||||
jt.signer = [mySigners, &env](Env&, JTx& jtx) {
|
||||
jtx[sfSigningPubKey.getJsonName()] = "";
|
||||
boost::optional<STObject> st;
|
||||
try
|
||||
{
|
||||
st = parse(jtx.jv);
|
||||
}
|
||||
catch(parse_error const&)
|
||||
catch (parse_error const&)
|
||||
{
|
||||
env.test.log << pretty(jtx.jv) << std::endl;
|
||||
Rethrow();
|
||||
}
|
||||
auto& js = jtx[sfSigners.getJsonName()];
|
||||
for(std::size_t i = 0; i < mySigners.size(); ++i)
|
||||
for (std::size_t i = 0; i < mySigners.size(); ++i)
|
||||
{
|
||||
auto const& e = mySigners[i];
|
||||
auto& jo = js[i][sfSigner.getJsonName()];
|
||||
jo[jss::Account] = e.acct.human();
|
||||
jo[jss::SigningPubKey] = strHex(e.sig.pk().slice());
|
||||
|
||||
Serializer ss {buildMultiSigningData (*st, e.acct.id())};
|
||||
auto const sig = ripple::sign (
|
||||
Serializer ss{buildMultiSigningData(*st, e.acct.id())};
|
||||
auto const sig = ripple::sign(
|
||||
*publicKeyType(e.sig.pk().slice()), e.sig.sk(), ss.slice());
|
||||
jo[sfTxnSignature.getJsonName()] =
|
||||
strHex(Slice{ sig.data(), sig.size() });
|
||||
strHex(Slice{sig.data(), sig.size()});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,16 +17,19 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/offer.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/offer.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
namespace jtx {
|
||||
|
||||
Json::Value
|
||||
offer (Account const& account,
|
||||
STAmount const& in, STAmount const& out, std::uint32_t flags)
|
||||
offer(
|
||||
Account const& account,
|
||||
STAmount const& in,
|
||||
STAmount const& out,
|
||||
std::uint32_t flags)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[jss::Account] = account.human();
|
||||
@@ -39,7 +42,7 @@ offer (Account const& account,
|
||||
}
|
||||
|
||||
Json::Value
|
||||
offer_cancel (Account const& account, std::uint32_t offerSeq)
|
||||
offer_cancel(Account const& account, std::uint32_t offerSeq)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[jss::Account] = account.human();
|
||||
@@ -48,6 +51,6 @@ offer_cancel (Account const& account, std::uint32_t offerSeq)
|
||||
return jv;
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -26,14 +26,11 @@ namespace jtx {
|
||||
namespace detail {
|
||||
|
||||
std::uint32_t
|
||||
owned_count_of(ReadView const& view,
|
||||
AccountID const& id,
|
||||
LedgerEntryType type)
|
||||
owned_count_of(ReadView const& view, AccountID const& id, LedgerEntryType type)
|
||||
{
|
||||
std::uint32_t count = 0;
|
||||
forEachItem (view, id,
|
||||
[&count, type](std::shared_ptr<SLE const> const& sle)
|
||||
{
|
||||
forEachItem(
|
||||
view, id, [&count, type](std::shared_ptr<SLE const> const& sle) {
|
||||
if (sle->getType() == type)
|
||||
++count;
|
||||
});
|
||||
@@ -41,25 +38,23 @@ owned_count_of(ReadView const& view,
|
||||
}
|
||||
|
||||
void
|
||||
owned_count_helper(Env& env,
|
||||
owned_count_helper(
|
||||
Env& env,
|
||||
AccountID const& id,
|
||||
LedgerEntryType type,
|
||||
std::uint32_t value)
|
||||
LedgerEntryType type,
|
||||
std::uint32_t value)
|
||||
{
|
||||
env.test.expect(owned_count_of(
|
||||
*env.current(), id, type) == value);
|
||||
env.test.expect(owned_count_of(*env.current(), id, type) == value);
|
||||
}
|
||||
|
||||
} // detail
|
||||
} // namespace detail
|
||||
|
||||
void
|
||||
owners::operator()(Env& env) const
|
||||
{
|
||||
env.test.expect(env.le(
|
||||
account_)->getFieldU32(sfOwnerCount) ==
|
||||
value_);
|
||||
env.test.expect(env.le(account_)->getFieldU32(sfOwnerCount) == value_);
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/app/paths/Pathfinder.h>
|
||||
#include <test/jtx/paths.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/paths.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -29,27 +29,28 @@ void
|
||||
paths::operator()(Env& env, JTx& jt) const
|
||||
{
|
||||
auto& jv = jt.jv;
|
||||
auto const from = env.lookup(
|
||||
jv[jss::Account].asString());
|
||||
auto const to = env.lookup(
|
||||
jv[jss::Destination].asString());
|
||||
auto const amount = amountFromJson(
|
||||
sfAmount, jv[jss::Amount]);
|
||||
Pathfinder pf (
|
||||
auto const from = env.lookup(jv[jss::Account].asString());
|
||||
auto const to = env.lookup(jv[jss::Destination].asString());
|
||||
auto const amount = amountFromJson(sfAmount, jv[jss::Amount]);
|
||||
Pathfinder pf(
|
||||
std::make_shared<RippleLineCache>(env.current()),
|
||||
from, to, in_.currency, in_.account,
|
||||
amount, boost::none, env.app());
|
||||
if (! pf.findPaths(depth_))
|
||||
from,
|
||||
to,
|
||||
in_.currency,
|
||||
in_.account,
|
||||
amount,
|
||||
boost::none,
|
||||
env.app());
|
||||
if (!pf.findPaths(depth_))
|
||||
return;
|
||||
|
||||
STPath fp;
|
||||
pf.computePathRanks (limit_);
|
||||
auto const found = pf.getBestPaths(
|
||||
limit_, fp, {}, in_.account);
|
||||
pf.computePathRanks(limit_);
|
||||
auto const found = pf.getBestPaths(limit_, fp, {}, in_.account);
|
||||
|
||||
// VFALCO TODO API to allow caller to examine the STPathSet
|
||||
// VFALCO isDefault should be renamed to empty()
|
||||
if (! found.isDefault())
|
||||
if (!found.isDefault())
|
||||
jv[jss::Paths] = found.getJson(JsonOptions::none);
|
||||
}
|
||||
|
||||
@@ -90,6 +91,6 @@ path::operator()(Env& env, JTx& jt) const
|
||||
jt.jv["Paths"].append(jv_);
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,18 +17,16 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/pay.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/protocol/TxFlags.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/pay.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
namespace jtx {
|
||||
|
||||
Json::Value
|
||||
pay (Account const& account,
|
||||
Account const& to,
|
||||
AnyAmount amount)
|
||||
pay(Account const& account, Account const& to, AnyAmount amount)
|
||||
{
|
||||
amount.to(to);
|
||||
Json::Value jv;
|
||||
@@ -40,6 +38,6 @@ pay (Account const& account,
|
||||
return jv;
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,28 +17,28 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/quality.h>
|
||||
#include <ripple/protocol/SField.h>
|
||||
#include <ripple/protocol/Quality.h>
|
||||
#include <ripple/protocol/SField.h>
|
||||
#include <test/jtx/quality.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
namespace jtx {
|
||||
|
||||
qualityInPercent::qualityInPercent (double percent)
|
||||
: qIn_ (static_cast<std::uint32_t>((percent / 100) * QUALITY_ONE))
|
||||
qualityInPercent::qualityInPercent(double percent)
|
||||
: qIn_(static_cast<std::uint32_t>((percent / 100) * QUALITY_ONE))
|
||||
{
|
||||
assert (percent <= 400 && percent >= 0);
|
||||
assert(percent <= 400 && percent >= 0);
|
||||
}
|
||||
|
||||
qualityOutPercent::qualityOutPercent (double percent)
|
||||
: qOut_ (static_cast<std::uint32_t>((percent / 100) * QUALITY_ONE))
|
||||
qualityOutPercent::qualityOutPercent(double percent)
|
||||
: qOut_(static_cast<std::uint32_t>((percent / 100) * QUALITY_ONE))
|
||||
{
|
||||
assert (percent <= 400 && percent >= 0);
|
||||
assert(percent <= 400 && percent >= 0);
|
||||
}
|
||||
|
||||
static void
|
||||
insertQualityIntoJtx (SField const& field, std::uint32_t value, JTx& jt)
|
||||
insertQualityIntoJtx(SField const& field, std::uint32_t value, JTx& jt)
|
||||
{
|
||||
jt.jv[field.jsonName] = value;
|
||||
}
|
||||
@@ -46,27 +46,27 @@ insertQualityIntoJtx (SField const& field, std::uint32_t value, JTx& jt)
|
||||
void
|
||||
qualityIn::operator()(Env&, JTx& jt) const
|
||||
{
|
||||
insertQualityIntoJtx (sfQualityIn, qIn_, jt);
|
||||
insertQualityIntoJtx(sfQualityIn, qIn_, jt);
|
||||
}
|
||||
|
||||
void
|
||||
qualityInPercent::operator()(Env&, JTx& jt) const
|
||||
{
|
||||
insertQualityIntoJtx (sfQualityIn, qIn_, jt);
|
||||
insertQualityIntoJtx(sfQualityIn, qIn_, jt);
|
||||
}
|
||||
|
||||
void
|
||||
qualityOut::operator()(Env&, JTx& jt) const
|
||||
{
|
||||
insertQualityIntoJtx (sfQualityOut, qOut_, jt);
|
||||
insertQualityIntoJtx(sfQualityOut, qOut_, jt);
|
||||
}
|
||||
|
||||
void
|
||||
qualityOutPercent::operator()(Env&, JTx& jt) const
|
||||
{
|
||||
insertQualityIntoJtx (sfQualityOut, qOut_, jt);
|
||||
insertQualityIntoJtx(sfQualityOut, qOut_, jt);
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,29 +17,27 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/rate.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <stdexcept>
|
||||
#include <test/jtx/rate.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
namespace jtx {
|
||||
|
||||
Json::Value
|
||||
rate (Account const& account, double multiplier)
|
||||
rate(Account const& account, double multiplier)
|
||||
{
|
||||
if (multiplier > 4)
|
||||
Throw<std::runtime_error> (
|
||||
"rate multiplier out of range");
|
||||
Throw<std::runtime_error>("rate multiplier out of range");
|
||||
Json::Value jv;
|
||||
jv[jss::Account] = account.human();
|
||||
jv[jss::TransferRate] = std::uint32_t(
|
||||
1000000000 * multiplier);
|
||||
jv[jss::TransferRate] = std::uint32_t(1000000000 * multiplier);
|
||||
jv[jss::TransactionType] = jss::AccountSet;
|
||||
return jv;
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,16 +17,15 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/regkey.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/regkey.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
namespace jtx {
|
||||
|
||||
Json::Value
|
||||
regkey (Account const& account,
|
||||
disabled_t)
|
||||
regkey(Account const& account, disabled_t)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[jss::Account] = account.human();
|
||||
@@ -35,8 +34,7 @@ regkey (Account const& account,
|
||||
}
|
||||
|
||||
Json::Value
|
||||
regkey (Account const& account,
|
||||
Account const& signer)
|
||||
regkey(Account const& account, Account const& signer)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[jss::Account] = account.human();
|
||||
@@ -45,6 +43,6 @@ regkey (Account const& account,
|
||||
return jv;
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/sendmax.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/sendmax.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -30,6 +30,6 @@ sendmax::operator()(Env& env, JTx& jt) const
|
||||
jt.jv[jss::SendMax] = amount_.getJson(JsonOptions::none);
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/seq.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/seq.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -27,13 +27,13 @@ namespace jtx {
|
||||
void
|
||||
seq::operator()(Env&, JTx& jt) const
|
||||
{
|
||||
if (! manual_)
|
||||
if (!manual_)
|
||||
return;
|
||||
jt.fill_seq = false;
|
||||
if (num_)
|
||||
jt[jss::Sequence] = *num_;
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -27,20 +27,17 @@ namespace jtx {
|
||||
void
|
||||
sig::operator()(Env&, JTx& jt) const
|
||||
{
|
||||
if (! manual_)
|
||||
if (!manual_)
|
||||
return;
|
||||
jt.fill_sig = false;
|
||||
if(account_)
|
||||
if (account_)
|
||||
{
|
||||
// VFALCO Inefficient pre-C++14
|
||||
auto const account = *account_;
|
||||
jt.signer = [account](Env&, JTx& jtx)
|
||||
{
|
||||
jtx::sign(jtx.jv, account);
|
||||
};
|
||||
jt.signer = [account](Env&, JTx& jtx) { jtx::sign(jtx.jv, account); };
|
||||
}
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/tag.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/tag.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -36,6 +36,6 @@ stag::operator()(Env&, JTx& jt) const
|
||||
jt.jv["SourceTag"] = value_;
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/ticket.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/ticket.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -29,9 +29,10 @@ namespace ticket {
|
||||
namespace detail {
|
||||
|
||||
Json::Value
|
||||
create (Account const& account,
|
||||
create(
|
||||
Account const& account,
|
||||
boost::optional<Account> const& target,
|
||||
boost::optional<std::uint32_t> const& expire)
|
||||
boost::optional<std::uint32_t> const& expire)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[jss::Account] = account.human();
|
||||
@@ -43,10 +44,10 @@ create (Account const& account,
|
||||
return jv;
|
||||
}
|
||||
|
||||
} // detail
|
||||
} // namespace detail
|
||||
|
||||
Json::Value
|
||||
cancel(Account const& account, std::string const & ticketId)
|
||||
cancel(Account const& account, std::string const& ticketId)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[jss::TransactionType] = jss::TicketCancel;
|
||||
@@ -55,8 +56,8 @@ cancel(Account const& account, std::string const & ticketId)
|
||||
return jv;
|
||||
}
|
||||
|
||||
} // ticket
|
||||
} // namespace ticket
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,23 +17,20 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/trust.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <stdexcept>
|
||||
#include <test/jtx/trust.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
namespace jtx {
|
||||
|
||||
Json::Value
|
||||
trust (Account const& account,
|
||||
STAmount const& amount,
|
||||
std::uint32_t flags)
|
||||
trust(Account const& account, STAmount const& amount, std::uint32_t flags)
|
||||
{
|
||||
if (isXRP(amount))
|
||||
Throw<std::runtime_error> (
|
||||
"trust() requires IOU");
|
||||
Throw<std::runtime_error>("trust() requires IOU");
|
||||
Json::Value jv;
|
||||
jv[jss::Account] = account.human();
|
||||
jv[jss::LimitAmount] = amount.getJson(JsonOptions::none);
|
||||
@@ -43,14 +40,14 @@ trust (Account const& account,
|
||||
}
|
||||
|
||||
Json::Value
|
||||
trust (Account const& account,
|
||||
trust(
|
||||
Account const& account,
|
||||
STAmount const& amount,
|
||||
Account const& peer,
|
||||
std::uint32_t flags)
|
||||
{
|
||||
if (isXRP(amount))
|
||||
Throw<std::runtime_error> (
|
||||
"trust() requires IOU");
|
||||
Throw<std::runtime_error>("trust() requires IOU");
|
||||
Json::Value jv;
|
||||
jv[jss::Account] = account.human();
|
||||
{
|
||||
@@ -62,7 +59,6 @@ trust (Account const& account,
|
||||
return jv;
|
||||
}
|
||||
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/txflags.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/txflags.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -27,10 +27,9 @@ namespace jtx {
|
||||
void
|
||||
txflags::operator()(Env&, JTx& jt) const
|
||||
{
|
||||
jt[jss::Flags] =
|
||||
v_ /*| tfUniversal*/;
|
||||
jt[jss::Flags] = v_ /*| tfUniversal*/;
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,76 +17,62 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/utility.h>
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
#include <ripple/protocol/HashPrefix.h>
|
||||
#include <ripple/protocol/Indexes.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/protocol/STParsedJSON.h>
|
||||
#include <ripple/protocol/UintTypes.h>
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <cstring>
|
||||
#include <test/jtx/utility.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
namespace jtx {
|
||||
|
||||
STObject
|
||||
parse (Json::Value const& jv)
|
||||
parse(Json::Value const& jv)
|
||||
{
|
||||
STParsedJSONObject p("tx_json", jv);
|
||||
if (! p.object)
|
||||
Throw<parse_error> (
|
||||
rpcErrorString(p.error));
|
||||
if (!p.object)
|
||||
Throw<parse_error>(rpcErrorString(p.error));
|
||||
return std::move(*p.object);
|
||||
}
|
||||
|
||||
void
|
||||
sign (Json::Value& jv,
|
||||
Account const& account)
|
||||
sign(Json::Value& jv, Account const& account)
|
||||
{
|
||||
jv[jss::SigningPubKey] =
|
||||
strHex(account.pk().slice());
|
||||
jv[jss::SigningPubKey] = strHex(account.pk().slice());
|
||||
Serializer ss;
|
||||
ss.add32 (HashPrefix::txSign);
|
||||
ss.add32(HashPrefix::txSign);
|
||||
parse(jv).addWithoutSigningFields(ss);
|
||||
auto const sig = ripple::sign(
|
||||
account.pk(), account.sk(), ss.slice());
|
||||
jv[jss::TxnSignature] =
|
||||
strHex(Slice{ sig.data(), sig.size() });
|
||||
auto const sig = ripple::sign(account.pk(), account.sk(), ss.slice());
|
||||
jv[jss::TxnSignature] = strHex(Slice{sig.data(), sig.size()});
|
||||
}
|
||||
|
||||
void
|
||||
fill_fee (Json::Value& jv,
|
||||
ReadView const& view)
|
||||
fill_fee(Json::Value& jv, ReadView const& view)
|
||||
{
|
||||
if (jv.isMember(jss::Fee))
|
||||
return;
|
||||
jv[jss::Fee] = to_string(
|
||||
view.fees().base);
|
||||
jv[jss::Fee] = to_string(view.fees().base);
|
||||
}
|
||||
|
||||
void
|
||||
fill_seq (Json::Value& jv,
|
||||
ReadView const& view)
|
||||
fill_seq(Json::Value& jv, ReadView const& view)
|
||||
{
|
||||
if (jv.isMember(jss::Sequence))
|
||||
return;
|
||||
auto const account =
|
||||
parseBase58<AccountID>(
|
||||
jv[jss::Account].asString());
|
||||
if (! account)
|
||||
Throw<parse_error> (
|
||||
"unexpected invalid Account");
|
||||
auto const ar = view.read(
|
||||
keylet::account(*account));
|
||||
if (! ar)
|
||||
Throw<parse_error> (
|
||||
"unexpected missing account root");
|
||||
jv[jss::Sequence] =
|
||||
ar->getFieldU32(sfSequence);
|
||||
auto const account = parseBase58<AccountID>(jv[jss::Account].asString());
|
||||
if (!account)
|
||||
Throw<parse_error>("unexpected invalid Account");
|
||||
auto const ar = view.read(keylet::account(*account));
|
||||
if (!ar)
|
||||
Throw<parse_error>("unexpected missing account root");
|
||||
jv[jss::Sequence] = ar->getFieldU32(sfSequence);
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
Reference in New Issue
Block a user