xrpld
Loading...
Searching...
No Matches
xrpl::test::jtx::MPTTester Class Reference

Test helper for creating, mutating, and asserting MPT and confidential MPT ledger state. More...

#include <mpt.h>

Collaboration diagram for xrpl::test::jtx::MPTTester:

Public Types

enum class  EncryptedBalanceType { IssuerEncryptedBalance , HolderEncryptedInbox , HolderEncryptedSpending , AuditorEncryptedBalance }

Public Member Functions

 MPTTester (Env &env, Account issuer, MPTInit const &constr={})
 MPTTester (MPTInitDef const &constr)
 MPTTester (Env &env, Account issuer, MPTID const &id, std::vector< Account > const &holders={}, bool close=true)
 operator MPT () const
void create (MPTCreate const &arg=MPTCreate{})
void destroy (MPTDestroy const &arg=MPTDestroy{})
void authorize (MPTAuthorize const &arg=MPTAuthorize{})
void authorizeHolders (Holders const &holders)
void set (MPTSet const &set={})
void convert (MPTConvert const &arg=MPTConvert{})
json::Value convertJV (MPTConvert const &arg, std::uint32_t seq)
 Build a confidential convert JV without submitting it.
void mergeInbox (MPTMergeInbox const &arg=MPTMergeInbox{})
json::Value mergeInboxJV (MPTMergeInbox const &arg=MPTMergeInbox{}) const
void send (MPTConfidentialSend const &arg=MPTConfidentialSend{})
json::Value sendJV (MPTConfidentialSend const &arg, std::uint32_t seq, std::optional< ConfidentialSendChainState > chain=std::nullopt)
 Build a confidential send JV.
ConfidentialSendChainState chainAfterSend (Account const &sender, std::uint64_t sendAmt, json::Value const &jv) const
 Compute the projected sender state after a confidential send in a batch.
void convertBack (MPTConvertBack const &arg=MPTConvertBack{})
json::Value convertBackJV (MPTConvertBack const &arg, std::uint32_t seq)
 Build a confidential convertBack JV without submitting it.
void confidentialClaw (MPTConfidentialClawback const &arg=MPTConfidentialClawback{})
bool checkDomainID (std::optional< uint256 > expected) const
bool checkMPTokenAmount (Account const &holder, std::int64_t expectedAmount) const
bool checkMPTokenOutstandingAmount (std::int64_t expectedAmount) const
bool checkIssuanceConfidentialBalance (std::int64_t expectedAmount) const
bool checkFlags (uint32_t const expectedFlags, std::optional< Account > const &holder=std::nullopt) const
bool checkMetadata (std::string const &metadata) const
bool isMetadataPresent () const
bool checkTransferFee (std::uint16_t transferFee) const
bool isTransferFeePresent () const
bool checkImmutableFlags (std::uint32_t expectedFlags) const
Account const & issuer () const
Account const & holder (std::string const &h) const
void pay (Account const &src, Account const &dest, std::int64_t amount, std::optional< TER > err=std::nullopt, std::optional< std::vector< std::string > > credentials=std::nullopt)
void claw (Account const &issuer, Account const &holder, std::int64_t amount, std::optional< TER > err=std::nullopt)
PrettyAmount mpt (std::int64_t amount) const
MPTID const & issuanceID () const
std::int64_t getBalance (Account const &account) const
std::int64_t getIssuanceConfidentialBalance () const
std::optional< BuffergetEncryptedBalance (Account const &account, EncryptedBalanceType option=holderEncryptedInbox) const
MPT operator[] (std::string const &name) const
PrettyAmount operator() (std::int64_t amount) const
 operator Asset () const
