xrpld
Loading...
Searching...
No Matches
xrpl::test::LoanMisc_test Class Reference
Inheritance diagram for xrpl::test::LoanMisc_test:
Collaboration diagram for xrpl::test::LoanMisc_test:

Public Member Functions

void run () override
 Runs the suite.
template<class = void>
void operator() (Runner &r)
 Invokes the test using the specified runner.
template<class = void>
void pass ()
 Record a successful test condition.
template<class F, class String>
bool except (F &&f, String const &reason)
template<class F>
bool except (F &&f)
template<class E, class F, class String>
bool except (F &&f, String const &reason)
template<class E, class F>
bool except (F &&f)
template<class F, class String>
bool unexcept (F &&f, String const &reason)
template<class F>
bool unexcept (F &&f)
std::string const & arg () const
 Return the argument associated with the runner.
template<class Condition, class String>
bool unexpected (Condition shouldBeFalse, String const &reason)
 DEPRECATED.
template<class Condition>
bool unexpected (Condition shouldBeFalse)
template<class String>
void fail (String const &reason, char const *file, int line)
 Record a failure.
template<class = void>
void fail (std::string const &reason="")
template<class Condition>
bool expect (Condition const &shouldBeTrue)
 Evaluate a test condition.
template<class Condition, class String>
bool expect (Condition const &shouldBeTrue, String const &reason)
template<class Condition>
bool expect (Condition const &shouldBeTrue, char const *file, int line)
template<class Condition, class String>
bool expect (Condition const &shouldBeTrue, String const &reason, char const *file, int line)

Static Public Member Functions

static SuitethisSuite ()
 Returns the "current" running suite.

Public Attributes

LogOs< char > log
 Logging output stream.
TestcaseT testcase
 Memberspace for declaring test cases.

Protected Types

enum class  AssetType { XRP = 0 , IOU = 1 , MPT = 2 }

Protected Member Functions

BrokerInfo createVaultAndBroker (jtx::Env &env, jtx::PrettyAsset const &asset, jtx::Account const &lender, BrokerParameters const &params=BrokerParameters::defaults())
LoanState getCurrentState (jtx::Env const &env, BrokerInfo const &broker, Keylet const &loanKeylet)
 Get the state without checking anything.
LoanState getCurrentState (jtx::Env const &env, BrokerInfo const &broker, Keylet const &loanKeylet, VerifyLoanStatus const &verifyLoanStatus)
 Get the state and check the values against the parameters used in lifecycle.
bool canImpairLoan (jtx::Env const &env, BrokerInfo const &broker, LoanState const &state)
jtx::PrettyAsset createAsset (jtx::Env &env, AssetType assetType, BrokerParameters const &brokerParams, jtx::Account const &issuer, jtx::Account const &lender, jtx::Account const &borrower)
Keylet nextLoanKeylet (jtx::Env const &env, BrokerInfo const &broker)
jtx::PrettyAsset createFundedIouAsset (jtx::Env &env, jtx::Account const &issuer, jtx::Account const &lender, jtx::Account const &borrower, Number const &lenderPay=100 '000 '000, Number const &borrowerPay=1 '000 '000)
jtx::Account brokerPseudoAccount (jtx::Env const &env, BrokerInfo const &broker, jtx::Account const &fallback)
void describeLoan (jtx::Env &env, BrokerParameters const &brokerParams, LoanParameters const &loanParams, AssetType assetType, jtx::Account const &issuer, jtx::Account const &lender, jtx::Account const &borrower)
std::optional< std::tuple< BrokerInfo, Keylet, jtx::Account > > createLoan (jtx::Env &env, AssetType assetType, BrokerParameters const &brokerParams, LoanParameters const &loanParams, jtx::Account const &issuer, jtx::Account const &lender, jtx::Account const &borrower)
void makeLoanPayments (jtx::Env &env, BrokerInfo const &broker, LoanParameters const &loanParams, Keylet const &loanKeylet, VerifyLoanStatus const &verifyLoanStatus, jtx::Account const &issuer, jtx::Account const &lender, jtx::Account const &borrower, PaymentParameters const &paymentParams=PaymentParameters::defaults())
void runLoan (AssetType assetType, BrokerParameters const &brokerParams, LoanParameters const &loanParams, FeatureBitset features)
void lifecycle (std::string const &caseLabel, char const *label, jtx::Env &env, Number const &loanAmount, int interestExponent, jtx::Account const &lender, jtx::Account const &borrower, jtx::Account const &evan, BrokerInfo const &broker, jtx::Account const &pseudoAcct, std::uint32_t flags, std::function< void(Keylet const &loanKeylet, VerifyLoanStatus const &verifyLoanStatus)> toEndOfLife)
 Runs through the complete lifecycle of a loan.
