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 obj[sfBaseFeeDrops] = XRPAmount{0};
34 obj[sfReserveBaseDrops] = XRPAmount{0};
35 obj[sfReserveIncrementDrops] = XRPAmount{0};
36 if (rules.enabled(featureSmartEscrow))
37 {
38 obj[sfGasLimit] = 0;
39 obj[sfBytecodeSizeLimit] = 0;
40 obj[sfGasPrice] = 0;
41 }
42 });
43
44 res.emplace_back(ttAMENDMENT, [&](auto& obj) {
45 obj.setAccountID(sfAccount, AccountID());
46 obj.setFieldH256(sfAmendment, UInt256(2));
47 obj.setFieldU32(sfLedgerSequence, seq);
48 });
49
50 return res;
51 }
52
55 {
57
58 res.emplace_back(ttACCOUNT_SET, [&](auto& obj) { obj[sfAccount] = AccountID(1); });
59
60 res.emplace_back(ttPAYMENT, [&](auto& obj) {
61 obj.setAccountID(sfAccount, AccountID(2));
62 obj.setAccountID(sfDestination, AccountID(3));
63 });
64
65 return res;
66 }
67
68 void
70 {
71 using namespace jtx;
72 Env env(*this, features);
73
74 for (auto const& stx : getPseudoTxs(env.closed()->rules(), env.closed()->seq() + 1))
75 {
76 std::string reason;
77 BEAST_EXPECT(isPseudoTx(stx));
78 BEAST_EXPECT(!passesLocalChecks(stx, reason));
79 BEAST_EXPECT(reason == "Cannot submit pseudo transactions.");
80 env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) {
81 auto const result = xrpl::apply(env.app(), view, stx, TapNone, j);
82 BEAST_EXPECT(!result.applied && result.ter == temINVALID);
83 return result.applied;
84 });
85 }
86 }
87
88 void
90 {
91 for (auto const& stx : getRealTxs())
92 {
93 std::string reason;
94 BEAST_EXPECT(!isPseudoTx(stx));
95 BEAST_EXPECT(passesLocalChecks(stx, reason));
96 }
97 }
98
99 void
100 run() override
101 {
102 using namespace test::jtx;
104
105 testPrevented(all - featureSmartEscrow);
106 testPrevented(all);
107 testAllowed();
108 }
109};
110
112
113} // namespace xrpl::test
A generic endpoint for log messages.
Definition Journal.h:44
A testsuite class.
Definition suite.h:52
bool modify(ModifyType const &f)
Modify the open ledger.
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:59
Rules controlling protocol behavior.
Definition Rules.h:40
bool enabled(UInt256 const &feature) const
Returns true if a feature is enabled.
Definition Rules.cpp:182
virtual OpenLedger & getOpenLedger()=0
A transaction testing environment.
Definition Env.h:161
Application & app()
Definition Env.h:300
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:92
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
constexpr XRPAmount
Convert XRP to drops (integral types).
Definition TxTest.h:53
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:181
bool passesLocalChecks(STTx const &tx, std::string &)
Definition STTx.cpp:850
BaseUInt< 256 > UInt256
Definition base_uint.h:581
@ TapNone
Definition ApplyView.h:28
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
@ temINVALID
Definition TER.h:98
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition STTx.cpp:889
void testPrevented(FeatureBitset features=test::jtx::testableAmendments())
void run() override
Runs the suite.
static std::vector< STTx > getPseudoTxs(Rules const &rules, std::uint32_t seq)
static std::vector< STTx > getRealTxs()