void generateKeyPair (Account const &account)
std::optional< BuffergetPubKey (Account const &account) const
std::optional< BuffergetPrivKey (Account const &account) const
Buffer encryptAmount (Account const &account, uint64_t const amt, Buffer const &blindingFactor) const
std::optional< uint64_t > decryptAmount (Account const &account, Buffer const &amt) const
std::optional< uint64_t > getDecryptedBalance (Account const &account, EncryptedBalanceType balanceType) const
std::optional< std::int64_tgetIssuanceOutstandingBalance () const
std::optional< BuffergetClawbackProof (Account const &holder, std::uint64_t amount, Buffer const &privateKey, uint256 const &txHash) const
std::optional< BuffergetSchnorrProof (Account const &account, uint256 const &ctxHash) const
std::optional< BuffergetConfidentialSendProof (Account const &sender, std::uint64_t const amount, std::vector< ConfidentialRecipient > const &recipients, Slice const &blindingFactor, uint256 const &contextHash, PedersenProofParams const &amountParams, PedersenProofParams const &balanceParams) const
Buffer getConvertBackProof (Account const &holder, std::uint64_t const amount, uint256 const &contextHash, PedersenProofParams const &pcParams) const
std::uint32_t getMPTokenVersion (Account const account) const

Static Public Member Functions

static json::Value createJV (MPTCreate const &arg=MPTCreate{})
static json::Value destroyJV (MPTDestroy const &arg=MPTDestroy{})
static json::Value authorizeJV (MPTAuthorize const &arg=MPTAuthorize{})
static json::Value setJV (MPTSet const &set={})
static Buffer getPedersenCommitment (std::uint64_t const amount, Buffer const &pedersenBlindingFactor)

Static Public Attributes

static constexpr auto issuerEncryptedBalance = EncryptedBalanceType::IssuerEncryptedBalance
static constexpr auto holderEncryptedInbox = EncryptedBalanceType::HolderEncryptedInbox
static constexpr auto holderEncryptedSpending = EncryptedBalanceType::HolderEncryptedSpending
static constexpr auto auditorEncryptedBalance = EncryptedBalanceType::AuditorEncryptedBalance

Private Types

using SLEP = SLE::const_pointer

Private Member Functions

bool forObject (std::function< bool(SLEP const &sle)> const &cb, std::optional< Account > const &holder=std::nullopt) const
template<typename A>
TER submit (A const &arg, json::Value jv)
std::uint32_t getFlags (std::optional< Account > const &holder) const
template<typename T>
void fillConversionCiphertexts (T const &arg, json::Value &jv, Buffer &holderCiphertext, Buffer &issuerCiphertext, std::optional< Buffer > &auditorCiphertext, Buffer &blindingFactor) const

Static Private Member Functions

static std::unordered_map< std::string, AccountmakeHolders (std::vector< Account > const &holders)

Private Attributes

Envenv_
Account const issuer_
std::unordered_map< std::string, Account > const holders_
std::optional< Account > const auditor_
std::optional< MPTIDid_
bool close_
std::unordered_map< AccountID, BufferpubKeys_
std::unordered_map< AccountID, BufferprivKeys_

Friends

BookSpec operator~ (MPTTester const &mpt)

Detailed Description

Test helper for creating, mutating, and asserting MPT and confidential MPT ledger state.

Definition at line 446 of file mpt.h.

Member Typedef Documentation

◆ SLEP

Definition at line 727 of file mpt.h.

Member Enumeration Documentation

◆ EncryptedBalanceType

Enumerator
IssuerEncryptedBalance 
HolderEncryptedInbox 
HolderEncryptedSpending 
AuditorEncryptedBalance 

Definition at line 458 of file mpt.h.

Constructor & Destructor Documentation

◆ MPTTester() [1/3]

xrpl::test::jtx::MPTTester::MPTTester ( Env & env,
Account issuer,
MPTInit const & constr = {} )

Definition at line 128 of file mpt.cpp.

◆ MPTTester() [2/3]

xrpl::test::jtx::MPTTester::MPTTester ( MPTInitDef const & constr)

Definition at line 195 of file mpt.cpp.

◆ MPTTester() [3/3]

xrpl::test::jtx::MPTTester::MPTTester ( Env & env,
Account issuer,
MPTID const & id,
std::vector< Account > const & holders = {},
bool close = true )

Definition at line 163 of file mpt.cpp.

Member Function Documentation

◆ operator MPT()

xrpl::test::jtx::MPTTester::operator MPT ( ) const

