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/SField.h>
24#include <xrpl/protocol/TER.h>
25#include <xrpl/protocol/TxFlags.h>
26#include <xrpl/protocol/UintTypes.h>
27#include <xrpl/protocol/XRPAmount.h>
28#include <xrpl/protocol/jss.h>
35#include <source_location>
502 Slice const& currentEncSpending,
505 Slice const& senderEncAmt);
551 operator MPT()
const;
559 createJV(MPTCreate
const& arg = MPTCreate{});
563 MPTDestroy
const& arg = MPTDestroy{},
567 destroyJV(MPTDestroy
const& arg = MPTDestroy{});
571 MPTAuthorize
const& arg = MPTAuthorize{},
575 authorizeJV(MPTAuthorize
const& arg = MPTAuthorize{});
590 MPTConvert
const& arg = MPTConvert{},
602 convertJV(MPTConvert
const& arg, std::uint32_t seq);
606 MPTMergeInbox
const& arg = MPTMergeInbox{},
609 [[nodiscard]] json::Value
610 mergeInboxJV(MPTMergeInbox
const& arg = MPTMergeInbox{})
const;
614 MPTConfidentialSend
const& arg = MPTConfidentialSend{},
632 MPTConfidentialSend
const& arg,
634 std::optional<ConfidentialSendChainState> chain = std::nullopt);
649 [[nodiscard]] ConfidentialSendChainState
654 MPTConvertBack
const& arg = MPTConvertBack{},
672 MPTConfidentialClawback
const& arg = MPTConfidentialClawback{},
677 MPTMirrorUpdate
const& arg = MPTMirrorUpdate{},
682 MPTHolderKeyUpdate
const& arg = MPTHolderKeyUpdate{},
698 checkFlags(uint32_t
const expectedFlags, std::optional<Account>
const&
holder = std::nullopt)
720 std::optional<std::uint32_t> issuerKeyEpoch,
721 std::optional<std::uint32_t> auditorKeyEpoch)
const;
729 std::optional<std::uint32_t> issuerKeyMirrorEpoch,
730 std::optional<std::uint32_t> auditorKeyMirrorEpoch)
const;
737 std::optional<Account>
const& issuerKeyOwner,
738 std::optional<Account>
const& auditorKeyOwner)
const;
767 [[nodiscard]]
MPTID const&
770 if (!
env_.test.BEAST_EXPECT(
id_))
791 operator Asset()
const;
840 Slice const& blindingFactor,
861 return ~static_cast<MPT>(
mpt);
875 template <
typename A>
879 auto const expectedFlags =
Txflags(arg.flags.value_or(0));
882 if constexpr (
requires { arg.fee; })
889 if constexpr (
requires { arg.ticketSeq; })
890 ticketSeq = arg.ticketSeq;
893 if constexpr (
requires { arg.delegate; })
894 delegateAcct = arg.delegate;
897 if constexpr (
requires { arg.destinationTag; })
898 dstTag = arg.destinationTag;
900 if (ticketSeq && delegateAcct)
913 else if (delegateAcct)
919 env_(jv, expectedFlags, expectedTer,
Dtag(*dstTag));
923 env_(jv, expectedFlags, expectedTer);
925 auto const err =
env_.ter();
933 env_.require(
Owners(it.second, *arg.holderCount));
959 template <
typename T>
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.
std::unordered_map< AccountID, std::vector< Buffer > > pubKeys_
static constexpr auto holderEncryptedInbox
void mirrorUpdate(MPTMirrorUpdate const &arg=MPTMirrorUpdate{}, std::source_location const &loc=std::source_location::current())
@ HolderEncryptedSpending
@ AuditorEncryptedBalance
std::optional< std::uint32_t > getMirrorEpoch(Account const &holder, SF_UINT32 const &field) const
std::unordered_map< std::string, Account > const holders_
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 mergeInbox(MPTMergeInbox const &arg=MPTMergeInbox{}, std::source_location const &loc=std::source_location::current())
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{})
void setIssuanceIdField(json::Value &jv, std::optional< MPTID > const &id) const
Sets sfMPTokenIssuanceID on jv, falling back to id_ if arg's id is not set.
std::optional< Buffer > getEncryptedBalance(Account const &account, EncryptedBalanceType option=holderEncryptedInbox) const
void convertBack(MPTConvertBack const &arg=MPTConvertBack{}, std::source_location const &loc=std::source_location::current())
std::optional< uint64_t > getDecryptedBalance(Account const &account, EncryptedBalanceType balanceType) const
bool checkMirrorEpochs(Account const &holder, std::optional< std::uint32_t > issuerKeyMirrorEpoch, std::optional< std::uint32_t > auditorKeyMirrorEpoch) const
Account const & holder(std::string const &h) const
static json::Value authorizeJV(MPTAuthorize const &arg=MPTAuthorize{})
bool isTransferFeePresent() const
std::optional< Buffer > getClawbackProof(Account const &holder, std::uint64_t amount, Buffer const &privateKey, UInt256 const &txHash) const
friend BookSpec operator~(MPTTester const &mpt)
bool checkMetadata(std::string const &metadata) const
std::uint32_t generateKeyPair(Account const &account)
bool checkFlags(uint32_t const expectedFlags, std::optional< Account > const &holder=std::nullopt) const
bool isMetadataPresent() const
MPT operator[](std::string const &name) const
void holderKeyUpdate(MPTHolderKeyUpdate const &arg=MPTHolderKeyUpdate{}, std::source_location const &loc=std::source_location::current())
std::optional< Buffer > getSchnorrProof(Account const &account, UInt256 const &ctxHash) const
static constexpr auto issuerEncryptedBalance
bool checkDomainID(std::optional< UInt256 > expected) const
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{})
MPTTester(Env &env, Account issuer, MPTInit const &constr={}, std::source_location const &loc=std::source_location::current())
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::optional< uint64_t > decryptAmount(Account const &account, Buffer const &amt, std::optional< std::uint32_t > epoch=std::nullopt) const
void send(MPTConfidentialSend const &arg=MPTConfidentialSend{}, std::source_location const &loc=std::source_location::current())
bool checkEncryptionKeys(std::optional< Account > const &issuerKeyOwner, std::optional< Account > const &auditorKeyOwner) const
bool checkImmutableFlags(std::uint32_t expectedFlags) const
std::int64_t getBalance(Account const &account) const
TER submit(A const &arg, WithSourceLocation< json::Value > jv)
void fillConversionCiphertexts(T const &arg, json::Value &jv, Account const &account, std::uint64_t const amount) 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< Buffer > getPubKey(Account const &account, std::optional< std::uint32_t > epoch=std::nullopt) const
std::optional< Account > const auditor_
json::Value mergeInboxJV(MPTMergeInbox const &arg=MPTMergeInbox{}) const
void authorizeHolders(Holders const &holders, std::source_location const &loc=std::source_location::current())
static constexpr auto auditorEncryptedBalance
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::source_location const &loc=std::source_location::current())
std::unordered_map< AccountID, std::vector< Buffer > > privKeys_
void claw(Account const &issuer, Account const &holder, std::int64_t amount, std::optional< TER > err=std::nullopt, std::source_location const &loc=std::source_location::current())
void confidentialClaw(MPTConfidentialClawback const &arg=MPTConfidentialClawback{}, std::source_location const &loc=std::source_location::current())
PrettyAmount mpt(std::int64_t amount) const
void create(MPTCreate const &arg=MPTCreate{}, std::source_location const &loc=std::source_location::current())
void set(MPTSet const &set={}, std::source_location const &loc=std::source_location::current())
std::int64_t getIssuanceConfidentialBalance() const
std::uint32_t ticketOrSeq(std::optional< std::uint32_t > const &ticketSeq, std::optional< Account > const &account) const
bool checkTransferFee(std::uint16_t transferFee) const
bool checkIssuanceConfidentialBalance(std::int64_t expectedAmount) const
void authorize(MPTAuthorize const &arg=MPTAuthorize{}, std::source_location const &loc=std::source_location::current())
PrettyAmount operator()(std::int64_t amount) const
std::uint32_t getFlags(std::optional< Account > const &holder) const
bool checkKeyEpochs(std::optional< std::uint32_t > issuerKeyEpoch, std::optional< std::uint32_t > auditorKeyEpoch) const
static std::unordered_map< std::string, Account > makeHolders(std::vector< Account > const &holders)
bool checkMPTokenOutstandingAmount(std::int64_t expectedAmount) const
void convert(MPTConvert const &arg=MPTConvert{}, std::source_location const &loc=std::source_location::current())
std::optional< Buffer > getPrivKey(Account const &account, std::optional< std::uint32_t > epoch=std::nullopt) const
void destroy(MPTDestroy const &arg=MPTDestroy{}, std::source_location const &loc=std::source_location::current())
std::optional< Buffer > getConvertBackProof(Account const &holder, std::uint64_t const amount, UInt256 const &contextHash, PedersenProofParams const &pcParams) const
json::Value convertBackJV(MPTConvertBack const &arg, std::uint32_t seq)
Build a confidential convertBack JV without submitting it.
Converts to MPT Issue or STAmount.
std::source_location testLoc_
MptBalance(MPTTester &tester, Account const &account, std::int64_t amount, std::source_location const &testLoc=std::source_location::current(), std::source_location const &checkLoc=std::source_location::current())
MPTTester const & tester_
std::int64_t const amount_
void operator()(Env &env) const
std::source_location checkLoc_
std::source_location checkLoc_
MptFlags(MPTTester &tester, std::uint32_t flags, std::optional< Account > const &holder=std::nullopt, std::source_location const &testLoc=std::source_location::current(), std::source_location const &checkLoc=std::source_location::current())
void operator()(Env &env) const
std::optional< Account > holder_
std::source_location testLoc_
Match the number of items in the account's owner directory.
std::function< bool()> cb_
std::source_location testLoc_
RequireAny(std::function< bool()> const &cb, std::source_location const &testLoc=std::source_location::current(), std::source_location const &checkLoc=std::source_location::current())
void operator()(Env &env) const
std::source_location checkLoc_
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
TypedField< STInteger< std::uint32_t > > SF_UINT32
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< std::uint64_t > maxAmt
std::optional< UInt256 > domainID
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
Arguments for building a ConfidentialMPTHolderKeyUpdate test transaction.
std::optional< Account > account
std::optional< Buffer > inboxCiphertext
std::optional< std::uint32_t > holderCount
std::optional< Buffer > proof
std::optional< XRPAmount > fee
std::optional< std::uint32_t > ownerCount
std::optional< Buffer > spendingCiphertext
std::optional< Buffer > holderPubKey
std::optional< std::uint32_t > flags
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 a ConfidentialMPTMirrorUpdate test transaction.
std::optional< XRPAmount > fee
std::optional< std::uint32_t > flags
std::optional< Buffer > auditorEncryptedAmount
std::optional< Account > holder
std::optional< Account > account
std::optional< Buffer > zkProof
std::optional< std::uint32_t > holderCount
std::optional< Buffer > issuerEncryptedAmount
std::optional< std::uint32_t > ownerCount
Arguments for building an MPTokenIssuanceSet test transaction.
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< UInt256 > domainID
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...
Wrapper that captures std::source_location when implicitly constructed.