xrpld
Loading...
Searching...
No Matches
SetAuth_test.cpp
1
2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/amount.h>
5#include <test/jtx/flags.h>
6#include <test/jtx/pay.h>
7#include <test/jtx/ter.h>
8#include <test/jtx/trust.h>
9
10#include <xrpl/beast/unit_test/suite.h>
11#include <xrpl/json/json_value.h>
12#include <xrpl/protocol/Feature.h>
13#include <xrpl/protocol/Indexes.h>
14#include <xrpl/protocol/TER.h>
15#include <xrpl/protocol/TxFlags.h>
16#include <xrpl/protocol/UintTypes.h>
17#include <xrpl/protocol/jss.h>
18
19#include <string>
20
21namespace xrpl::test {
22
24{
25 // Set just the tfSetfAuth flag on a trust line
26 // If the trust line does not exist, then it should
27 // be created under the new rules.
28 static json::Value
29 auth(jtx::Account const& account, jtx::Account const& dest, std::string const& currency)
30 {
31 using namespace jtx;
32 json::Value jv;
33 jv[jss::Account] = account.human();
34 jv[jss::LimitAmount] =
36 jv[jss::TransactionType] = jss::TrustSet;
37 jv[jss::Flags] = tfSetfAuth;
38 return jv;
39 }
40
41 void
43 {
44 using namespace jtx;
45 auto const gw = Account("gw");
46 auto const usd = gw["USD"];
47
48 Env env(*this);
49
50 env.fund(XRP(100000), "alice", "bob", gw);
51 env(fset(gw, asfRequireAuth));
52 env.close();
53 env(auth(gw, "alice", "USD"));
54 BEAST_EXPECT(env.le(keylet::trustLine(Account("alice").id(), gw.id(), usd.currency)));
55 env(trust("alice", usd(1000)));
56 env(trust("bob", usd(1000)));
57 env(pay(gw, "alice", usd(100)));
58 env(pay(gw, "bob", usd(100)),
59 Ter(tecPATH_DRY)); // Should be terNO_AUTH
60 env(pay("alice", "bob", usd(50)),
61 Ter(tecPATH_DRY)); // Should be terNO_AUTH
62 }
63
64 void
65 run() override
66 {
67 using namespace jtx;
68 auto const sa = testableAmendments();
69 testAuth(sa - featurePermissionedDEX);
70 testAuth(sa);
71 }
72};
73
75
76} // namespace xrpl::test
A testsuite class.
Definition suite.h:50
Represents a JSON value.
Definition json_value.h:130
A currency issued by an account.
Definition Issue.h:13
Immutable cryptographic account descriptor.
Definition jtx/Account.h:17
AccountID id() const
Returns the Account ID.
Definition jtx/Account.h:85
A transaction testing environment.
Definition Env.h:143
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:133
SLE::const_pointer le(Account const &account) const
Return an account root.
Definition Env.cpp:284
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:296
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:13
Keylet trustLine(AccountID const &id0, AccountID const &id1, Currency const &currency) noexcept
The index of a trust line for a given currency.
Definition Indexes.cpp:241
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:14
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
FeatureBitset testableAmendments()
Definition Env.h:76
json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition trust.cpp:18
json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Definition flags.cpp:15
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
bool toCurrency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.
Definition UintTypes.cpp:65
json::Value getJson(LedgerFill const &fill)
Return a new json::Value representing the ledger with given options.
@ tecPATH_DRY
Definition TER.h:292
static json::Value auth(jtx::Account const &account, jtx::Account const &dest, std::string const &currency)
void run() override
Runs the suite.
void testAuth(FeatureBitset features)