Definition at line 208 of file mpt.cpp.

◆ create()

void xrpl::test::jtx::MPTTester::create ( MPTCreate const & arg = MPTCreate{})

Definition at line 241 of file mpt.cpp.

◆ createJV()

json::Value xrpl::test::jtx::MPTTester::createJV ( MPTCreate const & arg = MPTCreate{})
static

Definition at line 217 of file mpt.cpp.

◆ destroy()

void xrpl::test::jtx::MPTTester::destroy ( MPTDestroy const & arg = MPTDestroy{})

Definition at line 319 of file mpt.cpp.

◆ destroyJV()

json::Value xrpl::test::jtx::MPTTester::destroyJV ( MPTDestroy const & arg = MPTDestroy{})
static

Definition at line 306 of file mpt.cpp.

◆ authorize()

void xrpl::test::jtx::MPTTester::authorize ( MPTAuthorize const & arg = MPTAuthorize{})

Definition at line 353 of file mpt.cpp.

◆ authorizeJV()

json::Value xrpl::test::jtx::MPTTester::authorizeJV ( MPTAuthorize const & arg = MPTAuthorize{})
static

Definition at line 338 of file mpt.cpp.

◆ authorizeHolders()

void xrpl::test::jtx::MPTTester::authorizeHolders ( Holders const & holders)

Definition at line 415 of file mpt.cpp.

◆ set()

void xrpl::test::jtx::MPTTester::set ( MPTSet const & set = {})

Definition at line 467 of file mpt.cpp.

◆ setJV()

json::Value xrpl::test::jtx::MPTTester::setJV ( MPTSet const & set = {})
static

Definition at line 424 of file mpt.cpp.

◆ convert()

void xrpl::test::jtx::MPTTester::convert ( MPTConvert const & arg = MPTConvert{})

Definition at line 1070 of file mpt.cpp.

◆ convertJV()

json::Value xrpl::test::jtx::MPTTester::convertJV ( MPTConvert const & arg,
std::uint32_t seq )

Build a confidential convert JV without submitting it.

Parameters
argTransaction builder arguments.
seqInner transaction sequence used in the Schnorr proof context hash.
Returns
The transaction JSON object.

Definition at line 1243 of file mpt.cpp.

◆ mergeInbox()

void xrpl::test::jtx::MPTTester::mergeInbox ( MPTMergeInbox const & arg = MPTMergeInbox{})

Definition at line 2148 of file mpt.cpp.

◆ mergeInboxJV()

json::Value xrpl::test::jtx::MPTTester::mergeInboxJV ( MPTMergeInbox const & arg = MPTMergeInbox{}) const
nodiscard

Definition at line 2122 of file mpt.cpp.

◆ send()

void xrpl::test::jtx::MPTTester::send ( MPTConfidentialSend const & arg = MPTConfidentialSend{})

Definition at line 1305 of file mpt.cpp.

◆ sendJV()

json::Value xrpl::test::jtx::MPTTester::sendJV ( MPTConfidentialSend const & arg,
std::uint32_t seq,
std::optional< ConfidentialSendChainState > chain = std::nullopt )

Build a confidential send JV.

When chain is provided, the sender's proof parameters are taken from it instead of the ledger, enabling proof generation for a second or later send from the same account inside a single batch.

Parameters
argTransaction builder arguments.
seqInner transaction sequence used in the proof context hash.
chainOptional predicted sender state from a previous batched send.
Returns
The transaction JSON object.

Definition at line 1643 of file mpt.cpp.

◆ chainAfterSend()

ConfidentialSendChainState xrpl::test::jtx::MPTTester::chainAfterSend ( Account const & sender,
std::uint64_t sendAmt,
json::Value const & jv ) const
nodiscard

Compute the projected sender state after a confidential send in a batch.

Each confidential send requires a ZK proof that the sender's spending balance covers the transfer. In a batch, the second and later sends from the same sender need proofs built against the updated spending balance.

Parameters
senderThe sender whose post-send state is being predicted.
sendAmtThe plaintext amount sent by the transaction.
jvThe confidential send transaction JSON object.
Returns
The predicted sender state after applying the send.

