21 #include <ripple/json/to_string.h>
22 #include <ripple/protocol/Feature.h>
23 #include <ripple/protocol/jss.h>
24 #include <ripple/protocol/TxFlags.h>
25 #include <ripple/beast/hash/uhash.h>
26 #include <ripple/beast/unit_test.h>
27 #include <ripple/app/misc/NetworkOPs.h>
28 #include <ripple/app/misc/TxQ.h>
29 #include <boost/lexical_cast.hpp>
30 #include <boost/optional.hpp>
36 class Env_test :
public beast::unit_test::suite
44 return boost::lexical_cast<
65 auto const USD = gw[
"USD"];
95 fail(
"missing exception");
105 fail(
"missing exception");
126 BEAST_EXPECT(
XRP(1) ==
drops(1000000));
131 auto const USD = gw[
"USD"];
132 BEAST_EXPECT(
to_string(USD(0)) ==
"0/USD(gw)");
133 BEAST_EXPECT(
to_string(USD(10)) ==
"10/USD(gw)");
134 BEAST_EXPECT(
to_string(USD(-10)) ==
"-10/USD(gw)");
135 BEAST_EXPECT(USD(0) ==
STAmount(USD, 0));
136 BEAST_EXPECT(USD(1) ==
STAmount(USD, 1));
137 BEAST_EXPECT(USD(-1) ==
STAmount(USD, -1));
140 BEAST_EXPECT(!
get(USD(10)).is_any);
141 BEAST_EXPECT(
get(
any(USD(10))).is_any);
149 auto const n =
XRP(10000);
151 auto const USD = gw[
"USD"];
152 auto const alice =
Account(
"alice");
165 env.
fund(n,
"alice");
166 env.
fund(n,
"bob",
"carol");
183 env.
fund(n,
"alice",
"bob", gw);
190 BEAST_EXPECT(env.
balance(alice) == 0);
191 BEAST_EXPECT(env.
balance(alice, USD) != 0);
192 BEAST_EXPECT(env.
balance(alice, USD) == USD(0));
193 env.
fund(n, alice, gw);
194 BEAST_EXPECT(env.
balance(alice) == n);
195 BEAST_EXPECT(env.
balance(gw) == n);
196 env.
trust(USD(1000), alice);
197 env(
pay(gw, alice, USD(10)));
206 BEAST_EXPECT(env.
seq(
"alice") == 3);
207 BEAST_EXPECT(env.
seq(gw) == 3);
213 env.
fund(n,
"alice");
220 env(
noop(
"alice"),
fee(autofill));
221 env(
noop(
"alice"),
fee(autofill),
seq(autofill));
222 env(
noop(
"alice"),
fee(autofill),
seq(autofill),
sig(autofill));
233 auto const USD = gw[
"USD"];
236 env.
fund(
XRP(10000),
"alice", gw);
238 env.
trust(USD(100),
"alice");
258 env.fund(
XRP(10000), alice, bob);
292 auto const gw =
Account(
"gateway");
293 auto const USD = gw[
"USD"];
295 env.
fund(
XRP(10000),
"alice",
"bob",
"carol", gw);
310 env.
trust(USD(100),
"alice",
"bob",
"carol");
314 env(
pay(gw,
"carol", USD(50)));
320 env(
pay(
"alice",
"bob",
any(USD(10))),
328 env(
regkey(
"alice",
"eric"));
330 env(
noop(
"alice"),
sig(
"alice"));
331 env(
noop(
"alice"),
sig(
"eric"));
341 env(
noop(
"alice"),
sig(
"eric"));
347 env(
regkey(
"alice", disabled));
360 auto const gw =
Account(
"gateway");
361 auto const USD = gw[
"USD"];
363 auto const alice =
Account {
"alice"};
368 auto const openTxCount = env.
current()->txCount();
369 BEAST_EXPECT(localTxCnt == 2 && queueTxCount == 0 && openTxCount == 2);
371 auto applyTxn = [&env](
auto&& ...txnArgs)
373 auto jt = env.
jt (txnArgs...);
380 args[jss::fail_hard] =
true;
382 return env.
rpc (
"json",
"submit", args.toStyledString());
385 auto jr = applyTxn(
noop (alice),
fee (1));
387 BEAST_EXPECT(jr[jss::result][jss::engine_result] ==
"telINSUF_FEE_P");
390 BEAST_EXPECT(env.
current()->txCount() == openTxCount);
392 jr = applyTxn(
noop (alice),
sig(
"bob"));
394 BEAST_EXPECT(jr[jss::result][jss::engine_result] ==
"tefBAD_AUTH");
397 BEAST_EXPECT(env.
current()->txCount() == openTxCount);
399 jr = applyTxn(
noop (alice),
seq(20));
401 BEAST_EXPECT(jr[jss::result][jss::engine_result] ==
"terPRE_SEQ");
404 BEAST_EXPECT(env.
current()->txCount() == openTxCount);
406 jr = applyTxn(
offer(alice,
XRP(1000), USD(1000)));
408 BEAST_EXPECT(jr[jss::result][jss::engine_result] ==
"tecUNFUNDED_OFFER");
411 BEAST_EXPECT(env.
current()->txCount() == openTxCount);
415 BEAST_EXPECT(jr[jss::result][jss::engine_result] ==
"temBAD_FEE");
418 BEAST_EXPECT(env.
current()->txCount() == openTxCount);
420 jr = applyTxn(
noop (alice));
422 BEAST_EXPECT(jr[jss::result][jss::engine_result] ==
"tesSUCCESS");
424 BEAST_EXPECT(env.
current()->txCount() == openTxCount + 1);
438 { {
"bob", 1 }, {
"carol", 2 } }));
441 auto const baseFee = env.
current()->fees().base;
443 env(
noop(
"alice"),
msig(
"carol"),
fee(2 * baseFee));
444 env(
noop(
"alice"),
msig(
"bob",
"carol"),
fee(3 * baseFee));
445 env(
noop(
"alice"),
msig(
"bob",
"carol",
"dilbert"),
456 ticket::create(
"alice",
"bob");
457 ticket::create(
"alice", 60);
458 ticket::create(
"alice",
"bob", 60);
459 ticket::create(
"alice", 60,
"bob");
481 BEAST_EXPECT(!jt1.
get<
int>());
483 BEAST_EXPECT(jt1.
get<
int>());
484 BEAST_EXPECT(*jt1.
get<
int>() == 7);
485 BEAST_EXPECT(!jt1.
get<
UDT>());
490 BEAST_EXPECT(jt1.
get<
int>());
491 BEAST_EXPECT(*jt1.
get<
int>() == 17);
492 BEAST_EXPECT(!jt1.
get<
UDT>());
496 *jt1.
get<
int>() = 42;
497 BEAST_EXPECT(jt1.
get<
int>());
498 BEAST_EXPECT(*jt1.
get<
int>() == 42);
499 BEAST_EXPECT(!jt1.
get<
UDT>());
502 auto const& jt2 = jt1;
503 BEAST_EXPECT(jt2.get<
int>());
504 BEAST_EXPECT(*jt2.get<
int>() == 42);
505 BEAST_EXPECT(!jt2.get<
UDT>());
512 env.
fund(
XRP(100000),
"alice");
513 auto jt1 = env.
jt(
noop(
"alice"));
515 auto jt2 = env.
jt(
noop(
"alice"),
520 auto jt3 = env.
jt(
noop(
"alice"),
527 BEAST_EXPECT(jt3.get<
bool>());
528 BEAST_EXPECT(!*jt3.get<
bool>());
537 BEAST_EXPECT(jt1.
get<
int>());
538 BEAST_EXPECT(*jt1.
get<
int>() == 7);
539 BEAST_EXPECT(!jt1.
get<
UDT>());
541 BEAST_EXPECT(jt2.
get<
int>());
542 BEAST_EXPECT(*jt2.
get<
int>() == 7);
543 BEAST_EXPECT(!jt2.
get<
UDT>());
546 BEAST_EXPECT(jt3.
get<
int>());
547 BEAST_EXPECT(*jt3.
get<
int>() == 7);
548 BEAST_EXPECT(!jt3.
get<
UDT>());
557 BEAST_EXPECT(jt1.
get<
int>());
558 BEAST_EXPECT(*jt1.
get<
int>() == 7);
559 BEAST_EXPECT(!jt1.
get<
UDT>());
560 JTx jt2(std::move(jt1));
561 BEAST_EXPECT(!jt1.
get<
int>());
562 BEAST_EXPECT(!jt1.
get<
UDT>());
563 BEAST_EXPECT(jt2.
get<
int>());
564 BEAST_EXPECT(*jt2.
get<
int>() == 7);
565 BEAST_EXPECT(!jt2.
get<
UDT>());
566 jt1 = std::move(jt2);
567 BEAST_EXPECT(!jt2.
get<
int>());
568 BEAST_EXPECT(!jt2.
get<
UDT>());
569 BEAST_EXPECT(jt1.
get<
int>());
570 BEAST_EXPECT(*jt1.
get<
int>() == 7);
571 BEAST_EXPECT(!jt1.
get<
UDT>());
586 env(
noop(
"alice"),
memo(
"data",
"format",
"type"));
587 env(
noop(
"alice"),
memo(
"data1",
"format1",
"type1"),
memo(
"data2",
"format2",
"type2"));
596 memo(
"data",
"format",
"type")(env, jt);
598 auto const&
memo = jt.
jv[
"Memos"][0u][
"Memo"];
610 BEAST_EXPECT(
seq == env.
closed()->seq() + 1);
612 BEAST_EXPECT(env.
closed()->seq() ==
seq);
613 BEAST_EXPECT(env.
current()->seq() ==
seq + 1);
615 BEAST_EXPECT(env.
closed()->seq() ==
seq + 1);
616 BEAST_EXPECT(env.
current()->seq() ==
seq + 2);
626 env.
fund(
XRP(100000),
"alice",
"bob");
628 env(
pay(
"alice",
"bob",
XRP(100)));
641 auto const USD = gw[
"USD"];
642 env.
fund(
XRP(10000),
"alice",
"bob");
644 pay(
"alice",
"bob", USD(10)),
661 auto const baseFee = env.
current()->fees().base;
668 JTx jt = env.
jt (jsonNoop);
678 auto const alice =
Account(
"alice");
686 if (BEAST_EXPECT(tx))
688 BEAST_EXPECT(tx->getAccountID(
sfAccount) == alice.id());
699 if (BEAST_EXPECT(tx))
701 BEAST_EXPECT(tx->getAccountID(
sfAccount) == alice.id());
709 params[jss::fee_mult_max] = 1;
710 params[jss::fee_div_max] = 2;
722 testcase(
"Env features");
730 auto const neverSupportedFeat = [&]() -> boost::optional<uint256>
732 auto const n = supported.size();
733 for(
size_t i = 0; i < n; ++i)
740 if (!neverSupportedFeat)
742 log <<
"No unsupported features found - skipping test." <<
std::endl;
747 auto hasFeature = [](
Env& env,
uint256 const& f)
759 this->BEAST_EXPECT(hasFeature(env, f));
769 this->BEAST_EXPECT(has == hasFeature(env, f));
773 auto const missingSomeFeatures =
777 Env env{*
this, missingSomeFeatures};
782 this->BEAST_EXPECT(hasnot != hasFeature(env, f));
799 BEAST_EXPECT(hasFeature(env, *neverSupportedFeat));
803 this->BEAST_EXPECT(has == hasFeature(env, f));
818 (supported.count() - 2 + 1));
819 BEAST_EXPECT(hasFeature(env, *neverSupportedFeat));
822 this->BEAST_EXPECT(hasnot != hasFeature(env, f));
836 BEAST_EXPECT(hasFeature(env, *neverSupportedFeat));
838 this->BEAST_EXPECT(hasFeature(env, f));
851 (*cfg).deprecatedClearSection(
"port_rpc");
Json::Value noop(Account const &account)
The null transaction.
const XRP_t XRP
Converts to XRP Issue or STAmount.
BEAST_DEFINE_TESTSUITE(AccountDelete, app, ripple)
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
std::shared_ptr< STTx const > tx() const
Return the tx data for the last JTx.
Set the expected result code for a JTx The test will fail if the code doesn't match.
Match the number of items in the account's owner directory.
void require(Args const &... args)
Check a set of requirements.
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Amount specifier with an option for any issuer.
const std::uint32_t asfDefaultRipple
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
const SF_Account sfAccount(access, STI_ACCOUNT, 1, "Account")
Check a set of conditions.
const uint256 featureMultiSignReserve
PrettyAmount balance(Account const &account) const
Returns the XRP balance on an account.
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Json::Value offer(Account const &account, STAmount const &in, STAmount const &out, std::uint32_t flags)
Create an offer.
Set a multisignature on a JTx.
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
virtual NetworkOPs & getOPs()=0
void foreachFeature(FeatureBitset bs, F &&f)
Json::Value signers(Account const &account, std::uint32_t quorum, std::vector< signer > const &v)
@ objectValue
object value (collection of name/value pairs).
const any_t any
Returns an amount representing "any issuer".
void testExceptionalShutdown()
virtual Config & config()=0
void set(std::unique_ptr< basic_prop > p)
Set a property If the property already exists, it is replaced.
Sets the SendMax on a JTx.
Execution context for applying a JSON transaction.
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
Set Paths, SendMax on a JTx.
Slice slice() const noexcept
const uint256 fixMasterKeyAsRegularKey
FeatureBitset supported_amendments()
Set the regular signature on a JTx.
const uint256 featureTickets
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
virtual std::size_t getLocalTxCount()=0
A transaction testing environment wrapper.
Json::Value fclear(Account const &account, std::uint32_t off)
Remove account flag.
const std::uint32_t asfRequireDest
static std::string to_string(T const &t)
const std::uint32_t asfDisableMaster
Prop * get()
Return a property if it exists.
Set the sequence number on a JTx.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::unordered_set< uint256, beast::uhash<> > features
std::array< Account, 1+sizeof...(Args)> noripple(Account const &account, Args const &... args)
Designate accounts as no-ripple in Env::fund.
Json::Value pay(Account const &account, Account const &to, AnyAmount amount)
Create a payment.
void close(NetClock::time_point closeTime, boost::optional< std::chrono::milliseconds > consensusDelay=boost::none)
Close and advance the ledger.
Json::Value regkey(Account const &account, disabled_t)
Disable the regular key.
const uint256 featureFlow
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
uint256 bitsetIndexToFeature(size_t i)
FeatureBitset & set(uint256 const &f, bool value=true)
std::size_t txCount
Number of transactions in the queue.
Match clear account flags.
Immutable cryptographic account descriptor.
std::string strHex(FwdIt begin, FwdIt end)
Metrics getMetrics(OpenView const &view) const
Returns fee metrics in reference fee level units.
void memoize(Account const &account)
Associate AccountID with account.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Json::Value json(JsonValue &&jv, FN const &... fN)
Create JSON from parameters.
A transaction testing environment.
Json::Value rpc(std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Represents an XRP or IOU quantity This customizes the string conversion and supports XRP conversions ...
T & get(EitherAmount &amt)
Json::Value rate(Account const &account, double multiplier)
Set a transfer rate.