rippled
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 <ripple/protocol/Feature.h>
21 #include <ripple/protocol/jss.h>
22 #include <test/jtx.h>
23 
24 namespace ripple {
25 namespace test {
26 
27 struct SetAuth_test : public beast::unit_test::suite
28 {
29  // Set just the tfSetfAuth flag on a trust line
30  // If the trust line does not exist, then it should
31  // be created under the new rules.
32  static Json::Value
34  jtx::Account const& account,
35  jtx::Account const& dest,
36  std::string const& currency)
37  {
38  using namespace jtx;
39  Json::Value jv;
40  jv[jss::Account] = account.human();
41  jv[jss::LimitAmount] =
42  STAmount({to_currency(currency), dest}).getJson(JsonOptions::none);
43  jv[jss::TransactionType] = jss::TrustSet;
44  jv[jss::Flags] = tfSetfAuth;
45  return jv;
46  }
47 
48  void
50  {
51  using namespace jtx;
52  auto const gw = Account("gw");
53  auto const USD = gw["USD"];
54 
55  Env env(*this);
56 
57  env.fund(XRP(100000), "alice", "bob", gw);
58  env(fset(gw, asfRequireAuth));
59  env(auth(gw, "alice", "USD"));
60  BEAST_EXPECT(
61  env.le(keylet::line(Account("alice").id(), gw.id(), USD.currency)));
62  env(trust("alice", USD(1000)));
63  env(trust("bob", USD(1000)));
64  env(pay(gw, "alice", USD(100)));
65  env(pay(gw, "bob", USD(100)),
66  ter(tecPATH_DRY)); // Should be terNO_AUTH
67  env(pay("alice", "bob", USD(50)),
68  ter(tecPATH_DRY)); // Should be terNO_AUTH
69  }
70 
71  void
72  run() override
73  {
74  using namespace jtx;
75  auto const sa = supported_amendments();
77  testAuth(sa);
78  }
79 };
80 
81 BEAST_DEFINE_TESTSUITE(SetAuth, test, ripple);
82 
83 } // namespace test
84 } // namespace ripple
ripple::to_currency
bool to_currency(Currency &currency, std::string const &code)
Tries to convert a string to a Currency, returns true on success.
Definition: UintTypes.cpp:80
ripple::test::jtx::XRP
const XRP_t XRP
Converts to XRP Issue or STAmount.
Definition: amount.cpp:105
std::string
STL class.
ripple::test::jtx::ter
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition: ter.h:33
ripple::test::SetAuth_test::run
void run() override
Definition: SetAuth_test.cpp:72
ripple::test::jtx::trust
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition: trust.cpp:30
ripple::test::jtx::Account::id
AccountID id() const
Returns the Account ID.
Definition: Account.h:106
ripple::JsonOptions::none
@ none
ripple::test::jtx::fset
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Definition: flags.cpp:28
ripple::STAmount
Definition: STAmount.h:45
ripple::test::jtx::supported_amendments
FeatureBitset supported_amendments()
Definition: Env.h:70
ripple::keylet::line
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:193
ripple::test::SetAuth_test::testAuth
void testAuth(FeatureBitset features)
Definition: SetAuth_test.cpp:49
ripple::getJson
Json::Value getJson(LedgerFill const &fill)
Return a new Json::Value representing the ledger with given options.
Definition: LedgerToJson.cpp:296
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::jtx::pay
Json::Value pay(Account const &account, Account const &to, AnyAmount amount)
Create a payment.
Definition: pay.cpp:29
ripple::tfSetfAuth
constexpr std::uint32_t tfSetfAuth
Definition: TxFlags.h:108
ripple::asfRequireAuth
constexpr std::uint32_t asfRequireAuth
Definition: TxFlags.h:75
ripple::test::jtx::Env::fund
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition: Env.cpp:228
ripple::test::jtx::Env::le
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Definition: Env.cpp:216
ripple::FeatureBitset
Definition: Feature.h:113
ripple::tecPATH_DRY
@ tecPATH_DRY
Definition: TER.h:261
ripple::test::jtx::Account
Immutable cryptographic account descriptor.
Definition: Account.h:37
ripple::featureFlowCross
const uint256 featureFlowCross
ripple::test::jtx::Env
A transaction testing environment.
Definition: Env.h:116
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::test::SetAuth_test::auth
static Json::Value auth(jtx::Account const &account, jtx::Account const &dest, std::string const &currency)
Definition: SetAuth_test.cpp:33
ripple::test::SetAuth_test
Definition: SetAuth_test.cpp:27
ripple::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple)