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 ripple {
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
16 jtx::Account const& account,
17 jtx::Account const& dest,
18 std::string const& currency)
19 {
20 using namespace jtx;
21 Json::Value jv;
22 jv[jss::Account] = account.human();
23 jv[jss::LimitAmount] = STAmount(Issue{to_currency(currency), dest})
25 jv[jss::TransactionType] = jss::TrustSet;
26 jv[jss::Flags] = tfSetfAuth;
27 return jv;
28 }
29
30 void
32 {
33 using namespace jtx;
34 auto const gw = Account("gw");
35 auto const USD = gw["USD"];
36
37 Env env(*this);
38
39 env.fund(XRP(100000), "alice", "bob", gw);
40 env(fset(gw, asfRequireAuth));
41 env.close();
42 env(auth(gw, "alice", "USD"));
43 BEAST_EXPECT(
44 env.le(keylet::line(Account("alice").id(), gw.id(), USD.currency)));
45 env(trust("alice", USD(1000)));
46 env(trust("bob", USD(1000)));
47 env(pay(gw, "alice", USD(100)));
48 env(pay(gw, "bob", USD(100)),
49 ter(tecPATH_DRY)); // Should be terNO_AUTH
50 env(pay("alice", "bob", USD(50)),
51 ter(tecPATH_DRY)); // Should be terNO_AUTH
52 }
53
54 void
55 run() override
56 {
57 using namespace jtx;
58 auto const sa = testable_amendments();
59 testAuth(sa - featurePermissionedDEX);
60 testAuth(sa);
61 }
62};
63
64BEAST_DEFINE_TESTSUITE(SetAuth, app, ripple);
65
66} // namespace test
67} // namespace ripple
Represents a JSON value.
Definition json_value.h:130
A testsuite class.
Definition suite.h:52
A currency issued by an account.
Definition Issue.h:14
Immutable cryptographic account descriptor.
Definition Account.h:20
AccountID id() const
Returns the Account ID.
Definition Account.h:92
A transaction testing environment.
Definition Env.h:102
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:103
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:271
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Definition Env.cpp:259
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:16
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:225
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition trust.cpp:13
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Definition flags.cpp:10
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:11
FeatureBitset testable_amendments()
Definition Env.h:55
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
constexpr std::uint32_t tfSetfAuth
Definition TxFlags.h:96
@ tecPATH_DRY
Definition TER.h:276
Json::Value getJson(LedgerFill const &fill)
Return a new Json::Value representing the ledger with given options.
constexpr std::uint32_t asfRequireAuth
Definition TxFlags.h:59
bool to_currency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.
Definition UintTypes.cpp:65
void run() override
Runs the suite.
void testAuth(FeatureBitset features)
static Json::Value auth(jtx::Account const &account, jtx::Account const &dest, std::string const &currency)