xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
app
vault
VaultTestBase.h
1
#pragma once
2
3
#include <test/jtx/Account.h>
4
#include <test/jtx/Env.h>
5
#include <test/jtx/amount.h>
6
#include <test/jtx/vault.h>
7
8
#include <xrpl/basics/chrono.h>
9
#include <xrpl/beast/unit_test/suite.h>
10
#include <xrpl/protocol/Asset.h>
11
#include <xrpl/protocol/Feature.h>
12
#include <xrpl/protocol/Keylet.h>
13
#include <xrpl/protocol/Protocol.h>
14
#include <xrpl/protocol/STAmount.h>
15
16
#include <
chrono
>
17
#include <
cstdint
>
18
#include <format>
19
#include <source_location>
20
#include <
string
>
21
#include <
utility
>
22
23
namespace
xrpl
{
24
37
class
VaultTestBase
:
public
beast::unit_test::Suite
38
{
39
protected
:
40
using
PrettyAsset
=
test::jtx::PrettyAsset
;
41
using
PrettyAmount
=
test::jtx::PrettyAmount
;
42
43
static
constexpr
auto
kNegativeAmount
= [](
PrettyAsset
const
& asset) ->
PrettyAmount
{
44
return
{
STAmount
{asset.raw(), 1ul, 0,
true
,
STAmount::Unchecked
{}},
""
};
45
};
46
51
static
NetClock::duration
52
getLedgerTimeResolution
(
test::jtx::Env
& env)
53
{
54
return
env.
current
()->header().closeTimeResolution;
55
}
56
57
void
58
closeToTime
(
59
test::jtx::Env
& env,
60
NetClock::time_point
time,
61
std::source_location
const
& loc =
std::source_location::current
())
62
{
63
using namespace
std::chrono_literals;
64
env.
close
(time - env.
closed
()->header().closeTimeResolution + 1s);
65
expect
(
66
env.
closed
()->header().closeTime == time,
67
std::format
(
68
"current ledger time {} is not equal to the target ledger time {}"
,
69
env.
closed
()->header().closeTime.time_since_epoch(),
70
time.time_since_epoch()),
71
loc.file_name(),
72
loc.line());
73
}
74
75
using
D
=
NetClock::duration
;
76
using
Tp
=
NetClock::time_point
;
77
78
// Vault holds an Env& so no default initializer is possible; the
79
// struct is always aggregate-initialized by makeClosedEndedVault.
80
// NOLINTBEGIN(cppcoreguidelines-pro-type-member-init)
81
struct
ClosedEndedSetup
82
{
83
test::jtx::Vault
vault
;
84
Keylet
keylet
;
85
std::uint32_t
sub
= 0;
86
std::uint32_t
red
= 0;
87
};
88
// NOLINTEND(cppcoreguidelines-pro-type-member-init)
89
90
// Submit a VaultCreate for a closed-ended vault with SubscriptionDate at
91
// env.now() + subOffset and RedemptionDate at SubscriptionDate + gap, then
92
// close the ledger. Returns the Vault helper, the vault's keylet and the
93
// resolved sub/red timestamps.
94
static
ClosedEndedSetup
95
makeClosedEndedVault
(
96
test::jtx::Env
& env,
97
test::jtx::Account
const
& owner,
98
Asset
const
& asset,
99
std::uint32_t
subOffset,
100
std::uint32_t
gap)
101
{
102
auto
const
sub = env.
now
().
time_since_epoch
().count() + subOffset;
103
auto
const
red = sub + gap;
104
test::jtx::Vault
const
vault{env};
105
auto
[tx,
keylet
] = vault.create(
106
{.owner = owner,
107
.asset = asset,
108
.vaultKind = std::to_underlying(
VaultKind::ClosedEnded
),
109
.subscriptionDate = sub,
110
.redemptionDate = red});
111
env(tx);
112
env.
close
();
113
return
{.vault = vault, .keylet =
keylet
, .sub = sub, .red = red};
114
}
115
116
FeatureBitset
const
all_
{
test::jtx::testableAmendments
()};
117
std::string
const
iouCurrency_
{
"IOU"
};
118
};
119
120
}
// namespace xrpl
std::string
chrono
beast::unit_test::Suite
A testsuite class.
Definition
suite.h:52
beast::unit_test::Suite::expect
bool expect(Condition const &shouldBeTrue)
Evaluate a test condition.
Definition
suite.h:235
xrpl::Asset
Definition
Asset.h:52
xrpl::FeatureBitset
Definition
Feature.h:196
xrpl::NetClock::time_point
std::chrono::time_point< NetClock > time_point
Definition
chrono.h:48
xrpl::NetClock::duration
std::chrono::duration< rep, period > duration
Definition
chrono.h:47
xrpl::STAmount
Definition
STAmount.h:46
xrpl::VaultTestBase
Shared base for the Vault*_test family under src/test/app/vault/.
Definition
VaultTestBase.h:38
xrpl::VaultTestBase::D
NetClock::duration D
Definition
VaultTestBase.h:75
xrpl::VaultTestBase::Tp
NetClock::time_point Tp
Definition
VaultTestBase.h:76
xrpl::VaultTestBase::all_
FeatureBitset const all_
Definition
VaultTestBase.h:116
xrpl::VaultTestBase::iouCurrency_
std::string const iouCurrency_
Definition
VaultTestBase.h:117
xrpl::VaultTestBase::makeClosedEndedVault
static ClosedEndedSetup makeClosedEndedVault(test::jtx::Env &env, test::jtx::Account const &owner, Asset const &asset, std::uint32_t subOffset, std::uint32_t gap)
Definition
VaultTestBase.h:95
xrpl::VaultTestBase::kNegativeAmount
static constexpr auto kNegativeAmount
Definition
VaultTestBase.h:43
xrpl::VaultTestBase::closeToTime
void closeToTime(test::jtx::Env &env, NetClock::time_point time, std::source_location const &loc=std::source_location::current())
Definition
VaultTestBase.h:58
xrpl::VaultTestBase::getLedgerTimeResolution
static NetClock::duration getLedgerTimeResolution(test::jtx::Env &env)
Get the current ledger's close time resolution.
Definition
VaultTestBase.h:52
xrpl::VaultTestBase::PrettyAmount
test::jtx::PrettyAmount PrettyAmount
Definition
VaultTestBase.h:41
xrpl::VaultTestBase::PrettyAsset
test::jtx::PrettyAsset PrettyAsset
Definition
VaultTestBase.h:40
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
xrpl::test::jtx::Env::close
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition
Env.cpp:133
xrpl::test::jtx::Env::closed
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
Definition
Env.cpp:127
xrpl::test::jtx::Env::current
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition
Env.h:377
xrpl::test::jtx::Env::now
NetClock::time_point now()
Returns the current network time.
Definition
Env.h:326
cstdint
std::source_location::current
T current(T... args)
std::format
T format(T... args)
std::uint32_t
xrpl::keylet
Keylet computation functions.
Definition
Indexes.h:40
xrpl::test::jtx::testableAmendments
FeatureBitset testableAmendments()
Definition
Env.h:92
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::VaultKind::ClosedEnded
@ ClosedEnded
Definition
Protocol.h:338
std::source_location
string
xrpl::Keylet
A pair of SHAMap key and LedgerEntryType.
Definition
Keylet.h:20
xrpl::STAmount::Unchecked
Definition
STAmount.h:84
xrpl::VaultTestBase::ClosedEndedSetup
Definition
VaultTestBase.h:82
xrpl::VaultTestBase::ClosedEndedSetup::red
std::uint32_t red
Definition
VaultTestBase.h:86
xrpl::VaultTestBase::ClosedEndedSetup::vault
test::jtx::Vault vault
Definition
VaultTestBase.h:83
xrpl::VaultTestBase::ClosedEndedSetup::sub
std::uint32_t sub
Definition
VaultTestBase.h:85
xrpl::VaultTestBase::ClosedEndedSetup::keylet
Keylet keylet
Definition
VaultTestBase.h:84
xrpl::test::jtx::PrettyAmount
Represents an XRP, IOU, or MPT quantity This customizes the string conversion and supports XRP conver...
Definition
src/test/jtx/amount.h:78
xrpl::test::jtx::PrettyAsset
Definition
src/test/jtx/amount.h:169
xrpl::test::jtx::Vault
Definition
vault.h:22
std::chrono::time_point::time_since_epoch
T time_since_epoch(T... args)
utility
Generated by
1.17.0