3#include <xrpl/protocol/SField.h>
4#include <xrpl/protocol/jss.h>
32 for (
auto const& h : holders)
34 if (accounts.
find(h.human()) != accounts.
cend())
35 Throw<std::runtime_error>(
"Duplicate holder");
44 , holders_(makeHolders(arg.holders))
61 Throw<std::runtime_error>(
"Issuer can't be holder");
71 Throw<std::runtime_error>(
"MPT can't be reused");
75 jv[sfTransactionType] = jss::MPTokenIssuanceCreate;
106 jv[sfAccount] = arg.
issuer->human();
114 Throw<std::runtime_error>(
"MPT has not been created");
117 jv[sfTransactionType] = jss::MPTokenIssuanceDestroy;
124 auto const& it =
holders_.find(holder_);
126 Throw<std::runtime_error>(
"Holder is not found");
135 jv[sfAccount] = arg.
account->human();
138 jv[sfTransactionType] = jss::MPTokenAuthorize;
144 Throw<std::runtime_error>(
"MPT has not been created");
148 jv[sfHolder] = arg.
holder->human();
175 [&](
SLEP const& sle) {
return env_.
test.BEAST_EXPECT(!sle); },
208 jv[sfAccount] = arg.
account->human();
211 jv[sfTransactionType] = jss::MPTokenIssuanceSet;
217 Throw<std::runtime_error>(
"MPT has not been created");
221 jv[sfHolder] = arg.
holder->human();
223 jv[sfDelegate] = arg.
delegate->human();
244 flags &= ~lsfMPTLocked;
252 flags &= ~lsfMPTCanLock;
257 flags &= ~lsfMPTRequireAuth;
262 flags &= ~lsfMPTCanEscrow;
267 flags &= ~lsfMPTCanClawback;
272 flags &= ~lsfMPTCanTrade;
277 flags &= ~lsfMPTCanTransfer;
295 Throw<std::runtime_error>(
"MPT has not been created");
298 if (
auto const sle =
env_.
le(key))
307 if (sle->isFieldPresent(sfDomainID))
308 return expected == sle->getFieldH256(sfDomainID);
319 [&](
SLEP const& sle) {
return expectedAmount == (*sle)[sfMPTAmount]; },
327 return expectedAmount == (*sle)[sfOutstandingAmount];
333 uint32_t
const expectedFlags,
343 if (sle->isFieldPresent(sfMPTokenMetadata))
344 return strHex(sle->getFieldVL(sfMPTokenMetadata)) ==
354 return sle->isFieldPresent(sfMPTokenMetadata);
362 if (sle->isFieldPresent(sfTransferFee))
363 return sle->getFieldU16(sfTransferFee) == transferFee;
372 return sle->isFieldPresent(sfTransferFee);
385 Throw<std::runtime_error>(
"MPT has not been created");
435 Throw<std::runtime_error>(
"MPT has not been created");
454 Throw<std::runtime_error>(
"MPT has not been created");
462 Throw<std::runtime_error>(
"MPT has not been created");
466 return sle->getFieldU64(sfOutstandingAmount);
471 return sle->getFieldU64(sfMPTAmount);
481 [&](
SLEP const& sle) {
482 flags = sle->getFlags();
486 Throw<std::runtime_error>(
"Failed to get the flags");
bool expect(Condition const &shouldBeTrue)
Evaluate a test condition.
constexpr value_type value() const
Returns the underlying value.
Immutable cryptographic account descriptor.
AccountID id() const
Returns the Account ID.
std::string const & name() const
Return the name.
std::string const & human() const
Returns the human readable public key.
A transaction testing environment.
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
void require(Args const &... args)
Check a set of requirements.
TER ter() const
Return the TER for the last JTx.
beast::unit_test::suite & test
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
bool checkMPTokenOutstandingAmount(std::int64_t expectedAmount) const
void authorize(MPTAuthorize const &arg=MPTAuthorize{})
void set(MPTSet const &set={})
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)
static std::unordered_map< std::string, Account > makeHolders(std::vector< Account > const &holders)
bool isMetadataPresent() const
bool checkTransferFee(std::uint16_t transferFee) const
MPTID const & issuanceID() const
TER submit(A const &arg, Json::Value const &jv)
void claw(Account const &issuer, Account const &holder, std::int64_t amount, std::optional< TER > err=std::nullopt)
MPTTester(Env &env, Account const &issuer, MPTInit const &constr={})
PrettyAmount mpt(std::int64_t amount) const
MPT operator[](std::string const &name) const
bool checkFlags(uint32_t const expectedFlags, std::optional< Account > const &holder=std::nullopt) const
Account const & holder(std::string const &h) const
Account const & issuer() const
bool checkMetadata(std::string const &metadata) const
bool forObject(std::function< bool(SLEP const &sle)> const &cb, std::optional< Account > const &holder=std::nullopt) const
bool isTransferFeePresent() const
std::optional< MPTID > id_
std::int64_t getBalance(Account const &account) const
std::unordered_map< std::string, Account > const holders_
bool checkDomainID(std::optional< uint256 > expected) const
std::uint32_t getFlags(std::optional< Account > const &holder) const
bool checkMPTokenAmount(Account const &holder, std::int64_t expectedAmount) const
void create(MPTCreate const &arg=MPTCreate{})
void destroy(MPTDestroy const &arg=MPTDestroy{})
Converts to MPT Issue or STAmount.
void operator()(Env &env) const
std::int64_t const amount_
MPTTester const & tester_
void operator()(Env &env) const
std::optional< Account > holder_
Match the number of items in the account's owner directory.
void operator()(Env &env) const
std::function< bool()> cb_
Check a set of conditions.
Set the expected result code for a JTx The test will fail if the code doesn't match.
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet mptIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Json::Value claw(Account const &account, STAmount const &amount, std::optional< Account > const &mptHolder)
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::uint32_t const tmfMPTClearCanClawback
constexpr std::uint32_t const tmfMPTClearCanEscrow
constexpr std::uint32_t const tmfMPTSetCanClawback
constexpr std::uint32_t const tmfMPTSetRequireAuth
constexpr std::uint32_t const tmfMPTClearCanTrade
constexpr std::uint32_t const tfMPTUnlock
constexpr std::uint32_t const tmfMPTClearRequireAuth
constexpr std::uint32_t const tmfMPTSetCanLock
STAmount multiply(STAmount const &amount, Rate const &rate)
constexpr std::uint32_t const tmfMPTSetCanTrade
std::string strHex(FwdIt begin, FwdIt end)
constexpr std::uint32_t const tfMPTUnauthorize
constexpr std::uint32_t const tmfMPTSetCanEscrow
constexpr std::uint32_t const tmfMPTClearCanLock
constexpr std::uint32_t const tmfMPTSetCanTransfer
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
constexpr std::uint32_t const tfMPTLock
std::string to_string(base_uint< Bits, Tag > const &a)
MPTID makeMptID(std::uint32_t sequence, AccountID const &account)
constexpr std::uint32_t const tmfMPTClearCanTransfer
std::optional< std::uint32_t > flags
std::optional< Account > holder
std::optional< Account > account
std::optional< MPTID > id
std::optional< std::uint8_t > assetScale
std::optional< std::uint16_t > transferFee
std::optional< uint256 > domainID
std::optional< std::uint32_t > mutableFlags
std::optional< std::uint32_t > flags
std::optional< std::string > metadata
std::optional< std::uint64_t > maxAmt
std::optional< Account > issuer
std::optional< MPTID > id
PrettyAmount const xrpHolders
std::optional< std::uint32_t > flags
std::optional< std::uint16_t > transferFee
std::optional< Account > account
std::optional< std::string > metadata
std::optional< uint256 > domainID
std::optional< std::uint32_t > mutableFlags
std::optional< MPTID > id
std::optional< Account > holder
std::optional< Account > delegate
Represents an XRP or IOU quantity This customizes the string conversion and supports XRP conversions ...