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>
27#include <xrpl/basics/base_uint.h>
28#include <xrpl/basics/chrono.h>
29#include <xrpl/basics/strHex.h>
30#include <xrpl/beast/unit_test/suite.h>
31#include <xrpl/ledger/ReadView.h>
32#include <xrpl/protocol/Feature.h>
33#include <xrpl/protocol/Indexes.h>
34#include <xrpl/protocol/Keylet.h>
35#include <xrpl/protocol/PublicKey.h>
36#include <xrpl/protocol/SField.h>
37#include <xrpl/protocol/STAmount.h>
38#include <xrpl/protocol/TER.h>
39#include <xrpl/protocol/TxFlags.h>
40#include <xrpl/protocol/jss.h>
67 json::Value const meta = env.
rpc(
"tx", txHash)[jss::result][jss::meta];
70 if (!BEAST_EXPECT(meta.
isMember(sfDeliveredAmount.jsonName)))
76 BEAST_EXPECT(meta[sfDeliveredAmount.jsonName] == jsonExpect);
77 BEAST_EXPECT(meta[jss::delivered_amount] == jsonExpect);
91 jv[jss::TransactionType] = jss::PaymentChannelCreate;
92 jv[jss::Account] = account.human();
93 jv[jss::Destination] = to.
human();
95 jv[sfSettleDelay.jsonName] = settleDelay.
count();
115 env.
fund(
XRP(10000), alice, becky, carol, gw);
129 auto const acctDelFee{
drops(env.
current()->fees().increment)};
139 env(
trust(becky, gw[
"USD"](1000)));
146 env(
offer(carol, gw[
"USD"](51),
XRP(51)));
149 env(
signers(carol, 1, {{alice, 1}, {becky, 1}}));
168 auto const aliceOldBalance{env.
balance(alice)};
169 auto const beckyOldBalance{env.
balance(becky)};
184 BEAST_EXPECT(env.
balance(becky) == aliceOldBalance + beckyOldBalance - acctDelFee);
205 for (
int i = 0; i < 8; ++i)
209 auto const beckyOldBalance{env.
balance(becky)};
210 auto const carolOldBalance{env.
balance(carol)};
236 BEAST_EXPECT(env.
balance(becky) == carolOldBalance + beckyOldBalance - acctDelFee);
258 env.
fund(
XRP(10000), alice, gw);
262 for (
int i{0}; i < 45; ++i)
264 env(
offer(alice, gw[
"USD"](1),
XRP(1)));
275 BEAST_EXPECT(env.
closed()->exists(aliceRootKey));
276 BEAST_EXPECT(env.
closed()->exists(alicePageKey));
279 auto const acctDelFee{
drops(env.
current()->fees().increment)};
280 auto const aliceBalance{env.
balance(alice)};
286 BEAST_EXPECT(!env.
closed()->exists(aliceRootKey));
287 BEAST_EXPECT(!env.
closed()->exists(alicePageKey));
303 env.
fund(
XRP(100000), alice, becky, gw);
309 for (
int i{0}; i < 200; ++i)
311 env(
offer(alice, gw[
"USD"](1),
XRP(1)));
312 env(
offer(becky, gw[
"USD"](1),
XRP(1)));
330 auto const acctDelFee{
drops(env.
current()->fees().increment)};
341 using namespace std::chrono_literals;
357 bool const withTokenEscrow = env.
current()->rules().enabled(featureTokenEscrow);
362 auto const usd = gw1[
"USD"];
363 env.
fund(
XRP(100000), carol, gw1);
364 env(
fset(gw1, asfAllowTrustLineLocking));
366 env.
trust(usd(10000), carol);
368 env(
pay(gw1, carol, usd(100)));
396 auto const beckyBalance{env.
balance(becky)};
408 jv[jss::TransactionType] = jss::PaymentChannelClaim;
409 jv[jss::Flags] = tfClose;
410 jv[jss::Account] = account.human();
411 jv[sfChannel.jsonName] =
to_string(payChanKeylet.key);
412 jv[sfPublicKey.jsonName] =
strHex(pk.slice());
415 env(payChanClose(alice, alicePayChanKey, alice.
pk()));
431 env(payChanClose(alice, gwPayChanKey, alice.
pk()));
435 auto const aliceBalance{env.
balance(alice)};
454 env.
fund(
XRP(10000000), alice, gw);
464 static constexpr int kOfferCount{1001};
465 for (
int i{0}; i < kOfferCount; ++i)
467 env(
offer(alice, gw[currency](1),
XRP(1)));
472 if (currency[0] >
'Z')
477 if (currency[1] >
'Z')
482 if (currency[2] >
'Z')
498 BEAST_EXPECT(closed->exists(aliceOwnerDirKey));
502 BEAST_EXPECT(closed->exists(
keylet::page(aliceOwnerDirKey, i)));
506 BEAST_EXPECT(closed->exists(
keylet::offer(alice.
id(), offerSeq0 + i)));
511 auto const acctDelFee{
drops(env.
current()->fees().increment)};
522 auto const alicePreDelBal{env.
balance(alice)};
532 BEAST_EXPECT(!closed->exists(aliceOwnerDirKey));
536 BEAST_EXPECT(!closed->exists(
keylet::page(aliceOwnerDirKey, i)));
540 BEAST_EXPECT(!closed->exists(
keylet::offer(alice.
id(), offerSeq0 + i)));
551 testcase(
"Implicitly created trust line");
556 auto const bux{gw[
"BUX"]};
558 env.
fund(
XRP(10000), alice, gw);
563 env(
offer(alice, bux(30),
XRP(30)));
576 auto const acctDelFee{
drops(env.
current()->fees().increment)};
596 testcase(
"Balance too small for fee");
612 auto const acctDelFee{
drops(env.
current()->fees().increment)};
613 BEAST_EXPECT(acctDelFee > env.
balance(alice));
651 env.
fund(
XRP(100000), alice, bob);
674 auto const acctDelFee{
drops(env.
current()->fees().increment)};
675 auto const bobOldBalance{env.
balance(bob)};
692 testcase(
"Destination Constraints");
702 env.
fund(
XRP(100000), alice, becky, carol);
708 env(
fset(alice, asfDepositAuth));
711 env(
fset(carol, asfRequireDest));
719 auto const acctDelFee{
drops(env.
current()->fees().increment)};
738 auto const beckyOldBalance{env.
balance(becky)};
748 testcase(
"Destination Constraints with DepositPreauth and Credentials");
757 char const credType[] =
"abcd";
760 env.
fund(
XRP(100000), alice, becky, carol, daria);
769 std::string const credIdx = jv[jss::result][jss::index].asString();
774 auto const acctDelFee{
drops(env.
current()->fees().increment)};
787 env(
fset(alice, asfDepositAuth));
828 credentials::Ids({
"48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6E"
842 jNoCred.isObject() && jNoCred.isMember(jss::result) &&
843 jNoCred[jss::result].isMember(jss::error) &&
844 jNoCred[jss::result][jss::error] ==
"entryNotFound");
847 testcase(
"Credentials that aren't required");
866 jNoCred.isObject() && jNoCred.isMember(jss::result) &&
867 jNoCred[jss::result].isMember(jss::error) &&
868 jNoCred[jss::result][jss::error] ==
"entryNotFound");
875 env.
fund(
XRP(5000), eaton, fred);
887 env(
fset(fred, asfDepositAuth));
894 auto const acctDelFee{
drops(env.
current()->fees().increment)};
905 jNoCred.isObject() && jNoCred.isMember(jss::result) &&
906 jNoCred[jss::result].isMember(jss::error) &&
907 jNoCred[jss::result][jss::error] ==
"entryNotFound");
919 env.
current()->header().parentCloseTime.time_since_epoch().count() + 20;
920 jv[sfExpiration.jsonName] = t;
926 std::string const credIdx = jv[jss::result][jss::index].asString();
942 jv.isObject() && jv.isMember(jss::result) &&
943 jv[jss::result].isMember(jss::error) &&
944 jv[jss::result][jss::error] ==
"entryNotFound");
950 testcase(
"Credentials feature disabled");
958 env.
fund(
XRP(100000), alice, becky, carol);
964 env(
fset(alice, asfDepositAuth));
970 auto const acctDelFee{
drops(env.
current()->fees().increment)};
973 "098B7F1B146470A1C5084DC7832C04A72939E3EBC58E68AB8B579BA072B0CE"
992 testcase(
"Deleting Issuer deletes issued credentials");
1000 char const credType[] =
"abcd";
1003 env.
fund(
XRP(100000), alice, becky, carol);
1014 std::string const credIdx = jv[jss::result][jss::index].asString();
1019 auto const acctDelFee{
drops(env.
current()->fees().increment)};
1024 BEAST_EXPECT(!env.
le(credIdx));
1027 jv.isObject() && jv.isMember(jss::result) &&
1028 jv[jss::result].isMember(jss::error) &&
1029 jv[jss::result][jss::error] ==
"entryNotFound");
1034 testcase(
"Deleting Subject deletes issued credentials");
1042 char const credType[] =
"abcd";
1045 env.
fund(
XRP(100000), alice, becky, carol);
1056 std::string const credIdx = jv[jss::result][jss::index].asString();
1061 auto const acctDelFee{
drops(env.
current()->fees().increment)};
1066 BEAST_EXPECT(!env.
le(credIdx));
1069 jv.isObject() && jv.isMember(jss::result) &&
1070 jv[jss::result].isMember(jss::error) &&
1071 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
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 ticket(AccountID const &id, std::uint32_t ticketSeq)
A ticket belonging to an account.
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Keylet payChannel(AccountID const &src, AccountID const &dst, std::uint32_t seq) noexcept
A PaymentChannel.
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, std::uint32_t seq) noexcept
A Check.
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
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.
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)