xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
tests
libxrpl
ledger
EntryTestHelpers.h
1
#pragma once
2
3
#include <xrpl/basics/base_uint.h>
4
#include <xrpl/ledger/ApplyView.h>
5
#include <xrpl/ledger/ApplyViewImpl.h>
6
#include <xrpl/ledger/ReadView.h>
7
#include <xrpl/protocol/Keylet.h>
8
#include <xrpl/protocol/LedgerHeader.h>
9
10
#include <gtest/gtest.h>
11
#include <helpers/Account.h>
12
#include <helpers/TxTest.h>
13
14
#include <
string
>
15
16
namespace
xrpl::test
{
17
27
class
EntryTestEnv
28
{
29
public
:
30
TxTest
env
;
31
Account
const
alice
{
"alice"
};
32
Account
const
bob
{
"bob"
};
33
Account
const
carol
{
"carol"
};
34
35
EntryTestEnv
() :
av_
(&
fundAndClose
(),
TapNone
)
36
{
37
}
38
44
[[nodiscard]]
ReadView
const
&
45
read
()
const
46
{
47
return
env
.getClosedLedger();
48
}
49
50
[[nodiscard]]
ApplyView
&
51
apply
()
52
{
53
return
av_
;
54
}
55
61
[[nodiscard]]
UInt256
62
someID
()
const
63
{
64
return
read
().
header
().
parentHash
;
65
}
66
67
private
:
68
// Runs from the av_ member initializer, so it may only touch env and the
69
// accounts -- everything declared above av_.
70
ReadView
const
&
71
fundAndClose
()
72
{
73
env
.createAccount(
alice
,
XRP
(10'000));
74
env
.createAccount(
bob
,
XRP
(10'000));
75
env
.createAccount(
carol
,
XRP
(10'000));
76
env
.close();
77
return
env
.getClosedLedger();
78
}
79
80
ApplyViewImpl
av_
;
81
};
82
94
template
<
template
<
typename
>
class
Entry,
typename
... Args>
95
void
96
expectKeylet
(
EntryTestEnv
& e,
Keylet
const
& expected,
std::string
const
& what, Args
const
&... args)
97
{
98
bool
const
present = e.
read
().
read
(expected) !=
nullptr
;
99
100
// The writable entry retains its keylet, so it can be inspected whether
101
// or not the entry exists.
102
Entry<ApplyView>
const
w(args..., e.
apply
());
103
EXPECT_EQ(w.keylet().key, expected.
key
) << what <<
": writable key"
;
104
EXPECT_EQ(w.keylet().type, expected.
type
) << what <<
": writable type"
;
105
EXPECT_EQ(w.exists(), present) << what <<
": writable exists"
;
106
107
// The read-only entry has no keylet of its own -- it derives one from the
108
// SLE, and only when the SLE exists. Its agreement with a direct read
109
// of the expected keylet is what shows it resolved the same key.
110
Entry<ReadView>
const
r(args..., e.
read
());
111
EXPECT_EQ(r.exists(), present) << what <<
": read-only exists"
;
112
if
(present)
113
{
114
EXPECT_EQ(r.key(), expected.
key
) << what <<
": read-only key"
;
115
}
116
117
// Not r.type(): for a typed entry that returns kEntryType, so checking it
118
// would just be this same assertion spelled twice.
119
static_assert
(Entry<ReadView>::kEntryType == Entry<ApplyView>::kEntryType);
120
EXPECT_EQ(Entry<ReadView>::kEntryType, expected.
type
) << what <<
": kEntryType"
;
121
}
122
123
}
// namespace xrpl::test
std::string
xrpl::ApplyViewImpl
Editable, discardable view that can build metadata for one tx.
Definition
ApplyViewImpl.h:29
xrpl::ApplyView
Writeable view to a ledger, for applying a transaction.
Definition
ApplyView.h:141
xrpl::ReadView
A view into a ledger.
Definition
ReadView.h:41
xrpl::ReadView::read
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
xrpl::ReadView::header
virtual LedgerHeader const & header() const =0
Returns information about the ledger.
xrpl::test::EntryTestEnv
Scaffolding shared by the per-entry-type suites.
Definition
EntryTestHelpers.h:28
xrpl::test::EntryTestEnv::fundAndClose
ReadView const & fundAndClose()
Definition
EntryTestHelpers.h:71
xrpl::test::EntryTestEnv::alice
Account const alice
Definition
EntryTestHelpers.h:31
xrpl::test::EntryTestEnv::someID
UInt256 someID() const
An arbitrary but stable UInt256, for the entry constructors that take an object ID directly.
Definition
EntryTestHelpers.h:62
xrpl::test::EntryTestEnv::av_
ApplyViewImpl av_
Definition
EntryTestHelpers.h:80
xrpl::test::EntryTestEnv::EntryTestEnv
EntryTestEnv()
Definition
EntryTestHelpers.h:35
xrpl::test::EntryTestEnv::bob
Account const bob
Definition
EntryTestHelpers.h:32
xrpl::test::EntryTestEnv::read
ReadView const & read() const
The closed ledger apply() was built over.
Definition
EntryTestHelpers.h:45
xrpl::test::EntryTestEnv::carol
Account const carol
Definition
EntryTestHelpers.h:33
xrpl::test::EntryTestEnv::env
TxTest env
Definition
EntryTestHelpers.h:30
xrpl::test::EntryTestEnv::apply
ApplyView & apply()
Definition
EntryTestHelpers.h:51
xrpl::test::TxTest
A lightweight transaction testing harness.
Definition
TxTest.h:185
xrpl::test::jtx::Account
Immutable cryptographic account descriptor.
Definition
jtx/Account.h:21
xrpl::test::jtx::XRP
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition
amount.cpp:92
xrpl::test
Definition
STLedgerEntry.h:21
xrpl::test::expectKeylet
void expectKeylet(EntryTestEnv &e, Keylet const &expected, std::string const &what, Args const &... args)
Assert that both flavors of Entry built from args resolve the ledger object that expected names.
Definition
EntryTestHelpers.h:96
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
xrpl::TapNone
@ TapNone
Definition
ApplyView.h:28
string
xrpl::Keylet
A pair of SHAMap key and LedgerEntryType.
Definition
Keylet.h:20
xrpl::Keylet::key
UInt256 key
Definition
Keylet.h:21
xrpl::Keylet::type
LedgerEntryType type
Definition
Keylet.h:22
xrpl::LedgerHeader::parentHash
UInt256 parentHash
Definition
LedgerHeader.h:37
Generated by
1.17.0