Definition at line 1869 of file mpt.cpp.

◆ convertBack()

void xrpl::test::jtx::MPTTester::convertBack ( MPTConvertBack const & arg = MPTConvertBack{})

Definition at line 2270 of file mpt.cpp.

◆ convertBackJV()

json::Value xrpl::test::jtx::MPTTester::convertBackJV ( MPTConvertBack const & arg,
std::uint32_t seq )

Build a confidential convertBack JV without submitting it.

Reads the current encrypted spending balance and version from the ledger, so call this before the batch is submitted.

Parameters
argTransaction builder arguments.
seqInner transaction sequence used in the proof context hash.
Returns
The transaction JSON object.

Definition at line 2437 of file mpt.cpp.

◆ confidentialClaw()

void xrpl::test::jtx::MPTTester::confidentialClaw ( MPTConfidentialClawback const & arg = MPTConfidentialClawback{})

Definition at line 1909 of file mpt.cpp.

◆ checkDomainID()

bool xrpl::test::jtx::MPTTester::checkDomainID ( std::optional< uint256 > expected) const
nodiscard

Definition at line 572 of file mpt.cpp.

◆ checkMPTokenAmount()

bool xrpl::test::jtx::MPTTester::checkMPTokenAmount ( Account const & holder,
std::int64_t expectedAmount ) const
nodiscard

Definition at line 582 of file mpt.cpp.

◆ checkMPTokenOutstandingAmount()

bool xrpl::test::jtx::MPTTester::checkMPTokenOutstandingAmount ( std::int64_t expectedAmount) const
nodiscard

Definition at line 589 of file mpt.cpp.

◆ checkIssuanceConfidentialBalance()

bool xrpl::test::jtx::MPTTester::checkIssuanceConfidentialBalance ( std::int64_t expectedAmount) const
nodiscard

Definition at line 596 of file mpt.cpp.

◆ checkFlags()

bool xrpl::test::jtx::MPTTester::checkFlags ( uint32_t const expectedFlags,
std::optional< Account > const & holder = std::nullopt ) const
nodiscard

Definition at line 604 of file mpt.cpp.

◆ checkMetadata()

bool xrpl::test::jtx::MPTTester::checkMetadata ( std::string const & metadata) const
nodiscard

Definition at line 610 of file mpt.cpp.

◆ isMetadataPresent()

bool xrpl::test::jtx::MPTTester::isMetadataPresent ( ) const
nodiscard

Definition at line 620 of file mpt.cpp.

◆ checkTransferFee()

bool xrpl::test::jtx::MPTTester::checkTransferFee ( std::uint16_t transferFee) const
nodiscard

Definition at line 627 of file mpt.cpp.

◆ isTransferFeePresent()

bool xrpl::test::jtx::MPTTester::isTransferFeePresent ( ) const
nodiscard

Definition at line 637 of file mpt.cpp.

◆ checkImmutableFlags()

bool xrpl::test::jtx::MPTTester::checkImmutableFlags ( std::uint32_t expectedFlags) const
nodiscard

Definition at line 643 of file mpt.cpp.

◆ issuer()

Account const & xrpl::test::jtx::MPTTester::issuer ( ) const
nodiscard

Definition at line 616 of file mpt.h.

◆ holder()

Account const & xrpl::test::jtx::MPTTester::holder ( std::string const & h) const
nodiscard

Definition at line 329 of file mpt.cpp.

◆ pay()

void xrpl::test::jtx::MPTTester::pay ( Account const & src,
Account const & dest,
std::int64_t amount,
std::optional< TER > err = std::nullopt,
std::optional< std::vector< std::string > > credentials = std::nullopt )

Definition at line 652 of file mpt.cpp.

◆ claw()

void xrpl::test::jtx::MPTTester::claw ( Account const & issuer,
Account const & holder,
std::int64_t amount,
std::optional< TER > err = std::nullopt )

Definition at line 704 of file mpt.cpp.

◆ mpt()

PrettyAmount xrpl::test::jtx::MPTTester::mpt ( std::int64_t amount) const
nodiscard