template<class TAsset, std::size_t NAsset>
void testCaseWrapper (jtx::Env &env, jtx::MPTTester &mptt, std::array< TAsset, NAsset > const &assets, BrokerInfo const &broker, Number const &loanAmount, int interestExponent)
 Wrapper to run a series of lifecycle tests for a given asset and loan amount.
Runner & runner () const
 Lets a suite compose other suites (e.g.

Static Protected Member Functions

static jtx::PrettyAsset createFundedRippleIouAsset (jtx::Env &env, jtx::Account const &issuer, jtx::Account const &lender, jtx::Account const &borrower, Number const &lenderPay=1 '000 '000, Number const &borrowerPay=1 '000 '000)
static void topUpBorrower (jtx::Env &env, BrokerInfo const &broker, jtx::Account const &issuer, jtx::Account const &borrower, LoanState const &state, std::optional< Number > const &servFee)
static std::string getCurrencyLabel (Asset const &asset)

Protected Attributes

FeatureBitset const all_ {jtx::testableAmendments() - featureLendingProtocolV1_1}
std::string const iouCurrency_ {"IOU"}

Private Member Functions

void testRPC (FeatureBitset features)
void testLendingCanTradeDisabledNoImpact ()
void runAmendmentIndependent ()
void runAmendmentSensitive (FeatureBitset features)
void propagateAbort () const

Static Private Member Functions

static Suite ** pThisSuite ()

Private Attributes

bool abort_ = false
bool aborted_ = false
Runner * runner_ = nullptr

Detailed Description

Definition at line 39 of file LoanMisc_test.cpp.

Member Enumeration Documentation

◆ AssetType

enum class xrpl::test::LoanTestBase::AssetType
strongprotectedinherited
Enumerator
XRP 
IOU 
MPT 

Definition at line 649 of file LoanTestBase.h.

Member Function Documentation

◆ testRPC()

void xrpl::test::LoanMisc_test::testRPC ( FeatureBitset features)
private

Definition at line 43 of file LoanMisc_test.cpp.

◆ testLendingCanTradeDisabledNoImpact()

void xrpl::test::LoanMisc_test::testLendingCanTradeDisabledNoImpact ( )
private

Definition at line 347 of file LoanMisc_test.cpp.

◆ runAmendmentIndependent()

void xrpl::test::LoanMisc_test::runAmendmentIndependent ( )
private

Definition at line 410 of file LoanMisc_test.cpp.

◆ runAmendmentSensitive()

void xrpl::test::LoanMisc_test::runAmendmentSensitive ( FeatureBitset features)
private

Definition at line 417 of file LoanMisc_test.cpp.

◆ run()

void xrpl::test::LoanMisc_test::run ( )
overridevirtual

Runs the suite.

Implements beast::unit_test::Suite.

Definition at line 424 of file LoanMisc_test.cpp.

◆ createVaultAndBroker()

BrokerInfo xrpl::test::LoanTestBase::createVaultAndBroker ( jtx::Env & env,
jtx::PrettyAsset const & asset,
jtx::Account const & lender,
BrokerParameters const & params = BrokerParameters::defaults() )
protectedinherited

Definition at line 473 of file LoanTestBase.h.

◆ getCurrentState() [1/2]

LoanState xrpl::test::LoanTestBase::getCurrentState ( jtx::Env const & env,
BrokerInfo const & broker,
Keylet const & loanKeylet )
protectedinherited

Get the state without checking anything.

Definition at line 550 of file LoanTestBase.h.

◆ getCurrentState() [2/2]

LoanState xrpl::test::LoanTestBase::getCurrentState ( jtx::Env const & env,
BrokerInfo const & broker,
Keylet const & loanKeylet,
VerifyLoanStatus const & verifyLoanStatus )
protectedinherited

Get the state and check the values against the parameters used in lifecycle.

Definition at line 581 of file LoanTestBase.h.

◆ canImpairLoan()

bool xrpl::test::LoanTestBase::canImpairLoan ( jtx::Env const & env,
BrokerInfo const & broker,
LoanState const & state )
protectedinherited

Definition at line 623 of file LoanTestBase.h.

◆ createAsset()

jtx::PrettyAsset xrpl::test::LoanTestBase::createAsset ( jtx::Env & env,
AssetType assetType,
BrokerParameters const & brokerParams,
jtx::Account const & issuer,
jtx::Account const & lender,
jtx::Account const & borrower )
protectedinherited

Definition at line 653 of file LoanTestBase.h.

◆ nextLoanKeylet()

Keylet xrpl::test::LoanTestBase::nextLoanKeylet ( jtx::Env const & env,
BrokerInfo const & broker )
protectedinherited

Definition at line 715 of file LoanTestBase.h.

◆ createFundedIouAsset()

jtx::PrettyAsset xrpl::test::LoanTestBase::createFundedIouAsset ( jtx::Env & env,
jtx::Account const & issuer,
jtx::Account const & lender,
jtx::Account const & borrower,
Number const & lenderPay = 100'000'000,
Number const & borrowerPay = 1'000'000 )
protectedinherited

Definition at line 729 of file LoanTestBase.h.

◆ createFundedRippleIouAsset()

jtx::PrettyAsset xrpl::test::LoanTestBase::createFundedRippleIouAsset ( jtx::Env & env,
jtx::Account const & issuer,
jtx::Account const & lender,
jtx::Account const & borrower,
Number const & lenderPay = 1'000'000,
Number const & borrowerPay = 1'000'000 )
staticprotectedinherited

Definition at line 761 of file LoanTestBase.h.

◆ brokerPseudoAccount()

jtx::Account xrpl::test::LoanTestBase::brokerPseudoAccount ( jtx::Env const & env,
BrokerInfo const & broker,
jtx::Account const & fallback )
protectedinherited

Definition at line 789 of file LoanTestBase.h.

◆ describeLoan()

void xrpl::test::LoanTestBase::describeLoan ( jtx::Env & env,
BrokerParameters const & brokerParams,
LoanParameters const & loanParams,
AssetType assetType,
jtx::Account const & issuer,
jtx::Account const & lender,
jtx::Account const & borrower )
protectedinherited

Definition at line 799 of file LoanTestBase.h.

◆ createLoan()

std::optional< std::tuple< BrokerInfo, Keylet, jtx::Account > > xrpl::test::LoanTestBase::createLoan ( jtx::Env & env,
AssetType assetType,
BrokerParameters const & brokerParams,
LoanParameters const & loanParams,
jtx::Account const & issuer,
jtx::Account const & lender,
jtx::Account const & borrower )
protectedinherited

Definition at line 848 of file LoanTestBase.h.

◆ topUpBorrower()

void xrpl::test::LoanTestBase::topUpBorrower ( jtx::Env & env,
BrokerInfo const & broker,
jtx::Account const & issuer,
jtx::Account const & borrower,
LoanState const & state,
std::optional< Number > const & servFee )
staticprotectedinherited

Definition at line 920 of file LoanTestBase.h.

◆ makeLoanPayments()

void xrpl::test::LoanTestBase::makeLoanPayments ( jtx::Env & env,
BrokerInfo const & broker,
LoanParameters const & loanParams,
Keylet const & loanKeylet,
VerifyLoanStatus const & verifyLoanStatus,
jtx::Account const & issuer,
jtx::Account const & lender,
jtx::Account const & borrower,
PaymentParameters const & paymentParams = PaymentParameters::defaults() )
protectedinherited

Definition at line 958 of file LoanTestBase.h.

◆ runLoan()

void xrpl::test::LoanTestBase::runLoan ( AssetType assetType,
BrokerParameters const & brokerParams,
LoanParameters const & loanParams,
FeatureBitset features )
protectedinherited

Definition at line 1303 of file LoanTestBase.h.

◆ lifecycle()

void xrpl::test::LoanTestBase::lifecycle ( std::string const & caseLabel,
char const * label,
jtx::Env & env,
Number const & loanAmount,
int interestExponent,
jtx::Account const & lender,
jtx::Account const & borrower,
jtx::Account const & evan,
BrokerInfo const & broker,
jtx::Account const & pseudoAcct,
std::uint32_t flags,
std::function< void(Keylet const &loanKeylet, VerifyLoanStatus const &verifyLoanStatus)> toEndOfLife )
protectedinherited

Runs through the complete lifecycle of a loan.

  1. Create a loan.
  2. Test a bunch of transaction failure conditions.
  3. Use the toEndOfLife callback to take the loan to 0. How that is done depends on the callback. e.g. Default, Early payoff, make all the normal payments, etc.
  4. Delete the loan. The loan will alternate between being deleted by the lender and the borrower.

Definition at line 1352 of file LoanTestBase.h.

◆ getCurrencyLabel()

std::string xrpl::test::LoanTestBase::getCurrencyLabel ( Asset const & asset)
staticprotectedinherited

Definition at line 1649 of file LoanTestBase.h.

◆ testCaseWrapper()

template<class TAsset, std::size_t NAsset>
void xrpl::test::LoanTestBase::testCaseWrapper ( jtx::Env & env,
jtx::MPTTester & mptt,
std::array< TAsset, NAsset > const & assets,
BrokerInfo const & broker,
Number const & loanAmount,
int interestExponent )
protectedinherited

Wrapper to run a series of lifecycle tests for a given asset and loan amount.

Will be used in the future to vary the loan parameters. For now, it is only called once.

Tests a bunch of LoanSet failure conditions before lifecycle.

Definition at line 1671 of file LoanTestBase.h.

◆ thisSuite()

Suite * beast::unit_test::Suite::thisSuite ( )
staticinherited

Returns the "current" running suite.

If no suite is running, nullptr is returned.

Definition at line 162 of file suite.h.

◆ operator()()

template<class>
void beast::unit_test::Suite::operator() ( Runner & r)
inherited

Invokes the test using the specified runner.

Data members are set up here instead of the constructor as a convenience to writing the derived class to avoid repetition of forwarded constructor arguments to the base. Normally this is called by the framework for you.

Definition at line 420 of file suite.h.

◆ pass()

template<class>
void beast::unit_test::Suite::pass ( )
inherited

Record a successful test condition.

Definition at line 532 of file suite.h.

◆ fail() [1/2]

template<class String>
void beast::unit_test::Suite::fail ( String const & reason,
char const * file,
int line )
inherited

Record a failure.

Parameters
reasonOptional text added to the output on a failure.
fileThe source code file where the test failed.
lineThe source code line number where the test failed.

Definition at line 554 of file suite.h.

◆ fail() [2/2]

template<class>
void beast::unit_test::Suite::fail ( std::string const & reason = "")
inherited

Definition at line 541 of file suite.h.

◆ expect() [1/4]

template<class Condition>
bool beast::unit_test::Suite::expect ( Condition const & shouldBeTrue)
inherited

Evaluate a test condition.

This function provides improved logging by incorporating the file name and line number into the reported output on failure, as well as additional text specified by the caller.

Parameters
shouldBeTrueThe condition to test. The condition is evaluated in a boolean context.
reasonOptional added text to output on a failure.
fileThe source code file where the test failed.
lineThe source code line number where the test failed.
Returns
true if the test condition indicates success.

Definition at line 235 of file suite.h.

◆ expect() [2/4]

template<class Condition, class String>
bool beast::unit_test::Suite::expect ( Condition const & shouldBeTrue,
String const & reason )
inherited

Definition at line 437 of file suite.h.

◆ expect() [3/4]

template<class Condition>
bool beast::unit_test::Suite::expect ( Condition const & shouldBeTrue,
char const * file,
int line )
inherited

Definition at line 246 of file suite.h.

◆ expect() [4/4]

template<class Condition, class String>
bool beast::unit_test::Suite::expect ( Condition const & shouldBeTrue,
String const & reason,
char const * file,
int line )
inherited

Definition at line 450 of file suite.h.

◆ except() [1/4]

template<class F, class String>
bool beast::unit_test::Suite::except ( F && f,
String const & reason )
inherited

Definition at line 465 of file suite.h.

◆ except() [2/4]

template<class F>
bool beast::unit_test::Suite::except ( F && f)
inherited

Definition at line 265 of file suite.h.

◆ except() [3/4]

template<class E, class F, class String>
bool beast::unit_test::Suite::except ( F && f,
String const & reason )
inherited

Definition at line 482 of file suite.h.

◆ except() [4/4]

template<class E, class F>
bool beast::unit_test::Suite::except ( F && f)
inherited

Definition at line 274 of file suite.h.

◆ unexcept() [1/2]

template<class F, class String>
bool beast::unit_test::Suite::unexcept ( F && f,
String const & reason )
inherited

Definition at line 499 of file suite.h.

◆ unexcept() [2/2]

template<class F>
bool beast::unit_test::Suite::unexcept ( F && f)
inherited

Definition at line 283 of file suite.h.

◆ arg()

std::string const & beast::unit_test::Suite::arg ( ) const
inherited

Return the argument associated with the runner.

Definition at line 292 of file suite.h.

◆ runner()

Runner & beast::unit_test::Suite::runner ( ) const
protectedinherited

Lets a suite compose other suites (e.g.

an aggregator that reruns a group of related suites under its own name) via SuiteInfo::run.

Returns
The runner this suite is executing under.

Definition at line 305 of file suite.h.

◆ unexpected() [1/2]

template<class Condition, class String>
bool beast::unit_test::Suite::unexpected ( Condition shouldBeFalse,
String const & reason )
inherited

DEPRECATED.

Returns
true if the test condition indicates success(a false value)

Definition at line 516 of file suite.h.

◆ unexpected() [2/2]

template<class Condition>
bool beast::unit_test::Suite::unexpected ( Condition shouldBeFalse)
inherited

Definition at line 321 of file suite.h.

◆ pThisSuite()

Suite ** beast::unit_test::Suite::pThisSuite ( )
staticprivateinherited

Definition at line 330 of file suite.h.

◆ propagateAbort()

void beast::unit_test::Suite::propagateAbort ( ) const
privateinherited

Definition at line 560 of file suite.h.

Member Data Documentation

◆ all_

FeatureBitset const xrpl::test::LoanTestBase::all_ {jtx::testableAmendments() - featureLendingProtocolV1_1}
protectedinherited

Definition at line 81 of file LoanTestBase.h.

◆ iouCurrency_

std::string const xrpl::test::LoanTestBase::iouCurrency_ {"IOU"}
protectedinherited

Definition at line 82 of file LoanTestBase.h.

◆ abort_

bool beast::unit_test::Suite::abort_ = false
privateinherited

Definition at line 54 of file suite.h.

◆ aborted_

bool beast::unit_test::Suite::aborted_ = false
privateinherited

Definition at line 55 of file suite.h.

◆ runner_

Runner* beast::unit_test::Suite::runner_ = nullptr
privateinherited

Definition at line 56 of file suite.h.

◆ log

LogOs<char> beast::unit_test::Suite::log
inherited

Logging output stream.

Text sent to the log output stream will be forwarded to the output stream associated with the runner.

Definition at line 150 of file suite.h.

◆ testcase

TestcaseT beast::unit_test::Suite::testcase
inherited

Memberspace for declaring test cases.

Definition at line 155 of file suite.h.