mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
test: Add tests to raise coverage of AMM (#4971)
--------- Co-authored-by: Howard Hinnant <howard.hinnant@gmail.com> Co-authored-by: Mark Travis <mtravis@ripple.com> Co-authored-by: Bronek Kozicki <brok@incorrekt.com> Co-authored-by: Mayukha Vadari <mvadari@gmail.com> Co-authored-by: Chenna Keshava <ckeshavabs@gmail.com>
This commit is contained in:
@@ -656,16 +656,8 @@ AMM::vote(VoteArg const& arg)
|
||||
return vote(arg.account, arg.tfee, arg.flags, arg.seq, arg.assets, arg.err);
|
||||
}
|
||||
|
||||
void
|
||||
AMM::bid(
|
||||
std::optional<Account> const& account,
|
||||
std::optional<std::variant<int, IOUAmount, STAmount>> const& bidMin,
|
||||
std::optional<std::variant<int, IOUAmount, STAmount>> const& bidMax,
|
||||
std::vector<Account> const& authAccounts,
|
||||
std::optional<std::uint32_t> const& flags,
|
||||
std::optional<jtx::seq> const& seq,
|
||||
std::optional<std::pair<Issue, Issue>> const& assets,
|
||||
std::optional<ter> const& ter)
|
||||
Json::Value
|
||||
AMM::bid(BidArg const& arg)
|
||||
{
|
||||
if (auto const amm =
|
||||
env_.current()->read(keylet::amm(asset1_.issue(), asset2_.issue())))
|
||||
@@ -684,8 +676,9 @@ AMM::bid(
|
||||
bidMax_ = std::nullopt;
|
||||
|
||||
Json::Value jv;
|
||||
jv[jss::Account] = account ? account->human() : creatorAccount_.human();
|
||||
setTokens(jv, assets);
|
||||
jv[jss::Account] =
|
||||
arg.account ? arg.account->human() : creatorAccount_.human();
|
||||
setTokens(jv, arg.assets);
|
||||
auto getBid = [&](auto const& bid) {
|
||||
if (std::holds_alternative<int>(bid))
|
||||
return STAmount{lptIssue_, std::get<int>(bid)};
|
||||
@@ -694,22 +687,22 @@ AMM::bid(
|
||||
else
|
||||
return std::get<STAmount>(bid);
|
||||
};
|
||||
if (bidMin)
|
||||
if (arg.bidMin)
|
||||
{
|
||||
STAmount saTokens = getBid(*bidMin);
|
||||
STAmount saTokens = getBid(*arg.bidMin);
|
||||
saTokens.setJson(jv[jss::BidMin]);
|
||||
bidMin_ = saTokens.iou();
|
||||
}
|
||||
if (bidMax)
|
||||
if (arg.bidMax)
|
||||
{
|
||||
STAmount saTokens = getBid(*bidMax);
|
||||
STAmount saTokens = getBid(*arg.bidMax);
|
||||
saTokens.setJson(jv[jss::BidMax]);
|
||||
bidMax_ = saTokens.iou();
|
||||
}
|
||||
if (authAccounts.size() > 0)
|
||||
if (arg.authAccounts.size() > 0)
|
||||
{
|
||||
Json::Value accounts(Json::arrayValue);
|
||||
for (auto const& account : authAccounts)
|
||||
for (auto const& account : arg.authAccounts)
|
||||
{
|
||||
Json::Value acct;
|
||||
Json::Value authAcct;
|
||||
@@ -719,26 +712,12 @@ AMM::bid(
|
||||
}
|
||||
jv[jss::AuthAccounts] = accounts;
|
||||
}
|
||||
if (flags)
|
||||
jv[jss::Flags] = *flags;
|
||||
if (arg.flags)
|
||||
jv[jss::Flags] = *arg.flags;
|
||||
jv[jss::TransactionType] = jss::AMMBid;
|
||||
if (fee_ != 0)
|
||||
jv[jss::Fee] = std::to_string(fee_);
|
||||
submit(jv, seq, ter);
|
||||
}
|
||||
|
||||
void
|
||||
AMM::bid(BidArg const& arg)
|
||||
{
|
||||
return bid(
|
||||
arg.account,
|
||||
arg.bidMin,
|
||||
arg.bidMax,
|
||||
arg.authAccounts,
|
||||
arg.flags,
|
||||
arg.seq,
|
||||
arg.assets,
|
||||
arg.err);
|
||||
return jv;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -472,6 +472,32 @@ Env::st(JTx const& jt)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<STTx const>
|
||||
Env::ust(JTx const& jt)
|
||||
{
|
||||
// The parse must succeed, since we
|
||||
// generated the JSON ourselves.
|
||||
std::optional<STObject> obj;
|
||||
try
|
||||
{
|
||||
obj = jtx::parse(jt.jv);
|
||||
}
|
||||
catch (jtx::parse_error const&)
|
||||
{
|
||||
test.log << "Exception: parse_error\n" << pretty(jt.jv) << std::endl;
|
||||
Rethrow();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return std::make_shared<STTx const>(std::move(*obj));
|
||||
}
|
||||
catch (std::exception const&)
|
||||
{
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Json::Value
|
||||
Env::do_rpc(
|
||||
unsigned apiVersion,
|
||||
|
||||
Reference in New Issue
Block a user