mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add MPTIssue to STIssue (#5200)
Replace Issue in STIssue with Asset. STIssue with MPTIssue is only used in MPT tests. Will be used in Vault and in transactions with STIssue fields once MPT is integrated into DEX.
This commit is contained in:
committed by
GitHub
parent
eabca8439f
commit
5cd72f2431
@@ -1470,19 +1470,19 @@ class MPToken_test : public beast::unit_test::suite
|
||||
void
|
||||
testMPTInvalidInTx(FeatureBitset features)
|
||||
{
|
||||
testcase("MPT Amount Invalid in Transaction");
|
||||
testcase("MPT Issue Invalid in Transaction");
|
||||
using namespace test::jtx;
|
||||
|
||||
// Validate that every transaction with an amount field,
|
||||
// Validate that every transaction with an amount/issue field,
|
||||
// which doesn't support MPT, fails.
|
||||
|
||||
// keyed by transaction + amount field
|
||||
// keyed by transaction + amount/issue field
|
||||
std::set<std::string> txWithAmounts;
|
||||
for (auto const& format : TxFormats::getInstance())
|
||||
{
|
||||
for (auto const& e : format.getSOTemplate())
|
||||
{
|
||||
// Transaction has amount fields.
|
||||
// Transaction has amount/issue fields.
|
||||
// Exclude pseudo-transaction SetFee. Don't consider
|
||||
// the Fee field since it's included in every transaction.
|
||||
if (e.supportMPT() == soeMPTNotSupported &&
|
||||
@@ -1508,9 +1508,9 @@ class MPToken_test : public beast::unit_test::suite
|
||||
env.fund(XRP(1'000), alice);
|
||||
env.fund(XRP(1'000), carol);
|
||||
auto test = [&](Json::Value const& jv,
|
||||
std::string const& amtField) {
|
||||
std::string const& mptField) {
|
||||
txWithAmounts.erase(
|
||||
jv[jss::TransactionType].asString() + amtField);
|
||||
jv[jss::TransactionType].asString() + mptField);
|
||||
|
||||
// tx is signed
|
||||
auto jtx = env.jt(jv);
|
||||
@@ -1530,8 +1530,27 @@ class MPToken_test : public beast::unit_test::suite
|
||||
jrr = env.rpc("json", "sign", to_string(jv1));
|
||||
BEAST_EXPECT(jrr[jss::result][jss::error] == "invalidParams");
|
||||
};
|
||||
// All transactions with sfAmount, which don't support MPT
|
||||
// and transactions with amount fields, which can't be MPT
|
||||
auto toSFieldRef = [](SField const& field) {
|
||||
return std::ref(field);
|
||||
};
|
||||
auto setMPTFields = [&](SField const& field,
|
||||
Json::Value& jv,
|
||||
bool withAmount = true) {
|
||||
jv[jss::Asset] = to_json(xrpIssue());
|
||||
jv[jss::Asset2] = to_json(USD.issue());
|
||||
if (withAmount)
|
||||
jv[field.fieldName] =
|
||||
USD(10).value().getJson(JsonOptions::none);
|
||||
if (field == sfAsset)
|
||||
jv[jss::Asset] = to_json(mpt.get<MPTIssue>());
|
||||
else if (field == sfAsset2)
|
||||
jv[jss::Asset2] = to_json(mpt.get<MPTIssue>());
|
||||
else
|
||||
jv[field.fieldName] = mpt.getJson(JsonOptions::none);
|
||||
};
|
||||
// All transactions with sfAmount, which don't support MPT.
|
||||
// Transactions with amount fields, which can't be MPT.
|
||||
// Transactions with issue fields, which can't be MPT.
|
||||
|
||||
// AMMCreate
|
||||
auto ammCreate = [&](SField const& field) {
|
||||
@@ -1554,58 +1573,84 @@ class MPToken_test : public beast::unit_test::suite
|
||||
Json::Value jv;
|
||||
jv[jss::TransactionType] = jss::AMMDeposit;
|
||||
jv[jss::Account] = alice.human();
|
||||
jv[jss::Asset] = to_json(xrpIssue());
|
||||
jv[jss::Asset2] = to_json(USD.issue());
|
||||
jv[field.fieldName] = mpt.getJson(JsonOptions::none);
|
||||
jv[jss::Flags] = tfSingleAsset;
|
||||
setMPTFields(field, jv);
|
||||
test(jv, field.fieldName);
|
||||
};
|
||||
for (SField const& field :
|
||||
{std::ref(sfAmount),
|
||||
std::ref(sfAmount2),
|
||||
std::ref(sfEPrice),
|
||||
std::ref(sfLPTokenOut)})
|
||||
{toSFieldRef(sfAmount),
|
||||
toSFieldRef(sfAmount2),
|
||||
toSFieldRef(sfEPrice),
|
||||
toSFieldRef(sfLPTokenOut),
|
||||
toSFieldRef(sfAsset),
|
||||
toSFieldRef(sfAsset2)})
|
||||
ammDeposit(field);
|
||||
// AMMWithdraw
|
||||
auto ammWithdraw = [&](SField const& field) {
|
||||
Json::Value jv;
|
||||
jv[jss::TransactionType] = jss::AMMWithdraw;
|
||||
jv[jss::Account] = alice.human();
|
||||
jv[jss::Asset] = to_json(xrpIssue());
|
||||
jv[jss::Asset2] = to_json(USD.issue());
|
||||
jv[jss::Flags] = tfSingleAsset;
|
||||
jv[field.fieldName] = mpt.getJson(JsonOptions::none);
|
||||
setMPTFields(field, jv);
|
||||
test(jv, field.fieldName);
|
||||
};
|
||||
ammWithdraw(sfAmount);
|
||||
for (SField const& field :
|
||||
{std::ref(sfAmount2),
|
||||
std::ref(sfEPrice),
|
||||
std::ref(sfLPTokenIn)})
|
||||
{toSFieldRef(sfAmount2),
|
||||
toSFieldRef(sfEPrice),
|
||||
toSFieldRef(sfLPTokenIn),
|
||||
toSFieldRef(sfAsset),
|
||||
toSFieldRef(sfAsset2)})
|
||||
ammWithdraw(field);
|
||||
// AMMBid
|
||||
auto ammBid = [&](SField const& field) {
|
||||
Json::Value jv;
|
||||
jv[jss::TransactionType] = jss::AMMBid;
|
||||
jv[jss::Account] = alice.human();
|
||||
jv[jss::Asset] = to_json(xrpIssue());
|
||||
jv[jss::Asset2] = to_json(USD.issue());
|
||||
jv[field.fieldName] = mpt.getJson(JsonOptions::none);
|
||||
setMPTFields(field, jv);
|
||||
test(jv, field.fieldName);
|
||||
};
|
||||
ammBid(sfBidMin);
|
||||
ammBid(sfBidMax);
|
||||
for (SField const& field :
|
||||
{toSFieldRef(sfBidMin),
|
||||
toSFieldRef(sfBidMax),
|
||||
toSFieldRef(sfAsset),
|
||||
toSFieldRef(sfAsset2)})
|
||||
ammBid(field);
|
||||
// AMMClawback
|
||||
{
|
||||
auto ammClawback = [&](SField const& field) {
|
||||
Json::Value jv;
|
||||
jv[jss::TransactionType] = jss::AMMClawback;
|
||||
jv[jss::Account] = alice.human();
|
||||
jv[jss::Holder] = carol.human();
|
||||
jv[jss::Asset] = to_json(xrpIssue());
|
||||
jv[jss::Asset2] = to_json(USD.issue());
|
||||
jv[jss::Amount] = mpt.getJson(JsonOptions::none);
|
||||
test(jv, jss::Amount.c_str());
|
||||
}
|
||||
setMPTFields(field, jv);
|
||||
test(jv, field.fieldName);
|
||||
};
|
||||
for (SField const& field :
|
||||
{toSFieldRef(sfAmount),
|
||||
toSFieldRef(sfAsset),
|
||||
toSFieldRef(sfAsset2)})
|
||||
ammClawback(field);
|
||||
// AMMDelete
|
||||
auto ammDelete = [&](SField const& field) {
|
||||
Json::Value jv;
|
||||
jv[jss::TransactionType] = jss::AMMDelete;
|
||||
jv[jss::Account] = alice.human();
|
||||
setMPTFields(field, jv, false);
|
||||
test(jv, field.fieldName);
|
||||
};
|
||||
ammDelete(sfAsset);
|
||||
ammDelete(sfAsset2);
|
||||
// AMMVote
|
||||
auto ammVote = [&](SField const& field) {
|
||||
Json::Value jv;
|
||||
jv[jss::TransactionType] = jss::AMMVote;
|
||||
jv[jss::Account] = alice.human();
|
||||
jv[jss::TradingFee] = 100;
|
||||
setMPTFields(field, jv, false);
|
||||
test(jv, field.fieldName);
|
||||
};
|
||||
ammVote(sfAsset);
|
||||
ammVote(sfAsset2);
|
||||
// CheckCash
|
||||
auto checkCash = [&](SField const& field) {
|
||||
Json::Value jv;
|
||||
|
||||
164
src/test/protocol/STIssue_test.cpp
Normal file
164
src/test/protocol/STIssue_test.cpp
Normal file
@@ -0,0 +1,164 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2024 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx.h>
|
||||
#include <xrpl/beast/unit_test.h>
|
||||
#include <xrpl/protocol/STIssue.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
|
||||
class STIssue_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void
|
||||
testConstructor()
|
||||
{
|
||||
testcase("Constructor");
|
||||
using namespace jtx;
|
||||
Account const alice{"alice"};
|
||||
auto const USD = alice["USD"];
|
||||
Issue issue;
|
||||
|
||||
try
|
||||
{
|
||||
issue = xrpIssue();
|
||||
issue.account = alice;
|
||||
STIssue stissue(sfAsset, Asset{issue});
|
||||
fail("Inconsistent XRP Issue doesn't fail");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
pass();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
issue = USD;
|
||||
issue.account = xrpAccount();
|
||||
STIssue stissue(sfAsset, Asset{issue});
|
||||
fail("Inconsistent IOU Issue doesn't fail");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
pass();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Currency is USD but account is XRP
|
||||
auto const data =
|
||||
"00000000000000000000000055534400000000000000000000000000000000"
|
||||
"000000000000000000";
|
||||
base_uint<320> uint;
|
||||
(void)uint.parseHex(data);
|
||||
SerialIter iter(Slice(uint.data(), uint.size()));
|
||||
STIssue stissue(iter, sfAsset);
|
||||
fail("Inconsistent IOU Issue doesn't fail on serializer");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
pass();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
STIssue stissue(sfAsset, Asset{xrpIssue()});
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
fail("XRP issue failed");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
STIssue stissue(sfAsset, Asset{USD});
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
fail("USD issue failed");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
auto const data =
|
||||
"0000000000000000000000005553440000000000ae123a8556f3cf91154711"
|
||||
"376afb0f894f832b3d";
|
||||
base_uint<320> uint;
|
||||
(void)uint.parseHex(data);
|
||||
SerialIter iter(Slice(uint.data(), uint.size()));
|
||||
STIssue stissue(iter, sfAsset);
|
||||
BEAST_EXPECT(stissue.value() == USD);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
fail("USD Issue fails on serializer");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
auto const data = "0000000000000000000000000000000000000000";
|
||||
base_uint<160> uint;
|
||||
(void)uint.parseHex(data);
|
||||
SerialIter iter(Slice(uint.data(), uint.size()));
|
||||
STIssue stissue(iter, sfAsset);
|
||||
BEAST_EXPECT(stissue.value() == xrpCurrency());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
fail("XRP Issue fails on serializer");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testCompare()
|
||||
{
|
||||
testcase("Compare");
|
||||
using namespace jtx;
|
||||
Account const alice{"alice"};
|
||||
auto const USD = alice["USD"];
|
||||
Asset const asset1{xrpIssue()};
|
||||
Asset const asset2{USD};
|
||||
Asset const asset3{MPTID{2}};
|
||||
|
||||
BEAST_EXPECT(STIssue(sfAsset, asset1) != asset2);
|
||||
BEAST_EXPECT(STIssue(sfAsset, asset1) != asset3);
|
||||
BEAST_EXPECT(STIssue(sfAsset, asset1) == asset1);
|
||||
BEAST_EXPECT(STIssue(sfAsset, asset1).getText() == "XRP");
|
||||
BEAST_EXPECT(
|
||||
STIssue(sfAsset, asset2).getText() ==
|
||||
"USD/rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn");
|
||||
BEAST_EXPECT(
|
||||
STIssue(sfAsset, asset3).getText() ==
|
||||
"000000000000000000000000000000000000000000000002");
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
// compliments other unit tests to ensure complete coverage
|
||||
testConstructor();
|
||||
testCompare();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(STIssue, ripple_data, ripple);
|
||||
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
Reference in New Issue
Block a user