mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Format first-party source according to .clang-format
This commit is contained in:
committed by
manojsdoshi
parent
65dfc5d19e
commit
50760c6935
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx.h>
|
||||
#include <test/jtx/envconfig.h>
|
||||
#include <ripple/app/tx/apply.h>
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <ripple/protocol/Feature.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx.h>
|
||||
#include <test/jtx/envconfig.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -29,7 +29,8 @@ namespace test {
|
||||
struct Regression_test : public beast::unit_test::suite
|
||||
{
|
||||
// OfferCreate, then OfferCreate with cancel
|
||||
void testOffer1()
|
||||
void
|
||||
testOffer1()
|
||||
{
|
||||
using namespace jtx;
|
||||
Env env(*this);
|
||||
@@ -37,12 +38,15 @@ struct Regression_test : public beast::unit_test::suite
|
||||
auto const USD = gw["USD"];
|
||||
env.fund(XRP(10000), "alice", gw);
|
||||
env(offer("alice", USD(10), XRP(10)), require(owners("alice", 1)));
|
||||
env(offer("alice", USD(20), XRP(10)), json(R"raw(
|
||||
env(offer("alice", USD(20), XRP(10)),
|
||||
json(R"raw(
|
||||
{ "OfferSequence" : 4 }
|
||||
)raw"), require(owners("alice", 1)));
|
||||
)raw"),
|
||||
require(owners("alice", 1)));
|
||||
}
|
||||
|
||||
void testLowBalanceDestroy()
|
||||
void
|
||||
testLowBalanceDestroy()
|
||||
{
|
||||
testcase("Account balance < fee destroys correct amount of XRP");
|
||||
using namespace jtx;
|
||||
@@ -53,8 +57,10 @@ struct Regression_test : public beast::unit_test::suite
|
||||
// be reproduced against an open ledger. Make a local
|
||||
// closed ledger and work with it directly.
|
||||
auto closed = std::make_shared<Ledger>(
|
||||
create_genesis, env.app().config(),
|
||||
std::vector<uint256>{}, env.app().family());
|
||||
create_genesis,
|
||||
env.app().config(),
|
||||
std::vector<uint256>{},
|
||||
env.app().family());
|
||||
auto expectedDrops = INITIAL_XRP;
|
||||
BEAST_EXPECT(closed->info().drops == expectedDrops);
|
||||
|
||||
@@ -62,15 +68,14 @@ struct Regression_test : public beast::unit_test::suite
|
||||
auto const aliceAmount = XRP(aliceXRP);
|
||||
|
||||
auto next = std::make_shared<Ledger>(
|
||||
*closed,
|
||||
env.app().timeKeeper().closeTime());
|
||||
*closed, env.app().timeKeeper().closeTime());
|
||||
{
|
||||
// Fund alice
|
||||
auto const jt = env.jt(pay(env.master, "alice", aliceAmount));
|
||||
OpenView accum(&*next);
|
||||
|
||||
auto const result = ripple::apply(env.app(),
|
||||
accum, *jt.stx, tapNONE, env.journal);
|
||||
auto const result =
|
||||
ripple::apply(env.app(), accum, *jt.stx, tapNONE, env.journal);
|
||||
BEAST_EXPECT(result.first == tesSUCCESS);
|
||||
BEAST_EXPECT(result.second);
|
||||
|
||||
@@ -79,32 +84,29 @@ struct Regression_test : public beast::unit_test::suite
|
||||
expectedDrops -= next->fees().base;
|
||||
BEAST_EXPECT(next->info().drops == expectedDrops);
|
||||
{
|
||||
auto const sle = next->read(
|
||||
keylet::account(Account("alice").id()));
|
||||
auto const sle = next->read(keylet::account(Account("alice").id()));
|
||||
BEAST_EXPECT(sle);
|
||||
auto balance = sle->getFieldAmount(sfBalance);
|
||||
|
||||
BEAST_EXPECT(balance == aliceAmount );
|
||||
BEAST_EXPECT(balance == aliceAmount);
|
||||
}
|
||||
|
||||
{
|
||||
// Specify the seq manually since the env's open ledger
|
||||
// doesn't know about this account.
|
||||
auto const jt = env.jt(noop("alice"), fee(expectedDrops),
|
||||
seq(2));
|
||||
auto const jt = env.jt(noop("alice"), fee(expectedDrops), seq(2));
|
||||
|
||||
OpenView accum(&*next);
|
||||
|
||||
auto const result = ripple::apply(env.app(),
|
||||
accum, *jt.stx, tapNONE, env.journal);
|
||||
auto const result =
|
||||
ripple::apply(env.app(), accum, *jt.stx, tapNONE, env.journal);
|
||||
BEAST_EXPECT(result.first == tecINSUFF_FEE);
|
||||
BEAST_EXPECT(result.second);
|
||||
|
||||
accum.apply(*next);
|
||||
}
|
||||
{
|
||||
auto const sle = next->read(
|
||||
keylet::account(Account("alice").id()));
|
||||
auto const sle = next->read(keylet::account(Account("alice").id()));
|
||||
BEAST_EXPECT(sle);
|
||||
auto balance = sle->getFieldAmount(sfBalance);
|
||||
|
||||
@@ -114,20 +116,20 @@ struct Regression_test : public beast::unit_test::suite
|
||||
BEAST_EXPECT(next->info().drops == expectedDrops);
|
||||
}
|
||||
|
||||
void testSecp256r1key ()
|
||||
void
|
||||
testSecp256r1key()
|
||||
{
|
||||
testcase("Signing with a secp256r1 key should fail gracefully");
|
||||
using namespace jtx;
|
||||
Env env(*this);
|
||||
|
||||
// Test case we'll use.
|
||||
auto test256r1key = [&env] (Account const& acct)
|
||||
{
|
||||
auto test256r1key = [&env](Account const& acct) {
|
||||
auto const baseFee = env.current()->fees().base;
|
||||
std::uint32_t const acctSeq = env.seq (acct);
|
||||
Json::Value jsonNoop = env.json (
|
||||
noop (acct), fee(baseFee), seq(acctSeq), sig(acct));
|
||||
JTx jt = env.jt (jsonNoop);
|
||||
std::uint32_t const acctSeq = env.seq(acct);
|
||||
Json::Value jsonNoop =
|
||||
env.json(noop(acct), fee(baseFee), seq(acctSeq), sig(acct));
|
||||
JTx jt = env.jt(jsonNoop);
|
||||
jt.fill_sig = false;
|
||||
|
||||
// Random secp256r1 public key generated by
|
||||
@@ -142,34 +144,33 @@ struct Regression_test : public beast::unit_test::suite
|
||||
|
||||
// Set the same key in the STTx.
|
||||
auto secp256r1Sig = std::make_unique<STTx>(*(jt.stx));
|
||||
auto pubKeyBlob = strUnHex (secp256r1PubKey);
|
||||
assert (pubKeyBlob); // Hex for public key must be valid
|
||||
secp256r1Sig->setFieldVL
|
||||
(sfSigningPubKey, std::move(*pubKeyBlob));
|
||||
jt.stx.reset (secp256r1Sig.release());
|
||||
auto pubKeyBlob = strUnHex(secp256r1PubKey);
|
||||
assert(pubKeyBlob); // Hex for public key must be valid
|
||||
secp256r1Sig->setFieldVL(sfSigningPubKey, std::move(*pubKeyBlob));
|
||||
jt.stx.reset(secp256r1Sig.release());
|
||||
|
||||
env (jt, ter (temINVALID));
|
||||
env(jt, ter(temINVALID));
|
||||
};
|
||||
|
||||
Account const alice {"alice", KeyType::secp256k1};
|
||||
Account const becky {"becky", KeyType::ed25519};
|
||||
Account const alice{"alice", KeyType::secp256k1};
|
||||
Account const becky{"becky", KeyType::ed25519};
|
||||
|
||||
env.fund(XRP(10000), alice, becky);
|
||||
|
||||
test256r1key (alice);
|
||||
test256r1key (becky);
|
||||
test256r1key(alice);
|
||||
test256r1key(becky);
|
||||
}
|
||||
|
||||
void testFeeEscalationAutofill()
|
||||
void
|
||||
testFeeEscalationAutofill()
|
||||
{
|
||||
testcase("Autofilled fee should use the escalated fee");
|
||||
using namespace jtx;
|
||||
Env env(*this, envconfig([](std::unique_ptr<Config> cfg)
|
||||
{
|
||||
cfg->section("transaction_queue")
|
||||
.set("minimum_txn_in_ledger_standalone", "3");
|
||||
return cfg;
|
||||
}));
|
||||
Env env(*this, envconfig([](std::unique_ptr<Config> cfg) {
|
||||
cfg->section("transaction_queue")
|
||||
.set("minimum_txn_in_ledger_standalone", "3");
|
||||
return cfg;
|
||||
}));
|
||||
Env_ss envs(env);
|
||||
|
||||
auto const alice = Account("alice");
|
||||
@@ -178,8 +179,7 @@ struct Regression_test : public beast::unit_test::suite
|
||||
auto params = Json::Value(Json::objectValue);
|
||||
// Max fee = 50k drops
|
||||
params[jss::fee_mult_max] = 5000;
|
||||
std::vector<int> const
|
||||
expectedFees({ 10, 10, 8889, 13889, 20000 });
|
||||
std::vector<int> const expectedFees({10, 10, 8889, 13889, 20000});
|
||||
|
||||
// We should be able to submit 5 transactions within
|
||||
// our fee limit.
|
||||
@@ -198,15 +198,15 @@ struct Regression_test : public beast::unit_test::suite
|
||||
}
|
||||
}
|
||||
|
||||
void testFeeEscalationExtremeConfig()
|
||||
void
|
||||
testFeeEscalationExtremeConfig()
|
||||
{
|
||||
testcase("Fee escalation shouldn't allocate extreme memory");
|
||||
using clock_type = std::chrono::steady_clock;
|
||||
using namespace jtx;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
Env env(*this, envconfig([](std::unique_ptr<Config> cfg)
|
||||
{
|
||||
Env env(*this, envconfig([](std::unique_ptr<Config> cfg) {
|
||||
auto& s = cfg->section("transaction_queue");
|
||||
s.set("minimum_txn_in_ledger_standalone", "4294967295");
|
||||
s.set("minimum_txn_in_ledger", "4294967295");
|
||||
@@ -224,24 +224,29 @@ struct Regression_test : public beast::unit_test::suite
|
||||
BEAST_EXPECT(clock_type::now() - start < 1s);
|
||||
}
|
||||
|
||||
void testJsonInvalid()
|
||||
void
|
||||
testJsonInvalid()
|
||||
{
|
||||
using namespace jtx;
|
||||
using boost::asio::buffer;
|
||||
testcase("jsonInvalid");
|
||||
|
||||
std::string const request = R"json({"command":"path_find","id":19,"subcommand":"create","source_account":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","destination_account":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","destination_amount":"1000000","source_currencies":[{"currency":"0000000000000000000000000000000000000000"},{"currency":"0000000000000000000000005553440000000000"},{"currency":"0000000000000000000000004254430000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004254430000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004254430000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004555520000000000"},{"currency":"0000000000000000000000004554480000000000"},{"currency":"0000000000000000000000004A50590000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"000000000000000000000000434E590000000000"},{"currency":"0000000000000000000000004742490000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004341440000000000"}]})json";
|
||||
std::string const request =
|
||||
R"json({"command":"path_find","id":19,"subcommand":"create","source_account":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","destination_account":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","destination_amount":"1000000","source_currencies":[{"currency":"0000000000000000000000000000000000000000"},{"currency":"0000000000000000000000005553440000000000"},{"currency":"0000000000000000000000004254430000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004254430000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004254430000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004555520000000000"},{"currency":"0000000000000000000000004554480000000000"},{"currency":"0000000000000000000000004A50590000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"000000000000000000000000434E590000000000"},{"currency":"0000000000000000000000004742490000000000"},{"issuer":"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh","currency":"0000000000000000000000004341440000000000"}]})json";
|
||||
|
||||
Json::Value jvRequest;
|
||||
Json::Reader jrReader;
|
||||
|
||||
std::vector<boost::asio::const_buffer> buffers;
|
||||
buffers.emplace_back(buffer(request, 1024));
|
||||
buffers.emplace_back(buffer(request.data() + 1024, request.length() - 1024));
|
||||
BEAST_EXPECT(jrReader.parse(jvRequest, buffers) && jvRequest.isObject());
|
||||
buffers.emplace_back(
|
||||
buffer(request.data() + 1024, request.length() - 1024));
|
||||
BEAST_EXPECT(
|
||||
jrReader.parse(jvRequest, buffers) && jvRequest.isObject());
|
||||
}
|
||||
|
||||
void run() override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testOffer1();
|
||||
testLowBalanceDestroy();
|
||||
@@ -252,7 +257,7 @@ struct Regression_test : public beast::unit_test::suite
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(Regression,app,ripple);
|
||||
BEAST_DEFINE_TESTSUITE(Regression, app, ripple);
|
||||
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
Reference in New Issue
Block a user