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));
77 next = view.
succ(*next);
95 next = ledger.
succ(*next);
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);
140 env.
app().getNodeFamily());
141 auto const ledger = std::make_shared<Ledger>(
145 succ(v, 0, std::nullopt);
146 ledger->rawInsert(
sle(1, 1));
148 BEAST_EXPECT(
seq(v.
read(
k(1))) == 1);
150 succ(v, 1, std::nullopt);
151 ledger->rawInsert(
sle(2, 2));
152 BEAST_EXPECT(
seq(v.
read(
k(2))) == 2);
153 ledger->rawInsert(
sle(3, 3));
154 BEAST_EXPECT(
seq(v.
read(
k(3))) == 3);
157 ledger->rawReplace(s);
158 BEAST_EXPECT(
seq(v.
read(
k(2))) == 4);
159 ledger->rawErase(
sle(2));
173 succ(v, 0, std::nullopt);
176 BEAST_EXPECT(
seq(v.
read(
k(1))) == 1);
177 BEAST_EXPECT(
seq(v.
peek(
k(1))) == 1);
179 succ(v, 1, std::nullopt);
181 BEAST_EXPECT(
seq(v.
read(
k(2))) == 2);
183 auto s = v.
peek(
k(3));
184 BEAST_EXPECT(
seq(s) == 3);
188 BEAST_EXPECT(
seq(v.
read(
k(2))) == 4);
224 succ(v0, 7, std::nullopt);
233 succ(v1, 7, std::nullopt);
257 succ(v0, 7, std::nullopt);
276 auto s = v1.
peek(
k(4));
279 BEAST_EXPECT(
seq(v1.
read(
k(1))) == 1);
280 BEAST_EXPECT(!v1.
exists(
k(2)));
281 BEAST_EXPECT(
seq(v1.
read(
k(3))) == 3);
282 BEAST_EXPECT(
seq(v1.
read(
k(4))) == 5);
285 auto s2 = v2.
peek(
k(3));
289 BEAST_EXPECT(
seq(v2.
read(
k(1))) == 1);
290 BEAST_EXPECT(!v2.
exists(
k(2)));
291 BEAST_EXPECT(
seq(v2.
read(
k(3))) == 6);
292 BEAST_EXPECT(!v2.
exists(
k(4)));
295 BEAST_EXPECT(
seq(v1.
read(
k(1))) == 1);
296 BEAST_EXPECT(!v1.
exists(
k(2)));
297 BEAST_EXPECT(
seq(v1.
read(
k(3))) == 3);
298 BEAST_EXPECT(
seq(v1.
read(
k(4))) == 5);
302 auto s2 = v2.
peek(
k(3));
306 BEAST_EXPECT(
seq(v2.
read(
k(1))) == 1);
307 BEAST_EXPECT(!v2.
exists(
k(2)));
308 BEAST_EXPECT(
seq(v2.
read(
k(3))) == 6);
309 BEAST_EXPECT(!v2.
exists(
k(4)));
312 BEAST_EXPECT(
seq(v1.
read(
k(1))) == 1);
313 BEAST_EXPECT(!v1.
exists(
k(2)));
314 BEAST_EXPECT(
seq(v1.
read(
k(3))) == 6);
315 BEAST_EXPECT(!v1.
exists(
k(4)));
318 BEAST_EXPECT(
seq(v0.
read(
k(1))) == 1);
319 BEAST_EXPECT(!v0.
exists(
k(2)));
320 BEAST_EXPECT(
seq(v0.
read(
k(3))) == 6);
321 BEAST_EXPECT(!v0.
exists(
k(4)));
335 BEAST_EXPECT(v0.
seq() != 98);
336 BEAST_EXPECT(v0.
seq() ==
open->seq());
342 BEAST_EXPECT(v1.
seq() == v0.
seq());
347 BEAST_EXPECT(v2.
seq() == v1.
seq());
351 BEAST_EXPECT(v3.
seq() == v2.
seq());
358 BEAST_EXPECT(v2.
seq() == v0.
seq());
362 BEAST_EXPECT(v3.
seq() == v2.
seq());
375 for (
auto const&
sle : ledger.
sles)
380 template <
class... Args>
397 env.
app().getNodeFamily());
398 auto const ledger = std::make_shared<Ledger>(
400 auto setup123 = [&ledger,
this]() {
403 ledger->rawInsert(
sle(1));
404 ledger->rawInsert(
sle(2));
405 ledger->rawInsert(
sle(3));
406 BEAST_EXPECT(
sles(*ledger) ==
list(1, 2, 3));
414 BEAST_EXPECT(
sles(view) ==
list(2, 3, 4, 5));
433 BEAST_EXPECT(
sles(view) ==
list(3, 4, 5));
452 BEAST_EXPECT(
sles(view) ==
list(4, 5));
468 BEAST_EXPECT(
sles(view) ==
list(1, 2, 4, 5));
485 BEAST_EXPECT(
sles(view) ==
list(1, 2, 3));
486 BEAST_EXPECT(
seq(view.
read(
k(1))) == 10);
487 BEAST_EXPECT(
seq(view.
read(
k(2))) == 1);
488 BEAST_EXPECT(
seq(view.
read(
k(3))) == 30);
491 BEAST_EXPECT(
sles(view) ==
list(1, 2));
504 BEAST_EXPECT(
sles(view) ==
list(1, 2, 3, 4, 5));
525 auto const alice =
Account(
"alice");
526 auto const bob =
Account(
"bob");
527 auto const carol =
Account(
"carol");
528 auto const gw =
Account(
"gateway");
529 auto const USD = gw[
"USD"];
530 auto const EUR = gw[
"EUR"];
532 env.
fund(
XRP(10000), alice, bob, carol, gw);
533 env.
trust(USD(100), alice, bob, carol);
536 env(
pay(gw, alice, USD(50)));
537 env(offer(alice,
XRP(5), USD(5)));
559 env(offer(
"alice",
XRP(4), USD(5)));
563 env(
pay(gw, bob, USD(50)));
596 env(
pay(gw, carol, USD(50)));
634 BEAST_EXPECT(carolsXRP ==
XRP(9750));
657 BEAST_EXPECT(gwUSD == USD(314159));
662 BEAST_EXPECT(carolsUSD == USD(50));
669 BEAST_EXPECT(carolsUSD == USD(0));
674 BEAST_EXPECT(carolsUSD == USD(50));
688 auto const gw1 =
Account(
"gw1");
693 auto rdView = env.
closed();
697 env(
rate(gw1, 1.02));
712 auto const alice =
Account(
"alice");
713 auto const bob =
Account(
"bob");
720 auto const rdViewA3 = eA.
closed();
724 auto const rdViewA4 = eA.
closed();
732 eB.fund(
XRP(10000), bob);
734 auto const rdViewB3 = eB.closed();
736 eB.fund(
XRP(10000), alice);
738 auto const rdViewB4 = eB.closed();
742 BEAST_EXPECT(
areCompatible(*rdViewA3, *rdViewA4, jStream,
""));
743 BEAST_EXPECT(
areCompatible(*rdViewA4, *rdViewA3, jStream,
""));
744 BEAST_EXPECT(
areCompatible(*rdViewA4, *rdViewA4, jStream,
""));
745 BEAST_EXPECT(!
areCompatible(*rdViewA3, *rdViewB4, jStream,
""));
746 BEAST_EXPECT(!
areCompatible(*rdViewA4, *rdViewB3, jStream,
""));
747 BEAST_EXPECT(!
areCompatible(*rdViewA4, *rdViewB4, jStream,
""));
751 auto const& iA3 = rdViewA3->info();
752 auto const& iA4 = rdViewA4->info();
754 BEAST_EXPECT(
areCompatible(iA3.hash, iA3.seq, *rdViewA4, jStream,
""));
755 BEAST_EXPECT(
areCompatible(iA4.hash, iA4.seq, *rdViewA3, jStream,
""));
756 BEAST_EXPECT(
areCompatible(iA4.hash, iA4.seq, *rdViewA4, jStream,
""));
757 BEAST_EXPECT(!
areCompatible(iA3.hash, iA3.seq, *rdViewB4, jStream,
""));
758 BEAST_EXPECT(
areCompatible(iA4.hash, iA4.seq, *rdViewB3, jStream,
""));
759 BEAST_EXPECT(!
areCompatible(iA4.hash, iA4.seq, *rdViewB4, jStream,
""));
774 std::make_shared<Ledger>(
778 env.
app().getNodeFamily());
779 auto const ledger = std::make_shared<Ledger>(
782 ledger->rawInsert(
sle(1));
790 BEAST_EXPECT(!v1.
exists(
k(1)));
806 BEAST_EXPECT(
k(0).key <
k(1).key);
831 BEAST_EXPECT(majorities.empty());
835 for (i = 0; i <= 256; ++i)
839 if (!majorities.empty())
845 BEAST_EXPECT(i == 254);
846 BEAST_EXPECT(majorities.size() >= 5);
850 BEAST_EXPECT(enableds.empty());
855 for (i = 0; i <= 256; ++i)
857 using namespace std::chrono_literals;
860 if (!enableds.empty())
863 BEAST_EXPECT(i == 255);
864 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)
std::optional< uint256 > succ(uint256 const &key, std::optional< uint256 > const &last=std::nullopt) const override
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.
const SF_UINT32 sfSequence
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.
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
std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const override
Return the key of the next state item.
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)
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the 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.
virtual std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const =0
Return the key of the next state item.
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 fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
const create_genesis_t create_genesis
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)
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.
void succ(ReadView const &v, std::uint32_t id, std::optional< std::uint32_t > answer)
Json::Value rate(Account const &account, double multiplier)
Set a transfer rate.
static std::uint32_t seq(std::shared_ptr< T > const &le)