2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/amount.h>
5#include <test/jtx/envconfig.h>
7#include <xrpld/core/Config.h>
9#include <xrpl/basics/base_uint.h>
10#include <xrpl/basics/strHex.h>
11#include <xrpl/beast/unit_test/suite.h>
12#include <xrpl/json/json_value.h>
13#include <xrpl/json/to_string.h>
14#include <xrpl/protocol/AccountID.h>
15#include <xrpl/protocol/Indexes.h>
16#include <xrpl/protocol/Issue.h>
17#include <xrpl/protocol/MPTIssue.h>
18#include <xrpl/protocol/SField.h>
19#include <xrpl/protocol/STIssue.h>
20#include <xrpl/protocol/Serializer.h>
21#include <xrpl/protocol/UintTypes.h>
22#include <xrpl/protocol/jss.h>
39 auto const usd = alice[
"USD"];
47 fail(
"Inconsistent XRP Issue doesn't fail");
59 fail(
"Inconsistent IOU Issue doesn't fail");
70 "00000000000000000000000055534400000000000000000000000000000000"
75 STIssue const stissue(iter, sfAsset);
76 fail(
"Inconsistent IOU Issue doesn't fail on serializer");
89 fail(
"XRP issue failed");
98 fail(
"USD issue failed");
104 "0000000000000000000000005553440000000000ae123a8556f3cf91154711"
105 "376afb0f894f832b3d";
109 STIssue const stissue(iter, sfAsset);
110 BEAST_EXPECT(stissue.
value() == usd);
114 fail(
"USD Issue fails on serializer");
119 auto const data =
"0000000000000000000000000000000000000000";
123 STIssue const stissue(iter, sfAsset);
128 fail(
"XRP Issue fails on serializer");
138 auto const usd = alice[
"USD"];
140 Asset const asset2{usd};
143 BEAST_EXPECT(
STIssue(sfAsset, asset1) != asset2);
144 BEAST_EXPECT(
STIssue(sfAsset, asset1) != asset3);
145 BEAST_EXPECT(
STIssue(sfAsset, asset1) == asset1);
146 BEAST_EXPECT(
STIssue(sfAsset, asset1).getText() ==
"XRP");
148 STIssue(sfAsset, asset2).getText() ==
"USD/rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn");
150 STIssue(sfAsset, asset3).getText() ==
151 "000000000000000000000000000000000000000000000002");
157 testcase(
"noAccount issuer rejected via RPC sign");
161 cfg->loadFromString(
"[signing_support]\ntrue");
170 txJson[jss::TransactionType] =
"AMMDelete";
171 txJson[jss::Account] = alice.
human();
172 txJson[jss::Asset][jss::currency] =
"USD";
174 txJson[jss::Asset2][jss::currency] =
"XRP";
177 req[jss::tx_json] = txJson;
178 req[jss::secret] = alice.
name();
180 auto const result = env.
rpc(
"json",
"sign",
to_string(req))[jss::result];
182 BEAST_EXPECT(result[jss::error] ==
"invalidParams");
183 BEAST_EXPECT(result[jss::error_message] ==
"Field 'tx_json.Asset' has invalid data.");
189 testcase(
"noAccount issuer rejection");
193 jv[jss::currency] =
"USD";
199 fail(
"issueFromJson accepted noAccount() as IOU issuer");
215 STIssue const stissue(iter, sfAsset);
217 "STIssue deserialization of [USD][noAccount()] should "
230 testcase(
"xrpAccount issuer rejected via RPC sign");
234 cfg->loadFromString(
"[signing_support]\ntrue");
243 txJson[jss::TransactionType] =
"AMMDelete";
244 txJson[jss::Account] = alice.
human();
245 txJson[jss::Asset][jss::currency] =
"USD";
247 txJson[jss::Asset2][jss::currency] =
"XRP";
250 req[jss::tx_json] = txJson;
251 req[jss::secret] = alice.
name();
253 auto const result = env.
rpc(
"json",
"sign",
to_string(req))[jss::result];
255 BEAST_EXPECT(result[jss::error] ==
"invalidParams");
256 BEAST_EXPECT(result[jss::error_message] ==
"Field 'tx_json.Asset' has invalid data.");
262 testcase(
"xrpAccount issuer rejection");
266 jv[jss::currency] =
"USD";
272 fail(
"issueFromJson accepted xrpAccount() as IOU issuer");
290 auto const sequences = std::to_array<std::uint32_t>({0x00000001, 0x01020304, 0xa1b2c3d4});
292 for (
auto const vector : sequences)
307 static_cast<unsigned char>(vector),
308 static_cast<unsigned char>(vector >> 8),
309 static_cast<unsigned char>(vector >> 16),
310 static_cast<unsigned char>(vector >> 24)};
318 STIssue const decoded(iter, sfAsset);
324 decoded.
add(roundTrip);
void pass()
Record a successful test condition.
void fail(String const &reason, char const *file, int line)
Record a failure.
TestcaseT testcase
Memberspace for declaring test cases.
constexpr TIss const & get() const
Integers of any length that is a multiple of 32-bits.
static constexpr std::size_t size()
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
A currency issued by an account.
constexpr MPTID const & getMptID() const
void add(Serializer &s) const override
value_type const & value() const noexcept
int addBitString(BaseUInt< Bits, Tag > const &v)
int addRaw(Blob const &vector)
Slice slice() const noexcept
An immutable linear range of bytes.
void testXrpAccountIssuer()
void testMPTSerialization()
void testNoAccountIssuerRpc()
void testNoAccountIssuer()
void testXrpAccountIssuerRpc()
void run() override
Runs the suite.
Immutable cryptographic account descriptor.
std::string const & human() const
Returns the human readable public key.
std::string const & name() const
Return the name.
AccountID id() const
Returns the Account ID.
A transaction testing environment.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
XrpT const XRP
Converts to XRP Issue or STAmount.
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
Issue issueFromJson(json::Value const &v)
std::string strHex(FwdIt begin, FwdIt end)
bool toCurrency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.
Currency const & xrpCurrency()
XRP currency.
std::string to_string(BaseUInt< Bits, Tag > const &a)
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
MPTID makeMptID(std::uint32_t const sequence, AccountID const &account)
AccountID const & noAccount()
A placeholder for empty accounts.
AccountID const & xrpAccount()
Compute AccountID from public key.