xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
app
invariants
InvariantsBase.h
1
#pragma once
2
3
#include <test/jtx/Account.h>
4
#include <test/jtx/Env.h>
5
#include <test/jtx/amount.h>
6
7
#include <xrpld/app/main/Application.h>
8
9
#include <xrpl/basics/base_uint.h>
10
#include <xrpl/beast/unit_test/suite.h>
11
#include <xrpl/protocol/AccountID.h>
12
#include <xrpl/protocol/Feature.h>
13
#include <xrpl/protocol/Keylet.h>
14
#include <xrpl/protocol/STObject.h>
15
#include <xrpl/protocol/STTx.h>
16
#include <xrpl/protocol/TER.h>
17
#include <xrpl/protocol/TxFormats.h>
18
#include <xrpl/protocol/XRPAmount.h>
19
#include <xrpl/tx/ApplyContext.h>
20
21
#include <
cstdint
>
22
#include <
functional
>
23
#include <
initializer_list
>
24
#include <
memory
>
25
#include <source_location>
26
#include <
string
>
27
#include <
vector
>
28
29
namespace
xrpl
{
30
31
class
Transactor
;
32
33
// Test-only factory — not part of the public API.
34
// The returned Transactor holds a raw reference to ctx; the caller must ensure
35
// the ApplyContext outlives the Transactor. Implemented in applySteps.cpp
36
std::unique_ptr<Transactor>
37
makeTransactor
(
ApplyContext
& ctx);
38
39
}
// namespace xrpl
40
41
namespace
xrpl::test
{
42
43
class
InvariantsBase
:
public
beast::unit_test::Suite
44
{
45
protected
:
46
// The optional Preclose function is used to process additional transactions
47
// on the ledger after creating two accounts, but before closing it, and
48
// before the Precheck function. These should only be valid functions, and
49
// not direct manipulations. Preclose is not commonly used.
50
using
Preclose
=
std::function
<
51
bool(
test::jtx::Account
const
& a,
test::jtx::Account
const
& b,
test::jtx::Env
& env)>;
52
53
// this is common setup/method for running a failing invariant check. The
54
// precheck function is used to manipulate the ApplyContext with view
55
// changes that will cause the check to fail.
56
using
Precheck
=
std::function
<
57
bool(
test::jtx::Account
const
& a,
test::jtx::Account
const
& b,
ApplyContext
& ac)>;
58
59
enum class
TxAccount
:
int
{
None
= 0,
A1
,
A2
};
60
61
test::jtx::Env
62
makeEnv
(
FeatureBitset
features);
63
81
void
82
doInvariantCheck
(
83
std::vector<std::string>
const
& expectLogs,
84
Precheck
const
& precheck,
85
XRPAmount
fee =
XRPAmount
{},
86
STTx
tx =
STTx
{ttACCOUNT_SET, [](
STObject
&) {}},
87
std::initializer_list<TER> ters = {
tecINVARIANT_FAILED
,
tefINVARIANT_FAILED
},
88
Preclose
const
& preclose = {},
89
TxAccount
setTxAccount =
TxAccount::None
,
90
std::source_location
const
& loc =
std::source_location::current
(),
91
// Result fed to the invariant checker on the first pass. Set it to a
92
// tec to exercise result-dependent invariants; the harness runs no
93
// transactor, so one never arises on its own.
94
TER
initialResult =
tesSUCCESS
);
95
96
void
97
doInvariantCheck
(
98
test::jtx::Env&& env,
99
std::vector<std::string>
const
& expectLogs,
100
Precheck
const
& precheck,
101
XRPAmount
fee =
XRPAmount
{},
102
STTx tx = STTx{ttACCOUNT_SET, [](STObject&) {}},
103
std::initializer_list<TER> ters = {
tecINVARIANT_FAILED
,
tefINVARIANT_FAILED
},
104
Preclose
const
& preclose = {},
105
TxAccount
setTxAccount =
TxAccount::None
,
106
std::source_location
const
& loc =
std::source_location::current
(),
107
TER
initialResult =
tesSUCCESS
);
108
109
void
110
doInvariantCheck
(
111
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
112
test::jtx::Env&& env,
113
test::jtx::Account
const
& a1,
114
test::jtx::Account
const
& a2,
115
std::vector<std::string>
const
& expectLogs,
116
Precheck
const
& precheck,
117
XRPAmount
fee =
XRPAmount
{},
118
STTx tx = STTx{ttACCOUNT_SET, [](STObject&) {}},
119
std::initializer_list<TER> ters = {
tecINVARIANT_FAILED
,
tefINVARIANT_FAILED
},
120
std::source_location
const
& loc =
std::source_location::current
(),
121
TER
initialResult =
tesSUCCESS
);
122
123
Keylet
124
createLoanBroker
(jtx::Account
const
& a, jtx::Env& env, jtx::PrettyAsset
const
& asset);
125
126
// Build an ltLOAN SLE with every SoeRequired field explicitly set and
127
// every SoeDefault field the invariants read via `at()` materialized, so
128
// rawInsert-based tests don't accidentally trip an unrelated invariant
129
// or throw from a missing SoeDefault field.
130
static
SLE::pointer
131
makeLoanSle
(
UInt256
const
& loanBrokerID, std::uint32_t loanSeq,
AccountID
const
& borrower);
132
};
133
134
}
// namespace xrpl::test
beast::unit_test::Suite
A testsuite class.
Definition
suite.h:52
xrpl::ApplyContext
State information when applying a tx.
Definition
ApplyContext.h:28
xrpl::FeatureBitset
Definition
Feature.h:196
xrpl::STLedgerEntry::pointer
std::shared_ptr< STLedgerEntry > pointer
Definition
STLedgerEntry.h:34
xrpl::STObject
Definition
STObject.h:49
xrpl::STTx
Definition
STTx.h:43
xrpl::Transactor
Definition
Transactor.h:160
xrpl::test::InvariantsBase
Definition
InvariantsBase.h:44
xrpl::test::InvariantsBase::createLoanBroker
Keylet createLoanBroker(jtx::Account const &a, jtx::Env &env, jtx::PrettyAsset const &asset)
Definition
InvariantsBase.cpp:179
xrpl::test::InvariantsBase::TxAccount
TxAccount
Definition
InvariantsBase.h:59
xrpl::test::InvariantsBase::TxAccount::A1
@ A1
Definition
InvariantsBase.h:59
xrpl::test::InvariantsBase::TxAccount::None
@ None
Definition
InvariantsBase.h:59
xrpl::test::InvariantsBase::TxAccount::A2
@ A2
Definition
InvariantsBase.h:59
xrpl::test::InvariantsBase::Precheck
std::function< bool(test::jtx::Account const &a, test::jtx::Account const &b, ApplyContext &ac)> Precheck
Definition
InvariantsBase.h:56
xrpl::test::InvariantsBase::makeEnv
test::jtx::Env makeEnv(FeatureBitset features)
Definition
InvariantsBase.cpp:47
xrpl::test::InvariantsBase::doInvariantCheck
void doInvariantCheck(std::vector< std::string > const &expectLogs, Precheck const &precheck, XRPAmount fee=XRPAmount{}, STTx tx=STTx{ttACCOUNT_SET, [](STObject &) {}}, std::initializer_list< TER > ters={tecINVARIANT_FAILED, tefINVARIANT_FAILED}, Preclose const &preclose={}, TxAccount setTxAccount=TxAccount::None, std::source_location const &loc=std::source_location::current(), TER initialResult=tesSUCCESS)
Run a specific test case to put the ledger into a state that will be detected by an invariant.
Definition
InvariantsBase.cpp:53
xrpl::test::InvariantsBase::makeLoanSle
static SLE::pointer makeLoanSle(UInt256 const &loanBrokerID, std::uint32_t loanSeq, AccountID const &borrower)
Definition
InvariantsBase.cpp:213
xrpl::test::InvariantsBase::Preclose
std::function< bool(test::jtx::Account const &a, test::jtx::Account const &b, test::jtx::Env &env)> Preclose
Definition
InvariantsBase.h:50
xrpl::test::jtx::Account
Immutable cryptographic account descriptor.
Definition
jtx/Account.h:21
xrpl::test::jtx::Env
A transaction testing environment.
Definition
Env.h:161
cstdint
std::source_location::current
T current(T... args)
std::function
functional
initializer_list
memory
xrpl::test
Definition
STLedgerEntry.h:21
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::tefINVARIANT_FAILED
@ tefINVARIANT_FAILED
Definition
TER.h:178
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
xrpl::makeTransactor
std::unique_ptr< Transactor > makeTransactor(ApplyContext &ctx)
Definition
applySteps.cpp:327
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
xrpl::TER
TERSubset< CanCvtToTER > TER
Definition
TER.h:654
xrpl::tecINVARIANT_FAILED
@ tecINVARIANT_FAILED
Definition
TER.h:321
xrpl::tesSUCCESS
@ tesSUCCESS
Definition
TER.h:250
string
xrpl::test::jtx::None
Definition
src/test/jtx/amount.h:61
vector
Generated by
1.17.0