xrpld
Loading...
Searching...
No Matches
PseudoTx_test.cpp
1
2#include <test/jtx/Env.h>
3
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/beast/unit_test/suite.h>
6#include <xrpl/beast/utility/Journal.h>
7#include <xrpl/ledger/ApplyView.h>
8#include <xrpl/ledger/OpenView.h>
9#include <xrpl/protocol/Feature.h>
10#include <xrpl/protocol/Rules.h>
11#include <xrpl/protocol/SField.h>
12#include <xrpl/protocol/STTx.h>
13#include <xrpl/protocol/TER.h>
14#include <xrpl/protocol/TxFormats.h>
15#include <xrpl/tx/apply.h>
16
17#include <cstdint>
18#include <string>
19#include <vector>
20
21namespace xrpl::test {
22
24{
26 getPseudoTxs(Rules const& rules, std::uint32_t seq)
27 {
29
30 res.emplace_back(ttFEE, [&](auto& obj) {
31 obj[sfAccount] = AccountID();
32 obj[sfLedgerSequence] = seq;
33 if (rules.enabled(featureXRPFees))
34 {
35 obj[sfBaseFeeDrops] = XRPAmount{0};
36 obj[sfReserveBaseDrops] = XRPAmount{0};
37 obj[sfReserveIncrementDrops] = XRPAmount{0};
38 }
39 else
40 {
41 obj[sfBaseFee] = 0;
42 obj[sfReserveBase] = 0;
43 obj[sfReserveIncrement] = 0;
44 obj[sfReferenceFeeUnits] = 0;
45 }
46 });
47
48 res.emplace_back(ttAMENDMENT, [&](auto& obj) {
49 obj.setAccountID(sfAccount, AccountID());
50 obj.setFieldH256(sfAmendment, uint256(2));
51 obj.setFieldU32(sfLedgerSequence, seq);
52 });
53
54 return res;
55 }
56
59 {
61
62 res.emplace_back(ttACCOUNT_SET, [&](auto& obj) { obj[sfAccount] = AccountID(1); });
63
64 res.emplace_back(ttPAYMENT, [&](auto& obj) {
65 obj.setAccountID(sfAccount, AccountID(2));
66 obj.setAccountID(sfDestination, AccountID(3));
67 });
68
69 return res;
70 }
71
72 void
74 {
75 using namespace jtx;
76 Env env(*this, features);
77
78 for (auto const& stx : getPseudoTxs(env.closed()->rules(), env.closed()->seq() + 1))
79 {
80 std::string reason;
81 BEAST_EXPECT(isPseudoTx(stx));
82 BEAST_EXPECT(!passesLocalChecks(stx, reason));
83 BEAST_EXPECT(reason == "Cannot submit pseudo transactions.");
84 env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) {
85 auto const result = xrpl::apply(env.app(), view, stx, TapNone, j);
86 BEAST_EXPECT(!result.applied && result.ter == temINVALID);
87 return result.applied;
88 });
89 }
90 }
91
92 void
94 {
95 for (auto const& stx : getRealTxs())
96 {
97 std::string reason;
98 BEAST_EXPECT(!isPseudoTx(stx));
99 BEAST_EXPECT(passesLocalChecks(stx, reason));
100 }
101 }
102
103 void
104 run() override
105 {
106 using namespace test::jtx;
108 FeatureBitset const xrpFees{featureXRPFees};
109
110 testPrevented(all - featureXRPFees);
111 testPrevented(all);
112 testAllowed();
113 }
114};
115
117
118} // namespace xrpl::test
A generic endpoint for log messages.
Definition Journal.h:38
A testsuite class.
Definition suite.h:50
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:33
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition Rules.cpp:171
virtual OpenLedger & getOpenLedger()=0
A transaction testing environment.
Definition Env.h:143
Application & app()
Definition Env.h:280
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
Definition Env.cpp:127
T emplace_back(T... args)
FeatureBitset testableAmendments()
Definition Env.h:76
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
constexpr XRPAmount
Convert XRP to drops (integral types).
Definition TxTest.h:48
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:139
bool passesLocalChecks(STObject const &st, std::string &)
Definition STTx.cpp:771
@ TapNone
Definition ApplyView.h:13
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
@ temINVALID
Definition TER.h:96
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition STTx.cpp:810
BaseUInt< 256 > uint256
Definition base_uint.h:562
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()