xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
app
DeliverMin_test.cpp
1
2
#include <test/jtx/Account.h>
3
#include <test/jtx/Env.h>
4
#include <test/jtx/amount.h>
5
#include <test/jtx/balance.h>
6
#include <test/jtx/delivermin.h>
7
#include <test/jtx/offer.h>
8
#include <test/jtx/paths.h>
9
#include <test/jtx/pay.h>
10
#include <test/jtx/sendmax.h>
11
#include <test/jtx/ter.h>
12
#include <test/jtx/txflags.h>
13
14
#include <xrpl/beast/unit_test/suite.h>
15
#include <xrpl/protocol/Feature.h>
16
#include <xrpl/protocol/TER.h>
17
#include <xrpl/protocol/TxFlags.h>
18
19
namespace
xrpl::test
{
20
21
class
DeliverMin_test
:
public
beast::unit_test::Suite
22
{
23
public
:
24
void
25
testConvertAllOfAnAsset
(
FeatureBitset
features)
26
{
27
testcase
(
"Convert all of an asset using DeliverMin"
);
28
29
using namespace
jtx
;
30
auto
const
gw =
Account
(
"gateway"
);
31
auto
const
usd = gw[
"USD"
];
32
33
{
34
Env
env(*
this
, features);
35
env.
fund
(
XRP
(10000),
"alice"
,
"bob"
,
"carol"
, gw);
36
env.
close
();
37
env.
trust
(usd(100),
"alice"
,
"bob"
,
"carol"
);
38
env.
close
();
39
env(
pay
(
"alice"
,
"bob"
, usd(10)),
DeliverMin
(usd(10)),
Ter
(
temBAD_AMOUNT
));
40
env(
pay
(
"alice"
,
"bob"
, usd(10)),
41
DeliverMin
(usd(-5)),
42
Txflags
(tfPartialPayment),
43
Ter
(
temBAD_AMOUNT
));
44
env(
pay
(
"alice"
,
"bob"
, usd(10)),
45
DeliverMin
(
XRP
(5)),
46
Txflags
(tfPartialPayment),
47
Ter
(
temBAD_AMOUNT
));
48
env(
pay
(
"alice"
,
"bob"
, usd(10)),
49
DeliverMin
(
Account
(
"carol"
)[
"USD"
](5)),
50
Txflags
(tfPartialPayment),
51
Ter
(
temBAD_AMOUNT
));
52
env(
pay
(
"alice"
,
"bob"
, usd(10)),
53
DeliverMin
(usd(15)),
54
Txflags
(tfPartialPayment),
55
Ter
(
temBAD_AMOUNT
));
56
env(
pay
(gw,
"carol"
, usd(50)));
57
env(
offer
(
"carol"
,
XRP
(5), usd(5)));
58
env(
pay
(
"alice"
,
"bob"
, usd(10)),
59
Paths
(
XRP
),
60
DeliverMin
(usd(7)),
61
Txflags
(tfPartialPayment),
62
Sendmax
(
XRP
(5)),
63
Ter
(
tecPATH_PARTIAL
));
64
env.
require
(
Balance
(
"alice"
,
XRP
(10000) -
drops
(env.
current
()->fees().base)));
65
env.
require
(
Balance
(
"bob"
,
XRP
(10000)));
66
}
67
68
{
69
Env
env(*
this
, features);
70
env.
fund
(
XRP
(10000),
"alice"
,
"bob"
, gw);
71
env.
close
();
72
env.
trust
(usd(1000),
"alice"
,
"bob"
);
73
env.
close
();
74
env(
pay
(gw,
"bob"
, usd(100)));
75
env(
offer
(
"bob"
,
XRP
(100), usd(100)));
76
env(
pay
(
"alice"
,
"alice"
, usd(10000)),
77
Paths
(
XRP
),
78
DeliverMin
(usd(100)),
79
Txflags
(tfPartialPayment),
80
Sendmax
(
XRP
(100)));
81
env.
require
(
Balance
(
"alice"
, usd(100)));
82
}
83
84
{
85
Env
env(*
this
, features);
86
env.
fund
(
XRP
(10000),
"alice"
,
"bob"
,
"carol"
, gw);
87
env.
close
();
88
env.
trust
(usd(1000),
"bob"
,
"carol"
);
89
env.
close
();
90
env(
pay
(gw,
"bob"
, usd(200)));
91
env(
offer
(
"bob"
,
XRP
(100), usd(100)));
92
env(
offer
(
"bob"
,
XRP
(1000), usd(100)));
93
env(
offer
(
"bob"
,
XRP
(10000), usd(100)));
94
env(
pay
(
"alice"
,
"carol"
, usd(10000)),
95
Paths
(
XRP
),
96
DeliverMin
(usd(200)),
97
Txflags
(tfPartialPayment),
98
Sendmax
(
XRP
(1000)),
99
Ter
(
tecPATH_PARTIAL
));
100
env(
pay
(
"alice"
,
"carol"
, usd(10000)),
101
Paths
(
XRP
),
102
DeliverMin
(usd(200)),
103
Txflags
(tfPartialPayment),
104
Sendmax
(
XRP
(1100)));
105
env.
require
(
Balance
(
"bob"
, usd(0)));
106
env.
require
(
Balance
(
"carol"
, usd(200)));
107
}
108
109
{
110
Env
env(*
this
, features);
111
env.
fund
(
XRP
(10000),
"alice"
,
"bob"
,
"carol"
,
"dan"
, gw);
112
env.
close
();
113
env.
trust
(usd(1000),
"bob"
,
"carol"
,
"dan"
);
114
env.
close
();
115
env(
pay
(gw,
"bob"
, usd(100)));
116
env(
pay
(gw,
"dan"
, usd(100)));
117
env(
offer
(
"bob"
,
XRP
(100), usd(100)));
118
env(
offer
(
"bob"
,
XRP
(1000), usd(100)));
119
env(
offer
(
"dan"
,
XRP
(100), usd(100)));
120
env(
pay
(
"alice"
,
"carol"
, usd(10000)),
121
Paths
(
XRP
),
122
DeliverMin
(usd(200)),
123
Txflags
(tfPartialPayment),
124
Sendmax
(
XRP
(200)));
125
env.
require
(
Balance
(
"bob"
, usd(0)));
126
env.
require
(
Balance
(
"carol"
, usd(200)));
127
env.
require
(
Balance
(
"dan"
, usd(0)));
128
}
129
}
130
131
void
132
run
()
override
133
{
134
using namespace
jtx
;
135
auto
const
sa =
testableAmendments
();
136
testConvertAllOfAnAsset
(sa - featurePermissionedDEX);
137
testConvertAllOfAnAsset
(sa);
138
}
139
};
140
141
BEAST_DEFINE_TESTSUITE
(
DeliverMin
, app,
xrpl
);
142
143
}
// namespace xrpl::test
beast::unit_test::Suite
A testsuite class.
Definition
suite.h:52
beast::unit_test::Suite::testcase
TestcaseT testcase
Memberspace for declaring test cases.
Definition
suite.h:155
xrpl::FeatureBitset
Definition
Feature.h:196
xrpl::test::DeliverMin_test
Definition
DeliverMin_test.cpp:22
xrpl::test::DeliverMin_test::testConvertAllOfAnAsset
void testConvertAllOfAnAsset(FeatureBitset features)
Definition
DeliverMin_test.cpp:25
xrpl::test::DeliverMin_test::run
void run() override
Runs the suite.
Definition
DeliverMin_test.cpp:132
xrpl::test::jtx::DeliverMin
Sets the DeliverMin on a JTx.
Definition
delivermin.h:16
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::fund
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition
Env.cpp:323
xrpl::test::jtx::Env::trust
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
Definition
Env.cpp:354
xrpl::test::jtx::Env::require
void require(Args const &... args)
Check a set of requirements.
Definition
Env.h:766
xrpl::test::jtx::Env::current
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition
Env.h:377
xrpl::test::jtx::Paths
Set Paths, SendMax on a JTx.
Definition
paths.h:23
xrpl::test::jtx::Sendmax
Sets the SendMax on a JTx.
Definition
sendmax.h:16
xrpl::test::jtx::Ter
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition
ter.h:18
xrpl::test::jtx::Txflags
Set the flags on a JTx.
Definition
txflags.h:14
xrpl::test::jtx
Definition
Oracle_test.cpp:34
xrpl::test::jtx::pay
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition
pay.cpp:14
xrpl::test::jtx::XRP
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition
amount.cpp:92
xrpl::test::jtx::testableAmendments
FeatureBitset testableAmendments()
Definition
Env.h:92
xrpl::test::jtx::offer
json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
Definition
offer.cpp:14
xrpl::test::jtx::drops
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
Definition
src/test/jtx/amount.h:361
xrpl::test
Definition
STLedgerEntry.h:21
xrpl::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::temBAD_AMOUNT
@ temBAD_AMOUNT
Definition
TER.h:77
xrpl::tecPATH_PARTIAL
@ tecPATH_PARTIAL
Definition
TER.h:290
xrpl::FeePayerType::Account
@ Account
Definition
Transactor.h:145
xrpl::test::Balance
Definition
XChain_test.cpp:243
Generated by
1.17.0