Definition at line 725 of file mpt.cpp.

◆ issuanceID()

MPTID const & xrpl::test::jtx::MPTTester::issuanceID ( ) const
nodiscard

Definition at line 641 of file mpt.h.

◆ getBalance()

std::int64_t xrpl::test::jtx::MPTTester::getBalance ( Account const & account) const
nodiscard

Definition at line 741 of file mpt.cpp.

◆ getIssuanceConfidentialBalance()

std::int64_t xrpl::test::jtx::MPTTester::getIssuanceConfidentialBalance ( ) const
nodiscard

Definition at line 759 of file mpt.cpp.

◆ getEncryptedBalance()

std::optional< Buffer > xrpl::test::jtx::MPTTester::getEncryptedBalance ( Account const & account,
EncryptedBalanceType option = holderEncryptedInbox ) const
nodiscard

Definition at line 956 of file mpt.cpp.

◆ operator[]()

MPT xrpl::test::jtx::MPTTester::operator[] ( std::string const & name) const

Definition at line 1005 of file mpt.cpp.

◆ operator()()

PrettyAmount xrpl::test::jtx::MPTTester::operator() ( std::int64_t amount) const

Definition at line 1011 of file mpt.cpp.

◆ operator Asset()

xrpl::test::jtx::MPTTester::operator Asset ( ) const

Definition at line 732 of file mpt.cpp.

◆ generateKeyPair()

void xrpl::test::jtx::MPTTester::generateKeyPair ( Account const & account)

Definition at line 2011 of file mpt.cpp.

◆ getPubKey()

std::optional< Buffer > xrpl::test::jtx::MPTTester::getPubKey ( Account const & account) const
nodiscard

Definition at line 2033 of file mpt.cpp.

◆ getPrivKey()

std::optional< Buffer > xrpl::test::jtx::MPTTester::getPrivKey ( Account const & account) const
nodiscard

Definition at line 2042 of file mpt.cpp.

◆ encryptAmount()

Buffer xrpl::test::jtx::MPTTester::encryptAmount ( Account const & account,
uint64_t const amt,
Buffer const & blindingFactor ) const
nodiscard

Definition at line 2051 of file mpt.cpp.

◆ decryptAmount()

std::optional< uint64_t > xrpl::test::jtx::MPTTester::decryptAmount ( Account const & account,
Buffer const & amt ) const
nodiscard

Definition at line 2066 of file mpt.cpp.

◆ getDecryptedBalance()

std::optional< uint64_t > xrpl::test::jtx::MPTTester::getDecryptedBalance ( Account const & account,
EncryptedBalanceType balanceType ) const
nodiscard

Definition at line 2096 of file mpt.cpp.

◆ getIssuanceOutstandingBalance()

std::optional< std::int64_t > xrpl::test::jtx::MPTTester::getIssuanceOutstandingBalance ( ) const
nodiscard

Definition at line 2240 of file mpt.cpp.

◆ getClawbackProof()

std::optional< Buffer > xrpl::test::jtx::MPTTester::getClawbackProof ( Account const & holder,
std::uint64_t amount,
Buffer const & privateKey,
uint256 const & txHash ) const
nodiscard

Definition at line 771 of file mpt.cpp.

◆ getSchnorrProof()

std::optional< Buffer > xrpl::test::jtx::MPTTester::getSchnorrProof ( Account const & account,
uint256 const & ctxHash ) const
nodiscard

Definition at line 811 of file mpt.cpp.

◆ getConfidentialSendProof()

std::optional< Buffer > xrpl::test::jtx::MPTTester::getConfidentialSendProof ( Account const & sender,
std::uint64_t const amount,
std::vector< ConfidentialRecipient > const & recipients,
Slice const & blindingFactor,
uint256 const & contextHash,
PedersenProofParams const & amountParams,
PedersenProofParams const & balanceParams ) const
nodiscard

Definition at line 834 of file mpt.cpp.

◆ getConvertBackProof()

Buffer xrpl::test::jtx::MPTTester::getConvertBackProof ( Account const & holder,
std::uint64_t const amount,
uint256 const & contextHash,
PedersenProofParams const & pcParams ) const
nodiscard

