22#include <xrpld/app/misc/NetworkOPs.h>
23#include <xrpld/app/misc/TxQ.h>
25#include <xrpl/beast/hash/uhash.h>
26#include <xrpl/beast/unit_test.h>
27#include <xrpl/protocol/Feature.h>
28#include <xrpl/protocol/TxFlags.h>
29#include <xrpl/protocol/jss.h>
31#include <boost/lexical_cast.hpp>
46 return boost::lexical_cast<std::string>(t);
66 auto const USD = gw[
"USD"];
99 fail(
"missing exception");
109 fail(
"missing exception");
130 BEAST_EXPECT(
XRP(1) ==
drops(1000000));
135 auto const USD = gw[
"USD"];
136 BEAST_EXPECT(
to_string(USD(0)) ==
"0/USD(gw)");
137 BEAST_EXPECT(
to_string(USD(10)) ==
"10/USD(gw)");
138 BEAST_EXPECT(
to_string(USD(-10)) ==
"-10/USD(gw)");
139 BEAST_EXPECT(USD(0) ==
STAmount(USD, 0));
140 BEAST_EXPECT(USD(1) ==
STAmount(USD, 1));
141 BEAST_EXPECT(USD(-1) ==
STAmount(USD, -1));
144 BEAST_EXPECT(!
get(USD(10)).is_any);
145 BEAST_EXPECT(
get(
any(USD(10))).is_any);
153 auto const n =
XRP(10000);
155 auto const USD = gw[
"USD"];
156 auto const alice =
Account(
"alice");
161 env(
pay(
"alice",
"bob",
XRP(1000)),
173 env.
fund(n,
"alice");
174 env.
fund(n,
"bob",
"carol");
191 env.
fund(n,
"alice",
"bob", gw);
199 BEAST_EXPECT(env.
balance(alice) == 0);
200 BEAST_EXPECT(env.
balance(alice, USD) != 0);
201 BEAST_EXPECT(env.
balance(alice, USD) == USD(0));
202 env.
fund(n, alice, gw);
204 BEAST_EXPECT(env.
balance(alice) == n);
205 BEAST_EXPECT(env.
balance(gw) == n);
206 env.
trust(USD(1000), alice);
207 env(
pay(gw, alice, USD(10)));
217 BEAST_EXPECT(env.
seq(
"alice") == 3);
218 BEAST_EXPECT(env.
seq(gw) == 3);
224 env.
fund(n,
"alice");
244 auto const USD = gw[
"USD"];
247 env.
fund(
XRP(10000),
"alice", gw);
250 env.
trust(USD(100),
"alice");
272 env.fund(
XRP(10000), alice, bob);
308 auto const gw =
Account(
"gateway");
309 auto const USD = gw[
"USD"];
311 env.
fund(
XRP(10000),
"alice",
"bob",
"carol", gw);
326 env.
trust(USD(100),
"alice",
"bob",
"carol");
330 env(
pay(gw,
"carol", USD(50)));
336 env(
pay(
"alice",
"bob",
any(USD(10))),
345 env(
regkey(
"alice",
"eric"));
347 env(
noop(
"alice"),
sig(
"alice"));
348 env(
noop(
"alice"),
sig(
"eric"));
360 env(
noop(
"alice"),
sig(
"eric"));
381 auto const gw =
Account(
"gateway");
382 auto const USD = gw[
"USD"];
384 auto const alice =
Account{
"alice"};
388 auto const queueTxCount =
390 auto const openTxCount = env.
current()->txCount();
391 BEAST_EXPECT(localTxCnt == 2 && queueTxCount == 0 && openTxCount == 2);
393 auto applyTxn = [&env](
auto&&... txnArgs) {
394 auto jt = env.
jt(txnArgs...);
401 args[jss::fail_hard] =
true;
403 return env.
rpc(
"json",
"submit", args.toStyledString());
406 auto jr = applyTxn(
noop(alice),
fee(1));
408 BEAST_EXPECT(jr[jss::result][jss::engine_result] ==
"telINSUF_FEE_P");
413 BEAST_EXPECT(env.
current()->txCount() == openTxCount);
415 jr = applyTxn(
noop(alice),
sig(
"bob"));
417 BEAST_EXPECT(jr[jss::result][jss::engine_result] ==
"tefBAD_AUTH");
422 BEAST_EXPECT(env.
current()->txCount() == openTxCount);
424 jr = applyTxn(
noop(alice),
seq(20));
426 BEAST_EXPECT(jr[jss::result][jss::engine_result] ==
"terPRE_SEQ");
431 BEAST_EXPECT(env.
current()->txCount() == openTxCount);
433 jr = applyTxn(
offer(alice,
XRP(1000), USD(1000)));
436 jr[jss::result][jss::engine_result] ==
"tecUNFUNDED_OFFER");
441 BEAST_EXPECT(env.
current()->txCount() == openTxCount);
445 BEAST_EXPECT(jr[jss::result][jss::engine_result] ==
"temBAD_FEE");
450 BEAST_EXPECT(env.
current()->txCount() == openTxCount);
452 jr = applyTxn(
noop(alice));
454 BEAST_EXPECT(jr[jss::result][jss::engine_result] ==
"tesSUCCESS");
456 BEAST_EXPECT(env.
current()->txCount() == openTxCount + 1);
467 env(
signers(
"alice", 1, {{
"alice", 1}, {
"bob", 2}}),
469 env(
signers(
"alice", 1, {{
"bob", 1}, {
"carol", 2}}));
472 auto const baseFee = env.
current()->fees().base;
474 env(
noop(
"alice"),
msig(
"carol"),
fee(2 * baseFee));
475 env(
noop(
"alice"),
msig(
"bob",
"carol"),
fee(3 * baseFee));
477 msig(
"bob",
"carol",
"dilbert"),
515 BEAST_EXPECT(!jt1.
get<
int>());
517 BEAST_EXPECT(jt1.
get<
int>());
518 BEAST_EXPECT(*jt1.
get<
int>() == 7);
519 BEAST_EXPECT(!jt1.
get<
UDT>());
524 BEAST_EXPECT(jt1.
get<
int>());
525 BEAST_EXPECT(*jt1.
get<
int>() == 17);
526 BEAST_EXPECT(!jt1.
get<
UDT>());
530 *jt1.
get<
int>() = 42;
531 BEAST_EXPECT(jt1.
get<
int>());
532 BEAST_EXPECT(*jt1.
get<
int>() == 42);
533 BEAST_EXPECT(!jt1.
get<
UDT>());
536 auto const& jt2 = jt1;
537 BEAST_EXPECT(jt2.get<
int>());
538 BEAST_EXPECT(*jt2.get<
int>() == 42);
539 BEAST_EXPECT(!jt2.get<
UDT>());
547 env.
fund(
XRP(100000),
"alice");
548 auto jt1 = env.
jt(
noop(
"alice"));
558 BEAST_EXPECT(*jt3.get<
std::string>() ==
"Hello, world!");
559 BEAST_EXPECT(jt3.get<
bool>());
560 BEAST_EXPECT(!*jt3.get<
bool>());
572 BEAST_EXPECT(jt1.
get<
int>());
573 BEAST_EXPECT(*jt1.
get<
int>() == 7);
574 BEAST_EXPECT(!jt1.
get<
UDT>());
576 BEAST_EXPECT(jt2.
get<
int>());
577 BEAST_EXPECT(*jt2.
get<
int>() == 7);
578 BEAST_EXPECT(!jt2.
get<
UDT>());
581 BEAST_EXPECT(jt3.
get<
int>());
582 BEAST_EXPECT(*jt3.
get<
int>() == 7);
583 BEAST_EXPECT(!jt3.
get<
UDT>());
595 BEAST_EXPECT(jt1.
get<
int>());
596 BEAST_EXPECT(*jt1.
get<
int>() == 7);
597 BEAST_EXPECT(!jt1.
get<
UDT>());
598 JTx jt2(std::move(jt1));
599 BEAST_EXPECT(!jt1.
get<
int>());
600 BEAST_EXPECT(!jt1.
get<
UDT>());
601 BEAST_EXPECT(jt2.
get<
int>());
602 BEAST_EXPECT(*jt2.
get<
int>() == 7);
603 BEAST_EXPECT(!jt2.
get<
UDT>());
604 jt1 = std::move(jt2);
605 BEAST_EXPECT(!jt2.
get<
int>());
606 BEAST_EXPECT(!jt2.
get<
UDT>());
607 BEAST_EXPECT(jt1.
get<
int>());
608 BEAST_EXPECT(*jt1.
get<
int>() == 7);
609 BEAST_EXPECT(!jt1.
get<
UDT>());
624 env(
noop(
"alice"),
memo(
"data",
"format",
"type"));
626 memo(
"data1",
"format1",
"type1"),
627 memo(
"data2",
"format2",
"type2"));
636 memo(
"data",
"format",
"type")(env, jt);
638 auto const&
memo = jt.
jv[
"Memos"][0u][
"Memo"];
653 BEAST_EXPECT(
seq == env.
closed()->seq() + 1);
655 BEAST_EXPECT(env.
closed()->seq() ==
seq);
656 BEAST_EXPECT(env.
current()->seq() ==
seq + 1);
658 BEAST_EXPECT(env.
closed()->seq() ==
seq + 1);
659 BEAST_EXPECT(env.
current()->seq() ==
seq + 2);
669 env.
fund(
XRP(100000),
"alice",
"bob");
671 env(
pay(
"alice",
"bob",
XRP(100)));
684 auto const USD = gw[
"USD"];
685 env.
fund(
XRP(10000),
"alice",
"bob");
688 pay(
"alice",
"bob", USD(10)),
705 auto const baseFee = env.
current()->fees().base;
712 JTx jt = env.
jt(jsonNoop);
723 auto const baseFee = env.
current()->fees().base;
725 auto const alice =
Account(
"alice");
733 if (BEAST_EXPECT(tx))
735 BEAST_EXPECT(tx->getAccountID(sfAccount) == alice.id());
736 BEAST_EXPECT(tx->getTxnType() == ttACCOUNT_SET);
746 if (BEAST_EXPECT(tx))
748 BEAST_EXPECT(tx->getAccountID(sfAccount) == alice.id());
749 BEAST_EXPECT(tx->getTxnType() == ttACCOUNT_SET);
756 params[jss::fee_mult_max] = 1;
757 params[jss::fee_div_max] = 2;
759 auto const expectedErrorString =
"Fee of " +
761 " exceeds the requested tx limit of " +
786 auto const n = supported.size();
787 for (
size_t i = 0; i < n; ++i)
794 if (!neverSupportedFeat)
796 log <<
"No unsupported features found - skipping test."
802 auto hasFeature = [](
Env& env,
uint256 const& f) {
814 this->BEAST_EXPECT(hasFeature(env, f));
824 (f == featureMultiSignReserve || f == featureFlow);
825 this->BEAST_EXPECT(has == hasFeature(env, f));
829 auto const missingSomeFeatures =
831 BEAST_EXPECT(missingSomeFeatures.count() == (supported.count() - 2));
834 Env env{*
this, missingSomeFeatures};
839 (f == featureMultiSignReserve || f == featureFlow);
840 this->BEAST_EXPECT(hasnot != hasFeature(env, f));
852 featureMultiSignReserve, featureFlow, *neverSupportedFeat)};
857 BEAST_EXPECT(hasFeature(env, *neverSupportedFeat));
860 bool has = (f == featureMultiSignReserve || f == featureFlow);
861 this->BEAST_EXPECT(has == hasFeature(env, f));
877 (supported.count() - 2 + 1));
878 BEAST_EXPECT(hasFeature(env, *neverSupportedFeat));
881 (f == featureMultiSignReserve || f == featureFlow);
882 this->BEAST_EXPECT(hasnot != hasFeature(env, f));
896 BEAST_EXPECT(hasFeature(env, *neverSupportedFeat));
898 this->BEAST_EXPECT(hasFeature(env, f));
910 (*cfg).deprecatedClearSection(
"port_rpc");
log_os< char > log
Logging output stream.
void pass()
Record a successful test condition.
testcase_t testcase
Memberspace for declaring test cases.
bool except(F &&f, String const &reason)
void fail(String const &reason, char const *file, int line)
Record a failure.
virtual Config & config()=0
virtual NetworkOPs & getOPs()=0
std::unordered_set< uint256, beast::uhash<> > features
FeatureBitset & set(uint256 const &f, bool value=true)
virtual std::size_t getLocalTxCount()=0
Slice slice() const noexcept
Metrics getMetrics(OpenView const &view) const
Returns fee metrics in reference fee level units.
static std::string to_string(T const &t)
void testExceptionalShutdown()
void run() override
Runs the suite.
Immutable cryptographic account descriptor.
A transaction testing environment wrapper.
A transaction testing environment.
Json::Value json(JsonValue &&jv, FN const &... fN)
Create JSON from parameters.
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
void require(Args const &... args)
Check a set of requirements.
std::shared_ptr< STTx const > tx() const
Return the tx data for the last JTx.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
Json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
PrettyAmount balance(Account const &account) const
Returns the XRP balance on an account.
void memoize(Account const &account)
Associate AccountID with account.
Set a multisignature on a JTx.
Match clear account flags.
Match the number of items in the account's owner directory.
Set Paths, SendMax on a JTx.
Check a set of conditions.
Set the expected result code for a JTx The test will fail if the code doesn't match.
Sets the SendMax on a JTx.
Set the regular signature on a JTx.
Set the expected result code for a JTx The test will fail if the code doesn't match.
@ objectValue
object value (collection of name/value pairs).
Json::Value create(Account const &account, std::uint32_t count)
Create one of more tickets.
owner_count< ltRIPPLE_STATE > lines
Match the number of trust lines in the account's owner directory.
Json::Value fclear(Account const &account, std::uint32_t off)
Remove account flag.
Json::Value regkey(Account const &account, disabled_t)
Disable the regular key.
Json::Value signers(Account const &account, std::uint32_t quorum, std::vector< signer > const &v)
static autofill_t const autofill
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
any_t const any
Returns an amount representing "any issuer".
FeatureBitset testable_amendments()
Json::Value rate(Account const &account, double multiplier)
Set a transfer rate.
static disabled_t const disabled
Json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
owner_count< ltTICKET > tickets
Match the number of tickets on the account.
XRP_t const XRP
Converts to XRP Issue or STAmount.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
uint256 bitsetIndexToFeature(size_t i)
constexpr std::uint32_t asfRequireDest
constexpr std::uint32_t asfDisableMaster
std::string strHex(FwdIt begin, FwdIt end)
constexpr std::uint32_t asfDefaultRipple
void foreachFeature(FeatureBitset bs, F &&f)
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
std::size_t txCount
Number of transactions in the queue.
Amount specifier with an option for any issuer.
Execution context for applying a JSON transaction.
Prop * get()
Return a property if it exists.
void set(std::unique_ptr< basic_prop > p)
Set a property If the property already exists, it is replaced.
Represents an XRP or IOU quantity This customizes the string conversion and supports XRP conversions ...
Set the sequence number on a JTx.