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");
77 , holders_(makeHolders(holders))
112MPTTester::operator
MPT()
const
115 Throw<std::runtime_error>(
"MPT has not been created");
116 return MPT(
"", *id_);
123 Throw<std::runtime_error>(
"MPTTester::createjv: issuer is not set");
125 jv[sfAccount] = arg.
issuer->human();
138 jv[sfTransactionType] = jss::MPTokenIssuanceCreate;
147 Throw<std::runtime_error>(
"MPT can't be reused");
169 auto authAndPay = [&](
auto const& accts,
auto const&& getAcct) {
170 for (
auto const& it : accts)
176 if (arg.
pay && arg.
pay->first.empty())
181 for (
auto const& p : arg.
pay->first)
188 authAndPay(
holders_, [](
auto const& it) {
return it.second; });
190 authAndPay(*arg.
authorize, [](
auto const& it) { return it; });
194 if (arg.
pay->first.empty())
195 authAndPay(
holders_, [](
auto const& it) {
return it.second; });
197 authAndPay(arg.
pay->first, [](
auto const& it) { return it; });
207 Throw<std::runtime_error>(
"MPTTester::destroyjv: issuer/id is not set");
208 jv[sfAccount] = arg.
issuer->human();
210 jv[sfTransactionType] = jss::MPTokenIssuanceDestroy;
219 Throw<std::runtime_error>(
"MPT has not been created");
229 auto const& it =
holders_.find(holder_);
231 Throw<std::runtime_error>(
"Holder is not found");
240 Throw<std::runtime_error>(
241 "MPTTester::authorizejv: issuer/id is not set");
242 jv[sfAccount] = arg.
account->human();
245 jv[sfHolder] = arg.
holder->human();
246 jv[sfTransactionType] = jss::MPTokenAuthorize;
255 Throw<std::runtime_error>(
"MPT has not been created");
287 [&](
SLEP const& sle) {
return env_.
test.BEAST_EXPECT(!sle); },
318 for (
auto const&
holder : holders)
329 Throw<std::runtime_error>(
"MPTTester::setjv: issuer/id is not set");
330 jv[sfAccount] = arg.
account->human();
335 [&jv]<
typename T>(T
const&
holder) {
345 jv[sfDelegate] = arg.
delegate->human();
354 jv[sfTransactionType] = jss::MPTokenIssuanceSet;
363 Throw<std::runtime_error>(
"MPT has not been created");
386 flags &= ~lsfMPTLocked;
394 flags &= ~lsfMPTCanLock;
399 flags &= ~lsfMPTRequireAuth;
404 flags &= ~lsfMPTCanEscrow;
409 flags &= ~lsfMPTCanClawback;
414 flags &= ~lsfMPTCanTrade;
419 flags &= ~lsfMPTCanTransfer;
426 if (
auto const account =
438 Throw<std::runtime_error>(
"MPT has not been created");
441 if (
auto const sle =
env_.
le(key))
450 if (sle->isFieldPresent(sfDomainID))
451 return expected == sle->getFieldH256(sfDomainID);
462 [&](
SLEP const& sle) {
return expectedAmount == (*sle)[sfMPTAmount]; },
470 return expectedAmount == (*sle)[sfOutstandingAmount];
476 uint32_t
const expectedFlags,
486 if (sle->isFieldPresent(sfMPTokenMetadata))
487 return strHex(sle->getFieldVL(sfMPTokenMetadata)) ==
497 return sle->isFieldPresent(sfMPTokenMetadata);
505 if (sle->isFieldPresent(sfTransferFee))
506 return sle->getFieldU16(sfTransferFee) == transferFee;
515 return sle->isFieldPresent(sfTransferFee);
528 Throw<std::runtime_error>(
"MPT has not been created");
578 Throw<std::runtime_error>(
"MPT has not been created");
597 Throw<std::runtime_error>(
"MPT has not been created");
604 Throw<std::runtime_error>(
"MPT has not been created");
612 Throw<std::runtime_error>(
"MPT has not been created");
616 return sle->getFieldU64(sfOutstandingAmount);
621 return sle->getFieldU64(sfMPTAmount);
631 [&](
SLEP const& sle) {
632 flags = sle->getFlags();
636 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.
std::string const & human() const
Returns the human readable public key.
std::string const & name() const
Return the name.
AccountID id() const
Returns the Account ID.
A transaction testing environment.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
TER ter() const
Return the TER for the last JTx.
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
beast::unit_test::suite & test
void require(Args const &... args)
Check a set of requirements.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
std::unordered_map< std::string, Account > const holders_
MPTTester(Env &env, Account const &issuer, MPTInit const &constr={})
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_
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)
Account const & holder(std::string const &h) const
void create(MPTCreate const &arg=MPTCreate{})
bool isTransferFeePresent() const
bool checkMetadata(std::string const &metadata) const
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 authorizeHolders(Holders const &holders)
Account const & issuer() const
void authorize(MPTAuthorize const &arg=MPTAuthorize{})
MPTID const & issuanceID() const
std::int64_t getBalance(Account const &account) const
void claw(Account const &issuer, Account const &holder, std::int64_t amount, std::optional< TER > err=std::nullopt)
TER submit(A const &arg, Json::Value const &jv)
static Json::Value setjv(MPTSet const &set={})
static Json::Value destroyjv(MPTDestroy const &arg=MPTDestroy{})
static Json::Value createjv(MPTCreate const &arg=MPTCreate{})
PrettyAmount mpt(std::int64_t amount) const
static Json::Value authorizejv(MPTAuthorize const &arg=MPTAuthorize{})
void destroy(MPTDestroy const &arg=MPTDestroy{})
bool checkTransferFee(std::uint16_t transferFee) const
bool checkDomainID(std::optional< uint256 > expected) const
std::uint32_t getFlags(std::optional< Account > const &holder) const
static std::unordered_map< std::string, Account > makeHolders(std::vector< Account > const &holders)
PrettyAmount operator()(std::uint64_t amount) const
bool checkMPTokenOutstandingAmount(std::int64_t expectedAmount) const
Converts to MPT Issue or STAmount.
MPTTester const & tester_
std::int64_t const amount_
void operator()(Env &env) const
std::optional< Account > holder_
void operator()(Env &env) const
Match the number of items in the account's owner directory.
std::function< bool()> cb_
void operator()(Env &env) const
Check a set of conditions.
Set the expected result code for a JTx The test will fail if the code doesn't match.
Keylet mptIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Json::Value create(AccountID const &account, AccountID const &to, STAmount const &amount, NetClock::duration const &settleDelay, PublicKey const &pk, std::optional< NetClock::time_point > const &cancelAfter, std::optional< std::uint32_t > const &dstTag)
Json::Value claw(Account const &account, STAmount const &amount, std::optional< Account > const &mptHolder)
static MPTCreate makeMPTCreate(MPTInitDef const &arg)
void fund(jtx::Env &env, jtx::Account const &gw, std::vector< jtx::Account > const &accounts, std::vector< STAmount > const &amts, Fund how)
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 tmfMPTClearCanTransfer
constexpr std::uint32_t const tmfMPTClearCanLock
constexpr std::uint32_t const tmfMPTClearCanClawback
std::string to_string(base_uint< Bits, Tag > const &a)
std::string strHex(FwdIt begin, FwdIt end)
constexpr std::uint32_t const tfMPTRequireAuth
constexpr std::uint32_t const tmfMPTClearCanEscrow
constexpr std::uint32_t const tmfMPTSetRequireAuth
constexpr std::uint32_t const tmfMPTClearRequireAuth
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
STAmount multiply(STAmount const &amount, Rate const &rate)
constexpr std::uint32_t const tfMPTUnlock
constexpr std::uint32_t const tmfMPTSetCanLock
constexpr std::uint32_t const tfMPTLock
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
constexpr std::uint32_t const tmfMPTClearCanTrade
constexpr std::uint32_t const tfMPTUnauthorize
constexpr std::uint32_t const tmfMPTSetCanTrade
constexpr std::uint32_t const tmfMPTSetCanClawback
constexpr std::uint32_t const tmfMPTSetCanEscrow
MPTID makeMptID(std::uint32_t sequence, AccountID const &account)
constexpr std::uint32_t const tmfMPTSetCanTransfer
std::optional< Account > holder
std::optional< Account > account
std::optional< MPTID > id
std::optional< std::uint32_t > flags
std::optional< std::uint8_t > assetScale
std::optional< std::uint32_t > mutableFlags
std::optional< std::string > metadata
std::optional< std::uint32_t > flags
std::optional< uint256 > domainID
std::optional< std::uint64_t > maxAmt
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
std::optional< Account > issuer
std::optional< MPTID > id
std::uint16_t transferFee
std::optional< std::uint64_t > maxAmt
std::optional< std::uint64_t > pay
std::optional< MPTCreate > create
PrettyAmount const xrpHolders
std::optional< uint256 > domainID
std::optional< Account > account
std::optional< MPTID > id
std::optional< std::uint16_t > transferFee
std::optional< std::uint32_t > flags
std::optional< std::variant< Account, AccountID > > holder
std::optional< std::uint32_t > mutableFlags
std::optional< std::string > metadata
std::optional< Account > delegate
Represents an XRP or IOU quantity This customizes the string conversion and supports XRP conversions ...