rippled
Loading...
Searching...
No Matches
PseudoTx_test.cpp
1#include <test/jtx.h>
2
3#include <xrpld/app/tx/apply.h>
4
5#include <xrpl/protocol/Feature.h>
6
7#include <string>
8#include <vector>
9
10namespace ripple {
11namespace test {
12
14{
17 {
19
20 res.emplace_back(STTx(ttFEE, [&](auto& obj) {
21 obj[sfAccount] = AccountID();
22 obj[sfLedgerSequence] = seq;
23 if (rules.enabled(featureXRPFees))
24 {
25 obj[sfBaseFeeDrops] = XRPAmount{0};
26 obj[sfReserveBaseDrops] = XRPAmount{0};
27 obj[sfReserveIncrementDrops] = XRPAmount{0};
28 }
29 else
30 {
31 obj[sfBaseFee] = 0;
32 obj[sfReserveBase] = 0;
33 obj[sfReserveIncrement] = 0;
34 obj[sfReferenceFeeUnits] = 0;
35 }
36 }));
37
38 res.emplace_back(STTx(ttAMENDMENT, [&](auto& obj) {
39 obj.setAccountID(sfAccount, AccountID());
40 obj.setFieldH256(sfAmendment, uint256(2));
41 obj.setFieldU32(sfLedgerSequence, seq);
42 }));
43
44 return res;
45 }
46
49 {
51
53 ttACCOUNT_SET, [&](auto& obj) { obj[sfAccount] = AccountID(1); }));
54
55 res.emplace_back(STTx(ttPAYMENT, [&](auto& obj) {
56 obj.setAccountID(sfAccount, AccountID(2));
57 obj.setAccountID(sfDestination, AccountID(3));
58 }));
59
60 return res;
61 }
62
63 void
65 {
66 using namespace jtx;
67 Env env(*this, features);
68
69 for (auto const& stx :
70 getPseudoTxs(env.closed()->rules(), env.closed()->seq() + 1))
71 {
72 std::string reason;
73 BEAST_EXPECT(isPseudoTx(stx));
74 BEAST_EXPECT(!passesLocalChecks(stx, reason));
75 BEAST_EXPECT(reason == "Cannot submit pseudo transactions.");
76 env.app().openLedger().modify(
77 [&](OpenView& view, beast::Journal j) {
78 auto const result =
79 ripple::apply(env.app(), view, stx, tapNONE, j);
80 BEAST_EXPECT(!result.applied && result.ter == temINVALID);
81 return result.applied;
82 });
83 }
84 }
85
86 void
88 {
89 for (auto const& stx : getRealTxs())
90 {
91 std::string reason;
92 BEAST_EXPECT(!isPseudoTx(stx));
93 BEAST_EXPECT(passesLocalChecks(stx, reason));
94 }
95 }
96
97 void
98 run() override
99 {
100 using namespace test::jtx;
102 FeatureBitset const xrpFees{featureXRPFees};
103
104 testPrevented(all - featureXRPFees);
106 testAllowed();
107 }
108};
109
110BEAST_DEFINE_TESTSUITE(PseudoTx, app, ripple);
111
112} // namespace test
113} // namespace ripple
A generic endpoint for log messages.
Definition Journal.h:41
A testsuite class.
Definition suite.h:52
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:46
Rules controlling protocol behavior.
Definition Rules.h:19
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition Rules.cpp:111
A transaction testing environment.
Definition Env.h:102
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
Definition Env.cpp:97
Application & app()
Definition Env.h:242
T emplace_back(T... args)
FeatureBitset testable_amendments()
Definition Env.h:55
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:29
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition STTx.cpp:851
base_uint< 256 > uint256
Definition base_uint.h:539
ApplyResult apply(Application &app, OpenView &view, STTx const &tx, ApplyFlags flags, beast::Journal journal)
Apply a transaction to an OpenView.
Definition apply.cpp:127
bool passesLocalChecks(STObject const &st, std::string &)
Definition STTx.cpp:812
@ tapNONE
Definition ApplyView.h:12
@ temINVALID
Definition TER.h:91
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:15