1#include <test/app/invariants/InvariantsBase.h>
3#include <test/jtx/Account.h>
4#include <test/jtx/Env.h>
5#include <test/jtx/TestHelpers.h>
6#include <test/jtx/amount.h>
7#include <test/jtx/envconfig.h>
8#include <test/jtx/fee.h>
9#include <test/jtx/tags.h>
10#include <test/jtx/vault.h>
11#include <test/unit_test/SuiteJournal.h>
13#include <xrpl/basics/Number.h>
14#include <xrpl/basics/base_uint.h>
15#include <xrpl/beast/unit_test/suite.h>
16#include <xrpl/beast/utility/Journal.h>
17#include <xrpl/ledger/ApplyView.h>
18#include <xrpl/ledger/OpenView.h>
19#include <xrpl/protocol/AccountID.h>
20#include <xrpl/protocol/Feature.h>
21#include <xrpl/protocol/Indexes.h>
22#include <xrpl/protocol/Keylet.h>
23#include <xrpl/protocol/Protocol.h>
24#include <xrpl/protocol/Rules.h>
25#include <xrpl/protocol/SField.h>
26#include <xrpl/protocol/STLedgerEntry.h>
27#include <xrpl/protocol/STTx.h>
28#include <xrpl/protocol/SeqProxy.h>
29#include <xrpl/protocol/TER.h>
30#include <xrpl/protocol/XRPAmount.h>
31#include <xrpl/tx/ApplyContext.h>
32#include <xrpl/tx/Transactor.h>
33#include <xrpl/tx/applySteps.h>
39#include <source_location>
94 env.fund(
XRP(1000), a1, a2);
96 BEAST_EXPECT(preclose(a1, a2, env));
103 std::move(env), a1, a2, expectLogs, precheck, fee, tx, ters, loc, initialResult);
131 BEAST_EXPECT(precheck(a1, a2, ac));
134 if (!BEAST_EXPECT(transactor))
142 if (!BEAST_EXPECT(ters.
size() == 2))
145 TER terActual = initialResult;
146 for (
TER const& terExpect : ters)
148 TER const terInput = terActual;
151 terExpect == terActual,
160 if (terActual != terInput)
163 messages.starts_with(
"Invariant failed:") ||
164 messages.starts_with(
"Transaction caused an exception"),
171 for (
auto const& m : expectLogs)
191 Vault const vault{env};
192 auto [tx, vKeylet, _] = vault.createClosedEnded(
198 BEAST_EXPECT(env.
le(vKeylet));
200 vaultID = vKeylet.key;
209 return loanBrokerKeylet;
221 sleLoan->at(sfLoanBrokerID) = loanBrokerID;
222 sleLoan->at(sfLoanSequence) = loanSeq;
223 sleLoan->at(sfBorrower) = borrower;
224 sleLoan->at(sfStartDate) = 0u;
225 sleLoan->at(sfPaymentInterval) = 1u;
226 sleLoan->at(sfPeriodicPayment) =
Number(1);
229 sleLoan->at(sfLoanServiceFee) =
Number(0);
230 sleLoan->at(sfLatePaymentFee) =
Number(0);
231 sleLoan->at(sfClosePaymentFee) =
Number(0);
232 sleLoan->at(sfPrincipalOutstanding) =
Number(0);
233 sleLoan->at(sfTotalValueOutstanding) =
Number(0);
234 sleLoan->at(sfManagementFeeOutstanding) =
Number(0);
235 sleLoan->setFieldU32(sfPaymentRemaining, 0);
236 sleLoan->makeFieldPresent(sfOwnerNode);
237 sleLoan->makeFieldPresent(sfLoanBrokerNode);
A generic endpoint for log messages.
bool expect(Condition const &shouldBeTrue)
Evaluate a test condition.
State information when applying a tx.
RAII class to set and restore the current transaction rules.
Number is a floating point type that can represent a wide range of values.
Writable ledger view that accumulates state and tx changes.
Rules const & rules() const override
Returns the tx processing rules.
std::shared_ptr< STLedgerEntry > pointer
void setAccountID(SField const &field, AccountID const &)
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Keylet createLoanBroker(jtx::Account const &a, jtx::Env &env, jtx::PrettyAsset const &asset)
std::function< bool(test::jtx::Account const &a, test::jtx::Account const &b, ApplyContext &ac)> Precheck
test::jtx::Env makeEnv(FeatureBitset features)
void doInvariantCheck(std::vector< std::string > const &expectLogs, Precheck const &precheck, XRPAmount fee=XRPAmount{}, STTx tx=STTx{ttACCOUNT_SET, [](STObject &) {}}, std::initializer_list< TER > ters={tecINVARIANT_FAILED, tefINVARIANT_FAILED}, Preclose const &preclose={}, TxAccount setTxAccount=TxAccount::None, std::source_location const &loc=std::source_location::current(), TER initialResult=tesSUCCESS)
Run a specific test case to put the ledger into a state that will be detected by an invariant.
static SLE::pointer makeLoanSle(UInt256 const &loanBrokerID, std::uint32_t loanSeq, AccountID const &borrower)
std::function< bool(test::jtx::Account const &a, test::jtx::Account const &b, test::jtx::Env &env)> Preclose
std::stringstream const & messages() const
Immutable cryptographic account descriptor.
AccountID id() const
Returns the Account ID.
A transaction testing environment.
SLE::const_pointer le(Account const &account) const
Return an account root.
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
Keylet loanBroker(AccountID const &owner, SeqProxy const &seq) noexcept
Keylet loan(UInt256 const &loanBrokerID, SeqProxy const &loanSeq) noexcept
XrpT const XRP
Converts to XRP Issue or STAmount.
FeatureBitset testableAmendments()
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
static IncrementT const kIncrement
constexpr XRPAmount
Convert XRP to drops (integral types).
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,...
std::string transToken(TER code)
std::unique_ptr< Transactor > makeTransactor(ApplyContext &ctx)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
TERSubset< CanCvtToTER > TER
constexpr std::uint32_t kMinInvestmentPeriod
Bounds on the length of a closed-ended vault's Investment phase (RedemptionDate - SubscriptionDate).
A pair of SHAMap key and LedgerEntryType.