20 #include <ripple/app/ledger/Ledger.h>
21 #include <ripple/core/ConfigSections.h>
22 #include <ripple/ledger/ApplyViewImpl.h>
23 #include <ripple/ledger/OpenView.h>
24 #include <ripple/ledger/PaymentSandbox.h>
25 #include <ripple/ledger/Sandbox.h>
26 #include <ripple/protocol/Feature.h>
27 #include <ripple/protocol/Protocol.h>
47 auto const le = std::make_shared<SLE>(
k(
id));
73 boost::optional<uint256> next;
77 next = view.
succ(*next);
91 boost::optional<uint256> next;
95 next = ledger.
succ(*next);
108 boost::optional<std::uint32_t> answer)
110 auto const next = v.
succ(
k(
id).key);
113 if (BEAST_EXPECT(next))
114 BEAST_EXPECT(*next ==
k(*answer).
key);
126 return std::make_shared<std::remove_const_t<T>>(*sp);
138 auto const ledger = std::make_shared<Ledger>(
142 succ(v, 0, boost::none);
143 ledger->rawInsert(
sle(1, 1));
145 BEAST_EXPECT(
seq(v.
read(
k(1))) == 1);
147 succ(v, 1, boost::none);
148 ledger->rawInsert(
sle(2, 2));
149 BEAST_EXPECT(
seq(v.
read(
k(2))) == 2);
150 ledger->rawInsert(
sle(3, 3));
151 BEAST_EXPECT(
seq(v.
read(
k(3))) == 3);
154 ledger->rawReplace(std::move(s));
155 BEAST_EXPECT(
seq(v.
read(
k(2))) == 4);
156 ledger->rawErase(
sle(2));
170 succ(v, 0, boost::none);
173 BEAST_EXPECT(
seq(v.
read(
k(1))) == 1);
174 BEAST_EXPECT(
seq(v.
peek(
k(1))) == 1);
176 succ(v, 1, boost::none);
178 BEAST_EXPECT(
seq(v.
read(
k(2))) == 2);
180 auto s = v.
peek(
k(3));
181 BEAST_EXPECT(
seq(s) == 3);
185 BEAST_EXPECT(
seq(v.
read(
k(2))) == 4);
221 succ(v0, 7, boost::none);
230 succ(v1, 7, boost::none);
254 succ(v0, 7, boost::none);
273 auto s = v1.
peek(
k(4));
276 BEAST_EXPECT(
seq(v1.
read(
k(1))) == 1);
277 BEAST_EXPECT(!v1.
exists(
k(2)));
278 BEAST_EXPECT(
seq(v1.
read(
k(3))) == 3);
279 BEAST_EXPECT(
seq(v1.
read(
k(4))) == 5);
282 auto s2 = v2.
peek(
k(3));
286 BEAST_EXPECT(
seq(v2.
read(
k(1))) == 1);
287 BEAST_EXPECT(!v2.
exists(
k(2)));
288 BEAST_EXPECT(
seq(v2.
read(
k(3))) == 6);
289 BEAST_EXPECT(!v2.
exists(
k(4)));
292 BEAST_EXPECT(
seq(v1.
read(
k(1))) == 1);
293 BEAST_EXPECT(!v1.
exists(
k(2)));
294 BEAST_EXPECT(
seq(v1.
read(
k(3))) == 3);
295 BEAST_EXPECT(
seq(v1.
read(
k(4))) == 5);
299 auto s2 = v2.
peek(
k(3));
303 BEAST_EXPECT(
seq(v2.
read(
k(1))) == 1);
304 BEAST_EXPECT(!v2.
exists(
k(2)));
305 BEAST_EXPECT(
seq(v2.
read(
k(3))) == 6);
306 BEAST_EXPECT(!v2.
exists(
k(4)));
309 BEAST_EXPECT(
seq(v1.
read(
k(1))) == 1);
310 BEAST_EXPECT(!v1.
exists(
k(2)));
311 BEAST_EXPECT(
seq(v1.
read(
k(3))) == 6);
312 BEAST_EXPECT(!v1.
exists(
k(4)));
315 BEAST_EXPECT(
seq(v0.
read(
k(1))) == 1);
316 BEAST_EXPECT(!v0.
exists(
k(2)));
317 BEAST_EXPECT(
seq(v0.
read(
k(3))) == 6);
318 BEAST_EXPECT(!v0.
exists(
k(4)));
332 BEAST_EXPECT(v0.
seq() != 98);
333 BEAST_EXPECT(v0.
seq() ==
open->seq());
339 BEAST_EXPECT(v1.
seq() == v0.
seq());
344 BEAST_EXPECT(v2.
seq() == v1.
seq());
348 BEAST_EXPECT(v3.
seq() == v2.
seq());
355 BEAST_EXPECT(v2.
seq() == v0.
seq());
359 BEAST_EXPECT(v3.
seq() == v2.
seq());
372 for (
auto const&
sle : ledger.
sles)
377 template <
class... Args>
392 auto const ledger = std::make_shared<Ledger>(
394 auto setup123 = [&ledger,
this]() {
397 ledger->rawInsert(
sle(1));
398 ledger->rawInsert(
sle(2));
399 ledger->rawInsert(
sle(3));
400 BEAST_EXPECT(
sles(*ledger) ==
list(1, 2, 3));
408 BEAST_EXPECT(
sles(view) ==
list(2, 3, 4, 5));
427 BEAST_EXPECT(
sles(view) ==
list(3, 4, 5));
446 BEAST_EXPECT(
sles(view) ==
list(4, 5));
462 BEAST_EXPECT(
sles(view) ==
list(1, 2, 4, 5));
479 BEAST_EXPECT(
sles(view) ==
list(1, 2, 3));
480 BEAST_EXPECT(
seq(view.
read(
k(1))) == 10);
481 BEAST_EXPECT(
seq(view.
read(
k(2))) == 1);
482 BEAST_EXPECT(
seq(view.
read(
k(3))) == 30);
485 BEAST_EXPECT(
sles(view) ==
list(1, 2));
498 BEAST_EXPECT(
sles(view) ==
list(1, 2, 3, 4, 5));
519 auto const alice =
Account(
"alice");
520 auto const bob =
Account(
"bob");
521 auto const carol =
Account(
"carol");
522 auto const gw =
Account(
"gateway");
523 auto const USD = gw[
"USD"];
524 auto const EUR = gw[
"EUR"];
526 env.
fund(
XRP(10000), alice, bob, carol, gw);
527 env.
trust(USD(100), alice, bob, carol);
530 env(
pay(gw, alice, USD(50)));
531 env(offer(alice,
XRP(5), USD(5)));
553 env(offer(
"alice",
XRP(4), USD(5)));
557 env(
pay(gw, bob, USD(50)));
590 env(
pay(gw, carol, USD(50)));
628 BEAST_EXPECT(carolsXRP ==
XRP(9750));
651 BEAST_EXPECT(gwUSD == USD(314159));
656 BEAST_EXPECT(carolsUSD == USD(50));
663 BEAST_EXPECT(carolsUSD == USD(0));
668 BEAST_EXPECT(carolsUSD == USD(50));
682 auto const gw1 =
Account(
"gw1");
687 auto rdView = env.
closed();
691 env(
rate(gw1, 1.02));
706 auto const alice =
Account(
"alice");
707 auto const bob =
Account(
"bob");
714 auto const rdViewA3 = eA.
closed();
718 auto const rdViewA4 = eA.
closed();
726 eB.fund(
XRP(10000), bob);
728 auto const rdViewB3 = eB.closed();
730 eB.fund(
XRP(10000), alice);
732 auto const rdViewB4 = eB.closed();
736 BEAST_EXPECT(
areCompatible(*rdViewA3, *rdViewA4, jStream,
""));
737 BEAST_EXPECT(
areCompatible(*rdViewA4, *rdViewA3, jStream,
""));
738 BEAST_EXPECT(
areCompatible(*rdViewA4, *rdViewA4, jStream,
""));
739 BEAST_EXPECT(!
areCompatible(*rdViewA3, *rdViewB4, jStream,
""));
740 BEAST_EXPECT(!
areCompatible(*rdViewA4, *rdViewB3, jStream,
""));
741 BEAST_EXPECT(!
areCompatible(*rdViewA4, *rdViewB4, jStream,
""));
745 auto const& iA3 = rdViewA3->info();
746 auto const& iA4 = rdViewA4->info();
748 BEAST_EXPECT(
areCompatible(iA3.hash, iA3.seq, *rdViewA4, jStream,
""));
749 BEAST_EXPECT(
areCompatible(iA4.hash, iA4.seq, *rdViewA3, jStream,
""));
750 BEAST_EXPECT(
areCompatible(iA4.hash, iA4.seq, *rdViewA4, jStream,
""));
751 BEAST_EXPECT(!
areCompatible(iA3.hash, iA3.seq, *rdViewB4, jStream,
""));
752 BEAST_EXPECT(
areCompatible(iA4.hash, iA4.seq, *rdViewB3, jStream,
""));
753 BEAST_EXPECT(!
areCompatible(iA4.hash, iA4.seq, *rdViewB4, jStream,
""));
768 std::make_shared<Ledger>(
773 auto const ledger = std::make_shared<Ledger>(
776 ledger->rawInsert(
sle(1));
784 BEAST_EXPECT(!v1.
exists(
k(1)));
800 BEAST_EXPECT(
k(0).key <
k(1).key);
825 BEAST_EXPECT(majorities.empty());
829 for (i = 0; i <= 256; ++i)
833 if (!majorities.empty())
839 BEAST_EXPECT(i == 254);
840 BEAST_EXPECT(majorities.size() >= 5);
844 BEAST_EXPECT(enableds.empty());
849 for (i = 0; i <= 256; ++i)
851 using namespace std::chrono_literals;
854 if (!enableds.empty())
857 BEAST_EXPECT(i == 255);
858 BEAST_EXPECT(enableds.size() >= 5);
Rate transferRate(ReadView const &view, AccountID const &issuer)
Json::Value noop(Account const &account)
The null transaction.
majorityAmendments_t getMajorityAmendments(ReadView const &view)
const XRP_t XRP
Converts to XRP Issue or STAmount.
A pair of SHAMap key and LedgerEntryType.
std::set< uint256 > getEnabledAmendments(ReadView const &view)
BEAST_DEFINE_TESTSUITE(AccountDelete, app, ripple)
static void seq(std::shared_ptr< SLE > const &le, std::uint32_t seq)
Represents a transfer rate.
Set the expected result code for a JTx The test will fail if the code doesn't match.
A wrapper which makes credits unavailable to balances.
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
Writable ledger view that accumulates state and tx changes.
const std::uint32_t asfGlobalFreeze
void rawErase(std::shared_ptr< SLE > const &sle) override
Delete an existing state item.
std::unique_ptr< Config > validator(std::unique_ptr< Config >, std::string const &)
adjust configuration with params needed to be a validator
bool exists(Keylet const &k) const override
Determine if a state item exists.
const SF_U32 sfSequence(access, STI_UINT32, 4, "Sequence")
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
void update(std::shared_ptr< SLE > const &sle) override
Indicate changes to a peeked SLE.
std::unique_ptr< Config > port_increment(std::unique_ptr< Config >, int)
adjust the default configured server ports by a specified value
const beast::Journal journal
iterator upper_bound(key_type const &key) const
Editable, discardable view that can build metadata for one tx.
virtual TimeKeeper & timeKeeper()=0
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
const std::uint32_t tfClearFreeze
virtual OpenLedger & openLedger()=0
NetClock::time_point parentCloseTime() const
Returns the close time of the previous ledger.
static std::vector< uint256 > sles(ReadView const &ledger)
void rawErase(std::shared_ptr< SLE > const &sle) override
Delete an existing state item.
const Rate parityRate(QUALITY_ONE)
A transfer rate signifying a 1:1 exchange.
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
static std::shared_ptr< SLE > sle(std::uint64_t id, std::uint32_t seq=1)
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
Discardable, editable view to a ledger.
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
static void wipe(Ledger &ledger)
AccountID const & xrpAccount()
Compute AccountID from public key.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
sles_type sles
Iterable range of ledger state items.
virtual time_point closeTime() const =0
Returns the close time, in network time.
static void wipe(OpenLedger &openLedger)
A generic endpoint for log messages.
const std::uint32_t tfSetFreeze
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
Json::Value fclear(Account const &account, std::uint32_t off)
Remove account flag.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
bool areCompatible(ReadView const &validLedger, ReadView const &testLedger, beast::Journal::Stream &s, const char *reason)
Return false if the test ledger is provably incompatible with the valid ledger, that is,...
bool empty() const
Returns true if there are no transactions.
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
Represents the open ledger.
void rawInsert(std::shared_ptr< SLE > const &sle) override
Unconditionally insert a state item.
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
void insert(std::shared_ptr< SLE > const &sle) override
Insert a new state SLE.
void erase(std::shared_ptr< SLE > const &sle) override
Remove a peeked SLE.
Set the sequence number on a JTx.
ApplyFlags flags() const override
Returns the tx apply flags.
static std::shared_ptr< std::remove_const_t< T > > copy(std::shared_ptr< T > const &sp)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Json::Value pay(Account const &account, Account const &to, AnyAmount amount)
Create a payment.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
void close(NetClock::time_point closeTime, boost::optional< std::chrono::milliseconds > consensusDelay=boost::none)
Close and advance the ledger.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
const create_genesis_t create_genesis
boost::optional< uint256 > succ(uint256 const &key, boost::optional< uint256 > const &last=boost::none) const override
Return the key of the next state item.
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
Immutable cryptographic account descriptor.
std::shared_ptr< SLE > peek(Keylet const &k) override
Prepare to modify the SLE associated with key.
static Keylet k(std::uint64_t id)
static std::vector< uint256 > list(Args... args)
void succ(ReadView const &v, std::uint32_t id, boost::optional< std::uint32_t > answer)
virtual boost::optional< key_type > succ(key_type const &key, boost::optional< key_type > const &last=boost::none) const =0
Return the key of the next state item.
bool modify(modify_type const &f)
Modify the open ledger.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Currency const & xrpCurrency()
XRP currency.
A transaction testing environment.
void rawInsert(std::shared_ptr< SLE > const &sle) override
Unconditionally insert a state item.
void open(soci::session &s, BasicConfig const &config, std::string const &dbName)
Open a soci session.
boost::optional< key_type > succ(key_type const &key, boost::optional< key_type > const &last=boost::none) const override
Return the key of the next state item.
Json::Value rate(Account const &account, double multiplier)
Set a transfer rate.
static std::uint32_t seq(std::shared_ptr< T > const &le)