22#include <xrpl/protocol/Feature.h>
23#include <xrpl/protocol/jss.h>
46 Json::Value const meta = env.
rpc(
"tx", txHash)[jss::result][jss::meta];
49 if (!BEAST_EXPECT(meta.
isMember(sfDeliveredAmount.jsonName)))
55 BEAST_EXPECT(meta[sfDeliveredAmount.jsonName] == jsonExpect);
56 BEAST_EXPECT(meta[jss::delivered_amount] == jsonExpect);
70 jv[jss::TransactionType] = jss::PaymentChannelCreate;
71 jv[jss::Account] = account.human();
72 jv[jss::Destination] = to.
human();
74 jv[sfSettleDelay.jsonName] = settleDelay.
count();
94 env.fund(
XRP(10000), alice, becky, carol, gw);
110 auto const acctDelFee{
drops(env.current()->fees().increment)};
122 env(
trust(becky, gw[
"USD"](1000)));
129 env(
offer(carol, gw[
"USD"](51),
XRP(51)));
132 env(
signers(carol, 1, {{alice, 1}, {becky, 1}}));
151 auto const aliceOldBalance{env.balance(alice)};
152 auto const beckyOldBalance{env.balance(becky)};
168 env.balance(becky) ==
169 aliceOldBalance + beckyOldBalance - acctDelFee);
190 for (
int i = 0; i < 8; ++i)
194 auto const beckyOldBalance{env.balance(becky)};
195 auto const carolOldBalance{env.balance(carol)};
201 BEAST_EXPECT(env.closed()->exists(
205 BEAST_EXPECT(env.closed()->exists(
218 BEAST_EXPECT(!env.closed()->exists(
220 BEAST_EXPECT(!env.closed()->exists(
222 BEAST_EXPECT(!env.closed()->exists(
228 env.balance(becky) ==
229 carolOldBalance + beckyOldBalance - acctDelFee);
251 env.fund(
XRP(10000), alice, gw);
255 for (
int i{0}; i < 45; ++i)
257 env(
offer(alice, gw[
"USD"](1),
XRP(1)));
260 env.require(
offers(alice, 45));
268 BEAST_EXPECT(env.closed()->exists(aliceRootKey));
269 BEAST_EXPECT(env.closed()->exists(alicePageKey));
272 auto const acctDelFee{
drops(env.current()->fees().increment)};
273 auto const aliceBalance{env.balance(alice)};
279 BEAST_EXPECT(!env.closed()->exists(aliceRootKey));
280 BEAST_EXPECT(!env.closed()->exists(alicePageKey));
300 env.fund(
XRP(100000), alice, becky, gw);
306 for (
int i{0}; i < 200; ++i)
308 env(
offer(alice, gw[
"USD"](1),
XRP(1)));
309 env(
offer(becky, gw[
"USD"](1),
XRP(1)));
312 env.require(
offers(alice, 200));
313 env.require(
offers(becky, 200));
327 auto const acctDelFee{
drops(env.current()->fees().increment)};
344 jv[jss::TransactionType] = jss::EscrowCreate;
345 jv[jss::Account] = account.human();
346 jv[jss::Destination] = to.human();
348 jv[sfFinishAfter.jsonName] =
349 cancelAfter.time_since_epoch().count() + 1;
350 jv[sfCancelAfter.jsonName] =
351 cancelAfter.time_since_epoch().count() + 2;
355 using namespace std::chrono_literals;
357 env(escrowCreate(alice, becky,
XRP(333), env.now() + 2s));
373 jv[jss::TransactionType] = jss::EscrowCancel;
374 jv[jss::Account] = account.human();
375 jv[sfOwner.jsonName] = from.human();
376 jv[sfOfferSequence.jsonName] =
seq;
379 env(escrowCancel(becky, alice, escrowSeq));
382 Keylet const alicePayChanKey{
386 alice, becky,
XRP(57), 4s, env.now() + 2s, alice.
pk()));
392 auto const beckyBalance{env.balance(becky)};
403 Keylet const& payChanKeylet,
406 jv[jss::TransactionType] = jss::PaymentChannelClaim;
408 jv[jss::Account] = account.human();
409 jv[sfChannel.jsonName] =
to_string(payChanKeylet.key);
410 jv[sfPublicKey.jsonName] =
strHex(pk.slice());
413 env(payChanClose(alice, alicePayChanKey, alice.
pk()));
418 env.enableFeature(fixPayChanRecipientOwnerDir);
435 env(payChanClose(alice, gwPayChanKey, alice.
pk()));
439 auto const aliceBalance{env.balance(alice)};
461 env.fund(
XRP(10000), alice, becky);
466 BEAST_EXPECT(env.closed()->exists(beckyAcctKey));
468 using namespace std::chrono_literals;
470 auto const payChanXRP =
XRP(37);
473 alice, becky, payChanXRP, 4s, env.now() + 1h, alice.
pk()));
475 BEAST_EXPECT(env.closed()->exists(payChanKey));
480 auto const beckyPreDelBalance{env.balance(becky)};
482 auto const acctDelFee{
drops(env.current()->fees().increment)};
488 BEAST_EXPECT(!env.closed()->exists(beckyAcctKey));
494 drops(env.current()->fees().accountReserve(0)) -
XRP(1)),
499 env(
pay(alice, becky,
XRP(10)));
503 BEAST_EXPECT(env.closed()->exists(beckyAcctKey));
504 BEAST_EXPECT(env.balance(becky) ==
XRP(10));
508 auto payChanClaim = [&]() {
510 jv[jss::TransactionType] = jss::PaymentChannelClaim;
511 jv[jss::Account] = alice.
human();
512 jv[sfChannel.jsonName] =
to_string(payChanKey.key);
513 jv[sfBalance.jsonName] =
520 BEAST_EXPECT(env.balance(becky) ==
XRP(10) + payChanXRP);
536 env.fund(
XRP(10000), alice, becky);
544 BEAST_EXPECT(env.closed()->exists(aliceAcctKey));
546 auto const alicePreDelBal{env.balance(alice)};
547 auto const beckyPreDelBal{env.balance(becky)};
549 auto const acctDelFee{
drops(env.current()->fees().increment)};
555 BEAST_EXPECT(env.current()->exists(aliceAcctKey));
556 BEAST_EXPECT(env.balance(alice) == alicePreDelBal);
557 BEAST_EXPECT(env.balance(becky) == beckyPreDelBal);
561 env.enableFeature(featureDeletableAccounts);
565 BEAST_EXPECT(env.closed()->exists(aliceAcctKey));
569 BEAST_EXPECT(!env.current()->exists(aliceAcctKey));
571 env.balance(becky) == alicePreDelBal + beckyPreDelBal - acctDelFee);
574 BEAST_EXPECT(!env.closed()->exists(aliceAcctKey));
590 env.fund(
XRP(10000000), alice, gw);
600 constexpr int offerCount{1001};
601 for (
int i{0}; i < offerCount; ++i)
603 env(
offer(alice, gw[currency](1),
XRP(1)));
608 if (currency[0] >
'Z')
613 if (currency[1] >
'Z')
618 if (currency[2] >
'Z')
634 BEAST_EXPECT(closed->exists(aliceOwnerDirKey));
638 BEAST_EXPECT(closed->exists(
keylet::page(aliceOwnerDirKey, i)));
648 auto const acctDelFee{
drops(env.current()->fees().increment)};
653 env.require(
offers(alice, offerCount));
656 env.require(
offers(alice, offerCount - 1));
659 auto const alicePreDelBal{env.balance(alice)};
669 BEAST_EXPECT(!closed->exists(aliceOwnerDirKey));
690 testcase(
"Implicitly created trust line");
695 auto const BUX{gw[
"BUX"]};
697 env.fund(
XRP(10000), alice, gw);
702 env(
offer(alice, BUX(30),
XRP(30)));
708 env.require(
balance(alice, BUX(30)));
715 auto const acctDelFee{
drops(env.current()->fees().increment)};
735 testcase(
"Balance too small for fee");
743 env.fund(env.current()->fees().accountReserve(0),
noripple(alice));
748 env(
noop(alice),
fee(env.balance(alice) -
XRP(1)));
751 auto const acctDelFee{
drops(env.current()->fees().increment)};
752 BEAST_EXPECT(acctDelFee > env.balance(alice));
758 auto const masterBalance{env.balance(env.master)};
766 BEAST_EXPECT(env.balance(env.master) == masterBalance);
771 BEAST_EXPECT(env.balance(alice) ==
XRP(1));
777 BEAST_EXPECT(env.balance(env.master) == masterBalance);
786 using namespace test::jtx;
792 env.
fund(
XRP(100000), alice, bob);
799 env.require(
owners(bob, 250));
816 auto const acctDelFee{
drops(env.current()->fees().increment)};
817 auto const bobOldBalance{env.balance(bob)};
835 testcase(
"Destination Constraints");
837 using namespace test::jtx;
845 env.
fund(
XRP(100000), alice, becky, carol);
862 auto const acctDelFee{
drops(env.current()->fees().increment)};
881 auto const beckyOldBalance{env.balance(becky)};
892 "Destination Constraints with DepositPreauth and Credentials");
894 using namespace test::jtx;
901 char const credType[] =
"abcd";
904 env.
fund(
XRP(100000), alice, becky, carol, daria);
914 std::string const credIdx = jv[jss::result][jss::index].asString();
919 auto const acctDelFee{
drops(env.current()->fees().increment)};
979 {
"48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6E"
996 jNoCred.isObject() && jNoCred.isMember(jss::result) &&
997 jNoCred[jss::result].isMember(jss::error) &&
998 jNoCred[jss::result][jss::error] ==
"entryNotFound");
1001 testcase(
"Credentials that aren't required");
1009 env, daria, carol, credType)[jss::result][jss::index]
1020 auto const jNoCred =
1024 jNoCred.isObject() && jNoCred.isMember(jss::result) &&
1025 jNoCred[jss::result].isMember(jss::error) &&
1026 jNoCred[jss::result][jss::error] ==
"entryNotFound");
1033 env.fund(
XRP(5000), eaton, fred);
1042 env, eaton, carol, credType)[jss::result][jss::index]
1053 auto const acctDelFee{
drops(env.current()->fees().increment)};
1063 auto const jNoCred =
1067 jNoCred.isObject() && jNoCred.isMember(jss::result) &&
1068 jNoCred[jss::result].isMember(jss::error) &&
1069 jNoCred[jss::result][jss::error] ==
"entryNotFound");
1076 env.fund(
XRP(10000), john);
1080 uint32_t
const t = env.current()
1082 .parentCloseTime.time_since_epoch()
1085 jv[sfExpiration.jsonName] = t;
1092 jv[jss::result][jss::index].asString();
1109 jv.isObject() && jv.isMember(jss::result) &&
1110 jv[jss::result].isMember(jss::error) &&
1111 jv[jss::result][jss::error] ==
"entryNotFound");
1117 testcase(
"Credentials feature disabled");
1118 using namespace test::jtx;
1125 env.fund(
XRP(100000), alice, becky, carol);
1137 auto const acctDelFee{
drops(env.current()->fees().increment)};
1140 "098B7F1B146470A1C5084DC7832C04A72939E3EBC58E68AB8B579BA072B0CE"
1159 testcase(
"Deleting Issuer deletes issued credentials");
1161 using namespace test::jtx;
1167 char const credType[] =
"abcd";
1170 env.
fund(
XRP(100000), alice, becky, carol);
1182 std::string const credIdx = jv[jss::result][jss::index].asString();
1187 auto const acctDelFee{
drops(env.current()->fees().increment)};
1192 BEAST_EXPECT(!env.le(credIdx));
1196 jv.isObject() && jv.isMember(jss::result) &&
1197 jv[jss::result].isMember(jss::error) &&
1198 jv[jss::result][jss::error] ==
"entryNotFound");
1203 testcase(
"Deleting Subject deletes issued credentials");
1205 using namespace test::jtx;
1211 char const credType[] =
"abcd";
1214 env.
fund(
XRP(100000), alice, becky, carol);
1226 std::string const credIdx = jv[jss::result][jss::index].asString();
1231 auto const acctDelFee{
drops(env.current()->fees().increment)};
1236 BEAST_EXPECT(!env.le(credIdx));
1240 jv.isObject() && jv.isMember(jss::result) &&
1241 jv[jss::result].isMember(jss::error) &&
1242 jv[jss::result][jss::error] ==
"entryNotFound");
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
testcase_t testcase
Memberspace for declaring test cases.
Slice slice() const noexcept
Json::Value getJson(JsonOptions=JsonOptions::none) const override
void testBalanceTooSmallForFee()
void verifyDeliveredAmount(jtx::Env &env, STAmount const &amount)
void testDeleteCredentialsOwner()
void run() override
Runs the suite.
void testAmendmentEnable()
void testDestinationDepositAuthCredentials()
static Json::Value payChanCreate(jtx::Account const &account, jtx::Account const &to, STAmount const &amount, NetClock::duration const &settleDelay, NetClock::time_point const &cancelAfter, PublicKey const &pk)
void testImplicitlyCreatedTrustline()
Immutable cryptographic account descriptor.
PublicKey const & pk() const
Return the public key.
AccountID id() const
Returns the Account ID.
static Account const master
The master account.
std::string const & human() const
Returns the human readable public key.
A transaction testing environment.
std::shared_ptr< STTx const > tx() const
Return the tx data for the last JTx.
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.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Set a multisignature on a JTx.
Match the number of items in the account's owner directory.
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 page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet signers(AccountID const &account) noexcept
A SignerList.
static ticket_t const ticket
Keylet check(AccountID const &id, std::uint32_t seq) noexcept
A Check.
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Keylet payChan(AccountID const &src, AccountID const &dst, std::uint32_t seq) noexcept
A PaymentChannel.
Json::Value create(A const &account, A const &dest, STAmount const &sendMax)
Create a check.
Json::Value cancel(jtx::Account const &dest, uint256 const &checkId)
Cancel a check.
Json::Value create(jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Json::Value accept(jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Json::Value ledgerEntry(jtx::Env &env, jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Json::Value auth(Account const &account, Account const &auth)
Preauthorize for deposit.
Json::Value authCredentials(jtx::Account const &account, std::vector< AuthorizeCredentials > const &auth)
Json::Value setValid(jtx::Account const &account)
Json::Value create(Account const &account, std::uint32_t count)
Create one of more tickets.
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)
owner_count< ltOFFER > offers
Match the number of offers in the account's owner directory.
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
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.
void incLgrSeqForAccDel(jtx::Env &env, jtx::Account const &acc, std::uint32_t margin=0)
Json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
Json::Value acctdelete(Account const &account, Account const &dest)
Delete account.
XRP_t const XRP
Converts to XRP Issue or STAmount.
FeatureBitset supported_amendments()
Json::Value offer_cancel(Account const &account, std::uint32_t offerSeq)
Cancel an offer.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::uint32_t asfDepositAuth
constexpr std::uint32_t asfRequireDest
constexpr std::uint32_t tfImmediateOrCancel
std::string strHex(FwdIt begin, FwdIt end)
std::string to_string(base_uint< Bits, Tag > const &a)
constexpr std::uint32_t tfClose
A pair of SHAMap key and LedgerEntryType.
Set the sequence number on a JTx.
T time_since_epoch(T... args)