22#include <xrpl/protocol/AmountConversions.h>
23#include <xrpl/protocol/Feature.h>
24#include <xrpl/protocol/Quality.h>
25#include <xrpl/protocol/Rate.h>
26#include <xrpl/protocol/jss.h>
38 using namespace test::jtx;
43 auto const jrr = env.
le(alice);
44 BEAST_EXPECT(jrr && jrr->at(sfFlags) == 0u);
52 using namespace test::jtx;
65 auto testFlags = [
this, &alice, &alie, &env](
69 flag < std::numeric_limits<std::uint32_t>::digits;
103 if (
std::find(goodFlags.begin(), goodFlags.end(), flag) !=
108 env(
fset(alice, flag),
sig(alice));
115 BEAST_EXPECT(now_flags == orig_flags);
120 BEAST_EXPECT((*env.
le(alice))[sfFlags] == orig_flags);
121 env(
fset(alice, flag),
sig(alice));
123 BEAST_EXPECT((*env.
le(alice))[sfFlags] == orig_flags);
126 BEAST_EXPECT((*env.
le(alice))[sfFlags] == orig_flags);
156 testcase(
"Set and reset AccountTxnID");
158 using namespace test::jtx;
167 BEAST_EXPECT(!env.
le(alice)->isFieldPresent(sfAccountTxnID));
169 BEAST_EXPECT(env.
le(alice)->isFieldPresent(sfAccountTxnID));
171 BEAST_EXPECT(!env.
le(alice)->isFieldPresent(sfAccountTxnID));
173 BEAST_EXPECT(now_flags == orig_flags);
181 using namespace test::jtx;
186 env(
regkey(alice,
"eric"));
202 using namespace test::jtx;
206 auto jt =
noop(alice);
214 jt[sfDomain.fieldName] =
strHex(domain);
216 BEAST_EXPECT((*env.
le(alice))[sfDomain] ==
makeSlice(domain));
218 jt[sfDomain.fieldName] =
"";
220 BEAST_EXPECT(!env.
le(alice)->isFieldPresent(sfDomain));
226 for (
std::size_t len = maxLength - 1; len <= maxLength + 1; ++len)
231 BEAST_EXPECT(domain2.
length() == len);
233 jt[sfDomain.fieldName] =
strHex(domain2);
235 if (len <= maxLength)
238 BEAST_EXPECT((*env.
le(alice))[sfDomain] ==
makeSlice(domain2));
252 using namespace test::jtx;
256 auto jt =
noop(alice);
259 jt[sfMessageKey.fieldName] =
strHex(rkp.first.slice());
262 strHex((*env.
le(alice))[sfMessageKey]) ==
263 strHex(rkp.first.slice()));
265 jt[sfMessageKey.fieldName] =
"";
267 BEAST_EXPECT(!env.
le(alice)->isFieldPresent(sfMessageKey));
269 using namespace std::string_literals;
270 jt[sfMessageKey.fieldName] =
strHex(
"NOT_REALLY_A_PUBKEY"s);
279 using namespace test::jtx;
283 auto jt =
noop(alice);
286 "9633EC8AF54F16B5286DB1D7B519EF49EEFC050C0C8AC4384F1D88ACD1BFDF05";
287 jt[sfWalletLocator.fieldName] = locator;
289 BEAST_EXPECT(
to_string((*env.
le(alice))[sfWalletLocator]) == locator);
291 jt[sfWalletLocator.fieldName] =
"";
293 BEAST_EXPECT(!env.
le(alice)->isFieldPresent(sfWalletLocator));
301 using namespace test::jtx;
305 auto jt =
noop(alice);
307 std::string const mh(
"5F31A79367DC3137FADA860C05742EE6");
308 jt[sfEmailHash.fieldName] = mh;
310 BEAST_EXPECT(
to_string((*env.
le(alice))[sfEmailHash]) == mh);
312 jt[sfEmailHash.fieldName] =
"";
314 BEAST_EXPECT(!env.
le(alice)->isFieldPresent(sfEmailHash));
329 using namespace test::jtx;
330 auto doTests = [
this](
333 Env env(*
this, features);
338 for (
auto const& r : testData)
340 env(
rate(alice, r.set),
ter(r.code));
344 if (!(*env.
le(alice))[~sfTransferRate])
345 BEAST_EXPECT(r.get == 1.0);
348 *(*env.
le(alice))[~sfTransferRate] ==
349 r.get * QUALITY_ONE);
369 using namespace test::jtx;
374 auto const USD = gw[
"USD"];
381 env.
fund(
XRP(10000), gw, alice, bob);
383 env.
trust(USD(10), alice, bob);
388 auto const amount = USD(1);
390 auto const amountWithRate =
393 env(
pay(gw, alice, USD(10)));
395 env(
pay(alice, bob, USD(1)),
sendmax(USD(10)));
413 env.
fund(
XRP(10000), gw, alice, bob);
415 env.
trust(USD(10), alice, bob);
449 auto replacement = std::make_shared<SLE>(*sle, sle->key());
450 (*replacement)[sfTransferRate] =
456 auto const amount = USD(1);
460 env(
pay(gw, alice, USD(10)));
461 env(
pay(alice, bob, amount),
sendmax(USD(10)));
473 using namespace test::jtx;
516 using namespace test::jtx;
528 env(
signers(alice, 1, {{bob, 1}}));
545 using namespace test::jtx;
568 BEAST_EXPECT(aliceSeq == env.
seq(alice));
A generic endpoint for log messages.
testcase_t testcase
Memberspace for declaring test cases.
void testNullAccountSet()
void testSetAndResetAccountTxnID()
void testRequireAuthWithDir()
void run() override
Runs the suite.
virtual OpenLedger & openLedger()=0
bool modify(modify_type const &f)
Modify the open ledger.
Writable ledger view that accumulates state and tx changes.
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
Immutable cryptographic account descriptor.
AccountID id() const
Returns the Account ID.
A transaction testing environment.
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
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.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
void enableFeature(uint256 const feature)
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
void memoize(Account const &account)
Associate AccountID with account.
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Match clear account flags.
Match the number of items in the account's owner directory.
Sets the SendMax on a JTx.
Set the regular signature on a JTx.
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.
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Json::Value create(Account const &account, std::uint32_t count)
Create one of more tickets.
uint256 getNextID(jtx::Env const &env, jtx::Account const &issuer, std::uint32_t nfTokenTaxon, std::uint16_t flags, std::uint16_t xferFee)
Get the next NFTokenID that will be issued.
Json::Value mint(jtx::Account const &account, std::uint32_t nfTokenTaxon)
Mint an NFToken.
Json::Value burn(jtx::Account const &account, uint256 const &nftokenID)
Burn an NFToken.
Json::Value fclear(Account const &account, std::uint32_t off)
Remove account flag.
Json::Value regkey(Account const &account, disabled_t)
Disable the regular key.
Json::Value signers(Account const &account, std::uint32_t quorum, std::vector< signer > const &v)
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Json::Value rate(Account const &account, double multiplier)
Set a transfer rate.
std::array< Account, 1+sizeof...(Args)> noripple(Account const &account, Args const &... args)
Designate accounts as no-ripple in Env::fund.
owner_count< ltTICKET > tickets
Match the number of tickets on the account.
XRP_t const XRP
Converts to XRP Issue or STAmount.
FeatureBitset supported_amendments()
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::uint32_t tfAllowXRP
constexpr std::uint32_t asfGlobalFreeze
constexpr std::uint32_t asfDepositAuth
constexpr std::uint32_t asfDisallowIncomingNFTokenOffer
constexpr std::uint32_t asfRequireDest
STAmount toAmount< STAmount >(STAmount const &amt)
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
constexpr std::uint32_t asfAuthorizedNFTokenMinter
constexpr std::uint32_t tfOptionalDestTag
constexpr std::uint32_t tfAccountSetMask
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
STAmount multiply(STAmount const &amount, Rate const &rate)
constexpr std::uint32_t asfNoFreeze
constexpr std::uint32_t asfDisableMaster
constexpr std::uint32_t asfDisallowIncomingTrustline
std::string strHex(FwdIt begin, FwdIt end)
constexpr std::uint32_t asfAccountTxnID
constexpr std::uint32_t asfDefaultRipple
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
constexpr std::uint32_t asfDisallowIncomingCheck
constexpr std::uint32_t tfOptionalAuth
std::string to_string(base_uint< Bits, Tag > const &a)
constexpr std::uint32_t asfDisallowIncomingPayChan
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
constexpr std::uint32_t asfAllowTrustLineClawback
constexpr std::uint32_t asfRequireAuth
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
constexpr std::uint32_t asfDisallowXRP
Represents a transfer rate.