rippled
PseudoTx_test.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2017 Ripple Labs Inc.
5  Permission to use, copy, modify, and/or distribute this software for any
6  purpose with or without fee is hereby granted, provided that the above
7  copyright notice and this permission notice appear in all copies.
8  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16 //==============================================================================
17 
18 #include <ripple/app/tx/apply.h>
19 #include <ripple/protocol/Feature.h>
20 #include <ripple/protocol/STAccount.h>
21 #include <string>
22 #include <test/jtx.h>
23 #include <vector>
24 
25 namespace ripple {
26 namespace test {
27 
28 struct PseudoTx_test : public beast::unit_test::suite
29 {
32  {
34 
35  res.emplace_back(STTx(ttFEE, [&](auto& obj) {
36  obj[sfAccount] = AccountID();
37  obj[sfLedgerSequence] = seq;
38  if (rules.enabled(featureXRPFees))
39  {
40  obj[sfBaseFeeDrops] = XRPAmount{0};
41  obj[sfReserveBaseDrops] = XRPAmount{0};
43  }
44  else
45  {
46  obj[sfBaseFee] = 0;
47  obj[sfReserveBase] = 0;
48  obj[sfReserveIncrement] = 0;
49  obj[sfReferenceFeeUnits] = 0;
50  }
51  }));
52 
53  res.emplace_back(STTx(ttAMENDMENT, [&](auto& obj) {
54  obj.setAccountID(sfAccount, AccountID());
55  obj.setFieldH256(sfAmendment, uint256(2));
56  obj.setFieldU32(sfLedgerSequence, seq);
57  }));
58 
59  return res;
60  }
61 
64  {
66 
67  res.emplace_back(STTx(
68  ttACCOUNT_SET, [&](auto& obj) { obj[sfAccount] = AccountID(1); }));
69 
70  res.emplace_back(STTx(ttPAYMENT, [&](auto& obj) {
71  obj.setAccountID(sfAccount, AccountID(2));
72  obj.setAccountID(sfDestination, AccountID(3));
73  }));
74 
75  return res;
76  }
77 
78  void
80  {
81  using namespace jtx;
82  Env env(*this, features);
83 
84  for (auto const& stx :
85  getPseudoTxs(env.closed()->rules(), env.closed()->seq() + 1))
86  {
87  std::string reason;
88  BEAST_EXPECT(isPseudoTx(stx));
89  BEAST_EXPECT(!passesLocalChecks(stx, reason));
90  BEAST_EXPECT(reason == "Cannot submit pseudo transactions.");
91  env.app().openLedger().modify(
92  [&](OpenView& view, beast::Journal j) {
93  auto const result =
94  ripple::apply(env.app(), view, stx, tapNONE, j);
95  BEAST_EXPECT(!result.second && result.first == temINVALID);
96  return result.second;
97  });
98  }
99  }
100 
101  void
103  {
104  for (auto const& stx : getRealTxs())
105  {
106  std::string reason;
107  BEAST_EXPECT(!isPseudoTx(stx));
108  BEAST_EXPECT(passesLocalChecks(stx, reason));
109  }
110  }
111 
112  void
113  run() override
114  {
115  using namespace test::jtx;
117  FeatureBitset const xrpFees{featureXRPFees};
118 
121  testAllowed();
122  }
123 };
124 
125 BEAST_DEFINE_TESTSUITE(PseudoTx, app, ripple);
126 
127 } // namespace test
128 } // namespace ripple
ripple::sfBaseFeeDrops
const SF_AMOUNT sfBaseFeeDrops
ripple::sfReserveBase
const SF_UINT32 sfReserveBase
ripple::featureXRPFees
const uint256 featureXRPFees
std::string
STL class.
ripple::Rules::enabled
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition: Rules.cpp:94
ripple::sfLedgerSequence
const SF_UINT32 sfLedgerSequence
ripple::apply
std::pair< TER, bool > apply(Application &app, OpenView &view, STTx const &tx, ApplyFlags flags, beast::Journal journal)
Apply a transaction to an OpenView.
Definition: apply.cpp:109
ripple::sfDestination
const SF_ACCOUNT sfDestination
ripple::test::jtx::Env::closed
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
Definition: Env.cpp:115
ripple::TxSearched::all
@ all
ripple::OpenView
Writable ledger view that accumulates state and tx changes.
Definition: OpenView.h:55
vector
ripple::test::PseudoTx_test::run
void run() override
Definition: PseudoTx_test.cpp:113
ripple::ttFEE
@ ttFEE
This system-generated transaction type is used to update the network's fee settings.
Definition: TxFormats.h:152
ripple::test::jtx::Env::app
Application & app()
Definition: Env.h:241
ripple::Application::openLedger
virtual OpenLedger & openLedger()=0
ripple::ttAMENDMENT
@ ttAMENDMENT
This system-generated transaction type is used to update the status of the various amendments.
Definition: TxFormats.h:146
ripple::tapNONE
@ tapNONE
Definition: ApplyView.h:30
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:550
ripple::ttPAYMENT
@ ttPAYMENT
This transaction type executes a payment.
Definition: TxFormats.h:59
ripple::base_uint< 160, detail::AccountIDTag >
ripple::isPseudoTx
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition: STTx.cpp:559
ripple::passesLocalChecks
bool passesLocalChecks(STObject const &st, std::string &reason)
Definition: STTx.cpp:530
ripple::test::PseudoTx_test::testAllowed
void testAllowed()
Definition: PseudoTx_test.cpp:102
ripple::sfReserveIncrement
const SF_UINT32 sfReserveIncrement
ripple::STTx
Definition: STTx.h:45
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::test::jtx::supported_amendments
FeatureBitset supported_amendments()
Definition: Env.h:70
std::uint32_t
ripple::sfReserveIncrementDrops
const SF_AMOUNT sfReserveIncrementDrops
ripple::sfReserveBaseDrops
const SF_AMOUNT sfReserveBaseDrops
ripple::test::PseudoTx_test::getPseudoTxs
std::vector< STTx > getPseudoTxs(Rules const &rules, std::uint32_t seq)
Definition: PseudoTx_test.cpp:31
ripple::ttACCOUNT_SET
@ ttACCOUNT_SET
This transaction type adjusts various account settings.
Definition: TxFormats.h:68
ripple::sfBaseFee
const SF_UINT64 sfBaseFee
ripple::test::jtx::seq
Set the sequence number on a JTx.
Definition: seq.h:33
std::vector::emplace_back
T emplace_back(T... args)
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::PseudoTx_test::testPrevented
void testPrevented(FeatureBitset features)
Definition: PseudoTx_test.cpp:79
ripple::test::PseudoTx_test::getRealTxs
std::vector< STTx > getRealTxs()
Definition: PseudoTx_test.cpp:63
ripple::test::PseudoTx_test
Definition: PseudoTx_test.cpp:28
ripple::FeatureBitset
Definition: Feature.h:113
ripple::sfReferenceFeeUnits
const SF_UINT32 sfReferenceFeeUnits
ripple::Rules
Rules controlling protocol behavior.
Definition: Rules.h:33
ripple::sfAccount
const SF_ACCOUNT sfAccount
ripple::sfAmendment
const SF_UINT256 sfAmendment
ripple::OpenLedger::modify
bool modify(modify_type const &f)
Modify the open ledger.
Definition: OpenLedger.cpp:57
ripple::test::jtx::Env
A transaction testing environment.
Definition: Env.h:116
ripple::temINVALID
@ temINVALID
Definition: TER.h:108
ripple::XRPAmount
Definition: XRPAmount.h:46
ripple::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple)
string