xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
app
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
21
namespace
xrpl::test
{
22
23
struct
PseudoTx_test
:
public
beast::unit_test::Suite
24
{
25
static
std::vector<STTx>
26
getPseudoTxs
(
Rules
const
& rules,
std::uint32_t
seq)
27
{
28
std::vector<STTx>
res;
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
53
static
std::vector<STTx>
54
getRealTxs
()
55
{
56
std::vector<STTx>
res;
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
69
testPrevented
(
FeatureBitset
features =
test::jtx::testableAmendments
())
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
89
testAllowed
()
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
;
103
FeatureBitset
const
all{
testableAmendments
()};
104
105
testPrevented
(all - featureSmartEscrow);
106
testPrevented
(all);
107
testAllowed
();
108
}
109
};
110
111
BEAST_DEFINE_TESTSUITE
(PseudoTx, app,
xrpl
);
112
113
}
// namespace xrpl::test
std::string
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
beast::unit_test::Suite
A testsuite class.
Definition
suite.h:52
xrpl::FeatureBitset
Definition
Feature.h:196
xrpl::OpenLedger::modify
bool modify(ModifyType const &f)
Modify the open ledger.
Definition
OpenLedger.cpp:63
xrpl::OpenView
Writable ledger view that accumulates state and tx changes.
Definition
OpenView.h:59
xrpl::Rules
Rules controlling protocol behavior.
Definition
Rules.h:40
xrpl::Rules::enabled
bool enabled(UInt256 const &feature) const
Returns true if a feature is enabled.
Definition
Rules.cpp:182
xrpl::ServiceRegistry::getOpenLedger
virtual OpenLedger & getOpenLedger()=0
xrpl::test::jtx::Env
A transaction testing environment.
Definition
Env.h:161
xrpl::test::jtx::Env::app
Application & app()
Definition
Env.h:300
xrpl::test::jtx::Env::closed
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
Definition
Env.cpp:127
cstdint
std::vector::emplace_back
T emplace_back(T... args)
std::uint32_t
xrpl::test::jtx
Definition
Oracle_test.cpp:34
xrpl::test::jtx::testableAmendments
FeatureBitset testableAmendments()
Definition
Env.h:92
xrpl::test
Definition
STLedgerEntry.h:21
xrpl::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
xrpl::test::XRPAmount
constexpr XRPAmount
Convert XRP to drops (integral types).
Definition
TxTest.h:53
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::apply
ApplyResult apply(ServiceRegistry ®istry, OpenView &view, STTx const &tx, ApplyFlags flags, beast::Journal journal)
Apply a transaction to an OpenView.
Definition
apply.cpp:181
xrpl::passesLocalChecks
bool passesLocalChecks(STTx const &tx, std::string &)
Definition
STTx.cpp:850
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:581
xrpl::TapNone
@ TapNone
Definition
ApplyView.h:28
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
xrpl::temINVALID
@ temINVALID
Definition
TER.h:98
xrpl::isPseudoTx
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition
STTx.cpp:889
string
xrpl::test::PseudoTx_test
Definition
PseudoTx_test.cpp:24
xrpl::test::PseudoTx_test::testPrevented
void testPrevented(FeatureBitset features=test::jtx::testableAmendments())
Definition
PseudoTx_test.cpp:69
xrpl::test::PseudoTx_test::run
void run() override
Runs the suite.
Definition
PseudoTx_test.cpp:100
xrpl::test::PseudoTx_test::testAllowed
void testAllowed()
Definition
PseudoTx_test.cpp:89
xrpl::test::PseudoTx_test::getPseudoTxs
static std::vector< STTx > getPseudoTxs(Rules const &rules, std::uint32_t seq)
Definition
PseudoTx_test.cpp:26
xrpl::test::PseudoTx_test::getRealTxs
static std::vector< STTx > getRealTxs()
Definition
PseudoTx_test.cpp:54
vector
Generated by
1.17.0