xrpld
Loading...
Searching...
No Matches
xrpl::test::AMMCalc_test Class Reference

AMM Calculator. More...

Inheritance diagram for xrpl::test::AMMCalc_test:
Collaboration diagram for xrpl::test::AMMCalc_test:

Public Member Functions

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)
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.

Private Types

using token_iter = boost::sregex_token_iterator
using steps = std::vector<std::pair<Amounts, bool>>
using transfer_rates = std::map<std::string, std::uint32_t>
using swapargs = std::tuple<steps, STAmount, transfer_rates, std::uint32_t>

Private Member Functions

std::optional< STAmountgetAmt (token_iter const &p, bool *delimited=nullptr)
std::optional< std::tuple< std::string, std::uint32_t, bool > > getRate (token_iter const &p)
std::uint32_t getFee (token_iter const &p)
std::optional< std::pair< Amounts, bool > > getAmounts (token_iter &p)
std::optional< transfer_ratesgetTransferRate (token_iter &p)
std::optional< swapargsgetSwap (token_iter &p)
void run () override
 Runs the suite.
void propagateAbort () const

Static Private Member Functions

static std::string toString (STAmount const &a)
static STAmount mulratio (STAmount const &amt, std::uint32_t a, std::uint32_t b, bool round)
static void swapOut (swapargs const &args)
static void swapIn (swapargs const &args)
static Suite ** pThisSuite ()

Private Attributes

jtx::Account const gw_ {jtx::Account("gw")}
token_iter const end_
bool abort_ = false
bool aborted_ = false
Runner * runner_ = nullptr

Detailed Description

AMM Calculator.

Uses AMM formulas to simulate the payment engine expected results. Assuming the formulas are correct some unit-tests can be verified. Currently supported operations are:

  • swapIn, find out given in. in can flow through multiple AMM/Offer steps.
  • swapOut, find in given out. out can flow through multiple AMM/Offer steps.
  • lptokens, find lptokens given pool composition.
  • changespq, change AMM spot price (SP) quality. given AMM and Offer find out AMM offer, which changes AMM's SP quality to the Offer's quality.

Definition at line 44 of file AMMCalc_test.cpp.

Member Typedef Documentation

◆ token_iter

using xrpl::test::AMMCalc_test::token_iter = boost::sregex_token_iterator
private

Definition at line 46 of file AMMCalc_test.cpp.

◆ steps

Definition at line 47 of file AMMCalc_test.cpp.

◆ transfer_rates

◆ swapargs

Member Function Documentation

◆ getAmt()

std::optional< STAmount > xrpl::test::AMMCalc_test::getAmt ( token_iter const & p,
bool * delimited = nullptr )
private

Definition at line 54 of file AMMCalc_test.cpp.

◆ getRate()

std::optional< std::tuple< std::string, std::uint32_t, bool > > xrpl::test::AMMCalc_test::getRate ( token_iter const & p)
private

Definition at line 83 of file AMMCalc_test.cpp.

◆ getFee()

std::uint32_t xrpl::test::AMMCalc_test::getFee ( token_iter const & p)
private

Definition at line 104 of file AMMCalc_test.cpp.

◆ getAmounts()

std::optional< std::pair< Amounts, bool > > xrpl::test::AMMCalc_test::getAmounts ( token_iter & p)
private

Definition at line 115 of file AMMCalc_test.cpp.

◆ getTransferRate()

std::optional< transfer_rates > xrpl::test::AMMCalc_test::getTransferRate ( token_iter & p)
private

Definition at line 131 of file AMMCalc_test.cpp.

◆ getSwap()

std::optional< swapargs > xrpl::test::AMMCalc_test::getSwap ( token_iter & p)
private

Definition at line 158 of file AMMCalc_test.cpp.

◆ toString()

std::string xrpl::test::AMMCalc_test::toString ( STAmount const & a)
staticprivate

Definition at line 188 of file AMMCalc_test.cpp.

◆ mulratio()

STAmount xrpl::test::AMMCalc_test::mulratio ( STAmount const & amt,
std::uint32_t a,
std::uint32_t b,
bool round )
staticprivate

Definition at line 195 of file AMMCalc_test.cpp.

◆ swapOut()

void xrpl::test::AMMCalc_test::swapOut ( swapargs const & args)
staticprivate

Definition at line 205 of file AMMCalc_test.cpp.

◆ swapIn()

void xrpl::test::AMMCalc_test::swapIn ( swapargs const & args)
staticprivate

Definition at line 268 of file AMMCalc_test.cpp.

◆ run()

void xrpl::test::AMMCalc_test::run ( )
overrideprivatevirtual

Runs the suite.

Implements beast::unit_test::Suite.

Definition at line 331 of file AMMCalc_test.cpp.

◆ thisSuite()

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

Returns the "current" running suite.

If no suite is running, nullptr is returned.

Definition at line 155 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 388 of file suite.h.

◆ pass()

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

Record a successful test condition.

Definition at line 500 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 522 of file suite.h.

◆ fail() [2/2]

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

Definition at line 509 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 223 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 405 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 234 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 418 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 433 of file suite.h.

◆ except() [2/4]

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

Definition at line 253 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 450 of file suite.h.

◆ except() [4/4]

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

Definition at line 262 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 467 of file suite.h.

◆ unexcept() [2/2]

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

Definition at line 271 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 278 of file suite.h.

◆ unexpected() [1/2]

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

Definition at line 484 of file suite.h.

◆ unexpected() [2/2]

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

Definition at line 291 of file suite.h.

◆ pThisSuite()

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

Definition at line 300 of file suite.h.

◆ propagateAbort()

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

Definition at line 528 of file suite.h.

Member Data Documentation

◆ gw_

jtx::Account const xrpl::test::AMMCalc_test::gw_ {jtx::Account("gw")}
private

Definition at line 50 of file AMMCalc_test.cpp.

◆ end_

token_iter const xrpl::test::AMMCalc_test::end_
private

Definition at line 51 of file AMMCalc_test.cpp.

◆ abort_

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

Definition at line 52 of file suite.h.

◆ aborted_

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

Definition at line 53 of file suite.h.

◆ runner_

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

Definition at line 54 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 146 of file suite.h.

◆ testcase

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

Memberspace for declaring test cases.

Definition at line 149 of file suite.h.