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
20#include <xrpld/app/tx/apply.h>
21
22#include <xrpl/protocol/Feature.h>
23
24#include <string>
25#include <vector>
26
27namespace ripple {
28namespace test {
29
31{
34 {
36
37 res.emplace_back(STTx(ttFEE, [&](auto& obj) {
38 obj[sfAccount] = AccountID();
39 obj[sfLedgerSequence] = seq;
40 if (rules.enabled(featureXRPFees))
41 {
42 obj[sfBaseFeeDrops] = XRPAmount{0};
43 obj[sfReserveBaseDrops] = XRPAmount{0};
44 obj[sfReserveIncrementDrops] = XRPAmount{0};
45 }
46 else
47 {
48 obj[sfBaseFee] = 0;
49 obj[sfReserveBase] = 0;
50 obj[sfReserveIncrement] = 0;
51 obj[sfReferenceFeeUnits] = 0;
52 }
53 }));
54
55 res.emplace_back(STTx(ttAMENDMENT, [&](auto& obj) {
56 obj.setAccountID(sfAccount, AccountID());
57 obj.setFieldH256(sfAmendment, uint256(2));
58 obj.setFieldU32(sfLedgerSequence, seq);
59 }));
60
61 return res;
62 }
63
66 {
68
70 ttACCOUNT_SET, [&](auto& obj) { obj[sfAccount] = AccountID(1); }));
71
72 res.emplace_back(STTx(ttPAYMENT, [&](auto& obj) {
73 obj.setAccountID(sfAccount, AccountID(2));
74 obj.setAccountID(sfDestination, AccountID(3));
75 }));
76
77 return res;
78 }
79
80 void
82 {
83 using namespace jtx;
84 Env env(*this, features);
85
86 for (auto const& stx :
87 getPseudoTxs(env.closed()->rules(), env.closed()->seq() + 1))
88 {
89 std::string reason;
90 BEAST_EXPECT(isPseudoTx(stx));
91 BEAST_EXPECT(!passesLocalChecks(stx, reason));
92 BEAST_EXPECT(reason == "Cannot submit pseudo transactions.");
93 env.app().openLedger().modify(
94 [&](OpenView& view, beast::Journal j) {
95 auto const result =
96 ripple::apply(env.app(), view, stx, tapNONE, j);
97 BEAST_EXPECT(!result.applied && result.ter == temINVALID);
98 return result.applied;
99 });
100 }
101 }
102
103 void
105 {
106 for (auto const& stx : getRealTxs())
107 {
108 std::string reason;
109 BEAST_EXPECT(!isPseudoTx(stx));
110 BEAST_EXPECT(passesLocalChecks(stx, reason));
111 }
112 }
113
114 void
115 run() override
116 {
117 using namespace test::jtx;
119 FeatureBitset const xrpFees{featureXRPFees};
120
121 testPrevented(all - featureXRPFees);
123 testAllowed();
124 }
125};
126
127BEAST_DEFINE_TESTSUITE(PseudoTx, app, ripple);
128
129} // namespace test
130} // 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.
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:65
Rules controlling protocol behavior.
Definition Rules.h:38
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition Rules.cpp:130
A transaction testing environment.
Definition Env.h:121
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
Definition Env.cpp:115
Application & app()
Definition Env.h:261
T emplace_back(T... args)
FeatureBitset testable_amendments()
Definition Env.h:74
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:48
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition STTx.cpp:820
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:148
bool passesLocalChecks(STObject const &st, std::string &)
Definition STTx.cpp:781
@ 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