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
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
57
static
std::vector<STTx>
58
getRealTxs
()
59
{
60
std::vector<STTx>
res;
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
73
testPrevented
(
FeatureBitset
features)
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
93
testAllowed
()
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
;
107
FeatureBitset
const
all{
testableAmendments
()};
108
FeatureBitset
const
xrpFees{featureXRPFees};
109
110
testPrevented
(all - featureXRPFees);
111
testPrevented
(all);
112
testAllowed
();
113
}
114
};
115
116
BEAST_DEFINE_TESTSUITE
(PseudoTx, app,
xrpl
);
117
118
}
// 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:64
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:54
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:580
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::run
void run() override
Runs the suite.
Definition
PseudoTx_test.cpp:104
xrpl::test::PseudoTx_test::testAllowed
void testAllowed()
Definition
PseudoTx_test.cpp:93
xrpl::test::PseudoTx_test::testPrevented
void testPrevented(FeatureBitset features)
Definition
PseudoTx_test.cpp:73
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:58
vector
Generated by
1.17.0