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