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#include <xrpl/protocol/Feature.h>
22#include <xrpl/protocol/jss.h>
23
24namespace ripple {
25namespace test {
26
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] = STAmount(Issue{to_currency(currency), dest})
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();
76 testAuth(sa - featureFlowCross);
77 testAuth(sa);
78 }
79};
80
81BEAST_DEFINE_TESTSUITE(SetAuth, test, ripple);
82
83} // namespace test
84} // 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:118
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition: Env.cpp:231
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Definition: Env.cpp:219
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:235
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition: trust.cpp:31
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Definition: flags.cpp:28
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition: pay.cpp:29
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition: amount.cpp:104
FeatureBitset supported_amendments()
Definition: Env.h:71
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)