2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/TestHelpers.h>
5#include <test/jtx/acctdelete.h>
6#include <test/jtx/amount.h>
7#include <test/jtx/balance.h>
8#include <test/jtx/check.h>
9#include <test/jtx/credentials.h>
10#include <test/jtx/deposit.h>
11#include <test/jtx/did.h>
12#include <test/jtx/escrow.h>
13#include <test/jtx/fee.h>
14#include <test/jtx/flags.h>
15#include <test/jtx/multisign.h>
16#include <test/jtx/noop.h>
17#include <test/jtx/offer.h>
18#include <test/jtx/owners.h>
19#include <test/jtx/pay.h>
20#include <test/jtx/regkey.h>
21#include <test/jtx/sig.h>
22#include <test/jtx/ter.h>
23#include <test/jtx/ticket.h>
24#include <test/jtx/trust.h>
25#include <test/jtx/txflags.h>
26#include <test/jtx/vault.h>
28#include <xrpl/basics/base_uint.h>
29#include <xrpl/basics/chrono.h>
30#include <xrpl/basics/strHex.h>
31#include <xrpl/beast/unit_test/suite.h>
32#include <xrpl/ledger/ReadView.h>
33#include <xrpl/protocol/Feature.h>
34#include <xrpl/protocol/Indexes.h>
35#include <xrpl/protocol/Issue.h>
36#include <xrpl/protocol/Keylet.h>
37#include <xrpl/protocol/PublicKey.h>
38#include <xrpl/protocol/SField.h>
39#include <xrpl/protocol/STAmount.h>
40#include <xrpl/protocol/SeqProxy.h>
41#include <xrpl/protocol/TER.h>
42#include <xrpl/protocol/TxFlags.h>
43#include <xrpl/protocol/jss.h>
70 json::Value const meta = env.
rpc(
"tx", txHash)[jss::result][jss::meta];
73 if (!BEAST_EXPECT(meta.
isMember(sfDeliveredAmount.jsonName)))
79 BEAST_EXPECT(meta[sfDeliveredAmount.jsonName] == jsonExpect);
80 BEAST_EXPECT(meta[jss::delivered_amount] == jsonExpect);
94 jv[jss::TransactionType] = jss::PaymentChannelCreate;
95 jv[jss::Account] = account.human();
96 jv[jss::Destination] = to.
human();
98 jv[sfSettleDelay.jsonName] = settleDelay.
count();
118 env.
fund(
XRP(10000), alice, becky, carol, gw);
132 auto const acctDelFee{
drops(env.
current()->fees().increment)};
142 env(
trust(becky, gw[
"USD"](1000)));
149 env(
offer(carol, gw[
"USD"](51),
XRP(51)));
152 env(
signers(carol, 1, {{alice, 1}, {becky, 1}}));
171 auto const aliceOldBalance{env.
balance(alice)};
172 auto const beckyOldBalance{env.
balance(becky)};
187 BEAST_EXPECT(env.
balance(becky) == aliceOldBalance + beckyOldBalance - acctDelFee);
208 for (
int i = 0; i < 8; ++i)
212 auto const beckyOldBalance{env.
balance(becky)};
213 auto const carolOldBalance{env.
balance(carol)};
220 BEAST_EXPECT(env.
closed()->exists(
222 BEAST_EXPECT(env.
closed()->exists(
236 BEAST_EXPECT(!env.
closed()->exists(
238 BEAST_EXPECT(!env.
closed()->exists(
243 BEAST_EXPECT(env.
balance(becky) == carolOldBalance + beckyOldBalance - acctDelFee);
265 env.
fund(
XRP(10000), alice, gw);
269 for (
int i{0}; i < 45; ++i)
271 env(
offer(alice, gw[
"USD"](1),
XRP(1)));
282 BEAST_EXPECT(env.
closed()->exists(aliceRootKey));
283 BEAST_EXPECT(env.
closed()->exists(alicePageKey));
286 auto const acctDelFee{
drops(env.
current()->fees().increment)};
287 auto const aliceBalance{env.
balance(alice)};
293 BEAST_EXPECT(!env.
closed()->exists(aliceRootKey));
294 BEAST_EXPECT(!env.
closed()->exists(alicePageKey));
310 env.
fund(
XRP(100000), alice, becky, gw);
316 for (
int i{0}; i < 200; ++i)
318 env(
offer(alice, gw[
"USD"](1),
XRP(1)));
319 env(
offer(becky, gw[
"USD"](1),
XRP(1)));
337 auto const acctDelFee{
drops(env.
current()->fees().increment)};
348 using namespace std::chrono_literals;
364 bool const withTokenEscrow = env.
current()->rules().enabled(featureTokenEscrow);
369 auto const usd = gw1[
"USD"];
370 env.
fund(
XRP(100000), carol, gw1);
371 env(
fset(gw1, asfAllowTrustLineLocking));
373 env.
trust(usd(10000), carol);
375 env(
pay(gw1, carol, usd(100)));
396 Keylet const alicePayChanKey{
404 auto const beckyBalance{env.
balance(becky)};
416 jv[jss::TransactionType] = jss::PaymentChannelClaim;
417 jv[jss::Flags] = tfClose;
418 jv[jss::Account] = account.human();
419 jv[sfChannel.jsonName] =
to_string(payChanKeylet.key);
420 jv[sfPublicKey.jsonName] =
strHex(pk.slice());
423 env(payChanClose(alice, alicePayChanKey, alice.
pk()));
428 Keylet const gwPayChanKey{
440 env(payChanClose(alice, gwPayChanKey, alice.
pk()));
444 auto const aliceBalance{env.
balance(alice)};
463 env.
fund(
XRP(10000000), alice, gw);
473 static constexpr int kOfferCount{1001};
474 for (
int i{0}; i < kOfferCount; ++i)
476 env(
offer(alice, gw[currency](1),
XRP(1)));
481 if (currency[0] >
'Z')
486 if (currency[1] >
'Z')
491 if (currency[2] >
'Z')
507 BEAST_EXPECT(closed->exists(aliceOwnerDirKey));
511 BEAST_EXPECT(closed->exists(
keylet::page(aliceOwnerDirKey, i)));
516 BEAST_EXPECT(closed->exists(
523 auto const acctDelFee{
drops(env.
current()->fees().increment)};
534 auto const alicePreDelBal{env.
balance(alice)};
544 BEAST_EXPECT(!closed->exists(aliceOwnerDirKey));
548 BEAST_EXPECT(!closed->exists(
keylet::page(aliceOwnerDirKey, i)));
553 BEAST_EXPECT(!closed->exists(
566 testcase(
"Implicitly created trust line");
571 auto const bux{gw[
"BUX"]};
573 env.
fund(
XRP(10000), alice, gw);
578 env(
offer(alice, bux(30),
XRP(30)));
591 auto const acctDelFee{
drops(env.
current()->fees().increment)};
611 testcase(
"Balance too small for fee");
627 auto const acctDelFee{
drops(env.
current()->fees().increment)};
628 BEAST_EXPECT(acctDelFee > env.
balance(alice));
666 env.
fund(
XRP(100000), alice, bob);
690 auto const acctDelFee{
drops(env.
current()->fees().increment)};
691 auto const bobOldBalance{env.
balance(bob)};
709 testcase(
"Destination Constraints");
718 Env env{*
this, features};
719 env.
fund(
XRP(100000), alice, becky, carol);
725 env(
fset(alice, asfDepositAuth));
728 env(
fset(carol, asfRequireDest));
732 Vault const vault{env};
733 auto [tx,
keylet] = vault.create({.owner = alice, .asset =
xrpIssue()});
736 auto const sleVault = env.
le(
keylet);
737 if (!BEAST_EXPECT(sleVault))
739 Account const vaultPseudo{
"vaultPseudo", sleVault->at(sfAccount)};
746 auto const acctDelFee{
drops(env.
current()->fees().increment)};
769 auto const beckyOldBalance{env.
balance(becky)};
779 testcase(
"Destination Constraints with DepositPreauth and Credentials");
788 char const credType[] =
"abcd";
791 env.
fund(
XRP(100000), alice, becky, carol, daria);
800 std::string const credIdx = jv[jss::result][jss::index].asString();
805 auto const acctDelFee{
drops(env.
current()->fees().increment)};
818 env(
fset(alice, asfDepositAuth));
859 credentials::Ids({
"48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6E"
873 jNoCred.isObject() && jNoCred.isMember(jss::result) &&
874 jNoCred[jss::result].isMember(jss::error) &&
875 jNoCred[jss::result][jss::error] ==
"entryNotFound");
878 testcase(
"Credentials that aren't required");
897 jNoCred.isObject() && jNoCred.isMember(jss::result) &&
898 jNoCred[jss::result].isMember(jss::error) &&
899 jNoCred[jss::result][jss::error] ==
"entryNotFound");
906 env.
fund(
XRP(5000), eaton, fred);
918 env(
fset(fred, asfDepositAuth));
925 auto const acctDelFee{
drops(env.
current()->fees().increment)};
936 jNoCred.isObject() && jNoCred.isMember(jss::result) &&
937 jNoCred[jss::result].isMember(jss::error) &&
938 jNoCred[jss::result][jss::error] ==
"entryNotFound");
950 env.
current()->header().parentCloseTime.time_since_epoch().count() + 20;
951 jv[sfExpiration.jsonName] = t;
957 std::string const credIdx = jv[jss::result][jss::index].asString();
973 jv.isObject() && jv.isMember(jss::result) &&
974 jv[jss::result].isMember(jss::error) &&
975 jv[jss::result][jss::error] ==
"entryNotFound");
981 testcase(
"Credentials feature disabled");
989 env.
fund(
XRP(100000), alice, becky, carol);
995 env(
fset(alice, asfDepositAuth));
1001 auto const acctDelFee{
drops(env.
current()->fees().increment)};
1004 "098B7F1B146470A1C5084DC7832C04A72939E3EBC58E68AB8B579BA072B0CE"
1023 testcase(
"Deleting Issuer deletes issued credentials");
1031 char const credType[] =
"abcd";
1034 env.
fund(
XRP(100000), alice, becky, carol);
1045 std::string const credIdx = jv[jss::result][jss::index].asString();
1050 auto const acctDelFee{
drops(env.
current()->fees().increment)};
1055 BEAST_EXPECT(!env.
le(credIdx));
1058 jv.isObject() && jv.isMember(jss::result) &&
1059 jv[jss::result].isMember(jss::error) &&
1060 jv[jss::result][jss::error] ==
"entryNotFound");
1065 testcase(
"Deleting Subject deletes issued credentials");
1073 char const credType[] =
"abcd";
1076 env.
fund(
XRP(100000), alice, becky, carol);
1087 std::string const credIdx = jv[jss::result][jss::index].asString();
1092 auto const acctDelFee{
drops(env.
current()->fees().increment)};
1097 BEAST_EXPECT(!env.
le(credIdx));
1100 jv.isObject() && jv.isMember(jss::result) &&
1101 jv[jss::result].isMember(jss::error) &&
1102 jv[jss::result][jss::error] ==
"entryNotFound");
TestcaseT testcase
Memberspace for declaring test cases.
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.
std::chrono::time_point< NetClock > time_point
std::chrono::duration< rep, period > duration
Slice slice() const noexcept
json::Value getJson(JsonOptions=JsonOptions::Values::None) const override
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
static constexpr SeqProxy rawTicket(std::uint32_t v)
Factory function to return a ticket-based SeqProxy.
void testDest(FeatureBitset features)
void run() override
Runs the suite.
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 testDeleteCredentialsOwner()
void verifyDeliveredAmount(jtx::Env &env, STAmount const &amount)
void testBalanceTooSmallForFee()
void testDestinationDepositAuthCredentials()
void testImplicitlyCreatedTrustline()
Immutable cryptographic account descriptor.
std::string const & human() const
Returns the human readable public key.
PublicKey const & pk() const
Return the public key.
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.
SLE::const_pointer le(Account const &account) const
Return an account root.
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
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.
json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
PrettyAmount balance(Account const &account) const
Returns the XRP balance on an account.
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
std::shared_ptr< STTx const > tx() const
Return the tx data for the last JTx.
void require(Args const &... args)
Check a set of requirements.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
NetClock::time_point now()
Returns the current network time.
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 computation functions.
Keylet payChannel(AccountID const &src, AccountID const &dst, SeqProxy const &seq) noexcept
A PaymentChannel.
Keylet offer(AccountID const &id, SeqProxy const &seq) noexcept
An offer from an account.
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Keylet signerList(AccountID const &account) noexcept
A SignerList.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet check(AccountID const &id, SeqProxy const &seq) noexcept
A Check.
Keylet ticket(AccountID const &id, SeqProxy const &ticketSeq)
A ticket belonging to an account.
Keylet page(uint256 const &root, std::uint64_t const index=0) noexcept
A page in a directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
json::Value cancel(jtx::Account const &dest, uint256 const &checkId)
Cancel a check.
json::Value create(A const &account, A const &dest, STAmount const &sendMax)
Create a check.
json::Value accept(jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
json::Value create(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 authCredentials(jtx::Account const &account, std::vector< AuthorizeCredentials > const &auth)
json::Value auth(Account const &account, Account const &auth)
Preauthorize for deposit.
json::Value setValid(jtx::Account const &account)
json::Value create(AccountID const &account, AccountID const &to, STAmount const &amount)
json::Value cancel(AccountID const &account, Account const &from, std::uint32_t seq)
auto const kCancelTime
Set the "CancelAfter" time tag on a JTx.
auto const kFinishTime
Set the "FinishAfter" time tag on a JTx.
json::Value create(Account const &account, std::uint32_t count)
Create one of more tickets.
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
json::Value regkey(Account const &account, DisabledT)
Disable the regular key.
json::Value offerCancel(Account const &account, std::uint32_t offerSeq)
Cancel an offer.
XrpT const XRP
Converts to XRP Issue or STAmount.
json::Value noop(Account const &account)
The null transaction.
FeatureBitset testableAmendments()
json::Value acctdelete(Account const &account, Account const &dest)
Delete account.
void incLgrSeqForAccDel(jtx::Env &env, jtx::Account const &acc, std::uint32_t margin=0)
std::array< Account, 1+sizeof...(Args)> noripple(Account const &account, Args const &... args)
Designate accounts as no-ripple in Env::fund.
json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
OwnerCount< 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 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.
BEAST_DEFINE_TESTSUITE_PRIO(AccountDelete, app, xrpl, 2)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
std::string strHex(FwdIt begin, FwdIt end)
std::string to_string(BaseUInt< Bits, Tag > const &a)
A pair of SHAMap key and LedgerEntryType.
T time_since_epoch(T... args)