rippled
Loading...
Searching...
No Matches
STIssue_test.cpp
1#include <test/jtx.h>
2
3#include <xrpl/beast/unit_test.h>
4#include <xrpl/protocol/STIssue.h>
5
6namespace ripple {
7namespace test {
8
10{
11public:
12 void
14 {
15 testcase("Constructor");
16 using namespace jtx;
17 Account const alice{"alice"};
18 auto const USD = alice["USD"];
19 Issue issue;
20
21 try
22 {
23 issue = xrpIssue();
24 issue.account = alice;
25 STIssue stissue(sfAsset, Asset{issue});
26 fail("Inconsistent XRP Issue doesn't fail");
27 }
28 catch (...)
29 {
30 pass();
31 }
32
33 try
34 {
35 issue = USD;
36 issue.account = xrpAccount();
37 STIssue stissue(sfAsset, Asset{issue});
38 fail("Inconsistent IOU Issue doesn't fail");
39 }
40 catch (...)
41 {
42 pass();
43 }
44
45 try
46 {
47 // Currency is USD but account is XRP
48 auto const data =
49 "00000000000000000000000055534400000000000000000000000000000000"
50 "000000000000000000";
51 base_uint<320> uint;
52 (void)uint.parseHex(data);
53 SerialIter iter(Slice(uint.data(), uint.size()));
54 STIssue stissue(iter, sfAsset);
55 fail("Inconsistent IOU Issue doesn't fail on serializer");
56 }
57 catch (...)
58 {
59 pass();
60 }
61
62 try
63 {
64 STIssue stissue(sfAsset, Asset{xrpIssue()});
65 }
66 catch (...)
67 {
68 fail("XRP issue failed");
69 }
70
71 try
72 {
73 STIssue stissue(sfAsset, Asset{USD});
74 }
75 catch (...)
76 {
77 fail("USD issue failed");
78 }
79
80 try
81 {
82 auto const data =
83 "0000000000000000000000005553440000000000ae123a8556f3cf91154711"
84 "376afb0f894f832b3d";
85 base_uint<320> uint;
86 (void)uint.parseHex(data);
87 SerialIter iter(Slice(uint.data(), uint.size()));
88 STIssue stissue(iter, sfAsset);
89 BEAST_EXPECT(stissue.value() == USD);
90 }
91 catch (...)
92 {
93 fail("USD Issue fails on serializer");
94 }
95
96 try
97 {
98 auto const data = "0000000000000000000000000000000000000000";
99 base_uint<160> uint;
100 (void)uint.parseHex(data);
101 SerialIter iter(Slice(uint.data(), uint.size()));
102 STIssue stissue(iter, sfAsset);
103 BEAST_EXPECT(stissue.value() == xrpCurrency());
104 }
105 catch (...)
106 {
107 fail("XRP Issue fails on serializer");
108 }
109 }
110
111 void
113 {
114 testcase("Compare");
115 using namespace jtx;
116 Account const alice{"alice"};
117 auto const USD = alice["USD"];
118 Asset const asset1{xrpIssue()};
119 Asset const asset2{USD};
120 Asset const asset3{MPTID{2}};
121
122 BEAST_EXPECT(STIssue(sfAsset, asset1) != asset2);
123 BEAST_EXPECT(STIssue(sfAsset, asset1) != asset3);
124 BEAST_EXPECT(STIssue(sfAsset, asset1) == asset1);
125 BEAST_EXPECT(STIssue(sfAsset, asset1).getText() == "XRP");
126 BEAST_EXPECT(
127 STIssue(sfAsset, asset2).getText() ==
128 "USD/rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn");
129 BEAST_EXPECT(
130 STIssue(sfAsset, asset3).getText() ==
131 "000000000000000000000000000000000000000000000002");
132 }
133
134 void
135 run() override
136 {
137 // compliments other unit tests to ensure complete coverage
139 testCompare();
140 }
141};
142
143BEAST_DEFINE_TESTSUITE(STIssue, protocol, ripple);
144
145} // namespace test
146} // namespace ripple
A testsuite class.
Definition suite.h:52
void pass()
Record a successful test condition.
Definition suite.h:508
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:152
void fail(String const &reason, char const *file, int line)
Record a failure.
Definition suite.h:530
A currency issued by an account.
Definition Issue.h:14
AccountID account
Definition Issue.h:17
value_type const & value() const noexcept
Definition STIssue.h:114
An immutable linear range of bytes.
Definition Slice.h:27
Integers of any length that is a multiple of 32-bits.
Definition base_uint.h:67
static constexpr std::size_t size()
Definition base_uint.h:507
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition base_uint.h:484
void run() override
Runs the suite.
Immutable cryptographic account descriptor.
Definition Account.h:20
auto const data
General field definitions, or fields used in multiple transaction namespaces.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
Definition Issue.h:96
AccountID const & xrpAccount()
Compute AccountID from public key.
Currency const & xrpCurrency()
XRP currency.