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::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AccountDelete, app, ripple)
std::string
STL class.
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::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::sfAccount
const SF_Account sfAccount(access, STI_ACCOUNT, 1, "Account")
Definition: SField.h:481
ripple::test::jtx::Env::app
Application & app()
Definition: Env.h:240
ripple::Application::openLedger
virtual OpenLedger & openLedger()=0
ripple::tapNONE
@ tapNONE
Definition: ApplyView.h:31
ripple::sfReserveBase
const SF_U32 sfReserveBase(access, STI_UINT32, 31, "ReserveBase")
Definition: SField.h:384
ripple::ttPAYMENT
@ ttPAYMENT
Definition: TxFormats.h:36
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:493
ripple::ttFEE
@ ttFEE
Definition: TxFormats.h:62
ripple::base_uint< 160, detail::AccountIDTag >
ripple::isPseudoTx
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition: STTx.cpp:540
ripple::passesLocalChecks
bool passesLocalChecks(STObject const &st, std::string &reason)
Definition: STTx.cpp:511
ripple::test::PseudoTx_test::testAllowed
void testAllowed()
Definition: PseudoTx_test.cpp:91
ripple::sfAmendment
const SF_U256 sfAmendment(access, STI_HASH256, 19, "Amendment")
Definition: SField.h:433
ripple::sfLedgerSequence
const SF_U32 sfLedgerSequence(access, STI_UINT32, 6, "LedgerSequence")
Definition: SField.h:358
ripple::sfReferenceFeeUnits
const SF_U32 sfReferenceFeeUnits(access, STI_UINT32, 30, "ReferenceFeeUnits")
Definition: SField.h:383
ripple::STTx
Definition: STTx.h:42
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::ttAMENDMENT
@ ttAMENDMENT
Definition: TxFormats.h:61
ripple::test::jtx::seq
Set the sequence number on a JTx.
Definition: seq.h:32
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::ttACCOUNT_SET
@ ttACCOUNT_SET
Definition: TxFormats.h:39
ripple::sfReserveIncrement
const SF_U32 sfReserveIncrement(access, STI_UINT32, 32, "ReserveIncrement")
Definition: SField.h:385
ripple::test::PseudoTx_test
Definition: PseudoTx_test.cpp:27
ripple::sfDestination
const SF_Account sfDestination(access, STI_ACCOUNT, 3, "Destination")
Definition: SField.h:483
ripple::test::PseudoTx_test::getPseudoTxs
std::vector< STTx > getPseudoTxs(std::uint32_t seq)
Definition: PseudoTx_test.cpp:30
ripple::sfBaseFee
const SF_U64 sfBaseFee(access, STI_UINT64, 5, "BaseFee")
Definition: SField.h:401
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:115
ripple::temINVALID
@ temINVALID
Definition: TER.h:105
string