xrpld
Loading...
Searching...
No Matches
xrpl::test::VaultTransactorPrecision_test Class Reference
Inheritance diagram for xrpl::test::VaultTransactorPrecision_test:
Collaboration diagram for xrpl::test::VaultTransactorPrecision_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 Suite * thisSuite ()
 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)
void advancePastDueDate (jtx::Env &env, Keylet const &loanKeylet)
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 Numbers read (jtx::Env const &env, Fixture const &f)
static Number oneUnit (Asset const &asset, Number const &assetsTotalAfter)
static Fixture setupSingleLoanVault (jtx::Env &env, bool impairAndPaySibling, bool allowClawback=false)
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"}

Static Protected Attributes

static constexpr std::uint32_t kFixturePaymentInterval = 86400u * 30u
static constexpr std::uint32_t kFixtureGracePeriod = 86400u * 30u
static constexpr std::uint32_t kFixturePaymentTotal = 120u
static constexpr std::uint32_t kFixtureInterestTenthBips = 1000u

Private Member Functions

jtx::Env makeEnv ()
bool ready (Fixture const &f)
void assertEqualDeltas (Numbers const &before, Numbers const &after, std::string const &tag)
void testDeposit ()
void testWithdraw ()
void testWithdrawInsufficientFundsPrecedence ()
void testClawback ()
void testImpairedVault ()
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 28 of file VaultTransactorPrecision_test.cpp.

Member Enumeration Documentation

◆ AssetType

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

Definition at line 699 of file LoanTestBase.h.

Member Function Documentation

◆ makeEnv()

jtx::Env xrpl::test::VaultTransactorPrecision_test::makeEnv ( )
private

Definition at line 31 of file VaultTransactorPrecision_test.cpp.

◆ ready()

bool xrpl::test::VaultTransactorPrecision_test::ready ( Fixture const & f)
private

Definition at line 37 of file VaultTransactorPrecision_test.cpp.

◆ assertEqualDeltas()

void xrpl::test::VaultTransactorPrecision_test::assertEqualDeltas ( Numbers const & before,
Numbers const & after,
std::string const & tag )
private

Definition at line 43 of file VaultTransactorPrecision_test.cpp.

◆ testDeposit()

void xrpl::test::VaultTransactorPrecision_test::testDeposit ( )
private

Definition at line 53 of file VaultTransactorPrecision_test.cpp.

◆ testWithdraw()

void xrpl::test::VaultTransactorPrecision_test::testWithdraw ( )
private

Definition at line 144 of file VaultTransactorPrecision_test.cpp.

◆ testWithdrawInsufficientFundsPrecedence()

void xrpl::test::VaultTransactorPrecision_test::testWithdrawInsufficientFundsPrecedence ( )
private

Definition at line 203 of file VaultTransactorPrecision_test.cpp.

◆ testClawback()

void xrpl::test::VaultTransactorPrecision_test::testClawback ( )
private

Definition at line 240 of file VaultTransactorPrecision_test.cpp.

◆ testImpairedVault()

void xrpl::test::VaultTransactorPrecision_test::testImpairedVault ( )
private

Definition at line 291 of file VaultTransactorPrecision_test.cpp.

◆ run()

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

Runs the suite.

Implements beast::unit_test::Suite.

Definition at line 350 of file VaultTransactorPrecision_test.cpp.

◆ read()

Numbers xrpl::test::VaultPrecisionFixture::read ( jtx::Env const & env,
Fixture const & f )
staticprotectedinherited

Definition at line 95 of file VaultPrecisionFixture.h.

◆ oneUnit()

Number xrpl::test::VaultPrecisionFixture::oneUnit ( Asset const & asset,
Number const & assetsTotalAfter )
staticprotectedinherited

Definition at line 116 of file VaultPrecisionFixture.h.

◆ setupSingleLoanVault()

Fixture xrpl::test::VaultPrecisionFixture::setupSingleLoanVault ( jtx::Env & env,
bool impairAndPaySibling,
bool allowClawback = false )
staticprotectedinherited

Definition at line 128 of file VaultPrecisionFixture.h.

◆ 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 487 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 583 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 614 of file LoanTestBase.h.

◆ canImpairLoan()

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

Definition at line 656 of file LoanTestBase.h.

◆ advancePastDueDate()

void xrpl::test::LoanTestBase::advancePastDueDate ( jtx::Env & env,
Keylet const & loanKeylet )
protectedinherited

Definition at line 688 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 703 of file LoanTestBase.h.

◆ nextLoanKeylet()

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

Definition at line 765 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 779 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 811 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 839 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 849 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 898 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 970 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 1008 of file LoanTestBase.h.

◆ runLoan()

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

Definition at line 1353 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 1402 of file LoanTestBase.h.

◆ getCurrencyLabel()

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

Definition at line 1717 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 1739 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

◆ kFixturePaymentInterval

std::uint32_t xrpl::test::VaultPrecisionFixture::kFixturePaymentInterval = 86400u * 30u
staticconstexprprotectedinherited

Definition at line 44 of file VaultPrecisionFixture.h.

◆ kFixtureGracePeriod

std::uint32_t xrpl::test::VaultPrecisionFixture::kFixtureGracePeriod = 86400u * 30u
staticconstexprprotectedinherited

Definition at line 45 of file VaultPrecisionFixture.h.

◆ kFixturePaymentTotal

std::uint32_t xrpl::test::VaultPrecisionFixture::kFixturePaymentTotal = 120u
staticconstexprprotectedinherited

Definition at line 46 of file VaultPrecisionFixture.h.

◆ kFixtureInterestTenthBips

std::uint32_t xrpl::test::VaultPrecisionFixture::kFixtureInterestTenthBips = 1000u
staticconstexprprotectedinherited

Definition at line 48 of file VaultPrecisionFixture.h.

◆ all_

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

Definition at line 91 of file LoanTestBase.h.

◆ iouCurrency_

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

Definition at line 92 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.