rippled
Loading...
Searching...
No Matches
SetAuth_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <test/jtx.h>
21
22#include <xrpl/protocol/Feature.h>
23#include <xrpl/protocol/jss.h>
24
25namespace ripple {
26namespace test {
27
29{
30 // Set just the tfSetfAuth flag on a trust line
31 // If the trust line does not exist, then it should
32 // be created under the new rules.
33 static Json::Value
35 jtx::Account const& account,
36 jtx::Account const& dest,
37 std::string const& currency)
38 {
39 using namespace jtx;
40 Json::Value jv;
41 jv[jss::Account] = account.human();
42 jv[jss::LimitAmount] = STAmount(Issue{to_currency(currency), dest})
44 jv[jss::TransactionType] = jss::TrustSet;
45 jv[jss::Flags] = tfSetfAuth;
46 return jv;
47 }
48
49 void
51 {
52 using namespace jtx;
53 auto const gw = Account("gw");
54 auto const USD = gw["USD"];
55
56 Env env(*this);
57
58 env.fund(XRP(100000), "alice", "bob", gw);
59 env(fset(gw, asfRequireAuth));
60 env.close();
61 env(auth(gw, "alice", "USD"));
62 BEAST_EXPECT(
63 env.le(keylet::line(Account("alice").id(), gw.id(), USD.currency)));
64 env(trust("alice", USD(1000)));
65 env(trust("bob", USD(1000)));
66 env(pay(gw, "alice", USD(100)));
67 env(pay(gw, "bob", USD(100)),
68 ter(tecPATH_DRY)); // Should be terNO_AUTH
69 env(pay("alice", "bob", USD(50)),
70 ter(tecPATH_DRY)); // Should be terNO_AUTH
71 }
72
73 void
74 run() override
75 {
76 using namespace jtx;
77 auto const sa = supported_amendments();
78 testAuth(sa - featureFlowCross);
79 testAuth(sa);
80 }
81};
82
83BEAST_DEFINE_TESTSUITE(SetAuth, test, ripple);
84
85} // namespace test
86} // namespace ripple
Represents a JSON value.
Definition: json_value.h:148
A testsuite class.
Definition: suite.h:55
A currency issued by an account.
Definition: Issue.h:36
Immutable cryptographic account descriptor.
Definition: Account.h:39
AccountID id() const
Returns the Account ID.
Definition: Account.h:107
A transaction testing environment.
Definition: Env.h:120
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition: Env.cpp:117
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition: Env.cpp:233
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Definition: Env.cpp:221
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition: ter.h:35
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:236
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition: trust.cpp:32
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Definition: flags.cpp:29
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition: pay.cpp:30
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition: amount.cpp:105
FeatureBitset supported_amendments()
Definition: Env.h:73
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
constexpr std::uint32_t tfSetfAuth
Definition: TxFlags.h:112
@ tecPATH_DRY
Definition: TER.h:281
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:77
bool to_currency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.
Definition: UintTypes.cpp:84
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)