rippled
Loading...
Searching...
No Matches
PseudoTx_test.cpp
1#include <test/jtx.h>
2
3#include <xrpl/protocol/Feature.h>
4#include <xrpl/tx/apply.h>
5
6#include <string>
7#include <vector>
8
9namespace xrpl {
10namespace test {
11
13{
16 {
18
19 res.emplace_back(STTx(ttFEE, [&](auto& obj) {
20 obj[sfAccount] = AccountID();
21 obj[sfLedgerSequence] = seq;
22 if (rules.enabled(featureXRPFees))
23 {
24 obj[sfBaseFeeDrops] = XRPAmount{0};
25 obj[sfReserveBaseDrops] = XRPAmount{0};
26 obj[sfReserveIncrementDrops] = XRPAmount{0};
27 }
28 else
29 {
30 obj[sfBaseFee] = 0;
31 obj[sfReserveBase] = 0;
32 obj[sfReserveIncrement] = 0;
33 obj[sfReferenceFeeUnits] = 0;
34 }
35 }));
36
37 res.emplace_back(STTx(ttAMENDMENT, [&](auto& obj) {
38 obj.setAccountID(sfAccount, AccountID());
39 obj.setFieldH256(sfAmendment, uint256(2));
40 obj.setFieldU32(sfLedgerSequence, seq);
41 }));
42
43 return res;
44 }
45
48 {
50
51 res.emplace_back(STTx(ttACCOUNT_SET, [&](auto& obj) { obj[sfAccount] = AccountID(1); }));
52
53 res.emplace_back(STTx(ttPAYMENT, [&](auto& obj) {
54 obj.setAccountID(sfAccount, AccountID(2));
55 obj.setAccountID(sfDestination, AccountID(3));
56 }));
57
58 return res;
59 }
60
61 void
63 {
64 using namespace jtx;
65 Env env(*this, features);
66
67 for (auto const& stx : getPseudoTxs(env.closed()->rules(), env.closed()->seq() + 1))
68 {
69 std::string reason;
70 BEAST_EXPECT(isPseudoTx(stx));
71 BEAST_EXPECT(!passesLocalChecks(stx, reason));
72 BEAST_EXPECT(reason == "Cannot submit pseudo transactions.");
73 env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) {
74 auto const result = xrpl::apply(env.app(), view, stx, tapNONE, j);
75 BEAST_EXPECT(!result.applied && result.ter == temINVALID);
76 return result.applied;
77 });
78 }
79 }
80
81 void
83 {
84 for (auto const& stx : getRealTxs())
85 {
86 std::string reason;
87 BEAST_EXPECT(!isPseudoTx(stx));
88 BEAST_EXPECT(passesLocalChecks(stx, reason));
89 }
90 }
91
92 void
93 run() override
94 {
95 using namespace test::jtx;
97 FeatureBitset const xrpFees{featureXRPFees};
98
99 testPrevented(all - featureXRPFees);
100 testPrevented(all);
101 testAllowed();
102 }
103};
104
105BEAST_DEFINE_TESTSUITE(PseudoTx, app, xrpl);
106
107} // namespace test
108} // 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:120
virtual OpenLedger & getOpenLedger()=0
A transaction testing environment.
Definition Env.h:122
Application & app()
Definition Env.h:259
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
Definition Env.cpp:94
T emplace_back(T... args)
FeatureBitset testable_amendments()
Definition Env.h:78
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
ApplyResult apply(ServiceRegistry &registry, OpenView &view, STTx const &tx, ApplyFlags flags, beast::Journal journal)
Apply a transaction to an OpenView.
Definition apply.cpp:124
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:531
bool passesLocalChecks(STObject const &st, std::string &)
Definition STTx.cpp:770
@ 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:809
void run() override
Runs the suite.
void testPrevented(FeatureBitset features)
static std::vector< STTx > getPseudoTxs(Rules const &rules, std::uint32_t seq)
static std::vector< STTx > getRealTxs()
Set the sequence number on a JTx.
Definition seq.h:14