3#include <test/jtx/Account.h>
4#include <test/jtx/Env.h>
5#include <test/jtx/amount.h>
6#include <test/jtx/delegate.h>
7#include <test/jtx/owners.h>
8#include <test/jtx/tag.h>
9#include <test/jtx/ter.h>
10#include <test/jtx/ticket.h>
11#include <test/jtx/txflags.h>
13#include <xrpl/basics/Buffer.h>
14#include <xrpl/basics/Slice.h>
15#include <xrpl/basics/base_uint.h>
16#include <xrpl/basics/contract.h>
17#include <xrpl/beast/unit_test/suite.h>
18#include <xrpl/core/ServiceRegistry.h>
19#include <xrpl/json/json_value.h>
20#include <xrpl/protocol/AccountID.h>
21#include <xrpl/protocol/Asset.h>
22#include <xrpl/protocol/ConfidentialTransfer.h>
23#include <xrpl/protocol/TER.h>
24#include <xrpl/protocol/TxFlags.h>
25#include <xrpl/protocol/UintTypes.h>
26#include <xrpl/protocol/XRPAmount.h>
27#include <xrpl/protocol/jss.h>
437 Slice const& currentEncSpending,
440 Slice const& senderEncAmt);
478 operator MPT()
const;
484 createJV(MPTCreate
const& arg = MPTCreate{});
487 destroy(MPTDestroy
const& arg = MPTDestroy{});
490 destroyJV(MPTDestroy
const& arg = MPTDestroy{});
493 authorize(MPTAuthorize
const& arg = MPTAuthorize{});
496 authorizeJV(MPTAuthorize
const& arg = MPTAuthorize{});
502 set(MPTSet
const&
set = {});
508 convert(MPTConvert
const& arg = MPTConvert{});
519 convertJV(MPTConvert
const& arg, std::uint32_t seq);
522 mergeInbox(MPTMergeInbox
const& arg = MPTMergeInbox{});
524 [[nodiscard]] json::Value
525 mergeInboxJV(MPTMergeInbox
const& arg = MPTMergeInbox{})
const;
528 send(MPTConfidentialSend
const& arg = MPTConfidentialSend{});
545 MPTConfidentialSend
const& arg,
547 std::optional<ConfidentialSendChainState> chain = std::nullopt);
562 [[nodiscard]] ConfidentialSendChainState
566 convertBack(MPTConvertBack
const& arg = MPTConvertBack{});
582 confidentialClaw(MPTConfidentialClawback
const& arg = MPTConfidentialClawback{});
597 checkFlags(uint32_t
const expectedFlags, std::optional<Account>
const&
holder = std::nullopt)
640 [[nodiscard]]
MPTID const&
643 if (!
env_.test.BEAST_EXPECT(
id_))
664 operator Asset()
const;
702 Slice const& blindingFactor,
723 return ~static_cast<MPT>(
mpt);
733 template <
typename A>
737 auto const expectedFlags =
Txflags(arg.flags.value_or(0));
740 if constexpr (
requires { arg.fee; })
747 if constexpr (
requires { arg.ticketSeq; })
748 ticketSeq = arg.ticketSeq;
751 if constexpr (
requires { arg.delegate; })
752 delegateAcct = arg.delegate;
755 if constexpr (
requires { arg.destinationTag; })
756 dstTag = arg.destinationTag;
758 if (ticketSeq && delegateAcct)
771 else if (delegateAcct)
777 env_(jv, expectedFlags, expectedTer,
Dtag(*dstTag));
781 env_(jv, expectedFlags, expectedTer);
783 auto const err =
env_.ter();
791 env_.require(
Owners(it.second, *arg.holderCount));
802 template <
typename T>
810 Buffer& blindingFactor)
const;
Like std::vector<char> but better.
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
std::shared_ptr< STLedgerEntry const > const_pointer
An immutable linear range of bytes.
Immutable cryptographic account descriptor.
A transaction testing environment.
Test helper for creating, mutating, and asserting MPT and confidential MPT ledger state.
void fillConversionCiphertexts(T const &arg, json::Value &jv, Buffer &holderCiphertext, Buffer &issuerCiphertext, std::optional< Buffer > &auditorCiphertext, Buffer &blindingFactor) const
static constexpr auto holderEncryptedInbox
std::optional< uint64_t > decryptAmount(Account const &account, Buffer const &amt) const
@ HolderEncryptedSpending
@ AuditorEncryptedBalance
std::unordered_map< std::string, Account > const holders_
Buffer getConvertBackProof(Account const &holder, std::uint64_t const amount, uint256 const &contextHash, PedersenProofParams const &pcParams) const
void send(MPTConfidentialSend const &arg=MPTConfidentialSend{})
Buffer encryptAmount(Account const &account, uint64_t const amt, Buffer const &blindingFactor) const
bool forObject(std::function< bool(SLEP const &sle)> const &cb, std::optional< Account > const &holder=std::nullopt) const
void set(MPTSet const &set={})
bool checkMPTokenAmount(Account const &holder, std::int64_t expectedAmount) const
std::optional< MPTID > id_
json::Value convertJV(MPTConvert const &arg, std::uint32_t seq)
Build a confidential convert JV without submitting it.
static Buffer getPedersenCommitment(std::uint64_t const amount, Buffer const &pedersenBlindingFactor)
static json::Value destroyJV(MPTDestroy const &arg=MPTDestroy{})
std::optional< Buffer > getEncryptedBalance(Account const &account, EncryptedBalanceType option=holderEncryptedInbox) const
void convertBack(MPTConvertBack const &arg=MPTConvertBack{})
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)
std::optional< uint64_t > getDecryptedBalance(Account const &account, EncryptedBalanceType balanceType) const
Account const & holder(std::string const &h) const
static json::Value authorizeJV(MPTAuthorize const &arg=MPTAuthorize{})
void create(MPTCreate const &arg=MPTCreate{})
bool isTransferFeePresent() const
std::optional< Buffer > getPrivKey(Account const &account) const
friend BookSpec operator~(MPTTester const &mpt)
bool checkMetadata(std::string const &metadata) const
void confidentialClaw(MPTConfidentialClawback const &arg=MPTConfidentialClawback{})
bool checkFlags(uint32_t const expectedFlags, std::optional< Account > const &holder=std::nullopt) const
bool isMetadataPresent() const
MPT operator[](std::string const &name) const
static constexpr auto issuerEncryptedBalance
void authorizeHolders(Holders const &holders)
std::uint32_t getMPTokenVersion(Account const account) const
Account const & issuer() const
std::optional< std::int64_t > getIssuanceOutstandingBalance() const
static json::Value createJV(MPTCreate const &arg=MPTCreate{})
void authorize(MPTAuthorize const &arg=MPTAuthorize{})
std::optional< Buffer > getSchnorrProof(Account const &account, uint256 const &ctxHash) const
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.
static json::Value setJV(MPTSet const &set={})
MPTID const & issuanceID() const
static constexpr auto holderEncryptedSpending
std::unordered_map< AccountID, Buffer > pubKeys_
bool checkImmutableFlags(std::uint32_t expectedFlags) const
std::unordered_map< AccountID, Buffer > privKeys_
std::optional< Buffer > getClawbackProof(Account const &holder, std::uint64_t amount, Buffer const &privateKey, uint256 const &txHash) const
std::int64_t getBalance(Account const &account) const
std::optional< Buffer > 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
std::optional< Account > const auditor_
json::Value mergeInboxJV(MPTMergeInbox const &arg=MPTMergeInbox{}) const
void claw(Account const &issuer, Account const &holder, std::int64_t amount, std::optional< TER > err=std::nullopt)
static constexpr auto auditorEncryptedBalance
MPTTester(Env &env, Account issuer, MPTInit const &constr={})
void generateKeyPair(Account const &account)
PrettyAmount mpt(std::int64_t amount) const
void destroy(MPTDestroy const &arg=MPTDestroy{})
std::int64_t getIssuanceConfidentialBalance() const
bool checkTransferFee(std::uint16_t transferFee) const
bool checkIssuanceConfidentialBalance(std::int64_t expectedAmount) const
bool checkDomainID(std::optional< uint256 > expected) const
void mergeInbox(MPTMergeInbox const &arg=MPTMergeInbox{})
PrettyAmount operator()(std::int64_t amount) const
void convert(MPTConvert const &arg=MPTConvert{})
std::uint32_t getFlags(std::optional< Account > const &holder) const
static std::unordered_map< std::string, Account > makeHolders(std::vector< Account > const &holders)
std::optional< Buffer > getPubKey(Account const &account) const
bool checkMPTokenOutstandingAmount(std::int64_t expectedAmount) const
TER submit(A const &arg, json::Value jv)
json::Value convertBackJV(MPTConvertBack const &arg, std::uint32_t seq)
Build a confidential convertBack JV without submitting it.
Converts to MPT Issue or STAmount.
MptBalance(MPTTester &tester, Account const &account, std::int64_t amount)
MPTTester const & tester_
std::int64_t const amount_
void operator()(Env &env) const
MptFlags(MPTTester &tester, std::uint32_t flags, std::optional< Account > const &holder=std::nullopt)
void operator()(Env &env) const
std::optional< Account > holder_
Match the number of items in the account's owner directory.
std::function< bool()> cb_
RequireAny(std::function< bool()> const &cb)
void operator()(Env &env) const
Set the expected result code for a JTx The test will fail if the code doesn't match.
Set a ticket sequence on a JTx.
Buffer gMakeZeroBuffer(std::size_t size)
Create a zero-initialized buffer for malformed cryptography test inputs.
XrpT const XRP
Converts to XRP Issue or STAmount.
std::vector< Account > Holders
std::optional< ConfidentialSendChainState > computeNextSendChainState(std::uint64_t currentSpending, Slice const ¤tEncSpending, std::uint32_t currentVersion, std::uint64_t sendAmt, Slice const &senderEncAmt)
Use this when building a second (or later) confidential send from the same account in the same batch.
static MPTInit const kMptInitNoFund
std::string to_string(BaseUInt< Bits, Tag > const &a)
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
TERSubset< CanCvtToTER > TER
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
When building multiple confidential sends from the same account inside a single batch transaction,...
std::uint32_t version
sfConfidentialBalanceVersion after the previous send.
std::uint64_t spending
Decrypted spending balance after the previous send.
Buffer encSpending
Encrypted spending balance after the previous send.
Set the destination tag on a JTx.
Arguments for building an MPTokenAuthorize test transaction.
std::optional< std::uint32_t > ownerCount
std::optional< std::uint32_t > holderCount
std::optional< Account > holder
std::optional< Account > account
std::optional< std::uint32_t > flags
Arguments for building a ConfidentialMPTClawback test transaction.
std::optional< std::uint32_t > holderCount
std::optional< std::uint32_t > ownerCount
std::optional< std::uint32_t > ticketSeq
std::optional< std::string > proof
std::optional< std::uint64_t > amt
std::optional< XRPAmount > fee
std::optional< Account > delegate
std::optional< std::uint32_t > flags
std::optional< Account > account
std::optional< Account > holder
Arguments for building a ConfidentialMPTSend test transaction.
std::optional< XRPAmount > fee
std::optional< std::vector< std::string > > credentials
std::optional< Buffer > balanceCommitment
std::optional< std::uint32_t > ticketSeq
std::optional< std::uint32_t > holderCount
std::optional< std::uint64_t > amt
std::optional< bool > fillAuditorEncryptedAmt
std::optional< std::uint32_t > destinationTag
std::optional< Account > account
std::optional< Buffer > auditorEncryptedAmt
std::optional< Account > dest
std::optional< std::uint32_t > flags
std::optional< Buffer > blindingFactor
std::optional< Buffer > amountCommitment
std::optional< Account > delegate
std::optional< std::string > proof
std::optional< Buffer > senderEncryptedAmt
std::optional< Buffer > destEncryptedAmt
std::optional< Buffer > issuerEncryptedAmt
std::optional< std::uint32_t > ownerCount
Arguments for building a ConfidentialMPTConvertBack test transaction.
std::optional< Buffer > auditorEncryptedAmt
std::optional< Account > delegate
std::optional< std::uint32_t > holderCount
std::optional< Buffer > issuerEncryptedAmt
std::optional< std::uint32_t > ownerCount
std::optional< std::uint64_t > amt
std::optional< Account > account
std::optional< XRPAmount > fee
std::optional< std::uint32_t > ticketSeq
std::optional< std::uint32_t > flags
std::optional< Buffer > holderEncryptedAmt
std::optional< Buffer > proof
std::optional< Buffer > blindingFactor
std::optional< Buffer > pedersenCommitment
std::optional< bool > fillAuditorEncryptedAmt
Arguments for building a ConfidentialMPTConvert test transaction.
std::optional< bool > fillAuditorEncryptedAmt
std::optional< std::uint32_t > ownerCount
std::optional< std::uint64_t > amt
std::optional< Buffer > holderEncryptedAmt
std::optional< Buffer > auditorEncryptedAmt
std::optional< bool > fillSchnorrProof
std::optional< std::uint32_t > holderCount
std::optional< Buffer > holderPubKey
std::optional< std::uint32_t > flags
std::optional< Account > account
std::optional< Buffer > blindingFactor
std::optional< XRPAmount > fee
std::optional< std::string > proof
std::optional< Account > delegate
std::optional< Buffer > issuerEncryptedAmt
std::optional< std::uint32_t > ticketSeq
Arguments for building an MPTokenIssuanceCreate test transaction.
std::optional< std::uint8_t > assetScale
static std::vector< Account > allHolders
std::optional< std::uint32_t > immutableFlags
std::optional< std::uint32_t > holderCount
std::optional< std::string > metadata
std::optional< std::uint32_t > flags
std::optional< uint256 > domainID
std::optional< std::uint64_t > maxAmt
std::optional< std::uint32_t > ownerCount
std::optional< Account > issuer
std::optional< std::pair< std::vector< Account >, std::uint64_t > > pay
std::optional< std::uint16_t > transferFee
std::optional< std::vector< Account > > authorize
Arguments for building an MPTokenIssuanceDestroy test transaction.
std::optional< Account > issuer
std::optional< std::uint32_t > flags
std::optional< std::uint32_t > holderCount
std::optional< std::uint32_t > ownerCount
Full constructor arguments for MPTTester initialization.
std::uint16_t transferFee
std::optional< std::uint64_t > maxAmt
std::optional< Account > auditor
std::optional< std::uint32_t > immutableFlags
std::optional< std::uint64_t > pay
Arguments for initializing funded MPT test accounts and issuance.
std::optional< MPTCreate > create
std::optional< Account > auditor
PrettyAmount const xrpHolders
Arguments for building a ConfidentialMPTMergeInbox test transaction.
std::optional< std::uint32_t > ownerCount
std::optional< std::uint32_t > holderCount
std::optional< std::uint32_t > flags
std::optional< XRPAmount > fee
std::optional< std::uint32_t > ticketSeq
std::optional< Account > account
std::optional< Account > delegate
Arguments for building an MPTokenIssuanceSet test transaction.
std::optional< uint256 > domainID
std::optional< Account > account
std::optional< std::uint32_t > holderCount
std::optional< Buffer > auditorPubKey
std::optional< std::uint32_t > ticketSeq
std::optional< std::uint32_t > immutableFlags
std::optional< std::uint16_t > transferFee
std::optional< std::uint32_t > flags
std::optional< std::variant< Account, AccountID > > holder
std::optional< std::string > metadata
std::optional< std::uint32_t > ownerCount
std::optional< Buffer > issuerPubKey
std::optional< Account > delegate
Stores the parameters that are exclusively used to generate a Pedersen linkage proof.
Buffer const pedersenCommitment
The Pedersen commitment used by the proof.
Buffer const blindingFactor
The blinding factor used to create the Pedersen commitment.
Buffer const encryptedAmt
The encrypted amount linked to the Pedersen commitment.
uint64_t const amt
Either the spending balance or the value being transferred.
Represents an XRP, IOU, or MPT quantity This customizes the string conversion and supports XRP conver...