3#include <xrpl/ledger/helpers/DirectoryHelpers.h>
4#include <xrpl/protocol/AmountConversions.h>
5#include <xrpl/protocol/Feature.h>
6#include <xrpl/protocol/Quality.h>
7#include <xrpl/protocol/Rate.h>
8#include <xrpl/protocol/jss.h>
9#include <xrpl/tx/apply.h>
21 using namespace test::jtx;
23 Account
const alice(
"alice");
24 env.fund(XRP(10000), noripple(alice));
26 auto const jrr = env.le(alice);
27 BEAST_EXPECT(jrr && jrr->at(sfFlags) == 0u);
35 using namespace test::jtx;
36 Account
const alice(
"alice");
38 Env env(*
this, testable_amendments());
39 env.fund(XRP(10000), noripple(alice));
44 env(regkey(alice, alie));
47 auto testFlags = [
this, &alice, &alie, &env](
50 for (
std::uint32_t flag{1u}; flag < std::numeric_limits<std::uint32_t>::digits; ++flag)
52 if (flag == asfNoFreeze)
59 if (flag == asfAuthorizedNFTokenMinter)
67 if (flag == asfDisallowIncomingCheck || flag == asfDisallowIncomingPayChan ||
68 flag == asfDisallowIncomingNFTokenOffer || flag == asfDisallowIncomingTrustline)
74 if (flag == asfAllowTrustLineClawback)
80 if (flag == asfAllowTrustLineLocking)
87 if (
std::find(goodFlags.begin(), goodFlags.end(), flag) != goodFlags.end())
90 env.require(nflags(alice, flag));
91 env(fset(alice, flag), sig(alice));
93 env.require(flags(alice, flag));
94 env(fclear(alice, flag), sig(alie));
96 env.require(nflags(alice, flag));
98 BEAST_EXPECT(now_flags == orig_flags);
103 BEAST_EXPECT((*env.le(alice))[sfFlags] == orig_flags);
104 env(fset(alice, flag), sig(alice));
106 BEAST_EXPECT((*env.le(alice))[sfFlags] == orig_flags);
107 env(fclear(alice, flag), sig(alie));
109 BEAST_EXPECT((*env.le(alice))[sfFlags] == orig_flags);
126 testcase(
"Set and reset AccountTxnID");
128 using namespace test::jtx;
130 Account
const alice(
"alice");
131 env.fund(XRP(10000), noripple(alice));
137 BEAST_EXPECT(!env.le(alice)->isFieldPresent(sfAccountTxnID));
138 env(fset(alice, asfAccountTxnID), sig(alice));
139 BEAST_EXPECT(env.le(alice)->isFieldPresent(sfAccountTxnID));
140 env(fclear(alice, asfAccountTxnID));
141 BEAST_EXPECT(!env.le(alice)->isFieldPresent(sfAccountTxnID));
143 BEAST_EXPECT(now_flags == orig_flags);
151 using namespace test::jtx;
153 Account
const alice(
"alice");
154 env.fund(XRP(10000), noripple(alice));
156 env(regkey(alice,
"eric"));
158 env.require(nflags(alice, asfNoFreeze));
160 env(fset(alice, asfNoFreeze), sig(alice));
161 env.require(flags(alice, asfNoFreeze));
162 env(fclear(alice, asfNoFreeze), sig(alice));
164 env.require(flags(alice, asfNoFreeze));
172 using namespace test::jtx;
174 Account
const alice(
"alice");
175 env.fund(XRP(10000), alice);
176 auto jt =
noop(alice);
184 jt[sfDomain.fieldName] =
strHex(domain);
186 BEAST_EXPECT((*env.le(alice))[sfDomain] ==
makeSlice(domain));
188 jt[sfDomain.fieldName] =
"";
190 BEAST_EXPECT(!env.le(alice)->isFieldPresent(sfDomain));
196 for (
std::size_t len = maxLength - 1; len <= maxLength + 1; ++len)
200 BEAST_EXPECT(domain2.
length() == len);
202 jt[sfDomain.fieldName] =
strHex(domain2);
204 if (len <= maxLength)
207 BEAST_EXPECT((*env.le(alice))[sfDomain] ==
makeSlice(domain2));
221 using namespace test::jtx;
223 Account
const alice(
"alice");
224 env.fund(XRP(10000), alice);
225 auto jt =
noop(alice);
228 jt[sfMessageKey.fieldName] =
strHex(rkp.first.slice());
230 BEAST_EXPECT(
strHex((*env.le(alice))[sfMessageKey]) ==
strHex(rkp.first.slice()));
232 jt[sfMessageKey.fieldName] =
"";
234 BEAST_EXPECT(!env.le(alice)->isFieldPresent(sfMessageKey));
236 using namespace std::string_literals;
237 jt[sfMessageKey.fieldName] =
strHex(
"NOT_REALLY_A_PUBKEY"s);
246 using namespace test::jtx;
248 Account
const alice(
"alice");
249 env.fund(XRP(10000), alice);
250 auto jt =
noop(alice);
253 "9633EC8AF54F16B5286DB1D7B519EF49EEFC050C0C8AC4384F1D88ACD1BFDF05";
254 jt[sfWalletLocator.fieldName] = locator;
256 BEAST_EXPECT(
to_string((*env.le(alice))[sfWalletLocator]) == locator);
258 jt[sfWalletLocator.fieldName] =
"";
260 BEAST_EXPECT(!env.le(alice)->isFieldPresent(sfWalletLocator));
268 using namespace test::jtx;
270 Account
const alice(
"alice");
271 env.fund(XRP(10000), alice);
272 auto jt =
noop(alice);
274 std::string const mh(
"5F31A79367DC3137FADA860C05742EE6");
275 jt[sfEmailHash.fieldName] = mh;
277 BEAST_EXPECT(
to_string((*env.le(alice))[sfEmailHash]) == mh);
279 jt[sfEmailHash.fieldName] =
"";
281 BEAST_EXPECT(!env.le(alice)->isFieldPresent(sfEmailHash));
296 using namespace test::jtx;
299 Env env(*
this, features);
301 Account
const alice(
"alice");
302 env.fund(XRP(10000), alice);
304 for (
auto const& r : testData)
306 env(rate(alice, r.set), ter(r.code));
310 if (!(*env.le(alice))[~sfTransferRate])
312 BEAST_EXPECT(r.get == 1.0);
316 BEAST_EXPECT(*(*env.le(alice))[~sfTransferRate] == r.get * QUALITY_ONE);
322 testable_amendments(),
337 using namespace test::jtx;
339 Account
const alice(
"alice");
340 Account
const bob(
"bob");
341 Account
const gw(
"gateway");
342 auto const USD = gw[
"USD"];
348 env.fund(XRP(10000), gw, alice, bob);
350 env.trust(USD(10), alice, bob);
355 auto const amount = USD(1);
359 env(pay(gw, alice, USD(10)));
361 env(pay(alice, bob, USD(1)), sendmax(USD(10)));
364 env.require(balance(alice, USD(10) - amountWithRate));
365 env.require(balance(bob, USD(1)));
379 env.fund(XRP(10000), gw, alice, bob);
381 env.trust(USD(10), alice, bob);
395 uint256 const nftId0{token::getNextID(env, gw, 0u)};
396 env(token::mint(gw, 0u));
399 env(token::burn(gw, nftId0));
415 (*replacement)[sfTransferRate] =
421 auto const amount = USD(1);
422 auto const amountWithRate =
425 env(pay(gw, alice, USD(10)));
426 env(pay(alice, bob, amount), sendmax(USD(10)));
428 env.require(balance(alice, USD(10) - amountWithRate));
429 env.require(balance(bob, amount));
438 using namespace test::jtx;
440 Account
const alice(
"alice");
441 env.fund(XRP(10000), alice);
443 auto jt = fset(alice, asfDisallowXRP);
444 jt[jss::ClearFlag] = asfDisallowXRP;
447 jt = fset(alice, asfRequireAuth);
448 jt[jss::ClearFlag] = asfRequireAuth;
451 jt = fset(alice, asfRequireDest);
452 jt[jss::ClearFlag] = asfRequireDest;
455 jt = fset(alice, asfDisallowXRP);
456 jt[sfFlags.fieldName] = tfAllowXRP;
459 jt = fset(alice, asfRequireAuth);
460 jt[sfFlags.fieldName] = tfOptionalAuth;
463 jt = fset(alice, asfRequireDest);
464 jt[sfFlags.fieldName] = tfOptionalDestTag;
467 jt = fset(alice, asfRequireDest);
468 jt[sfFlags.fieldName] = tfAccountSetMask;
479 using namespace test::jtx;
481 Account
const alice(
"alice");
482 Account
const bob(
"bob");
484 env.fund(XRP(10000), alice);
491 env(signers(alice, 1, {{bob, 1}}));
495 env(fset(alice, asfRequireAuth), ter(
tecOWNERS));
502 env(fset(alice, asfRequireAuth));
508 using namespace test::jtx;
510 Account
const alice(
"alice");
512 env.fund(XRP(10000), alice);
516 env(ticket::create(alice, 1));
518 env.require(owners(alice, 1), tickets(alice, 1));
523 env.require(owners(alice, 1), tickets(alice, 1));
528 env(
noop(alice), ticket::use(ticketSeq));
530 env.require(owners(alice, 0), tickets(alice, 0));
531 BEAST_EXPECT(aliceSeq == env.seq(alice));
541 using namespace test::jtx;
544 Account
const alice(
"alice");
546 env.fund(XRP(10000), alice);
550 if (!BEAST_EXPECT(jtx.stx))
558 BEAST_EXPECT(!result.applied);
559 return result.applied;
A generic endpoint for log messages.
testcase_t testcase
Memberspace for declaring test cases.
void testRequireAuthWithDir()
void testNullAccountSet()
void testSetAndResetAccountTxnID()
void run() override
Runs the suite.
Writable ledger view that accumulates state and tx changes.
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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,...
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
ApplyResult apply(ServiceRegistry ®istry, OpenView &view, STTx const &tx, ApplyFlags flags, beast::Journal journal)
Apply a transaction to an OpenView.
std::string to_string(base_uint< Bits, Tag > const &a)
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
std::string strHex(FwdIt begin, FwdIt end)
STAmount multiply(STAmount const &amount, Rate const &rate)
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
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)
STAmount toAmount< STAmount >(STAmount const &amt)
Represents a transfer rate.