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 xrpl {
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
52 res.emplace_back(STTx(ttACCOUNT_SET, [&](auto& obj) { obj[sfAccount] = AccountID(1); }));
53
54 res.emplace_back(STTx(ttPAYMENT, [&](auto& obj) {
55 obj.setAccountID(sfAccount, AccountID(2));
56 obj.setAccountID(sfDestination, AccountID(3));
57 }));
58
59 return res;
60 }
61
62 void
64 {
65 using namespace jtx;
66 Env env(*this, features);
67
68 for (auto const& stx : getPseudoTxs(env.closed()->rules(), env.closed()->seq() + 1))
69 {
70 std::string reason;
71 BEAST_EXPECT(isPseudoTx(stx));
72 BEAST_EXPECT(!passesLocalChecks(stx, reason));
73 BEAST_EXPECT(reason == "Cannot submit pseudo transactions.");
74 env.app().openLedger().modify([&](OpenView& view, beast::Journal j) {
75 auto const result = xrpl::apply(env.app(), view, stx, tapNONE, j);
76 BEAST_EXPECT(!result.applied && result.ter == temINVALID);
77 return result.applied;
78 });
79 }
80 }
81
82 void
84 {
85 for (auto const& stx : getRealTxs())
86 {
87 std::string reason;
88 BEAST_EXPECT(!isPseudoTx(stx));
89 BEAST_EXPECT(passesLocalChecks(stx, reason));
90 }
91 }
92
93 void
94 run() override
95 {
96 using namespace test::jtx;
98 FeatureBitset const xrpFees{featureXRPFees};
99
100 testPrevented(all - featureXRPFees);
102 testAllowed();
103 }
104};
105
106BEAST_DEFINE_TESTSUITE(PseudoTx, app, xrpl);
107
108} // namespace test
109} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
A testsuite class.
Definition suite.h:51
bool modify(modify_type const &f)
Modify the open ledger.
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:45
Rules controlling protocol behavior.
Definition Rules.h:18
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition Rules.cpp:118
virtual OpenLedger & openLedger()=0
A transaction testing environment.
Definition Env.h:119
Application & app()
Definition Env.h:251
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
Definition Env.cpp:92
T emplace_back(T... args)
FeatureBitset testable_amendments()
Definition Env.h:76
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
ApplyResult apply(Application &app, OpenView &view, STTx const &tx, ApplyFlags flags, beast::Journal journal)
Apply a transaction to an OpenView.
Definition apply.cpp:118
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
base_uint< 256 > uint256
Definition base_uint.h:526
bool passesLocalChecks(STObject const &st, std::string &)
Definition STTx.cpp:737
@ tapNONE
Definition ApplyView.h:11
@ temINVALID
Definition TER.h:90
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition STTx.cpp:776
std::vector< STTx > getRealTxs()
void run() override
Runs the suite.
std::vector< STTx > getPseudoTxs(Rules const &rules, std::uint32_t seq)
void testPrevented(FeatureBitset features)
Set the sequence number on a JTx.
Definition seq.h:14