Definition at line 921 of file mpt.cpp.

◆ getMPTokenVersion()

std::uint32_t xrpl::test::jtx::MPTTester::getMPTokenVersion ( Account const account) const
nodiscard

Definition at line 2254 of file mpt.cpp.

◆ getPedersenCommitment()

Buffer xrpl::test::jtx::MPTTester::getPedersenCommitment ( std::uint64_t const amount,
Buffer const & pedersenBlindingFactor )
static

Definition at line 895 of file mpt.cpp.

◆ forObject()

bool xrpl::test::jtx::MPTTester::forObject ( std::function< bool(SLEP const &sle)> const & cb,
std::optional< Account > const & holder = std::nullopt ) const
private

Definition at line 559 of file mpt.cpp.

◆ submit()

template<typename A>
TER xrpl::test::jtx::MPTTester::submit ( A const & arg,
json::Value jv )
private

Definition at line 735 of file mpt.h.

◆ makeHolders()

std::unordered_map< std::string, Account > xrpl::test::jtx::MPTTester::makeHolders ( std::vector< Account > const & holders)
staticprivate

Definition at line 116 of file mpt.cpp.

◆ getFlags()

std::uint32_t xrpl::test::jtx::MPTTester::getFlags ( std::optional< Account > const & holder) const
nodiscardprivate

Definition at line 991 of file mpt.cpp.

◆ fillConversionCiphertexts()

template<typename T>
void xrpl::test::jtx::MPTTester::fillConversionCiphertexts ( T const & arg,
json::Value & jv,
Buffer & holderCiphertext,
Buffer & issuerCiphertext,
std::optional< Buffer > & auditorCiphertext,
Buffer & blindingFactor ) const
private

Definition at line 1018 of file mpt.cpp.

◆ operator~

BookSpec operator~ ( MPTTester const & mpt)
friend

Definition at line 721 of file mpt.h.

Member Data Documentation

◆ env_

Env& xrpl::test::jtx::MPTTester::env_
private

Definition at line 448 of file mpt.h.

◆ issuer_

Account const xrpl::test::jtx::MPTTester::issuer_
private

Definition at line 449 of file mpt.h.

◆ holders_

std::unordered_map<std::string, Account> const xrpl::test::jtx::MPTTester::holders_
private

Definition at line 450 of file mpt.h.

◆ auditor_

std::optional<Account> const xrpl::test::jtx::MPTTester::auditor_
private

Definition at line 451 of file mpt.h.

◆ id_

std::optional<MPTID> xrpl::test::jtx::MPTTester::id_
private

Definition at line 452 of file mpt.h.

◆ close_

bool xrpl::test::jtx::MPTTester::close_
private

Definition at line 453 of file mpt.h.

◆ pubKeys_

std::unordered_map<AccountID, Buffer> xrpl::test::jtx::MPTTester::pubKeys_
private

Definition at line 454 of file mpt.h.

◆ privKeys_

std::unordered_map<AccountID, Buffer> xrpl::test::jtx::MPTTester::privKeys_
private

Definition at line 455 of file mpt.h.

◆ issuerEncryptedBalance

auto xrpl::test::jtx::MPTTester::issuerEncryptedBalance = EncryptedBalanceType::IssuerEncryptedBalance
staticconstexpr

Definition at line 465 of file mpt.h.

◆ holderEncryptedInbox

auto xrpl::test::jtx::MPTTester::holderEncryptedInbox = EncryptedBalanceType::HolderEncryptedInbox
staticconstexpr

Definition at line 466 of file mpt.h.

◆ holderEncryptedSpending

auto xrpl::test::jtx::MPTTester::holderEncryptedSpending = EncryptedBalanceType::HolderEncryptedSpending
staticconstexpr

Definition at line 467 of file mpt.h.

◆ auditorEncryptedBalance

auto xrpl::test::jtx::MPTTester::auditorEncryptedBalance = EncryptedBalanceType::AuditorEncryptedBalance
staticconstexpr

Definition at line 468 of file mpt.h.