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/STAccount.h>
20 #include <string>
21 #include <test/jtx.h>
22 #include <vector>
23 
24 namespace ripple {
25 namespace test {
26 
27 struct PseudoTx_test : public beast::unit_test::suite
28 {
31  {
33 
34  res.emplace_back(STTx(ttFEE, [&](auto& obj) {
35  obj[sfAccount] = AccountID();
36  obj[sfLedgerSequence] = seq;
37  obj[sfBaseFee] = 0;
38  obj[sfReserveBase] = 0;
39  obj[sfReserveIncrement] = 0;
40  obj[sfReferenceFeeUnits] = 0;
41  }));
42 
43  res.emplace_back(STTx(ttAMENDMENT, [&](auto& obj) {
44  obj.setAccountID(sfAccount, AccountID());
45  obj.setFieldH256(sfAmendment, uint256(2));
46  obj.setFieldU32(sfLedgerSequence, seq);
47  }));
48 
49  return res;
50  }
51 
54  {
56 
57  res.emplace_back(STTx(
58  ttACCOUNT_SET, [&](auto& obj) { obj[sfAccount] = AccountID(1); }));
59 
60  res.emplace_back(STTx(ttPAYMENT, [&](auto& obj) {
61  obj.setAccountID(sfAccount, AccountID(2));
62  obj.setAccountID(sfDestination, AccountID(3));
63  }));
64 
65  return res;
66  }
67 
68  void
70  {
71  using namespace jtx;
72  Env env(*this);
73 
74  for (auto const& stx : getPseudoTxs(env.closed()->seq() + 1))
75  {
76  std::string reason;
77  BEAST_EXPECT(isPseudoTx(stx));
78  BEAST_EXPECT(!passesLocalChecks(stx, reason));
79  BEAST_EXPECT(reason == "Cannot submit pseudo transactions.");
80  env.app().openLedger().modify(
81  [&](OpenView& view, beast::Journal j) {
82  auto const result =
83  ripple::apply(env.app(), view, stx, tapNONE, j);
84  BEAST_EXPECT(!result.second && result.first == temINVALID);
85  return result.second;
86  });
87  }
88  }
89 
90  void
92  {
93  for (auto const& stx : getRealTxs())
94  {
95  std::string reason;
96  BEAST_EXPECT(!isPseudoTx(stx));
97  BEAST_EXPECT(passesLocalChecks(stx, reason));
98  }
99  }
100 
101  void
102  run() override
103  {
104  testPrevented();
105  testAllowed();
106  }
107 };
108 
109 BEAST_DEFINE_TESTSUITE(PseudoTx, app, ripple);
110 
111 } // namespace test
112 } // namespace ripple
ripple::sfReserveBase
const SF_UINT32 sfReserveBase
std::string
STL class.
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::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:102
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:549
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:91
ripple::sfReserveIncrement
const SF_UINT32 sfReserveIncrement
ripple::STTx
Definition: STTx.h:45
ripple::test::PseudoTx_test::testPrevented
void testPrevented()
Definition: PseudoTx_test.cpp:69
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
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::getRealTxs
std::vector< STTx > getRealTxs()
Definition: PseudoTx_test.cpp:53
ripple::test::PseudoTx_test
Definition: PseudoTx_test.cpp:27
ripple::sfReferenceFeeUnits
const SF_UINT32 sfReferenceFeeUnits
ripple::sfAccount
const SF_ACCOUNT sfAccount
ripple::test::PseudoTx_test::getPseudoTxs
std::vector< STTx > getPseudoTxs(std::uint32_t seq)
Definition: PseudoTx_test.cpp:30
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:105
ripple::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple)
string