xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
app
lending
LoanManageFixedPrecisionBase.h
1
#pragma once
2
3
#include <test/app/lending/LoanPayFixedPrecisionBase.h>
4
#include <test/jtx/Account.h>
5
#include <test/jtx/Env.h>
6
#include <test/jtx/TestHelpers.h>
7
8
#include <xrpl/basics/chrono.h>
9
#include <xrpl/beast/unit_test/suite.h>
10
#include <xrpl/protocol/Keylet.h>
11
#include <xrpl/protocol/SField.h>
12
#include <xrpl/protocol/TxFlags.h>
13
14
#include <
chrono
>
15
#include <
cstdint
>
16
17
namespace
xrpl
{
18
19
// LoanManage-tier scaffolding on top of LoanPayFixedPrecisionBase: the
20
// default/impair helpers needed by LoanManageFixedPrecision only.
21
class
LoanManageFixedPrecisionBase
:
public
LoanPayFixedPrecisionBase
22
{
23
protected
:
24
// Advance the clock one second past the loan's due date (late, in grace) or
25
// past its grace period (defaultable).
26
void
27
closePastDue
(
test::jtx::Env
& env,
Keylet
const
& loanKeylet)
28
{
29
auto
const
loanSle = env.
le
(loanKeylet);
30
if
(!BEAST_EXPECT(loanSle))
31
return
;
32
std::uint32_t
const
dueDate = loanSle->at(sfNextPaymentDueDate);
33
env.
close
(
NetClock::time_point
{
NetClock::duration
{dueDate}} +
std::chrono::seconds
{1});
34
}
35
36
void
37
closePastGrace
(
test::jtx::Env
& env,
Keylet
const
& loanKeylet)
38
{
39
auto
const
loanSle = env.
le
(loanKeylet);
40
if
(!BEAST_EXPECT(loanSle))
41
return
;
42
std::uint32_t
const
dueDate = loanSle->at(sfNextPaymentDueDate);
43
std::uint32_t
const
grace = loanSle->at(sfGracePeriod);
44
env.
close
(
45
NetClock::time_point
{
NetClock::duration
{dueDate + grace}} +
std::chrono::seconds
{1});
46
}
47
48
void
49
impairWhenLate
(
test::jtx::Env
& env,
test::jtx::Account
const
& owner,
Keylet
const
& loanKeylet)
50
{
51
closePastDue
(env, loanKeylet);
52
env(
test::jtx::loan::manage
(owner, loanKeylet.
key
, tfLoanImpair));
53
env.
close
();
54
}
55
56
void
57
defaultAfterGrace
(
58
test::jtx::Env
& env,
59
test::jtx::Account
const
& owner,
60
Keylet
const
& loanKeylet)
61
{
62
closePastGrace
(env, loanKeylet);
63
env(
test::jtx::loan::manage
(owner, loanKeylet.
key
, tfLoanDefault));
64
env.
close
();
65
}
66
};
67
68
}
// namespace xrpl
chrono
xrpl::LoanManageFixedPrecisionBase
Definition
LoanManageFixedPrecisionBase.h:22
xrpl::LoanManageFixedPrecisionBase::defaultAfterGrace
void defaultAfterGrace(test::jtx::Env &env, test::jtx::Account const &owner, Keylet const &loanKeylet)
Definition
LoanManageFixedPrecisionBase.h:57
xrpl::LoanManageFixedPrecisionBase::closePastDue
void closePastDue(test::jtx::Env &env, Keylet const &loanKeylet)
Definition
LoanManageFixedPrecisionBase.h:27
xrpl::LoanManageFixedPrecisionBase::closePastGrace
void closePastGrace(test::jtx::Env &env, Keylet const &loanKeylet)
Definition
LoanManageFixedPrecisionBase.h:37
xrpl::LoanManageFixedPrecisionBase::impairWhenLate
void impairWhenLate(test::jtx::Env &env, test::jtx::Account const &owner, Keylet const &loanKeylet)
Definition
LoanManageFixedPrecisionBase.h:49
xrpl::LoanPayFixedPrecisionBase
Definition
LoanPayFixedPrecisionBase.h:45
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::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::le
SLE::const_pointer le(Account const &account) const
Return an account root.
Definition
Env.cpp:311
cstdint
std::chrono::seconds
std::uint32_t
xrpl::test::jtx::loan::manage
json::Value manage(AccountID const &account, UInt256 const &loanID, std::uint32_t flags)
Definition
TestHelpers.cpp:797
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::Keylet
A pair of SHAMap key and LedgerEntryType.
Definition
Keylet.h:20
xrpl::Keylet::key
UInt256 key
Definition
Keylet.h:21
Generated by
1.17.0