20#include <test/jtx/TestHelpers.h>
21#include <test/jtx/offer.h>
22#include <test/jtx/owners.h>
23#include <xrpl/protocol/TxFlags.h>
35 return env.
rpc(
"json",
"account_offers",
to_string(jv))[jss::result];
43 return env.
rpc(
"json",
"account_lines",
to_string(jv))[jss::result];
94 return env.
current()->fees().base * n;
100 auto feeDrops = env.
current()->fees().base;
114 bool const accountLow = account < issue.
account;
116 bool expectDefaultTrustLine =
true;
122 low.setIssuer(accountLow ? account : issue.
account);
123 high.setIssuer(accountLow ? issue.
account : account);
125 expectDefaultTrustLine = sle->getFieldAmount(sfLowLimit) == low &&
126 sle->getFieldAmount(sfHighLimit) == high;
129 auto amount = sle->getFieldAmount(sfBalance);
133 return amount == value && expectDefaultTrustLine;
157 if (sle->getType() == ltOFFER)
161 toMatch.begin(), toMatch.end(), [&](auto const& a) {
162 return a.in == sle->getFieldAmount(sfTakerPays) &&
163 a.out == sle->getFieldAmount(sfTakerGets);
169 return size == cnt && matched == toMatch.size();
176 jvParams[jss::ledger_index] =
"current";
177 jvParams[jss::account_root] = acct.
human();
178 return env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
189 jvParams[jss::ledger_index] =
"current";
190 jvParams[jss::ripple_state][jss::currency] = currency;
192 jvParams[jss::ripple_state][jss::accounts].
append(acct_a.
human());
193 jvParams[jss::ripple_state][jss::accounts].
append(acct_b.
human());
194 return env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
201 return jrr[jss::node][sfBalance.fieldName];
220 jv[jss::TransactionType] = jss::EscrowCreate;
232 jv[jss::TransactionType] = jss::EscrowFinish;
236 jv[sfOfferSequence.jsonName] =
seq;
244 jv[jss::TransactionType] = jss::EscrowCancel;
247 jv[sfOwner.jsonName] = from.
human();
248 jv[sfOfferSequence.jsonName] =
seq;
265 jv[jss::TransactionType] = jss::PaymentChannelCreate;
270 jv[jss::SettleDelay] = settleDelay.
count();
273 jv[sfCancelAfter.fieldName] = cancelAfter->time_since_epoch().count();
275 jv[sfDestinationTag.fieldName] = *dstTag;
287 jv[jss::TransactionType] = jss::PaymentChannelFund;
293 jv[sfExpiration.fieldName] =
expiration->time_since_epoch().count();
307 jv[jss::TransactionType] = jss::PaymentChannelClaim;
316 jv[
"Signature"] =
strHex(*signature);
318 jv[
"PublicKey"] =
strHex(pk->slice());
335 auto const slep = view.
read({ltPAYCHAN, chan});
338 return (*slep)[sfBalance];
344 auto const slep = view.
read({ltPAYCHAN, chan});
359 auto const ownerCount = env.
le(account)->getFieldU32(sfOwnerCount);
UInt size() const
Number of values in array or object.
Value & append(const Value &value)
Append value to array at the end.
A currency issued by an account.
Slice slice() const noexcept
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
Json::Value getJson(JsonOptions) const override
Issue const & issue() const
void push_back(STPathElement const &e)
Immutable cryptographic account descriptor.
std::string const & human() const
Returns the human readable public key.
A transaction testing environment.
std::uint32_t ownerCount(Account const &account) const
Return the number of objects owned by an account.
void require(Args const &... args)
Check a set of requirements.
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.
Json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Match the number of items in the account's owner directory.
@ arrayValue
array value (ordered list)
Keylet line(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
Keylet payChan(AccountID const &src, AccountID const &dst, std::uint32_t seq) noexcept
A PaymentChannel.
bool checkArraySize(Json::Value const &val, unsigned int size)
std::uint32_t ownerCount(Env const &env, Account const &account)
Json::Value ledgerEntryRoot(Env &env, Account const &acct)
Json::Value escrow(AccountID const &account, AccountID const &to, STAmount const &amount)
bool expectOffers(Env &env, AccountID const &account, std::uint16_t size, std::vector< Amounts > const &toMatch)
STAmount channelBalance(ReadView const &view, uint256 const &chan)
uint256 channel(AccountID const &account, AccountID const &dst, std::uint32_t seqProxyValue)
PrettyAmount xrpMinusFee(Env const &env, std::int64_t xrpAmount)
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
bool expectLine(Env &env, AccountID const &account, STAmount const &value, bool defaultLimits)
bool equal(STAmount const &sa1, STAmount const &sa2)
constexpr XRPAmount dropsPerXRP
Json::Value getAccountLines(Env &env, AccountID const &acctId)
Json::Value ledgerEntryState(Env &env, Account const &acct_a, Account const &acct_b, std::string const ¤cy)
void stpath_append_one(STPath &st, Account const &account)
void fund(jtx::Env &env, jtx::Account const &gw, std::vector< jtx::Account > const &accounts, std::vector< STAmount > const &amts, Fund how)
void n_offers(Env &env, std::size_t n, Account const &account, STAmount const &in, STAmount const &out)
Json::Value accountBalance(Env &env, Account const &acct)
Json::Value cancel(AccountID const &account, Account const &from, std::uint32_t seq)
STPathElement IPE(Issue const &iss)
Json::Value claim(AccountID const &account, uint256 const &channel, std::optional< STAmount > const &balance, std::optional< STAmount > const &amount, std::optional< Slice > const &signature, std::optional< PublicKey > const &pk)
Json::Value finish(AccountID const &account, AccountID const &from, std::uint32_t seq)
Json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
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)
STPathElement cpe(Currency const &c)
bool expectLedgerEntryRoot(Env &env, Account const &acct, STAmount const &expectedValue)
STPathElement allpe(AccountID const &a, Issue const &iss)
bool channelExists(ReadView const &view, uint256 const &chan)
XRPAmount txfee(Env const &env, std::uint16_t n)
Json::Value getAccountOffers(Env &env, AccountID const &acct, bool current)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
AccountID const & xrpAccount()
Compute AccountID from public key.
@ current
This was a new validation and was added.
std::string strHex(FwdIt begin, FwdIt end)
constexpr std::uint32_t tfUniversal
std::string to_string(base_uint< Bits, Tag > const &a)
void forEachItem(ReadView const &view, Keylet const &root, std::function< void(std::shared_ptr< SLE const > const &)> const &f)
Iterate all items in the given directory.
Represents an XRP or IOU quantity This customizes the string conversion and supports XRP conversions ...
Set the sequence number on a JTx.