rippled
Loading...
Searching...
No Matches
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 <test/jtx.h>
19#include <xrpld/app/tx/apply.h>
20#include <xrpl/protocol/Feature.h>
21
22#include <string>
23#include <vector>
24
25namespace ripple {
26namespace test {
27
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};
42 obj[sfReserveIncrementDrops] = 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
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.applied && result.ter == temINVALID);
96 return result.applied;
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
119 testPrevented(all - featureXRPFees);
121 testAllowed();
122 }
123};
124
125BEAST_DEFINE_TESTSUITE(PseudoTx, app, ripple);
126
127} // namespace test
128} // namespace ripple
A generic endpoint for log messages.
Definition: Journal.h:60
A testsuite class.
Definition: suite.h:55
virtual OpenLedger & openLedger()=0
bool modify(modify_type const &f)
Modify the open ledger.
Definition: OpenLedger.cpp:56
Writable ledger view that accumulates state and tx changes.
Definition: OpenView.h:56
Rules controlling protocol behavior.
Definition: Rules.h:35
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition: Rules.cpp:130
A transaction testing environment.
Definition: Env.h:118
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
Definition: Env.cpp:109
Application & app()
Definition: Env.h:256
T emplace_back(T... args)
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
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition: AccountID.h:49
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition: STTx.cpp:640
base_uint< 256 > uint256
Definition: base_uint.h:558
ApplyResult apply(Application &app, OpenView &view, STTx const &tx, ApplyFlags flags, beast::Journal journal)
Apply a transaction to an OpenView.
Definition: apply.cpp:109
bool passesLocalChecks(STObject const &st, std::string &)
Definition: STTx.cpp:604
@ tapNONE
Definition: ApplyView.h:31
@ temINVALID
Definition: TER.h:110
void testPrevented(FeatureBitset features)
void run() override
Runs the suite.
std::vector< STTx > getPseudoTxs(Rules const &rules, std::uint32_t seq)
std::vector< STTx > getRealTxs()
Set the sequence number on a JTx.
Definition: seq.h:34