xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
tests
libxrpl
ledger
tests/libxrpl/ledger/TokenHelpers.cpp
1
#include <xrpl/ledger/helpers/TokenHelpers.h>
2
3
#include <xrpl/protocol/AccountID.h>
4
#include <xrpl/protocol/Indexes.h>
5
#include <xrpl/protocol/Issue.h>
6
#include <xrpl/protocol/MPTIssue.h>
7
#include <xrpl/protocol/Rate.h>
8
#include <xrpl/protocol/STAmount.h>
9
#include <xrpl/protocol/UintTypes.h>
10
11
#include <gtest/gtest.h>
12
13
using namespace
xrpl
;
14
15
namespace
{
16
17
// A 25% transfer fee.
18
Rate
const
kRate125{1'250'000'000};
19
20
AccountID
const
kIssuer{1};
21
22
}
// namespace
23
24
TEST
(TokenHelpers, add_transfer_fee)
25
{
26
Issue
const
usd{
toCurrency
(
"USD"
), kIssuer};
27
MPTIssue
const
mpt{
makeMptID
(1, kIssuer)};
28
29
EXPECT_EQ(
addTransferFee
(
STAmount
{usd, 80}, kRate125),
STAmount
(usd, 100));
30
EXPECT_EQ(
addTransferFee
(
STAmount
{usd, 80},
kParityRate
),
STAmount
(usd, 80));
31
32
// Integral MPT: the fee on 1 unit rounds up to a whole unit.
33
EXPECT_EQ(
addTransferFee
(
STAmount
{mpt, 80}, kRate125),
STAmount
(mpt, 100));
34
EXPECT_EQ(
addTransferFee
(
STAmount
{mpt, 1}, kRate125),
STAmount
(mpt, 2));
35
EXPECT_EQ(
addTransferFee
(
STAmount
{mpt, 1},
kParityRate
),
STAmount
(mpt, 1));
36
}
37
38
TEST
(TokenHelpers, subtract_transfer_fee)
39
{
40
Issue
const
usd{
toCurrency
(
"USD"
), kIssuer};
41
MPTIssue
const
mpt{
makeMptID
(1, kIssuer)};
42
43
EXPECT_EQ(
subtractTransferFee
(
STAmount
{usd, 100}, kRate125),
STAmount
(usd, 80));
44
EXPECT_EQ(
subtractTransferFee
(
STAmount
{usd, 100},
kParityRate
),
STAmount
(usd, 100));
45
46
// Integral MPT: the payout rounds down, to zero for a single unit.
47
EXPECT_EQ(
subtractTransferFee
(
STAmount
{mpt, 31}, kRate125),
STAmount
(mpt, 24));
48
EXPECT_EQ(
subtractTransferFee
(
STAmount
{mpt, 1}, kRate125),
STAmount
(mpt));
49
EXPECT_EQ(
subtractTransferFee
(
STAmount
{mpt, 1},
kParityRate
),
STAmount
(mpt, 1));
50
}
xrpl::Issue
A currency issued by an account.
Definition
Issue.h:18
xrpl::MPTIssue
Definition
MPTIssue.h:23
xrpl::STAmount
Definition
STAmount.h:46
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::subtractTransferFee
STAmount subtractTransferFee(STAmount const &amount, Rate const &rate)
Returns the amount a receiver gets when amount leaves the sender and the issuer takes the transfer fe...
Definition
libxrpl/ledger/helpers/TokenHelpers.cpp:564
xrpl::TEST
TEST(FileUtilitiesTest, get_file_contents)
Definition
tests/libxrpl/basics/FileUtilities.cpp:60
xrpl::toCurrency
bool toCurrency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.
Definition
UintTypes.cpp:65
xrpl::kParityRate
Rate const kParityRate
A transfer rate signifying a 1:1 exchange.
xrpl::makeMptID
MPTID makeMptID(std::uint32_t const sequence, AccountID const &account)
Definition
Indexes.cpp:219
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
xrpl::addTransferFee
STAmount addTransferFee(STAmount const &amount, Rate const &rate)
Returns the amount a sender must part with for amount to reach the receiver once the issuer takes the...
Definition
libxrpl/ledger/helpers/TokenHelpers.cpp:556
xrpl::Rate
Represents a transfer rate.
Definition
Rate.h:21
Generated by
1.17.0