mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-29 01:50:43 +00:00
Merge pull request #7765 from Kassaking7/codecov-test
fix: sponsor test coverage
This commit is contained in:
@@ -64,11 +64,13 @@ confineOwnerCount(
|
||||
// Overflow is well defined on unsigned
|
||||
if (totalOwnerCount < currentOwnerCount)
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
if (id)
|
||||
{
|
||||
JLOG(j.fatal()) << "Account " << *id << " owner count exceeds max!";
|
||||
}
|
||||
totalOwnerCount = std::numeric_limits<std::uint32_t>::max();
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -99,8 +101,10 @@ accountCountImpl(SLE::const_ref sle, std::int32_t accountCountAdj, beast::Journa
|
||||
std::int64_t totalAccountCount{currentAccountCount + accountCountAdj};
|
||||
if (totalAccountCount > std::numeric_limits<std::uint32_t>::max())
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
JLOG(j.fatal()) << "Reserve count exceeds max!";
|
||||
totalAccountCount = std::numeric_limits<std::uint32_t>::max();
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
else if (totalAccountCount < 0)
|
||||
{
|
||||
@@ -215,19 +219,23 @@ ownerCount(SLE::const_ref sle, beast::Journal j, std::int32_t ownerCountAdj)
|
||||
|
||||
if (deltaCount > std::numeric_limits<std::int32_t>::max())
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
deltaCount = std::numeric_limits<std::int32_t>::max();
|
||||
JLOG(j.fatal()) << "Account " << id << " delta count exceeds max, "
|
||||
<< "adjustment: " << ownerCountAdj
|
||||
<< ", sponsoredCount: " << sponsoredOwnerCount
|
||||
<< ", sponsoringOwnerCount: " << sponsoringOwnerCount;
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
else if (deltaCount < std::numeric_limits<std::int32_t>::min())
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
deltaCount = std::numeric_limits<std::int32_t>::min();
|
||||
JLOG(j.fatal()) << "Account " << id << " delta count is below min, "
|
||||
<< "adjustment: " << ownerCountAdj
|
||||
<< ", sponsoredCount: " << sponsoredOwnerCount
|
||||
<< ", sponsoringCount: " << sponsoringOwnerCount;
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
|
||||
return confineOwnerCount(currentOwnerCount, deltaCount);
|
||||
|
||||
@@ -726,9 +726,11 @@ repairNFTokenDirectoryLinks(ApplyView& view, AccountID const& owner)
|
||||
auto const newPrev = view.peek(Keylet(ltNFTOKEN_PAGE, *prevLink));
|
||||
if (!newPrev)
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
Throw<std::runtime_error>(
|
||||
"NFTokenPage directory for " + to_string(owner) +
|
||||
" cannot be repaired. Unexpected link problem.");
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
newPrev->at(sfNextPageMin) = nextPage->key();
|
||||
view.update(newPrev);
|
||||
|
||||
@@ -174,8 +174,10 @@ getLedgerEntryOwner(ReadView const& view, SLE const& sle, AccountID const& accou
|
||||
return std::nullopt;
|
||||
}
|
||||
default:
|
||||
// LCOV_EXCL_START
|
||||
UNREACHABLE("xrpl::getLedgerEntryOwner : object is not supported by sponsorship.");
|
||||
return std::nullopt;
|
||||
// LCOV_EXCL_STOP
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ EscrowFinish::preclaim(PreclaimContext const& ctx)
|
||||
|
||||
auto const sponsorSle = getTxReserveSponsor(ctx.view, ctx.tx);
|
||||
if (!sponsorSle)
|
||||
return sponsorSle.error();
|
||||
return sponsorSle.error(); // LCOV_EXCL_LINE
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
@@ -509,9 +509,11 @@ Payment::doApply()
|
||||
sponsor->getFieldU32(sfSponsoringAccountCount);
|
||||
if (currentSponsoringAccountCount == std::numeric_limits<std::uint32_t>::max())
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
JLOG(j_.fatal()) << "Sponsoring account count overflow for account "
|
||||
<< to_string(accountID_);
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
return tecINTERNAL;
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
sponsor->setFieldU32(sfSponsoringAccountCount, currentSponsoringAccountCount + 1);
|
||||
|
||||
|
||||
@@ -359,7 +359,7 @@ SponsorshipTransfer::doApply()
|
||||
if (auto const ter = incrementSponsorCount(
|
||||
view(), ownerSle, sfSponsoredOwnerCount, ownerCountDelta);
|
||||
!isTesSuccess(ter))
|
||||
return ter;
|
||||
return ter; // LCOV_EXCL_LINE
|
||||
}
|
||||
else if (isReassign)
|
||||
{
|
||||
@@ -374,14 +374,14 @@ SponsorshipTransfer::doApply()
|
||||
if (auto const ter = decrementSponsorCount(
|
||||
view(), oldSponsorSle, sfSponsoringOwnerCount, ownerCountDelta);
|
||||
!isTesSuccess(ter))
|
||||
return ter;
|
||||
return ter; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
// Increment new sponsor's sponsoring count
|
||||
if (auto const ter = incrementSponsorCount(
|
||||
view(), newSponsorSle, sfSponsoringOwnerCount, ownerCountDelta);
|
||||
!isTesSuccess(ter))
|
||||
return ter;
|
||||
return ter; // LCOV_EXCL_LINE
|
||||
|
||||
// Object is now sponsored by new sponsor
|
||||
objectSle->setAccountID(sponsorField, newSponsorID);
|
||||
@@ -394,7 +394,7 @@ SponsorshipTransfer::doApply()
|
||||
if (auto const ter =
|
||||
decrementPrefundedReserveCount(view(), sponsorshipSle, ownerCountDelta);
|
||||
!isTesSuccess(ter))
|
||||
return ter;
|
||||
return ter; // LCOV_EXCL_LINE
|
||||
}
|
||||
}
|
||||
else if (ctx_.tx.isFlag(tfSponsorshipEnd))
|
||||
@@ -423,13 +423,13 @@ SponsorshipTransfer::doApply()
|
||||
if (auto const ter = decrementSponsorCount(
|
||||
view(), sponseeSle, sfSponsoredOwnerCount, ownerCountDelta);
|
||||
!isTesSuccess(ter))
|
||||
return ter;
|
||||
return ter; // LCOV_EXCL_LINE
|
||||
|
||||
// Decrement old sponsoring count
|
||||
if (auto const ter = decrementSponsorCount(
|
||||
view(), oldSponsorSle, sfSponsoringOwnerCount, ownerCountDelta);
|
||||
!isTesSuccess(ter))
|
||||
return ter;
|
||||
return ter; // LCOV_EXCL_LINE
|
||||
|
||||
// Remove sponsor from object
|
||||
objectSle->makeFieldAbsent(sponsorField);
|
||||
@@ -477,14 +477,14 @@ SponsorshipTransfer::doApply()
|
||||
if (auto const ter =
|
||||
decrementSponsorCount(view(), oldSponsorSle, sfSponsoringAccountCount, 1);
|
||||
!isTesSuccess(ter))
|
||||
return ter;
|
||||
return ter; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
// Increment new sponsoring count
|
||||
if (auto const ter =
|
||||
incrementSponsorCount(view(), newSponsorSle, sfSponsoringAccountCount, 1);
|
||||
!isTesSuccess(ter))
|
||||
return ter;
|
||||
return ter; // LCOV_EXCL_LINE
|
||||
|
||||
// Account is now sponsored by new sponsor
|
||||
sponseeSle->setAccountID(sfSponsor, newSponsorID);
|
||||
@@ -519,7 +519,7 @@ SponsorshipTransfer::doApply()
|
||||
if (auto const ter =
|
||||
decrementSponsorCount(view(), oldSponsorSle, sfSponsoringAccountCount, 1);
|
||||
!isTesSuccess(ter))
|
||||
return ter;
|
||||
return ter; // LCOV_EXCL_LINE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ MPTokenIssuanceCreate::create(
|
||||
// A reserve sponsor only covers tx.Account's own objects.
|
||||
auto const sponsorExp = getEffectiveTxReserveSponsor(ctx, acct);
|
||||
if (!sponsorExp)
|
||||
return std::unexpected(sponsorExp.error());
|
||||
return std::unexpected(sponsorExp.error()); // LCOV_EXCL_LINE
|
||||
auto const sponsorSle = *sponsorExp;
|
||||
|
||||
if (args.priorBalance)
|
||||
|
||||
@@ -5201,6 +5201,31 @@ class Invariants_test : public beast::unit_test::Suite
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
auto const expectMessage =
|
||||
"SponsoredObjectOwnerCount does not equal SponsoredOwnerCount delta.";
|
||||
uint256 checkID;
|
||||
|
||||
doInvariantCheck(
|
||||
{{expectMessage}},
|
||||
[&](Account const&, Account const& a2, ApplyContext& ac) {
|
||||
auto const check = ac.view().peek(keylet::check(checkID));
|
||||
if (!check)
|
||||
return false;
|
||||
check->setAccountID(sfSponsor, a2.id());
|
||||
ac.view().update(check);
|
||||
return true;
|
||||
},
|
||||
XRPAmount{},
|
||||
STTx{ttACCOUNT_SET, [](STObject&) {}},
|
||||
{tecINVARIANT_FAILED, tefINVARIANT_FAILED},
|
||||
[&checkID](Account const& a1, Account const& a2, Env& env) {
|
||||
checkID = keylet::check(a1.id(), env.seq(a1)).key;
|
||||
env(check::create(a1, a2, XRP(1)));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
auto const expectMessage =
|
||||
"Invariant failed: Net delta of SponsoringAccountCount does "
|
||||
|
||||
@@ -618,6 +618,32 @@ public:
|
||||
BEAST_EXPECT(sle->at(sfFeeAmount) == XRP(100));
|
||||
BEAST_EXPECT(sle->at(sfMaxFee) == XRP(1));
|
||||
|
||||
// update sponsorship flags
|
||||
auto testFlagUpdate = [&](auto setFlag, auto clearFlag, auto ledgerFlag) {
|
||||
env(sponsor::set(sponsor, setFlag), sponsor::SponseeAcc(alice), Fee(XRP(1)));
|
||||
env.close();
|
||||
|
||||
sle = env.le(keylet::sponsorship(sponsor, alice));
|
||||
BEAST_EXPECT(sle);
|
||||
BEAST_EXPECT(sle->isFlag(ledgerFlag));
|
||||
|
||||
env(sponsor::set(sponsor, clearFlag), sponsor::SponseeAcc(alice), Fee(XRP(1)));
|
||||
env.close();
|
||||
|
||||
sle = env.le(keylet::sponsorship(sponsor, alice));
|
||||
BEAST_EXPECT(sle);
|
||||
BEAST_EXPECT(!sle->isFlag(ledgerFlag));
|
||||
};
|
||||
|
||||
testFlagUpdate(
|
||||
tfSponsorshipSetRequireSignForFee,
|
||||
tfSponsorshipClearRequireSignForFee,
|
||||
lsfSponsorshipRequireSignForFee);
|
||||
testFlagUpdate(
|
||||
tfSponsorshipSetRequireSignForReserve,
|
||||
tfSponsorshipClearRequireSignForReserve,
|
||||
lsfSponsorshipRequireSignForReserve);
|
||||
|
||||
// update sponsorship with zero value
|
||||
env(sponsor::set(sponsor, 0, 0, XRP(0), XRP(0)),
|
||||
sponsor::SponseeAcc(alice),
|
||||
|
||||
@@ -205,6 +205,15 @@ public:
|
||||
resp[jss::result][jss::error_message] ==
|
||||
"Invalid field 'limit', not unsigned integer.");
|
||||
}
|
||||
// test error on sponsored param not a boolean
|
||||
{
|
||||
json::Value params;
|
||||
params[jss::account] = bob.human();
|
||||
params[jss::sponsored] = "true";
|
||||
auto resp = env.rpc("json", "account_objects", to_string(params));
|
||||
BEAST_EXPECT(
|
||||
resp[jss::result][jss::error_message] == "Invalid field 'sponsored', not boolean.");
|
||||
}
|
||||
// test errors on marker
|
||||
{
|
||||
Account const gw{"G"};
|
||||
|
||||
Reference in New Issue
Block a user