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");
42 : env_(env), issuer_(issuer), holders_(makeHolders(arg.holders)), close_(arg.close)
58 Throw<std::runtime_error>(
"Issuer can't be holder");
67 : env_(env), issuer_(issuer), holders_(makeHolders(holders)), id_(id), close_(close)
94MPTTester::operator
MPT()
const
97 Throw<std::runtime_error>(
"MPT has not been created");
105 Throw<std::runtime_error>(
"MPTTester::createjv: issuer is not set");
107 jv[sfAccount] = arg.
issuer->human();
120 jv[sfTransactionType] = jss::MPTokenIssuanceCreate;
129 Throw<std::runtime_error>(
"MPT can't be reused");
149 auto authAndPay = [&](
auto const& accts,
auto const&& getAcct) {
150 for (
auto const& it : accts)
155 if (arg.
pay && arg.
pay->first.empty())
160 for (
auto const& p : arg.
pay->first)
167 authAndPay(
holders_, [](
auto const& it) {
return it.second; });
169 authAndPay(*arg.
authorize, [](
auto const& it) { return it; });
173 if (arg.
pay->first.empty())
174 authAndPay(
holders_, [](
auto const& it) {
return it.second; });
176 authAndPay(arg.
pay->first, [](
auto const& it) { return it; });
186 Throw<std::runtime_error>(
"MPTTester::destroyjv: issuer/id is not set");
187 jv[sfAccount] = arg.
issuer->human();
189 jv[sfTransactionType] = jss::MPTokenIssuanceDestroy;
198 Throw<std::runtime_error>(
"MPT has not been created");
206 auto const& it =
holders_.find(holder_);
208 Throw<std::runtime_error>(
"Holder is not found");
217 Throw<std::runtime_error>(
"MPTTester::authorizejv: issuer/id is not set");
218 jv[sfAccount] = arg.
account->human();
221 jv[sfHolder] = arg.
holder->human();
222 jv[sfTransactionType] = jss::MPTokenAuthorize;
231 Throw<std::runtime_error>(
"MPT has not been created");
285 for (
auto const&
holder : holders)
296 Throw<std::runtime_error>(
"MPTTester::setjv: issuer/id is not set");
297 jv[sfAccount] = arg.
account->human();
302 [&jv]<
typename T>(T
const&
holder) {
312 jv[sfDelegate] = arg.
delegate->human();
321 jv[sfTransactionType] = jss::MPTokenIssuanceSet;
330 Throw<std::runtime_error>(
"MPT has not been created");
351 flags &= ~lsfMPTLocked;
359 flags &= ~lsfMPTCanLock;
364 flags &= ~lsfMPTRequireAuth;
369 flags &= ~lsfMPTCanEscrow;
374 flags &= ~lsfMPTCanClawback;
379 flags &= ~lsfMPTCanTrade;
384 flags &= ~lsfMPTCanTransfer;
400 Throw<std::runtime_error>(
"MPT has not been created");
402 if (
auto const sle =
env_.
le(key))
411 if (sle->isFieldPresent(sfDomainID))
412 return expected == sle->getFieldH256(sfDomainID);
420 return forObject([&](
SLEP const& sle) {
return expectedAmount == (*sle)[sfMPTAmount]; }, holder_);
426 return forObject([&](
SLEP const& sle) {
return expectedAmount == (*sle)[sfOutstandingAmount]; });
439 if (sle->isFieldPresent(sfMPTokenMetadata))
440 return strHex(sle->getFieldVL(sfMPTokenMetadata)) ==
strHex(metadata);
448 return forObject([&](
SLEP const& sle) ->
bool {
return sle->isFieldPresent(sfMPTokenMetadata); });
455 if (sle->isFieldPresent(sfTransferFee))
456 return sle->getFieldU16(sfTransferFee) == transferFee;
464 return forObject([&](
SLEP const& sle) ->
bool {
return sle->isFieldPresent(sfTransferFee); });
476 Throw<std::runtime_error>(
"MPT has not been created");
516 Throw<std::runtime_error>(
"MPT has not been created");
533 Throw<std::runtime_error>(
"MPT has not been created");
540 Throw<std::runtime_error>(
"MPT has not been created");
548 Throw<std::runtime_error>(
"MPT has not been created");
552 return sle->getFieldU64(sfOutstandingAmount);
557 return sle->getFieldU64(sfMPTAmount);
567 [&](
SLEP const& sle) {
568 flags = sle->getFlags();
572 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
PrettyAmount operator()(std::int64_t amount) const
std::uint32_t getFlags(std::optional< Account > const &holder) const
static std::unordered_map< std::string, Account > makeHolders(std::vector< Account > const &holders)
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 ...